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
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 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);
207 last_support_conditions_input_ =
nullptr;
211 template <
typename State_Name,
212 typename Name_Hash = std::hash<State_Name>,
213 typename Name_Equal = std::equal_to<State_Name>>
216 template <
typename State_Name,
217 typename Name_Hash = std::hash<State_Name>,
218 typename Name_Equal = std::equal_to<State_Name>>
226 create_formula_namer()
228 return create_namer<formula>();
240 const graph_t& get_graph()
const
245 unsigned num_states()
const
247 return g_.num_states();
250 unsigned num_edges()
const
252 return g_.num_edges();
255 void set_init_state(state_num s)
257 assert(s < num_states());
261 void set_init_state(
const state* s)
263 set_init_state(state_number(s));
266 state_num get_init_state_number()
const
268 if (num_states() == 0)
269 const_cast<graph_t&
>(g_).new_state();
275 if (num_states() == 0)
276 const_cast<graph_t&
>(g_).new_state();
277 return state_from_number(init_number_);
285 assert(!s->succ || g_.valid_trans(s->succ));
287 if (this->iter_cache_)
291 it->recycle(s->succ);
292 this->iter_cache_ =
nullptr;
299 state_number(
const state* st)
const
301 auto s = down_cast<
const typename graph_t::state_storage_t*>(st);
303 return s - &g_.state_storage(0);
306 const twa_graph_state*
307 state_from_number(state_num n)
const
309 return &g_.state_data(n);
312 std::string format_state(
unsigned n)
const
314 std::stringstream ss;
319 virtual std::string format_state(
const state* st)
const
321 return format_state(state_number(st));
324 twa_graph_edge_data& edge_data(
const twa_succ_iterator* it)
326 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
327 return g_.edge_data(i->pos());
330 twa_graph_edge_data& edge_data(
unsigned t)
332 return g_.edge_data(t);
335 const twa_graph_edge_data& edge_data(
const twa_succ_iterator* it)
const
337 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
338 return g_.edge_data(i->pos());
341 const twa_graph_edge_data& edge_data(
unsigned t)
const
343 return g_.edge_data(t);
346 edge_storage_t& edge_storage(
const twa_succ_iterator* it)
348 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
349 return g_.edge_storage(i->pos());
352 edge_storage_t& edge_storage(
unsigned t)
354 return g_.edge_storage(t);
358 edge_storage(
const twa_succ_iterator* it)
const
360 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
361 return g_.edge_storage(i->pos());
364 const edge_storage_t edge_storage(
unsigned t)
const
366 return g_.edge_storage(t);
371 return g_.new_state();
374 unsigned new_states(
unsigned n)
376 return g_.new_states(n);
379 unsigned new_edge(
unsigned src,
unsigned dst,
380 bdd cond, acc_cond::mark_t acc = 0
U)
382 return g_.new_edge(src, dst, cond, acc);
385 unsigned new_acc_edge(
unsigned src,
unsigned dst,
386 bdd cond,
bool acc =
true)
389 return g_.new_edge(src, dst, cond, acc_.all_sets());
391 return g_.new_edge(src, dst, cond);
395 internal::state_out<const graph_t>
396 out(
unsigned src)
const
402 internal::state_out<graph_t>
410 SPOT_RETURN(g_.states());
412 SPOT_RETURN(g_.states());
415 SPOT_RETURN(g_.edges());
417 SPOT_RETURN(g_.edges());
419 auto edge_vector() const
420 SPOT_RETURN(g_.edge_vector());
422 SPOT_RETURN(g_.edge_vector());
424 auto is_dead_edge(const graph_t::edge_storage_t& t) const
425 SPOT_RETURN(g_.is_dead_edge(t));
428 virtual bdd compute_support_conditions(
const state* s)
const
431 for (
auto& t: out(state_number(s)))
441 void purge_dead_states();
444 void purge_unreachable_states();
446 acc_cond::mark_t state_acc_sets(
unsigned s)
const
448 assert(prop_state_acc() || num_sets() == 0);
449 for (
auto& t: g_.out(s))
456 bool state_is_accepting(
unsigned s)
const
458 assert(prop_state_acc() || num_sets() == 0);
459 for (
auto& t: g_.out(s))
462 return acc_.accepting(t.acc);
466 bool state_is_accepting(
const state* s)
const
468 return state_is_accepting(state_number(s));
471 bool operator==(
const twa_graph& aut)
const
473 if (num_states() != aut.num_states() ||
474 num_edges() != aut.num_edges() ||
475 num_sets() != aut.num_sets())
477 auto& trans1 = edge_vector();
478 auto& trans2 = aut.edge_vector();
479 return std::equal(trans1.begin() + 1, trans1.end(),
483 void defrag_states(std::vector<unsigned>&& newst,
unsigned used_states);
486 inline twa_graph_ptr make_twa_graph(
const bdd_dict_ptr& dict)
488 return std::make_shared<twa_graph>(dict);
491 inline twa_graph_ptr make_twa_graph(
const twa_graph_ptr& aut,
494 return std::make_shared<twa_graph>(aut, p);
497 inline twa_graph_ptr make_twa_graph(
const const_twa_graph_ptr& aut,
500 return std::make_shared<twa_graph>(aut, p);
503 inline twa_graph_ptr make_twa_graph(
const const_twa_ptr& aut,
506 auto a = std::dynamic_pointer_cast<
const twa_graph>(aut);
508 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:281
A Transition-based ω-Automaton.
Definition: twa.hh:483
Abstract class for states.
Definition: twa.hh:43
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:332
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:273
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,.