1#ifndef FPMAS_MODEL_SPATIAL_GRAPH_H
2#define FPMAS_MODEL_SPATIAL_GRAPH_H
12namespace fpmas {
namespace model {
25 friend nlohmann::adl_serializer<ReachableCell>;
82 template<
typename GraphCellType,
typename Derived = GraphCellType>
84 public CellBase<api::model::Cell, GraphCellType, GraphCellBase<GraphCellType, Derived>>,
133 template<
typename GraphCellType = GraphCell>
136 std::is_base_of<api::model::Cell, GraphCellType>::value,
137 "The specified GraphCellType must implement api::model::Cell."
140 std::is_base_of<ReachableCell, GraphCellType>::value,
141 "The specified GraphCellType must extend ReachableCell"
144 bool include_location;
153 GraphRange(
bool include_location = INCLUDE_LOCATION) : include_location(include_location) {
165 std::size_t
radius(GraphCellType*)
const override {
179 bool contains(GraphCellType* root, GraphCellType* cell)
const override {
180 if(include_location && root->node()->getId() == cell->node()->getId())
182 return root->reachableCells().count(cell->node()->getId()) > 0;
205 for(
auto neighbor : cell->node()->outNeighbors(api::model::CELL_SUCCESSOR))
206 graph_cell->addReachableCell(neighbor->getId());
222 struct adl_serializer<
fpmas::model::ReachableCell> {
242 template<
typename AgentType,
typename Derived>
243 struct adl_serializer<
fpmas::api::utils::PtrWrapper<fpmas::model::GraphCellBase<AgentType, Derived>>> {
266 const_cast<Derived*
>(
dynamic_cast<const Derived*
>(ptr.
get())));
296 return derived_ptr.
get();
301namespace fpmas {
namespace io {
namespace json {
312 template<
typename AgentType,
typename Derived>
335 const_cast<Derived*
>(
dynamic_cast<const Derived*
>(agent.
get()))
356 return derived_ptr.
get();
362namespace fpmas {
namespace io {
namespace datapack {
379 static std::size_t size(
388 static void to_datapack(
418 template<
typename GraphCellType,
typename Derived>
431 const_cast<Derived*
>(
dynamic_cast<const Derived*
>(ptr.
get()))))
445 const_cast<Derived*
>(
dynamic_cast<const Derived*
>(ptr.
get())));
449 pack.
put(reachable_cell);
478 return derived_ptr.
get();
502 template<
typename GraphCellType,
typename Derived>
516 const_cast<Derived*
>(
dynamic_cast<const Derived*
>(ptr.
get()))
536 const_cast<Derived*
>(
dynamic_cast<const Derived*
>(ptr.
get()))
557 return derived_ptr.
get();
virtual void synchronize()=0
Definition: distributed_id.h:89
virtual std::vector< Agent * > localAgents() const =0
virtual AgentGraph & graph()=0
Definition: spatial_model.h:121
Definition: spatial_model.h:479
virtual AgentGroup & cellGroup()=0
Definition: ptr_wrapper.h:21
T * get()
Definition: ptr_wrapper.h:58
Definition: datapack.h:301
std::size_t size() const
Definition: datapack.h:367
void put(const T &item)
Definition: datapack.h:447
T get() const
Definition: datapack.h:459
Definition: spatial_model.h:215
GraphCellBase< GraphCellType, Derived > JsonBase
Definition: graph.h:90
bool contains(GraphCellType *root, GraphCellType *cell) const override
Definition: graph.h:179
static void synchronize(api::model::SpatialModel< GraphCellType > &model)
Definition: graph.h:201
GraphRange(bool include_location=INCLUDE_LOCATION)
Definition: graph.h:153
std::size_t radius(GraphCellType *) const override
Definition: graph.h:165
void addReachableCell(DistributedId id)
Definition: graph.h:51
std::set< DistributedId > reachable_cells
Definition: graph.h:35
void clearReachableCells()
Definition: graph.h:67
const std::set< DistributedId > & reachableCells() const
Definition: graph.h:42
void removeReachableCell(DistributedId id)
Definition: graph.h:60
#define FPMAS_DEFAULT_DATAPACK(AGENT)
Definition: datapack_serializer.h:154
#define FPMAS_DEFAULT_JSON(AGENT)
Definition: json_serializer.h:127
nlohmann::basic_json< std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, light_serializer > light_json
Definition: json.h:14
static std::size_t size(const LightObjectPack &pack, const Ptr &ptr)
Definition: graph.h:514
static Ptr from_datapack(const LightObjectPack &pack)
Definition: graph.h:552
PtrWrapper< fpmas::model::GraphCellBase< GraphCellType, Derived > > Ptr
Definition: graph.h:507
static void to_datapack(LightObjectPack &pack, const Ptr &ptr)
Definition: graph.h:532
Definition: datapack.h:1411
static void to_datapack(LightObjectPack &pack, const T &item)
Definition: datapack.h:1438
static T from_datapack(const LightObjectPack &pack)
Definition: datapack.h:1451
static void to_datapack(ObjectPack &pack, const Ptr &ptr)
Definition: graph.h:442
PtrWrapper< fpmas::model::GraphCellBase< GraphCellType, Derived > > Ptr
Definition: graph.h:423
static Ptr from_datapack(const ObjectPack &pack)
Definition: graph.h:468
static std::size_t size(const ObjectPack &p, const Ptr &ptr)
Definition: graph.h:429
Definition: datapack.h:55
PtrWrapper< fpmas::model::GraphCellBase< AgentType, Derived > > Ptr
Definition: graph.h:317
static void to_json(light_json &j, const Ptr &agent)
Definition: graph.h:331
static Ptr from_json(const light_json &j)
Definition: graph.h:351
static void from_json(const light_json &j, T &data)
Definition: json.h:123
static void to_json(light_json &j, const T &data)
Definition: json.h:107
static Ptr from_json(const nlohmann::json &j)
Definition: graph.h:288
fpmas::api::utils::PtrWrapper< fpmas::model::GraphCellBase< AgentType, Derived > > Ptr
Definition: graph.h:247
static void to_json(nlohmann::json &j, const Ptr &ptr)
Definition: graph.h:263