org.eclipse.emf.henshin.statespace.impl
Class BasicStateSpaceManager

java.lang.Object
  extended by org.eclipse.emf.henshin.statespace.impl.StateSpaceIndexImpl
      extended by org.eclipse.emf.henshin.statespace.impl.BasicStateSpaceManager
All Implemented Interfaces:
StateSpaceIndex, StateSpaceManager
Direct Known Subclasses:
ParallelStateSpaceManager, ProfilingStateSpaceManager

public class BasicStateSpaceManager
extends StateSpaceIndexImpl
implements StateSpaceManager

Basic StateSpaceManager implementation.


Field Summary
protected  Stack<StateExplorer> explorers
          State exploration helpers.
protected  boolean ignoreDuplicateTransitions
          Flag indicating whether duplicate transitions with the same label should be ignored.
protected  int maxStateDistance
          Maximum state distance.
protected  StateDistanceMonitor stateDistanceMonitor
          State distance monitor.
protected  Object stateSpaceLock
          A lock used when accessing the state space.
 
Fields inherited from interface org.eclipse.emf.henshin.statespace.StateSpaceManager
DEBUG_ENFORCE_DETERMINISM
 
Constructor Summary
BasicStateSpaceManager(StateSpace stateSpace)
          Default constructor.
 
Method Summary
protected  StateExplorer acquireExplorer()
           
 void clearCache()
          Clear all caches of the state space index.
 State createInitialState(Model model)
          Create a new initial state to the state space.
protected  State createOpenState(Model model, int hash, State derivedFrom, int[] location)
          Create a new open state in the state space.
protected  Model deriveModel(State state, boolean fromInitial)
           
protected  List<State> exploreState(State state, boolean generateLocation)
          Explore a given state.
 List<State> exploreStates(List<State> states, boolean generateLocation)
          Explore a state.
protected  State findState(Model model, int hashCode, Collection<State> states)
           
 int getNumThreads()
          Get the number of threads used by this state manager.
 int getStateDistance(State state)
          Get the distance of a state to an initial state.
protected  boolean isOpen(State state)
           
 List<State> mergeTerminalStates()
          Merge all terminal states
protected  void refreshHelpers()
           
protected  void releaseExplorer(StateExplorer explorer)
           
 List<State> removeState(State state)
          Remove a state from the state space.
 void resetStateSpace(boolean removeInitial)
          Reset the state space managed by this instance.
protected static int[] shiftedLocation(State base, int index)
           
 void shutdown()
          Shutdown this state space manager.
 
Methods inherited from class org.eclipse.emf.henshin.statespace.impl.StateSpaceIndexImpl
addToCache, addToIndex, getCachedModel, getModel, getState, getState, getStateSpace, removeFromIndex, resetIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.emf.henshin.statespace.StateSpaceIndex
getCachedModel, getModel, getState, getStateSpace
 

Field Detail

explorers

protected final Stack<StateExplorer> explorers
State exploration helpers.


stateSpaceLock

protected final Object stateSpaceLock
A lock used when accessing the state space.


stateDistanceMonitor

protected StateDistanceMonitor stateDistanceMonitor
State distance monitor.


maxStateDistance

protected int maxStateDistance
Maximum state distance.


ignoreDuplicateTransitions

protected boolean ignoreDuplicateTransitions
Flag indicating whether duplicate transitions with the same label should be ignored.

Constructor Detail

BasicStateSpaceManager

public BasicStateSpaceManager(StateSpace stateSpace)
Default constructor.

Parameters:
stateSpace - State space.
Method Detail

refreshHelpers

protected void refreshHelpers()

isOpen

protected boolean isOpen(State state)
                  throws StateSpaceException
Throws:
StateSpaceException

createOpenState

protected final State createOpenState(Model model,
                                      int hash,
                                      State derivedFrom,
                                      int[] location)
Create a new open state in the state space. Warning: this does not check if an equivalent state exists already or whether the hash code is incorrect.

Parameters:
model - Its model.
hash - The model's hash code.
Returns:
The newly created state.

createInitialState

public final State createInitialState(Model model)
                               throws StateSpaceException
Description copied from interface: StateSpaceManager
Create a new initial state to the state space. This throws a runtime exception if the state is not contained in a resource. If there is already a state for it, it is returned instead.

Specified by:
createInitialState in interface StateSpaceManager
Parameters:
model - Model of the initial state.
Returns:
The newly created state.
Throws:
StateSpaceException - If the state space contains errors.

removeState

public final List<State> removeState(State state)
                              throws StateSpaceException
Description copied from interface: StateSpaceManager
Remove a state from the state space. Unreachable states are automatically removed afterwards and the open-attributes are updated.

Specified by:
removeState in interface StateSpaceManager
Parameters:
state - State to be removed.
Returns:
List of removed states.
Throws:
StateSpaceException - If the state space contains errors.

mergeTerminalStates

public List<State> mergeTerminalStates()
                                throws StateSpaceException
Description copied from interface: StateSpaceManager
Merge all terminal states

Specified by:
mergeTerminalStates in interface StateSpaceManager
Returns:
List of removed states.
Throws:
StateSpaceException - If the state space contains errors.

resetStateSpace

public final void resetStateSpace(boolean removeInitial)
                           throws StateSpaceException
Description copied from interface: StateSpaceManager
Reset the state space managed by this instance. This removes all derived states and all transitions.

Specified by:
resetStateSpace in interface StateSpaceManager
Throws:
StateSpaceException - On errors.

findState

protected State findState(Model model,
                          int hashCode,
                          Collection<State> states)
                   throws StateSpaceException
Throws:
StateSpaceException

getStateDistance

public int getStateDistance(State state)
Get the distance of a state to an initial state. This returns the correct distance only if the maximum state distance of the state space is positive. Otherwise the distance is not relevant and therefore not stored.

Specified by:
getStateDistance in interface StateSpaceManager
Parameters:
state - The state.
Returns:
Its distance from an initial state, or -1 if not available.

deriveModel

protected Model deriveModel(State state,
                            boolean fromInitial)
                     throws StateSpaceException
Overrides:
deriveModel in class StateSpaceIndexImpl
Throws:
StateSpaceException

exploreStates

public List<State> exploreStates(List<State> states,
                                 boolean generateLocation)
                          throws StateSpaceException
Description copied from interface: StateSpaceManager
Explore a state. This computes all outgoing transitions and their target states and adds them to the state space if they do not exist yet.

Specified by:
exploreStates in interface StateSpaceManager
Returns:
List of newly created successor states.
Throws:
StateSpaceException - If the state space contains errors.

exploreState

protected List<State> exploreState(State state,
                                   boolean generateLocation)
                            throws StateSpaceException
Explore a given state.

Parameters:
state - State to be explored.
generateLocation - Whether to generate locations for the new state.
Returns:
List of newly created successor states.
Throws:
StateSpaceException - On errors.

acquireExplorer

protected StateExplorer acquireExplorer()

releaseExplorer

protected void releaseExplorer(StateExplorer explorer)

shiftedLocation

protected static int[] shiftedLocation(State base,
                                       int index)

getNumThreads

public int getNumThreads()
Description copied from interface: StateSpaceManager
Get the number of threads used by this state manager.

Specified by:
getNumThreads in interface StateSpaceManager
Returns:
The number of used threads.

shutdown

public void shutdown()
Description copied from interface: StateSpaceManager
Shutdown this state space manager.

Specified by:
shutdown in interface StateSpaceManager

clearCache

public void clearCache()
Description copied from interface: StateSpaceIndex
Clear all caches of the state space index.

Specified by:
clearCache in interface StateSpaceIndex
Overrides:
clearCache in class StateSpaceIndexImpl