Class Network2D

All Implemented Interfaces:
Iterable<Node2D>, Collection<Node2D>, Iterator<Node2D>, List<Node2D>, SequencedCollection<Node2D>
Direct Known Subclasses:
Network2DGWT

public abstract class Network2D extends Network<Node2D>
Graphical representation of generic population geometries in 2D. A network corresponds to a (possibly ephemeral) collection and configuration of nodes.
Author:
Christoph Hauert
  • Field Details

    • FIBONACCI_RADIAL_EXPONENT

      private static final double FIBONACCI_RADIAL_EXPONENT
      Radial growth exponent of the deterministic well-mixed phyllotactic seed. The value 0.5 reproduces Vogel's area-uniform law, while larger values move the layout towards an Archimedean-looking spiral with a denser center. Convenient values to compare are 0.5, 0.7, 0.8, and 1.0.
      See Also:
    • attraction

      private final Vector2D attraction
      Helper variable to store intermediate results when considering the potential energy resulting from the attraction between neighbouring nodes.
    • repulsion

      private final Vector2D repulsion
      Helper variable to store intermediate results when considering the potential energy resulting from the repulsion between nodes.
    • vec

      private final Vector2D vec
      Temporary storage for the directional vector connecting two nodes.
    • R

      public static final double R
      The baseline size of the 2D universe.
      See Also:
    • IR

      protected static final double IR
      The inverse size of the baseline 2D universe. Convenience constant.
      See Also:
    • IR2

      protected static final double IR2
      The inverse squared size of the baseline 2D universe, 1/R<sup>2</sup>. Convenience constant.
      See Also:
    • CONVERGENCE_ACCURACY_SCALE

      private static final double CONVERGENCE_ACCURACY_SCALE
      Scale factor applied to the nominal 2D accuracy. The contact-based spring energy is smaller than the former center-distance energy, so 2D layouts use a tighter effective threshold to avoid terminating too early.
      See Also:
  • Constructor Details

    • Network2D

      protected Network2D(EvoLudo engine, AbstractGeometry geometry)
      Create a new network in 2D for the given engine and geometry.
      Parameters:
      engine - the pacemaker for running the model
      geometry - the structure of the population
  • Method Details

    • getLinks

      public Path2D 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.
      Specified by:
      initNodes in class Network<Node2D>
      Parameters:
      pnorm - the maximal radius of a node
      nnorm - the minimal radius of a node
      unitradius - the reference radius of a node
    • relax

      public double relax(int nodeidx)
      Description copied from class: Network
      Relax the potential energy a single node with index nodeidx by adjusting its position. The potential energy increases proportional to D where D denotes the distance to its neighbours and decreases proportional to 1/D<sup>2</sup> where D refers to the distance from all other nodes.
      Specified by:
      relax in class Network<Node2D>
      Parameters:
      nodeidx - the index of the node to relax
      Returns:
      the change in potential energy
    • relax

      public double relax(int nodeidx, double dt)
      Description copied from class: Network
      Relaxes the network node with index nodeidx. The attraction and repulsion forces act on the node for a time interval dt, which limits the changes in the position of the node.
      Specified by:
      relax in class Network<Node2D>
      Parameters:
      nodeidx - the index of the node to relax
      dt - the time interval
      Returns:
      the change in potential energy
      See Also:
    • getConvergenceAccuracy

      protected double getConvergenceAccuracy()
      Description copied from class: Network
      Get the effective convergence threshold for the layouting process. The base implementation returns Network.accuracy, but subclasses may tighten or relax the criterion when their layout energies use a different natural scale.
      Overrides:
      getConvergenceAccuracy in class Network<Node2D>
      Returns:
      the effective convergence threshold
    • repulsion

      protected double repulsion(int nodeidx)
      Description copied from class: Network
      Calculate the potential energy based on repulsion for the node with index nodeidx. Return the net repulsion (overall direction and magnitude) acting on it in Network.repulsion(int). Implementations may include additional short-range penalties here, for example to discourage overlap between nodes with finite size.

      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.
      Specified by:
      repulsion in class Network<Node2D>
      Parameters:
      nodeidx - the index of the node to relax
      Returns:
      the potential energy of the node
    • 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 index nodeidx. Return the net attraction (overall direction and magnitude) acting on it in Network.attraction(int).
      Specified by:
      attraction in class Network<Node2D>
      Parameters:
      nodeidx - the index of the node to relax
      Returns:
      the potential energy of the node
    • pairDistance

      private double pairDistance(Node2D from, Node2D to, int fromidx, int toidx)
      Set vec to the directional vector from from to to and return the corresponding center-to-center distance. Coincident nodes are separated by a deterministic fallback direction to keep layouting stable and reproducible.
      Parameters:
      from - the source node
      to - the target node
      fromidx - the index of the source node
      toidx - the index of the target node
      Returns:
      the center-to-center distance
    • finishLayout

      public void finishLayout()
      Description copied from class: Network
      Add the finishing touches to the graph layout:
      1. shift center of mass into origin
      2. rescale size of graph
      3. find number of links
      Specified by:
      finishLayout in class Network<Node2D>
    • linkNodes

      public void linkNodes()
      Description copied from class: Network
      Generate the links for the current configuration of the network.
      Specified by:
      linkNodes in class Network<Node2D>
    • addEdge

      private void addEdge(int source, int target)
      Add an undirected edge to the link path.
      Parameters:
      source - the source node index
      target - the target node index
    • addArc

      private void addArc(int source, int target, Vector2D link, Vector2D tip, double arrowsize)
      Add a directed arc, including its arrowhead, to the link path.
      Parameters:
      source - the source node index
      target - the target node index
      link - helper vector aligned with the arc
      tip - helper vector storing the arrow tip position
      arrowsize - the normalized arrow size
    • toArray

      public Node2D[] toArray()
      Specified by:
      toArray in interface Collection<Node2D>
      Specified by:
      toArray in interface List<Node2D>
      Overrides:
      toArray in class AbstractCollection<Node2D>
    • get

      public Node2D get(int index)
      Specified by:
      get in interface List<Node2D>
      Specified by:
      get in class AbstractList<Node2D>
    • equals

      public boolean equals(Object obj)
      Specified by:
      equals in interface Collection<Node2D>
      Specified by:
      equals in interface List<Node2D>
      Overrides:
      equals in class Network<Node2D>
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<Node2D>
      Specified by:
      hashCode in interface List<Node2D>
      Overrides:
      hashCode in class Network<Node2D>