6using namespace fpmas::model;
26 std::vector<char> data;
48 :
MetaCell(utility, std::vector<char>(cell_size)) {
57 MetaCell(
float utility,
const std::vector<char>& data)
58 : utility(utility), data(data) {
72 const std::vector<char>&
getData()
const {
115 virtual const fpmas::api::model::AgentNode*
cellNode()
const = 0;
124template<
typename CellType>
129 static void to_json(nlohmann::json &j,
const CellType *cell) {
130 j = {cell->getUtility(), cell->getData()};
137 return new CellType(j[0].get<float>(), j[1].get<std::vector<char>>());
144 const fpmas::io::datapack::ObjectPack &o,
const CellType *cell) {
145 return o.size<
float>() + o.size(cell->getData());
152 fpmas::io::datapack::ObjectPack &o,
const CellType *cell) {
153 o.put(cell->getUtility());
154 o.put(cell->getData());
161 float utility = o.get<
float>();
162 std::vector<char> data = o.get<std::vector<char>>();
163 return new CellType(utility, data);
167#define IMPLEM_CELL_INTERACTION(INTERACTION, CELL_TYPE)\
168 void INTERACTION##_cell() override {\
169 auto neighbors = this->outNeighbors<fpmas::api::model::Agent>(fpmas::api::model::CELL_SUCCESSOR);\
170 ReaderWriter::INTERACTION(neighbors);\
173#define IMPLEM_CELL_INTERACTIONS(CELL_TYPE)\
174 IMPLEM_CELL_INTERACTION(read_all, CELL_TYPE)\
175 IMPLEM_CELL_INTERACTION(read_one, CELL_TYPE)\
176 IMPLEM_CELL_INTERACTION(write_all, CELL_TYPE)\
177 IMPLEM_CELL_INTERACTION(write_one, CELL_TYPE)\
178 IMPLEM_CELL_INTERACTION(read_all_write_one, CELL_TYPE)\
179 IMPLEM_CELL_INTERACTION(read_all_write_all, CELL_TYPE)
186 public GridCellBase<MetaGridCell>,
201 MetaGridCell(DiscretePoint location,
float utility,
const std::vector<char>& data)
214 MetaGridCell(DiscretePoint location,
float utility, std::size_t cell_size)
215 :
MetaGridCell(location, utility, std::vector<char>(cell_size)) {
218 const fpmas::api::model::AgentNode*
cellNode()
const override {
219 return this->GridCellBase<MetaGridCell>::node();
230 public GraphCellBase<MetaGraphCell>,
261 const fpmas::api::model::AgentNode*
cellNode()
const override {
262 return this->GraphCellBase<MetaGraphCell>::node();
354 std::vector<GridAttractor> attractors;
355 std::size_t cell_size;
370 std::vector<GridAttractor> attractors,
371 std::size_t cell_size) :
372 utility_function(utility_function), attractors(attractors),
373 cell_size(cell_size) {
388 std::size_t cell_size;
396 : cell_size(cell_size) {
InverseUtility()
Definition: cell.h:321
InverseUtility(float offset)
Definition: cell.h:329
float utility(GridAttractor attractor, DiscretePoint point) const override
static void to_json(nlohmann::json &j, const CellType *cell)
Definition: cell.h:129
static void to_datapack(fpmas::io::datapack::ObjectPack &o, const CellType *cell)
Definition: cell.h:151
static std::size_t size(const fpmas::io::datapack::ObjectPack &o, const CellType *cell)
Definition: cell.h:143
static CellType * from_json(const nlohmann::json &j)
Definition: cell.h:136
static CellType * from_datapack(const fpmas::io::datapack::ObjectPack &o)
Definition: cell.h:160
float utility(GridAttractor attractor, DiscretePoint point) const override
float utility(GridAttractor attractor, DiscretePoint point) const override
virtual float utility(GridAttractor attractor, DiscretePoint point) const =0