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 149 return &g_->state_data(g_->edge_storage(p_).dst);
152 virtual bdd
cond()
const override 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);
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<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(state_num s)
254 assert(s < num_states());
258 void set_init_state(
const state* s)
260 set_init_state(state_number(s));
263 state_num get_init_state_number()
const 265 if (num_states() == 0)
266 const_cast<graph_t&
>(g_).new_state();
272 if (num_states() == 0)
273 const_cast<graph_t&
>(g_).new_state();
274 return state_from_number(init_number_);
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 300 return s - &g_.state_storage(0);
304 state_from_number(state_num n)
const 306 return &g_.state_data(n);
309 std::string format_state(
unsigned n)
const 311 std::stringstream ss;
318 return format_state(state_number(st));
324 return g_.edge_data(i->pos());
329 return g_.edge_data(t);
335 return g_.edge_data(i->pos());
340 return g_.edge_data(t);
346 return g_.edge_storage(i->pos());
349 edge_storage_t& edge_storage(
unsigned t)
351 return g_.edge_storage(t);
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,
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, this->acc().all_sets());
388 return g_.new_edge(src, dst, cond);
393 out(
unsigned src)
const 407 SPOT_RETURN(g_.states());
409 SPOT_RETURN(g_.states());
425 auto edge_vector()
const 426 SPOT_RETURN(g_.edge_vector());
428 SPOT_RETURN(g_.edge_vector());
431 SPOT_RETURN(g_.is_dead_edge(t));
439 void purge_dead_states();
442 void purge_unreachable_states();
446 assert((
bool)prop_state_acc() || num_sets() == 0);
447 for (
auto& t: g_.out(s))
454 bool state_is_accepting(
unsigned s)
const 456 assert((
bool)prop_state_acc() || num_sets() == 0);
457 for (
auto& t: g_.out(s))
460 return acc().accepting(t.acc);
464 bool state_is_accepting(
const state* s)
const 466 return state_is_accepting(state_number(s));
469 bool operator==(
const twa_graph& aut)
const 471 if (num_states() != aut.num_states() ||
472 num_edges() != aut.num_edges() ||
475 auto& trans1 = edge_vector();
476 auto& trans2 = aut.edge_vector();
477 return std::equal(trans1.begin() + 1, trans1.end(),
481 void defrag_states(std::vector<unsigned>&& newst,
unsigned used_states);
484 inline twa_graph_ptr make_twa_graph(
const bdd_dict_ptr& dict)
486 return std::make_shared<twa_graph>(dict);
489 inline twa_graph_ptr make_twa_graph(
const twa_graph_ptr& aut,
492 return std::make_shared<twa_graph>(aut, p);
495 inline twa_graph_ptr make_twa_graph(
const const_twa_graph_ptr& aut,
498 return std::make_shared<twa_graph>(aut, p);
501 inline twa_graph_ptr make_twa_graph(
const const_twa_ptr& aut,
504 auto a = std::dynamic_pointer_cast<
const twa_graph>(aut);
506 return std::make_shared<twa_graph>(a, p);
virtual void destroy() const override
Release a state.
Definition: twagraph.hh:70
A Transition-based ω-Automaton.
Definition: twa.hh:577
Abstract class for states.
Definition: twa.hh:43
virtual size_t hash() const override
Hash a state.
Definition: twagraph.hh:58
virtual std::string format_state(const state *st) const override
Format the state as a string for printing.
Definition: twagraph.hh:316
virtual const twa_graph_state * get_init_state() const override
Get the initial state of the automaton.
Definition: twagraph.hh:270
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:390
virtual bdd cond() const override
Get the condition on the edge leading to this successor.
Definition: twagraph.hh:152
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:1216
unsigned num_sets() const
Number of acceptance sets used by the automaton.
Definition: twa.hh:809
virtual acc_cond::mark_t acc() const override
Get the acceptance mark of the edge leading to this successor.
Definition: twagraph.hh:158
virtual twa_succ_iterator * succ_iter(const state *st) const override
Get an iterator over the successors of local_state.
Definition: twagraph.hh:278
Definition: twagraph.hh:108
Definition: twagraph.hh:171
Definition: twagraph.hh:34
virtual bool next() override
Jump to the next successor (if any).
Definition: twagraph.hh:135
Definition: twagraph.hh:75
virtual twa_graph_state * clone() const override
Duplicate a state.
Definition: twagraph.hh:65