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> 61 virtual size_t hash()
const override 64 reinterpret_cast<const char*
>(
this) - static_cast<const char*>(
nullptr);
91 : cond(bddfalse), acc({})
98 : cond(cond), acc(acc)
104 if (cond.id() < other.cond.id())
106 if (cond.id() > other.cond.id())
108 return acc < other.acc;
113 return cond.id() == other.cond.id() &&
124 template<
class Graph>
129 typedef typename Graph::edge edge;
130 typedef typename Graph::state_data_t state;
154 p_ = g_->edge_storage(p_).next_succ;
158 virtual bool done()
const override 165 SPOT_ASSERT(!done());
166 return &g_->state_data(g_->edge_storage(p_).dst);
169 virtual bdd
cond()
const override 171 SPOT_ASSERT(!done());
172 return g_->edge_data(p_).cond;
177 SPOT_ASSERT(!done());
178 return g_->edge_data(p_).acc;
202 edge_storage_t>::value,
"type mismatch");
204 typedef unsigned state_num;
205 static_assert(std::is_same<typename graph_t::state, state_num>::value,
210 mutable unsigned init_number_;
219 explicit twa_graph(
const const_twa_graph_ptr& other, prop_set p)
220 :
twa(other->get_dict()),
221 g_(other->g_), init_number_(other->init_number_)
223 copy_acceptance_of(other);
233 template <
typename State_Name,
234 typename Name_Hash = std::hash<State_Name>,
235 typename Name_Equal = std::equal_to<State_Name>>
238 template <
typename State_Name,
239 typename Name_Hash = std::hash<State_Name>,
240 typename Name_Equal = std::equal_to<State_Name>>
248 create_formula_namer()
250 return create_namer<formula>();
262 const graph_t& get_graph()
const 267 unsigned num_states()
const 272 unsigned num_edges()
const 277 void set_init_state(state_num s)
279 if (SPOT_UNLIKELY(s >= num_states()))
280 throw std::invalid_argument
281 (
"set_init_state() called with nonexisting state");
286 void set_univ_init_state(I dst_begin, I dst_end)
288 auto ns = num_states();
289 for (I i = dst_begin; i != dst_end; ++i)
290 if (SPOT_UNLIKELY(*i >= ns))
291 throw std::invalid_argument
292 (
"set_univ_init_state() called with nonexisting state");
296 void set_univ_init_state(
const std::initializer_list<state_num>& il)
298 set_univ_init_state(il.begin(), il.end());
301 state_num get_init_state_number()
const 304 if (num_states() == 0)
305 throw std::runtime_error(
"automaton has no state at all");
311 unsigned n = get_init_state_number();
312 if (SPOT_UNLIKELY(!is_existential()))
313 throw std::runtime_error
314 (
"the abstract interface does not support alternating automata");
315 return state_from_number(n);
324 if (this->iter_cache_)
328 it->recycle(s->succ);
329 this->iter_cache_ =
nullptr;
335 static constexpr
bool is_univ_dest(
const edge_storage_t& e)
337 return is_univ_dest(e.dst);
340 static constexpr
bool is_univ_dest(
unsigned s)
348 state_number(
const state* st)
const 355 state_from_number(state_num n)
const 360 std::string format_state(
unsigned n)
const;
364 return format_state(state_number(st));
373 unsigned edge_number(
const edge_storage_t& e)
const 383 twa_graph_edge_data& edge_data(
unsigned t)
393 const twa_graph_edge_data& edge_data(
unsigned t)
const 403 edge_storage_t& edge_storage(
unsigned t)
414 const edge_storage_t edge_storage(
unsigned t)
const 424 unsigned new_states(
unsigned n)
429 unsigned new_edge(
unsigned src,
unsigned dst,
433 return g_.
new_edge(src, dst, cond, acc);
436 unsigned new_acc_edge(
unsigned src,
unsigned dst,
437 bdd cond,
bool acc =
true)
440 return g_.
new_edge(src, dst, cond, this->acc().all_sets());
446 unsigned new_univ_edge(
unsigned src, I begin, I end,
453 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);
493 SPOT_DEPRECATED(
"use !is_existential() instead")
498 bool is_alternating()
const 500 return !is_existential();
506 SPOT_RETURN(g_.states());
508 SPOT_RETURN(g_.states());
511 edges()
const noexcept
524 auto edge_vector()
const 525 SPOT_RETURN(g_.edge_vector());
527 SPOT_RETURN(g_.edge_vector());
530 SPOT_RETURN(g_.is_dead_edge(t));
554 void merge_univ_dests();
579 void purge_dead_states();
598 typedef void (*shift_action)(
const std::vector<unsigned>& newst,
600 void purge_unreachable_states(shift_action* f =
nullptr,
601 void* action_data =
nullptr);
607 void remove_unused_ap();
615 void copy_state_names_from(
const const_twa_graph_ptr& other);
621 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
622 throw std::runtime_error
623 (
"state_acc_sets() should only be called on " 624 "automata with state-based acceptance");
625 for (
auto& t: g_.out(s))
640 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
641 throw std::runtime_error
642 (
"state_is_accepting() should only be called on " 643 "automata with state-based acceptance");
644 for (
auto& t: g_.out(s))
647 return acc().accepting(t.acc);
653 return state_is_accepting(state_number(s));
657 bool operator==(
const twa_graph& aut)
const 659 auto& dests1 = g_.dests_vector();
661 if (num_states() != aut.num_states() ||
662 num_edges() != aut.num_edges() ||
664 dests1.size() != dests2.size())
666 auto& trans1 = edge_vector();
667 auto& trans2 = aut.edge_vector();
668 if (!std::equal(trans1.begin() + 1, trans1.end(),
671 return std::equal(dests1.begin(), dests1.end(),
684 void defrag_states(std::vector<unsigned>&& newst,
unsigned used_states);
691 return std::make_shared<twa_graph>(dict);
699 return std::make_shared<twa_graph>(aut, p);
707 return std::make_shared<twa_graph>(aut, p);
719 SPOT_API twa_graph_ptr
721 bool preserve_names =
false,
724 unsigned max_states = -(1
U));
state new_states(unsigned n, Args &&... args)
Create n new states.
Definition: graph.hh:697
Definition: automata.hh:26
virtual void destroy() const override
Release a state.
Definition: twagraph.hh:73
bool state_is_accepting(const state *s) const
Tell if a state is accepting.
Definition: twagraph.hh:651
const dests_vector_t & dests_vector() const
The vector used to store universal destinations.
Definition: graph.hh:1010
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:61
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:362
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:309
state_storage_t::data_t & state_data(state s)
return the State_Data associated to a state
Definition: graph.hh:730
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:146
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:169
acc_cond::mark_t state_acc_sets(unsigned s) const
Return the marks associated to a state if the acceptance is state-based.
Definition: twagraph.hh:619
twa_graph_ptr make_twa_graph(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,.
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:158
virtual int compare(const spot::state *other) const override
Compares two states (that come from the same automaton).
Definition: twagraph.hh:49
virtual const twa_graph_state * dst() const override
Get the destination state of the current edge.
Definition: twagraph.hh:163
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
edge index_of_edge(const edge_storage_t &tt) const
Conveart a storage reference into an edge number.
Definition: graph.hh:878
virtual acc_cond::mark_t acc() const override
Get the acceptance mark of the edge leading to this successor.
Definition: twagraph.hh:175
bool state_is_accepting(unsigned s) const
Tell if a state is accepting.
Definition: twagraph.hh:638
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:319
Iterator used by the on-the-fly interface of twa_graph.
Definition: twagraph.hh:125
state new_univ_dests(I dst_begin, I dst_end)
Create a new universal destination group.
Definition: graph.hh:809
Graph-based representation of a TωA.
Definition: twagraph.hh:190
Graph-based representation of a TωA.
Definition: twagraph.hh:38
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:930
virtual bool next() override
Jump to the next successor (if any).
Definition: twagraph.hh:152
bool is_existential() const
Whether the automaton uses only existential branching.
Definition: twagraph.hh:487
Data attached to edges of a twa_graph.
Definition: twagraph.hh:85
virtual twa_graph_state * clone() const override
Duplicate a state.
Definition: twagraph.hh:68