22 #include <spot/twa/fwd.hh>
23 #include <spot/graph/graph.hh>
24 #include <spot/graph/ngraph.hh>
25 #include <spot/twa/bdddict.hh>
26 #include <spot/twa/twa.hh>
27 #include <spot/twaalgos/copy.hh>
58 virtual size_t hash()
const override
61 reinterpret_cast<const char*
>(
this) - static_cast<const char*>(
nullptr);
81 : cond(bddfalse), acc(0)
86 : cond(cond), acc(acc)
92 if (cond.id() < other.cond.id())
94 if (cond.id() > other.cond.id())
96 return acc < other.acc;
101 return cond.id() == other.cond.id() &&
107 template<
class Graph>
112 typedef typename Graph::edge edge;
113 typedef typename Graph::state_data_t state;
137 p_ = g_->edge_storage(p_).next_succ;
141 virtual bool done()
const override
149 return &g_->state_data(g_->edge_storage(p_).dst);
152 virtual bdd
cond()
const override
155 return g_->edge_data(p_).cond;
161 return g_->edge_data(p_).acc;
179 typedef unsigned state_num;
180 static_assert(std::is_same<typename graph_t::state, state_num>::value,
185 mutable unsigned init_number_;
195 :
twa(other->get_dict()),
196 g_(other->g_), init_number_(other->init_number_)
198 copy_acceptance_of(other);
208 template <
typename State_Name,
209 typename Name_Hash = std::hash<State_Name>,
210 typename Name_Equal = std::equal_to<State_Name>>
213 template <
typename State_Name,
214 typename Name_Hash = std::hash<State_Name>,
215 typename Name_Equal = std::equal_to<State_Name>>
216 namer<State_Name, Name_Hash, Name_Equal>*
223 create_formula_namer()
225 return create_namer<formula>();
229 release_formula_namer(namer<formula>* namer,
bool keep_names);
237 const graph_t& get_graph()
const
242 unsigned num_states()
const
247 unsigned num_edges()
const
252 void set_init_state(state_num s)
254 assert(s < num_states());
258 void set_init_state(
const state* s)
260 set_init_state(state_number(s));
263 state_num get_init_state_number()
const
265 if (num_states() == 0)
266 const_cast<graph_t&
>(g_).new_state();
272 if (num_states() == 0)
273 const_cast<graph_t&
>(g_).new_state();
274 return state_from_number(init_number_);
278 succ_iter(
const state* st)
const override
284 if (this->iter_cache_)
288 it->recycle(s->succ);
289 this->iter_cache_ =
nullptr;
296 state_number(
const state* st)
const
304 state_from_number(state_num n)
const
309 std::string format_state(
unsigned n)
const
311 std::stringstream ss;
316 virtual std::string format_state(
const state* st)
const override
318 return format_state(state_number(st));
349 edge_storage_t& edge_storage(
unsigned t)
361 const edge_storage_t edge_storage(
unsigned t)
const
371 unsigned new_states(
unsigned n)
376 unsigned new_edge(
unsigned src,
unsigned dst,
379 return g_.
new_edge(src, dst, cond, acc);
382 unsigned new_acc_edge(
unsigned src,
unsigned dst,
383 bdd cond,
bool acc =
true)
386 return g_.
new_edge(src, dst, cond, this->acc().all_sets());
393 out(
unsigned src)
const
425 auto edge_vector()
const
439 void purge_dead_states();
442 void purge_unreachable_states();
448 void remove_unused_ap();
452 assert((
bool)prop_state_acc() || num_sets() == 0);
453 for (
auto& t: g_.
out(s))
460 bool state_is_accepting(
unsigned s)
const
462 assert((
bool)prop_state_acc() || num_sets() == 0);
463 for (
auto& t: g_.
out(s))
466 return acc().accepting(t.acc);
470 bool state_is_accepting(
const state* s)
const
472 return state_is_accepting(state_number(s));
475 bool operator==(
const twa_graph& aut)
const
477 if (num_states() != aut.num_states() ||
478 num_edges() != aut.num_edges() ||
481 auto& trans1 = edge_vector();
482 auto& trans2 = aut.edge_vector();
483 return std::equal(trans1.begin() + 1, trans1.end(),
487 void defrag_states(std::vector<unsigned>&& newst,
unsigned used_states);
490 inline twa_graph_ptr make_twa_graph(
const bdd_dict_ptr& dict)
492 return std::make_shared<twa_graph>(dict);
495 inline twa_graph_ptr make_twa_graph(
const twa_graph_ptr& aut,
498 return std::make_shared<twa_graph>(aut, p);
501 inline twa_graph_ptr make_twa_graph(
const const_twa_graph_ptr& aut,
504 return std::make_shared<twa_graph>(aut, p);
507 inline twa_graph_ptr make_twa_graph(
const const_twa_ptr& aut,
510 auto a = std::dynamic_pointer_cast<
const twa_graph>(aut);
512 return std::make_shared<twa_graph>(a, p);
unsigned num_edges() const
The number of edges in the automaton.
Definition: graph.hh:639
edge_storage_t & edge_storage(edge s)
return a reference to the storage of an edge
Definition: graph.hh:719
virtual void destroy() const override
Release a state.
Definition: twagraph.hh:70
edge_storage_t::data_t & edge_data(edge s)
return the Edgeg_Data of an edge.
Definition: graph.hh:739
state new_state(Args &&...args)
Create a new states.
Definition: graph.hh:650
unsigned num_states() const
The number of states in the automaton.
Definition: graph.hh:631
A Transition-based ω-Automaton.
Definition: twa.hh:577
internal::state_out< digraph > out(state src)
Return a fake container with all edges leaving src.
Definition: graph.hh:794
Abstract class for states.
Definition: twa.hh:43
virtual size_t hash() const override
Hash a state.
Definition: twagraph.hh:58
const state_vector & states() const
Return the vector of states.
Definition: graph.hh:838
bool is_dead_edge(unsigned t) const
Tests whether an edge has been erased.
Definition: graph.hh:901
twa_graph_ptr copy(const const_twa_ptr &aut, twa::prop_set p, bool preserve_names=false, unsigned max_states=-1U)
Build an explicit automaton from all states of aut,.
virtual bool first() override
Position the iterator on the first successor (if any).
Definition: twagraph.hh:129
Iterate over the successors of a state.
Definition: twa.hh:390
virtual bdd cond() const override
Get the condition on the edge leading to this successor.
Definition: twagraph.hh:152
const edge_vector_t & edge_vector() const
Return the vector of all edges.
Definition: graph.hh:872
virtual bool done() const override
Check whether the iteration is finished.
Definition: twagraph.hh:141
virtual int compare(const spot::state *other) const override
Compares two states (that come from the same automaton).
Definition: twagraph.hh:45
virtual const twa_graph_state * dst() const override
Get the destination state of the current edge.
Definition: twagraph.hh:146
A structure for selecting a set of automaton properties to copy.
Definition: twa.hh:1248
unsigned num_sets() const
Number of acceptance sets used by the automaton.
Definition: twa.hh:841
state new_states(unsigned n, Args &&...args)
Create n new states.
Definition: graph.hh:664
virtual acc_cond::mark_t acc() const override
Get the acceptance mark of the edge leading to this successor.
Definition: twagraph.hh:158
internal::all_trans< const digraph > edges() const
Return a fake container with all edges (exluding erased edges)
Definition: graph.hh:853
bool is_valid_edge(edge t) const
Test whether the given edge is valid.
Definition: graph.hh:889
edge new_edge(state src, out_state dst, Args &&...args)
Create a new edge.
Definition: graph.hh:760
Definition: twagraph.hh:108
A directed graph.
Definition: graph.hh:35
state_storage_t & state_storage(state s)
return a reference to the storage of a state
Definition: graph.hh:679
Definition: twagraph.hh:171
Definition: twagraph.hh:34
virtual bool next() override
Jump to the next successor (if any).
Definition: twagraph.hh:135
state_storage_t::data_t & state_data(state s)
return the State_Data associated to a state
Definition: graph.hh:699
Definition: twagraph.hh:75
virtual twa_graph_state * clone() const override
Duplicate a state.
Definition: twagraph.hh:65