(state_ptr_equal, state_ptr_hash): New functors. * src/tgba/statebdd.hh, src/tgba/statebdd.cc (state_bdd::hash): New method. * src/tgba/tgbaexplicit.hh, src/tgba/tgbaexplicit.cc (state_explicit::hash): New method. (ns_map, sn_map): Use Sgi::hash_map instead of std::map. * src/tgba/tgbaproduct.hh, src/tgba/tgbaproduct.cc (state_product::hash): New method. * src/tgba/tgbatba.cc (state_tba_proxy::hash): New method. * src/tgbaalgos/lbtt.cc (acp_seen, todo_set, seen_map): Redefine using Sgi::hash_map or Sgi::hash_set. (lbtt_reachable): Don't erase a key that is pointed to by an iterator. * src/tgbaalgos/reachiter.cc (tgba_reachable_iterator::~tgba_reachable_iterator): Likewise. * src/tgbaalgos/magic.cc (magic_search::~magic_search()): Likewise. * src/tgbaalgos/magic.hh (hash_type): Redefine using Sgi::hash_map. * src/tgbaalgos/reachiter.hh (seen_map): Redefine using Sgi::hash_map. * iface/gspn/gspn.cc (state_gspn::hash): New method. * src/misc/hash.hh (string_hash): New functor.
96 lines
2.9 KiB
C++
96 lines
2.9 KiB
C++
#ifndef SPOT_TGBAALGOS_REACHITER_HH
|
|
# define SPOT_TGBAALGOS_REACHITER_HH
|
|
|
|
#include <map>
|
|
#include "tgba/tgba.hh"
|
|
#include <stack>
|
|
#include <deque>
|
|
|
|
namespace spot
|
|
{
|
|
/// \brief Iterate over all reachable states of a spot::tgba.
|
|
class tgba_reachable_iterator
|
|
{
|
|
public:
|
|
tgba_reachable_iterator(const tgba* a);
|
|
virtual ~tgba_reachable_iterator();
|
|
|
|
/// \brief Iterate over all reachable states of a spot::tgba.
|
|
///
|
|
/// This is a template method that will call add_state(), next_state(),
|
|
/// start(), end(), process_state(), and process_link(), while it
|
|
/// iterate over state.
|
|
void run();
|
|
|
|
/// \name Todo list management.
|
|
///
|
|
/// spot::tgba_reachable_iterator_depth_first and
|
|
/// spot::tgba_reachable_iterator_breadth_first offer two precanned
|
|
/// implementations for these functions.
|
|
/// \{
|
|
/// \brief Called by run() to register newly discovered states.
|
|
virtual void add_state(const state* s) = 0;
|
|
/// \brief Called by run() to obtain the
|
|
virtual const state* next_state() = 0;
|
|
/// \}
|
|
|
|
/// Called by run() before starting its iteration.
|
|
virtual void start();
|
|
/// Called by run() once all states have been explored.
|
|
virtual void end();
|
|
|
|
/// Called by run() to process a state.
|
|
///
|
|
/// \param s The current state.
|
|
/// \param n An unique number assigned to \a s.
|
|
/// \param si The spot::tgba_succ_iterator for \a s.
|
|
virtual void process_state(const state* s, int n, tgba_succ_iterator* si);
|
|
/// Called by run() to process a transition.
|
|
///
|
|
/// \param in The source state number.
|
|
/// \param out The destination state number.
|
|
/// \param si The spot::tgba_succ_iterator positionned on the current
|
|
/// transition.
|
|
virtual void process_link(int in, int out, const tgba_succ_iterator* si);
|
|
|
|
protected:
|
|
const tgba* automata_; ///< The spot::tgba to explore.
|
|
|
|
typedef Sgi::hash_map<const state*, int,
|
|
state_ptr_hash, state_ptr_equal> seen_map;
|
|
seen_map seen; ///< States already seen.
|
|
};
|
|
|
|
/// \brief An implementation of spot::tgba_reachable_iterator that browses
|
|
/// states depth first.
|
|
class tgba_reachable_iterator_depth_first : public tgba_reachable_iterator
|
|
{
|
|
public:
|
|
tgba_reachable_iterator_depth_first(const tgba* a);
|
|
|
|
virtual void add_state(const state* s);
|
|
virtual const state* next_state();
|
|
|
|
protected:
|
|
std::stack<const state*> todo; ///< A stack of state yet to explore.
|
|
};
|
|
|
|
/// \brief An implementation of spot::tgba_reachable_iterator that browses
|
|
/// states breadth first.
|
|
class tgba_reachable_iterator_breadth_first : public tgba_reachable_iterator
|
|
{
|
|
public:
|
|
tgba_reachable_iterator_breadth_first(const tgba* a);
|
|
|
|
virtual void add_state(const state* s);
|
|
virtual const state* next_state();
|
|
|
|
protected:
|
|
std::deque<const state*> todo; ///< A queue of state yet to explore.
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif // SPOT_TGBAALGOS_REACHITER_HH
|