public class AnnealLayout extends java.lang.Object implements Layout
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 links and the number of link 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 and Description |
|---|
AnnealLayout()
Initializes a new instance of the AnnealLayout class.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
arrange(Diagram chart)
Applies the layout to the specified
Diagram. |
Anchoring |
getAnchoring()
Gets a value specifying how links 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 link 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 links is
relatively to the other criteria considered by the algorithm.
|
MultipleGraphsPlacement |
getMultipleGraphsOrientation()
Gets a value indicating how multiple independent graphs in
the diagram should be positioned relatively to each other.
|
double |
getNodeLinkCrossingCost()
Gets a value specifying how important the low number of crossings of links 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 links
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.
|
AnnealLayoutBuilder |
init()
Returns an AnnealLayoutBuilder object used to configure this AnnealLayout instance.
|
void |
setAnchoring(Anchoring value)
Sets a value specifying how links 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 link 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 links is
relatively to the other criteria considered by the algorithm.
|
void |
setMultipleGraphsOrientation(MultipleGraphsPlacement value)
Sets a value indicating how multiple independent graphs in
the diagram should be positioned relatively to each other.
|
void |
setNodeLinkCrossingCost(double nodeLinkCrossingCost)
Sets a value specifying how important the low number of crossings of links and nodes
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 links
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.
|
static AnnealLayoutBuilder |
with()
Returns an AnnealLayoutBuilder object used to configure and create new AnnealLayout instances.
|
public AnnealLayout()
public boolean arrange(Diagram chart)
Diagram.public DiagramNode getRoot()
DiagramNode object whose containing graph will be arranged.public void setRoot(DiagramNode value)
value - A DiagramNode object whose containing graph will be arranged.public boolean getKeepGroupLayout()
Group
of nodes as a single vertex in the arranged graph.true if groups will be treated as single graph vertices,
otherwise falsepublic void setKeepGroupLayout(boolean value)
Group
of nodes as a single vertex in the arranged graph.value - true if groups must be treated as single graph vertices,
otherwise falsepublic Anchoring getAnchoring()
Anchoring enumeration.public void setAnchoring(Anchoring value)
value - A member of the Anchoring enumeration.public double getDistributionFactor()
public void setDistributionFactor(double value)
value - A multiplier applied to the node distribution cost when evaluating
the total cost of a graph configuration. The default is 40000.public double getBoundaryFactor()
public void setBoundaryFactor(double value)
value - A multiplier applied to the node-to-boundary distance cost when evaluating
the total cost of a graph configuration. The default is 3000.public double getLinkLengthFactor()
public void setLinkLengthFactor(double value)
value - A multiplier applied to the link length cost when evaluating
the total cost of a graph configuration. The default is 0.25.public double getCrossingLinksCost()
public void setCrossingLinksCost(double value)
value - A value added to the total cost of a graph configuration
for each pair of crossing links. The default is 100000.public double getNodeLinkCrossingCost()
public void setNodeLinkCrossingCost(double nodeLinkCrossingCost)
nodeLinkCrossingCost - A value added to the total cost of a graph configuration
for each crossing of link and node. The default is 100000.public double getNodeLinkDistFactor()
public void setNodeLinkDistFactor(double value)
value - A multiplier applied to the node-to-link distance cost when evaluating
the total cost of a graph configuration. The default is 20000.public double getInitialTemperature()
public void setInitialTemperature(double value)
value - A double value specifying the initial temperature of the simulated process.public double getTemperatureScale()
public void setTemperatureScale(double value)
value - A multiplier applied to the current temperature at the end of each
cooling stage. The default value is 0.75public int getIterationsPerStage()
public void setIterationsPerStage(int value)
value - An integer value specifying the number of iterations. The default is 50public int getStages()
public void setStages(int value)
value - The number of cooling stagespublic java.awt.geom.Rectangle2D.Float getLayoutArea()
public void setLayoutArea(java.awt.geom.Rectangle2D.Float value)
value - The layout area coordinates.public float getWidthHeightRatio()
public void setWidthHeightRatio(float value)
public boolean getRandomize()
public void setRandomize(boolean value)
public boolean getSplitGraph()
public void setSplitGraph(boolean value)
public MultipleGraphsPlacement getMultipleGraphsOrientation()
public void setMultipleGraphsOrientation(MultipleGraphsPlacement value)
public double getPrecision()
public void setPrecision(double precision)
public static AnnealLayoutBuilder with()
AnnealLayoutBuilder instance.public AnnealLayoutBuilder init()
AnnealLayoutBuilder instance.