23 #include "graph/graph.hh"
24 #include "graph/ngraph.hh"
25 #include "twa/bdddict.hh"
27 #include "twaalgos/copy.hh"
58 virtual size_t hash()
const
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;
124 virtual void recycle(edge t)
137 p_ = g_->edge_storage(p_).next_succ;
150 (&g_->state_data(g_->edge_storage(p_).dst));
156 return g_->edge_data(p_).cond;
162 return g_->edge_data(p_).acc;
180 mutable unsigned init_number_;
190 :
twa(other->get_dict()),
191 g_(other->g_), init_number_(other->init_number_)
193 copy_acceptance_of(other);
200 get_dict()->unregister_all_my_variables(
this);
203 last_support_conditions_input_ =
nullptr;
207 template <
typename State_Name,
208 typename Name_Hash = std::hash<State_Name>,
209 typename Name_Equal = std::equal_to<State_Name>>
212 template <
typename State_Name,
213 typename Name_Hash = std::hash<State_Name>,
214 typename Name_Equal = std::equal_to<State_Name>>
222 create_formula_namer()
224 return create_namer<formula>();
236 const graph_t& get_graph()
const
241 unsigned num_states()
const
243 return g_.num_states();
246 unsigned num_edges()
const
248 return g_.num_edges();
251 void set_init_state(graph_t::state s)
253 assert(s < num_states());
257 void set_init_state(
const state* s)
259 set_init_state(state_number(s));
262 graph_t::state get_init_state_number()
const
264 if (num_states() == 0)
265 const_cast<graph_t&
>(g_).new_state();
272 if (num_states() == 0)
273 const_cast<graph_t&
>(g_).new_state();
282 assert(!s->succ || g_.valid_trans(s->succ));
284 if (this->iter_cache_)
288 it->recycle(s->succ);
289 this->iter_cache_ =
nullptr;
296 state_number(
const state* st)
const
298 auto s = down_cast<
const typename graph_t::state_storage_t*>(st);
300 return s - &g_.state_storage(0);
303 const twa_graph_state*
304 state_from_number(graph_t::state n)
const
306 return &g_.state_data(n);
309 std::string format_state(
unsigned n)
const
311 std::stringstream ss;
316 virtual std::string format_state(
const state* st)
const
318 return format_state(state_number(st));
321 twa_graph_edge_data& edge_data(
const twa_succ_iterator* it)
323 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
324 return g_.edge_data(i->pos());
327 twa_graph_edge_data& edge_data(
unsigned t)
329 return g_.edge_data(t);
332 const twa_graph_edge_data& edge_data(
const twa_succ_iterator* it)
const
334 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
335 return g_.edge_data(i->pos());
338 const twa_graph_edge_data& edge_data(
unsigned t)
const
340 return g_.edge_data(t);
343 edge_storage_t& edge_storage(
const twa_succ_iterator* it)
345 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
346 return g_.edge_storage(i->pos());
349 edge_storage_t& edge_storage(
unsigned t)
351 return g_.edge_storage(t);
355 edge_storage(
const twa_succ_iterator* it)
const
357 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
358 return g_.edge_storage(i->pos());
361 const edge_storage_t edge_storage(
unsigned t)
const
363 return g_.edge_storage(t);
368 return g_.new_state();
371 unsigned new_states(
unsigned n)
373 return g_.new_states(n);
376 unsigned new_edge(
unsigned src,
unsigned dst,
377 bdd cond, acc_cond::mark_t acc = 0
U)
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, acc_.all_sets());
388 return g_.new_edge(src, dst, cond);
392 auto out(
unsigned src)
const
393 SPOT_RETURN(g_.out(src));
394 auto out(
unsigned src)
395 SPOT_RETURN(g_.out(src));
398 SPOT_RETURN(g_.states());
400 SPOT_RETURN(g_.states());
403 SPOT_RETURN(g_.edges());
405 SPOT_RETURN(g_.edges());
407 auto edge_vector() const
408 SPOT_RETURN(g_.edge_vector());
410 SPOT_RETURN(g_.edge_vector());
412 auto is_dead_edge(const graph_t::edge_storage_t& t) const
413 SPOT_RETURN(g_.is_dead_edge(t));
416 virtual bdd compute_support_conditions(
const state* s)
const
419 for (
auto& t: out(state_number(s)))
429 void purge_dead_states();
432 void purge_unreachable_states();
434 acc_cond::mark_t state_acc_sets(
unsigned s)
const
436 assert(has_state_based_acc() || num_sets() == 0);
437 for (
auto& t: g_.out(s))
444 bool state_is_accepting(
unsigned s)
const
446 assert(has_state_based_acc() || num_sets() == 0);
447 for (
auto& t: g_.out(s))
450 return acc_.accepting(t.acc);
454 bool state_is_accepting(
const state* s)
const
456 return state_is_accepting(state_number(s));
459 bool operator==(
const twa_graph& aut)
const
461 if (num_states() != aut.num_states() ||
462 num_edges() != aut.num_edges() ||
463 num_sets() != aut.num_sets())
465 auto& trans1 = edge_vector();
466 auto& trans2 = aut.edge_vector();
467 return std::equal(trans1.begin() + 1, trans1.end(),
472 inline twa_graph_ptr make_twa_graph(
const bdd_dict_ptr& dict)
474 return std::make_shared<twa_graph>(dict);
477 inline twa_graph_ptr make_twa_graph(
const twa_graph_ptr& aut,
480 return std::make_shared<twa_graph>(aut, p);
483 inline twa_graph_ptr make_twa_graph(
const const_twa_graph_ptr& aut,
486 return std::make_shared<twa_graph>(aut, p);
489 inline twa_graph_ptr make_twa_graph(
const const_twa_ptr& aut,
492 auto a = std::dynamic_pointer_cast<
const twa_graph>(aut);
494 return std::make_shared<twa_graph>(a, p);
virtual twa_graph_state * clone() const
Duplicate a state.
Definition: twagraph.hh:65
virtual bool done() const
Check whether the iteration is finished.
Definition: twagraph.hh:141
virtual int compare(const spot::state *other) const
Compares two states (that come from the same automaton).
Definition: twagraph.hh:45
virtual twa_succ_iterator * succ_iter(const state *st) const
Get an iterator over the successors of local_state.
Definition: twagraph.hh:278
A Transition-based ω-Automaton.
Definition: twa.hh:494
Abstract class for states.
Definition: twa.hh:42
virtual bool first()
Position the iterator on the first successor (if any).
Definition: twagraph.hh:129
virtual size_t hash() const
Hash a state.
Definition: twagraph.hh:58
virtual twa_graph_state * current_state() const
Get the state of the current successor.
Definition: twagraph.hh:146
virtual bdd current_condition() const
Get the condition on the transition leading to this successor.
Definition: twagraph.hh:153
virtual bool next()
Jump to the next successor (if any).
Definition: twagraph.hh:135
Iterate over the successors of a state.
Definition: twa.hh:331
virtual twa_graph_state * get_init_state() const
Get the initial state of the automaton.
Definition: twagraph.hh:270
virtual void destroy() const
Release a state.
Definition: twagraph.hh:70
Definition: twagraph.hh:108
Definition: twagraph.hh:172
Definition: twagraph.hh:34
virtual acc_cond::mark_t current_acceptance_conditions() const
Get the acceptance conditions on the transition leading to this successor.
Definition: twagraph.hh:159
Definition: twagraph.hh:75
twa_graph_ptr copy(const const_twa_ptr &aut, twa::prop_set p, bool preserve_names=false)
Build an explicit automaton from all states of aut,.