com.mindfusion.diagramming
Class AnnealLayout

java.lang.Object
  extended by com.mindfusion.diagramming.AnnealLayout
All Implemented Interfaces:
Layout

public class AnnealLayout
extends java.lang.Object
implements Layout

Implements a simulated annealing graph layout algorithm.

Simulated Annealing is a general-purpose optimization method used to solve large-scale combinatorial problems by simulating the process of heating and cooling of metal to achieve freedom from defects. Finding a nice arrangement of a graph is a combinatorial problem that can be reduced to assigning costs to graph configurations and finding the minimum cost configuration. In that case, a cost is assigned to a graph configuration by evaluating different aesthetic criteria such as distance between nodes, length of arrows and the number of arrow crossings.

The AnnealLayout class implements a Simulated Annealing graph layout algorithm that can be used to arrange JDiagram diagrams. To arrange a diagram, create an AnnealLayout instance, set its properties and call the arrange(com.mindfusion.diagramming.Diagram) method.

The algorithm starts the simulation with the temperature set via setInitialTemperature(double), and runs several cooling stages, as set via setStages(int). At each stage the algorithm evaluates several graph configurations for each node, as set by calling setIterationsPerStage(int). At the end of each stage, the algorithm selects the configuration that has a minimum cost and decreases the temperature by multiplying it by TemperatureScale. The relative weight of an aesthetic criterion relative to the other criteria is set via the setDistributionFactor(double), setLinkLengthFactor(double), setBoundaryFactor(double) and setCrossingLinksCost(double) methods.


Constructor Summary
AnnealLayout()
          Initializes a new instance of the AnnealLayout class.
 
Method Summary
 boolean arrange(Diagram chart)
          Applies the layout to the specified Diagram.
 int getAnchoring()
          Gets a value specifying how arrows will be aligned to the anchor points of nodes.
 double getBoundaryFactor()
          Gets a value indicating how important the distance from nodes to the layout area boundaries is relatively to the other criteria considered by the algorithm.
 double getCrossingLinksCost()
          Gets a value specifying how important the low number of arrow crossings is relatively to the other criteria considered by the algorithm.
 double getDistributionFactor()
          Gets a value indicating the importance of node distribution relatively to the other criteria considered by the algorithm.
 double getInitialTemperature()
          Gets the initial temperature of the simulated annealing process.
 int getIterationsPerStage()
          Gets how many node shift iterations to perform at each stage of the algorithm.
 boolean getKeepGroupLayout()
          Gets a value indicating whether to treat each Group of nodes as a single vertex in the arranged graph.
 java.awt.geom.Rectangle2D.Float getLayoutArea()
          Gets the size of the layout area.
 double getLinkLengthFactor()
          Gets a value specifying how important the short length of arrows is relatively to the other criteria considered by the algorithm.
 int getMultipleGraphsOrientation()
          How multiple independent graphs in the diagram should be positioned relative to one another.
 double getNodeLinkCrossingCost()
          Gets a value specifying how important the low number of crossings of arrows with edges is relatively to the other criteria considered by the algorithm.
 double getNodeLinkDistFactor()
          Gets a value specifying the importance of the distance between nodes and arrows relative to the other criteria considered by the algorithm.
 double getPrecision()
          Gets the cost calculations precision.
 boolean getRandomize()
          Gets a value indicating whether the nodes should be placed at random positions when the layout routine starts.
 DiagramNode getRoot()
          Gets the diagram node that specifies which connected graph in the diagram should be arranged.
 boolean getSplitGraph()
          Whether unconnected sub-graphs should be laid out independently from each other.
 int getStages()
          Gets how many cooling stages the algorithm should simulate.
 double getTemperatureScale()
          Gets how much the simulated temperature is decreased at each stage of the algorithm.
 float getWidthHeightRatio()
          Gets what width / height ratio the layout area should have.
 void setAnchoring(int value)
          Sets a value specifying how arrows will be aligned to the anchor points of nodes.
 void setBoundaryFactor(double value)
          Sets a value indicating how important the distance from nodes to the layout area boundaries is relatively to the other criteria considered by the algorithm.
 void setCrossingLinksCost(double value)
          Sets a value specifying how important the low number of arrow crossings is relatively to the other criteria considered by the algorithm.
 void setDistributionFactor(double value)
          Sets a value indicating the importance of node distribution relatively to the other criteria considered by the algorithm.
 void setInitialTemperature(double value)
          Sets the initial temperature of the simulated annealing process.
 void setIterationsPerStage(int value)
          Sets how many node shift iterations to perform at each stage of the algorithm.
 void setKeepGroupLayout(boolean value)
          Sets a value indicating whether to treat each Group of nodes as a single vertex in the arranged graph.
 void setLayoutArea(java.awt.geom.Rectangle2D.Float value)
          Sets the size of the layout area.
 void setLinkLengthFactor(double value)
          Sets a value specifying how important the short length of arrows is relatively to the other criteria considered by the algorithm.
 void setMultipleGraphsOrientation(int value)
          How multiple independent graphs in the diagram should be positioned relative to one another.
 void setNodeLinkCrossingCost(double nodeLinkCrossingCost)
          Sets a value specifying how important the low number of crossings of arrows with edges is relatively to the other criteria considered by the algorithm.
 void setNodeLinkDistFactor(double value)
          Sets a value specifying the importance of the distance between nodes and arrows relative to the other criteria considered by the algorithm.
 void setPrecision(double precision)
          Sets the cost calculations precision.
 void setRandomize(boolean value)
          Sets a value indicating whether the nodes should be placed at random positions when the layout routine starts.
 void setRoot(DiagramNode value)
          Sets the diagram node that specifies which connected graph in the diagram should be arranged.
 void setSplitGraph(boolean value)
          Whether unconnected sub-graphs should be laid out independently from each other.
 void setStages(int value)
          Sets how many cooling stages the algorithm should simulate.
 void setTemperatureScale(double value)
          Sets how much the simulated temperature is decreased at each stage of the algorithm.
 void setWidthHeightRatio(float value)
          Sets what width / height ratio the layout area should have.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnealLayout

public AnnealLayout()
Initializes a new instance of the AnnealLayout class.

Method Detail

arrange

public boolean arrange(Diagram chart)
Applies the layout to the specified Diagram.

Specified by:
arrange in interface Layout
Parameters:
chart - A Diagram instance that should be laid out.

getRoot

public DiagramNode getRoot()
Gets the diagram node that specifies which connected graph in the diagram should be arranged.

Returns:
A DiagramNode object whose containing graph will be arranged.

setRoot

public void setRoot(DiagramNode value)
Sets the diagram node that specifies which connected graph in the diagram should be arranged.

Parameters:
value - A DiagramNode object whose containing graph will be arranged.

getKeepGroupLayout

public boolean getKeepGroupLayout()
Gets a value indicating whether to treat each Group of nodes as a single vertex in the arranged graph.

Returns:
true if groups will be treated as single graph vertices, otherwise false

setKeepGroupLayout

public void setKeepGroupLayout(boolean value)
Sets a value indicating whether to treat each Group of nodes as a single vertex in the arranged graph.

Parameters:
value - true if groups must be treated as single graph vertices, otherwise false

getAnchoring

public int getAnchoring()
Gets a value specifying how arrows will be aligned to the anchor points of nodes.

Returns:
One of the constants defined in Anchoring

setAnchoring

public void setAnchoring(int value)
Sets a value specifying how arrows will be aligned to the anchor points of nodes.

Parameters:
value - One of the constants defined in Anchoring

getDistributionFactor

public double getDistributionFactor()
Gets a value indicating the importance of node distribution relatively to the other criteria considered by the algorithm.

Returns:
A multiplier applied to the node distribution cost when evaluating the total cost of a graph configuration.

setDistributionFactor

public void setDistributionFactor(double value)
Sets a value indicating the importance of node distribution relatively to the other criteria considered by the algorithm.

Parameters:
value - A multiplier applied to the node distribution cost when evaluating the total cost of a graph configuration. The default is 40000.

getBoundaryFactor

public double getBoundaryFactor()
Gets a value indicating how important the distance from nodes to the layout area boundaries is relatively to the other criteria considered by the algorithm.

Returns:
A multiplier applied to the node-to-boundary distance cost when evaluating the total cost of a graph configuration.

setBoundaryFactor

public void setBoundaryFactor(double value)
Sets a value indicating how important the distance from nodes to the layout area boundaries is relatively to the other criteria considered by the algorithm.

Parameters:
value - A multiplier applied to the node-to-boundary distance cost when evaluating the total cost of a graph configuration. The default is 3000.

getLinkLengthFactor

public double getLinkLengthFactor()
Gets a value specifying how important the short length of arrows is relatively to the other criteria considered by the algorithm.

Returns:
A multiplier applied to the arrow length cost when evaluating the total cost of a graph configuration.

setLinkLengthFactor

public void setLinkLengthFactor(double value)
Sets a value specifying how important the short length of arrows is relatively to the other criteria considered by the algorithm.

Parameters:
value - A multiplier applied to the arrow length cost when evaluating the total cost of a graph configuration. The default is 0.25.

getCrossingLinksCost

public double getCrossingLinksCost()
Gets a value specifying how important the low number of arrow crossings is relatively to the other criteria considered by the algorithm.

Returns:
A value added to the total cost of a graph configuration for each pair of crossing arrows.

setCrossingLinksCost

public void setCrossingLinksCost(double value)
Sets a value specifying how important the low number of arrow crossings is relatively to the other criteria considered by the algorithm.

Parameters:
value - A value added to the total cost of a graph configuration for each pair of crossing arrows. The default is 100000.

getNodeLinkCrossingCost

public double getNodeLinkCrossingCost()
Gets a value specifying how important the low number of crossings of arrows with edges is relatively to the other criteria considered by the algorithm.

Returns:
A value added to the total cost of a graph configuration for each crossing of arrow and node.

setNodeLinkCrossingCost

public void setNodeLinkCrossingCost(double nodeLinkCrossingCost)
Sets a value specifying how important the low number of crossings of arrows with edges is relatively to the other criteria considered by the algorithm.

Parameters:
nodeLinkCrossingCost - A value added to the total cost of a graph configuration for each crossing of arrow and node. The default is 100000.

getNodeLinkDistFactor

public double getNodeLinkDistFactor()
Gets a value specifying the importance of the distance between nodes and arrows relative to the other criteria considered by the algorithm.

Returns:
A multiplier applied to the node-to-link distance cost when evaluating the total cost of a graph configuration.

setNodeLinkDistFactor

public void setNodeLinkDistFactor(double value)
Sets a value specifying the importance of the distance between nodes and arrows relative to the other criteria considered by the algorithm.

Parameters:
value - A multiplier applied to the node-to-link distance cost when evaluating the total cost of a graph configuration. The default is 20000.

getInitialTemperature

public double getInitialTemperature()
Gets the initial temperature of the simulated annealing process.

Returns:
A double value specifying the initial temperature of the simulated process.

setInitialTemperature

public void setInitialTemperature(double value)
Sets the initial temperature of the simulated annealing process.

Parameters:
value - A double value specifying the initial temperature of the simulated process.

getTemperatureScale

public double getTemperatureScale()
Gets how much the simulated temperature is decreased at each stage of the algorithm.

Returns:
A multiplier applied to the current temperature at the end of each cooling stage.

setTemperatureScale

public void setTemperatureScale(double value)
Sets how much the simulated temperature is decreased at each stage of the algorithm.

Parameters:
value - A multiplier applied to the current temperature at the end of each cooling stage. The default value is 0.75

getIterationsPerStage

public int getIterationsPerStage()
Gets how many node shift iterations to perform at each stage of the algorithm.

Returns:
An integer value specifying the number of iterations.

setIterationsPerStage

public void setIterationsPerStage(int value)
Sets how many node shift iterations to perform at each stage of the algorithm.

Parameters:
value - An integer value specifying the number of iterations. The default is 50

getStages

public int getStages()
Gets how many cooling stages the algorithm should simulate.

Returns:
The number of cooling stages

setStages

public void setStages(int value)
Sets how many cooling stages the algorithm should simulate.

Parameters:
value - The number of cooling stages

getLayoutArea

public java.awt.geom.Rectangle2D.Float getLayoutArea()
Gets the size of the layout area.

Returns:
The layout area coordinates.

setLayoutArea

public void setLayoutArea(java.awt.geom.Rectangle2D.Float value)
Sets the size of the layout area.

Parameters:
value - The layout area coordinates.

getWidthHeightRatio

public float getWidthHeightRatio()
Gets what width / height ratio the layout area should have.


setWidthHeightRatio

public void setWidthHeightRatio(float value)
Sets what width / height ratio the layout area should have.


getRandomize

public boolean getRandomize()
Gets a value indicating whether the nodes should be placed at random positions when the layout routine starts.


setRandomize

public void setRandomize(boolean value)
Sets a value indicating whether the nodes should be placed at random positions when the layout routine starts.


getSplitGraph

public boolean getSplitGraph()
Whether unconnected sub-graphs should be laid out independently from each other.


setSplitGraph

public void setSplitGraph(boolean value)
Whether unconnected sub-graphs should be laid out independently from each other.


getMultipleGraphsOrientation

public int getMultipleGraphsOrientation()
How multiple independent graphs in the diagram should be positioned relative to one another.


setMultipleGraphsOrientation

public void setMultipleGraphsOrientation(int value)
How multiple independent graphs in the diagram should be positioned relative to one another.


getPrecision

public double getPrecision()
Gets the cost calculations precision.


setPrecision

public void setPrecision(double precision)
Sets the cost calculations precision. 1 specifies highest precision. Accepted values are between 0.9 and 1. The algorithm completes faster when running with a lower precision, but produces slightly worse results.