fpmas 1.6
spatial_model.h
Go to the documentation of this file.
1#ifndef FPMAS_ENVIRONMENT_API_H
2#define FPMAS_ENVIRONMENT_API_H
3
8#include "../model.h"
9
10namespace fpmas { namespace api { namespace model {
11
18 CELL_SUCCESSOR = -1,
19 LOCATION = -2,
20 MOVE = -3,
21 PERCEIVE = -4,
22 PERCEPTION = -5,
23 NEW_LOCATION = -6,
24 NEW_MOVE = -7,
25 NEW_PERCEIVE = -8
26 };
27
33 public:
39 virtual void init() = 0;
48 virtual void handleNewLocation() = 0;
57 virtual void handleMove() = 0;
66 virtual void handlePerceive() = 0;
67
75 virtual void updatePerceptions(AgentGroup& group) = 0;
76
77 virtual ~CellBehavior() {}
78 };
79
90 class Cell : public Agent, public CellBehavior {
91 public:
103 virtual std::vector<Cell*> successors() = 0;
104
105 virtual ~Cell() {}
106 };
107
120 template<typename CellType>
121 class Range {
122 public:
137 virtual bool contains(CellType* root, CellType* cell) const = 0;
138
176 virtual std::size_t radius(CellType* origin) const = 0;
177
178 virtual ~Range() {}
179 };
180
186 public:
198 virtual void handleNewMove() = 0;
199
211 virtual void handleNewPerceive() = 0;
212
213 virtual ~SpatialAgentBehavior() {}
214 };
215
233 template<typename CellType>
234 class SpatialAgent : public Agent, public SpatialAgentBehavior {
235 public:
236 static_assert(std::is_base_of<api::model::Cell, CellType>::value,
237 "CellType must extend api::model::Cell");
241 typedef CellType Cell;
242
243
281 virtual DistributedId locationId() const = 0;
282
295 virtual CellType* locationCell() const = 0;
296
313 virtual void initLocation(Cell* cell) = 0;
314
320 virtual const Range<CellType>& mobilityRange() const = 0;
321
327 virtual const Range<CellType>& perceptionRange() const = 0;
328
329 protected:
342 virtual void moveTo(DistributedId id) = 0;
343
369 virtual void moveTo(Cell* cell) = 0;
370 };
371
375 template<typename CellType>
377 public:
398 virtual void init(
400 std::vector<api::model::SpatialAgent<CellType>*> agents,
401 std::vector<CellType*> cells) = 0;
402
406 virtual void step() = 0;
413 virtual bool end() = 0;
414
415 virtual ~EndCondition() {};
416 };
417
418 template<typename CellType> class SpatialModel;
419
420
424 template<typename CellType>
426 public:
445 virtual api::scheduler::JobList jobs() const = 0;
446
447 virtual ~DistributedMoveAlgorithm() {}
448 };
449
454 template<typename CellType>
455 class MoveAgentGroup : public virtual AgentGroup {
456 public:
473 };
474
478 template<typename _CellType>
479 class SpatialModel : public virtual Model {
480 public:
484 typedef _CellType CellType;
485
495 virtual void add(CellType* cell) = 0;
496
506 virtual std::vector<CellType*> cells() = 0;
507
514 virtual AgentGroup& cellGroup() = 0;
515
519 virtual const AgentGroup& cellGroup() const = 0;
520
540 virtual MoveAgentGroup<CellType>& buildMoveGroup(GroupId id, const Behavior& behavior) = 0;
541
542 virtual ~SpatialModel() {}
543 };
544
567 template<typename CellType>
569 public:
583 virtual std::vector<CellType*> build(
584 SpatialModel<CellType>& spatial_model
585 ) const = 0;
586
595 virtual std::vector<CellType*> build(
596 SpatialModel<CellType>& spatial_model,
597 GroupList groups
598 ) const = 0;
599
600 virtual ~CellNetworkBuilder() {}
601 };
602
606 template<typename CellType>
608 public:
615
616 virtual ~SpatialAgentFactory() {}
617 };
618
655 template<typename CellType>
657 public:
668 virtual std::size_t countAt(CellType* cell) = 0;
669
670 virtual ~SpatialAgentMapping() {}
671 };
672
684 template<typename CellType, typename MappingCellType>
686 static_assert(
687 std::is_base_of<MappingCellType, CellType>::value,
688 "MappingCellType must be a base of CellType"
689 );
690 public:
718 virtual void build(
720 GroupList groups,
723 ) = 0;
724
750 virtual void build(
752 GroupList groups,
753 std::function<SpatialAgent<CellType>*()> factory,
755 ) = 0;
756
757 virtual ~SpatialAgentBuilder() {}
758 };
759
760}}}
761#endif
Definition: communication.h:251
Definition: distributed_id.h:89
Definition: model.h:547
Definition: model.h:174
Definition: model.h:520
Definition: spatial_model.h:32
virtual void updatePerceptions(AgentGroup &group)=0
virtual void handleNewLocation()=0
Definition: spatial_model.h:568
virtual std::vector< CellType * > build(SpatialModel< CellType > &spatial_model, GroupList groups) const =0
virtual std::vector< CellType * > build(SpatialModel< CellType > &spatial_model) const =0
Definition: spatial_model.h:90
virtual std::vector< Cell * > successors()=0
Definition: spatial_model.h:425
virtual api::scheduler::JobList jobs() const =0
Definition: spatial_model.h:376
virtual void init(api::communication::MpiCommunicator &comm, std::vector< api::model::SpatialAgent< CellType > * > agents, std::vector< CellType * > cells)=0
Definition: model.h:841
Definition: spatial_model.h:455
virtual DistributedMoveAlgorithm< CellType > & distributedMoveAlgorithm()=0
Definition: spatial_model.h:121
virtual bool contains(CellType *root, CellType *cell) const =0
virtual std::size_t radius(CellType *origin) const =0
Definition: spatial_model.h:185
Definition: spatial_model.h:685
virtual void build(SpatialModel< CellType > &model, GroupList groups, std::function< SpatialAgent< CellType > *()> factory, SpatialAgentMapping< MappingCellType > &agent_mapping)=0
virtual void build(SpatialModel< CellType > &model, GroupList groups, SpatialAgentFactory< CellType > &factory, SpatialAgentMapping< MappingCellType > &agent_mapping)=0
Definition: spatial_model.h:607
virtual SpatialAgent< CellType > * build()=0
Definition: spatial_model.h:656
virtual std::size_t countAt(CellType *cell)=0
Definition: spatial_model.h:234
virtual void moveTo(DistributedId id)=0
virtual const Range< CellType > & mobilityRange() const =0
virtual CellType * locationCell() const =0
virtual void initLocation(Cell *cell)=0
virtual const Range< CellType > & perceptionRange() const =0
CellType Cell
Definition: spatial_model.h:237
virtual void moveTo(Cell *cell)=0
virtual DistributedId locationId() const =0
Definition: spatial_model.h:479
virtual void add(CellType *cell)=0
_CellType CellType
Definition: spatial_model.h:484
virtual MoveAgentGroup< CellType > & buildMoveGroup(GroupId id, const Behavior &behavior)=0
virtual AgentGroup & cellGroup()=0
virtual const AgentGroup & cellGroup() const =0
virtual std::vector< CellType * > cells()=0
int LayerId
Definition: edge.h:13
int GroupId
Definition: model.h:78
SpatialModelLayers
Definition: spatial_model.h:17
std::vector< std::reference_wrapper< AgentGroup > > GroupList
Definition: model.h:833
std::vector< std::reference_wrapper< const Job > > JobList
Definition: scheduler.h:215
Definition: fpmas.cpp:3