23 #include "graph/graph.hh"
24 #include "graph/ngraph.hh"
25 #include "twa/bdddict.hh"
27 #include "twaalgos/dupexp.hh"
59 virtual size_t hash()
const
62 reinterpret_cast<const char*
>(
this) - static_cast<const char*>(
nullptr);
82 : cond(bddfalse), acc(0)
87 : cond(cond), acc(acc)
93 if (cond.id() < other.cond.id())
95 if (cond.id() > other.cond.id())
97 return acc < other.acc;
102 return cond.id() == other.cond.id() &&
108 template<
class Graph>
113 typedef typename Graph::edge edge;
114 typedef typename Graph::state_data_t state;
125 virtual void recycle(edge t)
138 p_ = g_->edge_storage(p_).next_succ;
151 (&g_->state_data(g_->edge_storage(p_).dst));
157 return g_->edge_data(p_).cond;
163 return g_->edge_data(p_).acc;
181 mutable unsigned init_number_;
191 :
twa(other->get_dict()),
192 g_(other->g_), init_number_(other->init_number_)
194 copy_acceptance_of(other);
201 get_dict()->unregister_all_my_variables(
this);
204 last_support_conditions_input_ = 0;
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>>
223 create_formula_namer()
225 return create_namer<const ltl::formula*>();
237 const graph_t& get_graph()
const
242 unsigned num_states()
const
244 return g_.num_states();
247 unsigned num_edges()
const
249 return g_.num_edges();
252 void set_init_state(graph_t::state s)
254 assert(s < num_states());
258 void set_init_state(
const state* s)
260 set_init_state(state_number(s));
263 graph_t::state get_init_state_number()
const
265 if (num_states() == 0)
266 const_cast<graph_t&
>(g_).new_state();
273 if (num_states() == 0)
274 const_cast<graph_t&
>(g_).new_state();
283 assert(!s->succ || g_.valid_trans(s->succ));
285 if (this->iter_cache_)
289 it->recycle(s->succ);
290 this->iter_cache_ =
nullptr;
297 state_number(
const state* st)
const
299 auto s = down_cast<
const typename graph_t::state_storage_t*>(st);
301 return s - &g_.state_storage(0);
304 const twa_graph_state*
305 state_from_number(graph_t::state n)
const
307 return &g_.state_data(n);
310 std::string format_state(
unsigned n)
const
312 std::stringstream ss;
317 virtual std::string format_state(
const state* st)
const
319 return format_state(state_number(st));
322 twa_graph_edge_data& edge_data(
const twa_succ_iterator* it)
324 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
325 return g_.edge_data(i->pos());
328 twa_graph_edge_data& edge_data(
unsigned t)
330 return g_.edge_data(t);
333 const twa_graph_edge_data& edge_data(
const twa_succ_iterator* it)
const
335 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
336 return g_.edge_data(i->pos());
339 const twa_graph_edge_data& edge_data(
unsigned t)
const
341 return g_.edge_data(t);
344 edge_storage_t& edge_storage(
const twa_succ_iterator* it)
346 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
347 return g_.edge_storage(i->pos());
350 edge_storage_t& edge_storage(
unsigned t)
352 return g_.edge_storage(t);
356 edge_storage(
const twa_succ_iterator* it)
const
358 auto* i = down_cast<
const twa_graph_succ_iterator<graph_t>*>(it);
359 return g_.edge_storage(i->pos());
362 const edge_storage_t edge_storage(
unsigned t)
const
364 return g_.edge_storage(t);
369 return g_.new_state();
372 unsigned new_states(
unsigned n)
374 return g_.new_states(n);
377 unsigned new_edge(
unsigned src,
unsigned dst,
378 bdd cond, acc_cond::mark_t acc = 0U)
380 return g_.new_edge(src, dst, cond, acc);
383 unsigned new_acc_edge(
unsigned src,
unsigned dst,
384 bdd cond,
bool acc =
true)
387 return g_.new_edge(src, dst, cond, acc_.all_sets());
389 return g_.new_edge(src, dst, cond);
393 auto out(
unsigned src)
const
394 SPOT_RETURN(g_.out(src));
395 auto out(
unsigned src)
396 SPOT_RETURN(g_.out(src));
399 SPOT_RETURN(g_.states());
401 SPOT_RETURN(g_.states());
404 SPOT_RETURN(g_.edges());
406 SPOT_RETURN(g_.edges());
408 auto edge_vector() const
409 SPOT_RETURN(g_.edge_vector());
411 SPOT_RETURN(g_.edge_vector());
413 auto is_dead_edge(const graph_t::edge_storage_t& t) const
414 SPOT_RETURN(g_.is_dead_edge(t));
417 virtual bdd compute_support_conditions(
const state* s)
const
420 for (
auto& t: out(state_number(s)))
430 void purge_dead_states();
433 void purge_unreachable_states();
435 acc_cond::mark_t state_acc_sets(
unsigned s)
const
437 assert(has_state_based_acc() || num_sets() == 0);
438 for (
auto& t: g_.out(s))
445 bool state_is_accepting(
unsigned s)
const
447 assert(has_state_based_acc() || num_sets() == 0);
448 for (
auto& t: g_.out(s))
451 return acc_.accepting(t.acc);
455 bool state_is_accepting(
const state* s)
const
457 return state_is_accepting(state_number(s));
460 bool operator==(
const twa_graph& aut)
const
462 if (num_states() != aut.num_states() ||
463 num_edges() != aut.num_edges() ||
464 num_sets() != aut.num_sets())
466 auto& trans1 = edge_vector();
467 auto& trans2 = aut.edge_vector();
468 return std::equal(trans1.begin() + 1, trans1.end(),
473 inline twa_graph_ptr make_twa_graph(
const bdd_dict_ptr& dict)
475 return std::make_shared<twa_graph>(dict);
478 inline twa_graph_ptr make_twa_graph(
const twa_graph_ptr& aut,
481 return std::make_shared<twa_graph>(aut, p);
484 inline twa_graph_ptr make_twa_graph(
const const_twa_graph_ptr& aut,
487 return std::make_shared<twa_graph>(aut, p);
490 inline twa_graph_ptr make_twa_graph(
const const_twa_ptr& aut,
493 auto a = std::dynamic_pointer_cast<
const twa_graph>(aut);
495 return std::make_shared<twa_graph>(a, p);
virtual twa_graph_state * clone() const
Duplicate a state.
Definition: twagraph.hh:66
virtual bool done() const
Check whether the iteration is finished.
Definition: twagraph.hh:142
virtual int compare(const spot::state *other) const
Compares two states (that come from the same automaton).
Definition: twagraph.hh:46
virtual twa_succ_iterator * succ_iter(const state *st) const
Get an iterator over the successors of local_state.
Definition: twagraph.hh:279
A Transition-based ω-Automaton.
Definition: twa.hh:480
Abstract class for states.
Definition: twa.hh:40
virtual bool first()
Position the iterator on the first successor (if any).
Definition: twagraph.hh:130
virtual size_t hash() const
Hash a state.
Definition: twagraph.hh:59
virtual twa_graph_state * current_state() const
Get the state of the current successor.
Definition: twagraph.hh:147
virtual bdd current_condition() const
Get the condition on the transition leading to this successor.
Definition: twagraph.hh:154
virtual bool next()
Jump to the next successor (if any).
Definition: twagraph.hh:136
Iterate over the successors of a state.
Definition: twa.hh:329
virtual twa_graph_state * get_init_state() const
Get the initial state of the automaton.
Definition: twagraph.hh:271
virtual void destroy() const
Release a state.
Definition: twagraph.hh:71
SPOT_API twa_graph_ptr tgba_dupexp_dfs(const const_twa_ptr &aut, twa::prop_set p)
Build an explicit automaton from all states of aut, numbering states in depth first order as they are...
Definition: twagraph.hh:109
Definition: twagraph.hh:173
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:160
Definition: twagraph.hh:76