Class FunctionalAgentGenerator

java.lang.Object
modelarium.entities.generators.AgentGenerator
modelarium.entities.generators.FunctionalAgentGenerator

public class FunctionalAgentGenerator extends AgentGenerator
Class for generating agents by delegating creation logic to a user-defined function.

This implementation of AgentGenerator is intended for flexibility and cross-language use (e.g. from Python).

  • Constructor Details

    • FunctionalAgentGenerator

      public FunctionalAgentGenerator(BiFunction<Config,RandomGenerator,List<AgentSet>> getAgentsForEachThreadFunction, Runnable resetFunction)
      Constructs a new generator with the specified logic.
      Parameters:
      getAgentsForEachThreadFunction - the function used to generate agent sets for each thread
      resetFunction - the function used to reset the state of the generator after agents are generated
    • FunctionalAgentGenerator

      public FunctionalAgentGenerator(BiFunction<Config,RandomGenerator,List<AgentSet>> getAgentsForEachThreadFunction)
      Constructs a new generator with the specified logic and uses the default reset logic.
      Parameters:
      getAgentsForEachThreadFunction - the function used to generate agent sets for each thread
  • Method Details

    • generateAgentsForEachThread

      public List<AgentSet> generateAgentsForEachThread(Config config, RandomGenerator random)
      Generates the model's agents using the logic specified during construction and distributes them across the model's worker cores.
      Specified by:
      generateAgentsForEachThread in class AgentGenerator
      Parameters:
      config - the model settings containing the agent and thread counts
      random - the random generator the agent generator can use for constructing agents
      Returns:
      a list of AgentSet objects, one per thread
    • reset

      protected void reset()
      Resets the state of the generator.
      Overrides:
      reset in class AgentGenerator