Package org.evoludo.simulator
Class Network
- All Implemented Interfaces:
Iterable<Node>,Collection<Node>,Iterator<Node>,List<Node>,SequencedCollection<Node>
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 GeometryThe structure of the population.protected booleanThe flag to indicate whether the layouting process is running.private intCounter for the iterator over all nodes.protected intThe timeout for layout calculations.protected Network.LayoutListenerThe link to the GUI elements interested in updates about the layouting progress.protected intThe maximum number of links drawn in a graphical representation of the network.intThe number of links in the network.intThe number of nodes in the network.protected Node[]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.doubleThe timestamp of the last time the layouting process has completed.Fields inherited from class AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadjustAccuracy(double adjust) Adjusts the accuracy of the layouting process by a factoradjust.protected abstract doubleattraction(int nodeidx) Calculate the potential energy based on attraction to its neighbours for the node with indexnodeidx.voidAbort the layouting process.voidclear()booleanabstract voidStart the layouting process.voidPrepare for the layouting process.abstract voidAdd the finishing touches to the graph layout: shift center of mass into origin rescale size of graph find number of linksdoubleGet the desired accuracy of the layouting process.Get the geometry that is backing this network.intGet the timeout for layout calculations.doubleGet the radius of the network.Get the status of the layouting process.booleanhasNext()intabstract voidinitNodes(double pnorm, double nnorm, double unitradius) Generate the initial placement of all nodes.booleanisEmpty()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).voidscaleRadiusTo(double newradius) Scale the radius of the network tonewradius.voidsetAccuracy(double accuracy) Set the accuracy of the layouting process toaccuracy.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()Methods inherited from class AbstractList
add, add, addAll, equals, get, hashCode, listIterator, listIterator, remove, removeRange, subListMethods inherited from class AbstractCollection
addAll, containsAll, 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, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Field Details
-
status
The status of the network layout. -
nNodes
public int nNodesThe number of nodes in the network. Convenience variable. This must remain in sync withgeometry.sizeandnodes.length. -
nLinks
public 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 int MAX_LINK_COUNTThe maximum number of links drawn in a graphical representation of the network. -
nodes
The array with all nodes of this network. -
geometry
The structure of the population. -
timestamp
public 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. -
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. -
iteridx
private int iteridxCounter 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:
-
doLayoutPrep
public void doLayoutPrep()Prepare for the layouting process. -
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).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).ToDo:
Prevent nodes from overlapping.- 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
-
setAccuracy
public void setAccuracy(double accuracy) Set the accuracy of the layouting process toaccuracy.- Parameters:
accuracy- the accuracy of the layouting process
-
getAccuracy
public double getAccuracy()Get the desired accuracy of the layouting process.- Returns:
- the accuracy of the layouting process
-
adjustAccuracy
public void adjustAccuracy(double adjust) Adjusts the accuracy of the layouting process by a factoradjust. Foradjust>1the layouting process becomes more forgiving and less forgiving foradjust<1.- Parameters:
adjust- the factor to adjust the accuracy
-
clear
public void clear()- Specified by:
clearin interfaceCollection<Node>- Specified by:
clearin interfaceList<Node>- Overrides:
clearin classAbstractList<Node>
-
size
public int size()- Specified by:
sizein interfaceCollection<Node>- Specified by:
sizein interfaceList<Node>- Specified by:
sizein classAbstractCollection<Node>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<Node>- Specified by:
isEmptyin interfaceList<Node>- Overrides:
isEmptyin classAbstractCollection<Node>
-
contains
- Specified by:
containsin interfaceCollection<Node>- Specified by:
containsin interfaceList<Node>- Overrides:
containsin classAbstractCollection<Node>
-
set
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<Node>- Overrides:
lastIndexOfin classAbstractList<Node>
-
iterator
-
hasNext
public boolean hasNext() -
next
-