1#ifndef FPMAS_DIST_MOVE_ALGO_H
2#define FPMAS_DIST_MOVE_ALGO_H
11namespace fpmas {
namespace model {
31 template<
typename RangeType,
unsigned int MaxRangeSize,
typename CellType>
45 static const RangeType range(MaxRangeSize);
46 max_step = range.radius(
nullptr);
55 std::vector<CellType*>)
override {
73 return _step >= max_step;
98 template<
typename CellType>
102 std::size_t max_step;
115 std::vector<CellType*>)
override {
116 std::size_t local_max = 0;
117 for(
auto agent : agents) {
118 std::size_t radius = std::max(
119 agent->mobilityRange().radius(agent->locationCell()),
120 agent->perceptionRange().radius(agent->locationCell())
122 if(radius > local_max)
126 std::vector<std::size_t> local_max_list = mpi.
allGather(local_max);
127 this->max_step = *std::max_element(local_max_list.begin(), local_max_list.end());
136 return _step >= max_step;
144 template<
typename CellType>
156 : dist_move_algo(dist_move_algo) {}
182 model(model), move_agent_group(move_agent_group),
183 cell_group(cell_group), end(end), algo_task(*this) {
184 algo_job.
add(algo_task);
198 template<
typename CellType>
199 void DistributedMoveAlgorithm<CellType>::AlgoTask::run() {
200 FPMAS_LOGD(this->dist_move_algo.model.getMpiCommunicator().getRank(),
201 "DMA",
"Running DistributedMoveAlgorithm...",
"");
202 using api::model::SpatialAgent;
205 std::vector<SpatialAgent<CellType>*> agents;
206 for(
auto agent : dist_move_algo.move_agent_group.localAgents()) {
209 if(agent->node()->getOutgoingEdges(
210 api::model::SpatialModelLayers::NEW_LOCATION).size() > 0)
212 static_cast<SpatialAgent<CellType>*
>(agent));
219 for(
auto agent : agents) {
220 for(
auto perceiver : agent->node()->getIncomingEdges(fpmas::api::model::PERCEPTION)) {
221 dist_move_algo.model.graph().unlink(perceiver);
225 dist_move_algo.model.graph()
226 .synchronizationMode().getSyncLinker().synchronize();
228 std::vector<CellType*> cells;
229 for(
auto cell : dist_move_algo.cell_group.localAgents()) {
230 cells.push_back(
static_cast<CellType*
>(cell));
233 cells.back()->init();
238 cells.back()->node()->mutex()->synchronize();
242 dist_move_algo.end.init(
243 dist_move_algo.model.getMpiCommunicator(),
250 while(!dist_move_algo.end.end()) {
251 for(
auto cell : cells) {
253 cell->handleNewLocation();
255 cell->handlePerceive();
259 dist_move_algo.model.graph()
260 .synchronizationMode().getSyncLinker().synchronize();
263 dist_move_algo.model.graph()
265 dist_move_algo.model.graph().getUnsyncNodes(),
false
268 for(
auto agent : agents) {
271 agent->handleNewMove();
272 agent->handleNewPerceive();
277 dist_move_algo.model.graph()
278 .synchronizationMode().getSyncLinker().synchronize();
280 dist_move_algo.end.step();
282 for(
auto cell : cells) {
285 cell->updatePerceptions(dist_move_algo.move_agent_group);
288 dist_move_algo.model.graph()
289 .synchronizationMode().getSyncLinker().synchronize();
293 dist_move_algo.model.graph()
295 dist_move_algo.model.graph().getUnsyncNodes(),
false
298 FPMAS_LOGD(this->dist_move_algo.model.getMpiCommunicator().getRank(),
Definition: communication.h:251
Definition: spatial_model.h:32
Definition: spatial_model.h:425
Definition: spatial_model.h:376
Definition: spatial_model.h:185
Definition: spatial_model.h:234
std::vector< T > allGather(const T &) override
Definition: communication.h:492
Definition: dist_move_algo.h:145
DistributedMoveAlgorithm(api::model::SpatialModel< CellType > &model, api::model::AgentGroup &move_agent_group, api::model::AgentGroup &cell_group, api::model::EndCondition< CellType > &end)
Definition: dist_move_algo.h:176
api::scheduler::JobList jobs() const override
Definition: dist_move_algo.h:190
Definition: dist_move_algo.h:99
bool end() override
Definition: dist_move_algo.h:135
void step() override
Definition: dist_move_algo.h:132
void init(api::communication::MpiCommunicator &comm, std::vector< api::model::SpatialAgent< CellType > * > agents, std::vector< CellType * >) override
Definition: dist_move_algo.h:112
Definition: dist_move_algo.h:32
void init(api::communication::MpiCommunicator &, std::vector< api::model::SpatialAgent< CellType > * >, std::vector< CellType * >) override
Definition: dist_move_algo.h:52
StaticEndCondition()
Definition: dist_move_algo.h:44
bool end() override
Definition: dist_move_algo.h:72
void step() override
Definition: dist_move_algo.h:62
Definition: scheduler.h:169
void add(api::scheduler::Task &) override
Definition: scheduler.cpp:38
Definition: scheduler.h:33
std::vector< std::reference_wrapper< const Job > > JobList
Definition: scheduler.h:215
Definition: communication.h:585