Package org.evoludo.simulator
Class Network2D
- All Implemented Interfaces:
Iterable<Node>
,Collection<Node>
,Iterator<Node>
,List<Node>
,SequencedCollection<Node>
- Direct Known Subclasses:
Network2DGWT
Graphical representation of generic population geometries in 2D. A network
corresponds to a (possibly ephemeral) collection and configuration of nodes.
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested classes/interfaces inherited from class Network
Network.LayoutListener, Network.Status
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Vector2D
Helper variable to store intermediate results when considering the potential energy resulting from the attraction between neighbouring nodes.protected static final double
The inverse size of the baseline 2D universe.protected static final double
The inverse squared size of the baseline 2D universe,1/R<sup>2</sup>
.protected Path2D
The links in this network.protected Node2D[]
The array with all nodes of this network.static final double
The baseline size of the 2D universe.private final Vector2D
Helper variable to store intermediate results when considering the potential energy resulting from the repulsion between nodes.private final Vector2D
Temporary storage for the directional vector connecting two nodes.Fields inherited from class Network
accuracy, engine, fLinks, geometry, isRunning, layoutTimeout, listener, MAX_LINK_COUNT, nLinks, nNodes, norm, potential, prevAdjust, prevPotential, radius, rng, status, timestamp
Fields inherited from class AbstractList
modCount
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected double
attraction
(int nodeidx) Calculate the potential energy based on attraction to its neighbours for the node with indexnodeidx
.void
Add the finishing touches to the graph layout: shift center of mass into origin rescale size of graph find number of linksget
(int index) getLinks()
Get the links in this network for the GUI to draw.void
initNodes
(double pnorm, double nnorm, double unitradius) Generate the initial placement of all nodes.void
Generate the links for the current configuration of the network.double
relax
(int nodeidx) Relax the potential energy a single node with indexnodeidx
by adjusting its position.double
relax
(int nodeidx, double dt) Relaxes the network node with indexnodeidx
.protected 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).Node2D[]
toArray()
Methods inherited from class Network
adjustAccuracy, cancelLayout, clear, contains, doLayout, doLayoutPrep, getAccuracy, getGeometry, getLayoutTimout, getRadius, getStatus, hasNext, indexOf, isEmpty, isStatus, iterator, lastIndexOf, next, scaleRadiusTo, set, setAccuracy, setLayoutListener, setLayoutTimout, setRadius, setStatus, shake, size
Methods inherited from class AbstractList
add, add, addAll, equals, hashCode, listIterator, listIterator, remove, removeRange, subList
Methods inherited from class AbstractCollection
addAll, containsAll, remove, removeAll, retainAll, 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
-
Field Details
-
links
The links in this network. -
nodes
The array with all nodes of this network. This deliberately overridessuper.nodes
. The two arrays are identical but saves a ton of unnecesary casts. -
attraction
Helper variable to store intermediate results when considering the potential energy resulting from the attraction between neighbouring nodes. -
repulsion
Helper variable to store intermediate results when considering the potential energy resulting from the repulsion between nodes. -
vec
Temporary storage for the directional vector connecting two nodes. -
R
public static final double RThe baseline size of the 2D universe.- See Also:
-
IR
protected static final double IRThe inverse size of the baseline 2D universe. Convenience constant.- See Also:
-
IR2
protected static final double IR2The inverse squared size of the baseline 2D universe,1/R<sup>2</sup>
. Convenience constant.- See Also:
-
-
Constructor Details
-
Network2D
Create a new network in 2D for the given engine and geometry.- Parameters:
engine
- the pacemaker for running the modelgeometry
- the structure of the population
-
-
Method Details
-
reset
public void reset()Description copied from class:Network
Reset the network (discard any existing layouts). -
getLinks
Get the links in this network for the GUI to draw.- Returns:
- the links in this network
-
initNodes
public void initNodes(double pnorm, double nnorm, double unitradius) Description copied from class:Network
Generate the initial placement of all nodes. The size of nodes scales with their total number of incoming and outgoing links in heterogeneous networks. -
relax
public double relax(int nodeidx) Description copied from class:Network
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. -
relax
public double relax(int nodeidx, double dt) Description copied from class:Network
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. -
repulsion
protected double repulsion(int nodeidx) Description copied from class:Network
Calculate the potential energy based on repulsion for the node with indexnodeidx
. Return the net repulsion (overall direction and magnitude) acting on it inNetwork.repulsion(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. -
attraction
protected double attraction(int nodeidx) Description copied from class:Network
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 inNetwork.attraction(int)
.ToDo:
Prevent nodes from overlapping.- Specified by:
attraction
in classNetwork
- Parameters:
nodeidx
- the index of the node to relax- Returns:
- the potential energy of the node
-
finishLayout
public void finishLayout()Description copied from class:Network
Add the finishing touches to the graph layout:- shift center of mass into origin
- rescale size of graph
- find number of links
- Specified by:
finishLayout
in classNetwork
-
linkNodes
public void linkNodes()Description copied from class:Network
Generate the links for the current configuration of the network. -
toArray
- Specified by:
toArray
in interfaceCollection<Node>
- Specified by:
toArray
in interfaceList<Node>
- Overrides:
toArray
in classAbstractCollection<Node>
-
get
-