spot  1.0.1
Classes | Public Member Functions | Protected Types | Protected Attributes | Private Member Functions | List of all members
spot::enumerate_cycles Class Reference

Enumerate elementary cycles in a SCC. More...

#include <tgbaalgos/cycles.hh>

Collaboration diagram for spot::enumerate_cycles:
Collaboration graph

Classes

struct  dfs_entry
struct  state_info

Public Member Functions

 enumerate_cycles (const scc_map &map)
virtual ~enumerate_cycles ()
void run (unsigned scc)
 Run in SCC scc, and call cycle_found() for any new elementary cycle found.
virtual bool cycle_found (const state *start)
 Called whenever a cycle was found.

Protected Types

typedef Sgi::hash_set< const
state *, state_ptr_hash,
state_ptr_equal
set_type
typedef Sgi::hash_map< const
state *, state_info,
state_ptr_hash,
state_ptr_equal
hash_type
typedef hash_type::iterator tagged_state
typedef std::deque< dfs_entrydfs_stack

Protected Attributes

hash_type tags_
const tgbaaut_
const scc_mapsm_
dfs_stack dfs_

Private Member Functions

tagged_state tag_state (const state *s)
void push_state (tagged_state ts)
void nocycle (tagged_state x, tagged_state y)
void unmark (tagged_state y)

Detailed Description

Enumerate elementary cycles in a SCC.

This class implements a non-recursive version of the algorithm
on page 170 of:
@verbatim 

/// {loizou.82.is, /// author = {George Loizou and Peter Thanisch}, /// title = {Enumerating the Cycles of a Digraph: A New /// Preprocessing Strategy}, /// journal = {Information Sciences}, /// year = {1982}, /// volume = {27}, /// number = {3}, /// pages = {163–182}, /// month = aug /// } /// (the additional preprocessings described later in that paper are not implemented).

It should be noted that although the above paper does not consider multiple arcs and self-loops in its definitions, the algorithm they present works as expected in these cases.

For our purpose an elementary cycle is a sequence of transitions that form a cycle and that visit a state at most once. We may have two cycles that visit the same states in the same order if some pair of states are connected by several transitions. Also A cycle may visit only one state if it is a self-loop.

We represent a cycle by a sequence of succ_iterator objects positioned on the transition contributing to the cycle. These succ_itertor are stored, along with their source state, in the dfs_ stack. Only the last portion of this stack may form a cycle.

The class constructor takes an scc_map that should already have been built for its automaton. Calling run(n) will enumerate all elementary cycles in SCC #n. Each time an SCC is found, the method cycle_found(s) is called with the initial state s of the cycle: the cycle is constituted from all the states that are on the dfs_ stack after s (including s).

You should inherit from this class and redefine the cycle_found() method to perform any work you would like to do on the enumerated cycles. If cycle_found() returns false, the run() method will terminate. If it returns true, the run() method will search for the next elementary cycle and call cycle_found() again if it finds another cycle.

Member Typedef Documentation

typedef std::deque<dfs_entry> spot::enumerate_cycles::dfs_stack
protected
typedef hash_type::iterator spot::enumerate_cycles::tagged_state
protected

Constructor & Destructor Documentation

spot::enumerate_cycles::enumerate_cycles ( const scc_map map)
virtual spot::enumerate_cycles::~enumerate_cycles ( )
inlinevirtual

Member Function Documentation

virtual bool spot::enumerate_cycles::cycle_found ( const state start)
virtual

Called whenever a cycle was found.

The cycle uses all the states from the dfs stack, starting from the one labeled start. The iterators in the DFS stack are all pointing to the transition considered for the cycle.

This method is not const so you can modify private variables to your subclass, but it should definitely NOT modify the dfs stack or the tags map.

The default implementation, not very useful, will print the states in the cycle on std::cout.

This method method should return false iff no more cycles need should be enumerated by run().

void spot::enumerate_cycles::nocycle ( tagged_state  x,
tagged_state  y 
)
private
void spot::enumerate_cycles::push_state ( tagged_state  ts)
private
void spot::enumerate_cycles::run ( unsigned  scc)

Run in SCC scc, and call cycle_found() for any new elementary cycle found.

It is safe to call this method multiple times, for instance to enumerate the cycle of each SCC.

tagged_state spot::enumerate_cycles::tag_state ( const state s)
private
void spot::enumerate_cycles::unmark ( tagged_state  y)
private

Member Data Documentation

const tgba* spot::enumerate_cycles::aut_
protected
dfs_stack spot::enumerate_cycles::dfs_
protected
const scc_map& spot::enumerate_cycles::sm_
protected
hash_type spot::enumerate_cycles::tags_
protected

The documentation for this class was generated from the following file:

Please comment this page and report errors about it on the RefDocComments page.
Generated on Wed Jan 23 2013 15:00:03 for spot by doxygen 1.8.1.2