Class FWSimulationGenerator

java.lang.Object
net.simplace.sim.control.FWSimulationControlContainer
net.simplace.sim.control.FWSimulationGenerator
All Implemented Interfaces:
FWSimFieldContainer
Direct Known Subclasses:
DefaultSimulationGenerator, SimpleSimulationGenerator

public abstract class FWSimulationGenerator extends FWSimulationControlContainer
Base class of the simulation generators: a generator creates the simulations (FWSimSimulation) of a project (FWSimProject). Implementations: generate(FWSimulationControlCache, ResultSet) writes the parameter combinations of the simulations into the database table PROJECT_DATA (addSimulation(FWSimVarMap)); updateSimulations(FWSimulationControlCache, String, int) then reads them in chunks of FWSimEngine.MAX_SIMULATION_COUNT and creates the simulation objects.
Author:
Andreas Enders
  • Field Details

  • Constructor Details

    • FWSimulationGenerator

      public FWSimulationGenerator()
      Constructor for instantiation via reflection (documentation).
    • FWSimulationGenerator

      protected FWSimulationGenerator(org.jdom2.Element aControlContainerElement, FWSimSession aSession, HashMap<String, FWSimVariable<?>> aFieldMap, FWSimVariable.CONTENT_TYPE aContentType)
      Creates the generator; to be called by the subclasses. Except in SOLUTION_ONLY mode it reads the configuration and prepares the table PROJECT_DATA and the statements. Database errors are logged.
      Parameters:
      aControlContainerElement - the generator element, may be null
      aSession - the session
      aFieldMap - variables of the project data
      aContentType - FWSimVariable.CONTENT_TYPE.res or FWSimVariable.CONTENT_TYPE.sim
  • Method Details

    • createSimulationGenerator

      public static FWSimulationGenerator createSimulationGenerator(org.jdom2.Element aContainerElement, FWSimSession aSession, HashMap<String, FWSimVariable<?>> aFieldMap, FWSimVariable.CONTENT_TYPE aContentType)
      Factory method: creates the generator of the class given in the attribute class via its constructor (Element, FWSimSession, HashMap, CONTENT_TYPE). Errors are logged.
      Parameters:
      aContainerElement - the generator element
      aSession - the session
      aFieldMap - variables of the project data
      aContentType - content type of the generated variables
      Returns:
      the generator, or null if it cannot be created
    • clearSimulations

      protected void clearSimulations()
      Clears the simulations of the current chunk.
    • getSimulationsListSize

      protected int getSimulationsListSize()
      Returns:
      the number of simulations in the current chunk
    • getSimulation

      protected FWSimSimulation getSimulation(int index)
      Parameters:
      index - index in the current chunk
      Returns:
      the simulation
      Throws:
      IndexOutOfBoundsException - if the index is invalid
    • addSimulation

      protected boolean addSimulation(FWSimVarMap aVarMap)
      Adds a generated parameter combination as simulation: generates the simulation id and writes the values to PROJECT_DATA, if the constraint allows it. In GLOBAL mode the constraint is only checked for the first project, whose calibration values are remembered for the other projects.
      Parameters:
      aVarMap - control variable map with the values of the simulation
      Returns:
      true if the simulation was added
    • writeSimulation

      public void writeSimulation(FWSimVarMap aSimulationMap)
      Writes the values of a simulation (all variables of the control cache) into PROJECT_DATA; with an identifier rule the simulation name is generated first. SQL and type errors are logged.
      Parameters:
      aSimulationMap - variable map with the values of the simulation
    • updateSimulations

      public List<FWSimSimulation> updateSimulations(FWSimulationControlCache aCache, String aProjectID, int aStartNumber)
      Creates the next chunk of simulations of a project from PROJECT_DATA (at most FWSimEngine.MAX_SIMULATION_COUNT); on the first call the simulations are counted. Without database statements (SOLUTION_ONLY) a single simulation of the solution is created. If the chunk is not full, the generator is finished. Database errors are logged.
      Parameters:
      aCache - control cache of the run
      aProjectID - id of the project
      aStartNumber - offset of the chunk
      Returns:
      the simulations of the chunk, or null if there are none
    • initializeProject

      protected ResultSet initializeProject(String aProjectID, FWSimulationControlCache aControlCache) throws SQLException
      Reads the project data (iteration 0) of a project and sets the values of the first row to the control variable map (not simulation id and iteration). If the project has no rows, a warning is logged and no values are set.
      Parameters:
      aProjectID - id of the project
      aControlCache - control cache of the run
      Returns:
      the result set, positioned on the first row
      Throws:
      SQLException - if reading fails
    • generate

      public abstract void generate(FWSimulationControlCache aControlCache, ResultSet aSimulationsResultSet) throws Exception
      Generates the parameter combinations of a project for the current iteration and adds them with addSimulation(FWSimVarMap); to be implemented by the subclasses.
      Parameters:
      aControlCache - control cache of the run
      aSimulationsResultSet - project data of the project (first iteration only), may be null
      Throws:
      Exception - if generating fails
    • canUpdate

      public boolean canUpdate(String aProjectName)
      Parameters:
      aProjectName - not used
      Returns:
      true as long as the generator can deliver more simulations
    • setFinished

      protected void setFinished()
      Marks the generator as finished (no more simulations).
    • setInitial

      public void setInitial()
      Resets the generator so it can deliver simulations again.
    • finalize

      public void finalize()
      Returns the connections of the insert, select and count statements to the pool (each has its own connection).
      Overrides:
      finalize in class Object
    • reset

      public void reset()
      Discards the remembered calibration values (GLOBAL mode).