Satsuma
a delicious .NET graph library
|
Attempts to draw a graph to the plane such that a certain equilibrium is attained. More...
Public Member Functions | |
ForceDirectedLayout (IGraph graph, Func< Node, PointD > initialPositions=null) | |
void | Initialize (Func< Node, PointD > initialPositions=null) |
Initializes the layout with the given one and resets the temperature. More... | |
void | Run (double minimumTemperature=DefaultMinimumTemperature) |
Runs the algorithm until a low temperature is reached. More... | |
void | Step () |
Performs an optimization step. More... | |
Public Attributes | |
const double | DefaultMinimumTemperature = 0.01 |
The temperature where the simulated annealing should stop. More... | |
const double | DefaultStartingTemperature = 0.2 |
The default initial temperature for the simulated annealing. More... | |
const double | DefaultTemperatureAttenuation = 0.95 |
The ratio between two successive temperatures in the simulated annealing. More... | |
Properties | |
Func< double, double > | ElectricForce [get, set] |
The function defining the repulsion force between two nodes. More... | |
IGraph | Graph [get, set] |
The input graph. More... | |
Dictionary< Node, PointD > | NodePositions [get, set] |
The current layout, which assigns positions to the nodes. More... | |
Func< double, double > | SpringForce [get, set] |
The function defining the attraction force between two connected nodes. More... | |
double | Temperature [get, set] |
The current temperature in the simulated annealing. More... | |
double | TemperatureAttenuation [get, set] |
The temperature attenuation factor used during the simulated annealing. More... | |
Attempts to draw a graph to the plane such that a certain equilibrium is attained.
Models the graph as electrically charged nodes connected with springs. Nodes are attracted by the springs and repelled by electric forces.
By default, the springs behave logarithmically, and (as in reality) the electric repulsion force is inversely proportional to the square of the distance. The formulae for the attraction/repulsion forces can be configured through SpringForce and ElectricForce.
The algorithm starts from a given configuration (e.g. a random placement) and lets the forces move the graph to an equilibrium. Simulated annealing is used to ensure good convergence. Each convergence step requires O(n2) time, where n is the number of the nodes.
Force-directed layout algorithms work best for graphs with a few nodes (under about 100). Not only because of the running time, but also the probability of running into a poor local minimum is quite high for a large graph. This decreases the chance that a nice arrangement is attained.
Example:
void Satsuma.Drawing.ForceDirectedLayout.Run | ( | double | minimumTemperature = DefaultMinimumTemperature | ) |
void Satsuma.Drawing.ForceDirectedLayout.Step | ( | ) |
const double Satsuma.Drawing.ForceDirectedLayout.DefaultMinimumTemperature = 0.01 |
const double Satsuma.Drawing.ForceDirectedLayout.DefaultStartingTemperature = 0.2 |
const double Satsuma.Drawing.ForceDirectedLayout.DefaultTemperatureAttenuation = 0.95 |
|
getset |
|
getset |
|
getset |
The function defining the attraction force between two connected nodes.
Arcs are viewed as springs that want to bring the two connected nodes together. The function takes a single parameter, which is the distance of the two nodes.
The default force function is 2 ln(d).
|
getset |
|
getset |