26 #include <spot/twa/fwd.hh>
27 #include <spot/twa/acc.hh>
28 #include <spot/twa/bdddict.hh>
31 #include <unordered_map>
35 #include <spot/misc/casts.hh>
36 #include <spot/misc/hash.hh>
38 #include <spot/misc/trival.hh>
43 typedef std::shared_ptr<twa_run> twa_run_ptr;
46 typedef std::shared_ptr<twa_word> twa_word_ptr;
63 virtual int compare(
const state* other)
const = 0;
84 virtual size_t hash()
const = 0;
87 virtual state* clone()
const = 0;
130 operator()(
const state* left,
const state* right)
const
133 return left->
compare(right) < 0;
153 operator()(
const state* left,
const state* right)
const
156 return 0 == left->
compare(right);
177 operator()(
const state* that)
const
189 typedef std::unordered_set<
const state*,
196 using state_map = std::unordered_map<
const state*, val,
216 auto p = m.insert(s);
228 auto p = m.insert(s);
239 for (state_set::iterator i = m.begin(); i != m.end();)
243 state_set::iterator old = i++;
260 typedef std::shared_ptr<const state> shared_state;
262 inline void shared_state_deleter(state* s) { s->destroy(); }
280 operator()(shared_state left,
281 shared_state right)
const
284 return left->compare(right.get()) < 0;
308 operator()(shared_state left,
309 shared_state right)
const
312 return 0 == left->compare(right.get());
337 operator()(shared_state that)
const
345 typedef std::unordered_set<shared_state,
422 virtual bool first() = 0;
434 virtual bool next() = 0;
451 virtual bool done()
const = 0;
467 virtual const state* dst()
const = 0;
471 virtual bdd cond()
const = 0;
536 twa_succ_iterable(twa_succ_iterable&& other)
537 : aut_(other.aut_), it_(other.it_)
542 ~twa_succ_iterable();
544 internal::succ_iterator begin()
546 return it_->
first() ? it_ :
nullptr;
549 internal::succ_iterator end()
621 class SPOT_API
twa:
public std::enable_shared_from_this<twa>
624 twa(
const bdd_dict_ptr& d);
638 virtual const state* get_init_state()
const = 0;
648 succ_iter(
const state* local_state)
const = 0;
677 return {
this, succ_iter(s)};
728 int res = dict_->has_registered_proposition(ap,
this);
732 res = dict_->register_proposition(ap,
this);
733 bddaps_ &= bdd_ithvar(res);
747 void unregister_ap(
int num);
763 throw std::runtime_error(
"register_ap_from_dict() may not be"
764 " called on an automaton that has already"
765 " registered some AP");
766 auto& m = get_dict()->bdd_map;
767 unsigned s = m.size();
768 for (
unsigned n = 0; n < s; ++n)
769 if (m[n].refs.find(
this) != m[n].refs.end())
771 aps_.push_back(m[n].f);
772 bddaps_ &= bdd_ithvar(n);
778 const std::vector<formula>&
ap()
const
795 virtual std::string format_state(
const state* s)
const = 0;
810 virtual state* project_state(
const state* s,
811 const const_twa_ptr& t)
const;
830 virtual bool is_empty()
const;
844 virtual twa_run_ptr accepting_run()
const;
855 virtual twa_word_ptr accepting_word()
const;
859 virtual bool intersects(const_twa_ptr other)
const;
878 virtual twa_run_ptr intersecting_run(const_twa_ptr other,
879 bool from_other =
false)
const;
888 virtual twa_word_ptr intersecting_word(const_twa_ptr other)
const;
893 void set_num_sets_(
unsigned num)
895 if (num < acc_.num_sets())
900 acc_.add_sets(num - acc_.num_sets());
907 return acc_.num_sets();
913 return acc_.get_acceptance();
923 acc_.set_acceptance(c);
935 for (
auto f: a->ap())
936 this->register_ap(f);
954 acc_.set_generalized_buchi();
974 set_generalized_buchi(1);
979 std::vector<formula> aps_;
985 trival::repr_t state_based_acc:2;
986 trival::repr_t inherently_weak:2;
987 trival::repr_t weak:2;
988 trival::repr_t terminal:2;
989 trival::repr_t deterministic:2;
990 trival::repr_t unambiguous:2;
991 trival::repr_t stutter_invariant:2;
1001 std::unordered_map<std::string,
1003 std::function<void(void*)>>> named_prop_;
1005 void* get_named_prop_(std::string s)
const;
1010 void set_named_prop(std::string s,
1026 void* val, std::function<
void(
void*)> destructor);
1043 template<
typename T>
1046 set_named_prop(s, val, [](
void *p) {
delete static_cast<T*
>(p); });
1059 void set_named_prop(std::string s, std::nullptr_t);
1076 template<
typename T>
1079 if (
void* p = get_named_prop_(s))
1080 return static_cast<T*
>(p);
1097 template<
typename T>
1100 if (
void* p = get_named_prop_(s))
1101 return static_cast<T*
>(p);
1104 set_named_prop(s, tmp);
1117 for (
auto& np: named_prop_)
1118 np.second.second(np.second.first);
1119 named_prop_.clear();
1130 if (num_sets() == 0)
1132 return is.state_based_acc;
1141 is.state_based_acc = val.val();
1150 return prop_state_acc() && acc().is_buchi();
1163 return is.inherently_weak;
1175 is.inherently_weak = val.val();
1177 is.terminal = is.weak = val.val();
1205 is.terminal = val.val();
1207 is.inherently_weak = is.weak = val.val();
1232 is.weak = val.val();
1234 is.inherently_weak = val.val();
1236 is.terminal = val.val();
1252 return is.deterministic;
1263 is.deterministic = val.val();
1266 is.unambiguous = val.val();
1284 return is.unambiguous;
1295 is.unambiguous = val.val();
1297 is.deterministic = val.val();
1314 return is.stutter_invariant;
1320 is.stutter_invariant = val.val();
1380 return {
true,
true,
true,
true };
1397 prop_state_acc(other->prop_state_acc());
1400 prop_terminal(other->prop_terminal());
1401 prop_weak(other->prop_weak());
1402 prop_inherently_weak(other->prop_inherently_weak());
1406 prop_deterministic(other->prop_deterministic());
1407 prop_unambiguous(other->prop_unambiguous());
1410 prop_stutter_invariant(other->prop_stutter_invariant());
1421 prop_state_acc(trival::maybe());
1424 prop_terminal(trival::maybe());
1425 prop_weak(trival::maybe());
1426 prop_inherently_weak(trival::maybe());
1430 prop_deterministic(trival::maybe());
1431 prop_unambiguous(trival::maybe());
1434 prop_stutter_invariant(trival::maybe());
1442 inline twa_succ_iterable::~twa_succ_iterable()
Helper class to iterate over the successor of a state using the on-the-fly interface.
Definition: twa.hh:525
virtual ~state()
Destructor.
Definition: twa.hh:110
bool stutter_inv
preserve stutter invariance
Definition: twa.hh:1361
Helper structure to iterate over the successor of a state using the on-the-fly interface.
Definition: twa.hh:486
bool inherently_weak
preserve inherently weak, weak, & terminal
Definition: twa.hh:1359
An Equivalence Relation for state*.
Definition: twa.hh:150
Render state pointers unique via a hash table.
Definition: twa.hh:201
void prop_weak(trival val)
Set the weak property.
Definition: twa.hh:1230
bdd ap_vars() const
The set of atomic propositions as a conjunction.
Definition: twa.hh:784
void prop_inherently_weak(trival val)
Set the "inherently weak" proeprty.
Definition: twa.hh:1173
twa_succ_iterator * iter_cache_
Any iterator returned via release_iter.
Definition: twa.hh:626
bdd_dict_ptr dict_
BDD dictionary used by the automaton.
Definition: twa.hh:628
trival prop_inherently_weak() const
Whether the automaton is inherently weak.
Definition: twa.hh:1161
A Transition-based ω-Automaton.
Definition: twa.hh:621
void prop_stutter_invariant(trival val)
Set the stutter-invariant property.
Definition: twa.hh:1318
acc_cond & acc()
The acceptance condition of the automaton.
Definition: twa.hh:820
Abstract class for states.
Definition: twa.hh:50
Strict Weak Ordering for shared_state (shared_ptr).
Definition: twa.hh:277
T * get_or_set_named_prop(std::string s)
Create or retrieve a named property.
Definition: twa.hh:1098
trival prop_unambiguous() const
Whether the automaton is unambiguous.
Definition: twa.hh:1282
bool deterministic
preserve deterministic and unambiguous
Definition: twa.hh:1360
trival prop_state_acc() const
Whether the automaton uses state-based acceptance.
Definition: twa.hh:1128
virtual bool next()=0
Jump to the next successor (if any).
void set_generalized_buchi(unsigned num)
Set generalized Büchi acceptance.
Definition: twa.hh:951
void copy_acceptance_of(const const_twa_ptr &a)
Copy the acceptance condition of another TωA.
Definition: twa.hh:927
static prop_set all()
An all-true prop_set.
Definition: twa.hh:1378
virtual bool first()=0
Position the iterator on the first successor (if any).
void set_named_prop(std::string s, T *val)
Declare a named property.
Definition: twa.hh:1044
void set_acceptance(unsigned num, const acc_cond::acc_code &c)
Set the acceptance condition of the automaton.
Definition: twa.hh:920
void prop_state_acc(trival val)
Set the state-based-acceptance property.
Definition: twa.hh:1139
virtual void destroy() const
Release a state.
Definition: twa.hh:98
void prop_unambiguous(trival val)
Sets the unambiguous property.
Definition: twa.hh:1293
Hash Function for shared_state (shared_ptr).
Definition: twa.hh:334
Iterate over the successors of a state.
Definition: twa.hh:397
trival prop_stutter_invariant() const
Whether the automaton is stutter-invariant.
Definition: twa.hh:1312
void release_named_properties()
Destroy all named properties.
Definition: twa.hh:1114
void prop_deterministic(trival val)
Set the deterministic property.
Definition: twa.hh:1261
internal::twa_succ_iterable succ(const state *s) const
Build an iterable over the successors of s.
Definition: twa.hh:675
trival prop_terminal() const
Whether the automaton is terminal.
Definition: twa.hh:1191
const acc_cond::acc_code & get_acceptance() const
Acceptance formula used by the automaton.
Definition: twa.hh:911
trival prop_weak() const
Whether the automaton is weak.
Definition: twa.hh:1217
int register_ap(formula ap)
Register an atomic proposition designated by ap.
Definition: twa.hh:726
const state * operator()(const state *s)
Canonicalize state pointer.
Definition: twa.hh:214
void prop_terminal(trival val)
Set the terminal property.
Definition: twa.hh:1203
bool state_based
preserve state-based acceptnace
Definition: twa.hh:1358
A class implementing Kleene's three-valued logic.
Definition: trival.hh:33
void release_iter(twa_succ_iterator *i) const
Release an iterator after usage.
Definition: twa.hh:685
A structure for selecting a set of automaton properties to copy.
Definition: twa.hh:1356
const state * is_new(const state *s)
Canonicalize state pointer.
Definition: twa.hh:226
unsigned num_sets() const
Number of acceptance sets used by the automaton.
Definition: twa.hh:905
Hash Function for state*.
Definition: twa.hh:174
const acc_cond & acc() const
The acceptance condition of the automaton.
Definition: twa.hh:815
T * get_named_prop(std::string s) const
Retrieve a named property.
Definition: twa.hh:1077
void register_aps_from_dict()
Register all atomic propositions that have already be register by the bdd_dict for this automaton...
Definition: twa.hh:760
const std::vector< formula > & ap() const
The vector of atomic propositions registered by this automaton.
Definition: twa.hh:778
void prop_keep(prop_set p)
Keep only a subset of properties of the current automaton.
Definition: twa.hh:1418
virtual int compare(const state *other) const =0
Compares two states (that come from the same automaton).
int register_ap(std::string ap)
Register an atomic proposition designated by ap.
Definition: twa.hh:738
virtual size_t hash() const =0
Hash a state.
trival prop_deterministic() const
Whether the automaton is deterministic.
Definition: twa.hh:1250
void prop_copy(const const_twa_ptr &other, prop_set p)
Copy the properties of another automaton.
Definition: twa.hh:1394
trival is_sba() const
Whether this is a state-based Büchi automaton.
Definition: twa.hh:1148
Strict Weak Ordering for state*.
Definition: twa.hh:127
bdd_dict_ptr get_dict() const
Get the dictionary associated to the automaton.
Definition: twa.hh:709
acc_cond::mark_t set_buchi()
Set Büchi acceptance.
Definition: twa.hh:972
void copy_ap_of(const const_twa_ptr &a)
Copy the atomic propositions of another TωA.
Definition: twa.hh:933
An Equivalence Relation for shared_state (shared_ptr).
Definition: twa.hh:305