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>
60 auto o = down_cast<const twa_graph_state*>(other);
70 virtual size_t hash()
const override
72 return reinterpret_cast<size_t>(
this);
99 : cond(bddfalse), acc({})
106 : cond(cond), acc(acc)
112 if (cond.id() < other.cond.id())
114 if (cond.id() > other.cond.id())
116 return acc < other.acc;
121 return cond.id() == other.cond.id() &&
132 template<
class Graph>
137 typedef typename Graph::edge edge;
138 typedef typename Graph::state_data_t state;
162 p_ = g_->edge_storage(p_).next_succ;
166 virtual bool done()
const override
173 SPOT_ASSERT(!done());
174 return &g_->state_data(g_->edge_storage(p_).dst);
177 virtual bdd
cond()
const override
179 SPOT_ASSERT(!done());
180 return g_->edge_data(p_).cond;
185 SPOT_ASSERT(!done());
186 return g_->edge_data(p_).acc;
212 typedef unsigned state_num;
213 static_assert(std::is_same<typename graph_t::state, state_num>::value,
218 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 bool univ = is_univ_dest(s);
289 if (SPOT_UNLIKELY((!univ && s >= num_states())
292 throw std::invalid_argument
293 (
"set_init_state() called with nonexisting state");
298 void set_univ_init_state(I dst_begin, I dst_end)
300 auto ns = num_states();
301 for (I i = dst_begin; i != dst_end; ++i)
302 if (SPOT_UNLIKELY(*i >= ns))
303 throw std::invalid_argument
304 (
"set_univ_init_state() called with nonexisting state");
308 void set_univ_init_state(
const std::initializer_list<state_num>& il)
310 set_univ_init_state(il.begin(), il.end());
313 state_num get_init_state_number()
const
316 if (num_states() == 0)
317 throw std::runtime_error(
"automaton has no state at all");
323 unsigned n = get_init_state_number();
324 if (SPOT_UNLIKELY(!is_existential()))
325 throw std::runtime_error
326 (
"the abstract interface does not support alternating automata");
327 return state_from_number(n);
333 auto s = down_cast<const typename graph_t::state_storage_t*>(st);
336 if (this->iter_cache_)
339 down_cast<twa_graph_succ_iterator<graph_t>*>(this->iter_cache_);
340 it->recycle(s->succ);
341 this->iter_cache_ =
nullptr;
347 static constexpr bool is_univ_dest(
const edge_storage_t& e)
349 return is_univ_dest(e.dst);
352 static constexpr bool is_univ_dest(
unsigned s)
360 state_number(
const state* st)
const
362 auto s = down_cast<const typename graph_t::state_storage_t*>(st);
366 const twa_graph_state*
367 state_from_number(state_num n)
const
372 std::string format_state(
unsigned n)
const;
376 return format_state(state_number(st));
381 auto* i = down_cast<const twa_graph_succ_iterator<graph_t>*>(it);
385 unsigned edge_number(
const edge_storage_t& e)
const
390 twa_graph_edge_data& edge_data(
const twa_succ_iterator* it)
395 twa_graph_edge_data& edge_data(
unsigned t)
400 const twa_graph_edge_data& edge_data(
const twa_succ_iterator* it)
const
405 const twa_graph_edge_data& edge_data(
unsigned t)
const
410 edge_storage_t& edge_storage(
const twa_succ_iterator* it)
415 edge_storage_t& edge_storage(
unsigned t)
421 edge_storage(
const twa_succ_iterator* it)
const
426 const edge_storage_t edge_storage(
unsigned t)
const
436 unsigned new_states(
unsigned n)
441 unsigned new_edge(
unsigned src,
unsigned dst,
443 acc_cond::mark_t acc = {})
445 return g_.
new_edge(src, dst, cond, acc);
448 unsigned new_acc_edge(
unsigned src,
unsigned dst,
449 bdd cond,
bool acc =
true)
452 return g_.
new_edge(src, dst, cond, this->acc().all_sets());
458 unsigned new_univ_edge(
unsigned src, I begin, I end,
460 acc_cond::mark_t acc = {})
465 unsigned new_univ_edge(
unsigned src, std::initializer_list<unsigned> dst,
467 acc_cond::mark_t acc = {})
469 return g_.
new_univ_edge(src, dst.begin(), dst.end(), cond, acc);
473 internal::state_out<const graph_t>
474 out(
unsigned src)
const
480 internal::state_out<graph_t>
486 internal::killer_edge_iterator<graph_t>
487 out_iteraser(
unsigned src)
492 internal::const_universal_dests
493 univ_dests(
unsigned d)
const noexcept
495 return g_.univ_dests(d);
498 internal::const_universal_dests
499 univ_dests(
const edge_storage_t& e)
const noexcept
501 return g_.univ_dests(e);
512 SPOT_RETURN(g_.states());
514 SPOT_RETURN(g_.states());
516 internal::all_trans<const graph_t>
517 edges() const noexcept
523 internal::all_trans<graph_t>
530 auto edge_vector() const
531 SPOT_RETURN(g_.edge_vector());
533 SPOT_RETURN(g_.edge_vector());
536 bool is_dead_edge(
unsigned t)
const
541 bool is_dead_edge(
const graph_t::edge_storage_t& t)
const
607 const std::vector<bool>* to_merge_ptr =
nullptr);
644 typedef void (*shift_action)(
const std::vector<unsigned>& newst,
646 void purge_unreachable_states(shift_action* f =
nullptr,
647 void* action_data =
nullptr);
667 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
668 throw std::runtime_error
669 (
"state_acc_sets() should only be called on "
670 "automata with state-based acceptance");
671 for (
auto& t: g_.
out(s))
686 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
687 throw std::runtime_error
688 (
"state_is_accepting() should only be called on "
689 "automata with state-based acceptance");
690 for (
auto& t: g_.
out(s))
693 return acc().accepting(t.acc);
699 return state_is_accepting(state_number(s));
703 bool operator==(
const twa_graph& aut)
const
707 if (num_states() != aut.num_states() ||
708 num_edges() != aut.num_edges() ||
710 dests1.size() != dests2.size())
712 auto& trans1 = edge_vector();
713 auto& trans2 = aut.edge_vector();
714 if (!std::equal(trans1.begin() + 1, trans1.end(),
717 return std::equal(dests1.begin(), dests1.end(),
746 unsigned used_states);
749 SPOT_DEPRECATED(
"use reference version of this method")
750 void defrag_states(std::vector<
unsigned>&& newst,
751 unsigned used_states)
753 return defrag_states(newst, used_states);
773 const char* opt =
nullptr)
const;
777#if __GNUC__ == 8 && __GNUC_MINOR__ == 2
778# define SPOT_make_twa_graph__(...) \
779 std::shared_ptr<twa_graph>(new twa_graph(__VA_ARGS__))
781# define SPOT_make_twa_graph__(...) \
782 std::make_shared<twa_graph>(__VA_ARGS__)
789 return SPOT_make_shared_enabled__(
twa_graph, dict);
797 return SPOT_make_shared_enabled__(
twa_graph, aut, p);
808 bool preserve_name_properties =
false)
810 twa_graph_ptr res = SPOT_make_shared_enabled__(
twa_graph, aut, p);
811 if (preserve_name_properties)
812 res->copy_named_properties_of(aut);
825 SPOT_API twa_graph_ptr
827 bool preserve_names =
false,
830 unsigned max_states = -(1U));
unsigned num_states() const
The number of states in the automaton.
Definition: graph.hh:657
const dests_vector_t & dests_vector() const
The vector used to store universal destinations.
Definition: graph.hh:1024
state new_states(unsigned n, Args &&... args)
Create n new states.
Definition: graph.hh:696
state new_state(Args &&... args)
Create a new states.
Definition: graph.hh:682
edge index_of_edge(const edge_storage_t &tt) const
Convert a storage reference into an edge number.
Definition: graph.hh:892
bool is_valid_edge(edge t) const
Test whether the given edge is valid.
Definition: graph.hh:996
internal::state_out< digraph > out(state src)
Return a fake container with all edges leaving src.
Definition: graph.hh:901
bool is_existential() const
Whether the automaton uses only existential branching.
Definition: graph.hh:671
state_storage_t::data_t & state_data(state s)
return the State_Data associated to a state
Definition: graph.hh:729
state new_univ_dests(I dst_begin, I dst_end)
Create a new universal destination group.
Definition: graph.hh:808
edge_storage_t & edge_storage(edge s)
return a reference to the storage of an edge
Definition: graph.hh:747
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:930
internal::all_trans< const digraph > edges() const
Return a fake container with all edges (excluding erased edges)
Definition: graph.hh:960
unsigned num_edges() const
The number of edges in the automaton.
Definition: graph.hh:665
edge_storage_t::data_t & edge_data(edge s)
return the Edge_Data of an edge.
Definition: graph.hh:765
state_storage_t & state_storage(state s)
return a reference to the storage of a state
Definition: graph.hh:711
bool is_dead_edge(unsigned t) const
Tests whether an edge has been erased.
Definition: graph.hh:1008
edge new_univ_edge(state src, I dst_begin, I dst_end, Args &&... args)
Create a new universal edge.
Definition: graph.hh:843
edge new_edge(state src, state dst, Args &&... args)
Create a new edge.
Definition: graph.hh:784
This class is used to tell parallel algorithms what resources they may use.
Definition: common.hh:155
Abstract class for states.
Definition: twa.hh:47
Iterator used by the on-the-fly interface of twa_graph.
Definition: twagraph.hh:135
virtual bool next() override
Jump to the next successor (if any).
Definition: twagraph.hh:160
virtual bdd cond() const override
Get the condition on the edge leading to this successor.
Definition: twagraph.hh:177
virtual acc_cond::mark_t acc() const override
Get the acceptance mark of the edge leading to this successor.
Definition: twagraph.hh:183
virtual bool first() override
Position the iterator on the first successor (if any).
Definition: twagraph.hh:154
virtual const twa_graph_state * dst() const override
Get the destination state of the current edge.
Definition: twagraph.hh:171
virtual bool done() const override
Check whether the iteration is finished.
Definition: twagraph.hh:166
Graph-based representation of a TωA.
Definition: twagraph.hh:199
void copy_state_names_from(const const_twa_graph_ptr &other)
Define the state names of this automaton using the names from other.
void merge_univ_dests()
Merge common universal destinations.
void merge_edges()
Merge edges that can be merged.
virtual const twa_graph_state * get_init_state() const override
Get the initial state of the automaton.
Definition: twagraph.hh:321
void kill_state(unsigned state)
Make a state dead.
unsigned merge_states_of(bool stable=true, const std::vector< bool > *to_merge_ptr=nullptr)
Like merge states, but one can chose which states are candidates for merging.
bool state_is_accepting(unsigned s) const
Tell if a state is accepting.
Definition: twagraph.hh:684
void remove_unused_ap()
Remove unused atomic propositions.
void purge_dead_states()
Remove all dead states.
void defrag_states(std::vector< unsigned > &newst, unsigned used_states)
Renumber all states, and drop some.
bool state_is_accepting(const state *s) const
Tell if a state is accepting.
Definition: twagraph.hh:697
unsigned merge_states(parallel_policy ppolicy=parallel_policy())
Merge states that can be merged.
virtual std::string format_state(const state *st) const override
Format the state as a string for printing.
Definition: twagraph.hh:374
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:665
bool is_existential() const
Whether the automaton uses only existential branching.
Definition: twagraph.hh:505
virtual twa_succ_iterator * succ_iter(const state *st) const override
Get an iterator over the successors of local_state.
Definition: twagraph.hh:331
void dump_storage_as_dot(std::ostream &out, const char *opt=nullptr) const
Print the data structures used to represent the automaton in dot's format.
Iterate over the successors of a state.
Definition: twa.hh:394
A Transition-based ω-Automaton.
Definition: twa.hh:619
unsigned num_sets() const
Number of acceptance sets used by the automaton.
Definition: twa.hh:937
twa_graph_ptr make_twa_graph(const bdd_dict_ptr &dict)
Build an explicit automaton from all states of aut,.
Definition: twagraph.hh:787
Definition: automata.hh:26
void prop_copy(const const_twa_ptr &other, prop_set p)
Copy the properties of another automaton.
Definition: twa.hh:1630
An acceptance mark.
Definition: acc.hh:84
Data attached to edges of a twa_graph.
Definition: twagraph.hh:94
Graph-based representation of a TωA.
Definition: twagraph.hh:39
virtual void destroy() const override
Release a state.
Definition: twagraph.hh:81
virtual int compare(const spot::state *other) const override
Compares two states (that come from the same automaton).
Definition: twagraph.hh:58
virtual size_t hash() const override
Hash a state.
Definition: twagraph.hh:70
virtual twa_graph_state * clone() const override
Duplicate a state.
Definition: twagraph.hh:76