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 interface
Interface for GUI elements that are interested in receiving updates regarding the process of laying out the network.static enum
Status of the layout process of networks:Network.Status.HAS_LAYOUT
network layout complete. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double
The desired accuracy of the layouting process.protected EvoLudo
The pacemaker of all models.protected double
The fraction of links in the network to be drawn.protected Geometry
The structure of the population.protected boolean
The flag to indicate whether the layouting process is running.private int
Counter for the iterator over all nodes.protected int
The timeout for layout calculations.protected Network.LayoutListener
The link to the GUI elements interested in updates about the layouting progress.protected int
The maximum number of links drawn in a graphical representation of the network.int
The number of links in the network.int
The number of nodes in the network.protected Node[]
The array with all nodes of this network.protected double
The normalization factor for the network potential.protected double
The potential energy of the current network layout/configuration.protected double
The best (smallest) adjustment (lowering of the energy state) of previous layouting steps.protected double
The potential energy of the previous network layout/configuration.(package private) double
The radius of the network.protected RNGDistribution
The random number generator used for layout of networks.protected Network.Status
The status of the network layout.double
The timestamp of the last time the layouting process has completed.Fields inherited from class AbstractList
modCount
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
adjustAccuracy
(double adjust) Adjusts the accuracy of the layouting process by a factoradjust
.protected abstract double
attraction
(int nodeidx) Calculate the potential energy based on attraction to its neighbours for the node with indexnodeidx
.void
Abort the layouting process.void
clear()
boolean
abstract void
Start the layouting process.void
Prepare for the layouting process.abstract void
Add the finishing touches to the graph layout: shift center of mass into origin rescale size of graph find number of linksdouble
Get the desired accuracy of the layouting process.Get the geometry that is backing this network.int
Get the timeout for layout calculations.double
Get the radius of the network.Get the status of the layouting process.boolean
hasNext()
int
abstract void
initNodes
(double pnorm, double nnorm, double unitradius) Generate the initial placement of all nodes.boolean
isEmpty()
boolean
isStatus
(Network.Status stat) Checks the status of the layouting process.iterator()
int
abstract void
Generate the links for the current configuration of the network.next()
abstract double
relax
(int nodeidx) Relax the potential energy a single node with indexnodeidx
by adjusting its position.abstract double
relax
(int nodeidx, double dt) Relaxes the network node with indexnodeidx
.protected abstract double
repulsion
(int nodeidx) Calculate the potential energy based on repulsion for the node with indexnodeidx
.void
reset()
Reset the network (discard any existing layouts).void
scaleRadiusTo
(double newradius) Scale the radius of the network tonewradius
.void
setAccuracy
(double accuracy) Set the accuracy of the layouting process toaccuracy
.void
Set the layout listener for this network.void
setLayoutTimout
(int msec) Set the timeout for layout calculations.void
setRadius
(double radius) Set the radius of the network toradius
.void
setStatus
(Network.Status status) Set the status of the layouting process tostatus
.void
shake
(Network.LayoutListener ll, double quake) Shake the network by randomly shifting the position of all nodes by an amount of up toquake
in any coordinate.int
size()
Methods inherited from class AbstractList
add, add, addAll, equals, get, hashCode, listIterator, listIterator, remove, removeRange, subList
Methods inherited from class AbstractCollection
addAll, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
Methods inherited from interface Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface Iterator
forEachRemaining, remove
Methods 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.size
andnodes.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.0
links 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 indexnodeidx
by adjusting its position. The potential energy increases proportional toD
whereD
denotes the distance to its neighbours and decreases proportional to1/D<sup>2</sup>
whereD
refers 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 toquake
in 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:
true
if 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>1
the layouting process becomes more forgiving and less forgiving foradjust<1
.- Parameters:
adjust
- the factor to adjust the accuracy
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<Node>
- Specified by:
clear
in interfaceList<Node>
- Overrides:
clear
in classAbstractList<Node>
-
size
public int size()- Specified by:
size
in interfaceCollection<Node>
- Specified by:
size
in interfaceList<Node>
- Specified by:
size
in classAbstractCollection<Node>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<Node>
- Specified by:
isEmpty
in interfaceList<Node>
- Overrides:
isEmpty
in classAbstractCollection<Node>
-
contains
- Specified by:
contains
in interfaceCollection<Node>
- Specified by:
contains
in interfaceList<Node>
- Overrides:
contains
in classAbstractCollection<Node>
-
set
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<Node>
- Overrides:
lastIndexOf
in classAbstractList<Node>
-
iterator
-
hasNext
public boolean hasNext() -
next
-