21 #include <spot/twa/fwd.hh>
22 #include <spot/graph/graph.hh>
23 #include <spot/graph/ngraph.hh>
24 #include <spot/twa/bdddict.hh>
25 #include <spot/twa/twa.hh>
26 #include <spot/twaalgos/copy.hh>
56 virtual size_t hash()
const override
59 reinterpret_cast<const char*
>(
this) - static_cast<const char*>(
nullptr);
79 : cond(bddfalse), acc(0)
84 : cond(cond), acc(acc)
90 if (cond.id() < other.cond.id())
92 if (cond.id() > other.cond.id())
94 return acc < other.acc;
99 return cond.id() == other.cond.id() &&
105 template<
class Graph>
110 typedef typename Graph::edge edge;
111 typedef typename Graph::state_data_t state;
135 p_ = g_->edge_storage(p_).next_succ;
139 virtual bool done()
const override
146 SPOT_ASSERT(!done());
147 return &g_->state_data(g_->edge_storage(p_).dst);
150 virtual bdd
cond()
const override
152 SPOT_ASSERT(!done());
153 return g_->edge_data(p_).cond;
158 SPOT_ASSERT(!done());
159 return g_->edge_data(p_).acc;
181 edge_storage_t>::value,
"type mismatch");
183 typedef unsigned state_num;
184 static_assert(std::is_same<typename graph_t::state, state_num>::value,
189 mutable unsigned init_number_;
198 explicit twa_graph(
const const_twa_graph_ptr& other, prop_set p)
199 :
twa(other->get_dict()),
200 g_(other->g_), init_number_(other->init_number_)
202 copy_acceptance_of(other);
212 template <
typename State_Name,
213 typename Name_Hash = std::hash<State_Name>,
214 typename Name_Equal = std::equal_to<State_Name>>
217 template <
typename State_Name,
218 typename Name_Hash = std::hash<State_Name>,
219 typename Name_Equal = std::equal_to<State_Name>>
220 namer<State_Name, Name_Hash, Name_Equal>*
227 create_formula_namer()
229 return create_namer<formula>();
233 release_formula_namer(namer<formula>* namer,
bool keep_names);
241 const graph_t& get_graph()
const
246 unsigned num_states()
const
251 unsigned num_edges()
const
256 void set_init_state(state_num s)
258 if (SPOT_UNLIKELY(s >= num_states()))
259 throw std::invalid_argument
260 (
"set_init_state() called with nonexisiting state");
264 void set_init_state(
const state* s)
266 set_init_state(state_number(s));
270 void set_univ_init_state(I dst_begin, I dst_end)
272 auto ns = num_states();
273 for (I i = dst_begin; i != dst_end; ++i)
274 if (SPOT_UNLIKELY(*i >= ns))
275 throw std::invalid_argument
276 (
"set_univ_init_state() called with nonexisiting state");
281 void set_univ_init_state(
const std::initializer_list<state_num>& il)
283 set_univ_init_state(il.begin(), il.end());
286 state_num get_init_state_number()
const
289 if (num_states() == 0)
290 throw std::runtime_error(
"automaton has no state at all");
296 unsigned n = get_init_state_number();
297 if (SPOT_UNLIKELY(!is_existential()))
298 throw std::runtime_error
299 (
"the abstract interface does not support alternating automata");
300 return state_from_number(n);
304 succ_iter(
const state* st)
const override
309 if (this->iter_cache_)
313 it->recycle(s->succ);
314 this->iter_cache_ =
nullptr;
320 static constexpr
bool is_univ_dest(
const edge_storage_t& e)
322 return is_univ_dest(e.dst);
325 static constexpr
bool is_univ_dest(
unsigned s)
333 state_number(
const state* st)
const
340 state_from_number(state_num n)
const
345 std::string format_state(
unsigned n)
const
347 std::stringstream ss;
350 bool notfirst =
false;
351 for (
unsigned d: univ_dests(n))
366 virtual std::string format_state(
const state* st)
const override
368 return format_state(state_number(st));
382 twa_graph_edge_data& edge_data(
unsigned t)
392 const twa_graph_edge_data& edge_data(
unsigned t)
const
402 edge_storage_t& edge_storage(
unsigned t)
413 const edge_storage_t edge_storage(
unsigned t)
const
423 unsigned new_states(
unsigned n)
428 unsigned new_edge(
unsigned src,
unsigned dst,
431 return g_.
new_edge(src, dst, cond, acc);
434 unsigned new_acc_edge(
unsigned src,
unsigned dst,
435 bdd cond,
bool acc =
true)
438 return g_.
new_edge(src, dst, cond, this->acc().all_sets());
444 unsigned new_univ_edge(
unsigned src, I begin, I end,
450 unsigned new_univ_edge(
unsigned src, std::initializer_list<unsigned> dst,
453 return g_.
new_univ_edge(src, dst.begin(), dst.end(), cond, acc);
458 out(
unsigned src)
const
471 univ_dests(
unsigned d)
const noexcept
473 return g_.univ_dests(d);
477 univ_dests(
const edge_storage_t& e)
const noexcept
479 return g_.univ_dests(e);
483 bool is_existential()
const
489 SPOT_DEPRECATED(
"use !is_existential() instead")
494 bool is_alternating()
const
496 return !is_existential();
507 edges()
const noexcept
520 auto edge_vector()
const
536 void merge_univ_dests();
546 void purge_dead_states();
559 void purge_unreachable_states();
565 void remove_unused_ap();
569 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
570 throw std::runtime_error
571 (
"state_acc_sets() should only be called on "
572 "automata with state-based acceptance");
573 for (
auto& t: g_.
out(s))
580 bool state_is_accepting(
unsigned s)
const
582 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
583 throw std::runtime_error
584 (
"state_is_accepting() should only be called on "
585 "automata with state-based acceptance");
586 for (
auto& t: g_.
out(s))
589 return acc().accepting(t.acc);
593 bool state_is_accepting(
const state* s)
const
595 return state_is_accepting(state_number(s));
598 bool operator==(
const twa_graph& aut)
const
601 auto& dests2 = aut.get_graph().dests_vector();
602 if (num_states() != aut.num_states() ||
603 num_edges() != aut.num_edges() ||
605 dests1.size() != dests2.size())
607 auto& trans1 = edge_vector();
608 auto& trans2 = aut.edge_vector();
609 if (!std::equal(trans1.begin() + 1, trans1.end(),
612 return std::equal(dests1.begin(), dests1.end(),
616 void defrag_states(std::vector<unsigned>&& newst,
unsigned used_states);
619 inline twa_graph_ptr make_twa_graph(
const bdd_dict_ptr& dict)
621 return std::make_shared<twa_graph>(dict);
624 inline twa_graph_ptr make_twa_graph(
const twa_graph_ptr& aut,
627 return std::make_shared<twa_graph>(aut, p);
630 inline twa_graph_ptr make_twa_graph(
const const_twa_graph_ptr& aut,
633 return std::make_shared<twa_graph>(aut, p);
636 inline twa_graph_ptr make_twa_graph(
const const_twa_ptr& aut,
639 auto a = std::dynamic_pointer_cast<
const twa_graph>(aut);
641 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:712
virtual void destroy() const override
Release a state.
Definition: twagraph.hh:68
bool is_dead_edge(unsigned t) const
Tests whether an edge has been erased.
Definition: graph.hh:994
state_storage_t::data_t & state_data(state s)
return the State_Data associated to a state
Definition: graph.hh:730
state new_states(unsigned n, Args &&...args)
Create n new states.
Definition: graph.hh:697
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:748
state new_univ_dests(I dst_begin, I dst_end)
Create a new universal destination group.
Definition: graph.hh:809
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:56
const dests_vector_t & dests_vector() const
The vector used to store universal destinations.
Definition: graph.hh:1010
const state_vector & states() const
Return the vector of states.
Definition: graph.hh:931
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:127
edge_storage_t::data_t & edge_data(edge s)
return the Edgeg_Data of an edge.
Definition: graph.hh:766
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:887
virtual bdd cond() const override
Get the condition on the edge leading to this successor.
Definition: twagraph.hh:150
const edge_vector_t & edge_vector() const
Return the vector of all edges.
Definition: graph.hh:965
edge new_edge(state src, state dst, Args &&...args)
Create a new edge.
Definition: graph.hh:785
bool is_existential() const
Whether the automaton uses only existential branching.
Definition: graph.hh:660
virtual bool done() const override
Check whether the iteration is finished.
Definition: twagraph.hh:139
virtual int compare(const spot::state *other) const override
Compares two states (that come from the same automaton).
Definition: twagraph.hh:44
virtual const twa_graph_state * dst() const override
Get the destination state of the current edge.
Definition: twagraph.hh:144
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:156
bool is_valid_edge(edge t) const
Test whether the given edge is valid.
Definition: graph.hh:982
Definition: twagraph.hh:106
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:829
Definition: twagraph.hh:169
Definition: twagraph.hh:33
state new_state(Args &&...args)
Create a new states.
Definition: graph.hh:683
virtual bool next() override
Jump to the next successor (if any).
Definition: twagraph.hh:133
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:946
Definition: twagraph.hh:73
virtual twa_graph_state * clone() const override
Duplicate a state.
Definition: twagraph.hh:63