|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdiva.graph.layout.AbstractGlobalLayout
diva.graph.layout.GridAnnealingLayout
public class GridAnnealingLayout
A simple layout which places nodes on a grid using a cost function. It performs the following simple-minded algorithm:
Red |
Field Summary | |
---|---|
protected double |
_cool
The cooling constant. |
protected int |
_gh
The grid height. |
protected java.lang.Object |
_graph
The original graph that is passed in by the user on which the layout is applied. |
protected java.lang.Object[][] |
_grid
The current grid configuration as the algorithm progresses. |
protected int |
_gw
The grid width. |
protected java.util.HashMap |
_map
A mapping from nodes to their corresponding logical grid positions, stored as integer arrays of length 2. |
protected double |
_minCost
The relative cost of the best grid configuration so far as the algorithm progresses. |
protected java.lang.Object[][] |
_minGrid
The best grid configuration so far as the algorithm progresses. |
protected int |
_numIters
The number of iterations to cool over. |
protected int |
_numMoves
The number of moves per iteration. |
protected java.util.Random |
_random
The random number generator used in choosing which nodes to swap. |
protected double |
_sparseness
A sparseness measure for the layout. |
private static double |
CROSSING_PENALTY
The penalty for crossings with other edges in the graph. |
private static double |
EDGE_OVERLAP_PENALTY
The penalty for overlaps with other edges in the graph. |
private static double |
ELBOW_PENALTY
The penalty for elbow-shaped edges, i.e ones which have height and width. |
private static double |
HEIGHT_FACTOR
The penalty for each unit of height in an edge. |
private static double |
TEE_PENALTY
The penalty for tees, where a node lands ON another edge that is not connected to it. |
private static double |
WIDTH_FACTOR
The penalty for each unit of width in an edge. |
Fields inherited from class diva.graph.layout.AbstractGlobalLayout |
---|
_layoutTarget |
Constructor Summary | |
---|---|
GridAnnealingLayout(LayoutTarget target)
|
Method Summary | |
---|---|
private java.lang.Object |
_getParentInGraph(java.lang.Object node)
|
private void |
anneal()
Perform simulated annealing using the cost function. |
private void |
ASSERT(boolean b,
java.lang.String err)
Assert the given condition and throw a runtime exception with the given string if the assertion fails. |
private void |
assignLayout()
Assign layout positions to the nodes in the graph based on the logical grid positions determined in the annealing process. |
private void |
cleanupStructures()
Cleanup the data structures used in the layout so that they are empty next time the layout is called. |
protected double |
edgeCost(java.lang.Object edge)
Return the absolute cost of an individual edge. |
double |
getCoolingFactor()
|
int |
getIterationCount(int cnt)
|
int |
getMoveCount(int cnt)
|
double |
getSparseness()
Return the sparseness value of this layout; the default value is 1.0. |
protected int[] |
getXY(java.lang.Object node)
Return the logical X, Y positions of the given node as an integer array of length 2. |
protected void |
initGrid()
Initialize the grid and randomly assign nodes to vertices of the grid. |
void |
layout(java.lang.Object composite)
Perform the annealing layout algorithm on the given graph in the context of the given layout target. |
protected double |
nodeCost(java.lang.Object node)
Return the absolute cost of an individual node. |
protected int |
numCrossings(java.lang.Object inEdge,
java.lang.Object composite)
Return the number of crossings between this edge and other edges in the graph. |
protected int |
numOverlaps(java.lang.Object inEdge,
java.lang.Object composite)
Return the number of overlaps between this edge and other edges in the graph. |
protected int |
numTees(java.lang.Object composite)
Return the number of instances of nodes that are being placed on top of edges that they are not connected to. |
void |
setCoolingFactor(double val)
Set the cooling factor to be a value greater than 0 and less than or equal to 1. |
void |
setIterationCount(int cnt)
Set the number of iterations to cool over. |
void |
setMoveCount(int cnt)
Set the number of moves per iteration. |
void |
setSparseness(double val)
Set the sparseness of this layout. |
protected void |
setXY(java.lang.Object node,
int x,
int y)
Set the logical X, Y positions of the given node. |
private void |
snapMin()
Take a snapshot of the minimum cost arrangement of the nodes, so that we can backtrack to it later. |
private void |
swap(java.lang.Object node1,
java.lang.Object node2)
Swap the two nodes' grid positions. |
Methods inherited from class diva.graph.layout.AbstractGlobalLayout |
---|
getLayoutTarget, setLayoutTarget |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final double HEIGHT_FACTOR
private static final double WIDTH_FACTOR
private static final double ELBOW_PENALTY
private static final double EDGE_OVERLAP_PENALTY
private static final double TEE_PENALTY
private static final double CROSSING_PENALTY
protected java.util.Random _random
protected java.lang.Object _graph
protected int _gw
protected int _gh
protected java.lang.Object[][] _grid
protected java.lang.Object[][] _minGrid
protected double _minCost
protected java.util.HashMap _map
protected double _sparseness
setSparseness(double)
protected int _numIters
protected int _numMoves
protected double _cool
Constructor Detail |
---|
public GridAnnealingLayout(LayoutTarget target)
Method Detail |
---|
private void anneal()
private final void ASSERT(boolean b, java.lang.String err) throws java.lang.RuntimeException
java.lang.RuntimeException
private void assignLayout()
private void cleanupStructures()
protected double edgeCost(java.lang.Object edge)
EDGE_COST(e) = [ HEIGHT(e) + WIDTH(e) + ELBOW_PENALTY(e) + EDGE_OVERLAP_PENALTY * num_overlap(e) + CROSSING_PENALTY * num_crossing(e) ]
public double getCoolingFactor()
setCoolingFactor(double)
public int getIterationCount(int cnt)
setIterationCount(int)
public int getMoveCount(int cnt)
setMoveCount(int)
public double getSparseness()
setSparseness(double)
protected int[] getXY(java.lang.Object node)
protected void initGrid()
GH = H/W * sqrt(N) * SPARSENESSWhere H and W are the height and width of the viewport, N is the number of nodes in the graph, and SPARSENESS is some measure of the sparseness of the layout. A SPARSENESS of 1 will mean that the graph is tightly packed, and the packing amount decreases linearly with the SPARSENESS value.
setSparseness(double)
public void layout(java.lang.Object composite)
layout
in interface GlobalLayout
layout
in class AbstractGlobalLayout
protected double nodeCost(java.lang.Object node)
NODE_COST(n) = SUM [ EDGE_COST(n.edge(i)) ] + TEE_PENALTY * num_tee(g)
protected final int numCrossings(java.lang.Object inEdge, java.lang.Object composite)
protected final int numTees(java.lang.Object composite)
protected final int numOverlaps(java.lang.Object inEdge, java.lang.Object composite)
public void setCoolingFactor(double val)
public void setIterationCount(int cnt)
public void setMoveCount(int cnt)
public void setSparseness(double val)
protected void setXY(java.lang.Object node, int x, int y)
private void snapMin()
private void swap(java.lang.Object node1, java.lang.Object node2)
private java.lang.Object _getParentInGraph(java.lang.Object node)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |