fr.inria.opengve.bridge.algorithms
Class StepAlgo<V,E extends Link<V>>

java.lang.Object
  extended by java.util.Observable
      extended by fr.inria.opengve.bridge.algorithms.StepAlgo<V,E>
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
Dijkstra, EdmondsKarp, Kruskal, KShortestPaths, NagamochiMinCut, PrimST, ShortestPathWithSingleOrigin

public abstract class StepAlgo<V,E extends Link<V>>
extends java.util.Observable
implements java.lang.Runnable

StepAlgo is a class wich provides a way of running an algorithm step by step.

The goal is to implement an algorithm in two way: the common way where the algorithm is running as fast as possible. The other way is to perform demos. We want in this case, pause each step of the algo during some seconds or waitings notification. This class implements this behavior.

Note that this class is derivated from Runnable wich implement the Thread system.

For optimisation reason you must set the step mode in the constructor (use of final modifier).

This class extends the Observable class but the notification mechanism is only activate when the class is in "demoMode". There is five kinds of notifications (StepAlgo.StepAlgoMessage) :

- StepAlgo.StepAlgoMessageType.PAUSE_NOTIFICATION for notify that algorithms leave a pause.

- StepAlgo.StepAlgoMessageType.END_NOTIFICATION for notify that algorithms call ends() method.

- StepAlgo.StepAlgoMessageType.DISPLAY_GRAPH_NEW_WINDOW send a request to display a graph in a new window.

- StepAlgo.StepAlgoMessageType.EDGES_LABEL send a request to change edges labels.

- StepAlgo.StepAlgoMessageType.VERTICES_LABEL send a request to change vertices labels.

This class can be use with mascoptLib.gui.stepAlgoGui.StepAlgoGui for adding graphic representation.


Nested Class Summary
 class StepAlgo.StepAlgoMessage
          This class is used by StepAlgo to notify this obsevers.
static class StepAlgo.StepAlgoMessageType
          Enum of the type of message.
 
Constructor Summary
StepAlgo(boolean demoMode)
          Constructor that permit to specify the step by step mode.
 
Method Summary
 void ends()
          Indicate that this algorithm is terminated.
 boolean getDemoMode()
          Say if the algorithm is in demo mode ie step by step.
 boolean getStepMode()
          Say if the algorithms stop in pause().
 boolean isEnded()
          As the algorithm is run as a thread, we want to know when it ends.
 void nextStep()
          When calling nextStep, the algorithm is unpaused.
protected  void notifyGraphDisplayRequest(Graph<V,E> g)
          Send a graphic request.
protected  void notifyGraphDisplayRequest(Graph<V,E> g, java.lang.String name)
          Send a graphic request.
protected  void notifyLabelEdgesRequest(Graph<V,E> g, Map m, java.lang.Object context, java.lang.String label)
          Request a edges label display for a graph.
protected  void notifyLabelVerticesRequest(Graph<V,E> g, Map m, java.lang.Object context, java.lang.String label)
          Request a vertices label display for a graph.
 void pause()
          Give a method to put a pause in your algorithm.
abstract  void run()
          Run the algorithm.
 void setPauseMode(boolean pauseMode)
          Change the behavior of pause() methods.
 void setTime(int time)
          Set wait time in milliseconds
 java.lang.Thread start()
          Launch the algorithm
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StepAlgo

public StepAlgo(boolean demoMode)
Constructor that permit to specify the step by step mode.

Parameters:
demoMode - The step by step mode of the algorithm.
Method Detail

setTime

public void setTime(int time)
Set wait time in milliseconds

Parameters:
time - the time to wait between steps

start

public java.lang.Thread start()
Launch the algorithm

Returns:
Return a pointer on the newly created threads.

nextStep

public void nextStep()
When calling nextStep, the algorithm is unpaused.


isEnded

public final boolean isEnded()
As the algorithm is run as a thread, we want to know when it ends.

Returns:
a boolean saying if the algorithm ended.

ends

public void ends()
Indicate that this algorithm is terminated.


setPauseMode

public void setPauseMode(boolean pauseMode)
Change the behavior of pause() methods.

Parameters:
pauseMode - true for waiting notification and false to wait a given time (setTime(int)).

getStepMode

public final boolean getStepMode()
Say if the algorithms stop in pause().

Returns:
true if the algorithm pause in pause() and false otherwise.

getDemoMode

public final boolean getDemoMode()
Say if the algorithm is in demo mode ie step by step.


pause

public final void pause()
Give a method to put a pause in your algorithm.


run

public abstract void run()
Run the algorithm.

Specified by:
run in interface java.lang.Runnable

notifyGraphDisplayRequest

protected final void notifyGraphDisplayRequest(Graph<V,E> g)
Send a graphic request.

Parameters:
g - The graph to display.

notifyGraphDisplayRequest

protected final void notifyGraphDisplayRequest(Graph<V,E> g,
                                               java.lang.String name)
Send a graphic request.

Parameters:
g - The graph to display.
name - The name of the windows

notifyLabelEdgesRequest

protected final void notifyLabelEdgesRequest(Graph<V,E> g,
                                             Map m,
                                             java.lang.Object context,
                                             java.lang.String label)
Request a edges label display for a graph.

Parameters:
g - The graph.
m - The map to use to resolve names.
context - The context used to resolves names.
label - The label definition.

notifyLabelVerticesRequest

protected final void notifyLabelVerticesRequest(Graph<V,E> g,
                                                Map m,
                                                java.lang.Object context,
                                                java.lang.String label)
Request a vertices label display for a graph.

Parameters:
g - The graph.
m - The map to use to resolve names.
context - The context used to resolves names.
label - The label definition.


Copyright © 2009 INRIA (Projet Mascotte). All Rights Reserved.