30 #include <unordered_map>
33 #include "misc/casts.hh"
34 #include "misc/hash.hh"
53 virtual int compare(
const state* other)
const = 0;
74 virtual size_t hash()
const = 0;
77 virtual state* clone()
const = 0;
118 operator()(
const state* left,
const state* right)
const
121 return left->
compare(right) < 0;
141 operator()(
const state* left,
const state* right)
const
144 return 0 == left->
compare(right);
165 operator()(
const state* that)
const
172 typedef std::unordered_set<
const state*,
193 auto p = m.insert(s);
205 auto p = m.insert(s);
216 for (state_set::iterator i = m.begin(); i != m.end();)
220 state_set::iterator old = i++;
237 typedef std::shared_ptr<const state> shared_state;
239 inline void shared_state_deleter(state* s) { s->destroy(); }
257 operator()(shared_state left,
258 shared_state right)
const
261 return left->compare(right.get()) < 0;
283 operator()(shared_state left,
284 shared_state right)
const
287 return 0 == left->compare(right.get());
310 operator()(shared_state that)
const
317 typedef std::unordered_set<shared_state,
351 virtual bool first() = 0;
359 virtual bool next() = 0;
370 virtual bool done()
const = 0;
386 virtual state* current_state()
const = 0;
390 virtual bdd current_condition()
const = 0;
480 class SPOT_API
twa:
public std::enable_shared_from_this<twa>
483 twa(
const bdd_dict_ptr& d);
502 : aut_(other.aut_), it_(other.it_)
510 aut_->release_iter(it_);
515 return it_->
first() ? it_ :
nullptr;
532 virtual state* get_init_state()
const = 0;
540 succ_iter(
const state* local_state)
const = 0;
548 succ(
const state* s)
const
550 return {
this, succ_iter(s)};
558 void release_iter(twa_succ_iterator* i)
const
579 bdd support_conditions(
const state* state)
const;
588 bdd_dict_ptr get_dict()
const
597 virtual std::string format_state(
const state* state)
const = 0;
616 transition_annotation(
const twa_succ_iterator* t)
const;
631 virtual state* project_state(
const state* s,
632 const const_twa_ptr& t)
const;
635 const acc_cond& acc()
const
645 virtual bool is_empty()
const;
650 void set_num_sets_(
unsigned num)
652 if (num < acc_.num_sets())
655 new (&acc_) acc_cond;
657 acc_.add_sets(num - acc_.num_sets());
661 unsigned num_sets()
const
663 return acc_.num_sets();
666 const acc_cond::acc_code& get_acceptance()
const
668 return acc_.get_acceptance();
671 void set_acceptance(
unsigned num,
const acc_cond::acc_code& c)
674 acc_.set_acceptance(c);
676 prop_state_based_acc();
680 void copy_acceptance_of(
const const_twa_ptr& a)
683 unsigned num = acc_.num_sets();
685 prop_state_based_acc();
688 void copy_ap_of(
const const_twa_ptr& a)
690 get_dict()->register_all_propositions_of(a,
this);
693 void set_generalized_buchi(
unsigned num)
696 acc_.set_generalized_buchi();
698 prop_state_based_acc();
701 acc_cond::mark_t set_buchi()
703 set_generalized_buchi(1);
709 virtual bdd compute_support_conditions(
const state* state)
const = 0;
710 mutable const state* last_support_conditions_input_;
712 mutable bdd last_support_conditions_output_;
720 bool state_based_acc:1;
721 bool inherently_weak:1;
722 bool deterministic:1;
724 bool stutter_invariant:1;
725 bool stutter_sensitive:1;
735 std::unordered_map<std::string,
737 std::function<void(void*)>>> named_prop_;
739 void* get_named_prop_(std::string s)
const;
744 void set_named_prop(std::string s,
745 void* val, std::function<
void(
void*)> destructor);
748 void set_named_prop(std::string s, T* val)
750 set_named_prop(s, val, [](
void *p) {
delete static_cast<T*
>(p); });
754 T* get_named_prop(std::string s)
const
756 void* p = get_named_prop_(s);
759 return static_cast<T*
>(p);
763 void release_named_properties()
766 for (
auto& np: named_prop_)
767 np.second.second(np.second.first);
771 bool has_state_based_acc()
const
773 return is.state_based_acc;
776 void prop_state_based_acc(
bool val =
true)
778 is.state_based_acc = val;
783 return has_state_based_acc() && acc().is_buchi();
786 bool is_inherently_weak()
const
788 return is.inherently_weak;
791 void prop_inherently_weak(
bool val =
true)
793 is.inherently_weak = val;
798 return is.deterministic;
801 void prop_deterministic(
bool val =
true)
803 is.deterministic = val;
808 return is.unambiguous;
811 void prop_unambiguous(
bool val =
true)
813 is.unambiguous = val;
818 return is.stutter_invariant;
821 bool is_stutter_sensitive()
const
823 return is.stutter_sensitive;
826 void prop_stutter_invariant(
bool val =
true)
828 is.stutter_invariant = val;
831 void prop_stutter_sensitive(
bool val =
true)
833 is.stutter_sensitive = val;
839 bool inherently_weak;
845 return {
true,
true,
true,
true };
851 void prop_copy(
const const_twa_ptr& other,
prop_set p)
854 prop_state_based_acc(other->has_state_based_acc());
855 if (p.inherently_weak)
856 prop_inherently_weak(other->is_inherently_weak());
859 prop_deterministic(other->is_deterministic());
860 prop_unambiguous(other->is_unambiguous());
864 prop_stutter_invariant(other->is_stutter_invariant());
865 prop_stutter_sensitive(other->is_stutter_sensitive());
869 void prop_keep(prop_set p)
872 prop_state_based_acc(
false);
873 if (!p.inherently_weak)
874 prop_inherently_weak(
false);
875 if (!p.deterministic)
877 prop_deterministic(
false);
878 prop_unambiguous(
false);
882 prop_stutter_invariant(
false);
883 prop_stutter_sensitive(
false);
virtual ~state()
Destructor.
Definition: twa.hh:98
An Equivalence Relation for state*.
Definition: twa.hh:138
Render state pointers unique via a hash table.
Definition: twa.hh:178
SPOT_API bool is_deterministic(const const_twa_graph_ptr &aut)
Return true iff aut is deterministic.
A Transition-based ω-Automaton.
Definition: twa.hh:480
Abstract class for states.
Definition: twa.hh:40
Strict Weak Ordering for shared_state (shared_ptr).
Definition: twa.hh:254
virtual bool next()=0
Jump to the next successor (if any).
virtual bool first()=0
Position the iterator on the first successor (if any).
virtual void destroy() const
Release a state.
Definition: twa.hh:88
Hash Function for shared_state (shared_ptr).
Definition: twa.hh:307
Iterate over the successors of a state.
Definition: twa.hh:329
const state * operator()(const state *s)
Canonicalize state pointer.
Definition: twa.hh:191
const state * is_new(const state *s)
Canonicalize state pointer.
Definition: twa.hh:203
Hash Function for state*.
Definition: twa.hh:162
SPOT_API bool is_unambiguous(const const_twa_graph_ptr &aut)
Whether the automaton aut is unambiguous.
virtual int compare(const state *other) const =0
Compares two states (that come from the same automaton).
SPOT_API bool is_stutter_invariant(const ltl::formula *f)
Check if a formula has the stutter invariance property.
virtual size_t hash() const =0
Hash a state.
Strict Weak Ordering for state*.
Definition: twa.hh:115
An Equivalence Relation for shared_state (shared_ptr).
Definition: twa.hh:280