fpmas 1.6
Public Member Functions | List of all members
fpmas::api::model::SpatialAgentBuilder< CellType, MappingCellType > Class Template Referenceabstract

#include <spatial_model.h>

Inheritance diagram for fpmas::api::model::SpatialAgentBuilder< CellType, MappingCellType >:
Inheritance graph
[legend]

Public Member Functions

virtual void build (SpatialModel< CellType > &model, GroupList groups, SpatialAgentFactory< CellType > &factory, SpatialAgentMapping< MappingCellType > &agent_mapping)=0
 
virtual void build (SpatialModel< CellType > &model, GroupList groups, std::function< SpatialAgent< CellType > *()> factory, SpatialAgentMapping< MappingCellType > &agent_mapping)=0
 

Detailed Description

template<typename CellType, typename MappingCellType>
class fpmas::api::model::SpatialAgentBuilder< CellType, MappingCellType >

SpatialAgentBuilder API.

The purpose of the SpatialAgentBuilder is to instantiate and initialize SpatialAgents in a distributed way, independently of the current Cell network distribution.

Template Parameters
CellTypefinal Cell type on which agents are moving
MappingCellTypeCell type used by the SpatialAgentMapping. MappingCellType must be a base of CellType.

Member Function Documentation

◆ build() [1/2]

template<typename CellType , typename MappingCellType >
virtual void fpmas::api::model::SpatialAgentBuilder< CellType, MappingCellType >::build ( SpatialModel< CellType > &  model,
GroupList  groups,
SpatialAgentFactory< CellType > &  factory,
SpatialAgentMapping< MappingCellType > &  agent_mapping 
)
pure virtual

Build SpatialAgents in the specified model in a distributed way.

More precisely:

  1. For each cell in model.cells(), agent_mapping.countAt(cell) SpatialAgents are allocated using factory.build().
  2. All built agents are added to all the AgentGroups specified in groups, using AgentGroup::add().
  3. The location of each SpatialAgent is initialized to the cell they were built from, according to point 1. This is eventually performed using SpatialAgent::initLocation().
  4. The DistributedMoveAlgorithm provided by model.distributedMoveAlgorithm() is executed to complete the location initialization of built SpatialAgents.

Additionnal implementation defined behaviors can be added according to the current model type.

Parameters
modelmodel in which agent are initialized. More precisely, agents are initialized within the Cell network defined by model.cells()
groupsgroups to which each agent must be added
factoryagent factory used to allocate agents
agent_mappingagent mapping used to compute the number of agents to initialize on each cell

◆ build() [2/2]

template<typename CellType , typename MappingCellType >
virtual void fpmas::api::model::SpatialAgentBuilder< CellType, MappingCellType >::build ( SpatialModel< CellType > &  model,
GroupList  groups,
std::function< SpatialAgent< CellType > *()>  factory,
SpatialAgentMapping< MappingCellType > &  agent_mapping 
)
pure virtual

Same as build(SpatialModel<CellType>&, GroupList, SpatialAgentFactory<CellType>&, SpatialAgentMapping<MappingCellType>&) but uses a call to factory() instead of the SpatialAgentFactory::build() method to build Agents.

It might be convenient to initialize the factory from a lambda function:

int data;
agent_builder.build(
model, {agent_group},
[&data] () {return new Agent(data);}, // Called only when required
agent_mapping
);
Parameters
modelmodel in which agent are initialized. More precisely, agents are initialized within the Cell network defined by model.cells()
groupsgroups to which each agent must be added
factorycallable object used to allocate agents
agent_mappingagent mapping used to compute the number of agents to initialize on each cell

The documentation for this class was generated from the following file: