fsmvis.engine
Class SpringModel

java.lang.Object
  |
  +--fsmvis.engine.SpringModel
Direct Known Subclasses:
NeighbourAndSampleModel

public class SpringModel
extends java.lang.Object
implements LayoutModel

See Also:
Serialized Form

Field Summary
protected static double dampingFactor
           
protected  DataItemCollection dataItems
           
protected  double dataSizeFactor
           
protected static double deltaTime
           
protected  EndCriteria endC
           
protected  java.util.ArrayList force
           
protected static double freeness
           
protected static double gravityDampingForce
           
protected static double gravityForce
           
protected static double layoutBounds
           
protected  int numIterations
           
protected  java.util.ArrayList position
           
protected  java.util.Properties properties
           
protected static double rangeHi
           
protected static double rangeLo
           
protected  long runningTime
           
protected static double springForce
           
protected  long startTime
           
protected static double timeDampingForce
           
protected static double timeForce
           
protected  double unrelatedDist
           
protected  java.util.ArrayList velocity
           
protected  Viewer viewParent
           
 
Constructor Summary
SpringModel(DataItemCollection dataItems, EndCriteria ec, Viewer v)
          constructor:
 
Method Summary
protected  void addForces(int obj1, int obj2)
          Calculates the force that will be acting between obj1 and obj2 This is based on the difference between their actual distance and their high dimensional distance.
 void calcForces(int index)
          Calculates the forces that will be exerted on dataItem with index index Calcs forces by comparing every object with every other object with indices < index.
protected  void calcGravityForce(int index)
          Method to simulate gravity acting on the system, does this by dividing the z component of the force
protected  void calcTimeForce(int index)
          Method to apply a similar effect on the fourth dimension, which I have called time, to flatten everything out to 2D
 void doIteration()
          Method to perform one iteration of the layout algorithm for this layout model
 void doNormalise()
          Instruction to normalise data for spring model
 double getApproxError()
          Calculates the approximate error in this layout, does this by calcing the value for a subset of the data set to get an approximation of the error without slowing down the layout too much.
 double getApproxVelocity()
          Returns an approximation of the average error in the data set
 double getAvgError()
          Returns the average error in the data set
 double getAvgVelocity()
          Returns the average velocity in the data set
 DataItem getDataItem(int index)
          Returns the data item at index index.
 DataItemCollection getDataItemCollection()
          Returns the dataItemCollection object that this layoutmodel is representing.
 java.util.List getDisplayableItems()
          Returns the indices of the items which are displayable.
 long getExecutionTime()
          Returns the number of milliseconds that the algorithm has been running for.
 int getNumIterations()
          Returns the number of iterations that have been carried out by this layout model
 Coordinate getPosition(int index)
          Returns the coordinate position of the object corresponding to the index index
 java.util.Properties getProperties()
          Returns the properties object used by a layout model
 double getStress()
          Calculates stress
protected  void init()
          Initalises the data structures needed for the spring model
 void initValues()
          intitialises the values held in the properties object
protected  void integrateChanges(int index)
          Integrates the changes that have already been calculated.
protected  void loadProperties()
          Initialises the properties for this object to be the properties held for this object
 void randomizePositions()
          randomizes the starting locations of the data set.
 void resetIterations()
          reset iterations
 void setDataItemCollection(DataItemCollection dataItems)
          Accessor method for the dataItems object
 void updateValues()
          called whenever the values for this layout model have been altered externally, so that the system knows to update their values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

position

protected java.util.ArrayList position

velocity

protected java.util.ArrayList velocity

force

protected java.util.ArrayList force

dataItems

protected DataItemCollection dataItems

numIterations

protected int numIterations

unrelatedDist

protected double unrelatedDist

endC

protected EndCriteria endC

properties

protected java.util.Properties properties

layoutBounds

protected static double layoutBounds

rangeLo

protected static double rangeLo

rangeHi

protected static double rangeHi

dampingFactor

protected static double dampingFactor

springForce

protected static double springForce

gravityForce

protected static double gravityForce

gravityDampingForce

protected static double gravityDampingForce

timeForce

protected static double timeForce

timeDampingForce

protected static double timeDampingForce

freeness

protected static double freeness

deltaTime

protected static double deltaTime

dataSizeFactor

protected double dataSizeFactor

startTime

protected long startTime

runningTime

protected long runningTime

viewParent

protected Viewer viewParent
Constructor Detail

SpringModel

public SpringModel(DataItemCollection dataItems,
                   EndCriteria ec,
                   Viewer v)
constructor:
Parameters:
dataItems - The data set to use for this layout
Method Detail

init

protected final void init()
Initalises the data structures needed for the spring model

loadProperties

protected void loadProperties()
Initialises the properties for this object to be the properties held for this object

initValues

public void initValues()
intitialises the values held in the properties object

doNormalise

public void doNormalise()
Instruction to normalise data for spring model

randomizePositions

public void randomizePositions()
randomizes the starting locations of the data set. to be called once at startup preferably

doIteration

public void doIteration()
                 throws TooManyIterationsException
Method to perform one iteration of the layout algorithm for this layout model
Specified by:
doIteration in interface LayoutModel

calcForces

public void calcForces(int index)
Calculates the forces that will be exerted on dataItem with index index Calcs forces by comparing every object with every other object with indices < index.
Parameters:
index - The index of the dataItem that forces are to be calculated on

addForces

protected final void addForces(int obj1,
                               int obj2)
Calculates the force that will be acting between obj1 and obj2 This is based on the difference between their actual distance and their high dimensional distance.
Parameters:
obj1 -  
obj2 -  

calcGravityForce

protected void calcGravityForce(int index)
Method to simulate gravity acting on the system, does this by dividing the z component of the force
Parameters:
index - The index of the object to calc Gravity force for

calcTimeForce

protected void calcTimeForce(int index)
Method to apply a similar effect on the fourth dimension, which I have called time, to flatten everything out to 2D
Parameters:
index - The index of the object to calc Time force for

integrateChanges

protected final void integrateChanges(int index)
Integrates the changes that have already been calculated. Uses the force and velocity calculations, to move the position based on the current velocity and then to alter the current velocity based on the forces acting on this object.
Parameters:
index - The index of the object to integrate changes for

getPosition

public Coordinate getPosition(int index)
Returns the coordinate position of the object corresponding to the index index
Specified by:
getPosition in interface LayoutModel
Parameters:
index - The index of the object
Returns:
The coordinate of the object

getDataItem

public DataItem getDataItem(int index)
Returns the data item at index index.
Specified by:
getDataItem in interface LayoutModel
Parameters:
index - The index of the data item wanted
Returns:
The data item that was at this index

getDataItemCollection

public DataItemCollection getDataItemCollection()
Returns the dataItemCollection object that this layoutmodel is representing.
Specified by:
getDataItemCollection in interface LayoutModel
Returns:
The DataItemCollection that this model is laying out

getDisplayableItems

public java.util.List getDisplayableItems()
Returns the indices of the items which are displayable. By default this returns null. However, if it was required to only display a portion of the data set at a time this method could be overriden. Anyone interested in viewing the items should call this method, if it returns null then they can use all available indices
Specified by:
getDisplayableItems in interface LayoutModel
Returns:
The indices of the displayable data items

setDataItemCollection

public void setDataItemCollection(DataItemCollection dataItems)
Accessor method for the dataItems object
Parameters:
dataItems - THe dataItemCollection to be used with this layout model

getNumIterations

public int getNumIterations()
Returns the number of iterations that have been carried out by this layout model
Specified by:
getNumIterations in interface LayoutModel
Returns:
The number of iterations that this layout model has done

getExecutionTime

public long getExecutionTime()
Returns the number of milliseconds that the algorithm has been running for.
Specified by:
getExecutionTime in interface LayoutModel
Returns:
The time in millis that the system has been running

getApproxError

public double getApproxError()
Calculates the approximate error in this layout, does this by calcing the value for a subset of the data set to get an approximation of the error without slowing down the layout too much.
Specified by:
getApproxError in interface LayoutModel
Returns:
The approximation of the avg error

getAvgError

public double getAvgError()
Returns the average error in the data set
Specified by:
getAvgError in interface LayoutModel
Returns:
the average error

getApproxVelocity

public double getApproxVelocity()
Returns an approximation of the average error in the data set
Specified by:
getApproxVelocity in interface LayoutModel
Returns:
An approx of the avg velocity

getAvgVelocity

public double getAvgVelocity()
Returns the average velocity in the data set
Specified by:
getAvgVelocity in interface LayoutModel
Returns:
the average velocity

updateValues

public void updateValues()
called whenever the values for this layout model have been altered externally, so that the system knows to update their values
Specified by:
updateValues in interface LayoutModel

getProperties

public java.util.Properties getProperties()
Returns the properties object used by a layout model
Specified by:
getProperties in interface LayoutModel
Returns:
The properties object

getStress

public double getStress()
Calculates stress
Returns:
stress

resetIterations

public void resetIterations()
reset iterations