fpmas 1.6
grid_agent_mapping.h
Go to the documentation of this file.
1#ifndef FPMAS_GRID_AGENT_MAPPING_G
2#define FPMAS_GRID_AGENT_MAPPING_G
3
10#include "fpmas/random/random.h"
12
13
14namespace fpmas { namespace model {
15 using api::model::DiscretePoint;
17
27 class RandomGridAgentMapping : public api::model::SpatialAgentMapping<api::model::GridCell> {
28 private:
29 std::unordered_map<DiscreteCoordinate, std::unordered_map<DiscreteCoordinate, std::size_t>> count_map;
30 public:
52 template<typename DistributionX, typename DistributionY>
54 DistributionX&& x,
55 DistributionY&& y,
56 std::size_t agent_count
57 );
58
59 std::size_t countAt(api::model::GridCell* cell) override {
60 // When values are not in the map, 0 (default initialized) will
61 // be returned
62 return count_map[cell->location().x][cell->location().y];
63 }
64 };
65
66 template<typename DistributionX, typename DistributionY>
68 DistributionX&& x,
69 DistributionY&& y,
70 std::size_t agent_count) {
71
72 for(std::size_t i = 0; i < agent_count; i++) {
74 count_map[p.x][p.y]++;
75 }
76 }
77
78
85 public:
97 DiscreteCoordinate grid_width,
98 DiscreteCoordinate grid_height,
99 std::size_t agent_count
100 )
102 random::UniformIntDistribution<DiscreteCoordinate>(0, grid_width-1),
103 random::UniformIntDistribution<DiscreteCoordinate>(0, grid_height-1),
104 agent_count) {}
105 };
106
117 private:
118 std::unordered_map<DiscreteCoordinate, std::unordered_map<DiscreteCoordinate, std::size_t>>
119 count_map;
120 public:
136 DiscreteCoordinate grid_width,
137 DiscreteCoordinate grid_height,
138 std::size_t agent_count,
139 std::size_t max_agent_by_cell
140 );
141
142 std::size_t countAt(api::model::GridCell* cell) override;
143 };
144
145}}
146#endif
Definition: grid.h:78
virtual DiscretePoint location() const =0
Definition: spatial_model.h:656
Definition: grid_agent_mapping.h:116
ConstrainedGridAgentMapping(DiscreteCoordinate grid_width, DiscreteCoordinate grid_height, std::size_t agent_count, std::size_t max_agent_by_cell)
Definition: grid_agent_mapping.cpp:6
std::size_t countAt(api::model::GridCell *cell) override
Definition: grid_agent_mapping.cpp:64
Definition: grid_agent_mapping.h:27
RandomGridAgentMapping(DistributionX &&x, DistributionY &&y, std::size_t agent_count)
Definition: grid_agent_mapping.h:67
std::size_t countAt(api::model::GridCell *cell) override
Definition: grid_agent_mapping.h:59
Definition: grid_agent_mapping.h:84
UniformGridAgentMapping(DiscreteCoordinate grid_width, DiscreteCoordinate grid_height, std::size_t agent_count)
Definition: grid_agent_mapping.h:96
long DiscreteCoordinate
Definition: grid.h:15
Distribution< std::uniform_int_distribution< IntType > > UniformIntDistribution
Definition: distribution.h:78
Definition: fpmas.cpp:3
DiscreteCoordinate x
Definition: grid.h:25
DiscreteCoordinate y
Definition: grid.h:29
static random::mt19937_64 rd
Definition: spatial_agent_mapping.h:31