Package org.jgrapht.alg.drawing
Class FRLayoutAlgorithm2D<V,E>
- java.lang.Object
-
- org.jgrapht.alg.drawing.FRLayoutAlgorithm2D<V,E>
-
- Type Parameters:
V
- the vertex typeE
- the edge type
- All Implemented Interfaces:
LayoutAlgorithm2D<V,E>
- Direct Known Subclasses:
IndexedFRLayoutAlgorithm2D
public class FRLayoutAlgorithm2D<V,E> extends java.lang.Object
Fruchterman and Reingold Force-Directed Placement Algorithm. The algorithm belongs in the broad category of force directed graph drawing algorithms and is described in the paper:- Thomas M. J. Fruchterman and Edward M. Reingold. Graph drawing by force-directed placement. Software: Practice and experience, 21(11):1129--1164, 1991.
- Author:
- Dimitrios Michail
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
FRLayoutAlgorithm2D.InverseLinearTemperatureModel
An inverse linear temperature model.static interface
FRLayoutAlgorithm2D.TemperatureModel
A general interface for a temperature model.
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_ITERATIONS
Default number of iterationsstatic double
DEFAULT_NORMALIZATION_FACTOR
Default normalization factor when calculating optimal distanceprotected java.util.function.Function<V,Point2D>
initializer
A model initializerprotected int
iterations
protected double
normalizationFactor
protected double
optimalDistance
protected java.util.Random
rng
protected java.util.function.BiFunction<LayoutModel2D<V>,java.lang.Integer,FRLayoutAlgorithm2D.TemperatureModel>
temperatureModelSupplier
-
Constructor Summary
Constructors Constructor Description FRLayoutAlgorithm2D()
Create a new layout algorithmFRLayoutAlgorithm2D(int iterations)
Create a new layout algorithmFRLayoutAlgorithm2D(int iterations, double normalizationFactor)
Create a new layout algorithmFRLayoutAlgorithm2D(int iterations, double normalizationFactor, java.util.function.BiFunction<LayoutModel2D<V>,java.lang.Integer,FRLayoutAlgorithm2D.TemperatureModel> temperatureModelSupplier, java.util.Random rng)
Create a new layout algorithmFRLayoutAlgorithm2D(int iterations, double normalizationFactor, java.util.Random rng)
Create a new layout algorithm
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected double
attractiveForce(double distance)
Calculate the attractive force.protected java.util.Map<V,Point2D>
calculateAttractiveForces(Graph<V,E> graph, LayoutModel2D<V> model)
Calculate the repulsive forces between vertices connected with edges.protected java.util.Map<V,Point2D>
calculateRepulsiveForces(Graph<V,E> graph, LayoutModel2D<V> model)
Calculate the repulsive forces between verticesjava.util.function.Function<V,Point2D>
getInitializer()
Get the initializerprotected void
init(Graph<V,E> graph, LayoutModel2D<V> model)
Initialize a model using the initializer.void
layout(Graph<V,E> graph, LayoutModel2D<V> model)
Layout a graph.protected double
repulsiveForce(double distance)
Calculate the repulsive force.void
setInitializer(java.util.function.Function<V,Point2D> initializer)
Set the initializer
-
-
-
Field Detail
-
DEFAULT_ITERATIONS
public static final int DEFAULT_ITERATIONS
Default number of iterations- See Also:
- Constant Field Values
-
DEFAULT_NORMALIZATION_FACTOR
public static final double DEFAULT_NORMALIZATION_FACTOR
Default normalization factor when calculating optimal distance- See Also:
- Constant Field Values
-
rng
protected java.util.Random rng
-
optimalDistance
protected double optimalDistance
-
normalizationFactor
protected double normalizationFactor
-
iterations
protected int iterations
-
temperatureModelSupplier
protected java.util.function.BiFunction<LayoutModel2D<V>,java.lang.Integer,FRLayoutAlgorithm2D.TemperatureModel> temperatureModelSupplier
-
initializer
protected java.util.function.Function<V,Point2D> initializer
A model initializer
-
-
Constructor Detail
-
FRLayoutAlgorithm2D
public FRLayoutAlgorithm2D()
Create a new layout algorithm
-
FRLayoutAlgorithm2D
public FRLayoutAlgorithm2D(int iterations)
Create a new layout algorithm- Parameters:
iterations
- number of iterations
-
FRLayoutAlgorithm2D
public FRLayoutAlgorithm2D(int iterations, double normalizationFactor)
Create a new layout algorithm- Parameters:
iterations
- number of iterationsnormalizationFactor
- normalization factor for the optimal distance
-
FRLayoutAlgorithm2D
public FRLayoutAlgorithm2D(int iterations, double normalizationFactor, java.util.Random rng)
Create a new layout algorithm- Parameters:
iterations
- number of iterationsnormalizationFactor
- normalization factor for the optimal distancerng
- the random number generator
-
FRLayoutAlgorithm2D
public FRLayoutAlgorithm2D(int iterations, double normalizationFactor, java.util.function.BiFunction<LayoutModel2D<V>,java.lang.Integer,FRLayoutAlgorithm2D.TemperatureModel> temperatureModelSupplier, java.util.Random rng)
Create a new layout algorithm- Parameters:
iterations
- number of iterationsnormalizationFactor
- normalization factor for the optimal distancetemperatureModelSupplier
- a simulated annealing temperature model supplierrng
- the random number generators
-
-
Method Detail
-
layout
public void layout(Graph<V,E> graph, LayoutModel2D<V> model)
Description copied from interface:LayoutAlgorithm2D
Layout a graph.- Parameters:
graph
- the graphmodel
- the layout model to use
-
attractiveForce
protected double attractiveForce(double distance)
Calculate the attractive force.- Parameters:
distance
- the distance- Returns:
- the force
-
repulsiveForce
protected double repulsiveForce(double distance)
Calculate the repulsive force.- Parameters:
distance
- the distance- Returns:
- the force
-
calculateRepulsiveForces
protected java.util.Map<V,Point2D> calculateRepulsiveForces(Graph<V,E> graph, LayoutModel2D<V> model)
Calculate the repulsive forces between vertices- Parameters:
graph
- the graphmodel
- the model- Returns:
- the displacement per vertex due to the repulsive forces
-
calculateAttractiveForces
protected java.util.Map<V,Point2D> calculateAttractiveForces(Graph<V,E> graph, LayoutModel2D<V> model)
Calculate the repulsive forces between vertices connected with edges.- Parameters:
graph
- the graphmodel
- the model- Returns:
- the displacement per vertex due to the attractive forces
-
getInitializer
public java.util.function.Function<V,Point2D> getInitializer()
Get the initializer- Returns:
- the initializer
-
setInitializer
public void setInitializer(java.util.function.Function<V,Point2D> initializer)
Set the initializer- Parameters:
initializer
- the initializer
-
init
protected void init(Graph<V,E> graph, LayoutModel2D<V> model)
Initialize a model using the initializer.- Parameters:
graph
- the graphmodel
- the model
-
-