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> 70 virtual size_t hash()
const override 73 reinterpret_cast<const char*
>(
this) - static_cast<const char*>(
nullptr);
100 : cond(bddfalse), acc({})
107 : cond(cond), acc(acc)
113 if (cond.id() < other.cond.id())
115 if (cond.id() > other.cond.id())
117 return acc < other.acc;
122 return cond.id() == other.cond.id() &&
133 template<
class Graph>
138 typedef typename Graph::edge edge;
139 typedef typename Graph::state_data_t state;
163 p_ = g_->edge_storage(p_).next_succ;
167 virtual bool done()
const override 174 SPOT_ASSERT(!done());
175 return &g_->state_data(g_->edge_storage(p_).dst);
178 virtual bdd
cond()
const override 180 SPOT_ASSERT(!done());
181 return g_->edge_data(p_).cond;
186 SPOT_ASSERT(!done());
187 return g_->edge_data(p_).acc;
211 edge_storage_t>::value,
"type mismatch");
213 typedef unsigned state_num;
214 static_assert(std::is_same<typename graph_t::state, state_num>::value,
219 mutable unsigned init_number_;
228 explicit twa_graph(
const const_twa_graph_ptr& other, prop_set p)
229 :
twa(other->get_dict()),
230 g_(other->g_), init_number_(other->init_number_)
232 copy_acceptance_of(other);
242 template <
typename State_Name,
243 typename Name_Hash = std::hash<State_Name>,
244 typename Name_Equal = std::equal_to<State_Name>>
247 template <
typename State_Name,
248 typename Name_Hash = std::hash<State_Name>,
249 typename Name_Equal = std::equal_to<State_Name>>
257 create_formula_namer()
259 return create_namer<formula>();
271 const graph_t& get_graph()
const 276 unsigned num_states()
const 281 unsigned num_edges()
const 286 void set_init_state(state_num s)
288 if (SPOT_UNLIKELY(s >= num_states()))
289 throw std::invalid_argument
290 (
"set_init_state() called with nonexisting state");
295 void set_univ_init_state(I dst_begin, I dst_end)
297 auto ns = num_states();
298 for (I i = dst_begin; i != dst_end; ++i)
299 if (SPOT_UNLIKELY(*i >= ns))
300 throw std::invalid_argument
301 (
"set_univ_init_state() called with nonexisting state");
305 void set_univ_init_state(
const std::initializer_list<state_num>& il)
307 set_univ_init_state(il.begin(), il.end());
310 state_num get_init_state_number()
const 313 if (num_states() == 0)
314 throw std::runtime_error(
"automaton has no state at all");
320 unsigned n = get_init_state_number();
321 if (SPOT_UNLIKELY(!is_existential()))
322 throw std::runtime_error
323 (
"the abstract interface does not support alternating automata");
324 return state_from_number(n);
333 if (this->iter_cache_)
337 it->recycle(s->succ);
338 this->iter_cache_ =
nullptr;
344 static constexpr
bool is_univ_dest(
const edge_storage_t& e)
346 return is_univ_dest(e.dst);
349 static constexpr
bool is_univ_dest(
unsigned s)
357 state_number(
const state* st)
const 364 state_from_number(state_num n)
const 369 std::string format_state(
unsigned n)
const;
373 return format_state(state_number(st));
382 unsigned edge_number(
const edge_storage_t& e)
const 392 twa_graph_edge_data& edge_data(
unsigned t)
402 const twa_graph_edge_data& edge_data(
unsigned t)
const 412 edge_storage_t& edge_storage(
unsigned t)
423 const edge_storage_t edge_storage(
unsigned t)
const 433 unsigned new_states(
unsigned n)
438 unsigned new_edge(
unsigned src,
unsigned dst,
442 return g_.
new_edge(src, dst, cond, acc);
445 unsigned new_acc_edge(
unsigned src,
unsigned dst,
446 bdd cond,
bool acc =
true)
449 return g_.
new_edge(src, dst, cond, this->acc().all_sets());
455 unsigned new_univ_edge(
unsigned src, I begin, I end,
462 unsigned new_univ_edge(
unsigned src, std::initializer_list<unsigned> dst,
466 return g_.
new_univ_edge(src, dst.begin(), dst.end(), cond, acc);
471 out(
unsigned src)
const 484 out_iteraser(
unsigned src)
490 univ_dests(
unsigned d)
const noexcept
492 return g_.univ_dests(d);
496 univ_dests(
const edge_storage_t& e)
const noexcept
498 return g_.univ_dests(e);
508 SPOT_DEPRECATED(
"use !is_existential() instead")
513 bool is_alternating()
const 515 return !is_existential();
521 SPOT_RETURN(g_.states());
523 SPOT_RETURN(g_.states());
526 edges()
const noexcept
539 auto edge_vector()
const 540 SPOT_RETURN(g_.edge_vector());
542 SPOT_RETURN(g_.edge_vector());
545 bool is_dead_edge(
unsigned t)
const 547 return g_.is_dead_edge(t);
552 return g_.is_dead_edge(t);
576 void merge_univ_dests();
601 void purge_dead_states();
620 typedef void (*shift_action)(
const std::vector<unsigned>& newst,
622 void purge_unreachable_states(shift_action* f =
nullptr,
623 void* action_data =
nullptr);
629 void remove_unused_ap();
637 void copy_state_names_from(
const const_twa_graph_ptr& other);
643 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
644 throw std::runtime_error
645 (
"state_acc_sets() should only be called on " 646 "automata with state-based acceptance");
647 for (
auto& t: g_.out(s))
662 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
663 throw std::runtime_error
664 (
"state_is_accepting() should only be called on " 665 "automata with state-based acceptance");
666 for (
auto& t: g_.out(s))
669 return acc().accepting(t.acc);
675 return state_is_accepting(state_number(s));
679 bool operator==(
const twa_graph& aut)
const 681 auto& dests1 = g_.dests_vector();
683 if (num_states() != aut.num_states() ||
684 num_edges() != aut.num_edges() ||
686 dests1.size() != dests2.size())
688 auto& trans1 = edge_vector();
689 auto& trans2 = aut.edge_vector();
690 if (!std::equal(trans1.begin() + 1, trans1.end(),
693 return std::equal(dests1.begin(), dests1.end(),
706 void defrag_states(std::vector<unsigned>&& newst,
unsigned used_states);
713 void dump_storage_as_dot(std::ostream& out,
714 const char* opt =
nullptr)
const;
718 #if __GNUC__ == 8 && __GNUC_MINOR__ == 2 719 # define SPOT_make_twa_graph__(...) \ 720 std::shared_ptr<twa_graph>(new twa_graph(__VA_ARGS__)) 722 # define SPOT_make_twa_graph__(...) \ 723 std::make_shared<twa_graph>(__VA_ARGS__) 730 return SPOT_make_shared_enabled__(
twa_graph, dict);
738 return SPOT_make_shared_enabled__(
twa_graph, aut, p);
746 return SPOT_make_shared_enabled__(
twa_graph, aut, p);
758 SPOT_API twa_graph_ptr
760 bool preserve_names =
false,
763 unsigned max_states = -(1
U));
state new_states(unsigned n, Args &&... args)
Create n new states.
Definition: graph.hh:696
Definition: automata.hh:26
virtual void destroy() const override
Release a state.
Definition: twagraph.hh:82
bool state_is_accepting(const state *s) const
Tell if a state is accepting.
Definition: twagraph.hh:673
const dests_vector_t & dests_vector() const
The vector used to store universal destinations.
Definition: graph.hh:1009
state new_state(Args &&... args)
Create a new states.
Definition: graph.hh:682
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:659
virtual size_t hash() const override
Hash a state.
Definition: twagraph.hh:70
internal::killer_edge_iterator< digraph > out_iteraser(state_storage_t &src)
Return a fake container with all edges leaving src, allowing erasure.
Definition: graph.hh:915
edge_storage_t & edge_storage(edge s)
return a reference to the storage of an edge
Definition: graph.hh:747
virtual std::string format_state(const state *st) const override
Format the state as a string for printing.
Definition: twagraph.hh:371
edge new_edge(state src, state dst, Args &&... args)
Create a new edge.
Definition: graph.hh:784
virtual const twa_graph_state * get_init_state() const override
Get the initial state of the automaton.
Definition: twagraph.hh:318
state_storage_t::data_t & state_data(state s)
return the State_Data associated to a state
Definition: graph.hh:729
state_storage_t & state_storage(state s)
return a reference to the storage of a state
Definition: graph.hh:711
virtual bool first() override
Position the iterator on the first successor (if any).
Definition: twagraph.hh:155
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:765
virtual bdd cond() const override
Get the condition on the edge leading to this successor.
Definition: twagraph.hh:178
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:641
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:645
virtual bool done() const override
Check whether the iteration is finished.
Definition: twagraph.hh:167
virtual int compare(const spot::state *other) const override
Compares two states (that come from the same automaton).
Definition: twagraph.hh:58
virtual const twa_graph_state * dst() const override
Get the destination state of the current edge.
Definition: twagraph.hh:172
unsigned num_edges() const
The number of edges in the automaton.
Definition: graph.hh:653
bool is_valid_edge(edge t) const
Test whether the given edge is valid.
Definition: graph.hh:981
edge index_of_edge(const edge_storage_t &tt) const
Conveart a storage reference into an edge number.
Definition: graph.hh:877
virtual acc_cond::mark_t acc() const override
Get the acceptance mark of the edge leading to this successor.
Definition: twagraph.hh:184
bool state_is_accepting(unsigned s) const
Tell if a state is accepting.
Definition: twagraph.hh:660
internal::state_out< digraph > out(state src)
Return a fake container with all edges leaving src.
Definition: graph.hh:886
virtual twa_succ_iterator * succ_iter(const state *st) const override
Get an iterator over the successors of local_state.
Definition: twagraph.hh:328
Iterator used by the on-the-fly interface of twa_graph.
Definition: twagraph.hh:134
state new_univ_dests(I dst_begin, I dst_end)
Create a new universal destination group.
Definition: graph.hh:808
Graph-based representation of a TωA.
Definition: twagraph.hh:199
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:828
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:161
An acceptance mark.
Definition: acc.hh:81
bool is_existential() const
Whether the automaton uses only existential branching.
Definition: twagraph.hh:502
Data attached to edges of a twa_graph.
Definition: twagraph.hh:94
virtual twa_graph_state * clone() const override
Duplicate a state.
Definition: twagraph.hh:77