N
- The type of the Nodes in the graphE
- The type of the Edges in the graphpublic class ForceLayout<N extends PositionableNode,E> extends Layout<N,E>
This algorithm tries to layout a graph as if the nodes are repelled by each other, exponentially more so as they get closer to each other, while at the same time the edges act like springs to pull nodes together. These are combined to give each node a velocity and momentum, acting in tension on other nodes. If node's have a mass, this is taken into account.
The algorithm takes a number of iterations to reach equilibrium, presuming there are no other forces acting on the graph.
The behaviour of the algorithm is can be tuned by a number of parameters. Unfortunately, different graphs may require different values for certain parameters for best effect.
Constructor and Description |
---|
ForceLayout(Graph<N,E> graph,
java.awt.Dimension bound,
int maxiterations) |
ForceLayout(Graph<N,E> graph,
java.awt.Dimension bound,
int maxiterations,
double initial_temperature)
Create a ForceLayout instance, with the initial temperature set as given.
|
ForceLayout(Graph<N,E> graph,
java.awt.Dimension bound,
int maxiterations,
double initial_temperature,
double C)
Create a ForceLayout instance, with the initial temperature set as given,
and using the specific C scalar for the k parameter of the algorithm.
|
Modifier and Type | Method and Description |
---|---|
boolean |
layout(float interval)
returns true if layout can still change.
|
ForceLayout<N,E> |
setC(double C) |
ForceLayout<N,E> |
setDecay(double decay)
The velocity on each iteration is scaled by a 'temperature' factor, which
is decayed according to temperature(t+1) = temperature(t) * decay, or
temperature (t) = decay^t.
|
void |
setJiggle(double jiggle) |
ForceLayout<N,E> |
setMinkve(double minkve) |
ForceLayout<N,E> |
setMintemp(double mintemp)
Set the minimum temperature possible.
|
factory, isaLayout, maxiterations, maxiterations
public ForceLayout(Graph<N,E> graph, java.awt.Dimension bound, int maxiterations, double initial_temperature)
graph
- The Graph to act onbound
- The boundary to apply to the layout algorithmmaxiterations
- The maximum number of iterations to run for.initial_temperature
- The initial temperature scale factor to apply.for further discussion of temperature.
public ForceLayout(Graph<N,E> graph, java.awt.Dimension bound, int maxiterations, double initial_temperature, double C)
C defaults to 1.
graph
- bound
- maxiterations
- initial_temperature
- C
- scalar to apply to the k constant, which is used to calculate
the attractive and repulsive forces.public ForceLayout<N,E> setMintemp(double mintemp)
The velocity calculated for a node on each iteration is scaled by a 'temperature' factor. This temperature decays on each iteration, to simulate the algorithm getting 'colder' - the idea being to allow the algorithm to stabilise.
Generally, you want this parameter set so that in later iterations of the algorithm there is still some amount of energy attainable to allow nodes to move around, while being low enough to damp out any wild movement of nodes.
On dense graphs, and/or graphs with very well connected nodes, you will want this value to be lower, to prevent oscillations. On more evenly distributed graphs, this value can be set higher.
The default is 0.001
mintemp
- The minimum temperature that can apply. Generally this
should be 1 or less.public ForceLayout<N,E> setDecay(double decay)
This defaults to 0.94.
decay
- The decay factor to apply to the temperature. Generally it
should be <= 1. Higher values lead to a more linear decay.
Lower values to a more exponential and initially rapid
decay.setMintemp
public ForceLayout<N,E> setMinkve(double minkve)
minkve
- Sets the minimum sum of kinetic energy values, below which
the algorithm will be considered to no longer have any
movement.
Default: 0.1
public ForceLayout<N,E> setC(double C)
C
- Sets the C parameter of the algorithm, which is used to scale
the k factor of the algorithm. Increasing this factor will magnify the
repulsive and attractive forces, decreasing will minimise them. Values
around 1 will try balance nodes around the area. Values above will
tend to force many nodes against the boundary. Values below 1 will
tend to cause nodes to cluster more toward centre of the area.
Default: 1
public void setJiggle(double jiggle)
jiggle
- Adds some entropy to the algorithm. Higher values
add more jiggle. Recommended value is between
0 and 1. Defaults to 0.1.
Note that increasing this value will increase the
background 'heat' of the algorithm, and you may need
increase minkve if you're depending on it rather
than maxiterations.public boolean layout(float interval)
Layout
layout
in class Layout<N extends PositionableNode,E>