Class Network

All Implemented Interfaces:
Iterable<Node>, Collection<Node>, Iterator<Node>, List<Node>, SequencedCollection<Node>
Direct Known Subclasses:
Network2D, Network3D

public abstract class Network extends AbstractList<Node> implements Iterator<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:
  • Field Details

    • status

      protected Network.Status status
      The status of the network layout.
    • nNodes

      public int nNodes
      The number of nodes in the network. Convenience variable. This must remain in sync with geometry.size and nodes.length.
    • nodes

      protected Node[] nodes
      The array with all nodes of this network.
    • geometry

      protected Geometry geometry
      The structure of the population.
    • timestamp

      public double timestamp
      The timestamp of the last time the layouting process has completed.
    • accuracy

      protected double accuracy
      The desired accuracy of the layouting process. The layouting process stops if the change in potential energy falls below this threshold.
    • radius

      double radius
      The radius of the network.
    • isRunning

      protected boolean isRunning
      The flag to indicate whether the layouting process is running.
    • prevPotential

      protected double prevPotential
      The potential energy of the previous network layout/configuration.
    • prevAdjust

      protected double prevAdjust
      The best (smallest) adjustment (lowering of the energy state) of previous layouting steps.
    • norm

      protected double norm
      The normalization factor for the network potential.
    • potential

      protected double potential
      The potential energy of the current network layout/configuration.
    • listener

      protected Network.LayoutListener listener
      The link to the GUI elements interested in updates about the layouting progress.
    • engine

      protected EvoLudo engine
      The pacemaker of all models. Interface with the outside world.
    • rng

      protected RNGDistribution 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 layoutTimeout
      The timeout for layout calculations. The default is 5 sec. The layouting process is stopped if it exceeds this time.
    • iteridx

      private int iteridx
      Counter for the iterator over all nodes.
  • Constructor Details

    • Network

      public Network(EvoLudo engine, Geometry geometry)
      Create a new network for the given engine and geometry.
      Parameters:
      engine - the pacemaker for running the model
      geometry - the structure of the population
  • Method Details

    • setLayoutListener

      public void setLayoutListener(Network.LayoutListener ll)
      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

      public abstract void doLayout(Network.LayoutListener nll)
      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 node
      nnorm - the minimal radius of a node
      unitradius - the reference radius of a node
    • relax

      public abstract double relax(int nodeidx)
      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.
      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 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.
      Parameters:
      nodeidx - the index of the node to relax
      dt - 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 index nodeidx. Return the net repulsion (overall direction and magnitude) acting on it in 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.
      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 index nodeidx. Return the net attraction (overall direction and magnitude) acting on it in attraction(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:
      1. shift center of mass into origin
      2. rescale size of graph
      3. 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

      public Geometry 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

      public void shake(Network.LayoutListener ll, double quake)
      Shake the network by randomly shifting the position of all nodes by an amount of up to quake in any coordinate.
      Parameters:
      ll - the layout listener
      quake - the maximum shift in any coordinate
    • scaleRadiusTo

      public void scaleRadiusTo(double newradius)
      Scale the radius of the network to newradius. 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 to radius.
      Parameters:
      radius - the radius of the network
    • getRadius

      public double getRadius()
      Get the radius of the network.
      Returns:
      the radius of the network
    • setStatus

      public void setStatus(Network.Status status)
      Set the status of the layouting process to status.
      Parameters:
      status - the status of the layouting process
      See Also:
    • getStatus

      public Network.Status getStatus()
      Get the status of the layouting process.
      Returns:
      the status of the layouting process
    • isStatus

      public boolean isStatus(Network.Status stat)
      Checks the status of the layouting process.
      Parameters:
      stat - the status to check
      Returns:
      true if the current status is stat
    • setAccuracy

      public void setAccuracy(double accuracy)
      Set the accuracy of the layouting process to accuracy.
      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 factor adjust. For adjust>1 the layouting process becomes more forgiving and less forgiving for adjust<1.
      Parameters:
      adjust - the factor to adjust the accuracy
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<Node>
      Specified by:
      clear in interface List<Node>
      Overrides:
      clear in class AbstractList<Node>
    • size

      public int size()
      Specified by:
      size in interface Collection<Node>
      Specified by:
      size in interface List<Node>
      Specified by:
      size in class AbstractCollection<Node>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<Node>
      Specified by:
      isEmpty in interface List<Node>
      Overrides:
      isEmpty in class AbstractCollection<Node>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<Node>
      Specified by:
      contains in interface List<Node>
      Overrides:
      contains in class AbstractCollection<Node>
    • set

      public Node set(int index, Node element)
      Specified by:
      set in interface List<Node>
      Overrides:
      set in class AbstractList<Node>
    • indexOf

      public int indexOf(Object o)
      Specified by:
      indexOf in interface List<Node>
      Overrides:
      indexOf in class AbstractList<Node>
    • lastIndexOf

      public int lastIndexOf(Object o)
      Specified by:
      lastIndexOf in interface List<Node>
      Overrides:
      lastIndexOf in class AbstractList<Node>
    • iterator

      public Iterator<Node> iterator()
      Specified by:
      iterator in interface Collection<Node>
      Specified by:
      iterator in interface Iterable<Node>
      Specified by:
      iterator in interface List<Node>
      Overrides:
      iterator in class AbstractList<Node>
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<Node>
    • next

      public Node next()
      Specified by:
      next in interface Iterator<Node>