fpmas 1.6
Public Member Functions | List of all members
fpmas::model::GridAgentBuilder< CellType > Class Template Reference

#include <grid.h>

Inheritance diagram for fpmas::model::GridAgentBuilder< CellType >:
Inheritance graph
[legend]
Collaboration diagram for fpmas::model::GridAgentBuilder< CellType >:
Collaboration graph
[legend]

Public Member Functions

void build (api::model::SpatialModel< CellType > &model, api::model::GroupList groups, api::model::SpatialAgentFactory< CellType > &factory, api::model::SpatialAgentMapping< api::model::GridCell > &agent_mapping) override
 
void build (api::model::SpatialModel< CellType > &model, api::model::GroupList groups, std::function< api::model::SpatialAgent< CellType > *()> factory, api::model::SpatialAgentMapping< api::model::GridCell > &agent_mapping) override
 
void initSample (std::size_t n, std::function< void(api::model::GridAgent< CellType > *)> init_function) const
 
template<typename T >
void initSequence (const std::vector< T > &items, std::function< void(api::model::GridAgent< CellType > *, typename std::vector< T >::const_reference)> init_function) const
 
- Public Member Functions inherited from fpmas::api::model::SpatialAgentBuilder< GridCell, api::model::GridCell >
virtual void build (SpatialModel< GridCell > &model, GroupList groups, SpatialAgentFactory< GridCell > &factory, SpatialAgentMapping< api::model::GridCell > &agent_mapping)=0
 
virtual void build (SpatialModel< GridCell > &model, GroupList groups, std::function< SpatialAgent< GridCell > *()> factory, SpatialAgentMapping< api::model::GridCell > &agent_mapping)=0
 

Additional Inherited Members

- Static Public Attributes inherited from fpmas::model::SpatialAgentBuilderBase< GridCell, api::model::GridCell >
static const api::model::GroupId TEMP_GROUP_ID
 
- Protected Member Functions inherited from fpmas::model::SpatialAgentBuilderBase< GridCell, api::model::GridCell >
void build_agents (api::model::SpatialModel< GridCell > &model, api::model::GroupList groups, api::model::SpatialAgentFactory< GridCell > &factory, api::model::SpatialAgentMapping< api::model::GridCell > &agent_mapping)
 
void build_agents (api::model::SpatialModel< GridCell > &model, api::model::GroupList groups, std::function< api::model::SpatialAgent< GridCell > *()> factory, api::model::SpatialAgentMapping< api::model::GridCell > &agent_mapping)
 

Detailed Description

template<typename CellType = GridCell>
class fpmas::model::GridAgentBuilder< CellType >

Grid specialization of the SpatialAgentBuilder class.

The fpmas::model::GridAgentBuilder uses api::model::GridCell as the MappingCellType parameter, meaning an SpatialAgentMapping<api::model::GridCell> must be provided to the fpmas::model::GridAgentBuilder::build() method. As an example, RandomGridAgentMapping might be used.

Member Function Documentation

◆ build() [1/2]

template<typename CellType >
void fpmas::model::GridAgentBuilder< CellType >::build ( api::model::SpatialModel< CellType > &  model,
api::model::GroupList  groups,
api::model::SpatialAgentFactory< CellType > &  factory,
api::model::SpatialAgentMapping< api::model::GridCell > &  agent_mapping 
)
override

Implements api::model::SpatialAgentBuilder::build(SpatialModel<CellType>&, GroupList, SpatialAgentFactory<CellType>&, SpatialAgentMapping<MappingCellType>&), and seeds built agents, implicitly considered as api::model::GridAgent.

The seed associated to each agent is independent from the current cell distribution. This notably means that all agents will generate the same random numbers sequence, independently of the current process count, the cell distribution or the migration of agents during the simulation.

The process can be seeded with fpmas::seed().

◆ build() [2/2]

template<typename CellType >
void fpmas::model::GridAgentBuilder< CellType >::build ( api::model::SpatialModel< CellType > &  model,
api::model::GroupList  groups,
std::function< api::model::SpatialAgent< CellType > *()>  factory,
api::model::SpatialAgentMapping< api::model::GridCell > &  agent_mapping 
)
override

◆ initSample()

template<typename CellType >
void fpmas::model::GridAgentBuilder< CellType >::initSample ( std::size_t  n,
std::function< void(api::model::GridAgent< CellType > *)>  init_function 
) const

Initializes a sample of n agents selected from the previously built agents with the provided init_function.

The sample of agents selected is deterministic: it is guaranteed that the same agents are initialized independently of the current cell distribution.

The selection process can be seeded with fpmas::seed().

Successive calls can be used to independently initialize several agent states.

Example
std::size_t n_agent = 50;
fpmas::model::UniformGridAgentMapping mapping(20, 20, n_agent);
agent_builder.build(
grid_model,
{agent_group},
[] () {return new UserAgent;},
agent_mapping
);
// Sets 10 random agents to be INFECTED
agent_builder.initSample(
((UserAgent*) agent)->setState(INFECTED);
}
);
// Sets 15 random agents to be HAPPY
agent_builder.initSample(
((UserAgent*) agent)->setMood(HAPPY);
}
);
Definition: grid.h:147
Definition: grid.h:258
void build(api::model::SpatialModel< CellType > &model, api::model::GroupList groups, api::model::SpatialAgentFactory< CellType > &factory, api::model::SpatialAgentMapping< api::model::GridCell > &agent_mapping) override
Definition: grid.h:403
void initSample(std::size_t n, std::function< void(api::model::GridAgent< CellType > *)> init_function) const
Definition: grid.h:466
Definition: grid_agent_mapping.h:84
Parameters
nsample size
init_functioninitialization function

◆ initSequence()

template<typename CellType >
template<typename T >
void fpmas::model::GridAgentBuilder< CellType >::initSequence ( const std::vector< T > &  items,
std::function< void(api::model::GridAgent< CellType > *, typename std::vector< T >::const_reference)>  init_function 
) const

Sequentially initializes built agents from the input items.

Each item is assigned to an agent using the specified init_function.

The item assignment is deterministic: it is guaranteed that each agent is always initialized with the same item independently of the current cell distribution.

Example
std::size_t n_agent = 50;
fpmas::model::UniformGridAgentMapping mapping(20, 20, n_agent);
agent_builder.build(
grid_model,
{agent_group},
[] () {return new UserAgent;},
agent_mapping
);
// Vector containing n_agent items
std::vector<unsigned long> items(n_agent);
// items initialization
...
// Assign items to agents
agent_builder.initSequence(
items, [] (
const unsigned long& item
) {
((UserAgent*) agent)->setData(item);
}
);
Parameters
itemsItems to assign to built agents. The number of items must be greater or equal to the total number of built agents, n_agent. Only the first n_agent items are assigned, other are ignored.
init_functionitem assignment function

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