Class GenericPop<T, N extends Network<?>, G extends GenericPopGraph<T,N>>

Type Parameters:
T - the element type used by the color map / trait representation
N - the concrete Network type used by graphs
G - the concrete GenericPopGraph type managed by this view
All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsRenderable, IsWidget, ProvidesResize, RequiresResize, TooltipProvider, TooltipProvider.Index, ChangeListener, LifecycleListener, RunListener, SampleListener, BasicTooltipProvider
Direct Known Subclasses:
Pop2D, Pop3D

public abstract class GenericPop<T, N extends Network<?>, G extends GenericPopGraph<T,N>> extends AbstractView<G> implements TooltipProvider.Index
Abstract base view for rendering population-related data (traits or fitness) for EvoLudo models that expose spatial/graph structure (IBS and PDE models).

GenericPop manages one or more GenericPopGraph instances, coordinates layout and painting, reads data from the model (traits or fitness) and assembles HTML tooltips describing nodes, their neighbourhoods and metrics. The view supports both 2D and 3D variants (through subclasses such as Pop2D or Pop3D to determine the concrete geometry string used in the name).

Responsibilities:

  • Manage lifecycle of graphs (initialisation, invalidation, destruction).
  • Query networks for layout readiness and notify the engine when layout completes.
  • Pull trait or fitness data from the underlying model and forward it to graphs for updating and painting.
  • Assign geometries to graphs based on model/module configuration (interaction vs competition geometry).
  • Provide rich HTML tooltips for nodes that include trait names, colors, payoffs/fitness, neighbour lists, tags, and interaction counts.
  • Forward mouse node-hit events to IBS models and handle a small set of view-level keyboard shortcuts (e.g. 's' for shaking network layouts).
Author:
Christoph Hauert Type parameters:
See Also:
  • Field Details

    • hitNode

      protected int hitNode
      The index of the node that was hit by the mouse.
    • dim

      private final String dim
      The type of data to display.
  • Constructor Details

    • GenericPop

      protected GenericPop(EvoLudoGWT engine, Data type)
      Construct a new view to display the configuration of the current state of the EvoLudo model in 2D or 3D.
      Parameters:
      engine - the pacemaker for running the model
      type - the type of data to display
  • Method Details

    • getName

      public String getName()
      Description copied from class: AbstractView
      Get the name of this view. This is used to dynamically build the view selector.
      Specified by:
      getName in class AbstractView<G extends GenericPopGraph<T,N>>
      Returns:
      the name of this view
    • unload

      public void unload()
      Description copied from class: AbstractView
      Unload the view. This is called when changing the module or model that implement this view. This is independent of the activation of the view.
      Overrides:
      unload in class AbstractView<G extends GenericPopGraph<T,N>>
    • modelChanged

      public void modelChanged(ChangeListener.PendingAction action)
      Description copied from interface: ChangeListener
      Called whenever the state of the EvoLudo model changed. Process potentially pending requests.

      Note: the model may process some pending actions directly and without notifying the listeners through modelChanged(PendingAction) first. In particular, this applies to pending actions that fire their own notifications, such as RESET and INIT that in turn trigger modelReset() and modelInit(), respectively.

      Specified by:
      modelChanged in interface ChangeListener
      Overrides:
      modelChanged in class AbstractView<G extends GenericPopGraph<T,N>>
      Parameters:
      action - pending action that needs to be processed.
      See Also:
    • hasLayout

      public boolean hasLayout()
      Description copied from class: AbstractView
      Check if the view has finished layouting its graphs. Currently only GenericPop and its graphs require layouting.
      Overrides:
      hasLayout in class AbstractView<G extends GenericPopGraph<T,N>>
      Returns:
      true if the view has layout
      See Also:
    • layoutComplete

      public void layoutComplete()
      Description copied from class: AbstractView
      Notification of the completion of the layouting process.
      Overrides:
      layoutComplete in class AbstractView<G extends GenericPopGraph<T,N>>
    • destroyGraphs

      protected void destroyGraphs()
      Description copied from class: AbstractView
      Destroy all graphs in this view and free up resources.
      Overrides:
      destroyGraphs in class AbstractView<G extends GenericPopGraph<T,N>>
    • setGraphGeometry

      void setGraphGeometry(GenericPopGraph<T,N> graph, boolean inter)
      Helper method to assign a geometry to a graph.
      Parameters:
      graph - the graph to assign the geometry
      inter - true for interaction geometry, false for competition geometry
    • modelDidInit

      public void modelDidInit()
      Description copied from interface: RunListener
      Called after the EvoLudo model got re-initialized.
      Specified by:
      modelDidInit in interface RunListener
      Overrides:
      modelDidInit in class AbstractView<G extends GenericPopGraph<T,N>>
    • update

      public void update(boolean force)
      Description copied from class: AbstractView
      Called when the view needs updating. This gets called when the selected view changed or new data is available from the model. Views may ignore updating requests unless force is true.
      Specified by:
      update in class AbstractView<G extends GenericPopGraph<T,N>>
      Parameters:
      force - true to force the update
    • onKeyDown

      public boolean onKeyDown(String key)
      Opportunity for view to implement keyboard shortcut for actions (repeating). If the key remains pressed this event is triggered repeatedly.

      List of additional shortcuts provided by MVPop2D for the following keys:

      s
      Shake and relax dynamically generated network layouts to help achieve a lower 'energy' state.
      Overrides:
      onKeyDown in class AbstractView<G extends GenericPopGraph<T,N>>
      Parameters:
      key - the code of the pressed key
      Returns:
      true if the key was handled
      See Also:
    • mouseHitNode

      public void mouseHitNode(int id, int node, boolean alt)
      Description copied from class: AbstractView
      Notifies the controller that the mouse/tap has hit node with index node on the graph with the tag id. The flag alt indicates whether the alt-modifier was pressed (optional implementation).
      Overrides:
      mouseHitNode in class AbstractView<G extends GenericPopGraph<T,N>>
      Parameters:
      id - the id of the graph
      node - the index of the node that was hit
      alt - true if the alt-key was pressed
    • getTooltipAt

      public String getTooltipAt(AbstractGraph<?> agraph, int node)
      Description copied from interface: TooltipProvider.Index
      Get the tooltip for the location with index index.
      Specified by:
      getTooltipAt in interface TooltipProvider.Index
      Parameters:
      agraph - the graph requesting the tooltip
      node - the index of the location
      Returns:
      the tooltip for the node
      See Also:
    • tooltipForIBS

      private String tooltipForIBS(int node, int nNodes, Module<?> module, G graph, StringBuilder tip)
      Assemble tooltip for IBS models.
      Parameters:
      node - node index
      nNodes - total number of geometry nodes
      module - module owning the graph
      graph - graph providing geometry and color mapping
      tip - builder used to accumulate HTML
      Returns:
      tooltip HTML string
    • appendLinearTip

      private void appendLinearTip(int node, int nNodes, StringBuilder tip)
      Append tooltip information for linear geometry / time slices.
      Parameters:
      node - the node index
      nNodes - the number of nodes per time slice
      tip - the StringBuilder to append to
    • appendNodeTraitTip

      private void appendNodeTraitTip(int node, int id, G graph, StringBuilder tip)
      Append node and trait information (with color when appropriate).
      Parameters:
      node - the node index
      id - the module ID
      graph - the graph
      tip - the StringBuilder to append to
    • appendPDETraitTip

      private void appendPDETraitTip(int node, Module<?> module, G graph, StringBuilder tip)
      Append trait and density information for PDE models.
      Parameters:
      node - the node index
      module - the module
      graph - the graph
      tip - the StringBuilder to append to
    • appendFitnessTip

      private void appendFitnessTip(int node, Module<?> module, StringBuilder tip)
      Append fitness (and payoffs if the module is using payoff-to-fitness mappings) as well as interaction count for modules implementing the Payoffs interface.
      Parameters:
      node - the node index
      module - the module
      tip - the StringBuilder to append to
    • appendPDEFitnessTip

      private void appendPDEFitnessTip(int node, Module<?> module, G graph, StringBuilder tip)
      Append fitness and payoff information for PDE models.
      Parameters:
      node - the node index
      module - the module
      graph - the graph
      tip - the StringBuilder to append to
    • appendFormattedValues

      private void appendFormattedValues(StringBuilder tip, double[] values, int vac, Map2Fitness map, boolean useInvMap)
      Append a comma separated list of values (or '-' for vacant index). If useInvMap is true, values are converted via map.invmap(...).
      Parameters:
      tip - the StringBuilder to append to
      values - the array of values
      vac - the vacant index
      map - the Map2Fitness
      useInvMap - whether to convert values via map.invmap(...)
    • tooltipForPDE

      private String tooltipForPDE(int node, int nNodes, AbstractGeometry geometry, Module<?> module, G graph, StringBuilder tip)
      Assemble tooltip for PDE models.
      Parameters:
      node - the node index
      nNodes - the total number of nodes
      geometry - the geometry of the graph
      module - the module
      graph - the graph
      tip - the StringBuilder to append to
      Returns:
      tooltip HTML string
    • getOppInterGraph

      private G getOppInterGraph(G graph)
      Get the interaction graph of the opponent of the module associated with the given graph.
      Parameters:
      graph - the graph for which to get the opponent's interaction graph
      Returns:
      the interaction graph of the opponent
    • getOppCompGraph

      private G getOppCompGraph(G graph)
      Get the competition graph of the opponent of the module associated with the given graph.
      Parameters:
      graph - the graph for which to get the opponent's competition graph
      Returns:
      the competition graph of the opponent
    • appendOppTraitsAt

      private StringBuilder appendOppTraitsAt(int node, AbstractGeometry geom, G graph, StringBuilder tip)
      Append opponent traits at the given node.
      Parameters:
      node - the node index
      geom - the geometry
      graph - the opponent's graph
      tip - the StringBuilder to append to
      Returns:
      the updated StringBuilder
    • appendInterNeighborsAt

      private static StringBuilder appendInterNeighborsAt(int node, AbstractGeometry geom, StringBuilder tip)
      Append interaction neighbours at the given node.
      Parameters:
      node - the node index
      geom - the geometry
      tip - the StringBuilder to append to
      Returns:
      the updated StringBuilder
    • appendCompNeighborsAt

      private static StringBuilder appendCompNeighborsAt(int node, AbstractGeometry geom, StringBuilder tip)
      Append competition neighbours at the given node.
      Parameters:
      node - the node index
      geom - the geometry
      tip - the StringBuilder to append to
      Returns:
      the updated StringBuilder
    • appendNeighbors

      private static StringBuilder appendNeighbors(String label, int[] links, int k, StringBuilder tip)
      Return a formatted string of the neighbourhood structure at the given node.
      Parameters:
      label - label describing the neighbour set
      links - array of neighbour indices
      k - number of links
      tip - builder to append to
      Returns:
      the updated builder