Class Network<N extends Node>
Object
AbstractCollection<N>
AbstractList<N>
Network<N>
- Type Parameters:
N- the node type managed by the network
- All Implemented Interfaces:
Iterable<N>, Collection<N>, Iterator<N>, List<N>, SequencedCollection<N>
Abstract graphical representation for generic population geometries. A
network corresponds to a (possibly ephemeral) collection and configuration of
nodes. Implementations are available in 2D and 3D.
- Author:
- Christoph Hauert
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for GUI elements that are interested in receiving updates regarding the process of laying out the network.static enumStatus of the layout process of networks:Network.Status.HAS_LAYOUTnetwork layout complete. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected doubleThe desired accuracy of the layouting process.protected EvoLudoThe pacemaker of all models.protected doubleThe fraction of links in the network to be drawn.protected AbstractGeometryThe structure of the population.protected static final doubleGolden-angle increment used by deterministic phyllotactic seed layouts.protected static final doubleStiffness of the hard-core penalty that separates overlapping nodes.private intCounter for the iterator over all nodes.protected doubleThe first observed layout adjustment after the current layout started.protected booleanThe flag to indicate whether the layouting process is running.protected doubleEstimate of how close the current state is to a relaxed layout.protected intThe timeout for layout calculations.protected Network.LayoutListenerThe link to the GUI elements interested in updates about the layouting progress.protected static final intThe maximum number of links drawn in a graphical representation of the network.protected static final doubleSmallest admissible center-to-center distance during layout calculations.protected static final doubleSmallest admissible normalized distance used by the long-range repulsion.protected intThe number of links in the network.protected intThe number of nodes in the network.protected N[]The array with all nodes of this network.protected doubleThe normalization factor for the network potential.protected doubleThe potential energy of the current network layout/configuration.protected doubleThe best (smallest) adjustment (lowering of the energy state) of previous layouting steps.protected doubleThe potential energy of the previous network layout/configuration.(package private) doubleThe radius of the network.protected RNGDistributionThe random number generator used for layout of networks.protected Network.StatusThe status of the network layout.protected doubleThe timestamp of the last time the layouting process has completed.private static final doubleBaseline radius atUNIT_RADIUS_REFERENCE_SIZE.private static final doubleExponent of the baseline node radius law.private static final doubleReference population size for the baseline node radius law.Fields inherited from class AbstractList
modCount -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNetwork(EvoLudo engine, AbstractGeometry geometry) Create a new network for the given engine and geometry. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract doubleattraction(int nodeidx) Calculate the potential energy based on attraction to its neighbours for the node with indexnodeidx.voidAbort the layouting process.voidclear()protected intcollectEdges(int[] sources, int[] targets) Collect all unique undirected edges that can be rendered for the current geometry.protected intcollectLinks(int[] sources, int[] targets, boolean[] isUndirected) Collect all renderable links of a directed geometry, collapsing reciprocal pairs into a single undirected edge.protected voidFinalize the current layout synchronously.booleanabstract voidStart the layouting process.voidPrepare for the layouting process.booleanabstract voidAdd the finishing touches to the graph layout: shift center of mass into origin rescale size of graph find number of linksprotected doubleGet the effective convergence threshold for the layouting process.Get the geometry that is backing this network.intGet the timeout for layout calculations.intGet the number of links in the network.doubleGet the radius of the network.Get the status of the layouting process.doubleGet the timestamp of the last time the layouting process has completed.protected doubleCompute the baseline node radius used when initializing layouts.inthashCode()booleanhasNext()intabstract voidinitNodes(double pnorm, double nnorm, double unitradius) Generate the initial placement of all nodes.booleanisStatus(Network.Status stat) Checks the status of the layouting process.iterator()intabstract voidGenerate the links for the current configuration of the network.next()abstract doublerelax(int nodeidx) Relax the potential energy a single node with indexnodeidxby adjusting its position.abstract doublerelax(int nodeidx, double dt) Relaxes the network node with indexnodeidx.protected abstract doublerepulsion(int nodeidx) Calculate the potential energy based on repulsion for the node with indexnodeidx.voidreset()Reset the network (discard any existing layouts).protected int[]sampleIndices(int itemCount, int sampleCount) Draw a random sample without replacement from the integer range[0, itemCount).protected doublescaledNodeRadius(int nodeidx, double avgTot, double pnorm, double nnorm, double unitradius) Compute the radius of a node from its total degree relative to the average degree of the geometry.voidscaleRadiusTo(double newradius) Scale the radius of the network tonewradius.voidSet the layout listener for this network.voidsetLayoutTimout(int msec) Set the timeout for layout calculations.voidsetRadius(double radius) Set the radius of the network toradius.voidsetStatus(Network.Status status) Set the status of the layouting process tostatus.voidshake(Network.LayoutListener ll, double quake) Shake the network by randomly shifting the position of all nodes by an amount of up toquakein any coordinate.intsize()protected doubleupdateLayoutProgress(double adjust) Update the estimate of how close the current layout is to a fully relaxed state.Methods inherited from class AbstractList
add, add, addAll, get, listIterator, listIterator, remove, removeRange, subListMethods inherited from class AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface Iterator
forEachRemaining, removeMethods inherited from interface List
addAll, addFirst, addLast, containsAll, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Field Details
-
status
The status of the network layout. -
nNodes
protected int nNodesThe number of nodes in the network. Convenience variable. This must remain in sync withgeometry.getSize()andnodes.length. -
nLinks
protected int nLinksThe number of links in the network. If networks has too many links only some or none may be drawn.- See Also:
-
MAX_LINK_COUNT
protected static final int MAX_LINK_COUNTThe maximum number of links drawn in a graphical representation of the network.- See Also:
-
MIN_DISTANCE
protected static final double MIN_DISTANCESmallest admissible center-to-center distance during layout calculations. This avoids divisions by zero for coincident nodes.- See Also:
-
MIN_SCALED_DISTANCE
protected static final double MIN_SCALED_DISTANCESmallest admissible normalized distance used by the long-range repulsion.- See Also:
-
HARD_CORE_STIFFNESS
protected static final double HARD_CORE_STIFFNESSStiffness of the hard-core penalty that separates overlapping nodes. The penalty is quadratic in the overlap depth measured in units of the baseline universe size. The value remains moderate because dense graphs may require a small amount of residual overlap.- See Also:
-
GOLDEN_ANGLE
protected static final double GOLDEN_ANGLEGolden-angle increment used by deterministic phyllotactic seed layouts. -
UNIT_RADIUS_REFERENCE_SIZE
private static final double UNIT_RADIUS_REFERENCE_SIZEReference population size for the baseline node radius law.- See Also:
-
UNIT_RADIUS_AT_REFERENCE
private static final double UNIT_RADIUS_AT_REFERENCEBaseline radius atUNIT_RADIUS_REFERENCE_SIZE. This preserves the former visual scale around medium-sized populations while allowing the size law to become slightly steeper overall. -
UNIT_RADIUS_EXPONENT
private static final double UNIT_RADIUS_EXPONENTExponent of the baseline node radius law. The value is moderately steeper than the former inverse-fourth-root scaling so small populations get noticeably larger nodes and very large populations get a bit smaller still while the reference size remains unchanged.- See Also:
-
nodes
-
geometry
The structure of the population. -
timestamp
protected double timestampThe timestamp of the last time the layouting process has completed. -
accuracy
protected double accuracyThe desired accuracy of the layouting process. The layouting process stops if the change in potential energy falls below this threshold. -
fLinks
protected double fLinksThe fraction of links in the network to be drawn. IffLinks < 1.0links are randomly selected and drawn.- See Also:
-
radius
double radiusThe radius of the network. -
isRunning
protected boolean isRunningThe flag to indicate whether the layouting process is running. -
prevPotential
protected double prevPotentialThe potential energy of the previous network layout/configuration. -
prevAdjust
protected double prevAdjustThe best (smallest) adjustment (lowering of the energy state) of previous layouting steps. -
initialAdjust
protected double initialAdjustThe first observed layout adjustment after the current layout started. This provides the reference scale for estimating how close the current state is to a fully relaxed configuration. -
layoutProgress
protected double layoutProgressEstimate of how close the current state is to a relaxed layout. Values range from 0 for the initial configuration to 1 once the desired accuracy is reached. -
norm
protected double normThe normalization factor for the network potential. -
potential
protected double potentialThe potential energy of the current network layout/configuration. -
listener
The link to the GUI elements interested in updates about the layouting progress. -
engine
The pacemaker of all models. Interface with the outside world. -
rng
The random number generator used for layout of networks. Must NOT interfere with modelling and calculations. Do NOT use the shared RNG!- See Also:
-
layoutTimeout
protected int layoutTimeoutThe timeout for layout calculations. The default is 5 sec. The layouting process is stopped if it exceeds this time. -
idx
private int idxCounter for the iterator over all nodes.
-
-
Constructor Details
-
Network
Create a new network for the given engine and geometry.- Parameters:
engine- the pacemaker for running the modelgeometry- the structure of the population
-
-
Method Details
-
setLayoutListener
Set the layout listener for this network. The layout listener gets notified about the progress of laying out this network.- Parameters:
ll- the layout listener
-
reset
public void reset()Reset the network (discard any existing layouts). -
doLayout
Start the layouting process. The layout listener (if any) is informed about the progress of the layouting process. Implementations can take advantage of optimizations available for GWT (scheduling) or JRE (multiple threads).- Parameters:
nll- the layout listener- See Also:
-
scaledNodeRadius
protected double scaledNodeRadius(int nodeidx, double avgTot, double pnorm, double nnorm, double unitradius) Compute the radius of a node from its total degree relative to the average degree of the geometry. Positive deviations usepnorm, negative deviations usennorm.- Parameters:
nodeidx- the index of the nodeavgTot- the average total degree of the geometrypnorm- the scaling for nodes above the average degreennorm- the scaling for nodes below the average degreeunitradius- the baseline node radius- Returns:
- the radius assigned to the node
-
getUnitRadius
protected double getUnitRadius()Compute the baseline node radius used when initializing layouts. The default is anchored at a medium population size and then scales slightly more strongly than inverse-square-root with population size.- Returns:
- the baseline node radius
-
collectEdges
protected int collectEdges(int[] sources, int[] targets) Collect all unique undirected edges that can be rendered for the current geometry.- Parameters:
sources- the array receiving the source node index of each edgetargets- the array receiving the target node index of each edge- Returns:
- the number of collected edges
-
collectLinks
protected int collectLinks(int[] sources, int[] targets, boolean[] isUndirected) Collect all renderable links of a directed geometry, collapsing reciprocal pairs into a single undirected edge.- Parameters:
sources- the array receiving the source node index of each linktargets- the array receiving the target node index of each linkisUndirected- the array receiving whether the collected link is undirected- Returns:
- the number of collected renderable links
-
sampleIndices
protected int[] sampleIndices(int itemCount, int sampleCount) Draw a random sample without replacement from the integer range[0, itemCount).- Parameters:
itemCount- the number of available itemssampleCount- the number of requested samples- Returns:
- the sampled indices in randomized order
-
doLayoutPrep
public void doLayoutPrep()Prepare for the layouting process. -
completeLayout
protected void completeLayout()Finalize the current layout synchronously. This helper is used when a layout is already in its final configuration and therefore does not need any relaxation sweeps before being presented. -
updateLayoutProgress
protected double updateLayoutProgress(double adjust) Update the estimate of how close the current layout is to a fully relaxed state. The estimate is based on the logarithmic distance between the best adjustment reached so far and the target accuracy relative to the first observed adjustment. A square-root easing spreads out the early part of the curve so progress becomes visible earlier while remaining monotone.- Parameters:
adjust- the current change in potential energy after a full relaxation sweep- Returns:
- the updated progress estimate in
[0, 1]
-
getConvergenceAccuracy
protected double getConvergenceAccuracy()Get the effective convergence threshold for the layouting process. The base implementation returnsaccuracy, but subclasses may tighten or relax the criterion when their layout energies use a different natural scale.- Returns:
- the effective convergence threshold
-
initNodes
public abstract void initNodes(double pnorm, double nnorm, double unitradius) Generate the initial placement of all nodes. The size of nodes scales with their total number of incoming and outgoing links in heterogeneous networks.- Parameters:
pnorm- the maximal radius of a nodennorm- the minimal radius of a nodeunitradius- the reference radius of a node
-
relax
public abstract double relax(int nodeidx) Relax the potential energy a single node with indexnodeidxby adjusting its position. The potential energy increases proportional toDwhereDdenotes the distance to its neighbours and decreases proportional to1/D<sup>2</sup>whereDrefers to the distance from all other nodes.- Parameters:
nodeidx- the index of the node to relax- Returns:
- the change in potential energy
-
relax
public abstract double relax(int nodeidx, double dt) Relaxes the network node with indexnodeidx. The attraction and repulsion forces act on the node for a time intervaldt, which limits the changes in the position of the node.- Parameters:
nodeidx- the index of the node to relaxdt- the time interval- Returns:
- the change in potential energy
- See Also:
-
repulsion
protected abstract double repulsion(int nodeidx) Calculate the potential energy based on repulsion for the node with indexnodeidx. Return the net repulsion (overall direction and magnitude) acting on it inrepulsion(int). Implementations may include additional short-range penalties here, for example to discourage overlap between nodes with finite size.Note:
To prevent disjoint parts of a network (and unstructured populations, in particular) to continue to fly apart, the repulsion changes sign, i.e. turns into attraction, once the distance between nodes exceeds the radius of the universe.- Parameters:
nodeidx- the index of the node to relax- Returns:
- the potential energy of the node
-
attraction
protected abstract double attraction(int nodeidx) Calculate the potential energy based on attraction to its neighbours for the node with indexnodeidx. Return the net attraction (overall direction and magnitude) acting on it inattraction(int).- Parameters:
nodeidx- the index of the node to relax- Returns:
- the potential energy of the node
-
finishLayout
public abstract void finishLayout()Add the finishing touches to the graph layout:- shift center of mass into origin
- rescale size of graph
- find number of links
-
cancelLayout
public void cancelLayout()Abort the layouting process. -
setLayoutTimout
public void setLayoutTimout(int msec) Set the timeout for layout calculations.- Parameters:
msec- the timeout in milliseconds
-
getLayoutTimout
public int getLayoutTimout()Get the timeout for layout calculations.- Returns:
- the timeout in milliseconds
-
getGeometry
Get the geometry that is backing this network.- Returns:
- the backing geometry
-
linkNodes
public abstract void linkNodes()Generate the links for the current configuration of the network. -
shake
Shake the network by randomly shifting the position of all nodes by an amount of up toquakein any coordinate.- Parameters:
ll- the layout listenerquake- the maximum shift in any coordinate
-
scaleRadiusTo
public void scaleRadiusTo(double newradius) Scale the radius of the network tonewradius. Scales the radii of all nodes accordingly.- Parameters:
newradius- the new radius of the network
-
setRadius
public void setRadius(double radius) Set the radius of the network toradius.- Parameters:
radius- the radius of the network
-
getRadius
public double getRadius()Get the radius of the network.- Returns:
- the radius of the network
-
setStatus
Set the status of the layouting process tostatus.- Parameters:
status- the status of the layouting process- See Also:
-
getStatus
Get the status of the layouting process.- Returns:
- the status of the layouting process
-
isStatus
Checks the status of the layouting process.- Parameters:
stat- the status to check- Returns:
trueif the current status isstat
-
getTimestamp
public double getTimestamp()Get the timestamp of the last time the layouting process has completed.- Returns:
- the timestamp
-
clear
-
size
-
getNLinks
public int getNLinks()Get the number of links in the network.- Returns:
- the number of links
-
contains
-
set
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<N extends Node>- Overrides:
lastIndexOfin classAbstractList<N extends Node>
-
hasNext
-
next
-
iterator
-
equals
-
hashCode
-