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;
149 return &g_->state_data(g_->edge_storage(p_).dst);
155 return g_->edge_data(p_).cond;
161 return g_->edge_data(p_).acc;
179 mutable unsigned init_number_;
189 :
twa(other->get_dict()),
190 g_(other->g_), init_number_(other->init_number_)
192 copy_acceptance_of(other);
199 get_dict()->unregister_all_my_variables(
this);
202 last_support_conditions_input_ =
nullptr;
206 template <
typename State_Name,
207 typename Name_Hash = std::hash<State_Name>,
208 typename Name_Equal = std::equal_to<State_Name>>
211 template <
typename State_Name,
212 typename Name_Hash = std::hash<State_Name>,
213 typename Name_Equal = std::equal_to<State_Name>>
221 create_formula_namer()
223 return create_namer<formula>();
235 const graph_t& get_graph()
const
240 unsigned num_states()
const
242 return g_.num_states();
245 unsigned num_edges()
const
247 return g_.num_edges();
250 void set_init_state(graph_t::state s)
252 assert(s < num_states());
256 void set_init_state(
const state* s)
258 set_init_state(state_number(s));
261 graph_t::state get_init_state_number()
const
263 if (num_states() == 0)
264 const_cast<graph_t&
>(g_).new_state();
270 if (num_states() == 0)
271 const_cast<graph_t&
>(g_).new_state();
272 return state_from_number(init_number_);
280 assert(!s->succ || g_.valid_trans(s->succ));
282 if (this->iter_cache_)
286 it->recycle(s->succ);
287 this->iter_cache_ =
nullptr;
294 state_number(
const state* st)
const
296 auto s = down_cast<
const typename graph_t::state_storage_t*>(st);
298 return s - &g_.state_storage(0);
301 const twa_graph_state*
302 state_from_number(graph_t::state n)
const
304 return &g_.state_data(n);
307 std::string format_state(
unsigned n)
const
309 std::stringstream ss;
314 virtual std::string format_state(
const state* st)
const
316 return format_state(state_number(st));
319 twa_graph_edge_data& edge_data(
const twa_succ_iterator* it)
321 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
322 return g_.edge_data(i->pos());
325 twa_graph_edge_data& edge_data(
unsigned t)
327 return g_.edge_data(t);
330 const twa_graph_edge_data& edge_data(
const twa_succ_iterator* it)
const
332 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
333 return g_.edge_data(i->pos());
336 const twa_graph_edge_data& edge_data(
unsigned t)
const
338 return g_.edge_data(t);
341 edge_storage_t& edge_storage(
const twa_succ_iterator* it)
343 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
344 return g_.edge_storage(i->pos());
347 edge_storage_t& edge_storage(
unsigned t)
349 return g_.edge_storage(t);
353 edge_storage(
const twa_succ_iterator* it)
const
355 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
356 return g_.edge_storage(i->pos());
359 const edge_storage_t edge_storage(
unsigned t)
const
361 return g_.edge_storage(t);
366 return g_.new_state();
369 unsigned new_states(
unsigned n)
371 return g_.new_states(n);
374 unsigned new_edge(
unsigned src,
unsigned dst,
375 bdd cond, acc_cond::mark_t acc = 0
U)
377 return g_.new_edge(src, dst, cond, acc);
380 unsigned new_acc_edge(
unsigned src,
unsigned dst,
381 bdd cond,
bool acc =
true)
384 return g_.new_edge(src, dst, cond, acc_.all_sets());
386 return g_.new_edge(src, dst, cond);
390 auto out(
unsigned src)
const
391 SPOT_RETURN(g_.out(src));
392 auto out(
unsigned src)
393 SPOT_RETURN(g_.out(src));
396 SPOT_RETURN(g_.states());
398 SPOT_RETURN(g_.states());
401 SPOT_RETURN(g_.edges());
403 SPOT_RETURN(g_.edges());
405 auto edge_vector() const
406 SPOT_RETURN(g_.edge_vector());
408 SPOT_RETURN(g_.edge_vector());
410 auto is_dead_edge(const graph_t::edge_storage_t& t) const
411 SPOT_RETURN(g_.is_dead_edge(t));
414 virtual bdd compute_support_conditions(
const state* s)
const
417 for (
auto& t: out(state_number(s)))
427 void purge_dead_states();
430 void purge_unreachable_states();
432 acc_cond::mark_t state_acc_sets(
unsigned s)
const
434 assert(prop_state_acc() || num_sets() == 0);
435 for (
auto& t: g_.out(s))
442 bool state_is_accepting(
unsigned s)
const
444 assert(prop_state_acc() || num_sets() == 0);
445 for (
auto& t: g_.out(s))
448 return acc_.accepting(t.acc);
452 bool state_is_accepting(
const state* s)
const
454 return state_is_accepting(state_number(s));
457 bool operator==(
const twa_graph& aut)
const
459 if (num_states() != aut.num_states() ||
460 num_edges() != aut.num_edges() ||
461 num_sets() != aut.num_sets())
463 auto& trans1 = edge_vector();
464 auto& trans2 = aut.edge_vector();
465 return std::equal(trans1.begin() + 1, trans1.end(),
470 inline twa_graph_ptr make_twa_graph(
const bdd_dict_ptr& dict)
472 return std::make_shared<twa_graph>(dict);
475 inline twa_graph_ptr make_twa_graph(
const twa_graph_ptr& aut,
478 return std::make_shared<twa_graph>(aut, p);
481 inline twa_graph_ptr make_twa_graph(
const const_twa_graph_ptr& aut,
484 return std::make_shared<twa_graph>(aut, p);
487 inline twa_graph_ptr make_twa_graph(
const const_twa_ptr& aut,
490 auto a = std::dynamic_pointer_cast<
const twa_graph>(aut);
492 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:276
A Transition-based ω-Automaton.
Definition: twa.hh:482
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 acc_cond::mark_t acc() const
Get the acceptance conditions on the transition leading to this successor.
Definition: twagraph.hh:158
virtual const twa_graph_state * dst() const
Get the state of the current successor.
Definition: twagraph.hh:146
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 void destroy() const
Release a state.
Definition: twagraph.hh:70
virtual const twa_graph_state * get_init_state() const
Get the initial state of the automaton.
Definition: twagraph.hh:268
Definition: twagraph.hh:108
virtual bdd cond() const
Get the condition on the transition leading to this successor.
Definition: twagraph.hh:152
Definition: twagraph.hh:171
Definition: twagraph.hh:34
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,.