30 #include <unordered_map>
34 #include "misc/casts.hh"
35 #include "misc/hash.hh"
55 virtual int compare(
const state* other)
const = 0;
76 virtual size_t hash()
const = 0;
79 virtual state* clone()
const = 0;
120 operator()(
const state* left,
const state* right)
const
123 return left->
compare(right) < 0;
143 operator()(
const state* left,
const state* right)
const
146 return 0 == left->
compare(right);
167 operator()(
const state* that)
const
174 typedef std::unordered_set<
const state*,
195 auto p = m.insert(s);
207 auto p = m.insert(s);
218 for (state_set::iterator i = m.begin(); i != m.end();)
222 state_set::iterator old = i++;
239 typedef std::shared_ptr<const state> shared_state;
241 inline void shared_state_deleter(state* s) { s->destroy(); }
259 operator()(shared_state left,
260 shared_state right)
const
263 return left->compare(right.get()) < 0;
285 operator()(shared_state left,
286 shared_state right)
const
289 return 0 == left->compare(right.get());
312 operator()(shared_state that)
const
319 typedef std::unordered_set<shared_state,
353 virtual bool first() = 0;
361 virtual bool next() = 0;
372 virtual bool done()
const = 0;
388 virtual state* current_state()
const = 0;
392 virtual bdd current_condition()
const = 0;
494 class SPOT_API
twa:
public std::enable_shared_from_this<twa>
497 twa(
const bdd_dict_ptr& d);
516 : aut_(other.aut_), it_(other.it_)
524 aut_->release_iter(it_);
529 return it_->
first() ? it_ :
nullptr;
546 virtual state* get_init_state()
const = 0;
554 succ_iter(
const state* local_state)
const = 0;
562 succ(
const state* s)
const
564 return {
this, succ_iter(s)};
572 void release_iter(twa_succ_iterator* i)
const
593 bdd support_conditions(
const state* state)
const;
602 bdd_dict_ptr get_dict()
const
610 int register_ap(formula
ap)
613 int res = dict_->register_proposition(ap,
this);
614 bddaps_ &= bdd_ithvar(res);
621 int register_ap(std::string name)
628 const std::vector<formula>&
ap()
const
642 virtual std::string format_state(
const state* state)
const = 0;
661 transition_annotation(
const twa_succ_iterator* t)
const;
676 virtual state* project_state(
const state* s,
677 const const_twa_ptr& t)
const;
680 const acc_cond& acc()
const
690 virtual bool is_empty()
const;
695 void set_num_sets_(
unsigned num)
697 if (num < acc_.num_sets())
700 new (&acc_) acc_cond;
702 acc_.add_sets(num - acc_.num_sets());
706 unsigned num_sets()
const
708 return acc_.num_sets();
711 const acc_cond::acc_code& get_acceptance()
const
713 return acc_.get_acceptance();
716 void set_acceptance(
unsigned num,
const acc_cond::acc_code& c)
719 acc_.set_acceptance(c);
721 prop_state_based_acc();
725 void copy_acceptance_of(
const const_twa_ptr& a)
728 unsigned num = acc_.num_sets();
730 prop_state_based_acc();
733 void copy_ap_of(
const const_twa_ptr& a)
735 get_dict()->register_all_propositions_of(a,
this);
736 for (
auto f: a->ap())
737 this->register_ap(f);
740 void set_generalized_buchi(
unsigned num)
743 acc_.set_generalized_buchi();
745 prop_state_based_acc();
748 acc_cond::mark_t set_buchi()
750 set_generalized_buchi(1);
756 virtual bdd compute_support_conditions(
const state* state)
const = 0;
757 mutable const state* last_support_conditions_input_;
759 mutable bdd last_support_conditions_output_;
760 std::vector<formula> aps_;
769 bool state_based_acc:1;
770 bool inherently_weak:1;
771 bool deterministic:1;
773 bool stutter_invariant:1;
774 bool stutter_sensitive:1;
784 std::unordered_map<std::string,
786 std::function<void(void*)>>> named_prop_;
788 void* get_named_prop_(std::string s)
const;
793 void set_named_prop(std::string s,
794 void* val, std::function<
void(
void*)> destructor);
797 void set_named_prop(std::string s, T* val)
799 set_named_prop(s, val, [](
void *p) {
delete static_cast<T*
>(p); });
803 T* get_named_prop(std::string s)
const
805 void* p = get_named_prop_(s);
808 return static_cast<T*
>(p);
812 void release_named_properties()
815 for (
auto& np: named_prop_)
816 np.second.second(np.second.first);
820 bool has_state_based_acc()
const
822 return is.state_based_acc;
825 void prop_state_based_acc(
bool val =
true)
827 is.state_based_acc = val;
832 return has_state_based_acc() && acc().is_buchi();
835 bool is_inherently_weak()
const
837 return is.inherently_weak;
840 void prop_inherently_weak(
bool val =
true)
842 is.inherently_weak = val;
847 return is.deterministic;
850 void prop_deterministic(
bool val =
true)
852 is.deterministic = val;
857 return is.unambiguous;
860 void prop_unambiguous(
bool val =
true)
862 is.unambiguous = val;
865 bool is_stutter_invariant()
const
867 return is.stutter_invariant;
870 bool is_stutter_sensitive()
const
872 return is.stutter_sensitive;
875 void prop_stutter_invariant(
bool val =
true)
877 is.stutter_invariant = val;
880 void prop_stutter_sensitive(
bool val =
true)
882 is.stutter_sensitive = val;
888 bool inherently_weak;
894 return {
true,
true,
true,
true };
900 void prop_copy(
const const_twa_ptr& other,
prop_set p)
903 prop_state_based_acc(other->has_state_based_acc());
904 if (p.inherently_weak)
905 prop_inherently_weak(other->is_inherently_weak());
908 prop_deterministic(other->is_deterministic());
909 prop_unambiguous(other->is_unambiguous());
913 prop_stutter_invariant(other->is_stutter_invariant());
914 prop_stutter_sensitive(other->is_stutter_sensitive());
918 void prop_keep(prop_set p)
921 prop_state_based_acc(
false);
922 if (!p.inherently_weak)
923 prop_inherently_weak(
false);
924 if (!p.deterministic)
926 prop_deterministic(
false);
927 prop_unambiguous(
false);
931 prop_stutter_invariant(
false);
932 prop_stutter_sensitive(
false);
virtual ~state()
Destructor.
Definition: twa.hh:100
bool is_deterministic(const const_twa_graph_ptr &aut)
Return true iff aut is deterministic.
An Equivalence Relation for state*.
Definition: twa.hh:140
Render state pointers unique via a hash table.
Definition: twa.hh:180
A Transition-based ω-Automaton.
Definition: twa.hh:494
Abstract class for states.
Definition: twa.hh:42
Strict Weak Ordering for shared_state (shared_ptr).
Definition: twa.hh:256
virtual bool all_enabled() const
this method is only usefull if partial order reductions are enabled to check wether all states have b...
Definition: twa.hh:404
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:90
Hash Function for shared_state (shared_ptr).
Definition: twa.hh:309
Iterate over the successors of a state.
Definition: twa.hh:331
bool is_unambiguous(const const_twa_graph_ptr &aut)
Whether the automaton aut is unambiguous.
const state * operator()(const state *s)
Canonicalize state pointer.
Definition: twa.hh:193
const state * is_new(const state *s)
Canonicalize state pointer.
Definition: twa.hh:205
Hash Function for state*.
Definition: twa.hh:164
virtual void fire_all() const
this method is only usefull if partial order reductions are enabled
Definition: twa.hh:399
virtual int compare(const state *other) const =0
Compares two states (that come from the same automaton).
virtual size_t hash() const =0
Hash a state.
Strict Weak Ordering for state*.
Definition: twa.hh:117
An Equivalence Relation for shared_state (shared_ptr).
Definition: twa.hh:282