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;
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 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_based_acc();
713 void copy_acceptance_of(
const const_twa_ptr& a)
716 unsigned num = acc_.num_sets();
718 prop_state_based_acc();
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_based_acc();
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;
759 bool deterministic:1;
761 bool stutter_invariant:1;
762 bool stutter_sensitive:1;
772 std::unordered_map<std::string,
774 std::function<void(void*)>>> named_prop_;
776 void* get_named_prop_(std::string s)
const;
781 void set_named_prop(std::string s,
782 void* val, std::function<
void(
void*)> destructor);
785 void set_named_prop(std::string s, T* val)
787 set_named_prop(s, val, [](
void *p) {
delete static_cast<T*
>(p); });
791 T* get_named_prop(std::string s)
const
793 void* p = get_named_prop_(s);
796 return static_cast<T*
>(p);
800 void release_named_properties()
803 for (
auto& np: named_prop_)
804 np.second.second(np.second.first);
808 bool has_state_based_acc()
const
810 return is.state_based_acc;
813 void prop_state_based_acc(
bool val =
true)
815 is.state_based_acc = val;
820 return has_state_based_acc() && acc().is_buchi();
823 bool is_inherently_weak()
const
825 return is.inherently_weak;
828 void prop_inherently_weak(
bool val =
true)
830 is.inherently_weak = val;
835 return is.deterministic;
838 void prop_deterministic(
bool val =
true)
840 is.deterministic = val;
845 return is.unambiguous;
848 void prop_unambiguous(
bool val =
true)
850 is.unambiguous = val;
853 bool is_stutter_invariant()
const
855 return is.stutter_invariant;
858 bool is_stutter_sensitive()
const
860 return is.stutter_sensitive;
863 void prop_stutter_invariant(
bool val =
true)
865 is.stutter_invariant = val;
868 void prop_stutter_sensitive(
bool val =
true)
870 is.stutter_sensitive = val;
876 bool inherently_weak;
882 return {
true,
true,
true,
true };
888 void prop_copy(
const const_twa_ptr& other,
prop_set p)
891 prop_state_based_acc(other->has_state_based_acc());
892 if (p.inherently_weak)
893 prop_inherently_weak(other->is_inherently_weak());
896 prop_deterministic(other->is_deterministic());
897 prop_unambiguous(other->is_unambiguous());
901 prop_stutter_invariant(other->is_stutter_invariant());
902 prop_stutter_sensitive(other->is_stutter_sensitive());
906 void prop_keep(prop_set p)
909 prop_state_based_acc(
false);
910 if (!p.inherently_weak)
911 prop_inherently_weak(
false);
912 if (!p.deterministic)
914 prop_deterministic(
false);
915 prop_unambiguous(
false);
919 prop_stutter_invariant(
false);
920 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: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
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 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