fpmas 1.5
model.h
Go to the documentation of this file.
1#ifndef FPMAS_MODEL_H
2#define FPMAS_MODEL_H
3
9#include "guards.h"
10#include "detail/model.h"
11#include "fpmas/random/random.h"
12#include "fpmas/io/breakpoint.h"
13#include "fpmas/utils/format.h"
16#include "fpmas/synchro/synchro.h"
17#include <fstream>
18
19
20namespace fpmas { namespace model {
21
26 bool is_agent_in_group(api::model::Agent* agent, api::model::GroupId group_id);
27
31 bool is_agent_in_group(api::model::Agent* agent, api::model::AgentGroup& group);
32
41 template<typename AgentType>
42 class Neighbor {
43 private:
44 AgentPtr* _agent;
45 AgentEdge* _edge;
46
47 public:
61 Neighbor() : Neighbor(nullptr, nullptr) {}
62
70 HEDLEY_DEPRECATED_FOR(1.1, Neighbor(AgentPtr*, AgentEdge*))
72 : Neighbor(agent, nullptr) {}
73
81 : _agent(agent), _edge(edge) {}
82
86 operator AgentType*() const {
87 return static_cast<AgentType*>(_agent->get());
88 }
89
95 AgentType* operator->() const {
96 return static_cast<AgentType*>(_agent->get());
97 }
98
104 AgentType& operator*() const {
105 return *static_cast<AgentType*>(_agent->get()); }
106
113 AgentEdge* edge() const {
114 return _edge;
115 }
116
123 AgentType* agent() const {
124 if(_agent == nullptr)
125 return nullptr;
126 return static_cast<AgentType*>(_agent->get());
127 }
128 };
129
142 template<typename AgentType, typename Compare = std::less<AgentType>>
144 private:
145 Compare compare;
146 public:
147 CompareNeighbors() = default;
148
152 CompareNeighbors(const Compare& compare) : compare(compare) {
153 }
154
159 const Neighbor<AgentType>& n1,
160 const Neighbor<AgentType>& n2) const {
161 return compare(*n1.agent(), *n2.agent());
162 }
163 };
164
184 template<typename AgentType>
186 return *n1.agent() < *n2.agent();
187 }
188
204
211 };
212
224 template<typename AgentType>
225 class Neighbors {
226 private:
227 typedef typename std::vector<Neighbor<AgentType>>::iterator iterator;
228 typedef typename std::vector<Neighbor<AgentType>>::const_iterator const_iterator;
229 std::vector<Neighbor<AgentType>> neighbors;
230
231 public:
232 Neighbors() = default;
233
239 Neighbors(const std::vector<Neighbor<AgentType>>& neighbors)
240 : neighbors(neighbors) {}
241
247 iterator begin() {
248 return neighbors.begin();
249 }
255 const_iterator begin() const {
256 return neighbors.begin();
257 }
258
264 iterator end() {
265 return neighbors.end();
266 }
267
273 const_iterator end() const {
274 return neighbors.end();
275 }
276
282 std::size_t count() const {
283 return neighbors.size();
284 }
285
291 bool empty() const {
292 return neighbors.empty();
293 }
294
303 Neighbor<AgentType>& at(std::size_t i) {
304 try {
305 return neighbors.at(i);
306 } catch(const std::out_of_range&) {
307 throw;
308 }
309 }
310
314 const Neighbor<AgentType>& at(std::size_t i) const {
315 try {
316 return neighbors.at(i);
317 } catch(const std::out_of_range&) {
318 throw;
319 }
320 }
321
329 return neighbors[i];
330 }
331
335 const Neighbor<AgentType>& operator[](std::size_t i) const {
336 return neighbors[i];
337 }
338
348 template<typename Gen>
349 Neighbors& shuffle(Gen& gen) {
350 std::shuffle(neighbors.begin(), neighbors.end(), gen);
351 return *this;
352 }
353
364 }
365
397 template<typename Compare = std::less<AgentType>>
398 Neighbors& sort(Compare comp = Compare()) {
399 std::sort(
400 neighbors.begin(), neighbors.end(),
402 );
403 return *this;
404 }
405
416 template<typename Filter>
417 Neighbors& filter(Filter _filter) {
418 neighbors.erase(
419 std::remove_if(
420 neighbors.begin(), neighbors.end(),
421 [&_filter] (const Neighbor<AgentType>& agent) {return !_filter(agent);}),
422 neighbors.end()
423 );
424 return *this;
425 }
426
433 template<typename Gen>
436 0, this->count()-1);
437 return neighbors.at(index(gen));
438 }
439
450 }
451 };
452
459 template<typename AgentType>
461 private:
462 std::vector<void(AgentType::*)()> _behaviors;
463
464 template<typename T, typename Enable=void>
465 struct AutoAgentCast {
466 static T* cast(api::model::Agent* agent) {
467 return dynamic_cast<T*>(agent);
468 }
469 };
470
471 template<typename T>
472 struct AutoAgentCast<T, typename std::enable_if<
473 std::is_base_of<api::model::Agent, T>::value
474 >::type> {
475 static T* cast(api::model::Agent* agent) {
476 return static_cast<T*>(agent);
477 }
478 };
479
480 public:
531 template<typename ...T>
532 Behavior(T... behaviors)
533 : _behaviors({behaviors...}){
534 }
535
536 void execute(api::model::Agent* agent) const {
537 for(auto behavior : this->_behaviors)
538 (AutoAgentCast<AgentType>::cast(agent)->*behavior)();
539 }
540 };
541
551 template<typename AgentType, typename ... Args>
553 private:
554 void (AgentType::* behavior)(Args...);
555 std::tuple<Args...> args;
556
557 // helpers for tuple unrolling
558 // From: https://riptutorial.com/cplusplus/example/24746/storing-function-arguments-in-std--tuple
559 template<int ...> struct seq {};
560 template<int N, int ...S> struct gens {
561 public:
562 typedef typename gens<N-1, N-1, S...>::type type;
563 };
564 template<int ...S> struct gens<0, S...>{ typedef seq<S...> type; };
565
566 // invocation helper
567 template<int ...S>
568 void call_fn_internal(api::model::Agent* agent, const seq<S...>) const
569 {
570 (dynamic_cast<AgentType*>(agent)->*behavior)(std::get<S>(args) ...);
571 }
572
573 public:
582 void (AgentType::* behavior)(Args...),
583 Args... args)
584 : behavior(behavior), args(args...) {}
585
592 void execute(api::model::Agent* agent) const override {
593 return call_fn_internal(agent, typename gens<sizeof...(Args)>::type());
594 }
595 };
596
601 void execute(api::model::Agent*) const override {
602 }
603 };
604
605 namespace detail {
701 template<typename AgentInterface, typename AgentType, typename TypeIdBase = AgentType>
702 class AgentBase : public AgentInterface {
703 public:
712 typedef AgentType FinalAgentType;
713
714 private:
715 std::vector<api::model::GroupId> group_ids;
716 std::vector<api::model::AgentGroup*> _groups;
717 std::unordered_map<
718 api::model::GroupId, std::list<api::model::Agent*>::iterator
719 > group_pos;
720 std::unordered_map<api::model::GroupId, api::model::AgentTask*> _tasks;
722 api::model::Model* _model;
723
724 public:
728 AgentBase() = default;
729
744 AgentBase(const AgentBase& agent) = default;
745
760 AgentBase& operator=(const AgentBase& agent) = default;
761
762 // Move constructor and assignment preserve groupIds(), groups(),
763 // group_pos, tasks(), node() and model()
764
779 AgentBase(AgentBase&&) = default;
780
794 return *this;
795 }
796
800 GroupId groupId() const override {
801 if(group_ids.size() > 0)
802 return group_ids.back();
803 return {};
804 }
808 std::vector<GroupId> groupIds() const override {return group_ids;}
812 void setGroupId(api::model::GroupId id) override {
813 group_ids.push_back(id);}
817 void addGroupId(api::model::GroupId id) override {
818 group_ids.push_back(id);
819 }
820
825 group_ids.erase(std::remove(group_ids.begin(), group_ids.end(), id));
826 }
827
832 if(_groups.size() > 0)
833 return _groups.back();
834 return nullptr;
835 }
839 std::vector<const api::model::AgentGroup*> groups() const override {
840 return {_groups.begin(), _groups.end()};
841 }
842
846 const api::model::AgentGroup* group() const override {return _groups.back();}
850 std::vector<api::model::AgentGroup*> groups() override {return _groups;}
851
856 _groups.push_back(group);
857 }
862 _groups.push_back(group);
863 }
864
869 _groups.erase(std::remove(_groups.begin(), _groups.end(), group));
870 _tasks.erase(group->groupId());
871 }
872
878 std::list<api::model::Agent*>::iterator pos
879 ) override {
880 group_pos[gid] = pos;
881 }
882
886 std::list<api::model::Agent*>::iterator getGroupPos(api::model::GroupId gid) const override {
887 return group_pos.find(gid)->second;
888 }
889
893 api::model::TypeId typeId() const override {return TYPE_ID;}
897 api::model::Agent* copy() const override {
898 return new AgentType(*static_cast<const AgentType*>(this));
899 }
900
904 void copyAssign(api::model::Agent* agent) override {
905 // Uses AgentType copy assignment operator
906 *static_cast<AgentType*>(this) = *static_cast<const AgentType*>(agent);
907 }
908
912 void moveAssign(api::model::Agent* agent) override {
913
914 // Uses AgentType move assignment operator
915 //
916 // groupIds(), groups(), tasks(), node() and model() are
917 // notably moved from agent to this, but this as no effect
918 // considering the move assignment operator defined above. In
919 // consequence, those fields are properly preserved, as
920 // required by the method.
921 // If AgentType only explicitly defines a move assignment
922 // operator, it should not call the AgentBase move assignment
923 // so there should not be any problem.
924 *static_cast<AgentType*>(this) = std::move(*static_cast<AgentType*>(agent));
925 }
926
930 api::model::AgentNode* node() override {return _node;}
934 const api::model::AgentNode* node() const override {return _node;}
938 void setNode(api::model::AgentNode* node) override {_node = node;}
939
943 api::model::Model* model() override {return _model;}
947 const api::model::Model* model() const override {return _model;}
951 void setModel(api::model::Model* model) override {_model = model;}
952
957 return _tasks.at(this->groupId());
958 }
962 const api::model::AgentTask* task() const override {
963 return _tasks.at(this->groupId());
964 }
969 _tasks[this->groupId()] = task;
970 }
971
976 assert(_tasks.count(id) > 0);
977 return _tasks.at(id);
978 }
983 return _tasks.at(id);}
984
989 _tasks[id] = task;
990 }
991
995 const std::unordered_map<api::model::GroupId, api::model::AgentTask*>&
996 tasks() override { return _tasks;}
997
998
1005 virtual void act() override {}
1006
1020 template<typename NeighborAgentType> Neighbors<NeighborAgentType> outNeighbors() const {
1021 std::vector<Neighbor<NeighborAgentType>> out;
1022 for(api::model::AgentEdge* _edge : node()->getOutgoingEdges()) {
1023 api::model::AgentNode* _node = _edge->getTargetNode();
1024 if(NeighborAgentType* neighbor = dynamic_cast<NeighborAgentType*>(_node->data().get())) {
1025 out.push_back({&_node->data(), _edge});
1026 }
1027 }
1028 return out;
1029 }
1030
1044 template<typename NeighborAgentType> Neighbors<NeighborAgentType> outNeighbors(api::graph::LayerId layer) const {
1045 std::vector<Neighbor<NeighborAgentType>> out;
1046 for(api::model::AgentEdge* _edge : node()->getOutgoingEdges(layer)) {
1047 api::model::AgentNode* _node = _edge->getTargetNode();
1048 if(NeighborAgentType* neighbor = dynamic_cast<NeighborAgentType*>(_node->data().get())) {
1049 out.push_back({&_node->data(), _edge});
1050 }
1051 }
1052 return out;
1053 }
1054
1055
1069 template<typename NeighborAgentType> Neighbors<NeighborAgentType> inNeighbors() const {
1070 std::vector<Neighbor<NeighborAgentType>> in;
1071 for(api::model::AgentEdge* _edge : node()->getIncomingEdges()) {
1072 api::model::AgentNode* _node = _edge->getSourceNode();
1073 if(NeighborAgentType* neighbor = dynamic_cast<NeighborAgentType*>(_node->data().get())) {
1074 in.push_back({&_node->data(), _edge});
1075 }
1076 }
1077 return in;
1078 }
1079
1093 template<typename NeighborAgentType> Neighbors<NeighborAgentType> inNeighbors(api::graph::LayerId layer) const {
1094 std::vector<Neighbor<NeighborAgentType>> in;
1095 for(api::model::AgentEdge* _edge : node()->getIncomingEdges(layer)) {
1096 api::model::AgentNode* _node = _edge->getSourceNode();
1097 if(NeighborAgentType* neighbor = dynamic_cast<NeighborAgentType*>(_node->data().get())) {
1098 in.push_back({&_node->data(), _edge});
1099 }
1100 }
1101 return in;
1102 }
1103
1104 virtual ~AgentBase() {}
1105 };
1111 template<typename AgentInterface, typename AgentType, typename TypeIdBase>
1113 }
1114
1123 template<typename AgentType, typename TypeIdBase = AgentType>
1125
1130
1140 private:
1142 std::vector<api::model::Agent*> agents;
1143
1144 public:
1151 : group(group) {}
1152
1160 agents.push_back(agent);
1161 }
1162
1175
1181 std::size_t nodeCount() override {
1182 return agents.size();
1183 }
1184 };
1194 private:
1195 std::function<api::model::Agent*()> allocator;
1196 std::function<api::model::Agent*()> distant_allocator;
1198
1199 public:
1240 std::size_t agent_count,
1241 std::function<api::model::Agent*()> allocator,
1243
1288 std::size_t agent_count,
1289 std::function<api::model::Agent*()> allocator,
1290 std::function<api::model::Agent*()> distant_allocator,
1292
1293
1299
1306 int location,
1308 };
1309
1313 template<template<typename> class SyncMode>
1315
1317
1328
1334
1345
1351
1356
1364 private:
1365 std::string file_format;
1366 std::fstream stream;
1368 api::model::Model& model;
1369 scheduler::detail::LambdaTask task {[this] () {
1370 stream.open(utils::format(
1371 file_format,
1372 model.getMpiCommunicator().getRank(),
1373 model.runtime().currentDate()
1374 ), std::ios_base::out);
1375 breakpoint.dump(stream, model);
1376 stream.close();
1377 }};
1378 scheduler::Job _job {{task}};
1379
1380 public:
1402 std::string file_format,
1404 api::model::Model& model)
1405 : file_format(file_format), breakpoint(breakpoint), model(model) {
1406 }
1407
1413 const api::scheduler::Job& job() const {return _job;}
1414 };
1415}}
1416
1417namespace fpmas { namespace io { namespace json {
1418
1428 template<>
1455 static void to_json(light_json& j, const
1457
1485 };
1486
1496 template<>
1501 static void to_json(light_json& j, const
1503
1504
1512 };
1513}}}
1514
1515namespace fpmas { namespace io { namespace datapack {
1516 using api::model::AgentPtr;
1518
1528 template<>
1534 static std::size_t size(const ObjectPack& p, const AgentPtr& ptr);
1535
1543 static void to_datapack(ObjectPack& pack, const AgentPtr& pointer);
1544
1558 static AgentPtr from_datapack(const ObjectPack& pack);
1559 };
1560
1575 template<>
1581 static std::size_t size(const ObjectPack& pack, const WeakAgentPtr& ptr);
1582
1586 static void to_datapack(ObjectPack& pack, const WeakAgentPtr& ptr);
1587
1594 };
1595
1605 template<>
1617 static std::size_t size(const LightObjectPack& pack, const AgentPtr& ptr);
1618
1641 static void to_datapack(LightObjectPack& pack, const AgentPtr& pointer);
1642
1673 };
1674
1689 template<>
1695 static std::size_t size(const LightObjectPack& pack, const WeakAgentPtr& ptr);
1696
1700 static void to_datapack(LightObjectPack& pack, const WeakAgentPtr& ptr);
1701
1709 };
1710}}}
1711
1712namespace fpmas { namespace synchro {
1719 template<>
1749 static void update(
1750 api::model::AgentPtr& local_agent,
1751 api::model::AgentPtr&& updated_agent) {
1752 // TODO: this should probably be improved in 2.0
1753 // The purpose of "moveAssign" is clearly inconsistent with its
1754 // current behavior, that does much more that just "moving" the
1755 // agent.
1756
1757 // Sets and overrides the fields that must be preserved
1758 std::set<api::model::GroupId> local_ids;
1759 for(auto id : local_agent->groupIds())
1760 local_ids.insert(id);
1761 std::set<api::model::GroupId> updated_ids;
1762 for(auto id : updated_agent->groupIds())
1763 updated_ids.insert(id);
1764
1765 std::vector<api::model::GroupId> new_groups;
1766 for(auto id : updated_ids)
1767 if(local_ids.count(id) == 0)
1768 new_groups.push_back(id);
1769
1770 std::vector<api::model::GroupId> obsolete_groups;
1771 for(auto id : local_ids)
1772 if(updated_ids.count(id) == 0)
1773 obsolete_groups.push_back(id);
1774
1775 local_agent = std::move(updated_agent);
1776
1777 // Dynamically updates groups lists
1778 // If `agent` was added to / removed from group on a distant
1779 // process for example (assuming that this agent is DISTANT),
1780 // this agent representation groups are updated.
1781 for(auto id : new_groups)
1782 local_agent->model()->getGroup(id).add(local_agent.get());
1783 for(auto id : obsolete_groups)
1784 local_agent->model()->getGroup(id).remove(local_agent.get());
1785
1786 }
1787 };
1788}}
1789
1790namespace nlohmann {
1799 template<>
1800 struct adl_serializer<fpmas::api::model::AgentPtr> {
1812 static void to_json(json& j, const fpmas::api::model::AgentPtr& pointer);
1813
1828 };
1829
1839 template<>
1840 struct adl_serializer<fpmas::api::model::WeakAgentPtr> {
1841
1845 static void to_json(json& j, const fpmas::api::model::WeakAgentPtr& pointer);
1846
1853 };
1854
1858 template<>
1859 struct adl_serializer<fpmas::api::model::Model> {
1871 static void to_json(json& j, const fpmas::api::model::Model& model);
1872
1885 static void from_json(const json& j, fpmas::api::model::Model& model);
1886 };
1887}
1888#endif
Definition: communication.h:251
Definition: distributed_edge.h:91
Definition: distributed_graph.h:169
Definition: distributed_id.h:89
Definition: distributed_node.h:28
Definition: graph_builder.h:23
Definition: breakpoint.h:26
virtual void dump(std::ostream &stream, const T &object)=0
Definition: model.h:547
virtual GroupId groupId() const =0
Definition: model.h:92
Definition: model.h:497
Definition: model.h:174
Definition: model.h:520
Definition: model.h:841
virtual api::runtime::Runtime & runtime()=0
virtual api::communication::MpiCommunicator & getMpiCommunicator()=0
virtual Date currentDate() const =0
Definition: scheduler.h:135
T * get()
Definition: ptr_wrapper.h:58
Definition: clustered_graph_builder.h:349
Definition: graph_builder.h:23
Definition: uniform_graph_builder.h:150
Definition: random_load_balancing.h:27
Definition: ring_graph_builder.h:55
Definition: breakpoint.h:26
Definition: datapack.h:275
Definition: model.h:1139
std::size_t nodeCount() override
Definition: model.h:1181
AgentNodeBuilder(api::model::AgentGroup &group)
Definition: model.h:1150
void push(api::model::Agent *agent)
Definition: model.h:1159
api::model::AgentNode * buildNode(api::graph::DistributedGraph< AgentPtr > &) override
Definition: model.cpp:22
Definition: model.h:1363
AutoBreakpoint(std::string file_format, api::io::Breakpoint< api::model::Model > &breakpoint, api::model::Model &model)
Definition: model.h:1401
const api::scheduler::Job & job() const
Definition: model.h:1413
Definition: model.h:552
void execute(api::model::Agent *agent) const override
Definition: model.h:592
BehaviorWithArgs(void(AgentType::*behavior)(Args...), Args... args)
Definition: model.h:581
Definition: model.h:460
Behavior(T... behaviors)
Definition: model.h:532
void execute(api::model::Agent *agent) const
Definition: model.h:536
Definition: model.h:143
CompareNeighbors(const Compare &compare)
Definition: model.h:152
bool operator()(const Neighbor< AgentType > &n1, const Neighbor< AgentType > &n2) const
Definition: model.h:158
api::model::AgentNode * buildDistantNode(api::graph::DistributedId id, int location, api::graph::DistributedGraph< AgentPtr > &graph) override
Definition: model.cpp:67
api::model::AgentNode * buildNode(api::graph::DistributedGraph< AgentPtr > &graph) override
Definition: model.cpp:57
DistributedAgentNodeBuilder(api::model::AgentGroup &group, std::size_t agent_count, std::function< api::model::Agent *()> allocator, api::communication::MpiCommunicator &comm)
Definition: model.cpp:32
Definition: model.h:600
Definition: model.h:42
Neighbor(AgentPtr *agent, AgentEdge *edge)
Definition: model.h:80
AgentType * operator->() const
Definition: model.h:95
AgentEdge * edge() const
Definition: model.h:113
AgentType & operator*() const
Definition: model.h:104
AgentType * agent() const
Definition: model.h:123
Neighbor()
Definition: model.h:61
Definition: model.h:225
const Neighbor< AgentType > & at(std::size_t i) const
Definition: model.h:314
Neighbor< AgentType > & operator[](std::size_t i)
Definition: model.h:328
bool empty() const
Definition: model.h:291
Neighbors & shuffle(Gen &gen)
Definition: model.h:349
const_iterator end() const
Definition: model.h:273
iterator begin()
Definition: model.h:247
Neighbor< AgentType > random()
Definition: model.h:448
Neighbor< AgentType > random(Gen &gen)
Definition: model.h:434
std::size_t count() const
Definition: model.h:282
Neighbor< AgentType > & at(std::size_t i)
Definition: model.h:303
Neighbors & sort(Compare comp=Compare())
Definition: model.h:398
Neighbors & shuffle()
Definition: model.h:362
const Neighbor< AgentType > & operator[](std::size_t i) const
Definition: model.h:335
iterator end()
Definition: model.h:264
Neighbors & filter(Filter _filter)
Definition: model.h:417
Neighbors(const std::vector< Neighbor< AgentType > > &neighbors)
Definition: model.h:239
const_iterator begin() const
Definition: model.h:255
Definition: model.h:702
api::model::AgentTask * task(api::model::GroupId id) override
Definition: model.h:975
void copyAssign(api::model::Agent *agent) override
Definition: model.h:904
static const api::model::TypeId TYPE_ID
Definition: model.h:704
AgentBase & operator=(AgentBase &&)
Definition: model.h:793
Neighbors< NeighborAgentType > inNeighbors() const
Definition: model.h:1069
void setNode(api::model::AgentNode *node) override
Definition: model.h:938
void removeGroupId(api::model::GroupId id) override
Definition: model.h:824
const std::unordered_map< api::model::GroupId, api::model::AgentTask * > & tasks() override
Definition: model.h:996
void setGroupPos(api::model::GroupId gid, std::list< api::model::Agent * >::iterator pos) override
Definition: model.h:876
api::model::TypeId typeId() const override
Definition: model.h:893
api::model::AgentGroup * group() override
Definition: model.h:831
api::model::Agent * copy() const override
Definition: model.h:897
GroupId groupId() const override
Definition: model.h:800
const api::model::AgentNode * node() const override
Definition: model.h:934
void addGroupId(api::model::GroupId id) override
Definition: model.h:817
AgentBase(AgentBase &&)=default
std::vector< const api::model::AgentGroup * > groups() const override
Definition: model.h:839
void setModel(api::model::Model *model) override
Definition: model.h:951
std::vector< api::model::AgentGroup * > groups() override
Definition: model.h:850
api::model::AgentNode * node() override
Definition: model.h:930
api::model::Model * model() override
Definition: model.h:943
Neighbors< NeighborAgentType > inNeighbors(api::graph::LayerId layer) const
Definition: model.h:1093
std::vector< GroupId > groupIds() const override
Definition: model.h:808
const api::model::AgentTask * task() const override
Definition: model.h:962
Neighbors< NeighborAgentType > outNeighbors(api::graph::LayerId layer) const
Definition: model.h:1044
void removeGroup(api::model::AgentGroup *group) override
Definition: model.h:868
void setTask(api::model::AgentTask *task) override
Definition: model.h:968
void setGroup(api::model::AgentGroup *group) override
Definition: model.h:855
std::list< api::model::Agent * >::iterator getGroupPos(api::model::GroupId gid) const override
Definition: model.h:886
AgentType FinalAgentType
Definition: model.h:712
api::model::AgentTask * task() override
Definition: model.h:956
const api::model::AgentTask * task(api::model::GroupId id) const override
Definition: model.h:982
void moveAssign(api::model::Agent *agent) override
Definition: model.h:912
Neighbors< NeighborAgentType > outNeighbors() const
Definition: model.h:1020
void setTask(api::model::GroupId id, api::model::AgentTask *task) override
Definition: model.h:988
const api::model::AgentGroup * group() const override
Definition: model.h:846
AgentBase & operator=(const AgentBase &agent)=default
void setGroupId(api::model::GroupId id) override
Definition: model.h:812
void addGroup(api::model::AgentGroup *group) override
Definition: model.h:861
AgentBase(const AgentBase &agent)=default
virtual void act() override
Definition: model.h:1005
const api::model::Model * model() const override
Definition: model.h:947
Definition: model.h:638
Definition: generator.h:322
Generator_t::result_type result_type
Definition: generator.h:345
Definition: distribution.h:24
Definition: scheduler.h:169
Definition: scheduler.h:78
int LayerId
Definition: edge.h:13
int GroupId
Definition: model.h:78
api::utils::PtrWrapper< api::model::Agent > WeakAgentPtr
Definition: model.h:160
std::type_index TypeId
Definition: model.h:82
api::graph::DistributedEdge< AgentPtr > AgentEdge
Definition: model.h:49
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
io::Breakpoint< api::model::Model > Breakpoint
Definition: model.h:1355
api::utils::Callback< AgentNode * > AgentNodeCallback
Definition: model.h:1129
bool operator<(const Neighbor< AgentType > &n1, const Neighbor< AgentType > &n2)
Definition: model.h:185
detail::DefaultModel< SyncMode > Model
Definition: model.h:1314
bool is_agent_in_group(api::model::Agent *agent, api::model::GroupId group_id)
Definition: model.cpp:5
std::string format(std::string input, int rank)
Definition: format.cpp:4
Definition: fpmas.cpp:3
static std::size_t size(const LightObjectPack &pack, const AgentPtr &ptr)
static void to_datapack(LightObjectPack &pack, const AgentPtr &pointer)
static AgentPtr from_datapack(const LightObjectPack &pack)
static std::size_t size(const LightObjectPack &pack, const WeakAgentPtr &ptr)
static void to_datapack(LightObjectPack &pack, const WeakAgentPtr &ptr)
static WeakAgentPtr from_datapack(const LightObjectPack &pack)
Definition: datapack.h:1382
static void to_datapack(ObjectPack &pack, const AgentPtr &pointer)
static AgentPtr from_datapack(const ObjectPack &pack)
static std::size_t size(const ObjectPack &p, const AgentPtr &ptr)
static std::size_t size(const ObjectPack &pack, const WeakAgentPtr &ptr)
static WeakAgentPtr from_datapack(const ObjectPack &pack)
static void to_datapack(ObjectPack &pack, const WeakAgentPtr &ptr)
Definition: datapack.h:55
static void to_json(light_json &j, const fpmas::api::model::AgentPtr &pointer)
static fpmas::api::model::AgentPtr from_json(const light_json &j)
static fpmas::api::model::WeakAgentPtr from_json(const light_json &j)
static void to_json(light_json &j, const fpmas::api::model::WeakAgentPtr &pointer)
Definition: model.h:199
static random::DistributedGenerator rd
Definition: model.h:203
static void seed(random::DistributedGenerator<>::result_type seed)
Definition: model.cpp:17
static void update(api::model::AgentPtr &local_agent, api::model::AgentPtr &&updated_agent)
Definition: model.h:1749
Definition: synchro.h:16
static fpmas::api::model::AgentPtr from_json(const json &j)
static void to_json(json &j, const fpmas::api::model::AgentPtr &pointer)
static fpmas::api::model::WeakAgentPtr from_json(const json &j)
static void to_json(json &j, const fpmas::api::model::WeakAgentPtr &pointer)