Class AbstractGeometry
Object
AbstractGeometry
- Direct Known Subclasses:
AbstractLattice, AbstractNetwork, CompleteGeometry, DesarguesGeometry, DodekahedronGeometry, DynamicGeometry, FranklinGeometry, FruchtGeometry, HeawoodGeometry, IcosahedronGeometry, RandomDirectedGeometry, RandomGeometry, StarGeometry, StrongAmplifierGeometry, StrongSuppressorGeometry, SuperstarGeometry, TietzeGeometry, WellmixedGeometry, WheelGeometry
Abstract implementation of the population interaction and competition
structures. Instances of
AbstractGeometry describe neighbourhood
graphs for IBS, PDE's and graphical representations, such as trait
distributions in 1D or 2D.-
Field Summary
FieldsModifier and TypeFieldDescription(package private) doubleConnectivity (average number of neighbors).(package private) static final int[]Empty link arrays used for well-mixed geometries and while allocating networks lazily.(package private) final EvoLudoThe pacemaker of all models.(package private) GeometryFeaturesLazily computed summary statistics for the geometry.int[][]The array storing the neighbourhood of each node by listing the indices of nodes that connect to this one.protected booleantrueif this geometry links different species/populations.(package private) booleantrueif the network structure is regular (all nodes have the same number of neighbours).(package private) booleantrueif rewiring should be applied.(package private) booleanConvenience flag denoting whether intra- and interspecific competitions are identical.(package private) booleanFlag indicating whether the network structure is undirected.(package private) booleantrueif the network structure has been successfully initialized.int[]The array storing the number of incoming neighbours for each node.int[]The array storing the number of outgoing neighbours for each node.(package private) final LoggerLogger for keeping track of and reporting events and issues.(package private) StringOptional descriptive name.(package private) Network2DLocal storage for the 2D representation of this graph.(package private) Network3DLocal storage for the 3D representation of this graph.int[][]The array storing the neighbourhood of each node by listing the indices of nodes that this one connects to.(package private) doubleProbability for adding new links.(package private) doubleProbability for rewiring.(package private) intThe number of nodes in the graph.(package private) StringOptional CLI specification used to configure this geometry.(package private) GeometryTypeCurrent geometry type handled by this instance. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractGeometry(EvoLudo engine) Create a new geometry scaffold linked to the given pacemaker. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd directed links to network.voidaddEdgeAt(int nodea, int nodeb) Add edge (undirected link) by inserting a pair of directed links.voidaddLinkAt(int from, int to) Add a directed link fromfromtoto, allocating storage as needed.booleanAdd undirected links.protected voidalloc()Allocate the memory necessary to store the network structure.final booleancheck()Validate geometry parameters and adjust infeasible settings.private booleanCheck consistency of in- and out-connections.private booleancheckMultiple(int[] degree, int[][] links, String type) Check for multiple connections in the given links.private booleanCheck regularity of the graph.private booleanCheck for self-connections (loops).protected booleanHook for subclasses to implement geometry specific checks.private booleanCheck undirected structure of the graph.voidclearLinksFrom(int idx) Remove all outgoing links from nodeidx.voidclearLinksTo(int idx) Remove all incoming links to nodeidx.clone()Clone geometry.static AbstractGeometryInstantiate the requested geometry based oncli.static AbstractGeometrycreate(EvoLudo engine, GeometryType type) Factory method for creating geometry instances by type.voiddecodeGeometry(Plist plist) Decode the geometry from the plist.Derive competition geometry from current (interaction) geometry for inter-species interactions withisSingle == true.static booleandisplaySingle(AbstractGeometry interaction, AbstractGeometry competition) Checks whether a single graphical representation can be used for the interaction and competition graphs.Encode geometry as a plist string fragment.protected booleanenforceSize(int requiredSize) Ensure the geometry uses at leastrequiredSizenodes.booleandoubleGet the probability used when adding new links.doubleGet the average node degree (connectivity) configured for the geometry.Retrieve the name of the key for storing geometry in plist.Evaluate geometry.protected StringgetLabel()Compose a human readable prefix for log messages.getName()Retrieve the display name of the geometry (sans trailing structural suffixes such as": Structure").Retrieve (and lazily create) the 2D representation associated with this geometry.Retrieve (and lazily create) the 3D representation associated with this geometry.doubleGet the probability used when rewiring existing links.intgetSize()Report the current number of nodes contained in the geometry.getSpecs()Get the CLI specification string that configured this geometry.getType()Get the currentGeometryTypethat defines this structure.inthashCode()private booleanHelper that checks whetherneighscontainssrcand logs an error if it does not.abstract voidinit()Initialise the geometry.booleanCheck consistency of links.booleanCheck if graph is connected.private booleanisGraphConnected(int node, boolean[] check) Depth-first traversal helper used to determine connectivity.booleanCheck whether this geometry connects individuals from different populations.booleanUtility method to determine whether a given geometry type is a lattice.booleanisNeighborOf(int focal, int check) Check whethercheckis currently a neighbour offocal.booleanCheck whether the geometry is regular (all nodes share the same degree).booleanCheck if the geometry was modified by rewiring.booleanisSingle()Check if a single geometry suffices for interaction and competition structures.booleanisType(GeometryType type) Convenience helper to check the geometry type.booleanCheck whether all links are undirected.booleanisUnique()Check if current geometry unique.booleanparse()Re-parse the stored specification string.(package private) booleanParse geometry-specific CLI options.voidremoveEdgeAt(int nodea, int nodeb) Remove edge (undirected link) fromnodeatonodeb.private voidremoveInLink(int from, int to) Remove an incoming link (directed) to nodetofrom nodefrom.voidremoveLinkAt(int from, int to) Remove a directed link from nodefromto nodeto.private voidremoveOutLink(int from, int to) Remove an outgoing link (directed) from nodefromto nodeto.voidrewire()Add/rewire directed and undirected random links.booleanRewire directed links.voidrewireEdgeAt(int focal, int newneigh, int oldneigh) Rewire an undirected edge so that an edge formerly connectingfocalandoldneighnow connectsfocalandnewneigh.voidrewireLinkAt(int from, int to, int prev) Rewire a directed link so that an edge formerly connectingfromtoprevnow connects toto.protected voidrewireUndirected(double prob) Rewire undirected links.voidsetAddwire(double probability) Sets the probability for adding links to the network.voidsetConnectivity(double connectivity) Sets the connectivity (average number of neighbors).voidsetInterspecies(boolean interspecies) Set whether this geometry links different populations.voidSet a descriptive name for this geometry (used in UI/tooltips).voidsetNetwork2D(Network2D net) Store the 2D network representation.voidsetNetwork3D(Network3D net) Store the 3D network representation.voidsetRewire(double probability) Sets the probability for rewiring existing links.voidsetSingle(boolean single) Sets whether a single geometry is used for both interaction and competition graphs.booleansetSize(int size) Set the size of the network.protected voidsetType(GeometryType type) Update the geometryGeometryType.(package private) booleanswapEdges(int a, int an, int b, int bn) Utility method to swap edges (undirected links) between nodes: change linka-antoa-bnandb-bntob-an.usage()Get the usage description for the command line option--geometry.private voidEnsure rewiring parameters are feasible for the current connectivity and adjust them if needed.protected voidLog a warning message using the geometry-conditioned label.
-
Field Details
-
EMPTY_LINKS
static final int[] EMPTY_LINKSEmpty link arrays used for well-mixed geometries and while allocating networks lazily. -
engine
The pacemaker of all models. Interface with the outside world. -
logger
Logger for keeping track of and reporting events and issues. -
network2D
Network2D network2DLocal storage for the 2D representation of this graph. -
network3D
Network3D network3DLocal storage for the 3D representation of this graph. -
specs
String specsOptional CLI specification used to configure this geometry. -
name
String nameOptional descriptive name. -
type
GeometryType typeCurrent geometry type handled by this instance. -
size
int sizeThe number of nodes in the graph. -
isUndirected
boolean isUndirectedFlag indicating whether the network structure is undirected. -
isRegular
boolean isRegulartrueif the network structure is regular (all nodes have the same number of neighbours). -
isRewired
boolean isRewiredtrueif rewiring should be applied. -
isInterspecies
protected boolean isInterspeciestrueif this geometry links different species/populations. -
features
GeometryFeatures featuresLazily computed summary statistics for the geometry. -
isValid
boolean isValidtrueif the network structure has been successfully initialized. -
isSingle
boolean isSingleConvenience flag denoting whether intra- and interspecific competitions are identical. -
connectivity
double connectivityConnectivity (average number of neighbors). -
pRewire
double pRewireProbability for rewiring. -
pAddwire
double pAddwireProbability for adding new links. -
in
public int[][] inThe array storing the neighbourhood of each node by listing the indices of nodes that connect to this one. -
out
public int[][] outThe array storing the neighbourhood of each node by listing the indices of nodes that this one connects to. -
kin
public int[] kinThe array storing the number of incoming neighbours for each node. -
kout
public int[] koutThe array storing the number of outgoing neighbours for each node.
-
-
Constructor Details
-
AbstractGeometry
Create a new geometry scaffold linked to the given pacemaker.- Parameters:
engine- the EvoLudo engine coordinating simulations
-
-
Method Details
-
create
Instantiate the requested geometry based oncli. Parsing of geometry specific arguments is left to the created instance viaparse(String).- Parameters:
engine- the EvoLudo engine providing module/CLI metadatacli- the command line style geometry descriptor- Returns:
- the instantiated geometry (arguments not yet parsed)
-
create
Factory method for creating geometry instances by type.- Parameters:
engine- pacemaker used by the geometrytype- geometry type to instantiate- Returns:
- the instantiated geometry
-
deriveCompetitionGeometry
Derive competition geometry from current (interaction) geometry for inter-species interactions withisSingle == true. This clones the interaction geometry and simply removes links to self, which corresponds to interactions with individuals at the same location in the other species.- Returns:
- the derived competition geometry
-
setName
Set a descriptive name for this geometry (used in UI/tooltips).- Parameters:
name- the human-readable name
-
getName
Retrieve the display name of the geometry (sans trailing structural suffixes such as": Structure").- Returns:
- the display name or the empty string for anonymous structures
-
getEncodeKey
Retrieve the name of the key for storing geometry in plist.- Returns:
- the plist key
-
getType
Get the currentGeometryTypethat defines this structure.- Returns:
- the current geometry
GeometryType
-
setType
Update the geometryGeometryType.- Parameters:
type- the new type
-
setNetwork2D
Store the 2D network representation.- Parameters:
net- the 2D network
-
getNetwork2D
Retrieve (and lazily create) the 2D representation associated with this geometry.- Returns:
- the stored 2D network representation (may be
null)
-
setNetwork3D
Store the 3D network representation.- Parameters:
net- the 3D network
-
getNetwork3D
Retrieve (and lazily create) the 3D representation associated with this geometry.- Returns:
- the stored 3D network representation (may be
null)
-
displaySingle
Checks whether a single graphical representation can be used for the interaction and competition graphs. Two distinct graphical representations 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:
interaction- the interaction geometry (required)competition- the competition geometry (optional)- Returns:
trueif a single representation can be reused for both structures
-
getSpecs
Get the CLI specification string that configured this geometry.- Returns:
- the CLI specification string that configured this geometry, or
null
-
parse
Parse geometry-specific CLI options.- Parameters:
spec- the argument string without the geometry key- Returns:
trueif parsing succeeded,falseif invalid
-
parse
public boolean parse()Re-parse the stored specification string.- Returns:
trueif parsing succeeded
-
setSize
public boolean setSize(int size) Set the size of the network.- Parameters:
size- the desired number of nodes- Returns:
trueif the size changed (requiring a reset)
-
getSize
public int getSize()Report the current number of nodes contained in the geometry.- Returns:
- the number of nodes in the network
-
isType
Convenience helper to check the geometry type.- Parameters:
type- the type to compare to- Returns:
trueifgetType()matchestype
-
setRewire
public void setRewire(double probability) Sets the probability for rewiring existing links.- Parameters:
probability- rewiring probability
-
getRewire
public double getRewire()Get the probability used when rewiring existing links.- Returns:
- the rewiring probability
-
setAddwire
public void setAddwire(double probability) Sets the probability for adding links to the network.- Parameters:
probability- link-addition probability
-
getAddwire
public double getAddwire()Get the probability used when adding new links.- Returns:
- the link-addition probability
-
isRewired
public boolean isRewired()Check if the geometry was modified by rewiring.- Returns:
trueif the geometry has been rewired.
-
setSingle
public void setSingle(boolean single) Sets whether a single geometry is used for both interaction and competition graphs.- Parameters:
single-trueif both graphs are identical
-
isSingle
public boolean isSingle()Check if a single geometry suffices for interaction and competition structures.- Returns:
trueif a single geometry suffices for interaction and competition structures
-
setConnectivity
public void setConnectivity(double connectivity) Sets the connectivity (average number of neighbors).- Parameters:
connectivity- average degree
-
getConnectivity
public double getConnectivity()Get the average node degree (connectivity) configured for the geometry.- Returns:
- the current connectivity (average degree)
-
isUndirected
public boolean isUndirected()Check whether all links are undirected.- Returns:
trueif this geometry is undirected.
-
isRegular
public boolean isRegular()Check whether the geometry is regular (all nodes share the same degree).- Returns:
trueif this geometry is regular (all nodes have identical degree).
-
check
public final boolean check()Validate geometry parameters and adjust infeasible settings.- Returns:
trueif adjustments require a reset
-
checkSettings
protected boolean checkSettings()Hook for subclasses to implement geometry specific checks.- Returns:
trueif adjustments require a reset
-
validateRewiring
private void validateRewiring()Ensure rewiring parameters are feasible for the current connectivity and adjust them if needed. -
enforceSize
protected boolean enforceSize(int requiredSize) Ensure the geometry uses at leastrequiredSizenodes.- Parameters:
requiredSize- the minimum allowed size- Returns:
trueif enforcing the size changed the network
-
warn
Log a warning message using the geometry-conditioned label.- Parameters:
message- the message to log
-
getLabel
Compose a human readable prefix for log messages.- Returns:
- the label to prepend to log output
-
alloc
protected void alloc()Allocate the memory necessary to store the network structure. -
getFeatures
Evaluate geometry. Convenience method to set frequently used quantities such asminIn, maxOut, avgTotetc.- Returns:
- cached or freshly computed
GeometryFeatures
-
isLattice
public boolean isLattice()Utility method to determine whether a given geometry type is a lattice.- Returns:
trueifgetType()is lattice,falseotherwise.
-
isUnique
public boolean isUnique()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.
- Complete graphs, stars, wheels, etc. are not unique.
- All geometries involving random elements are unique.
- All rewired geometries are unique.
- Hierarchical geometries require recursive checks of uniqueness.
- Returns:
trueif geometry is unique
-
isGraphConnected
public boolean isGraphConnected()Check if graph is connected.- Returns:
trueif graph is connected
-
isGraphConnected
private boolean isGraphConnected(int node, boolean[] check) Depth-first traversal helper used to determine connectivity.- Parameters:
node- node to visitcheck- bookkeeping array marking visited nodes- Returns:
trueif all nodes have been visited
-
isInterspecies
public boolean isInterspecies()Check whether this geometry connects individuals from different populations.- Returns:
trueif this geometry links two different populations.
-
setInterspecies
public void setInterspecies(boolean interspecies) Set whether this geometry links different populations.- Parameters:
interspecies-truefor inter-species interactions
-
rewire
public void rewire()Add/rewire directed and undirected random links.Requirements/notes:
None.- See Also:
-
rewireUndirected
protected void 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, the expected fraction of original links rewired at most an \(1-1/e\) (or \(~63%\)).
- Any rewiring attempts that disconnect the graph are reverted (but still count towards the number of rewired links to prevent deadlocks in graphs with low connectivity).
- Parameters:
prob- the probability of rewiring an undirected link
-
swapEdges
boolean swapEdges(int a, int an, int b, int bn) Utility method to swap edges (undirected links) between nodes: change linka-antoa-bnandb-bntob-an.Requirements/notes:
Equivalent to invokingrewireEdgeAt(a, bn, an);followed byrewireEdgeAt(b, an, bn);but avoids the additional allocations of those helper methods.- Parameters:
a- the first nodean- the neighbour ofato replaceb- the second nodebn- the neighbour ofbto replace- Returns:
trueif the swap succeeded
-
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:
trueif 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:
trueif 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:
trueif adding links succeeded
-
addEdgeAt
public void addEdgeAt(int nodea, int nodeb) Add edge (undirected link) by inserting a pair of directed links.- Parameters:
nodea- the index of the first nodenodeb- the index of the second node
-
addLinkAt
public void addLinkAt(int from, int to) Add a directed link fromfromtoto, allocating storage as needed.Requirements/notes:
- Allocates additional memory for adjacency lists as needed.
- Marks the geometry as requiring recomputation of statistics (via
getFeatures()) before cached values are used again.
- Parameters:
from- the source node indexto- the destination node index
-
removeEdgeAt
public void removeEdgeAt(int nodea, int nodeb) Remove edge (undirected link) fromnodeatonodeb. The convenience method simply removes the directed link in both directions.- Parameters:
nodea- the index of the first nodenodeb- the index of the second node
-
removeLinkAt
public void removeLinkAt(int from, int to) Remove a directed link from nodefromto nodeto. Statistics are not updated immediately; callgetFeatures()afterwards if fresh metrics are required.- Parameters:
from- the index of the first nodeto- the index of the second node
-
clearLinksFrom
public void clearLinksFrom(int idx) Remove all outgoing links from nodeidx. Memory is retained for potential reuse.- Parameters:
idx- the index of the node whose outgoing links should be removed
-
clearLinksTo
public void clearLinksTo(int idx) Remove all incoming links to nodeidx. Memory is retained for potential reuse.- Parameters:
idx- the index of the node whose incoming links should be removed
-
removeInLink
private void removeInLink(int from, int to) Remove an incoming link (directed) to nodetofrom nodefrom. Does not shrink the backing arrays.- Parameters:
from- the node that previously pointed tototo- the node that received the incoming edge
-
removeOutLink
private void removeOutLink(int from, int to) Remove an outgoing link (directed) from nodefromto nodeto. Does not shrink the backing arrays.- Parameters:
from- the node whose outgoing edge should be removedto- the neighbor to disconnect fromfrom
-
rewireLinkAt
public void rewireLinkAt(int from, int to, int prev) Rewire a directed link so that an edge formerly connectingfromtoprevnow connects toto. Statistics are not updated untilgetFeatures()is called to recompute them.- Parameters:
from- the node whose outgoing link should changeto- the new neighbourprev- the previous neighbour to disconnect
-
rewireEdgeAt
public void rewireEdgeAt(int focal, int newneigh, int oldneigh) Rewire an undirected edge so that an edge formerly connectingfocalandoldneighnow connectsfocalandnewneigh.- Parameters:
focal- the node whose neighbour should changenewneigh- the new neighbouroldneigh- the previous neighbour to disconnect
-
isNeighborOf
public boolean isNeighborOf(int focal, int check) Check whethercheckis currently a neighbour offocal.- Parameters:
focal- the node whose adjacency list to scancheck- the node to test for adjacency- Returns:
trueifcheckoccurs amongfocal's outgoing links
-
init
public abstract void init()Initialise the geometry. -
usage
Get the usage description for the command line option--geometry.- Returns:
- the usage description
-
isConsistent
public boolean isConsistent()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.
- Returns:
trueif check succeeded
-
checkMultiple
Check for multiple connections in the given links.- Parameters:
degree- the degree of each nodelinks- the adjacency listtype- the type of connection ("in" or "out")- Returns:
trueif no multiple connections found
-
checkInOut
private boolean checkInOut()Check consistency of in- and out-connections. Every in-connection must be balanced by a corresponding out-connection and vice versa.- Returns:
trueif all connections are consistent
-
checkSelfing
private boolean checkSelfing()Check for self-connections (loops).- Returns:
trueif no self-connections found
-
checkRegular
private boolean checkRegular()Check regularity of the graph.- Returns:
trueif the graph is regular
-
checkUndirected
private boolean checkUndirected()Check undirected structure of the graph. Every outgoing link must be balanced by a corresponding incoming link and vice versa.- Returns:
trueif the graph is undirected
-
hasNeigh
Helper that checks whetherneighscontainssrcand logs an error if it does not.- Parameters:
src- the node whose reciprocal connection is requiredtarget- the node whose adjacency list is being inspectedneighs- adjacency list oftargetnNeigh- number of valid entries inneighsdir- textual description of the direction being verified- Returns:
trueif a reciprocal connection is present
-
clone
Clone geometry.Requirements/notes:
-
hashCode
-
equals
-
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:
-