22#include <spot/twa/fwd.hh>
23#include <spot/twa/acc.hh>
24#include <spot/twa/bdddict.hh>
27#include <unordered_map>
31#include <spot/misc/casts.hh>
32#include <spot/misc/hash.hh>
34#include <spot/misc/trival.hh>
39 typedef std::shared_ptr<twa_run> twa_run_ptr;
42 typedef std::shared_ptr<twa_word> twa_word_ptr;
80 virtual size_t hash()
const = 0;
126 operator()(
const state* left,
const state* right)
const
129 return left->
compare(right) < 0;
149 operator()(
const state* left,
const state* right)
const
152 return 0 == left->
compare(right);
173 operator()(
const state* that)
const
185 typedef std::unordered_set<
const state*,
212 auto p = m.insert(s);
224 auto p = m.insert(s);
235 for (state_set::iterator i = m.begin(); i != m.end();)
239 state_set::iterator old = i++;
256 typedef std::shared_ptr<const state> shared_state;
258 inline void shared_state_deleter(state* s) { s->destroy(); }
276 operator()(shared_state left,
277 shared_state right)
const
280 return left->compare(right.get()) < 0;
304 operator()(shared_state left,
305 shared_state right)
const
308 return 0 == left->compare(right.get());
333 operator()(shared_state that)
const
341 typedef std::unordered_set<shared_state,
533 : aut_(other.aut_), it_(other.it_)
542 return it_->
first() ? it_ :
nullptr;
618 class SPOT_API
twa:
public std::enable_shared_from_this<twa>
621 twa(
const bdd_dict_ptr& d);
674 return {
this, succ_iter(s)};
725 int res = dict_->has_registered_proposition(
ap,
this);
728 aps_.emplace_back(
ap);
729 res = dict_->register_proposition(
ap,
this);
730 bddaps_ &= bdd_ithvar(res);
760 throw std::runtime_error(
"register_aps_from_dict() may not be"
761 " called on an automaton that has already"
762 " registered some AP");
763 auto& m = get_dict()->bdd_map;
764 unsigned s = m.size();
765 for (
unsigned n = 0; n < s; ++n)
766 if (m[n].refs.find(
this) != m[n].refs.end())
768 aps_.emplace_back(m[n].f);
769 bddaps_ &= bdd_ithvar(n);
775 const std::vector<formula>&
ap()
const
808 const const_twa_ptr& t)
const;
894 SPOT_DEPRECATED(
"replace a->intersecting_run(b, true) "
895 "by b->intersecting_run(a).")
896 twa_run_ptr intersecting_run(const_twa_ptr other,
897 bool from_other)
const
900 return other->intersecting_run(shared_from_this());
902 return this->intersecting_run(other);
974 for (
auto f: a->ap())
975 this->register_ap(f);
1058 std::vector<formula> aps_;
1064 trival::repr_t state_based_acc:2;
1065 trival::repr_t inherently_weak:2;
1066 trival::repr_t weak:2;
1067 trival::repr_t terminal:2;
1068 trival::repr_t universal:2;
1069 trival::repr_t unambiguous:2;
1070 trival::repr_t stutter_invariant:2;
1071 trival::repr_t very_weak:2;
1072 trival::repr_t semi_deterministic:2;
1084 std::unordered_map<std::string,
1086 std::function<void(
void*)>>> named_prop_;
1088 void* get_named_prop_(std::string s)
const;
1109 void* val, std::function<
void(
void*)> destructor);
1126 template<
typename T>
1129 set_named_prop(s, val,
1130 [](
void *p)
noexcept {
delete static_cast<T*
>(p); });
1160 template<
typename T>
1163 if (
void* p = get_named_prop_(s))
1164 return static_cast<T*
>(p);
1181 template<
typename T>
1184 if (
void* p = get_named_prop_(s))
1185 return static_cast<T*
>(p);
1188 set_named_prop(s, tmp);
1201 for (
auto& np: named_prop_)
1202 np.second.second(np.second.first);
1203 named_prop_.clear();
1214 if (num_sets() == 0)
1216 return trival::from_repr_t(is.state_based_acc);
1225 is.state_based_acc = val.val();
1234 return prop_state_acc() && acc().is_buchi();
1247 return trival::from_repr_t(is.inherently_weak);
1259 is.inherently_weak = val.val();
1261 is.very_weak = is.terminal = is.weak = val.val();
1277 return trival::from_repr_t(is.terminal);
1289 is.terminal = val.val();
1291 is.inherently_weak = is.weak = val.val();
1303 return trival::from_repr_t(is.weak);
1316 is.weak = val.val();
1318 is.inherently_weak = val.val();
1320 is.very_weak = is.terminal = val.val();
1333 return trival::from_repr_t(is.very_weak);
1345 is.very_weak = val.val();
1347 is.weak = is.inherently_weak = val.val();
1364 return trival::from_repr_t(is.complete);
1372 is.complete = val.val();
1388 return trival::from_repr_t(is.universal);
1400 is.universal = val.val();
1403 is.unambiguous = is.semi_deterministic = val.val();
1412 SPOT_DEPRECATED(
"use prop_universal() instead")
1413 void prop_deterministic(
trival val)
1415 prop_universal(val);
1418 SPOT_DEPRECATED(
"use prop_universal() instead")
1419 trival prop_deterministic()
const
1421 return prop_universal();
1439 return trival::from_repr_t(is.unambiguous);
1450 is.unambiguous = val.val();
1452 is.universal = val.val();
1469 return trival::from_repr_t(is.semi_deterministic);
1480 is.semi_deterministic = val.val();
1482 is.universal = val.val();
1499 return trival::from_repr_t(is.stutter_invariant);
1505 is.stutter_invariant = val.val();
1550 bool inherently_weak;
1557 : state_based(false),
1558 inherently_weak(false),
1559 deterministic(false),
1566 prop_set(
bool state_based,
1567 bool inherently_weak,
1572 : state_based(state_based),
1573 inherently_weak(inherently_weak),
1574 deterministic(deterministic),
1575 improve_det(improve_det),
1577 stutter_inv(stutter_inv)
1583 SPOT_DEPRECATED(
"prop_set() now takes 6 arguments")
1584 prop_set(
bool state_based,
1585 bool inherently_weak,
1589 : state_based(state_based),
1590 inherently_weak(inherently_weak),
1591 deterministic(deterministic),
1592 improve_det(improve_det),
1594 stutter_inv(stutter_inv)
1616 return {
true,
true,
true,
true,
true,
true };
1633 prop_state_acc(other->prop_state_acc());
1634 if (p.inherently_weak)
1636 prop_terminal(other->prop_terminal());
1637 prop_weak(other->prop_weak());
1638 prop_very_weak(other->prop_very_weak());
1639 prop_inherently_weak(other->prop_inherently_weak());
1641 if (p.deterministic)
1643 prop_universal(other->prop_universal());
1644 prop_semi_deterministic(other->prop_semi_deterministic());
1645 prop_unambiguous(other->prop_unambiguous());
1647 else if (p.improve_det)
1649 if (other->prop_universal().is_true())
1651 prop_universal(
true);
1655 if (other->prop_semi_deterministic().is_true())
1656 prop_semi_deterministic(
true);
1657 if (other->prop_unambiguous().is_true())
1658 prop_unambiguous(
true);
1662 prop_complete(other->prop_complete());
1664 prop_stutter_invariant(other->prop_stutter_invariant());
1675 prop_state_acc(trival::maybe());
1676 if (!p.inherently_weak)
1678 prop_terminal(trival::maybe());
1679 prop_weak(trival::maybe());
1680 prop_very_weak(trival::maybe());
1681 prop_inherently_weak(trival::maybe());
1683 if (!p.deterministic)
1685 if (!(p.improve_det && prop_universal().is_true()))
1686 prop_universal(trival::maybe());
1687 if (!(p.improve_det && prop_semi_deterministic().is_true()))
1688 prop_semi_deterministic(trival::maybe());
1689 if (!(p.improve_det && prop_unambiguous().is_true()))
1690 prop_unambiguous(trival::maybe());
1693 prop_complete(trival::maybe());
1695 prop_stutter_invariant(trival::maybe());
1707 inline twa_succ_iterable::~twa_succ_iterable()
An acceptance condition.
Definition: acc.hh:61
const acc_code & get_acceptance() const
Retrieve the acceptance formula.
Definition: acc.hh:1551
unsigned num_sets() const
The number of sets used in the acceptance condition.
Definition: acc.hh:2052
Helper class to iterate over the successors of a state using the on-the-fly interface.
Definition: twa.hh:522
Render state pointers unique via a hash table.
Definition: twa.hh:198
const state * operator()(const state *s)
Canonicalize state pointer.
Definition: twa.hh:210
const state * is_new(const state *s)
Canonicalize state pointer.
Definition: twa.hh:222
Abstract class for states.
Definition: twa.hh:47
virtual state * clone() const =0
Duplicate a state.
virtual size_t hash() const =0
Hash a state.
virtual void destroy() const
Release a state.
Definition: twa.hh:94
virtual ~state()
Destructor.
Definition: twa.hh:106
virtual int compare(const state *other) const =0
Compares two states (that come from the same automaton).
A class implementing Kleene's three-valued logic.
Definition: trival.hh:33
Iterate over the successors of a state.
Definition: twa.hh:394
virtual acc_cond::mark_t acc() const =0
Get the acceptance mark of the edge leading to this successor.
virtual bool done() const =0
Check whether the iteration is finished.
virtual const state * dst() const =0
Get the destination state of the current edge.
virtual bool first()=0
Position the iterator on the first successor (if any).
virtual bool next()=0
Jump to the next successor (if any).
virtual bdd cond() const =0
Get the condition on the edge leading to this successor.
A Transition-based ω-Automaton.
Definition: twa.hh:619
void prop_terminal(trival val)
Set the terminal property.
Definition: twa.hh:1287
void copy_acceptance_of(const const_twa_ptr &a)
Copy the acceptance condition of another TωA.
Definition: twa.hh:966
void set_acceptance(unsigned num, const acc_cond::acc_code &c)
Set the acceptance condition of the automaton.
Definition: twa.hh:952
virtual twa_run_ptr intersecting_run(const_twa_ptr other) const
Return an accepting run recognizing a word accepted by two automata.
virtual bool intersects(const_twa_word_ptr w) const
Check if this automaton _word intersects a word.
void prop_inherently_weak(trival val)
Set the "inherently weak" property.
Definition: twa.hh:1257
trival prop_universal() const
Whether the automaton is universal.
Definition: twa.hh:1386
void set_generalized_buchi(unsigned num)
Set generalized Büchi acceptance.
Definition: twa.hh:993
acc_cond::mark_t set_buchi()
Set Büchi acceptance.
Definition: twa.hh:1030
void set_generalized_co_buchi(unsigned num)
Set generalized co-Büchi acceptance.
Definition: twa.hh:1010
const acc_cond & acc() const
The acceptance condition of the automaton.
Definition: twa.hh:812
void release_named_properties()
Destroy all named properties.
Definition: twa.hh:1198
void set_named_prop(std::string s, void *val, std::function< void(void *)> destructor)
Declare a named property.
virtual state * project_state(const state *s, const const_twa_ptr &t) const
Project a state on an automaton.
T * get_named_prop(std::string s) const
Retrieve a named property.
Definition: twa.hh:1161
bdd_dict_ptr dict_
BDD dictionary used by the automaton.
Definition: twa.hh:625
void prop_weak(trival val)
Set the weak property.
Definition: twa.hh:1314
trival prop_unambiguous() const
Whether the automaton is unambiguous.
Definition: twa.hh:1437
trival prop_stutter_invariant() const
Whether the automaton is stutter-invariant.
Definition: twa.hh:1497
void set_named_prop(std::string s, std::nullptr_t)
Erase a named property.
virtual twa_succ_iterator * succ_iter(const state *local_state) const =0
Get an iterator over the successors of local_state.
bdd ap_vars() const
The set of atomic propositions as a conjunction.
Definition: twa.hh:781
virtual const state * get_init_state() const =0
Get the initial state of the automaton.
void set_named_prop(std::string s, T *val)
Declare a named property.
Definition: twa.hh:1127
virtual twa_run_ptr accepting_run() const
Return an accepting run if one exists.
void prop_stutter_invariant(trival val)
Set the stutter-invariant property.
Definition: twa.hh:1503
void copy_named_properties_of(const const_twa_ptr &a)
Copy all the named properties of a into this automaton.
trival prop_terminal() const
Whether the automaton is terminal.
Definition: twa.hh:1275
trival prop_state_acc() const
Whether the automaton uses state-based acceptance.
Definition: twa.hh:1212
void set_acceptance(const acc_cond &c)
Set the acceptance condition of the automaton.
Definition: twa.hh:960
void copy_ap_of(const const_twa_ptr &a)
Copy the atomic propositions of another TωA.
Definition: twa.hh:972
trival prop_inherently_weak() const
Whether the automaton is inherently weak.
Definition: twa.hh:1245
void prop_semi_deterministic(trival val)
Set the semi-deterministic property.
Definition: twa.hh:1478
unsigned num_sets() const
Number of acceptance sets used by the automaton.
Definition: twa.hh:937
virtual twa_word_ptr exclusive_word(const_twa_ptr other) const
Return a word accepted by exactly one of the two automata.
void prop_complete(trival val)
Set the complete property.
Definition: twa.hh:1370
void prop_unambiguous(trival val)
Set the unambiguous property.
Definition: twa.hh:1448
T * get_or_set_named_prop(std::string s)
Create or retrieve a named property.
Definition: twa.hh:1182
void unregister_ap(int num)
Unregister an atomic proposition.
trival prop_very_weak() const
Whether the automaton is very-weak.
Definition: twa.hh:1331
virtual std::string format_state(const state *s) const =0
Format the state as a string for printing.
acc_cond::mark_t set_co_buchi()
Set co-Büchi acceptance.
Definition: twa.hh:1051
void prop_very_weak(trival val)
Set the very-weak property.
Definition: twa.hh:1343
void prop_state_acc(trival val)
Set the state-based-acceptance property.
Definition: twa.hh:1223
trival prop_complete() const
Whether the automaton is complete.
Definition: twa.hh:1362
bdd_dict_ptr get_dict() const
Get the dictionary associated to the automaton.
Definition: twa.hh:706
trival prop_weak() const
Whether the automaton is weak.
Definition: twa.hh:1301
trival is_sba() const
Whether this is a state-based Büchi automaton.
Definition: twa.hh:1232
const acc_cond::acc_code & get_acceptance() const
Acceptance formula used by the automaton.
Definition: twa.hh:943
void prop_universal(trival val)
Set the universal property.
Definition: twa.hh:1398
virtual bool is_empty() const
Check whether the language of the automaton is empty.
static prop_set all()
A structure for selecting a set of automaton properties to copy.
Definition: twa.hh:1614
acc_cond & acc()
The acceptance condition of the automaton.
Definition: twa.hh:817
void register_aps_from_dict()
Register all atomic propositions that have already been registered by the bdd_dict for this automaton...
Definition: twa.hh:757
virtual twa_run_ptr exclusive_run(const_twa_ptr other) const
Return an accepting run recognizing a word accepted by exactly one of the two automata.
virtual twa_word_ptr accepting_word() const
Return an accepting word if one exists.
trival prop_semi_deterministic() const
Whether the automaton is semi-deterministic.
Definition: twa.hh:1467
virtual twa_word_ptr intersecting_word(const_twa_ptr other) const
Return a word accepted by two automata.
void release_iter(twa_succ_iterator *i) const
Release an iterator after usage.
Definition: twa.hh:682
int register_ap(std::string ap)
Register an atomic proposition designated by ap.
Definition: twa.hh:735
twa_succ_iterator * iter_cache_
Any iterator returned via release_iter.
Definition: twa.hh:623
const std::vector< formula > & ap() const
The vector of atomic propositions registered by this automaton.
Definition: twa.hh:775
virtual bool intersects(const_twa_ptr other) const
Check whether the language of this automaton intersects that of the other automaton.
internal::twa_succ_iterable succ(const state *s) const
Build an iterable over the successors of s.
Definition: twa.hh:672
int register_ap(formula ap)
Register an atomic proposition designated by ap.
Definition: twa.hh:723
Definition: automata.hh:26
void prop_keep(prop_set p)
Keep only a subset of properties of the current automaton.
Definition: twa.hh:1672
std::unordered_set< shared_state, state_shared_ptr_hash, state_shared_ptr_equal > shared_state_set
Unordered set of shared states.
Definition: twa.hh:343
void prop_copy(const const_twa_ptr &other, prop_set p)
Copy the properties of another automaton.
Definition: twa.hh:1630
std::unordered_map< const state *, val, state_ptr_hash, state_ptr_equal > state_map
Unordered map of abstract states.
Definition: twa.hh:193
std::unordered_set< const state *, state_ptr_hash, state_ptr_equal > state_set
Unordered set of abstract states.
Definition: twa.hh:186
twa_graph_ptr complete(const const_twa_ptr &aut)
Clone a twa and complete it.
An acceptance formula.
Definition: acc.hh:470
static acc_code generalized_buchi(unsigned n)
Build a generalized-Büchi acceptance condition with n sets.
Definition: acc.hh:761
static acc_code cobuchi()
Build a co-Büchi acceptance condition.
Definition: acc.hh:751
static acc_code buchi()
Build a Büchi acceptance condition.
Definition: acc.hh:743
static acc_code generalized_co_buchi(unsigned n)
Build a generalized-co-Büchi acceptance condition with n sets.
Definition: acc.hh:775
An acceptance mark.
Definition: acc.hh:84
Helper structure to iterate over the successors of a state using the on-the-fly interface.
Definition: twa.hh:483
An Equivalence Relation for state*.
Definition: twa.hh:147
Hash Function for state*.
Definition: twa.hh:171
Strict Weak Ordering for state*.
Definition: twa.hh:124
An Equivalence Relation for shared_state (shared_ptr<const state*>).
Definition: twa.hh:302
Hash Function for shared_state (shared_ptr<const state*>).
Definition: twa.hh:331
Strict Weak Ordering for shared_state (shared_ptr<const state*>).
Definition: twa.hh:274