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
148 SPOT_ASSERT(!done());
149 return &g_->state_data(g_->edge_storage(p_).dst);
152 virtual bdd
cond()
const override
154 SPOT_ASSERT(!done());
155 return g_->edge_data(p_).cond;
160 SPOT_ASSERT(!done());
161 return g_->edge_data(p_).acc;
183 edge_storage_t>::value,
"type mismatch");
185 typedef unsigned state_num;
186 static_assert(std::is_same<typename graph_t::state, state_num>::value,
191 mutable unsigned init_number_;
200 explicit twa_graph(
const const_twa_graph_ptr& other, prop_set p)
201 :
twa(other->get_dict()),
202 g_(other->g_), init_number_(other->init_number_)
204 copy_acceptance_of(other);
214 template <
typename State_Name,
215 typename Name_Hash = std::hash<State_Name>,
216 typename Name_Equal = std::equal_to<State_Name>>
219 template <
typename State_Name,
220 typename Name_Hash = std::hash<State_Name>,
221 typename Name_Equal = std::equal_to<State_Name>>
222 namer<State_Name, Name_Hash, Name_Equal>*
229 create_formula_namer()
231 return create_namer<formula>();
235 release_formula_namer(namer<formula>* namer,
bool keep_names);
243 const graph_t& get_graph()
const
248 unsigned num_states()
const
253 unsigned num_edges()
const
258 void set_init_state(state_num s)
260 if (SPOT_UNLIKELY(s >= num_states()))
261 throw std::invalid_argument
262 (
"set_init_state() called with nonexisiting state");
266 void set_init_state(
const state* s)
268 set_init_state(state_number(s));
272 void set_univ_init_state(I dst_begin, I dst_end)
274 auto ns = num_states();
275 for (I i = dst_begin; i != dst_end; ++i)
276 if (SPOT_UNLIKELY(*i >= ns))
277 throw std::invalid_argument
278 (
"set_univ_init_state() called with nonexisiting state");
283 void set_univ_init_state(
const std::initializer_list<state_num>& il)
285 set_univ_init_state(il.begin(), il.end());
288 state_num get_init_state_number()
const
291 if (num_states() == 0)
292 throw std::runtime_error(
"automaton has no state at all");
298 unsigned n = get_init_state_number();
299 if (SPOT_UNLIKELY(is_alternating()))
300 throw std::runtime_error
301 (
"the abstract interface does not support alternating automata");
302 return state_from_number(n);
306 succ_iter(
const state* st)
const override
312 if (this->iter_cache_)
316 it->recycle(s->succ);
317 this->iter_cache_ =
nullptr;
323 static constexpr
bool is_univ_dest(
const edge_storage_t& e)
325 return is_univ_dest(e.dst);
328 static constexpr
bool is_univ_dest(
unsigned s)
336 state_number(
const state* st)
const
344 state_from_number(state_num n)
const
349 std::string format_state(
unsigned n)
const
351 std::stringstream ss;
354 bool notfirst =
false;
355 for (
unsigned d: univ_dests(n))
370 virtual std::string format_state(
const state* st)
const override
372 return format_state(state_number(st));
386 twa_graph_edge_data& edge_data(
unsigned t)
396 const twa_graph_edge_data& edge_data(
unsigned t)
const
406 edge_storage_t& edge_storage(
unsigned t)
417 const edge_storage_t edge_storage(
unsigned t)
const
427 unsigned new_states(
unsigned n)
432 unsigned new_edge(
unsigned src,
unsigned dst,
435 return g_.
new_edge(src, dst, cond, acc);
438 unsigned new_acc_edge(
unsigned src,
unsigned dst,
439 bdd cond,
bool acc =
true)
442 return g_.
new_edge(src, dst, cond, this->acc().all_sets());
448 unsigned new_univ_edge(
unsigned src, I begin, I end,
454 unsigned new_univ_edge(
unsigned src, std::initializer_list<unsigned> dst,
457 return g_.
new_univ_edge(src, dst.begin(), dst.end(), cond, acc);
462 out(
unsigned src)
const
475 univ_dests(
unsigned d)
const noexcept
477 return g_.univ_dests(d);
481 univ_dests(
const edge_storage_t& e)
const noexcept
483 return g_.univ_dests(e);
486 bool is_alternating()
const
498 edges()
const noexcept
511 auto edge_vector()
const
527 void merge_univ_dests();
537 void purge_dead_states();
550 void purge_unreachable_states();
556 void remove_unused_ap();
560 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
561 throw std::runtime_error
562 (
"state_acc_sets() should only be called on "
563 "automata with state-based acceptance");
564 for (
auto& t: g_.
out(s))
571 bool state_is_accepting(
unsigned s)
const
573 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
574 throw std::runtime_error
575 (
"state_is_accepting() should only be called on "
576 "automata with state-based acceptance");
577 for (
auto& t: g_.
out(s))
580 return acc().accepting(t.acc);
584 bool state_is_accepting(
const state* s)
const
586 return state_is_accepting(state_number(s));
589 bool operator==(
const twa_graph& aut)
const
592 auto& dests2 = aut.get_graph().dests_vector();
593 if (num_states() != aut.num_states() ||
594 num_edges() != aut.num_edges() ||
596 dests1.size() != dests2.size())
598 auto& trans1 = edge_vector();
599 auto& trans2 = aut.edge_vector();
600 if (!std::equal(trans1.begin() + 1, trans1.end(),
603 return std::equal(dests1.begin(), dests1.end(),
607 void defrag_states(std::vector<unsigned>&& newst,
unsigned used_states);
610 inline twa_graph_ptr make_twa_graph(
const bdd_dict_ptr& dict)
612 return std::make_shared<twa_graph>(dict);
615 inline twa_graph_ptr make_twa_graph(
const twa_graph_ptr& aut,
618 return std::make_shared<twa_graph>(aut, p);
621 inline twa_graph_ptr make_twa_graph(
const const_twa_graph_ptr& aut,
624 return std::make_shared<twa_graph>(aut, p);
627 inline twa_graph_ptr make_twa_graph(
const const_twa_ptr& aut,
630 auto a = std::dynamic_pointer_cast<
const twa_graph>(aut);
632 return std::make_shared<twa_graph>(a, p);
state_storage_t & state_storage(state s)
return a reference to the storage of a state
Definition: graph.hh:700
virtual void destroy() const override
Release a state.
Definition: twagraph.hh:70
bool is_dead_edge(unsigned t) const
Tests whether an edge has been erased.
Definition: graph.hh:982
state_storage_t::data_t & state_data(state s)
return the State_Data associated to a state
Definition: graph.hh:718
state new_states(unsigned n, Args &&...args)
Create n new states.
Definition: graph.hh:685
A Transition-based ω-Automaton.
Definition: twa.hh:622
edge_storage_t & edge_storage(edge s)
return a reference to the storage of an edge
Definition: graph.hh:736
state new_univ_dests(I dst_begin, I dst_end)
Create a new universal destination group.
Definition: graph.hh:797
Abstract class for states.
Definition: twa.hh:50
unsigned num_edges() const
The number of edges in the automaton.
Definition: graph.hh:654
virtual size_t hash() const override
Hash a state.
Definition: twagraph.hh:58
const dests_vector_t & dests_vector() const
The vector used to store universal destinations.
Definition: graph.hh:998
const state_vector & states() const
Return the vector of states.
Definition: graph.hh:919
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
edge_storage_t::data_t & edge_data(edge s)
return the Edgeg_Data of an edge.
Definition: graph.hh:754
Iterate over the successors of a state.
Definition: twa.hh:397
internal::state_out< digraph > out(state src)
Return a fake container with all edges leaving src.
Definition: graph.hh:875
virtual bdd cond() const override
Get the condition on the edge leading to this successor.
Definition: twagraph.hh:152
const edge_vector_t & edge_vector() const
Return the vector of all edges.
Definition: graph.hh:953
edge new_edge(state src, state dst, Args &&...args)
Create a new edge.
Definition: graph.hh:773
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
unsigned num_sets() const
Number of acceptance sets used by the automaton.
Definition: twa.hh:906
virtual acc_cond::mark_t acc() const override
Get the acceptance mark of the edge leading to this successor.
Definition: twagraph.hh:158
bool is_valid_edge(edge t) const
Test whether the given edge is valid.
Definition: graph.hh:970
Definition: twagraph.hh:108
A directed graph.
Definition: graph.hh:36
edge new_univ_edge(state src, I dst_begin, I dst_end, Args &&...args)
Create a new universal edge.
Definition: graph.hh:817
bool is_alternating() const
Whether the automaton is alternating.
Definition: graph.hh:660
Definition: twagraph.hh:171
Definition: twagraph.hh:34
state new_state(Args &&...args)
Create a new states.
Definition: graph.hh:671
virtual bool next() override
Jump to the next successor (if any).
Definition: twagraph.hh:135
unsigned num_states() const
The number of states in the automaton.
Definition: graph.hh:646
internal::all_trans< const digraph > edges() const
Return a fake container with all edges (exluding erased edges)
Definition: graph.hh:934
Definition: twagraph.hh:75
virtual twa_graph_state * clone() const override
Duplicate a state.
Definition: twagraph.hh:65