Class FR91Layout
java.lang.Object
FR91Layout
A class implementing the force directed algorithm by Fruchterman and Reingold (1991)
- Version:
- jan 2024
- Author:
- Luca Castelli Aleardi, Ecole Polytechnique
-
Field Summary
FieldsModifier and TypeFieldDescriptiondoublearea of the drawing region (width times height)doublestep: by default step=1, in the original algorithm FR91protected doublecooling constant: temperature decreases (e.g.private intInput graph to drawdoubledimensions of the drawing regionintdoublestrength of the spring ("optimal distance")static intmaximum number of iterations to performprotected doubleminimal temperature (strictly positive)Jcg.geometry.Point_2[]3D positions of the vertices of the graph defining the planar layout.protected doubleinitial temperatureprotected booleandecide whether to make use of simulated annealingdoubledimensions of the drawing region -
Constructor Summary
ConstructorsConstructorDescriptionFR91Layout(AdjacencyListGraph g, double w, double h) Initialize the parameters of the force-directed method, according to the original FR91 algorithm -
Method Summary
Modifier and TypeMethodDescriptiondoubleattractiveForce(double distance) Compute the (intensity of the) attractive force between two nodes at a given distanceJcg.geometry.Vector_2[]Compute attractive forces for all vertices (between neighboring vertices)Jcg.geometry.Vector_2[]Compute repulsive forces for all vertices (between all vertices)Jcg.geometry.Vector_2Jcg.geometry.Vector_2protected voidcooling()Cooling system: the temperature decreases at each iteration of a multiplicative factor Remark: the temperature is assumed to remain strictly positive (>=minTemperature)voidDisable cooling processvoidEnable cooling processvoidPerform one iteration of the Force-Directed algorithm.doublerepulsiveForce(double distance) Compute the (intensity of the) repulsive force between two nodes at a given distancevoidrepulsiveForce(Node u, Jcg.geometry.Vector_2[] disp) Compute the resultant of all repulsive forces acting on node 'u'.Jcg.geometry.Vector_2toString()
-
Field Details
-
g
Input graph to draw -
points
public Jcg.geometry.Point_2[] points3D positions of the vertices of the graph defining the planar layout.
Remark: vertices are indexed from 0..n-1 -
maxIterations
public static int maxIterationsmaximum number of iterations to perform -
k
public double kstrength of the spring ("optimal distance") -
C
public double Cstep: by default step=1, in the original algorithm FR91 -
w
public double wdimensions of the drawing region -
h
public double hdimensions of the drawing region -
area
public double areaarea of the drawing region (width times height) -
temperature
protected double temperatureinitial temperature -
minTemperature
protected double minTemperatureminimal temperature (strictly positive) -
coolingConstant
protected double coolingConstantcooling constant: temperature decreases (e.g. linearly) at each iteration -
useCooling
protected boolean useCoolingdecide whether to make use of simulated annealing -
iterationCount
public int iterationCount -
countRepulsive
private int countRepulsive
-
-
Constructor Details
-
FR91Layout
Initialize the parameters of the force-directed method, according to the original FR91 algorithm- Parameters:
g- the input graph to draww- width of the drawing areah- height of the drawing area
-
-
Method Details
-
enableCooling
public void enableCooling()Enable cooling process -
disableCooling
public void disableCooling()Disable cooling process -
attractiveForce
public double attractiveForce(double distance) Compute the (intensity of the) attractive force between two nodes at a given distance- Parameters:
distance- distance between two nodes
-
repulsiveForce
public double repulsiveForce(double distance) Compute the (intensity of the) repulsive force between two nodes at a given distance- Parameters:
distance- distance between two nodes
-
oneIteration
public void oneIteration()Perform one iteration of the Force-Directed algorithm. Positions of vertices are updated according to their mutual attractive and repulsive forces.
This function computes first the node displacements vectors, and the updates node locations (stored in the array -
slowRepulsiveForce
-
computeRepulsiveForce
-
repulsiveForce
Compute the resultant of all repulsive forces acting on node 'u'. The result is stored in the vector 'disp' -
computeAttractiveForce
-
computeAllRepulsiveForces
public Jcg.geometry.Vector_2[] computeAllRepulsiveForces()Compute repulsive forces for all vertices (between all vertices)- Returns:
- a vector v[]: v[i] represent the geometric displacement of vertex i
-
computeAllAttractiveForces
public Jcg.geometry.Vector_2[] computeAllAttractiveForces()Compute attractive forces for all vertices (between neighboring vertices)- Returns:
- a vector v[]: v[i] represent the geometric displacement of vertex i
-
cooling
protected void cooling()Cooling system: the temperature decreases at each iteration of a multiplicative factor Remark: the temperature is assumed to remain strictly positive (>=minTemperature) -
toString
-