Class Geometry
Geometry
represent the interaction and/or
competition structure of the population. For a list of currently implemented
geometries, Geometry.Type
.- Author:
- Christoph Hauert
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptiondouble
The average number of incoming links.double
The average number of outgoing links.double
The average number of the sum of incoming and outgoing links.double
The degree or connectivity of the graph or (average) number of neighbours.(package private) EvoLudo
The pacemaker of all models.private boolean
true
if geometry has been evaluated.boolean
Flag indicating whether boundaries are fixed or periodic (default).private Geometry.Type
The geometry of the graph.int[]
The number of units in each hierarchical level.double
The strength of interactions between hierarchical levels.int[][]
This is the neighbourhood network structure of incoming links.boolean
true
if the interaction and competition graphs are the same.boolean
true
if the network structure is ephemeral.boolean
true
if the network structure is regular (all nodes have the same number of neighbours).boolean
true
if the graph includes rewired edges or links.boolean
true
if the graph is undirected.boolean
true
if the network structure has been successfully initialized.int[]
The array storing the number of incoming neighbours for each node, i.e.int[]
The array storing the number of outgoing neighbours for each node, i.e.int
The difference between the number of neighbours on the left and the right in linear, 1D lattices.(package private) Logger
Logger for keeping track of and reporting events and issues.protected static final int
Maximum number of attempts to generate a graph structure.int
The maximum number of incoming links.int
The maximum number of outgoing links.int
The maximum sum of incoming and outgoing links.int
The minimum number of incoming links.int
The minimum number of outgoing links.int
The minimum sum of incoming and outgoing links.The name of this graph.private Network2D
Local storage for the 2D representation of this graph.private Network3D
Local storage for the 3D representation of this graph.private static final int[]
Convenience field.The IBS population representing the opponent.int[][]
This is the neighbourhood network structure of outgoing links.double
Fraction of directed links to add or rewire.double
The probability for adding links adjust small-world properties of Klemm-Eguiluz scale-free networks.(package private) IBSPopulation
The IBS population that has this geometry.double
Fraction of undirected links to add or rewire.protected int[]
The number of units in each hierarchical level requested.double
The exponent in scale-free networks.int
The number of nodes in the graph.Only used for hierarchical geometries to specify the geometry of each level.int
The chain length in superstars.int
The number of petals or tips in superstars. -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a new geometry for data visualization with pacemakerengine
.Instantiates a new geometry for intra-species modulemodule
with pacemakerengine
.Instantiates a new geometry for inter-species modulepopModule
and opponentoppModule
with pacemakerengine
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add directed links to network.void
addEdgeAt
(int from, int to) Add edge (undirected link) from nodefrom
to nodeto
.void
addLinkAt
(int from, int to) Add link (directed link) from nodefrom
to nodeto
.boolean
Add undirected links.void
alloc()
Allocate the memory neccessary to store the network structure.boolean
check()
Check the feasibility of the network parameters.boolean
Check consistency of links.void
clearLinksFrom
(int idx) Remove all outgoing links from nodeidx
.void
clearLinksTo
(int idx) Remove all incoming links to nodeidx
.clone()
Clone geometry.void
decodeGeometry
(Plist plist) Decode the geometry from the plist.Derive competition geometry from current (interaction) geometry.Derive interaction geometry from current (competition) geometry.static boolean
displayUniqueGeometry
(Geometry inter, Geometry comp) Checks whether a single graphical representation can be used for the interaction and competition graphs.static boolean
displayUniqueGeometry
(Module module) Checks whether a single graphical representation can be used for the interaction and competition graphs.Encode geometry as a plist string fragment.boolean
Check ifthis
Geometry andgeo
refer to the same structures.void
evaluate()
Evaluate geometry.getName()
Gets the name of this graph.Get the 2D network representation of this graph.Get the 3D network representation of this graph.Gets the opponent of the population represented by this graph.getType()
Get the type of this geometry.void
init()
Entry point to initialize the network structure according to the given parameters.void
Generates a strong undirected amplifier of selection.void
Generates a complete graph where every node is connected to every other node.void
Generates a cubic (3D) regular lattice.private boolean
initGeometryDegreeDistr
(int[] distr) Utility method to generate network with a given degree distribution.void
Generates a Desargues graph, named after Girard Desargues (1591–1661).void
Generates a dodecahedron graph.void
Generates a Franklin graph.void
Generates a Frucht graph.void
Generates a Heawood graph.void
Generates hierarchical graphs.private void
initGeometryHierarchy
(int level, int start) Utility method to generate hierarchical graphs.private int
initGeometryHierarchyMeanfield
(int start, int end) Utility method to generate hierarchical well-mixed subpopulations (demes).private int
initGeometryHierarchySquare
(int start, int end) Utility method to generate hierarchical square lattices with degreedegree
.void
Generates a hexagonal regular lattice (degree \(6\)).void
Generates an icosahedron graph.void
Generates a linear chain (1D lattice).void
Generates well-mixed graph, also termed mean-field networks or unstructured populations.void
Generate a (connected, directed) random graph.void
Generate a (connected, directed) random graph.void
Generate a (connected, undirected) random regular graph.void
Generate a (connected, undirected) scale-free network.void
Generate a (connected, undirected) scale-free network following the procedure by Barabási & Albert (1999).void
Generate a (connected, undirected) scale-free network following the procedure by Klemm & Eguíluz (2001).void
Generates a square regular lattice (chessboard).private void
initGeometrySquare
(int side, int fullside, int offset) Utility method to generate a square lattice with arbitrarily large neighbourhoods.private void
initGeometrySquareMoore
(int side, int fullside, int offset) Utility method to generate a square lattice with Moore neighbourhood.private void
initGeometrySquareSelf
(int side, int fullside, int offset) Utility method to generate a square lattice with exclusively 'self'-connections.private void
initGeometrySquareVonNeumann
(int side, int fullside, int offset) Utility method to generate a square lattice with von Neumann neighbourhood.private void
initGeometrySquareVonNeumann2nd
(int side, int fullside, int offset) Utility method to generate a square lattice with von Neumann neighbourhood.void
Generates a star geometry with a hub in the middle that is connected to all other nodes (leaves).void
Generates a superstar geometry, which represents a strong directed amplifier of selection.void
Generates a strong undirected suppressor of selection.void
Generates a Tietze graph.void
Generates a triangular regular lattice (degree \(3\)).void
Generates a wheel geometry, which corresponds to a ring (periodic 1D lattice) with a hub in the middle that is connected to all nodes in the ring (resembling spokes).private void
initRRGCore
(RNGDistribution rng, int start, int end, int degree) Utility method to generate an (almost) regular graph as the core of an evolutionary amplifier.boolean
Check if graph is connected.boolean
isGraphConnected
(int node, boolean[] check) Check if any other node can be reached fromnode
.boolean
Check if graph refers to inter-species model.boolean
Utility method to determine whether a given geometry type is a lattice.boolean
isNeighborOf
(int focal, int check) Check ifcheck
is a neighbor offocal
(not necessarily the other way round).boolean
Check if current geometry unique.private boolean
Helper method to check uniqueness of the geometrygeo
.boolean
Parse string of geometry specificationscli
.void
printParams
(PrintStream output) Report relevant parameters of geometry and print tooutput
.void
removeEdgeAt
(int from, int to) Remove edge (undirected link) from nodefrom
to nodeto
.private void
removeInLink
(int from, int to) Remove incoming link (directed link) to nodeto
from nodefrom
.void
removeLinkAt
(int from, int to) Remove link (directed link) from nodefrom
to nodeto
.private void
removeOutLink
(int from, int to) Remove outgoing link (directed link) from nodefrom
to nodeto
.void
reset()
Reset the network structure and free the allocated memory.void
rewire()
Add/rewire directed and undirected random links.boolean
Rewire directed links.void
rewireEdgeAt
(int from, int to, int prev) Rewire edge (undirected link) from nodefrom
to nodeprev
to nodeto
.void
rewireLinkAt
(int from, int to, int prev) Rewire directed link from nodefrom
to nodeprev
to nodeto
.private boolean
rewireNeighbourEdge
(RNGDistribution rng, int nodeA, int nodeB, int[] done, int nDone) Utility method to rewire an edge between two nodes.boolean
rewireUndirected
(double prob) Rewire undirected links.void
Sets the name of this graph.void
setNetwork2D
(Network2D net) Set the 2D network representation of this graph.void
setNetwork3D
(Network3D net) Set the 3D network representation of this graph.boolean
setSize
(int size) Sets the number of nodes in the graph tosize
.void
setType
(Geometry.Type type) Set the type of this geometry.private static void
swap
(int[] x, int a, int b) Swap elements with indicesa
andb
in arrayx
private boolean
swapEdges
(int a, int an, int b, int bn) Utility method to swap edges (undirected links) between nodes: change linka-an
toa-bn
andb-bn
tob-an
.usage()
Get the usage description for the command line option--geometry
.
-
Field Details
-
engine
EvoLudo engineThe pacemaker of all models. Interface with the outside world. -
population
IBSPopulation populationThe IBS population that has this geometry. -
opponent
The IBS population representing the opponent. For intra-species interactionspopulation==opponent
holds. -
logger
Logger loggerLogger for keeping track of and reporting events and issues. -
network2D
Local storage for the 2D representation of this graph. -
network3D
Local storage for the 3D representation of this graph. -
geometry
The geometry of the graph. -
subgeometry
Only used for hierarchical geometries to specify the geometry of each level.- See Also:
-
name
The name of this graph. Typically this is "interaction" or "competition" for the correpsonding graphs, or "structure" if the two graphs are the same. In multi-species models the name of the species may be prepended. -
in
public int[][] inThis is the neighbourhood network structure of incoming links. More specifically, for each node a list of indices of neighbouring nodes with links to this one.Requirements/notes:
in[i].length
does not necessarily reflect the number of neighbours! Usekin[i]
instead. To minimize memory allocation requestsin[i].length>kin[i]
may hold. This is primarily important for dynamical networks. -
out
public int[][] outThis is the neighbourhood network structure of outgoing links. More specifically, for each node a list of indices of neighbouring nodes that links point to.Requirements/notes:
out[i].length
does not necessarily reflect the number of neighbours! Usekout[i]
instead. To minimize memory allocation requestsout[i].length>kout[i]
may hold. This is primarily important for dynamical networks. -
kin
public int[] kinThe array storing the number of incoming neighbours for each node, i.e. the number of neighbours that have a link pointing to this one. -
kout
public int[] koutThe array storing the number of outgoing neighbours for each node, i.e. the number of links pointing from this node to another. -
size
public int sizeThe number of nodes in the graph. -
fixedBoundary
public boolean fixedBoundaryFlag indicating whether boundaries are fixed or periodic (default). -
rawhierarchy
protected int[] rawhierarchyThe number of units in each hierarchical level requested. Processed for feasibility and then stored inhierarchy
.- See Also:
-
hierarchy
public int[] hierarchyThe number of units in each hierarchical level. The lowest level refers to the number of nodes.- See Also:
-
hierarchyweight
public double hierarchyweightThe strength of interactions between hierarchical levels. For example, with a strength \(p\) between the first and second level, the strength is \(p^2\) between the first and third. More generally, the interaction strength is \(p^n\), where \(n\) denotes the number of levels between the two interacting individuals.- See Also:
-
minIn
public int minInThe minimum number of incoming links.- See Also:
-
maxIn
public int maxInThe maximum number of incoming links.- See Also:
-
avgIn
public double avgInThe average number of incoming links.- See Also:
-
minOut
public int minOutThe minimum number of outgoing links.- See Also:
-
maxOut
public int maxOutThe maximum number of outgoing links.- See Also:
-
avgOut
public double avgOutThe average number of outgoing links.- See Also:
-
minTot
public int minTotThe minimum sum of incoming and outgoing links.- See Also:
-
maxTot
public int maxTotThe maximum sum of incoming and outgoing links.- See Also:
-
avgTot
public double avgTotThe average number of the sum of incoming and outgoing links.- See Also:
-
superstar_petals
public int superstar_petalsThe number of petals or tips in superstars.- See Also:
-
superstar_amplification
public int superstar_amplificationThe chain length in superstars.- See Also:
-
sfExponent
public double sfExponentThe exponent in scale-free networks.- See Also:
-
pKlemm
public double pKlemmThe probability for adding links adjust small-world properties of Klemm-Eguiluz scale-free networks.- See Also:
-
linearAsymmetry
public int linearAsymmetryThe difference between the number of neighbours on the left and the right in linear, 1D lattices. -
connectivity
public double connectivityThe degree or connectivity of the graph or (average) number of neighbours. -
pRewire
public double pRewireFraction of undirected links to add or rewire.- See Also:
-
pAddwire
public double pAddwireFraction of directed links to add or rewire.- See Also:
-
isUndirected
public boolean isUndirectedtrue
if the graph is undirected. -
isRewired
public boolean isRewiredtrue
if the graph includes rewired edges or links. -
interCompSame
public boolean interCompSametrue
if the interaction and competition graphs are the same. -
isDynamic
public boolean isDynamictrue
if the network structure is ephemeral. -
isRegular
public boolean isRegulartrue
if the network structure is regular (all nodes have the same number of neighbours). -
isValid
public boolean isValidtrue
if the network structure has been successfully initialized. -
nulllink
private static final int[] nulllinkConvenience field. Array of zero length for initialization and well-mixed populations. -
MAX_TRIALS
protected static final int MAX_TRIALSMaximum number of attempts to generate a graph structure.- See Also:
-
evaluated
private boolean evaluatedtrue
if geometry has been evaluated.- See Also:
-
-
Constructor Details
-
Geometry
Instantiates a new geometry for data visualization with pacemakerengine
.- Parameters:
engine
- the pacemaker for running the model- See Also:
-
Geometry
Instantiates a new geometry for intra-species modulemodule
with pacemakerengine
.- Parameters:
engine
- the pacemaker for running the modelmodule
- the module with interaction parameters
-
Geometry
Instantiates a new geometry for inter-species modulepopModule
and opponentoppModule
with pacemakerengine
. For intra-species interactionspopulation==opponent
holds.- Parameters:
engine
- the pacemaker for running the modelpopModule
- the module with interaction parametersoppModule
- the module of the opponent
-
-
Method Details
-
getName
Gets the name of this graph. Typically this is "Interaction" or "Competition" for the correpsonding graphs, or "Structure" if the two graphs are the same. In multi-species models the name of the species may be prepended.- Returns:
- the name of the graph
- See Also:
-
setName
Sets the name of this graph.- Parameters:
name
- the name of this graph.- See Also:
-
getType
Get the type of this geometry.- Returns:
- the type of this geometry
-
setType
Set the type of this geometry.- Parameters:
type
- the type of this geometry
-
setNetwork2D
Set the 2D network representation of this graph. This is purely for storage. The network is generated inNetwork2D
.- Parameters:
net
- the 2D network representation
-
getNetwork2D
Get the 2D network representation of this graph. This is purely for storage. The network is generated inNetwork2D
.- Returns:
- the 2D network representation of this graph
-
setNetwork3D
Set the 3D network representation of this graph. This is purely for storage. The network is generated inNetwork3D
.- Parameters:
net
- the 3D network representation
-
getNetwork3D
Get the 3D network representation of this graph. This is purely for storage. The network is generated inNetwork3D
.- Returns:
- the 3D network representation of this graph.
-
setSize
public boolean setSize(int size) Sets the number of nodes in the graph tosize
. This affects memory allocations in the model and hence a reset is required if the size changes.- Parameters:
size
- the new size of the graph- Returns:
true
if the graph size changed
-
getOpponent
Gets the opponent of the population represented by this graph. For intra-species modelsthis.opponent==this.population
holds.- Returns:
- the opponent population
-
isInterspecies
public boolean isInterspecies()Check if graph refers to inter-species model. For intra-species modelsthis.opponent==this.population
holds.- Returns:
true
for inter-species graphs.
-
displayUniqueGeometry
Checks whether a single graphical representation can be used for the interaction and competition graphs. Two distinct graphical represntations are generally required if the two graphs differ but not if they both refer to the same lattice structure even if connectivities or boundary conditions are different.Examples:
A single graphical representation is adequate:- if the interaction and competition graphs are identical,
- if both the interaction and competition graphs are lattices, even if the boundary conditions or the connectivities are different,
- but not if the interaction and competition graphs are separate instances of the same random structure, e.g. random regular graphs.
Requirements/notes:
- Tooltips need to be careful to report the different graphs and neighborhoods properly.
- Parameters:
inter
- the interaction graphcomp
- the competition graph- Returns:
true
if a single graphical representation suffices,false
if two separate graphical representations are required for the interaction and the competition graphs- See Also:
-
displayUniqueGeometry
Checks whether a single graphical representation can be used for the interaction and competition graphs.- Parameters:
module
- the population whose interaction and competition structures to check- Returns:
true
if a single graphical representation suffices- See Also:
-
reset
public void reset()Reset the network structure and free the allocated memory. -
alloc
public void alloc()Allocate the memory neccessary to store the network structure. -
check
public boolean check()Check the feasibility of the network parameters. If parameters need to be adjusted a warning is issued through thelogger
. Some changes require a reset of the model because they affect memory allocations (e.g. adjustments of the population size).- Returns:
true
if reset is required
-
init
public void init()Entry point to initialize the network structure according to the given parameters.- See Also:
-
printParams
Report relevant parameters of geometry and print tooutput
.- Parameters:
output
- the print stream to direct the output to
-
initGeometryMeanField
public void initGeometryMeanField()Generates well-mixed graph, also termed mean-field networks or unstructured populations.Requirements/notes:
In the limit of large population sizes the results of individual based simulations (IBS) must converge to those of the corresponding deterministic dynamical equations (ODE's) or, with mutations, the stochastic dynamical equations (SDE's). -
initGeometryComplete
public void initGeometryComplete()Generates a complete graph where every node is connected to every other node. This is very similar to well-mixed (unstructured) populations. The only difference is the potential treatment of the focal node. For example, in the Moran process offspring can replace their parent in the original formulation for well-mixed populations (birth-death updating) but this does not occur in complete networks where offspring replaces one of the parents neighbours.Requirements/notes:
None.- See Also:
-
initGeometryHierarchical
public void initGeometryHierarchical()Generates hierarchical graphs.Requirements/notes:
Only well-mixed (complete) or square lattice graphs are currently supported. -
initGeometryHierarchy
private void initGeometryHierarchy(int level, int start) Utility method to generate hierarchical graphs.Requirements/notes:
None.- Parameters:
level
- the hierarchical levelstart
- the index of the first node to process
-
initGeometryHierarchyMeanfield
private int initGeometryHierarchyMeanfield(int start, int end) Utility method to generate hierarchical well-mixed subpopulations (demes).Requirements/notes:
None.- Parameters:
start
- the index of the first node to processend
- the index of the last node to process- Returns:
- the number of nodes processed
-
initGeometryHierarchySquare
private int initGeometryHierarchySquare(int start, int end) Utility method to generate hierarchical square lattices with degreedegree
.Requirements/notes:
None.- Parameters:
start
- the index of the first node to processend
- the index of the last node to process- Returns:
- the number of nodes processed
-
initGeometryLinear
public void initGeometryLinear()Generates a linear chain (1D lattice). With asymmetric neighbours and fixed boundaries this represents the simplest suppressor of selection.Requirements/notes:
- May have different numbers of neighbours to the left and the right.
- For inter-species interactions connectivities are \(+1\) and a connectivity of \(1\) is admissible.
- Boundaries fixed or periodic (default).
-
initGeometryStar
public void initGeometryStar()Generates a star geometry with a hub in the middle that is connected to all other nodes (leaves). The star structure is the simplest undirected evolutionary amplifier.Requirements/notes:
Node \(0\) is the hub. -
initGeometryWheel
public void initGeometryWheel()Generates a wheel geometry, which corresponds to a ring (periodic 1D lattice) with a hub in the middle that is connected to all nodes in the ring (resembling spokes). The wheel structure is an undirected evolutionary amplifier but less than the star structure.Requirements/notes:
Node \(0\) is the hub.- See Also:
-
initGeometrySuperstar
public void initGeometrySuperstar()Generates a superstar geometry, which represents a strong directed amplifier of selection. The superstar consists of a central hub surrounded by \(p\) petals that are each equipped with a reservoir of size \(r\) and a linear chain of length \(k\) connecting the reservoir with the hub (last node of each chain). The hub connects to all reservoir nodes (in all petals) and all reservoir nodes in each petal connect to the first node in the linear chain. The superstar represents the best studied evolutionary amplifier of arbitrary strength (in the limit \(N\to\infty\) as well as \(p, r, k \to\infty\)).Requirements/notes:
- Population size: \(N=(r+k-1)p+1\) with \(r,k,p\) integer.
- Strong amplification requires \(r\gg k,p\).
- Node \(0\) is the hub.
- See Also:
-
initGeometryAmplifier
public void initGeometryAmplifier()Generates a strong undirected amplifier of selection.Requirements/notes:
Population size: \(N=n^3+(1+a)n^2\) where \(n\) integer and a suitable \(a\geq 5\). Three types of nodes \(U=n^3\), \(V=n^2\) and \(W=N-U-V\) where \(W\) represents a regular graph core with degree \(n^2\), each node in \(U\) is a leaf and connected to a single node in \(V\), while each node in \(V\) is connected to \(n^2\) nodes in \(W\).- See Also:
-
initRRGCore
Utility method to generate an (almost) regular graph as the core of an evolutionary amplifier.Requirements/notes:
In contrast toinitGeometryRandomRegularGraph()
no extra effort is made to ensure regularity.- Parameters:
rng
- the random number generatorstart
- the index of the first node in the (almost) regular graphend
- the index of the last node in the (almost) regular graphdegree
- the degree/connectivity of the (almost) regular graph
-
rewireNeighbourEdge
private boolean rewireNeighbourEdge(RNGDistribution rng, int nodeA, int nodeB, int[] done, int nDone) Utility method to rewire an edge between two nodes. This assumes thatnodeA
andnodeB
are neighbours. Pick random nodeC
from setdone
and nodeD
a random neighbour ofC
. Now try to rewire the edgeA-B
toA-C
andB-D
orB-C
andA-D
, respectively. Returnsfalse
and do nothing if the edge would result in self-loops or double edges.- Parameters:
rng
- the random number generatornodeA
- the first node withnodeB
as neighbournodeB
- the second node withnodeA
as neighbourdone
- the set of nodes to pick nodeC
fromnDone
- the number of nodes indone
- Returns:
true
if the edges are successfully rewired,false
otherwise
-
initGeometrySuppressor
public void initGeometrySuppressor()Generates a strong undirected suppressor of selection.Requirements/notes:
Population size: \(N=n^2(1+n(1+n))=n^2+n^3+n^4\) for \(n\) integer. With three types of nodes \(U=n^3\), \(V=n^4\) and \(W=n^2\), each node in \(V\) is connected to one node in \(U\) and to all in \(W\).- See Also:
-
initGeometrySquare
public void initGeometrySquare()Generates a square regular lattice (chessboard). The most common lattices are the von Neumann lattice with four nearest neighbours (north, south, east and west) as well as the Moore lattice with eight nearest neighbours (chess king's moves).Requirements/notes:
- Integer square population size, \(N=n^2\).
- Admissible connectivities: \(4\) (von Neumann) or \(3\times 3-1=8\) (Moore), \(5\times 5-1=24\), \(7\times 7-1=48\) etc.
- For inter-species interactions connectivities are \(+1\) and a connectivity of \(1\) is admissible.
- Boundaries are periodic by default.
- For
SQUARE_MOORE
interactions withGroup.SAMPLING_ALL
and group sizes between2
and8
(excluding boundaries) relies on a particular arrangement of the neighbors, seeIBSDPopulation.playGroupGameAt(IBSGroup)
andIBSCPopulation.playGroupGameAt(IBSGroup)
.
- See Also:
-
initGeometrySquareSelf
private void initGeometrySquareSelf(int side, int fullside, int offset) Utility method to generate a square lattice with exclusively 'self'-connections.Requirements/notes:
- Makes only sense in inter-species interactions.
- Inter-species interactions include 'self'-connections.
- Hierarchical structures may call this method recursively.
- Neighbourhood corresponds to a \(3\times 3\), \(5\times 5\), \(7\times 7\), etc. area.
- Boundaries fixed or periodic (default).
- Parameters:
side
- the side length of the (sub) latticefullside
- the full side length of the entire latticeoffset
- the offset to the sub-lattice
-
initGeometrySquareVonNeumann
private void initGeometrySquareVonNeumann(int side, int fullside, int offset) Utility method to generate a square lattice with von Neumann neighbourhood.Requirements/notes:
- Inter-species interactions include 'self'-connections.
- Hierarchical structures may call this method recursively.
- Neighbourhood corresponds to a \(3\times 3\), \(5\times 5\), \(7\times 7\), etc. area.
- Boundaries fixed or periodic (default).
- Parameters:
side
- the side length of the (sub) latticefullside
- the full side length of the entire latticeoffset
- the offset to the sub-lattice
-
initGeometrySquareVonNeumann2nd
private void initGeometrySquareVonNeumann2nd(int side, int fullside, int offset) Utility method to generate a square lattice with von Neumann neighbourhood.Requirements/notes:
- Inter-species interactions include 'self'-connections.
- Hierarchical structures may call this method recursively.
- Neighbourhood corresponds to a \(3\times 3\), \(5\times 5\), \(7\times 7\), etc. area.
- Boundaries fixed or periodic (default).
- Parameters:
side
- the side length of the (sub) latticefullside
- the full side length of the entire latticeoffset
- the offset to the sub-lattice
-
initGeometrySquareMoore
private void initGeometrySquareMoore(int side, int fullside, int offset) Utility method to generate a square lattice with Moore neighbourhood.Requirements/notes:
- Inter-species interactions include 'self'-connections.
- Hierarchical structures may call this method recursively.
- Boundaries fixed or periodic (default).
- Parameters:
side
- the side length of the (sub) latticefullside
- the full side length of the entire latticeoffset
- the offset to the sub-lattice
-
initGeometrySquare
private void initGeometrySquare(int side, int fullside, int offset) Utility method to generate a square lattice with arbitrarily large neighbourhoods.Requirements/notes:
- Inter-species interactions include 'self'-connections.
- Hierarchical structures may call this method recursively.
- Neighbourhood corresponds to a \(3\times 3\), \(5\times 5\), \(7\times 7\), etc. area.
- Boundaries fixed or periodic (default).
- Parameters:
side
- the side length of the (sub) latticefullside
- the full side length of the entire latticeoffset
- the offset to the sub-lattice
-
initGeometryCube
public void initGeometryCube()Generates a cubic (3D) regular lattice.Requirements/notes:
- Integer cube population size, \(N=n^3\).
- Admissible connectivities: \(6\) or \(3\times 3\times 3-1=26\), \(5\times 5\times 5-1\), \(7\times 7\times 7-1\) etc.
- For inter-species interactions connectivities are \(+1\) and a connectivity of \(1\) is admissible.
- Boundaries fixed or periodic (default).
- For \(N=25'000\) a lattice is generated representing the NOVA installation in the Zürich main train station (2006-20012). EvoLudo was launched on the NOVA on September 9, 2009 to commemorate the bicentenary of Darwin and 150 years since the publication of his On the Origin of Species.
- See Also:
-
initGeometryHoneycomb
public void initGeometryHoneycomb()Generates a hexagonal regular lattice (degree \(6\)). Also called a triangular lattice depending on whether the focus is on the nodes or on the tiles.Requirements/notes:
- Even integer square population size, i.e. \(N=n^2\) where \(n\) is even.
- Boundaries fixed or periodic (default).
- See Also:
-
initGeometryTriangular
public void initGeometryTriangular()Generates a triangular regular lattice (degree \(3\)). Also called a hexagonal lattice depending on whether the focus is on the nodes or on the tiles.Requirements/notes:
- Even integer square population size, i.e. \(N=n^2\) where \(n\) is even.
- Boundaries fixed or periodic (default).
- See Also:
-
initGeometryFruchtGraph
public void initGeometryFruchtGraph()Generates a Frucht graph. The Frucht graph is the smallest regular graph without any further symmetries. A cubic graph with \(12\) nodes and no automorphisms apart from the identity map.Requirements/notes:
- No automorphisms, \(k=3, N=12\).
- The numbering of the nodes follows McAvoy & Hauert (2015).
- See Also:
-
initGeometryTietzeGraph
public void initGeometryTietzeGraph()Generates a Tietze graph. Tietze’s graph is a (regular) cubic graph with twelve vertices but with a higher degree of symmetry than the Frucht graph. Tietze’s graph has twelve automorphisms but is not vertex-transitive.Requirements/notes:
\(12\) automorphisms, \(k=3, N=12\).- See Also:
-
initGeometryFranklinGraph
public void initGeometryFranklinGraph()Generates a Franklin graph. The Franklin graph is another a cubic graph with twelve nodes but is also vertex-transitive. Intuitively speaking, vertex transitivity means that the graph looks the same from the perspective of every node.Requirements/notes:
Vertex-transitive graph, \(k=3, N=12\).- See Also:
-
initGeometryHeawoodGraph
public void initGeometryHeawoodGraph()Generates a Heawood graph. No cubic symmetric graph with \(12\) vertices exists. The closest comparable graph is the Heawood graph, which cubic and symmetric but with \(14\) nodes.Symmetric graphs satisfy the stronger structural symmetry requirements of arc-transitivity. intuitively speaking, arc-transitivity means that not only does the graph look the same from the perspective of every node but also that if a pair of neighbouring individuals is randomly relocated to some other neighbouring pair of nodes, the two individuals are not able to tell whether and where they have been moved even when both are aware of the overall graph structure and share their conclusions.
Requirements/notes:
Symmetric graph, \(k=3, N=14\).- See Also:
-
initGeometryIcosahedronGraph
public void initGeometryIcosahedronGraph()Generates an icosahedron graph. A symmetric graph with \(12\) nodes and degree \(5\).Requirements/notes:
Symmetric graph, \(k=5, N=12\).- See Also:
-
initGeometryDodekahedronGraph
public void initGeometryDodekahedronGraph()Generates a dodecahedron graph. A cubic, symmetric graph with \(20\) nodes (same as Desargue's graph). The two graphs have the same diameter, mean shortest path length, and clustering coefficient. Nevertheless the highly susceptible fixation times differ for the two graphs.Requirements/notes:
Symmetric graph, \(k=3, N=20\).- See Also:
-
initGeometryDesarguesGraph
public void initGeometryDesarguesGraph()Generates a Desargues graph, named after Girard Desargues (1591–1661). A cubic, symmetric graph with \(20\) nodes (same as icosahedron graph). The two graphs have the same diameter, mean shortest path length, and clustering coefficient. Nevertheless the highly susceptible fixation times differ for the two graphs.Requirements/notes:
Symmetric graph, \(k=3, N=20\).- See Also:
-
initGeometryRandomGraph
public void initGeometryRandomGraph()Generate a (connected, directed) random graph.Requirements/notes:
- Rounds link count to even number.
- Ensure minimal assumptions, i.e. fully general graph.
-
initGeometryRandomGraphDirected
public void initGeometryRandomGraphDirected()Generate a (connected, directed) random graph.Requirements/notes:
- check if truly connected
- first node may not necessarily get an incoming link
- ensure minimal assumptions, i.e. fully general graph
-
initGeometryRandomRegularGraph
public void initGeometryRandomRegularGraph()Generate a (connected, undirected) random regular graph.Requirements/notes:
- Graph generation may fail
- After MAX_TRIALS failures, resort to well-mixed population
- Minimize risk of failure?
-
initGeometryScaleFree
public void initGeometryScaleFree()Generate a (connected, undirected) scale-free network. Generates power-law degree distribution first and then a random network that satisfies those connectivities.Requirements/notes:
Makes efforts to match the desired overall connectivity. -
swap
private static void swap(int[] x, int a, int b) Swap elements with indicesa
andb
in arrayx
- Parameters:
x
- [] the data arraya
- the index of the first elementb
- the index of the second element
-
initGeometryDegreeDistr
private boolean initGeometryDegreeDistr(int[] distr) Utility method to generate network with a given degree distribution.Requirements/notes:
The degree distribution is sorted with descending degrees.- Parameters:
distr
- the array to store the degree distribution- Returns:
true
if generation succeeded
-
initGeometryScaleFreeBA
public void initGeometryScaleFreeBA()Generate a (connected, undirected) scale-free network following the procedure by Barabási & Albert (1999).Requirements/notes:
None.- See Also:
-
initGeometryScaleFreeKlemm
public void initGeometryScaleFreeKlemm()Generate a (connected, undirected) scale-free network following the procedure by Klemm & Eguíluz (2001).Requirements/notes:
- Effective connectivity is \(k (N-1)/N\) where \(k\) is the desired average connectivity and \(N\) is the population size.
- Add bookkeeping to optimize generation time.
- See Also:
-
rewire
public void rewire()Add/rewire directed and undirected random links.Requirements/notes:
None.- See Also:
-
rewireUndirected
public boolean rewireUndirected(double prob) Rewire undirected links.Requirements/notes:
- Requires an undirected graph.
- Rewiring preserves connectivity of all nodes.
- Resulting graph obviously remains undirected.
- The number of rewired links is \(N_\text{rewired}=\min {N_\text{links}, N_\text{links} \log(1-p_\text{undir})}\), i.e. at most the number undirected links in the graph. Thus, at most an expected fraction of \(1-1/e\) (or \(~63%\)) of original links get rewired.
- Parameters:
prob
- the probability of rewiring an undirected link- Returns:
true
if geometry rewired
-
addUndirected
public boolean addUndirected()Add undirected links.Requirements/notes:
The number of links added is \(N_\text{add}=N_\text{links} p_\text{undir}\).- Returns:
true
if adding of undirected links successfult
-
rewireDirected
public boolean rewireDirected()Rewire directed links.Requirements/notes:
- Only undirected graphs are guaranteed to remain connected.
- Resulting graph is obviously directed (even if original was undirected).
- Rewiring preserves connectivity of all nodes (both inlinks and outlinks).
- The number of rewired links is \(N_\text{rewired}=\min {N_\text{links}, N_\text{links} \log(1-p_\text{dir})}\), i.e. at most the number directed links in the graph. Thus, at most an expected fraction of \(1-1/e\) (or \(~63%\)) of original links get rewired.
- ToDo: Rewrite similar to rewireUndirected().
- Returns:
true
if rewiring succeeded
-
addDirected
public boolean addDirected()Add directed links to network.Requirements/notes:
The number of links added is \(N_\text{add}=N_\text{links} p_\text{dir}\).- Returns:
true
if adding links succeeded
-
evaluate
public void evaluate()Evaluate geometry. Convenience method to set frequently used quantities such asminIn, maxOut, avgTot
etc.Requirements/notes:
- For
Geometry.Type.MEANFIELD
geometries all quantities are set to zero. - Dynamic graphs are always evaluated because all quantities are ephemeral.
- For
-
isLattice
public boolean isLattice()Utility method to determine whether a given geometry type is a lattice.- Returns:
true
ifgeometry
is lattice,false
otherwise
-
isGraphConnected
public boolean isGraphConnected()Check if graph is connected.Requirements/notes:
Requires undirected graphs.- Returns:
true
if graph is connected
-
isGraphConnected
public boolean isGraphConnected(int node, boolean[] check) Check if any other node can be reached fromnode
.Requirements/notes:
- Requires undirected graphs.
check
is aboolean
array indicating which nodes can or cannot be reached fromnode
.
- Parameters:
node
- the node to check the connections fromcheck
- the array of nodes that can be reached- Returns:
true
if graph is connected
-
swapEdges
private boolean swapEdges(int a, int an, int b, int bn) Utility method to swap edges (undirected links) between nodes: change linka-an
toa-bn
andb-bn
tob-an
.Requirements/notes:
Does the same asrewireEdgeAt(a, bn, an); rewireEdgeAt(b, an, bn);
but without allocating and freeing memory.- Parameters:
a
- the first nodean
- the neighbour of the first nodeb
- the second nodebn
- the neighbour of the second node- Returns:
true
if swap succeeded
-
checkConnections
public boolean checkConnections()Check consistency of links.Requirements/notes:
- Self connections are unacceptable.
- Double links between nodes are unacceptable.
- For undirected networks every outgoing link must correspond to an incoming link.
- ToDo: "self-connections" are acceptable for inter-species interactions.
- Returns:
true
if check succeeded
-
addEdgeAt
public void addEdgeAt(int from, int to) Add edge (undirected link) from nodefrom
to nodeto
.Requirements/notes:
None.- Parameters:
from
- the first nodeto
- the second node
-
addLinkAt
public void addLinkAt(int from, int to) Add link (directed link) from nodefrom
to nodeto
.Requirements/notes:
- Allocate new memory if required.
- Geometry needs to be re-evaluated when finished.
- Parameters:
from
- the index of the first nodeto
- the index of the second node- See Also:
-
removeEdgeAt
public void removeEdgeAt(int from, int to) Remove edge (undirected link) from nodefrom
to nodeto
.Requirements/notes:
- Does not update
maxIn
,maxOut
ormaxTot
. - Geometry needs to be re-evaluated when finished.
- Parameters:
from
- the index of the first nodeto
- the index of the second node- See Also:
- Does not update
-
removeLinkAt
public void removeLinkAt(int from, int to) Remove link (directed link) from nodefrom
to nodeto
.Requirements/notes:
- Does not update
maxIn
,maxOut
ormaxTot
. - Geometry needs to be re-evaluated when finished.
- Parameters:
from
- the index of the first nodeto
- the index of the second node- See Also:
- Does not update
-
clearLinksFrom
public void clearLinksFrom(int idx) Remove all outgoing links from nodeidx
.Requirements/notes:
Doesn't free memory.- Parameters:
idx
- the index of the node to remove all outgoing links
-
removeInLink
private void removeInLink(int from, int to) Remove incoming link (directed link) to nodeto
from nodefrom
.Requirements/notes:
Geometry needs to be re-evaluated when done with all manipulations.- Parameters:
from
- the index of the first nodeto
- the index of the second node- See Also:
-
clearLinksTo
public void clearLinksTo(int idx) Remove all incoming links to nodeidx
.Requirements/notes:
Doesn't free memory.- Parameters:
idx
- the index of the node to remove all incoming links
-
removeOutLink
private void removeOutLink(int from, int to) Remove outgoing link (directed link) from nodefrom
to nodeto
.Requirements/notes:
Geometry needs to be re-evaluated when done with all manipulations.- Parameters:
from
- the index of the first nodeto
- the index of the second node- See Also:
-
rewireLinkAt
public void rewireLinkAt(int from, int to, int prev) Rewire directed link from nodefrom
to nodeprev
to nodeto
.Requirements/notes:
Geometry needs to be re-evaluated when done with all manipulations.- Parameters:
from
- the index of the first nodeto
- the index of the second nodeprev
- the index of the second node- See Also:
-
rewireEdgeAt
public void rewireEdgeAt(int from, int to, int prev) Rewire edge (undirected link) from nodefrom
to nodeprev
to nodeto
.Requirements/notes:
Geometry needs to be re-evaluated when done with all manipulations.- Parameters:
from
- the index of the first nodeto
- the index of the second nodeprev
- the index of the second node- See Also:
-
isNeighborOf
public boolean isNeighborOf(int focal, int check) Check ifcheck
is a neighbor offocal
(not necessarily the other way round). For undirected networksfocal
andcheck
can be exchanged.- Parameters:
focal
- index of focal individualcheck
- index of individual to be checked- Returns:
true
ifcheck
is neighbor offocal
-
deriveInteractionGeometry
Derive interaction geometry from current (competition) geometry. This is only possible ifinterCompSame
istrue
. Returnsnull
otherwise.If
opp==population
then it is an intra-species interaction, which allows to simply returnthis
, i.e. no cloning etc. required. Otherwise the geometry is cloned, theopponent
set and 'self-loops' added for interactions with individuals in the same location.- Parameters:
opp
- the population of interaction partners- Returns:
- the derived interaction geometry or
null
if it cannot be derived
-
deriveCompetitionGeometry
Derive competition geometry from current (interaction) geometry. This is only possible ifinterCompSame
istrue
. Returnsnull
otherwise.If
opp==population
then it is an intra-species interaction, which allows to simply returnthis
, i.e. no cloning etc. required. Otherwise the geometry is cloned, theopponent
, the opponent set and 'self-loops' removed.- Returns:
- the derived interaction geometry or
null
if it cannot be derived
-
parse
Parse string of geometry specificationscli
. Check for consistency of settings (e.g. in terms of population size, connectivity). If adjustments are required and possible inform the user through thelogger
.- Parameters:
cli
- the string with geometry specifications- Returns:
true
if reset is required
-
usage
Get the usage description for the command line option--geometry
.- Returns:
- the usage description
-
clone
Clone geometry.Requirements/notes:
-
equals
Check ifthis
Geometry andgeo
refer to the same structures. Different realizations of random structures, such as random regular graphs, are considered equal as long as their characteristic parameters are the same.- Parameters:
geo
- the geometry to compare to.- Returns:
true
if the structures are the same
-
encodeGeometry
Encode geometry as a plist string fragment.- Returns:
- the geometry encoded as a plist
- See Also:
-
decodeGeometry
Decode the geometry from the plist. The structure is encoded in map which provides array of neighbor indices for each individual index.Requirements/notes:
The population (including its geometry/geometries) must already have been initialized. This only restores a particular (unique) geometry.- Parameters:
plist
- the plist encoding the geometry- See Also:
-
isUniqueGeometry
public boolean isUniqueGeometry()Check if current geometry unique. Only unique geomteries need to be encoded.Requirements/notes:
- Lattices etc. are not unique because they can be identically recreated.
- All geometries involving random elements are unique.
- Returns:
true
if geometry is unique
-
isUniqueGeometry
Helper method to check uniqueness of the geometrygeo
.Requirements/notes:
Hierarchical geometries require recursive checks of uniqueness.- Parameters:
geo
- the geometry to be checked for uniqueness- Returns:
true
if geometry is unique
-