org.graffiti.plugins.algorithms.mst
Class PrimsAlgorithm

java.lang.Object
  extended by org.graffiti.plugin.AbstractParametrizable
      extended by org.graffiti.plugin.algorithm.AbstractAlgorithm
          extended by org.graffiti.plugins.algorithms.mst.PrimsAlgorithm
All Implemented Interfaces:
Algorithm, Parametrizable

public class PrimsAlgorithm
extends AbstractAlgorithm

An implementation of Prims Algorithm for computing minimum spanning trees in undirected graphs; this class supports animations.

Version:
$Revision$ $Date$
Author:
Harald

Constructor Summary
PrimsAlgorithm()
          Sole constructor; does nothing.
 
Method Summary
 void check()
          Checks whether all preconditions of the current graph are satisfied.
 void execute()
          Executes the whole algorithm.
 Parameter<?>[] getAlgorithmParameters()
          Returns a list of Parameter that are set for this algorithm.
 Animation getAnimation()
          Returns an animation for this algorithm if it supports animation.
 float getDefaultWeight()
          Returns the default weight for unlabelled edges.
 String getName()
          Returns the name of this algorithm.
 void setAlgorithmParameters(Parameter<?>[] p)
          Sets the parameters for this algorithm.
 void setDefaultWeight(float value)
          Sets the default weight for unlabelled edges.
 void setShowTreeEdges(boolean b)
          Specifies whether this algorithm's animation uses colored edges to visualize its result.
 void setStepsToPreviousStatesEnabled(boolean b)
          Specifies whether the animation of this algorithm supports steps to previous states of this algorithm.
 void setUsesAnimation(boolean b)
          Specifies whether this algorithm uses its animation (instead of running just once).
 boolean showTreeEdges()
          Returns true if this algorithm's animation uses colored edges to visualize its result.
 boolean stepsToPreviousStatesEnabled()
          Returns true if this algorithm's animation supports steps to previous states of this algorithm.
 boolean supportsAnimation()
          Returns true if this algorithm supports animation.
 boolean usesAnimation()
          Returns true if this algorithm uses its animation.
 
Methods inherited from class org.graffiti.plugin.algorithm.AbstractAlgorithm
attach, reset
 
Methods inherited from class org.graffiti.plugin.AbstractParametrizable
copyParameters, getDefaultParameters, getParameters, getUserParameters, saveUserParameters, saveUserParameters, setParameters
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.graffiti.plugin.Parametrizable
getDefaultParameters, getParameters, setParameters
 

Constructor Detail

PrimsAlgorithm

public PrimsAlgorithm()
Sole constructor; does nothing.

Method Detail

getName

public String getName()
Returns the name of this algorithm.

This implementation returns "Prim's Algorithm".

Returns:
the name of this algorithm.

getAlgorithmParameters

public Parameter<?>[] getAlgorithmParameters()
Returns a list of Parameter that are set for this algorithm.

This implementation returns a list of four parameters:

  1. a BooleanParameter that is true if this algorithm uses its animation.
  2. a BooleanParameter that ist true if this algorithm's animation supports steps to previous states.
  3. a BooleanParameter that is true if this algorithm's animation uses colored edges to show its result.
  4. a FloatParameter that specifies the default weight for edges that are not labelled by a string that parses as a float value.

Overrides:
getAlgorithmParameters in class AbstractParametrizable
Returns:
a collection of Parameter that are needed by the Algorithm.
See Also:
BooleanParameter, FloatParameter

setAlgorithmParameters

public void setAlgorithmParameters(Parameter<?>[] p)
Sets the parameters for this algorithm. Must have the same types and order as the array returned by getParameter.

See the specification of getParameters for further information on the parameters of this algorithm.

Overrides:
setAlgorithmParameters in class AbstractParametrizable
See Also:
getAlgorithmParameters()

setUsesAnimation

public void setUsesAnimation(boolean b)
Specifies whether this algorithm uses its animation (instead of running just once).

This implementation sets the first parameter of the array returned by getParameters

Parameters:
b - true if this algorithm uses its animation; false if it runs only once.
See Also:
getAlgorithmParameters()

usesAnimation

public boolean usesAnimation()
Returns true if this algorithm uses its animation.

This implementation returns the value of the first parameter of the array returned by getParameters

Returns:
true if this algorithm uses its animation.
See Also:
getAlgorithmParameters()

setStepsToPreviousStatesEnabled

public void setStepsToPreviousStatesEnabled(boolean b)
Specifies whether the animation of this algorithm supports steps to previous states of this algorithm.

This implementation sets the second parameter of the array returned by getParameters

Parameters:
b - true if this algorithm's animation supports steps to previous states, false otherwise.
See Also:
getAlgorithmParameters()

stepsToPreviousStatesEnabled

public boolean stepsToPreviousStatesEnabled()
Returns true if this algorithm's animation supports steps to previous states of this algorithm.

This implementation returns the value of the second parameter of the array returned by getParameters.

Returns:
true if this algorithm's animation supports steps to previous states of this algorithm; false otherwise.
See Also:
getAlgorithmParameters()

showTreeEdges

public boolean showTreeEdges()
Returns true if this algorithm's animation uses colored edges to visualize its result.

This implementation returns the value of the third parameter of the array returned by getParameters.

Returns:
true if this algorithm's animation uses colored edges to visualize its result.
See Also:
getAlgorithmParameters()

setShowTreeEdges

public void setShowTreeEdges(boolean b)
Specifies whether this algorithm's animation uses colored edges to visualize its result.

This implementation sets the third parameter of the array returned by getParameters.

Parameters:
b - true if this algorithm's animation uses colored edges to visualize its result; false otherwise.
See Also:
getAlgorithmParameters()

getDefaultWeight

public float getDefaultWeight()
Returns the default weight for unlabelled edges.

This implementation returns the value of the fourth parameter of the array returned by getParameters.

Returns:
the default weight for unlabelled edges.
See Also:
getAlgorithmParameters()

setDefaultWeight

public void setDefaultWeight(float value)
Sets the default weight for unlabelled edges.

This implementation sets the fourth parameter of the array returned by getParameters

Parameters:
value - the default weight for unlabelled edges.
See Also:
getAlgorithmParameters()

check

public void check()
           throws PreconditionException
Checks whether all preconditions of the current graph are satisfied.

This implementation checks whether this algorithm's graph is undirected and connected. If not it throws PreconditionException.

Specified by:
check in interface Algorithm
Overrides:
check in class AbstractAlgorithm
Throws:
PreconditionException - if this algorithm's graph is directed or not connected.
See Also:
Algorithm.check()

execute

public void execute()
Executes the whole algorithm.

This implementation simply returns if this algorithm uses its animation. Otherwise it executes Prim's algorithm for computing the minimum spanning tree in an undirected connected graph.


supportsAnimation

public boolean supportsAnimation()
Returns true if this algorithm supports animation.

This implementation delegates to usesAnimation.

Specified by:
supportsAnimation in interface Algorithm
Overrides:
supportsAnimation in class AbstractAlgorithm
Returns:
true if this algorithm supports animation.
See Also:
getAnimation(), usesAnimation()

getAnimation

public Animation getAnimation()
Returns an animation for this algorithm if it supports animation. An algorithm supports animation if supportsAnimation returns true. Throws UnsupportedOperationException otherwise.

This implementation first checks whether this algorithm supports animation. If it doesn't it throws UnsupportedOperationException . If it does, it creates a new instance of PrimsAlgorithmAnimation. If stepsToPreviousStatesEnabled returns true the returned animation will support steps to previous states of this algorithm.

Specified by:
getAnimation in interface Algorithm
Overrides:
getAnimation in class AbstractAlgorithm
Returns:
an animation for this algorithm.
Throws:
UnsupportedOperationException - if this algorithm does not support animation.
See Also:
supportsAnimation(), PrimsAlgorithmAnimation, stepsToPreviousStatesEnabled()


Generated at 2012-05-30 11:01:25 PM CEST