25 #include <spot/twa/fwd.hh>
26 #include <spot/twa/acc.hh>
27 #include <spot/twa/bdddict.hh>
30 #include <unordered_map>
34 #include <spot/misc/casts.hh>
35 #include <spot/misc/hash.hh>
37 #include <spot/misc/trival.hh>
56 virtual int compare(
const state* other)
const = 0;
77 virtual size_t hash()
const = 0;
80 virtual state* clone()
const = 0;
121 operator()(
const state* left,
const state* right)
const
124 return left->
compare(right) < 0;
144 operator()(
const state* left,
const state* right)
const
147 return 0 == left->
compare(right);
168 operator()(
const state* that)
const
175 typedef std::unordered_set<
const state*,
196 auto p = m.insert(s);
208 auto p = m.insert(s);
219 for (state_set::iterator i = m.begin(); i != m.end();)
223 state_set::iterator old = i++;
240 typedef std::shared_ptr<const state> shared_state;
242 inline void shared_state_deleter(state* s) { s->destroy(); }
260 operator()(shared_state left,
261 shared_state right)
const
264 return left->compare(right.get()) < 0;
286 operator()(shared_state left,
287 shared_state right)
const
290 return 0 == left->compare(right.get());
313 operator()(shared_state that)
const
320 typedef std::unordered_set<shared_state,
354 virtual bool first() = 0;
362 virtual bool next() = 0;
373 virtual bool done()
const = 0;
389 virtual const state* dst()
const = 0;
393 virtual bdd cond()
const = 0;
483 class SPOT_API
twa:
public std::enable_shared_from_this<twa>
486 twa(
const bdd_dict_ptr& d);
505 : aut_(other.aut_), it_(other.it_)
513 aut_->release_iter(it_);
518 return it_->
first() ? it_ :
nullptr;
535 virtual const state* get_init_state()
const = 0;
543 succ_iter(
const state* local_state)
const = 0;
551 succ(
const state* s)
const
553 return {
this, succ_iter(s)};
561 void release_iter(twa_succ_iterator* i)
const
582 bdd support_conditions(
const state* state)
const;
591 bdd_dict_ptr get_dict()
const
599 int register_ap(formula
ap)
601 int res = dict_->has_registered_proposition(ap,
this);
605 res = dict_->register_proposition(ap,
this);
606 bddaps_ &= bdd_ithvar(res);
614 int register_ap(std::string name)
621 const std::vector<formula>&
ap()
const
635 virtual std::string format_state(
const state* state)
const = 0;
654 transition_annotation(
const twa_succ_iterator* t)
const;
669 virtual state* project_state(
const state* s,
670 const const_twa_ptr& t)
const;
673 const acc_cond& acc()
const
683 virtual bool is_empty()
const;
688 void set_num_sets_(
unsigned num)
690 if (num < acc_.num_sets())
693 new (&acc_) acc_cond;
695 acc_.add_sets(num - acc_.num_sets());
699 unsigned num_sets()
const
701 return acc_.num_sets();
704 const acc_cond::acc_code& get_acceptance()
const
706 return acc_.get_acceptance();
709 void set_acceptance(
unsigned num,
const acc_cond::acc_code& c)
712 acc_.set_acceptance(c);
714 prop_state_acc(
true);
718 void copy_acceptance_of(
const const_twa_ptr& a)
721 unsigned num = acc_.num_sets();
723 prop_state_acc(
true);
726 void copy_ap_of(
const const_twa_ptr& a)
728 for (
auto f: a->ap())
729 this->register_ap(f);
732 void set_generalized_buchi(
unsigned num)
735 acc_.set_generalized_buchi();
737 prop_state_acc(
true);
740 acc_cond::mark_t set_buchi()
742 set_generalized_buchi(1);
748 virtual bdd compute_support_conditions(
const state* state)
const = 0;
749 mutable const state* last_support_conditions_input_;
751 mutable bdd last_support_conditions_output_;
752 std::vector<formula> aps_;
761 trival::repr_t state_based_acc:2;
762 trival::repr_t inherently_weak:2;
763 trival::repr_t weak:2;
764 trival::repr_t terminal:2;
765 trival::repr_t deterministic:2;
766 trival::repr_t unambiguous:2;
767 trival::repr_t stutter_invariant:2;
777 std::unordered_map<std::string,
779 std::function<void(void*)>>> named_prop_;
781 void* get_named_prop_(std::string s)
const;
786 void set_named_prop(std::string s,
787 void* val, std::function<
void(
void*)> destructor);
790 void set_named_prop(std::string s, T* val)
792 set_named_prop(s, val, [](
void *p) {
delete static_cast<T*
>(p); });
796 T* get_named_prop(std::string s)
const
798 void* p = get_named_prop_(s);
801 return static_cast<T*
>(p);
805 void release_named_properties()
808 for (
auto& np: named_prop_)
809 np.second.second(np.second.first);
813 trival prop_state_acc()
const
815 return is.state_based_acc;
818 void prop_state_acc(trival val)
820 is.state_based_acc = val.val();
823 trival is_sba()
const
825 return prop_state_acc() && acc().is_buchi();
828 trival prop_inherently_weak()
const
830 return is.inherently_weak;
833 void prop_inherently_weak(trival val)
835 is.inherently_weak = val.val();
837 is.terminal = is.weak = val.val();
840 trival prop_terminal()
const
845 void prop_terminal(trival val)
847 is.terminal = val.val();
849 is.inherently_weak = is.weak = val.val();
852 trival prop_weak()
const
857 void prop_weak(trival val)
861 is.inherently_weak = val.val();
863 is.terminal = val.val();
866 trival prop_deterministic()
const
868 return is.deterministic;
871 void prop_deterministic(trival val)
873 is.deterministic = val.val();
876 is.unambiguous = val.val();
879 trival prop_unambiguous()
const
881 return is.unambiguous;
884 void prop_unambiguous(trival val)
886 is.unambiguous = val.val();
888 is.deterministic = val.val();
891 trival prop_stutter_invariant()
const
893 return is.stutter_invariant;
896 void prop_stutter_invariant(trival val)
898 is.stutter_invariant = val.val();
904 bool inherently_weak;
910 return {
true,
true,
true,
true };
916 void prop_copy(
const const_twa_ptr& other,
prop_set p)
919 prop_state_acc(other->prop_state_acc());
920 if (p.inherently_weak)
922 prop_terminal(other->prop_terminal());
923 prop_weak(other->prop_weak());
924 prop_inherently_weak(other->prop_inherently_weak());
928 prop_deterministic(other->prop_deterministic());
929 prop_unambiguous(other->prop_unambiguous());
932 prop_stutter_invariant(other->prop_stutter_invariant());
935 void prop_keep(prop_set p)
938 prop_state_acc(trival::maybe());
939 if (!p.inherently_weak)
941 prop_terminal(trival::maybe());
942 prop_weak(trival::maybe());
943 prop_inherently_weak(trival::maybe());
945 if (!p.deterministic)
947 prop_deterministic(trival::maybe());
948 prop_unambiguous(trival::maybe());
951 prop_stutter_invariant(trival::maybe());
virtual ~state()
Destructor.
Definition: twa.hh:101
An Equivalence Relation for state*.
Definition: twa.hh:141
Render state pointers unique via a hash table.
Definition: twa.hh:181
A Transition-based ω-Automaton.
Definition: twa.hh:483
Abstract class for states.
Definition: twa.hh:43
Strict Weak Ordering for shared_state (shared_ptr).
Definition: twa.hh:257
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:91
Hash Function for shared_state (shared_ptr).
Definition: twa.hh:310
Iterate over the successors of a state.
Definition: twa.hh:332
const state * operator()(const state *s)
Canonicalize state pointer.
Definition: twa.hh:194
const state * is_new(const state *s)
Canonicalize state pointer.
Definition: twa.hh:206
Hash Function for state*.
Definition: twa.hh:165
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:118
An Equivalence Relation for shared_state (shared_ptr).
Definition: twa.hh:283