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
148 SPOT_ASSERT(!done());
149 return &g_->state_data(g_->edge_storage(p_).dst);
152 virtual bdd
cond()
const override
154 SPOT_ASSERT(!done());
155 return g_->edge_data(p_).cond;
160 SPOT_ASSERT(!done());
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 if (SPOT_UNLIKELY(s >= num_states()))
255 throw std::invalid_argument
256 (
"set_init_state() called with nonexisiting state");
260 void set_init_state(
const state* s)
262 set_init_state(state_number(s));
265 state_num get_init_state_number()
const
267 if (num_states() == 0)
268 const_cast<graph_t&
>(g_).new_state();
274 if (num_states() == 0)
275 const_cast<graph_t&
>(g_).new_state();
276 return state_from_number(init_number_);
280 succ_iter(
const state* st)
const override
286 if (this->iter_cache_)
290 it->recycle(s->succ);
291 this->iter_cache_ =
nullptr;
298 state_number(
const state* st)
const
306 state_from_number(state_num n)
const
311 std::string format_state(
unsigned n)
const
313 std::stringstream ss;
318 virtual std::string format_state(
const state* st)
const override
320 return format_state(state_number(st));
354 edge_storage_t& edge_storage(
unsigned t)
365 const edge_storage_t edge_storage(
unsigned t)
const
375 unsigned new_states(
unsigned n)
380 unsigned new_edge(
unsigned src,
unsigned dst,
383 return g_.
new_edge(src, dst, cond, acc);
386 unsigned new_acc_edge(
unsigned src,
unsigned dst,
387 bdd cond,
bool acc =
true)
390 return g_.
new_edge(src, dst, cond, this->acc().all_sets());
397 out(
unsigned src)
const
429 auto edge_vector()
const
443 void purge_dead_states();
446 void purge_unreachable_states();
452 void remove_unused_ap();
456 if (SPOT_UNLIKELY(!((
bool)prop_state_acc() || num_sets() == 0)))
457 throw std::runtime_error
458 (
"state_acc_sets() should only be called on "
459 "automata with state-based acceptance");
461 for (
auto& t: g_.
out(s))
468 bool state_is_accepting(
unsigned s)
const
470 if (SPOT_UNLIKELY(!((
bool)prop_state_acc() || num_sets() == 0)))
471 throw std::runtime_error
472 (
"state_is_accepting() should only be called on "
473 "automata with state-based acceptance");
474 for (
auto& t: g_.
out(s))
477 return acc().accepting(t.acc);
481 bool state_is_accepting(
const state* s)
const
483 return state_is_accepting(state_number(s));
486 bool operator==(
const twa_graph& aut)
const
488 if (num_states() != aut.num_states() ||
489 num_edges() != aut.num_edges() ||
492 auto& trans1 = edge_vector();
493 auto& trans2 = aut.edge_vector();
494 return std::equal(trans1.begin() + 1, trans1.end(),
498 void defrag_states(std::vector<unsigned>&& newst,
unsigned used_states);
501 inline twa_graph_ptr make_twa_graph(
const bdd_dict_ptr& dict)
503 return std::make_shared<twa_graph>(dict);
506 inline twa_graph_ptr make_twa_graph(
const twa_graph_ptr& aut,
509 return std::make_shared<twa_graph>(aut, p);
512 inline twa_graph_ptr make_twa_graph(
const const_twa_graph_ptr& aut,
515 return std::make_shared<twa_graph>(aut, p);
518 inline twa_graph_ptr make_twa_graph(
const const_twa_ptr& aut,
521 auto a = std::dynamic_pointer_cast<
const twa_graph>(aut);
523 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:715
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:733
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:621
internal::state_out< digraph > out(state src)
Return a fake container with all edges leaving src.
Definition: graph.hh:784
Abstract class for states.
Definition: twa.hh:50
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:828
bool is_dead_edge(unsigned t) const
Tests whether an edge has been erased.
Definition: graph.hh:891
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:397
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:862
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:1317
unsigned num_sets() const
Number of acceptance sets used by the automaton.
Definition: twa.hh:863
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:843
bool is_valid_edge(edge t) const
Test whether the given edge is valid.
Definition: graph.hh:879
edge new_edge(state src, out_state dst, Args &&...args)
Create a new edge.
Definition: graph.hh:752
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:697
Definition: twagraph.hh:75
virtual twa_graph_state * clone() const override
Duplicate a state.
Definition: twagraph.hh:65