org.graffiti.plugins.algorithms.mst.animation
Class PrimsAlgorithmAnimation

java.lang.Object
  extended by org.graffiti.plugin.algorithm.animation.AbstractAnimation
      extended by org.graffiti.plugins.algorithms.mst.animation.PrimsAlgorithmAnimation
All Implemented Interfaces:
Animation

public class PrimsAlgorithmAnimation
extends AbstractAnimation

Animated version of Prim's algorithm; supports steps to previous states. This implementation uses instances of ForwardAnimation and BidirectionalAnimation to implement its iteration logic. Both use PrimsAlgorithmStep as a first step. Depending on which instance is used, this animation acts as either a forward or bidirectional animation. You select an instance by passing the appropriate value of supportsPreviousSteps to this animation's constructor. This instance acts as a delegate for all public methods of this animation except isReady. Some of them such as supportsPreviousStep delegate directly to the enclosed instance, others such as nextStep augment the delegates functionality with additional processing. Consult the specification of these methods for further information.

Both delegates use instances of PrimsAlgorithmStep.

Version:
$Revision$ $Date$
Author:
Harald Frankenberger
See Also:
ForwardAnimation, BidirectionalAnimation, PrimsAlgorithmStep, PrimsAlgorithmAnimation(GraphAdapter, HeapAdapter, boolean)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.graffiti.plugin.algorithm.animation.Animation
Animation.GraphModificationPolicy
 
Field Summary
 
Fields inherited from interface org.graffiti.plugin.algorithm.animation.Animation
EMPTY_ANIMATION
 
Constructor Summary
PrimsAlgorithmAnimation(org.graffiti.plugins.algorithms.mst.adapters.GraphAdapter g, org.graffiti.plugins.algorithms.mst.adapters.HeapAdapter h, boolean supportsPreviousSteps)
          Initializes this animation with the given GraphProxy and HeapProxy.
 
Method Summary
 void disableGraphModificationPolicy()
          Disables the graph modification policies of all instances of PrimsAlgorithmAnimation.
 void enableGraphModificationPolicy()
          Enables the graph modification policies of all instances of PrimsAlgorithmAnimation.
 String getName()
          Returns "Prim's Algorithm".
 boolean hasNextStep()
          Returns true if this animation has a next step.
 boolean hasPreviousStep()
          Returns true if this animation has a previous step.
 boolean isCleared()
          Returns true if this animation is cleared.
 boolean isReady()
          Returns true if the preconditions of the algorithm underlying this animation are satisfied.
 void performClear()
          Resets this animation to its initial state.
 void performNextStep()
          Computes the next state of the underlying algorithm; i.e.
 void performPreviousStep()
          Computes the previous state of the underlying algorithm; i.e.
 boolean supportsClear()
          This animation supports clear; returns true.
 boolean supportsPreviousStep()
          Returns true if this animation supports steps to previous states of the underlying algorithm.
 
Methods inherited from class org.graffiti.plugin.algorithm.animation.AbstractAnimation
clear, getGraphModificationPolicy, nextStep, previousStep
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrimsAlgorithmAnimation

public PrimsAlgorithmAnimation(org.graffiti.plugins.algorithms.mst.adapters.GraphAdapter g,
                               org.graffiti.plugins.algorithms.mst.adapters.HeapAdapter h,
                               boolean supportsPreviousSteps)
Initializes this animation with the given GraphProxy and HeapProxy. If supportsPreviousSteps is true, this animation will support steps to previous states of Prim's algorithm.

Depending on the value of supportsPreviousSteps this animation is initialized either with an instance of ForwardAnimation or BidirectionalAnimation. This instance acts as a delegate for calls to all public methods except isReady.

Parameters:
g -
h -
supportsPreviousSteps -
Method Detail

isReady

public boolean isReady()
Returns true if the preconditions of the algorithm underlying this animation are satisfied.

This implementation returns true if the underlying graph of this animation is undirected and connected.

Specified by:
isReady in interface Animation
Specified by:
isReady in class AbstractAnimation
Returns:
true if the preconditions of the algoritm underlying this animation are satisfied.

hasNextStep

public boolean hasNextStep()
Returns true if this animation has a next step.

This implementation first checks whether this animation is ready. If not it throws IllegalStateException. Otherwise it checks whether this animation is cleared. If so, it returns true if the underlying graph is not empty. Otherwise it delegates to hasNextStep of its enclosed Animation instance.

Specified by:
hasNextStep in interface Animation
Specified by:
hasNextStep in class AbstractAnimation
Returns:
true if this animation has a next step.

supportsPreviousStep

public boolean supportsPreviousStep()
Returns true if this animation supports steps to previous states of the underlying algorithm.

This implementation delegates to supportsPreviousStep of its enclosed Animation instance.

Specified by:
supportsPreviousStep in interface Animation
Overrides:
supportsPreviousStep in class AbstractAnimation
Returns:
true if this animation supports steps to previous states of the underlying algorithm.

hasPreviousStep

public boolean hasPreviousStep()
Returns true if this animation has a previous step.

This implementation first checks whether this animation is ready. If not it throws IllegalStateException. Otherwise it delegates to hasPreviousStep of its enclosed Animation instance.

Specified by:
hasPreviousStep in interface Animation
Overrides:
hasPreviousStep in class AbstractAnimation
Returns:
true if this animation has a previous step.
Throws:
IllegalStateException - if this animation is not ready.
See Also:
Animation.previousStep(), Animation.supportsPreviousStep()

performNextStep

public void performNextStep()
Computes the next state of the underlying algorithm; i.e. moves the animation one step forward.

This implementation first checks whether this animation is ready. If not it throws IllegalStateException. Otherwise if proceeds as follows:

  1. if this animation is newly created or cleared, it initializes this animation's data; i.e. adding attributes to the graph, nodes and edges, adding nodes to the heap, etc.
  2. the delegate's nextStep method is called.
  3. if this animation does not have another next step, this animations data are cleaned up; i.e. basically retaining only those attributes, that are of interest for further processing of the graph.

Overrides:
performNextStep in class AbstractAnimation
Throws:
IllegalStateException - if this animation does not have a next step.
IllegalStateException - if this animation is not ready.
See Also:
hasNextStep(), isReady()

performPreviousStep

public void performPreviousStep()
Computes the previous state of the underlying algorithm; i.e. moves this animation one step backwards.

This implementation first checks whether this animation is ready. If not it throws IllegalStateException. Otherwise it delegates to previousStep of the enclosed Animation instance.

Overrides:
performPreviousStep in class AbstractAnimation
Throws:
IllegalStateException - if this animation does not have a previous step or does not support steps to previous states at all.
IllegalStateException - if this animation is not ready.
UnsupportedOperationException - if this animation does not support steps to previous states.
See Also:
supportsPreviousStep(), hasPreviousStep(), isReady()

supportsClear

public boolean supportsClear()
This animation supports clear; returns true.

Specified by:
supportsClear in interface Animation
Overrides:
supportsClear in class AbstractAnimation
Returns:
true.
See Also:
AbstractAnimation.clear(), AbstractAnimation.isCleared()

isCleared

public boolean isCleared()
Returns true if this animation is cleared.

Specified by:
isCleared in interface Animation
Overrides:
isCleared in class AbstractAnimation
Returns:
true if this animation is cleared.
See Also:
AbstractAnimation.supportsClear(), AbstractAnimation.clear()

performClear

public void performClear()
Resets this animation to its initial state.

This implementation first calls clear on this animation's delegate. Then this animations GraphProxy and HeapProxy instance are cleared.

Overrides:
performClear in class AbstractAnimation
See Also:
GraphAdapter.clear(), HeapAdapter.clear()

getName

public String getName()
Returns "Prim's Algorithm".

Specified by:
getName in interface Animation
Overrides:
getName in class AbstractAnimation
Returns:
the name of this animation.

enableGraphModificationPolicy

public void enableGraphModificationPolicy()
Enables the graph modification policies of all instances of PrimsAlgorithmAnimation.

Overrides:
enableGraphModificationPolicy in class AbstractAnimation
See Also:
AbstractAnimation.graphModificationPolicy

disableGraphModificationPolicy

public void disableGraphModificationPolicy()
Disables the graph modification policies of all instances of PrimsAlgorithmAnimation.

Overrides:
disableGraphModificationPolicy in class AbstractAnimation
See Also:
AbstractAnimation.graphModificationPolicy


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