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>
62 auto o = down_cast<const twa_graph_state*>(other);
72 virtual size_t hash()
const override
74 return reinterpret_cast<size_t>(
this);
101 : cond(bddfalse), acc({})
109 : cond(cond), acc(acc)
116 if (cond.id() < other.
cond.id())
118 if (cond.id() > other.
cond.id())
120 return acc < other.
acc;
126 return cond.id() == other.
cond.id() &&
137 template<
class Graph>
142 typedef typename Graph::edge edge;
143 typedef typename Graph::state_data_t state;
169 p_ = g_->edge_storage(p_).next_succ;
173 virtual bool done()
const override
180 SPOT_ASSERT(!done());
181 return &g_->state_data(g_->edge_storage(p_).dst);
184 virtual bdd
cond()
const override
186 SPOT_ASSERT(!done());
187 return g_->edge_data(p_).cond;
192 SPOT_ASSERT(!done());
193 return g_->edge_data(p_).acc;
215 typedef spot::internal::edge_storage<unsigned, unsigned, unsigned,
216 internal::boxed_label
223 static_assert(std::is_same<typename graph_t::state, state_num>::value,
241 :
twa(other->get_dict()),
242 g_(other->g_), init_number_(other->init_number_)
244 copy_acceptance_of(other);
255 template <
typename State_Name,
256 typename Name_Hash = std::hash<State_Name>,
257 typename Name_Equal = std::equal_to<State_Name>>
261 template <
typename State_Name,
262 typename Name_Hash = std::hash<State_Name>,
263 typename Name_Equal = std::equal_to<State_Name>>
274 return create_namer<formula>();
312 bool univ = is_univ_dest(s);
313 if (SPOT_UNLIKELY((!univ && s >= num_states())
316 throw std::invalid_argument
317 (
"set_init_state() called with nonexisting state");
325 auto ns = num_states();
326 for (I i = dst_begin; i != dst_end; ++i)
327 if (SPOT_UNLIKELY(*i >= ns))
328 throw std::invalid_argument
329 (
"set_univ_init_state() called with nonexisting state");
336 set_univ_init_state(il.begin(), il.end());
343 if (num_states() == 0)
344 throw std::runtime_error(
"automaton has no state at all");
350 unsigned n = get_init_state_number();
351 if (SPOT_UNLIKELY(!is_existential()))
352 throw std::runtime_error
353 (
"the abstract interface does not support alternating automata");
354 return state_from_number(n);
360 auto s = down_cast<const typename graph_t::state_storage_t*>(st);
363 if (this->iter_cache_)
366 down_cast<twa_graph_succ_iterator<graph_t>*>(this->iter_cache_);
367 it->recycle(s->succ);
368 this->iter_cache_ =
nullptr;
377 return is_univ_dest(e.dst);
392 auto s = down_cast<const typename graph_t::state_storage_t*>(st);
408 return format_state(state_number(st));
414 auto* i = down_cast<const twa_graph_succ_iterator<graph_t>*>(it);
493 return g_.
new_edge(src, dst, cond, acc);
500 bdd cond,
bool acc =
true)
503 return g_.
new_edge(src, dst, cond, this->acc().all_sets());
522 return g_.
new_univ_edge(src, dst.begin(), dst.end(), cond, acc);
527 internal::state_out<const graph_t>
535 internal::state_out<graph_t>
542 internal::killer_edge_iterator<graph_t>
549 internal::const_universal_dests
556 internal::const_universal_dests
571 SPOT_RETURN(g_.states());
574 SPOT_RETURN(g_.states());
577 internal::all_trans<const
graph_t>
578 edges() const noexcept
585 internal::all_trans<graph_t>
594 SPOT_RETURN(g_.edge_vector());
597 SPOT_RETURN(g_.edge_vector());
673 const std::vector<bool>* to_merge_ptr =
nullptr);
710 typedef void (*shift_action)(
const std::vector<unsigned>& newst,
717 void* action_data =
nullptr);
737 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
738 throw std::runtime_error
739 (
"state_acc_sets() should only be called on "
740 "automata with state-based acceptance");
741 for (
auto& t: g_.
out(s))
756 if (SPOT_UNLIKELY(!(
bool)prop_state_acc()))
757 throw std::runtime_error
758 (
"state_is_accepting() should only be called on "
759 "automata with state-based acceptance");
760 for (
auto& t: g_.
out(s))
763 return acc().accepting(t.acc);
769 return state_is_accepting(state_number(s));
781 dests1.size() != dests2.size())
783 auto& trans1 = edge_vector();
785 if (!std::equal(trans1.begin() + 1, trans1.end(),
788 return std::equal(dests1.begin(), dests1.end(),
816 unsigned used_states);
819 SPOT_DEPRECATED(
"use reference version of this method")
820 void defrag_states(std::vector<
unsigned>&& newst,
821 unsigned used_states)
823 return defrag_states(newst, used_states);
851 const char* opt =
nullptr)
const;
855#if __GNUC__ == 8 && __GNUC_MINOR__ == 2
856# define SPOT_make_twa_graph__(...) \
857 std::shared_ptr<twa_graph>(new twa_graph(__VA_ARGS__))
859# define SPOT_make_twa_graph__(...) \
860 std::make_shared<twa_graph>(__VA_ARGS__)
867 return SPOT_make_shared_enabled__(
twa_graph, dict);
875 return SPOT_make_shared_enabled__(
twa_graph, aut, p);
886 bool preserve_name_properties =
false)
889 if (preserve_name_properties)
890 res->copy_named_properties_of(aut);
905 bool preserve_names =
false,
908 unsigned max_states = -(1U));
A directed graph.
Definition graph.hh:605
unsigned num_states() const
The number of states in the automaton.
Definition graph.hh:670
const dests_vector_t & dests_vector() const
The vector used to store universal destinations.
Definition graph.hh:1039
state new_states(unsigned n, Args &&... args)
Create n new states.
Definition graph.hh:709
state new_state(Args &&... args)
Create a new state.
Definition graph.hh:695
edge index_of_edge(const edge_storage_t &tt) const
Convert a storage reference into an edge number.
Definition graph.hh:907
bool is_valid_edge(edge t) const
Test whether the given edge is valid.
Definition graph.hh:1011
internal::state_out< digraph > out(state src)
Return a fake container with all edges leaving src.
Definition graph.hh:916
bool is_existential() const
Whether the automaton uses only existential branching.
Definition graph.hh:684
state_storage_t::data_t & state_data(state s)
Return the State_Data associated to a state.
Definition graph.hh:742
state new_univ_dests(I dst_begin, I dst_end)
Create a new universal destination group.
Definition graph.hh:821
internal::const_universal_dests univ_dests(state src) const
Return universal destinations for state src.
Definition graph.hh:877
edge_storage_t & edge_storage(edge s)
Return a reference to the storage of an edge.
Definition graph.hh:760
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:945
internal::all_trans< const digraph > edges() const
Return a fake container with all edges (excluding erased edges)
Definition graph.hh:975
unsigned num_edges() const
The number of edges in the automaton.
Definition graph.hh:678
edge_storage_t::data_t & edge_data(edge s)
Return the Edge_Data of an edge.
Definition graph.hh:778
state_storage_t & state_storage(state s)
Return a reference to the storage of a state.
Definition graph.hh:724
bool is_dead_edge(unsigned t) const
Test whether an edge has been erased.
Definition graph.hh:1023
internal::edge_storage< state, state, edge, internal::boxed_label< twa_graph_edge_data > > edge_storage_t
Edge storage type.
Definition graph.hh:632
edge new_univ_edge(state src, I dst_begin, I dst_end, Args &&... args)
Create a new universal edge.
Definition graph.hh:856
edge new_edge(state src, state dst, Args &&... args)
Create a new edge.
Definition graph.hh:797
A graph wrapper associating named states to graph state indices.
Definition ngraph.hh:33
This class is used to tell parallel algorithms what resources they may use.
Definition common.hh:157
Abstract class for states.
Definition twa.hh:49
Iterator used by the on-the-fly interface of twa_graph.
Definition twagraph.hh:140
virtual bool next() override
Jump to the next successor (if any).
Definition twagraph.hh:167
twa_graph_succ_iterator(const Graph *g, edge t)
Construct an iterator starting at edge t of graph g.
Definition twagraph.hh:150
virtual bdd cond() const override
Get the condition on the edge leading to this successor.
Definition twagraph.hh:184
virtual acc_cond::mark_t acc() const override
Get the acceptance mark of the edge leading to this successor.
Definition twagraph.hh:190
virtual bool first() override
Position the iterator on the first successor (if any).
Definition twagraph.hh:161
edge pos() const
Returns the index of the current edge.
Definition twagraph.hh:197
void recycle(edge t)
Reset the iterator to start from edge t.
Definition twagraph.hh:156
virtual const twa_graph_state * dst() const override
Get the destination state of the current edge.
Definition twagraph.hh:178
virtual bool done() const override
Check whether the iteration is finished.
Definition twagraph.hh:173
Graph-based representation of a TωA.
Definition twagraph.hh:207
unsigned new_univ_edge(unsigned src, I begin, I end, bdd cond, acc_cond::mark_t acc={})
Create a universal edge from src to states in [begin, end).
Definition twagraph.hh:510
void copy_state_names_from(const const_twa_graph_ptr &other)
Define the state names of this automaton using the names from other.
unsigned num_edges() const
Returns the number of edges in the automaton.
Definition twagraph.hh:304
internal::state_out< graph_t > out(unsigned src)
Returns a range over outgoing edges of state src.
Definition twagraph.hh:536
const graph_t & get_graph() const
Access the underlying digraph (const overload).
Definition twagraph.hh:292
state_num state_number(const state *st) const
Returns the state number corresponding to state pointer st.
Definition twagraph.hh:390
void merge_univ_dests()
Merge common universal destinations.
void release_formula_namer(namer< formula > *namer, bool keep_names)
Release a formula namer.
digraph< twa_graph_state, twa_graph_edge_data > graph_t
The underlying graph type.
Definition twagraph.hh:210
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:348
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.
unsigned edge_number(const twa_succ_iterator *it) const
Returns the index of the current edge of iterator it.
Definition twagraph.hh:412
graph_t g_
The underlying graph.
Definition twagraph.hh:227
internal::all_trans< graph_t > edges() noexcept
Returns a range over all edges.
Definition twagraph.hh:586
bool state_is_accepting(unsigned s) const
Tell if a state is accepting.
Definition twagraph.hh:754
unsigned new_acc_edge(unsigned src, unsigned dst, bdd cond, bool acc=true)
Create an edge from src to dst.
Definition twagraph.hh:499
unsigned state_num
Numeric type used to identify states.
Definition twagraph.hh:222
unsigned init_number_
Number of the initial state.
Definition twagraph.hh:228
namer< formula > * create_formula_namer()
Create a namer that associates formulas to states.
Definition twagraph.hh:272
void remove_unused_ap()
Remove unused atomic propositions.
twa_graph_edge_data & edge_data(const twa_succ_iterator *it)
Returns the edge data at the current position of iterator it.
Definition twagraph.hh:425
void purge_dead_states()
Remove all dead states.
void purge_unreachable_states(shift_action *f=nullptr, void *action_data=nullptr)
Remove all unreachable states.
void defrag_states(std::vector< unsigned > &newst, unsigned used_states)
Renumber all states, and drop some.
twa_graph(const const_twa_graph_ptr &other, prop_set p)
Copy another automaton, keeping only the properties in p.
Definition twagraph.hh:240
bool state_is_accepting(const state *s) const
Tell if a state is accepting.
Definition twagraph.hh:767
const edge_storage_t edge_storage(unsigned t) const
Returns edge storage for edge number t (const overload).
Definition twagraph.hh:468
state_num get_init_state_number() const
Returns the number of the initial state.
Definition twagraph.hh:340
void set_univ_init_state(I dst_begin, I dst_end)
Set a universal initial state from a range of destination states.
Definition twagraph.hh:323
static constexpr bool is_univ_dest(unsigned s)
Returns true iff destination s is a universal destination.
Definition twagraph.hh:381
spot::internal::edge_storage< unsigned, unsigned, unsigned, internal::boxed_label< twa_graph_edge_data, false > > edge_storage_t
Edge storage type (src, dst, and edge data).
Definition twagraph.hh:218
edge_storage_t & edge_storage(const twa_succ_iterator *it)
Returns the edge storage at the position of iterator it.
Definition twagraph.hh:449
const twa_graph_edge_data & edge_data(const twa_succ_iterator *it) const
Returns the edge data at the position of iterator it (const).
Definition twagraph.hh:437
unsigned num_states() const
Returns the number of states in the automaton.
Definition twagraph.hh:298
auto states() const SPOT_RETURN(g_.states())
Returns a range over all states (const).
internal::state_out< const graph_t > out(unsigned src) const
Returns a range over outgoing edges of state src (const).
Definition twagraph.hh:528
edge_storage_t & edge_storage(unsigned t)
Returns the edge storage for edge number t.
Definition twagraph.hh:455
bool is_dead_edge(const graph_t::edge_storage_t &t) const
Returns true iff edge t is a dead (removed) edge.
Definition twagraph.hh:607
void rename_states_(const std::vector< unsigned > &newst)
Rename all states.
void set_init_state(state_num s)
Set the initial state to state number s.
Definition twagraph.hh:310
unsigned merge_states(parallel_policy ppolicy=parallel_policy())
Merge states that can be merged.
unsigned new_edge(unsigned src, unsigned dst, bdd cond, acc_cond::mark_t acc={})
Create a new edge from src to dst.
Definition twagraph.hh:489
bool is_dead_edge(unsigned t) const
Returns true iff edge number t is a dead (removed) edge.
Definition twagraph.hh:601
const twa_graph_edge_data & edge_data(unsigned t) const
Returns the edge data for edge number t (const overload).
Definition twagraph.hh:443
bool operator==(const twa_graph &aut) const
Structural equality: same states, edges, labels, and acceptance.
Definition twagraph.hh:774
std::string format_state(unsigned n) const
Returns a human-readable representation of state number n.
internal::const_universal_dests univ_dests(unsigned d) const noexcept
Returns the universal destinations of dest-index d.
Definition twagraph.hh:550
unsigned new_univ_edge(unsigned src, std::initializer_list< unsigned > dst, bdd cond, acc_cond::mark_t acc={})
Create a universal edge from src to the listed destinations.
Definition twagraph.hh:518
virtual std::string format_state(const state *st) const override
Format the state as a string for printing.
Definition twagraph.hh:406
const edge_storage_t edge_storage(const twa_succ_iterator *it) const
Returns edge storage at the position of iterator it (const).
Definition twagraph.hh:462
graph_t & get_graph()
Access the underlying digraph.
Definition twagraph.hh:286
const twa_graph_state * state_from_number(state_num n) const
Returns the state pointer for state number n.
Definition twagraph.hh:398
void set_univ_init_state(const std::initializer_list< state_num > &il)
Set a universal initial state from an initializer list.
Definition twagraph.hh:334
unsigned new_state()
Create a new state and return its number.
Definition twagraph.hh:474
auto edge_vector() const SPOT_RETURN(g_.edge_vector())
Returns the raw edge storage vector (const).
static constexpr bool is_univ_dest(const edge_storage_t &e)
Returns true iff edge e has a universal destination.
Definition twagraph.hh:375
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:735
twa_graph_edge_data & edge_data(unsigned t)
Returns the edge data for edge number t.
Definition twagraph.hh:431
namer< State_Name, Name_Hash, Name_Equal > * create_namer()
Create a namer to associate custom names of type State_Name to states.
Definition twagraph.hh:265
internal::killer_edge_iterator< graph_t > out_iteraser(unsigned src)
Returns an edge-erasing iterator over outgoing edges of src.
Definition twagraph.hh:543
bool is_existential() const
Whether the automaton uses only existential branching.
Definition twagraph.hh:563
twa_graph(const bdd_dict_ptr &dict)
Construct an empty automaton using dict for BDD variables.
Definition twagraph.hh:233
virtual twa_succ_iterator * succ_iter(const state *st) const override
Get an iterator over the successors of local_state.
Definition twagraph.hh:358
unsigned new_states(unsigned n)
Create n new states; return the number of the first one.
Definition twagraph.hh:480
internal::const_universal_dests univ_dests(const edge_storage_t &e) const noexcept
Returns the universal destinations of edge e.
Definition twagraph.hh:557
unsigned edge_number(const edge_storage_t &e) const
Returns the index of edge e.
Definition twagraph.hh:419
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:425
A Transition-based ω-Automaton.
Definition twa.hh:648
unsigned num_sets() const
Number of acceptance sets used by the automaton.
Definition twa.hh:949
std::shared_ptr< bdd_dict > bdd_dict_ptr
Shared pointer to a bdd_dict.
Definition bdddict.hh:304
std::shared_ptr< const twa > const_twa_ptr
Shared pointer to a const twa.
Definition fwd.hh:36
std::shared_ptr< twa_graph > twa_graph_ptr
Shared pointer to a mutable twa_graph.
Definition fwd.hh:44
std::shared_ptr< const twa_graph > const_twa_graph_ptr
Shared pointer to a const twa_graph.
Definition fwd.hh:41
twa_graph_ptr make_twa_graph(const bdd_dict_ptr &dict)
Build an explicit automaton from all states of aut,.
Definition twagraph.hh:865
Definition automata.hh:26
An acceptance mark.
Definition acc.hh:76
A structure for selecting a set of automaton properties to copy.
Definition twa.hh:1548
Data attached to edges of a twa_graph.
Definition twagraph.hh:96
acc_cond::mark_t acc
The acceptance mark of this edge.
Definition twagraph.hh:98
bdd cond
The Boolean formula labeling this edge.
Definition twagraph.hh:97
twa_graph_edge_data(bdd cond, acc_cond::mark_t acc={}) noexcept
Construct an edge labeled with cond and acceptance mark acc.
Definition twagraph.hh:106
bool operator<(const twa_graph_edge_data &other) const
Lexicographic less-than comparison on (cond id, acc).
Definition twagraph.hh:114
bool operator==(const twa_graph_edge_data &other) const
Equality: same condition and same acceptance mark.
Definition twagraph.hh:124
Graph-based representation of a TωA.
Definition twagraph.hh:39
virtual void destroy() const override
Release a state.
Definition twagraph.hh:83
virtual int compare(const spot::state *other) const override
Compares two states (that come from the same automaton).
Definition twagraph.hh:60
virtual size_t hash() const override
Hash a state.
Definition twagraph.hh:72
virtual twa_graph_state * clone() const override
Duplicate a state.
Definition twagraph.hh:78
twa_graph_state & operator=(const twa_graph_state &) noexcept
Copy-assignment (no-op; graph states are identified by address).
Definition twagraph.hh:51
twa_graph_state(const twa_graph_state &) noexcept
Copy constructor (no-op; graph states are identified by address).
Definition twagraph.hh:46