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>>
227 create_formula_namer()
229 return create_namer<formula>();
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 nonexisting state");
265 void set_univ_init_state(I dst_begin, I dst_end)
267 auto ns = num_states();
268 for (I i = dst_begin; i != dst_end; ++i)
269 if (SPOT_UNLIKELY(*i >= ns))
270 throw std::invalid_argument
271 (
"set_univ_init_state() called with nonexisting state");
275 void set_univ_init_state(
const std::initializer_list<state_num>& il)
277 set_univ_init_state(il.begin(), il.end());
280 state_num get_init_state_number()
const 283 if (num_states() == 0)
284 throw std::runtime_error(
"automaton has no state at all");
290 unsigned n = get_init_state_number();
291 if (SPOT_UNLIKELY(!is_existential()))
292 throw std::runtime_error
293 (
"the abstract interface does not support alternating automata");
294 return state_from_number(n);
303 if (this->iter_cache_)
307 it->recycle(s->succ);
308 this->iter_cache_ =
nullptr;
314 static constexpr
bool is_univ_dest(
const edge_storage_t& e)
316 return is_univ_dest(e.dst);
319 static constexpr
bool is_univ_dest(
unsigned s)
327 state_number(
const state* st)
const 334 state_from_number(state_num n)
const 339 std::string format_state(
unsigned n)
const 341 std::stringstream ss;
344 bool notfirst =
false;
345 for (
unsigned d: univ_dests(n))
362 return format_state(state_number(st));
376 twa_graph_edge_data& edge_data(
unsigned t)
386 const twa_graph_edge_data& edge_data(
unsigned t)
const 396 edge_storage_t& edge_storage(
unsigned t)
407 const edge_storage_t edge_storage(
unsigned t)
const 417 unsigned new_states(
unsigned n)
422 unsigned new_edge(
unsigned src,
unsigned dst,
425 return g_.
new_edge(src, dst, cond, acc);
428 unsigned new_acc_edge(
unsigned src,
unsigned dst,
429 bdd cond,
bool acc =
true)
432 return g_.
new_edge(src, dst, cond, this->acc().all_sets());
438 unsigned new_univ_edge(
unsigned src, I begin, I end,
444 unsigned new_univ_edge(
unsigned src, std::initializer_list<unsigned> dst,
447 return g_.
new_univ_edge(src, dst.begin(), dst.end(), cond, acc);
452 out(
unsigned src)
const 465 univ_dests(
unsigned d)
const noexcept
467 return g_.univ_dests(d);
471 univ_dests(
const edge_storage_t& e)
const noexcept
473 return g_.univ_dests(e);
483 SPOT_DEPRECATED(
"use !is_existential() instead")
488 bool is_alternating()
const 490 return !is_existential();
496 SPOT_RETURN(g_.states());
498 SPOT_RETURN(g_.states());
501 edges()
const noexcept
514 auto edge_vector()
const 515 SPOT_RETURN(g_.edge_vector());
517 SPOT_RETURN(g_.edge_vector());
520 SPOT_RETURN(g_.is_dead_edge(t));
530 void merge_univ_dests();
547 void purge_dead_states();
561 void purge_unreachable_states();
567 void remove_unused_ap();
571 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
572 throw std::runtime_error
573 (
"state_acc_sets() should only be called on " 574 "automata with state-based acceptance");
575 for (
auto& t: g_.out(s))
582 bool state_is_accepting(
unsigned s)
const 584 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
585 throw std::runtime_error
586 (
"state_is_accepting() should only be called on " 587 "automata with state-based acceptance");
588 for (
auto& t: g_.out(s))
591 return acc().accepting(t.acc);
595 bool state_is_accepting(
const state* s)
const 597 return state_is_accepting(state_number(s));
600 bool operator==(
const twa_graph& aut)
const 602 auto& dests1 = g_.dests_vector();
604 if (num_states() != aut.num_states() ||
605 num_edges() != aut.num_edges() ||
607 dests1.size() != dests2.size())
609 auto& trans1 = edge_vector();
610 auto& trans2 = aut.edge_vector();
611 if (!std::equal(trans1.begin() + 1, trans1.end(),
614 return std::equal(dests1.begin(), dests1.end(),
618 void defrag_states(std::vector<unsigned>&& newst,
unsigned used_states);
621 inline twa_graph_ptr make_twa_graph(
const bdd_dict_ptr& dict)
623 return std::make_shared<twa_graph>(dict);
626 inline twa_graph_ptr make_twa_graph(
const twa_graph_ptr& aut,
629 return std::make_shared<twa_graph>(aut, p);
632 inline twa_graph_ptr make_twa_graph(
const const_twa_graph_ptr& aut,
635 return std::make_shared<twa_graph>(aut, p);
638 inline twa_graph_ptr make_twa_graph(
const const_twa_ptr& aut,
641 auto a = std::dynamic_pointer_cast<
const twa_graph>(aut);
643 return std::make_shared<twa_graph>(a, p);
state new_states(unsigned n, Args &&... args)
Create n new states.
Definition: graph.hh:697
virtual void destroy() const override
Release a state.
Definition: twagraph.hh:68
const dests_vector_t & dests_vector() const
The vector used to store universal destinations.
Definition: graph.hh:1010
void prop_copy(const const_twa_ptr &other, prop_set p)
Copy the properties of another automaton.
Definition: twa.hh:1550
state new_state(Args &&... args)
Create a new states.
Definition: graph.hh:683
A Transition-based ω-Automaton.
Definition: twa.hh:622
Abstract class for states.
Definition: twa.hh:50
bool is_existential() const
Whether the automaton uses only existential branching.
Definition: graph.hh:660
virtual size_t hash() const override
Hash a state.
Definition: twagraph.hh:56
edge_storage_t & edge_storage(edge s)
return a reference to the storage of an edge
Definition: graph.hh:748
virtual std::string format_state(const state *st) const override
Format the state as a string for printing.
Definition: twagraph.hh:360
edge new_edge(state src, state dst, Args &&... args)
Create a new edge.
Definition: graph.hh:785
virtual const twa_graph_state * get_init_state() const override
Get the initial state of the automaton.
Definition: twagraph.hh:288
state_storage_t::data_t & state_data(state s)
return the State_Data associated to a state
Definition: graph.hh:730
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,.
state_storage_t & state_storage(state s)
return a reference to the storage of a state
Definition: graph.hh:712
virtual bool first() override
Position the iterator on the first successor (if any).
Definition: twagraph.hh:127
Iterate over the successors of a state.
Definition: twa.hh:397
edge_storage_t::data_t & edge_data(edge s)
return the Edgeg_Data of an edge.
Definition: graph.hh:766
virtual bdd cond() const override
Get the condition on the edge leading to this successor.
Definition: twagraph.hh:150
unsigned num_states() const
The number of states in the automaton.
Definition: graph.hh:646
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_edges() const
The number of edges in the automaton.
Definition: graph.hh:654
bool is_valid_edge(edge t) const
Test whether the given edge is valid.
Definition: graph.hh:982
virtual acc_cond::mark_t acc() const override
Get the acceptance mark of the edge leading to this successor.
Definition: twagraph.hh:156
internal::state_out< digraph > out(state src)
Return a fake container with all edges leaving src.
Definition: graph.hh:887
virtual twa_succ_iterator * succ_iter(const state *st) const override
Get an iterator over the successors of local_state.
Definition: twagraph.hh:298
Definition: twagraph.hh:106
state new_univ_dests(I dst_begin, I dst_end)
Create a new universal destination group.
Definition: graph.hh:809
Definition: twagraph.hh:169
Definition: twagraph.hh:33
edge new_univ_edge(state src, I dst_begin, I dst_end, Args &&... args)
Create a new universal edge.
Definition: graph.hh:829
unsigned num_sets() const
Number of acceptance sets used by the automaton.
Definition: twa.hh:906
virtual bool next() override
Jump to the next successor (if any).
Definition: twagraph.hh:133
bool is_existential() const
Whether the automaton uses only existential branching.
Definition: twagraph.hh:477
Definition: twagraph.hh:73
virtual twa_graph_state * clone() const override
Duplicate a state.
Definition: twagraph.hh:63