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>
82 virtual size_t hash()
const = 0;
134 return left->
compare(right) < 0;
160 return 0 == left->
compare(right);
196 typedef std::unordered_set<
const state*,
223 auto p = m.insert(s);
235 auto p = m.insert(s);
246 for (state_set::iterator i = m.begin(); i != m.end();)
250 state_set::iterator old = i++;
307 return left->compare(right.get()) < 0;
337 return 0 == left->compare(right.get());
373 state_shared_ptr_hash,
513 struct SPOT_API succ_iterator
552 class twa_succ_iterable
556 twa_succ_iterator* it_;
558 twa_succ_iterable(
const twa* aut, twa_succ_iterator* it)
563 twa_succ_iterable(twa_succ_iterable&& other) noexcept
564 : aut_(other.aut_), it_(other.it_)
569 ~twa_succ_iterable();
571 internal::succ_iterator begin()
573 return it_->first() ? it_ :
nullptr;
576 internal::succ_iterator end()
647 class SPOT_API
twa:
public std::enable_shared_from_this<twa>
701 internal::twa_succ_iterable
704 return {
this, succ_iter(s)};
755 int res = dict_->has_registered_proposition(
ap,
this);
758 aps_.emplace_back(
ap);
759 res = dict_->register_proposition(
ap,
this);
760 bddaps_ &= bdd_ithvar(res);
767 return register_ap(formula::ap(
ap));
790 throw std::runtime_error(
"register_aps_from_dict() may not be"
791 " called on an automaton that has already"
792 " registered some AP");
793 auto& m = get_dict()->bdd_map;
794 unsigned s = m.size();
795 for (
unsigned n = 0; n < s; ++n)
796 if (m[n].refs.contains(
this))
798 aps_.emplace_back(m[n].f);
799 bddaps_ &= bdd_ithvar(n);
805 const std::vector<formula>&
ap()
const
986 for (
auto f: a->ap())
987 this->register_ap(f);
1007 acc_ =
acc_cond(num, acc_cond::acc_code::generalized_buchi(num));
1024 acc_ =
acc_cond(num, acc_cond::acc_code::generalized_co_buchi(num));
1044 acc_ =
acc_cond(1, acc_cond::acc_code::buchi());
1065 acc_ =
acc_cond(1, acc_cond::acc_code::cobuchi());
1070 std::vector<formula> aps_;
1098 std::unordered_map<std::string,
1127 void* val, std::function<
void(
void*)> destructor);
1144 template<
typename T>
1147 set_named_prop(s, val,
1148 [](
void *p)
noexcept {
delete static_cast<T*
>(p); });
1178 template<
typename T>
1181 if (
void* p = get_named_prop_(s))
1182 return static_cast<T*
>(p);
1199 template<
typename T>
1202 if (
void* p = get_named_prop_(s))
1203 return static_cast<T*
>(p);
1206 set_named_prop(s, tmp);
1219 for (
auto& np: named_prop_)
1220 np.second.second(np.second.first);
1221 named_prop_.clear();
1232 if (num_sets() == 0)
1234 return trival::from_repr_t(is.state_based_acc);
1243 is.state_based_acc = val.
val();
1252 return prop_state_acc() && acc().is_buchi();
1265 return trival::from_repr_t(is.inherently_weak);
1277 is.inherently_weak = val.
val();
1279 is.very_weak = is.terminal = is.weak = val.
val();
1295 return trival::from_repr_t(is.terminal);
1307 is.terminal = val.
val();
1309 is.inherently_weak = is.weak = val.
val();
1321 return trival::from_repr_t(is.weak);
1334 is.weak = val.
val();
1336 is.inherently_weak = val.
val();
1338 is.very_weak = is.terminal = val.
val();
1351 return trival::from_repr_t(is.very_weak);
1363 is.very_weak = val.
val();
1365 is.weak = is.inherently_weak = val.
val();
1382 return trival::from_repr_t(is.complete);
1390 is.complete = val.
val();
1406 return trival::from_repr_t(is.universal);
1418 is.universal = val.
val();
1421 is.unambiguous = is.semi_deterministic = val.
val();
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();
1558 : state_based(false),
1559 inherently_weak(false),
1560 deterministic(false),
1579 bool inherently_weak,
1584 : state_based(state_based),
1585 inherently_weak(inherently_weak),
1586 deterministic(deterministic),
1587 improve_det(improve_det),
1589 stutter_inv(stutter_inv)
1610 return {
true,
true,
true,
true,
true,
true };
1627 prop_state_acc(other->prop_state_acc());
1630 prop_terminal(other->prop_terminal());
1631 prop_weak(other->prop_weak());
1632 prop_very_weak(other->prop_very_weak());
1633 prop_inherently_weak(other->prop_inherently_weak());
1637 prop_universal(other->prop_universal());
1638 prop_semi_deterministic(other->prop_semi_deterministic());
1639 prop_unambiguous(other->prop_unambiguous());
1643 if (other->prop_universal().is_true())
1645 prop_universal(
true);
1649 if (other->prop_semi_deterministic().is_true())
1650 prop_semi_deterministic(
true);
1651 if (other->prop_unambiguous().is_true())
1652 prop_unambiguous(
true);
1656 prop_complete(other->prop_complete());
1658 prop_stutter_invariant(other->prop_stutter_invariant());
1669 prop_state_acc(trival::maybe());
1672 prop_terminal(trival::maybe());
1673 prop_weak(trival::maybe());
1674 prop_very_weak(trival::maybe());
1675 prop_inherently_weak(trival::maybe());
1679 if (!(p.
improve_det && prop_universal().is_true()))
1680 prop_universal(trival::maybe());
1681 if (!(p.
improve_det && prop_semi_deterministic().is_true()))
1682 prop_semi_deterministic(trival::maybe());
1683 if (!(p.
improve_det && prop_unambiguous().is_true()))
1684 prop_unambiguous(trival::maybe());
1687 prop_complete(trival::maybe());
1689 prop_stutter_invariant(trival::maybe());
1705 inline twa_succ_iterable::~twa_succ_iterable()
1708 aut_->release_iter(it_);
An acceptance condition.
Definition acc.hh:54
const acc_code & get_acceptance() const
Retrieve the acceptance formula.
Definition acc.hh:1601
unsigned num_sets() const
The number of sets used in the acceptance condition.
Definition acc.hh:2128
Render state pointers unique via a hash table.
Definition twa.hh:209
size_t size()
Return the number of unique states in the table.
Definition twa.hh:257
const state * operator()(const state *s)
Canonicalize state pointer.
Definition twa.hh:221
const state * is_new(const state *s)
Canonicalize state pointer.
Definition twa.hh:233
Abstract class for states.
Definition twa.hh:49
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:96
virtual ~state()
Destructor.
Definition twa.hh:108
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
signed char repr_t
Definition trival.hh:37
constexpr value_t val() const
Return the raw value_t enumerator.
Definition trival.hh:101
Iterate over the successors of a state.
Definition twa.hh:425
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:648
void prop_terminal(trival val)
Set the terminal property.
Definition twa.hh:1305
void copy_acceptance_of(const const_twa_ptr &a)
Copy the acceptance condition of another TωA.
Definition twa.hh:978
twa(const bdd_dict_ptr &d)
Construct a TωA using the given BDD dictionary.
void set_acceptance(unsigned num, const acc_cond::acc_code &c)
Set the acceptance condition of the automaton.
Definition twa.hh:964
virtual twa_run_ptr intersecting_run(const_twa_ptr other) const
Return an accepting run recognizing a word accepted by two automata.
void prop_reset()
Reset all automaton properties to trival::maybe().
Definition twa.hh:1696
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:1275
trival prop_universal() const
Whether the automaton is universal.
Definition twa.hh:1404
void set_generalized_buchi(unsigned num)
Set generalized Büchi acceptance.
Definition twa.hh:1005
void prop_keep(prop_set p)
Keep only a subset of properties of the current automaton.
Definition twa.hh:1666
acc_cond::mark_t set_buchi()
Set Büchi acceptance.
Definition twa.hh:1042
void set_generalized_co_buchi(unsigned num)
Set generalized co-Büchi acceptance.
Definition twa.hh:1022
const acc_cond & acc() const
The acceptance condition of the automaton.
Definition twa.hh:842
void release_named_properties()
Destroy all named properties.
Definition twa.hh:1216
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:1179
bdd_dict_ptr dict_
BDD dictionary used by the automaton.
Definition twa.hh:655
void prop_weak(trival val)
Set the weak property.
Definition twa.hh:1332
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:811
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:1145
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:1293
trival prop_state_acc() const
Whether the automaton uses state-based acceptance.
Definition twa.hh:1230
void set_acceptance(const acc_cond &c)
Set the acceptance condition of the automaton.
Definition twa.hh:972
std::unordered_map< std::string, std::pair< void *, std::function< void(void *)> > > named_prop_
Storage for named properties.
Definition twa.hh:1100
void copy_ap_of(const const_twa_ptr &a)
Copy the atomic propositions of another TωA.
Definition twa.hh:984
trival prop_inherently_weak() const
Whether the automaton is inherently weak.
Definition twa.hh:1263
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:949
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:1388
void prop_unambiguous(trival val)
Set the unambiguous property.
Definition twa.hh:1448
void prop_copy(const const_twa_ptr &other, prop_set p)
Copy the properties of another automaton.
Definition twa.hh:1624
T * get_or_set_named_prop(std::string s)
Create or retrieve a named property.
Definition twa.hh:1200
unsigned props
All property flags packed as a bitmask.
Definition twa.hh:1089
void unregister_ap(int num)
Unregister an atomic proposition.
trival prop_very_weak() const
Whether the automaton is very-weak.
Definition twa.hh:1349
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:1063
void prop_very_weak(trival val)
Set the very-weak property.
Definition twa.hh:1361
void prop_state_acc(trival val)
Set the state-based-acceptance property.
Definition twa.hh:1241
trival prop_complete() const
Whether the automaton is complete.
Definition twa.hh:1380
bdd_dict_ptr get_dict() const
Get the dictionary associated to the automaton.
Definition twa.hh:736
trival prop_weak() const
Whether the automaton is weak.
Definition twa.hh:1319
trival is_sba() const
Whether this is a state-based Büchi automaton.
Definition twa.hh:1250
const acc_cond::acc_code & get_acceptance() const
Acceptance formula used by the automaton.
Definition twa.hh:955
void prop_universal(trival val)
Set the universal property.
Definition twa.hh:1416
virtual bool is_empty() const
Check whether the language of the automaton is empty.
void * get_named_prop_(std::string s) const
Look up a named property by name.
acc_cond & acc()
The acceptance condition of the automaton.
Definition twa.hh:847
void register_aps_from_dict()
Register all atomic propositions that have already been registered by the bdd_dict for this automaton...
Definition twa.hh:787
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
bprop is
Named access to individual property flags.
Definition twa.hh:1090
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:712
int register_ap(std::string ap)
Register an atomic proposition designated by ap.
Definition twa.hh:765
twa_succ_iterator * iter_cache_
Any iterator returned via release_iter.
Definition twa.hh:653
const std::vector< formula > & ap() const
The vector of atomic propositions registered by this automaton.
Definition twa.hh:805
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:702
int register_ap(formula ap)
Register an atomic proposition designated by ap.
Definition twa.hh:753
twa_graph_ptr complete(const const_twa_ptr &aut)
Clone a twa and complete it.
std::shared_ptr< const state > shared_state
Shared pointer to a const state.
Definition twa.hh:272
std::shared_ptr< twa_run > twa_run_ptr
Shared pointer to a twa_run.
Definition twa.hh:41
void shared_state_deleter(state *s)
Deleter for shared_state: calls state::destroy().
Definition twa.hh:283
std::shared_ptr< twa_word > twa_word_ptr
Shared pointer to a mutable twa_word.
Definition fwd.hh:60
std::shared_ptr< const twa_word > const_twa_word_ptr
Shared pointer to a const twa_word.
Definition fwd.hh:57
std::shared_ptr< bdd_dict > bdd_dict_ptr
Shared pointer to a bdd_dict.
Definition bdddict.hh:304
std::shared_ptr< const twa > const_twa_ptr
Shared pointer to a const twa.
Definition fwd.hh:36
Definition automata.hh:26
std::unordered_set< shared_state, state_shared_ptr_hash, state_shared_ptr_equal > shared_state_set
Unordered set of shared states.
Definition twa.hh:374
constexpr bool operator==(trival a, trival b)
Equality comparison of two trival values.
Definition trival.hh:134
std::unordered_map< const state *, val, state_ptr_hash, state_ptr_equal > state_map
Unordered map of abstract states.
Definition twa.hh:204
std::unordered_set< const state *, state_ptr_hash, state_ptr_equal > state_set
Unordered set of abstract states.
Definition twa.hh:197
constexpr bool operator!=(trival a, trival b)
Inequality comparison of two trival values.
Definition trival.hh:140
An acceptance formula.
Definition acc.hh:456
An acceptance mark.
Definition acc.hh:76
An Equivalence Relation for state pointers.
Definition twa.hh:154
bool operator()(const state *left, const state *right) const
Test two state pointers for equality via state::compare().
Definition twa.hh:157
Hash Function for state pointers.
Definition twa.hh:181
size_t operator()(const state *that) const
Hash a state pointer using state::hash().
Definition twa.hh:184
Strict Weak Ordering for state pointers.
Definition twa.hh:128
bool operator()(const state *left, const state *right) const
Compare two state pointers using state::compare().
Definition twa.hh:131
An Equivalence Relation for shared_state.
Definition twa.hh:330
bool operator()(shared_state left, shared_state right) const
Test two shared states for equality via state::compare().
Definition twa.hh:333
Hash Function for shared_state.
Definition twa.hh:361
size_t operator()(shared_state that) const
Hash a shared state using state::hash().
Definition twa.hh:364
Strict Weak Ordering for shared_state.
Definition twa.hh:300
bool operator()(shared_state left, shared_state right) const
Compare two shared states using state::compare().
Definition twa.hh:303
A structure for selecting a set of automaton properties to copy.
Definition twa.hh:1548
bool deterministic
preserve deterministic, semi-det, unambiguous
Definition twa.hh:1551
bool improve_det
improve deterministic, semi-det, unambiguous
Definition twa.hh:1552
bool stutter_inv
preserve stutter invariance
Definition twa.hh:1554
static prop_set all()
An all-true prop_set.
Definition twa.hh:1608
bool inherently_weak
preserve inherently weak, weak, & terminal
Definition twa.hh:1550
prop_set(bool state_based, bool inherently_weak, bool deterministic, bool improve_det, bool complete, bool stutter_inv)
Construct a prop_set with explicit flag values.
Definition twa.hh:1578
bool complete
preserve completeness
Definition twa.hh:1553
prop_set()
Construct a prop_set with all flags set to false.
Definition twa.hh:1557
bool state_based
preserve state-based acceptance
Definition twa.hh:1549
An infinite word stored as a lasso.
Definition word.hh:35