3#include "fpmas/model/spatial/graph_builder.h"
26 virtual fpmas::api::model::Model&
getModel() = 0;
30 virtual fpmas::api::model::AgentGroup&
cellGroup() = 0;
47 virtual void run() = 0;
63template<
typename BaseModel,
typename AgentType>
66 typedef typename BaseModel::CellType CellType;
69 fpmas::model::IdleBehavior idle_behavior;
70 Behavior<MetaCell> cell_update_edge_weights_behavior {
73 Behavior<MetaCell> cell_read_all_cell_behavior {
76 Behavior<MetaCell> cell_write_all_cell_behavior {
79 Behavior<MetaCell> cell_read_one_cell_behavior {
82 Behavior<MetaCell> cell_write_one_cell_behavior {
85 Behavior<MetaCell> cell_read_all_write_one_cell_behavior {
88 Behavior<MetaCell> cell_read_all_write_all_cell_behavior {
93 Behavior<AgentType> create_relations_from_neighborhood {
94 &AgentType::create_relations_from_neighborhood
96 Behavior<AgentType> create_relations_from_contacts {
97 &AgentType::create_relations_from_contacts
99 Behavior<AgentType> handle_new_contacts {
100 &AgentType::handle_new_contacts
102 Behavior<AgentType> move_behavior {
106 fpmas::scheduler::detail::LambdaTask sync_graph_task {
107 [
this] () {this->
model.graph().synchronize();}
109 fpmas::scheduler::Job sync_graph {{sync_graph_task}};
119 fpmas::utils::perf::Monitor monitor;
121 fpmas::utils::perf::Probe lb_algorithm_probe {
"LB_ALGORITHM"};
122 fpmas::utils::perf::Probe sync_probe {
"SYNC"};
123 fpmas::utils::perf::Probe graph_balance_probe {
"GRAPH_BALANCE"};
166 fpmas::api::scheduler::Scheduler& scheduler,
167 fpmas::api::runtime::Runtime& runtime,
168 fpmas::api::model::LoadBalancing& lb_algorithm,
169 fpmas::scheduler::TimeStep lb_period
189 return model.cellGroup();
201template<
typename BaseModel,
typename AgentType>
204 fpmas::api::scheduler::Scheduler& scheduler,
205 fpmas::api::runtime::Runtime& runtime,
206 fpmas::api::model::LoadBalancing& lb_algorithm,
207 fpmas::scheduler::TimeStep lb_period
210 model(scheduler, runtime, lb_algorithm),
211 graph_balance_probe_job(
212 model.graph(), lb_algorithm, lb_algorithm_probe, graph_balance_probe),
223 sync_probe_task(sync_probe, model.graph()),
224 cells_location_output(*this, this->name, config.grid_width, config.grid_height),
225 cells_utility_output(*this, config.grid_width, config.grid_height),
226 agents_output(*this, config.grid_width, config.grid_height),
227 dot_output(*this, this->name +
".%t"),
230 case Interactions::READ_ALL:
233 cell_read_all_cell_behavior
236 case Interactions::WRITE_ALL:
239 cell_write_all_cell_behavior
242 case Interactions::READ_ONE:
245 cell_read_one_cell_behavior
248 case Interactions::WRITE_ONE:
251 cell_write_one_cell_behavior
254 case Interactions::READ_ALL_WRITE_ONE:
257 cell_read_all_write_one_cell_behavior
260 case Interactions::READ_ALL_WRITE_ALL:
263 cell_read_all_write_all_cell_behavior
273 auto& create_relations_neighbors_group =
model.buildGroup(
274 RELATIONS_FROM_NEIGHBORS_GROUP, create_relations_from_neighborhood
276 auto& create_relations_contacts_group =
model.buildGroup(
277 RELATIONS_FROM_CONTACTS_GROUP, create_relations_from_contacts
279 auto& handle_new_contacts_group =
model.buildGroup(
280 HANDLE_NEW_CONTACTS_GROUP, handle_new_contacts
282 auto& move_group =
model.buildMoveGroup(
283 MOVE_GROUP, move_behavior
287 scheduler.schedule(0, lb_period, graph_balance_probe_job.
job);
292 create_relations_neighbors_group.jobs()
296 create_relations_contacts_group.jobs()
300 handle_new_contacts_group.jobs()
303 scheduler.schedule(0.23, 1, move_group.jobs());
306 auto& update_cell_edge_weights_group =
model.buildGroup(
307 UPDATE_CELL_EDGE_WEIGHTS_GROUP,
308 cell_update_edge_weights_behavior);
309 scheduler.schedule(0.24, 1, update_cell_edge_weights_group.jobs());
313 model.getGroup(CELL_GROUP).agentExecutionJob().setEndTask(sync_probe_task);
314 scheduler.schedule(0.25, 1,
model.getGroup(CELL_GROUP).jobs());
316 scheduler.schedule(0.30, 1, csv_output.
jobs());
318 fpmas::scheduler::TimeStep last_lb_date
319 = ((config.
num_steps-1) / lb_period) * lb_period;
334 scheduler.schedule(last_lb_date + 0.02, cells_location_output.job());
337 scheduler.schedule(last_lb_date + 0.03, agents_output.job());
343 scheduler.schedule(last_lb_date + 0.04, dot_output.job());
346template<
typename BaseModel,
typename AgentType>
349 model.graph().synchronize();
353 for(
auto cell : model.cellGroup().localAgents())
354 cell->node()->setWeight(config.cell_weight);
355 for(
auto agent : model.getGroup(
AGENT_GROUP).localAgents())
356 agent->node()->setWeight(config.agent_weight);
358 model.graph().synchronize();
366template<
template<
typename>
class SyncMode>
368 public MetaModel<GridModel<SyncMode, MetaGridCell>, MetaGridAgent> {
404template<
template<
typename>
class SyncMode>
406 std::unique_ptr<UtilityFunction> utility_function;
423 MooreGrid<MetaGridCell>::Builder grid(
425 fpmas::api::model::GroupList cell_groups;
427 cell_groups.push_back(this->model.getGroup(CELL_GROUP));
428 auto local_cells = grid.build(this->model, cell_groups);
434template<
template<
typename>
class SyncMode>
436 fpmas::model::UniformGridAgentMapping mapping(
440 fpmas::model::GridAgentBuilder<MetaGridCell> agent_builder;
441 fpmas::model::DefaultSpatialAgentFactory<MetaGridAgent> agent_factory;
446 this->model.getGroup(RELATIONS_FROM_NEIGHBORS_GROUP),
447 this->model.getGroup(RELATIONS_FROM_CONTACTS_GROUP),
448 this->model.getGroup(HANDLE_NEW_CONTACTS_GROUP),
449 this->model.getGroup(MOVE_GROUP)
451 agent_factory, mapping);
460template<
template<
typename>
class SyncMode>
462 public MetaModel<SpatialModel<SyncMode, MetaGraphCell>, MetaGraphAgent> {
495template<
template<
typename>
class SyncMode>
497 fpmas::random::PoissonDistribution<std::size_t> edge_dist(config.
output_degree);
498 fpmas::api::graph::DistributedGraphBuilder<fpmas::model::AgentPtr>* builder;
501 builder =
new DistributedUniformGraphBuilder(edge_dist);
504 builder =
new DistributedClusteredGraphBuilder(edge_dist);
507 builder =
new SmallWorldGraphBuilder(config.
p, config.
output_degree);
514 CellNetworkBuilder<MetaGraphCell> cell_network_builder(
518 fpmas::api::model::GroupList cell_groups;
520 cell_groups.push_back(this->model.getGroup(UPDATE_CELL_EDGE_WEIGHTS_GROUP));
522 cell_groups.push_back(this->model.getGroup(CELL_GROUP));
523 cell_network_builder.build(this->model, cell_groups);
527 GraphRange<MetaGraphCell>::synchronize(this->model);
530template<
template<
typename>
class SyncMode>
532 fpmas::model::UniformAgentMapping mapping(
533 this->getModel().getMpiCommunicator(),
537 fpmas::model::SpatialAgentBuilder<MetaGraphCell> agent_builder;
538 fpmas::model::DefaultSpatialAgentFactory<MetaGraphAgent> agent_factory;
542 this->model.getGroup(RELATIONS_FROM_NEIGHBORS_GROUP),
543 this->model.getGroup(RELATIONS_FROM_CONTACTS_GROUP),
544 this->model.getGroup(HANDLE_NEW_CONTACTS_GROUP),
545 this->model.getGroup(MOVE_GROUP)
547 agent_factory, mapping);
583 fpmas::api::scheduler::Scheduler& scheduler,
584 fpmas::api::runtime::Runtime& runtime,
585 fpmas::api::model::LoadBalancing& lb_algorithm,
586 fpmas::scheduler::TimeStep lb_period
fpmas::scheduler::Job job
Definition: probe.h:80
SyncMode
Definition: config.h:221
#define AGENT_GROUP
Definition: config.h:27
Environment
Definition: config.h:37
std::size_t output_degree
Definition: config.h:315
bool json_output
Definition: config.h:347
float p
Definition: config.h:323
Utility utility
Definition: config.h:331
int json_output_period
Definition: config.h:354
bool dot_output
Definition: config.h:359
std::vector< GridAttractor > grid_attractors
Definition: config.h:336
Environment environment
Definition: config.h:297
std::size_t num_cells
Definition: config.h:310
std::size_t grid_width
Definition: config.h:301
std::size_t grid_height
Definition: config.h:305
std::size_t cell_size
Definition: config.h:468
bool dynamic_cell_edge_weights
Definition: config.h:458
AgentInteractions agent_interactions
Definition: config.h:446
fpmas::api::scheduler::TimeStep refresh_local_contacts
Definition: config.h:479
fpmas::api::scheduler::TimeStep num_steps
Definition: config.h:442
float occupation_rate
Definition: config.h:438
fpmas::api::scheduler::TimeStep refresh_distant_contacts
Definition: config.h:486
Interactions cell_interactions
Definition: config.h:452
Definition: interactions.h:24