set_printer = nullptr) const;
/// \brief Construct an acc_code from a string.
///
/// The string can follow the following grammar:
///
///
/// acc ::= "t"
/// | "f"
/// | "Inf" "(" num ")"
/// | "Fin" "(" num ")"
/// | "(" acc ")"
/// | acc "&" acc
/// | acc "|" acc
///
///
/// Where num is an integer and "&" has priority over "|". Note that
/// "Fin(!x)" and "Inf(!x)" are not supported by this parser.
///
/// Or the string can be the name of an acceptance condition, as
/// speficied in the HOA format. (E.g. "Rabin 2", "parity max odd 3",
/// "generalized-Rabin 4 2 1", etc.).
///
/// A spot::parse_error is thrown on syntax error.
acc_code(const char* input);
/// \brief Build an empty acceptance condition.
///
/// This is the same as t().
acc_code()
{
}
// Calls to_text
SPOT_API
friend std::ostream& operator<<(std::ostream& os, const acc_code& code);
};
acc_cond(unsigned n_sets = 0, const acc_code& code = {})
: num_(0U), all_(0U), code_(code)
{
add_sets(n_sets);
uses_fin_acceptance_ = check_fin_acceptance();
}
acc_cond(const acc_code& code)
: num_(0U), all_(0U), code_(code)
{
add_sets(code.used_sets().max_set());
uses_fin_acceptance_ = check_fin_acceptance();
}
acc_cond(const acc_cond& o)
: num_(o.num_), all_(o.all_), code_(o.code_),
uses_fin_acceptance_(o.uses_fin_acceptance_)
{
}
~acc_cond()
{
}
void set_acceptance(const acc_code& code)
{
code_ = code;
uses_fin_acceptance_ = check_fin_acceptance();
}
const acc_code& get_acceptance() const
{
return code_;
}
acc_code& get_acceptance()
{
return code_;
}
bool uses_fin_acceptance() const
{
return uses_fin_acceptance_;
}
bool is_t() const
{
return code_.is_t();
}
bool is_all() const
{
return num_ == 0 && is_t();
}
bool is_f() const
{
return code_.is_f();
}
bool is_none() const
{
return num_ == 0 && is_f();
}
bool is_buchi() const
{
unsigned s = code_.size();
return num_ == 1 &&
s == 2 && code_[1].op == acc_op::Inf && code_[0].mark == all_sets();
}
bool is_co_buchi() const
{
return num_ == 1 && is_generalized_co_buchi();
}
void set_generalized_buchi()
{
set_acceptance(inf(all_sets()));
}
bool is_generalized_buchi() const
{
unsigned s = code_.size();
return (s == 0 && num_ == 0) ||
(s == 2 && code_[1].op == acc_op::Inf && code_[0].mark == all_sets());
}
bool is_generalized_co_buchi() const
{
unsigned s = code_.size();
return (s == 2 &&
code_[1].op == acc_op::Fin && code_[0].mark == all_sets());
}
// Returns a number of pairs (>=0) if Rabin, or -1 else.
int is_rabin() const;
// Returns a number of pairs (>=0) if Streett, or -1 else.
int is_streett() const;
// Return the number of Inf in each pair.
bool is_generalized_rabin(std::vector& pairs) const;
// If EQUIV is false, this return true iff the acceptance
// condition is a parity condition written in the canonical way
// given in the HOA specifications. If EQUIV is true, then we
// check whether the condition is logically equivalent to some
// parity acceptance condition.
bool is_parity(bool& max, bool& odd, bool equiv = false) const;
bool is_parity() const
{
bool max;
bool min;
return is_parity(max, min);
}
// Return (true, m) if there exist some acceptance mark m that
// does not satisfy the acceptance condition. Return (false, 0U)
// otherwise.
std::pair unsat_mark() const;
protected:
bool check_fin_acceptance() const;
public:
static acc_code inf(mark_t mark)
{
return acc_code::inf(mark);
}
static acc_code inf(std::initializer_list vals)
{
return inf(mark_t(vals.begin(), vals.end()));
}
static acc_code inf_neg(mark_t mark)
{
return acc_code::inf_neg(mark);
}
static acc_code inf_neg(std::initializer_list vals)
{
return inf_neg(mark_t(vals.begin(), vals.end()));
}
static acc_code fin(mark_t mark)
{
return acc_code::fin(mark);
}
static acc_code fin(std::initializer_list vals)
{
return fin(mark_t(vals.begin(), vals.end()));
}
static acc_code fin_neg(mark_t mark)
{
return acc_code::fin_neg(mark);
}
static acc_code fin_neg(std::initializer_list vals)
{
return fin_neg(mark_t(vals.begin(), vals.end()));
}
unsigned add_sets(unsigned num)
{
if (num == 0)
return -1U;
unsigned j = num_;
num_ += num;
if (num_ > 8 * sizeof(mark_t::id))
throw std::runtime_error("Too many acceptance sets used.");
all_ = all_sets_();
return j;
}
unsigned add_set()
{
return add_sets(1);
}
mark_t mark(unsigned u) const
{
SPOT_ASSERT(u < num_sets());
return 1U << u;
}
mark_t comp(mark_t l) const
{
return all_ ^ l.id;
}
mark_t all_sets() const
{
return all_;
}
bool accepting(mark_t inf) const
{
return code_.accepting(inf);
}
bool inf_satisfiable(mark_t inf) const
{
return code_.inf_satisfiable(inf);
}
mark_t accepting_sets(mark_t inf) const;
std::ostream& format(std::ostream& os, mark_t m) const
{
auto a = m;
if (a == 0U)
return os;
return os << m;
}
std::string format(mark_t m) const
{
std::ostringstream os;
format(os, m);
return os.str();
}
unsigned num_sets() const
{
return num_;
}
template
mark_t useless(iterator begin, iterator end) const
{
mark_t::value_t u = 0U; // The set of useless marks.
for (unsigned x = 0; x < num_; ++x)
{
// Skip marks that are already known to be useless.
if (u & (1 << x))
continue;
unsigned all = all_ ^ (u | (1 << x));
for (iterator y = begin; y != end; ++y)
{
auto v = y->id;
if (v & (1 << x))
{
all &= v;
if (!all)
break;
}
}
u |= all;
}
return u;
}
protected:
mark_t::value_t all_sets_() const
{
if (num_ == 0)
return 0;
return -1U >> (8 * sizeof(mark_t::value_t) - num_);
}
unsigned num_;
mark_t::value_t all_;
acc_code code_;
bool uses_fin_acceptance_ = false;
};
SPOT_API
std::ostream& operator<<(std::ostream& os, const acc_cond& acc);
}
namespace std
{
template<>
struct hash
{
size_t operator()(spot::acc_cond::mark_t m) const
{
std::hash h;
return h(m.id);
}
};
}