Class ImageEvolutionDemoView

All Implemented Interfaces:
IFeedbackProvider, IImageEvolutionResettable, ISimulationHost, SimulationListener, IFileDropHandler, ComponentListener, FocusListener, MouseListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants

public class ImageEvolutionDemoView extends SimulationView implements IImageEvolutionResettable
MDI SimulationView that evolves a population of semi-transparent triangles to approximate a target image using the MDI genetic algorithm framework.

Layout

The view's world container is replaced by a custom ImageEvolutionPanel installed as the CENTER component. It renders three regions side-by-side:

  • Left — best individual found so far, at full display resolution.
  • Center — thumbnail grid of the entire current population.
  • Right — the fixed target image.

Fitness and diversity diagnostic plots are installed on the right side of a split pane via the SimulationView diagnostics mechanism.

Threading

The GA runs on the simulation thread. On each refresh callback (EDT), the view asks the simulation for its best individual, renders it at display resolution, renders all population thumbnails, then hands both to ImageEvolutionPanel and calls repaint().

Reset

The view implements IImageEvolutionResettable so the control panel can request a fresh run with different parameters without knowing the view's concrete type. Reset is delegated to SimulationView.requestEngineReset(java.util.function.Supplier<edu.cnu.mdi.sim.Simulation>, java.util.function.Consumer<edu.cnu.mdi.sim.SimulationEngine>, boolean, boolean).

See Also:
  • Field Details

    • DEFAULT_NUM_TRIANGLES

      public static final int DEFAULT_NUM_TRIANGLES
      Default number of triangles per chromosome.
      See Also:
    • DEFAULT_POPULATION_SIZE

      public static final int DEFAULT_POPULATION_SIZE
      Default population size.
      See Also:
  • Constructor Details

    • ImageEvolutionDemoView

      public ImageEvolutionDemoView(Object... keyVals)
      Create the image evolution demo view.
      Parameters:
      keyVals - standard BaseView key-value args
  • Method Details

    • onSimulationRefresh

      protected void onSimulationRefresh(SimulationContext ctx)
      Called on the EDT before the view repaints in response to a refresh.

      On each refresh:

      1. Ask the simulation for a copy of the best individual.
      2. Render it at DISPLAY_SIZE×DISPLAY_SIZE for the left panel.
      3. Render all current population individuals as THUMB_SIZE×THUMB_SIZE thumbnails for the grid.
      4. Push both to ImageEvolutionPanel and repaint.

      All rendering here uses PolygonChromosome.render(int, int), which allocates a new image — this is intentional for display paths. Fitness evaluation uses the allocation-free PolygonChromosome.renderInto(java.awt.image.BufferedImage, double) path via thread-local buffers.

      Overrides:
      onSimulationRefresh in class SimulationView
    • onSimulationStateChange

      protected void onSimulationStateChange(SimulationContext ctx, SimulationState from, SimulationState to, String reason)
      Description copied from class: SimulationView
      Called on the EDT after any engine state transition.
      Overrides:
      onSimulationStateChange in class SimulationView
      Parameters:
      ctx - simulation context
      from - previous state
      to - new state
      reason - human-readable transition reason
    • filesDropped

      public void filesDropped(List<File> files)
      Description copied from class: BaseView
      Called on the EDT when one or more accepted files are dropped on this view.

      The default implementation is a no-op. Subclasses that have called BaseView.enableFileDrop(Predicate) should override this method to handle the dropped files. The list is never null and is never empty; the filter (if any) has already been applied.

      Specified by:
      filesDropped in interface IFileDropHandler
      Overrides:
      filesDropped in class BaseView
      Parameters:
      files - the accepted dropped files; never null, never empty
    • getViewInfo

      public AbstractViewInfo getViewInfo()
      Description copied from class: BaseView
      Override to supply structured information for the info dialog. The default returns null (no info available).
      Overrides:
      getViewInfo in class BaseView
      Returns:
      view info, or null
    • requestReset

      public void requestReset(int numTriangles, int populationSize, ImageFitnessMode fitnessMode)
      Request a reset with the given parameters.

      Implementations should stop the current engine, build a new simulation with the supplied parameters, and restart. This should only be called when the simulation is in a safe state (READY, PAUSED, TERMINATED, or FAILED); the control panel is responsible for enforcing this via button enable/disable logic.

      Stops the current engine, builds a new simulation with the supplied parameters, swaps the engine, and restarts against the current target image.

      Specified by:
      requestReset in interface IImageEvolutionResettable
      Parameters:
      numTriangles - number of triangles per chromosome (must be > 0)
      populationSize - number of individuals in the population (must be > 0)
      fitnessMode - fitness metric for the new run