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 const state* dst()
const = 0;
392 virtual bdd cond()
const = 0;
482 class SPOT_API
twa:
public std::enable_shared_from_this<twa>
485 twa(
const bdd_dict_ptr& d);
504 : aut_(other.aut_), it_(other.it_)
512 aut_->release_iter(it_);
517 return it_->
first() ? it_ :
nullptr;
534 virtual const state* get_init_state()
const = 0;
542 succ_iter(
const state* local_state)
const = 0;
550 succ(
const state* s)
const
552 return {
this, succ_iter(s)};
560 void release_iter(twa_succ_iterator* i)
const
581 bdd support_conditions(
const state* state)
const;
590 bdd_dict_ptr get_dict()
const
598 int register_ap(formula
ap)
601 int res = dict_->register_proposition(ap,
this);
602 bddaps_ &= bdd_ithvar(res);
609 int register_ap(std::string name)
616 const std::vector<formula>&
ap()
const
630 virtual std::string format_state(
const state* state)
const = 0;
649 transition_annotation(
const twa_succ_iterator* t)
const;
664 virtual state* project_state(
const state* s,
665 const const_twa_ptr& t)
const;
668 const acc_cond& acc()
const
678 virtual bool is_empty()
const;
683 void set_num_sets_(
unsigned num)
685 if (num < acc_.num_sets())
688 new (&acc_) acc_cond;
690 acc_.add_sets(num - acc_.num_sets());
694 unsigned num_sets()
const
696 return acc_.num_sets();
699 const acc_cond::acc_code& get_acceptance()
const
701 return acc_.get_acceptance();
704 void set_acceptance(
unsigned num,
const acc_cond::acc_code& c)
707 acc_.set_acceptance(c);
709 prop_state_acc(
true);
713 void copy_acceptance_of(
const const_twa_ptr& a)
716 unsigned num = acc_.num_sets();
718 prop_state_acc(
true);
721 void copy_ap_of(
const const_twa_ptr& a)
723 get_dict()->register_all_propositions_of(a,
this);
724 for (
auto f: a->ap())
725 this->register_ap(f);
728 void set_generalized_buchi(
unsigned num)
731 acc_.set_generalized_buchi();
733 prop_state_acc(
true);
736 acc_cond::mark_t set_buchi()
738 set_generalized_buchi(1);
744 virtual bdd compute_support_conditions(
const state* state)
const = 0;
745 mutable const state* last_support_conditions_input_;
747 mutable bdd last_support_conditions_output_;
748 std::vector<formula> aps_;
757 bool state_based_acc:1;
758 bool inherently_weak:1;
761 bool deterministic:1;
763 bool stutter_invariant:1;
764 bool stutter_sensitive:1;
774 std::unordered_map<std::string,
776 std::function<void(void*)>>> named_prop_;
778 void* get_named_prop_(std::string s)
const;
783 void set_named_prop(std::string s,
784 void* val, std::function<
void(
void*)> destructor);
787 void set_named_prop(std::string s, T* val)
789 set_named_prop(s, val, [](
void *p) {
delete static_cast<T*
>(p); });
793 T* get_named_prop(std::string s)
const
795 void* p = get_named_prop_(s);
798 return static_cast<T*
>(p);
802 void release_named_properties()
805 for (
auto& np: named_prop_)
806 np.second.second(np.second.first);
810 bool prop_state_acc()
const
812 return is.state_based_acc;
815 void prop_state_acc(
bool val)
817 is.state_based_acc = val;
822 return prop_state_acc() && acc().is_buchi();
825 bool prop_inherently_weak()
const
827 return is.inherently_weak;
830 void prop_inherently_weak(
bool val)
832 is.inherently_weak = val;
835 bool prop_terminal()
const
840 void prop_terminal(
bool val)
843 is.inherently_weak = is.weak = is.terminal =
true;
848 bool prop_weak()
const
853 void prop_weak(
bool val)
856 is.inherently_weak = is.weak =
true;
861 bool prop_deterministic()
const
863 return is.deterministic;
866 void prop_deterministic(
bool val)
871 is.deterministic =
true;
872 is.unambiguous =
true;
876 is.deterministic =
false;
880 bool prop_unambiguous()
const
882 return is.unambiguous;
885 void prop_unambiguous(
bool val)
887 is.unambiguous = val;
890 bool prop_stutter_invariant()
const
892 return is.stutter_invariant;
895 bool prop_stutter_sensitive()
const
897 return is.stutter_sensitive;
900 void prop_stutter_invariant(
bool val)
902 is.stutter_invariant = val;
905 void prop_stutter_sensitive(
bool val)
907 is.stutter_sensitive = val;
913 bool inherently_weak;
919 return {
true,
true,
true,
true };
925 void prop_copy(
const const_twa_ptr& other,
prop_set p)
928 prop_state_acc(other->prop_state_acc());
929 if (p.inherently_weak)
931 prop_terminal(other->prop_terminal());
932 prop_weak(other->prop_weak());
933 prop_inherently_weak(other->prop_inherently_weak());
937 prop_deterministic(other->prop_deterministic());
938 prop_unambiguous(other->prop_unambiguous());
942 prop_stutter_invariant(other->prop_stutter_invariant());
943 prop_stutter_sensitive(other->prop_stutter_sensitive());
947 void prop_keep(prop_set p)
950 prop_state_acc(
false);
951 if (!p.inherently_weak)
953 prop_terminal(
false);
955 prop_inherently_weak(
false);
957 if (!p.deterministic)
959 prop_deterministic(
false);
960 prop_unambiguous(
false);
964 prop_stutter_invariant(
false);
965 prop_stutter_sensitive(
false);
virtual ~state()
Destructor.
Definition: twa.hh:100
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:482
Abstract class for states.
Definition: twa.hh:42
Strict Weak Ordering for shared_state (shared_ptr).
Definition: twa.hh:256
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
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 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