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);
737 return register_ap(formula::ap(
ap));
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;
887 SPOT_DEPRECATED(
"replace a->intersecting_run(b, true) "
888 "by b->intersecting_run(a).")
889 twa_run_ptr intersecting_run(const_twa_ptr other,
890 bool from_other)
const
893 return other->intersecting_run(shared_from_this());
895 return this->intersecting_run(other);
967 for (
auto f: a->ap())
968 this->register_ap(f);
988 acc_ =
acc_cond(num, acc_cond::acc_code::generalized_buchi(num));
1005 acc_ =
acc_cond(num, acc_cond::acc_code::generalized_co_buchi(num));
1025 acc_ =
acc_cond(1, acc_cond::acc_code::buchi());
1046 acc_ =
acc_cond(1, acc_cond::acc_code::cobuchi());
1051 std::vector<formula> aps_;
1057 trival::repr_t state_based_acc:2;
1058 trival::repr_t inherently_weak:2;
1059 trival::repr_t weak:2;
1060 trival::repr_t terminal:2;
1061 trival::repr_t universal:2;
1062 trival::repr_t unambiguous:2;
1063 trival::repr_t stutter_invariant:2;
1064 trival::repr_t very_weak:2;
1065 trival::repr_t semi_deterministic:2;
1077 std::unordered_map<std::string,
1079 std::function<void(
void*)>>> named_prop_;
1081 void* get_named_prop_(std::string s)
const;
1102 void* val, std::function<
void(
void*)> destructor);
1119 template<
typename T>
1122 set_named_prop(s, val,
1123 [](
void *p)
noexcept {
delete static_cast<T*
>(p); });
1153 template<
typename T>
1156 if (
void* p = get_named_prop_(s))
1157 return static_cast<T*
>(p);
1174 template<
typename T>
1177 if (
void* p = get_named_prop_(s))
1178 return static_cast<T*
>(p);
1181 set_named_prop(s, tmp);
1194 for (
auto& np: named_prop_)
1195 np.second.second(np.second.first);
1196 named_prop_.clear();
1207 if (num_sets() == 0)
1209 return trival::from_repr_t(is.state_based_acc);
1218 is.state_based_acc = val.val();
1227 return prop_state_acc() && acc().is_buchi();
1240 return trival::from_repr_t(is.inherently_weak);
1252 is.inherently_weak = val.val();
1254 is.very_weak = is.terminal = is.weak = val.val();
1270 return trival::from_repr_t(is.terminal);
1282 is.terminal = val.val();
1284 is.inherently_weak = is.weak = val.val();
1296 return trival::from_repr_t(is.weak);
1309 is.weak = val.val();
1311 is.inherently_weak = val.val();
1313 is.very_weak = is.terminal = val.val();
1326 return trival::from_repr_t(is.very_weak);
1338 is.very_weak = val.val();
1340 is.weak = is.inherently_weak = val.val();
1357 return trival::from_repr_t(is.complete);
1365 is.complete = val.val();
1381 return trival::from_repr_t(is.universal);
1393 is.universal = val.val();
1396 is.unambiguous = is.semi_deterministic = val.val();
1405 SPOT_DEPRECATED(
"use prop_universal() instead")
1406 void prop_deterministic(
trival val)
1408 prop_universal(val);
1411 SPOT_DEPRECATED(
"use prop_universal() instead")
1412 trival prop_deterministic()
const
1414 return prop_universal();
1432 return trival::from_repr_t(is.unambiguous);
1443 is.unambiguous = val.val();
1445 is.universal = val.val();
1462 return trival::from_repr_t(is.semi_deterministic);
1473 is.semi_deterministic = val.val();
1475 is.universal = val.val();
1492 return trival::from_repr_t(is.stutter_invariant);
1498 is.stutter_invariant = val.val();
1543 bool inherently_weak;
1550 : state_based(false),
1551 inherently_weak(false),
1552 deterministic(false),
1559 prop_set(
bool state_based,
1560 bool inherently_weak,
1565 : state_based(state_based),
1566 inherently_weak(inherently_weak),
1567 deterministic(deterministic),
1568 improve_det(improve_det),
1570 stutter_inv(stutter_inv)
1576 SPOT_DEPRECATED(
"prop_set() now takes 6 arguments")
1577 prop_set(
bool state_based,
1578 bool inherently_weak,
1582 : state_based(state_based),
1583 inherently_weak(inherently_weak),
1584 deterministic(deterministic),
1585 improve_det(improve_det),
1587 stutter_inv(stutter_inv)
1609 return {
true,
true,
true,
true,
true,
true };
1626 prop_state_acc(other->prop_state_acc());
1627 if (p.inherently_weak)
1629 prop_terminal(other->prop_terminal());
1630 prop_weak(other->prop_weak());
1631 prop_very_weak(other->prop_very_weak());
1632 prop_inherently_weak(other->prop_inherently_weak());
1634 if (p.deterministic)
1636 prop_universal(other->prop_universal());
1637 prop_semi_deterministic(other->prop_semi_deterministic());
1638 prop_unambiguous(other->prop_unambiguous());
1640 else if (p.improve_det)
1642 if (other->prop_universal().is_true())
1644 prop_universal(
true);
1648 if (other->prop_semi_deterministic().is_true())
1649 prop_semi_deterministic(
true);
1650 if (other->prop_unambiguous().is_true())
1651 prop_unambiguous(
true);
1655 prop_complete(other->prop_complete());
1657 prop_stutter_invariant(other->prop_stutter_invariant());
1668 prop_state_acc(trival::maybe());
1669 if (!p.inherently_weak)
1671 prop_terminal(trival::maybe());
1672 prop_weak(trival::maybe());
1673 prop_very_weak(trival::maybe());
1674 prop_inherently_weak(trival::maybe());
1676 if (!p.deterministic)
1678 if (!(p.improve_det && prop_universal().is_true()))
1679 prop_universal(trival::maybe());
1680 if (!(p.improve_det && prop_semi_deterministic().is_true()))
1681 prop_semi_deterministic(trival::maybe());
1682 if (!(p.improve_det && prop_unambiguous().is_true()))
1683 prop_unambiguous(trival::maybe());
1686 prop_complete(trival::maybe());
1688 prop_stutter_invariant(trival::maybe());
1700 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:1555
unsigned num_sets() const
The number of sets used in the acceptance condition.
Definition acc.hh:2057
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:1280
void copy_acceptance_of(const const_twa_ptr &a)
Copy the acceptance condition of another TωA.
Definition twa.hh:959
void set_acceptance(unsigned num, const acc_cond::acc_code &c)
Set the acceptance condition of the automaton.
Definition twa.hh:945
virtual twa_run_ptr intersecting_run(const_twa_ptr other) const
Return an accepting run recognizing a word accepted by two automata.
void prop_inherently_weak(trival val)
Set the "inherently weak" property.
Definition twa.hh:1250
trival prop_universal() const
Whether the automaton is universal.
Definition twa.hh:1379
void set_generalized_buchi(unsigned num)
Set generalized Büchi acceptance.
Definition twa.hh:986
acc_cond::mark_t set_buchi()
Set Büchi acceptance.
Definition twa.hh:1023
void set_generalized_co_buchi(unsigned num)
Set generalized co-Büchi acceptance.
Definition twa.hh:1003
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:1191
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:1154
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:1307
trival prop_unambiguous() const
Whether the automaton is unambiguous.
Definition twa.hh:1430
trival prop_stutter_invariant() const
Whether the automaton is stutter-invariant.
Definition twa.hh:1490
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:1120
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:1496
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:1268
trival prop_state_acc() const
Whether the automaton uses state-based acceptance.
Definition twa.hh:1205
void set_acceptance(const acc_cond &c)
Set the acceptance condition of the automaton.
Definition twa.hh:953
void copy_ap_of(const const_twa_ptr &a)
Copy the atomic propositions of another TωA.
Definition twa.hh:965
trival prop_inherently_weak() const
Whether the automaton is inherently weak.
Definition twa.hh:1238
void prop_semi_deterministic(trival val)
Set the semi-deterministic property.
Definition twa.hh:1471
unsigned num_sets() const
Number of acceptance sets used by the automaton.
Definition twa.hh:930
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:1363
void prop_unambiguous(trival val)
Set the unambiguous property.
Definition twa.hh:1441
T * get_or_set_named_prop(std::string s)
Create or retrieve a named property.
Definition twa.hh:1175
void unregister_ap(int num)
Unregister an atomic proposition.
trival prop_very_weak() const
Whether the automaton is very-weak.
Definition twa.hh:1324
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:1044
void prop_very_weak(trival val)
Set the very-weak property.
Definition twa.hh:1336
void prop_state_acc(trival val)
Set the state-based-acceptance property.
Definition twa.hh:1216
trival prop_complete() const
Whether the automaton is complete.
Definition twa.hh:1355
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:1294
trival is_sba() const
Whether this is a state-based Büchi automaton.
Definition twa.hh:1225
const acc_cond::acc_code & get_acceptance() const
Acceptance formula used by the automaton.
Definition twa.hh:936
void prop_universal(trival val)
Set the universal property.
Definition twa.hh:1391
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:1607
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:1460
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:1665
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:1623
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:478
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