fpmas 1.6
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"
18#include <fstream>
19
20
21namespace fpmas { namespace model {
22
27 bool is_agent_in_group(api::model::Agent* agent, api::model::GroupId group_id);
28
32 bool is_agent_in_group(api::model::Agent* agent, api::model::AgentGroup& group);
33
42 template<typename AgentType>
43 class Neighbor {
44 private:
45 AgentPtr* _agent;
46 AgentEdge* _edge;
47
48 public:
62 Neighbor() : Neighbor(nullptr, nullptr) {}
63
71 HEDLEY_DEPRECATED_FOR(1.1, Neighbor(AgentPtr*, AgentEdge*))
73 : Neighbor(agent, nullptr) {}
74
82 : _agent(agent), _edge(edge) {}
83
87 operator AgentType*() const {
88 return static_cast<AgentType*>(_agent->get());
89 }
90
96 AgentType* operator->() const {
97 return static_cast<AgentType*>(_agent->get());
98 }
99
105 AgentType& operator*() const {
106 return *static_cast<AgentType*>(_agent->get()); }
107
114 AgentEdge* edge() const {
115 return _edge;
116 }
117
124 AgentType* agent() const {
125 if(_agent == nullptr)
126 return nullptr;
127 return static_cast<AgentType*>(_agent->get());
128 }
129 };
130
143 template<typename AgentType, typename Compare = std::less<AgentType>>
145 private:
146 Compare compare;
147 public:
148 CompareNeighbors() = default;
149
153 CompareNeighbors(const Compare& compare) : compare(compare) {
154 }
155
160 const Neighbor<AgentType>& n1,
161 const Neighbor<AgentType>& n2) const {
162 return compare(*n1.agent(), *n2.agent());
163 }
164 };
165
185 template<typename AgentType>
187 return *n1.agent() < *n2.agent();
188 }
189
205
212 };
213
225 template<typename AgentType>
226 class Neighbors {
227 private:
228 typedef typename std::vector<Neighbor<AgentType>>::iterator iterator;
229 typedef typename std::vector<Neighbor<AgentType>>::const_iterator const_iterator;
230 std::vector<Neighbor<AgentType>> neighbors;
231
232 public:
233 Neighbors() = default;
234
240 Neighbors(const std::vector<Neighbor<AgentType>>& neighbors)
241 : neighbors(neighbors) {}
242
248 iterator begin() {
249 return neighbors.begin();
250 }
256 const_iterator begin() const {
257 return neighbors.begin();
258 }
259
265 iterator end() {
266 return neighbors.end();
267 }
268
274 const_iterator end() const {
275 return neighbors.end();
276 }
277
283 std::size_t count() const {
284 return neighbors.size();
285 }
286
292 bool empty() const {
293 return neighbors.empty();
294 }
295
304 Neighbor<AgentType>& at(std::size_t i) {
305 try {
306 return neighbors.at(i);
307 } catch(const std::out_of_range&) {
308 throw;
309 }
310 }
311
315 const Neighbor<AgentType>& at(std::size_t i) const {
316 try {
317 return neighbors.at(i);
318 } catch(const std::out_of_range&) {
319 throw;
320 }
321 }
322
330 return neighbors[i];
331 }
332
336 const Neighbor<AgentType>& operator[](std::size_t i) const {
337 return neighbors[i];
338 }
339
349 template<typename Gen>
350 Neighbors& shuffle(Gen& gen) {
351 std::shuffle(neighbors.begin(), neighbors.end(), gen);
352 return *this;
353 }
354
365 }
366
398 template<typename Compare = std::less<AgentType>>
399 Neighbors& sort(Compare comp = Compare()) {
400 std::sort(
401 neighbors.begin(), neighbors.end(),
403 );
404 return *this;
405 }
406
417 template<typename Filter>
418 Neighbors& filter(Filter _filter) {
419 neighbors.erase(
420 std::remove_if(
421 neighbors.begin(), neighbors.end(),
422 [&_filter] (const Neighbor<AgentType>& agent) {return !_filter(agent);}),
423 neighbors.end()
424 );
425 return *this;
426 }
427
436 template<typename Gen>
439 0, this->count()-1);
440 return neighbors[index(gen)];
441 }
442
453 }
454
458 template<typename Gen>
459 const Neighbor<AgentType> random(Gen& gen) const {
461 0, this->count()-1);
462 return neighbors[index(gen)];
463 }
464
470 }
471 };
472
479 template<typename AgentType>
481 private:
482 std::vector<void(AgentType::*)()> _behaviors;
483
484 template<typename T, typename Enable=void>
485 struct AutoAgentCast {
486 static T* cast(api::model::Agent* agent) {
487 return dynamic_cast<T*>(agent);
488 }
489 };
490
491 template<typename T>
492 struct AutoAgentCast<T, typename std::enable_if<
493 std::is_base_of<api::model::Agent, T>::value
494 >::type> {
495 static T* cast(api::model::Agent* agent) {
496 return static_cast<T*>(agent);
497 }
498 };
499
500 public:
551 template<typename ...T>
552 Behavior(T... behaviors)
553 : _behaviors({behaviors...}){
554 }
555
556 void execute(api::model::Agent* agent) const {
557 for(auto behavior : this->_behaviors)
558 (AutoAgentCast<AgentType>::cast(agent)->*behavior)();
559 }
560 };
561
571 template<typename AgentType, typename ... Args>
573 private:
574 void (AgentType::* behavior)(Args...);
575 std::tuple<Args...> args;
576
577 // helpers for tuple unrolling
578 // From: https://riptutorial.com/cplusplus/example/24746/storing-function-arguments-in-std--tuple
579 template<int ...> struct seq {};
580 template<int N, int ...S> struct gens {
581 public:
582 typedef typename gens<N-1, N-1, S...>::type type;
583 };
584 template<int ...S> struct gens<0, S...>{ typedef seq<S...> type; };
585
586 // invocation helper
587 template<int ...S>
588 void call_fn_internal(api::model::Agent* agent, const seq<S...>) const
589 {
590 (dynamic_cast<AgentType*>(agent)->*behavior)(std::get<S>(args) ...);
591 }
592
593 public:
602 void (AgentType::* behavior)(Args...),
603 Args... args)
604 : behavior(behavior), args(args...) {}
605
612 void execute(api::model::Agent* agent) const override {
613 return call_fn_internal(agent, typename gens<sizeof...(Args)>::type());
614 }
615 };
616
621 void execute(api::model::Agent*) const override {
622 }
623 };
624
625 namespace detail {
721 template<typename AgentInterface, typename AgentType, typename TypeIdBase = AgentType>
722 class AgentBase : public AgentInterface {
723 public:
732 typedef AgentType FinalAgentType;
733
734 private:
735 std::vector<api::model::GroupId> group_ids;
736 std::vector<api::model::AgentGroup*> _groups;
737 std::unordered_map<
738 api::model::GroupId, std::list<api::model::Agent*>::iterator
739 > group_pos;
740 std::unordered_map<api::model::GroupId, api::model::AgentTask*> _tasks;
742 api::model::Model* _model;
743
744 public:
748 AgentBase() = default;
749
764 AgentBase(const AgentBase& agent) = default;
765
780 AgentBase& operator=(const AgentBase& agent) = default;
781
782 // Move constructor and assignment preserve groupIds(), groups(),
783 // group_pos, tasks(), node() and model()
784
799 AgentBase(AgentBase&&) = default;
800
814 return *this;
815 }
816
820 GroupId groupId() const override {
821 if(group_ids.size() > 0)
822 return group_ids.back();
823 return {};
824 }
828 std::vector<GroupId> groupIds() const override {return group_ids;}
832 void setGroupId(api::model::GroupId id) override {
833 group_ids.push_back(id);}
837 void addGroupId(api::model::GroupId id) override {
838 group_ids.push_back(id);
839 }
840
845 group_ids.erase(std::remove(group_ids.begin(), group_ids.end(), id));
846 }
847
852 if(_groups.size() > 0)
853 return _groups.back();
854 return nullptr;
855 }
859 std::vector<const api::model::AgentGroup*> groups() const override {
860 return {_groups.begin(), _groups.end()};
861 }
862
866 const api::model::AgentGroup* group() const override {return _groups.back();}
870 std::vector<api::model::AgentGroup*> groups() override {return _groups;}
871
876 _groups.push_back(group);
877 }
882 _groups.push_back(group);
883 }
884
889 _groups.erase(std::remove(_groups.begin(), _groups.end(), group));
890 _tasks.erase(group->groupId());
891 }
892
898 std::list<api::model::Agent*>::iterator pos
899 ) override {
900 group_pos[gid] = pos;
901 }
902
906 std::list<api::model::Agent*>::iterator getGroupPos(api::model::GroupId gid) const override {
907 return group_pos.find(gid)->second;
908 }
909
913 api::model::TypeId typeId() const override {return TYPE_ID;}
917 api::model::Agent* copy() const override {
918 return new AgentType(*static_cast<const AgentType*>(this));
919 }
920
924 void copyAssign(api::model::Agent* agent) override {
925 // Uses AgentType copy assignment operator
926 *static_cast<AgentType*>(this) = *static_cast<const AgentType*>(agent);
927 }
928
932 void moveAssign(api::model::Agent* agent) override {
933
934 // Uses AgentType move assignment operator
935 //
936 // groupIds(), groups(), tasks(), node() and model() are
937 // notably moved from agent to this, but this as no effect
938 // considering the move assignment operator defined above. In
939 // consequence, those fields are properly preserved, as
940 // required by the method.
941 // If AgentType only explicitly defines a move assignment
942 // operator, it should not call the AgentBase move assignment
943 // so there should not be any problem.
944 *static_cast<AgentType*>(this) = std::move(*static_cast<AgentType*>(agent));
945 }
946
950 api::model::AgentNode* node() override {return _node;}
954 const api::model::AgentNode* node() const override {return _node;}
958 void setNode(api::model::AgentNode* node) override {_node = node;}
959
963 api::model::Model* model() override {return _model;}
967 const api::model::Model* model() const override {return _model;}
971 void setModel(api::model::Model* model) override {_model = model;}
972
977 return _tasks.find(this->groupId())->second;
978 }
982 const api::model::AgentTask* task() const override {
983 return _tasks.find(this->groupId())->second;
984 }
989 _tasks[this->groupId()] = task;
990 }
991
996 assert(_tasks.count(id) > 0);
997 return _tasks.find(id)->second;
998 }
1003 return _tasks.find(id)->second;}
1004
1009 _tasks[id] = task;
1010 }
1011
1015 const std::unordered_map<api::model::GroupId, api::model::AgentTask*>&
1016 tasks() override { return _tasks;}
1017
1018
1025 virtual void act() override {}
1026
1040 template<typename NeighborAgentType> Neighbors<NeighborAgentType> outNeighbors() const {
1041 std::vector<Neighbor<NeighborAgentType>> out;
1042 auto edges = node()->getOutgoingEdges();
1043 out.reserve(edges.size());
1044 for(api::model::AgentEdge* _edge : edges) {
1045 api::model::AgentNode* _node = _edge->getTargetNode();
1046 if(NeighborAgentType* neighbor = dynamic_cast<NeighborAgentType*>(_node->data().get())) {
1047 out.emplace_back(&_node->data(), _edge);
1048 }
1049 }
1050 return out;
1051 }
1052
1066 template<typename NeighborAgentType> Neighbors<NeighborAgentType> outNeighbors(api::graph::LayerId layer) const {
1067 std::vector<Neighbor<NeighborAgentType>> out;
1068 auto edges = node()->getOutgoingEdges(layer);
1069 out.reserve(edges.size());
1070 for(api::model::AgentEdge* _edge : edges) {
1071 api::model::AgentNode* _node = _edge->getTargetNode();
1072 if(NeighborAgentType* neighbor = dynamic_cast<NeighborAgentType*>(_node->data().get())) {
1073 out.emplace_back(&_node->data(), _edge);
1074 }
1075 }
1076 return out;
1077 }
1078
1079
1093 template<typename NeighborAgentType> Neighbors<NeighborAgentType> inNeighbors() const {
1094 std::vector<Neighbor<NeighborAgentType>> in;
1095 auto edges = node()->getIncomingEdges();
1096 in.reserve(edges.size());
1097 for(api::model::AgentEdge* _edge : edges) {
1098 api::model::AgentNode* _node = _edge->getSourceNode();
1099 if(NeighborAgentType* neighbor = dynamic_cast<NeighborAgentType*>(_node->data().get())) {
1100 in.emplace_back(&_node->data(), _edge);
1101 }
1102 }
1103 return in;
1104 }
1105
1119 template<typename NeighborAgentType> Neighbors<NeighborAgentType> inNeighbors(api::graph::LayerId layer) const {
1120 std::vector<Neighbor<NeighborAgentType>> in;
1121 auto edges = node()->getIncomingEdges(layer);
1122 in.reserve(edges.size());
1123 for(api::model::AgentEdge* _edge : edges) {
1124 api::model::AgentNode* _node = _edge->getSourceNode();
1125 if(NeighborAgentType* neighbor = dynamic_cast<NeighborAgentType*>(_node->data().get())) {
1126 in.emplace_back(&_node->data(), _edge);
1127 }
1128 }
1129 return in;
1130 }
1131
1132 virtual ~AgentBase() {}
1133 };
1139 template<typename AgentInterface, typename AgentType, typename TypeIdBase>
1141 }
1142
1151 template<typename AgentType, typename TypeIdBase = AgentType>
1153
1158
1168 private:
1170 std::vector<api::model::Agent*> agents;
1171
1172 public:
1179 : group(group) {}
1180
1188 agents.push_back(agent);
1189 }
1190
1203
1209 std::size_t nodeCount() override {
1210 return agents.size();
1211 }
1212 };
1222 private:
1223 std::function<api::model::Agent*()> allocator;
1224 std::function<api::model::Agent*()> distant_allocator;
1225 api::model::GroupList groups;
1226
1227 public:
1267 const api::model::GroupList& groups,
1268 std::size_t agent_count,
1269 std::function<api::model::Agent*()> allocator,
1271
1315 const api::model::GroupList& groups,
1316 std::size_t agent_count,
1317 std::function<api::model::Agent*()> allocator,
1318 std::function<api::model::Agent*()> distant_allocator,
1320
1321
1327
1334 int location,
1336 };
1337
1341 template<template<typename> class SyncMode>
1343
1345
1356
1362
1368
1379
1385
1391
1396
1404 private:
1405 std::string file_format;
1406 std::fstream stream;
1408 api::model::Model& model;
1409 scheduler::detail::LambdaTask task {[this] () {
1410 stream.open(utils::format(
1411 file_format,
1412 model.getMpiCommunicator().getRank(),
1413 model.runtime().currentDate()
1414 ), std::ios_base::out);
1415 breakpoint.dump(stream, model);
1416 stream.close();
1417 }};
1418 scheduler::Job _job {{task}};
1419
1420 public:
1442 std::string file_format,
1444 api::model::Model& model)
1445 : file_format(file_format), breakpoint(breakpoint), model(model) {
1446 }
1447
1453 const api::scheduler::Job& job() const {return _job;}
1454 };
1455}}
1456
1457namespace fpmas { namespace io { namespace json {
1458
1468 template<>
1495 static void to_json(light_json& j, const
1497
1525 };
1526
1536 template<>
1541 static void to_json(light_json& j, const
1543
1544
1552 };
1553}}}
1554
1555namespace fpmas { namespace io { namespace datapack {
1556 using api::model::AgentPtr;
1558
1568 template<>
1574 static std::size_t size(const ObjectPack& p, const AgentPtr& ptr);
1575
1583 static void to_datapack(ObjectPack& pack, const AgentPtr& pointer);
1584
1598 static AgentPtr from_datapack(const ObjectPack& pack);
1599 };
1600
1615 template<>
1621 static std::size_t size(const ObjectPack& pack, const WeakAgentPtr& ptr);
1622
1626 static void to_datapack(ObjectPack& pack, const WeakAgentPtr& ptr);
1627
1634 };
1635
1645 template<>
1657 static std::size_t size(const LightObjectPack& pack, const AgentPtr& ptr);
1658
1681 static void to_datapack(LightObjectPack& pack, const AgentPtr& pointer);
1682
1713 };
1714
1729 template<>
1735 static std::size_t size(const LightObjectPack& pack, const WeakAgentPtr& ptr);
1736
1740 static void to_datapack(LightObjectPack& pack, const WeakAgentPtr& ptr);
1741
1749 };
1750}}}
1751
1752namespace fpmas { namespace synchro {
1759 template<>
1789 static void update(
1790 api::model::AgentPtr& local_agent,
1791 api::model::AgentPtr&& updated_agent) {
1792 // TODO: this should probably be improved in 2.0
1793 // The purpose of "moveAssign" is clearly inconsistent with its
1794 // current behavior, that does much more that just "moving" the
1795 // agent.
1796
1797 // Sets and overrides the fields that must be preserved
1798 std::set<api::model::GroupId> local_ids;
1799 for(auto id : local_agent->groupIds())
1800 local_ids.insert(id);
1801 std::set<api::model::GroupId> updated_ids;
1802 for(auto id : updated_agent->groupIds())
1803 updated_ids.insert(id);
1804
1805 std::vector<api::model::GroupId> new_groups;
1806 for(auto id : updated_ids)
1807 if(local_ids.count(id) == 0)
1808 new_groups.push_back(id);
1809
1810 std::vector<api::model::GroupId> obsolete_groups;
1811 for(auto id : local_ids)
1812 if(updated_ids.count(id) == 0)
1813 obsolete_groups.push_back(id);
1814
1815 local_agent = std::move(updated_agent);
1816
1817 // Dynamically updates groups lists
1818 // If `agent` was added to / removed from group on a distant
1819 // process for example (assuming that this agent is DISTANT),
1820 // this agent representation groups are updated.
1821 for(auto id : new_groups)
1822 local_agent->model()->getGroup(id).add(local_agent.get());
1823 for(auto id : obsolete_groups)
1824 local_agent->model()->getGroup(id).remove(local_agent.get());
1825
1826 }
1827 };
1828}}
1829
1830namespace nlohmann {
1839 template<>
1840 struct adl_serializer<fpmas::api::model::AgentPtr> {
1852 static void to_json(json& j, const fpmas::api::model::AgentPtr& pointer);
1853
1868 };
1869
1879 template<>
1880 struct adl_serializer<fpmas::api::model::WeakAgentPtr> {
1881
1885 static void to_json(json& j, const fpmas::api::model::WeakAgentPtr& pointer);
1886
1893 };
1894
1898 template<>
1899 struct adl_serializer<fpmas::api::model::Model> {
1911 static void to_json(json& j, const fpmas::api::model::Model& model);
1912
1925 static void from_json(const json& j, fpmas::api::model::Model& model);
1926 };
1927}
1928#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
virtual const std::vector< EdgeType * > getIncomingEdges() const =0
virtual const std::vector< EdgeType * > getOutgoingEdges() const =0
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:351
Definition: graph_builder.h:24
Definition: uniform_graph_builder.h:150
Definition: random_load_balancing.h:27
Definition: ring_graph_builder.h:55
Definition: scheduled_load_balancing.h:25
Definition: small_world_graph_builder.h:60
Definition: static_load_balancing.h:22
Definition: zoltan_load_balancing.h:419
Definition: breakpoint.h:26
Definition: datapack.h:301
Definition: model.h:1167
std::size_t nodeCount() override
Definition: model.h:1209
AgentNodeBuilder(api::model::AgentGroup &group)
Definition: model.h:1178
void push(api::model::Agent *agent)
Definition: model.h:1187
api::model::AgentNode * buildNode(api::graph::DistributedGraph< AgentPtr > &) override
Definition: model.cpp:22
Definition: model.h:1403
AutoBreakpoint(std::string file_format, api::io::Breakpoint< api::model::Model > &breakpoint, api::model::Model &model)
Definition: model.h:1441
const api::scheduler::Job & job() const
Definition: model.h:1453
Definition: model.h:572
void execute(api::model::Agent *agent) const override
Definition: model.h:612
BehaviorWithArgs(void(AgentType::*behavior)(Args...), Args... args)
Definition: model.h:601
Definition: model.h:480
Behavior(T... behaviors)
Definition: model.h:552
void execute(api::model::Agent *agent) const
Definition: model.h:556
Definition: model.h:144
CompareNeighbors(const Compare &compare)
Definition: model.h:153
bool operator()(const Neighbor< AgentType > &n1, const Neighbor< AgentType > &n2) const
Definition: model.h:159
api::model::AgentNode * buildDistantNode(api::graph::DistributedId id, int location, api::graph::DistributedGraph< AgentPtr > &graph) override
Definition: model.cpp:68
DistributedAgentNodeBuilder(const api::model::GroupList &groups, std::size_t agent_count, std::function< api::model::Agent *()> allocator, api::communication::MpiCommunicator &comm)
Definition: model.cpp:32
api::model::AgentNode * buildNode(api::graph::DistributedGraph< AgentPtr > &graph) override
Definition: model.cpp:57
Definition: model.h:620
Definition: model.h:43
Neighbor(AgentPtr *agent, AgentEdge *edge)
Definition: model.h:81
AgentType * operator->() const
Definition: model.h:96
AgentEdge * edge() const
Definition: model.h:114
AgentType & operator*() const
Definition: model.h:105
AgentType * agent() const
Definition: model.h:124
Neighbor()
Definition: model.h:62
Definition: model.h:226
const Neighbor< AgentType > & at(std::size_t i) const
Definition: model.h:315
Neighbor< AgentType > & operator[](std::size_t i)
Definition: model.h:329
bool empty() const
Definition: model.h:292
Neighbors & shuffle(Gen &gen)
Definition: model.h:350
const_iterator end() const
Definition: model.h:274
iterator begin()
Definition: model.h:248
Neighbor< AgentType > random()
Definition: model.h:451
const Neighbor< AgentType > random() const
Definition: model.h:468
Neighbor< AgentType > random(Gen &gen)
Definition: model.h:437
const Neighbor< AgentType > random(Gen &gen) const
Definition: model.h:459
std::size_t count() const
Definition: model.h:283
Neighbor< AgentType > & at(std::size_t i)
Definition: model.h:304
Neighbors & sort(Compare comp=Compare())
Definition: model.h:399
Neighbors & shuffle()
Definition: model.h:363
const Neighbor< AgentType > & operator[](std::size_t i) const
Definition: model.h:336
iterator end()
Definition: model.h:265
Neighbors & filter(Filter _filter)
Definition: model.h:418
Neighbors(const std::vector< Neighbor< AgentType > > &neighbors)
Definition: model.h:240
const_iterator begin() const
Definition: model.h:256
Definition: model.h:722
api::model::AgentTask * task(api::model::GroupId id) override
Definition: model.h:995
void copyAssign(api::model::Agent *agent) override
Definition: model.h:924
static const api::model::TypeId TYPE_ID
Definition: model.h:724
AgentBase & operator=(AgentBase &&)
Definition: model.h:813
Neighbors< NeighborAgentType > inNeighbors() const
Definition: model.h:1093
void setNode(api::model::AgentNode *node) override
Definition: model.h:958
void removeGroupId(api::model::GroupId id) override
Definition: model.h:844
const std::unordered_map< api::model::GroupId, api::model::AgentTask * > & tasks() override
Definition: model.h:1016
void setGroupPos(api::model::GroupId gid, std::list< api::model::Agent * >::iterator pos) override
Definition: model.h:896
api::model::TypeId typeId() const override
Definition: model.h:913
api::model::AgentGroup * group() override
Definition: model.h:851
api::model::Agent * copy() const override
Definition: model.h:917
GroupId groupId() const override
Definition: model.h:820
const api::model::AgentNode * node() const override
Definition: model.h:954
void addGroupId(api::model::GroupId id) override
Definition: model.h:837
AgentBase(AgentBase &&)=default
std::vector< const api::model::AgentGroup * > groups() const override
Definition: model.h:859
void setModel(api::model::Model *model) override
Definition: model.h:971
std::vector< api::model::AgentGroup * > groups() override
Definition: model.h:870
api::model::AgentNode * node() override
Definition: model.h:950
api::model::Model * model() override
Definition: model.h:963
Neighbors< NeighborAgentType > inNeighbors(api::graph::LayerId layer) const
Definition: model.h:1119
std::vector< GroupId > groupIds() const override
Definition: model.h:828
const api::model::AgentTask * task() const override
Definition: model.h:982
Neighbors< NeighborAgentType > outNeighbors(api::graph::LayerId layer) const
Definition: model.h:1066
void removeGroup(api::model::AgentGroup *group) override
Definition: model.h:888
void setTask(api::model::AgentTask *task) override
Definition: model.h:988
void setGroup(api::model::AgentGroup *group) override
Definition: model.h:875
std::list< api::model::Agent * >::iterator getGroupPos(api::model::GroupId gid) const override
Definition: model.h:906
AgentType FinalAgentType
Definition: model.h:732
api::model::AgentTask * task() override
Definition: model.h:976
const api::model::AgentTask * task(api::model::GroupId id) const override
Definition: model.h:1002
void moveAssign(api::model::Agent *agent) override
Definition: model.h:932
Neighbors< NeighborAgentType > outNeighbors() const
Definition: model.h:1040
void setTask(api::model::GroupId id, api::model::AgentTask *task) override
Definition: model.h:1008
const api::model::AgentGroup * group() const override
Definition: model.h:866
AgentBase & operator=(const AgentBase &agent)=default
void setGroupId(api::model::GroupId id) override
Definition: model.h:832
void addGroup(api::model::AgentGroup *group) override
Definition: model.h:881
AgentBase(const AgentBase &agent)=default
virtual void act() override
Definition: model.h:1025
const api::model::Model * model() const override
Definition: model.h:967
Definition: model.h:638
Definition: generator.h:322
Generator_t::result_type result_type
Definition: generator.h:359
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
std::vector< std::reference_wrapper< AgentGroup > > GroupList
Definition: model.h:833
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:1395
api::utils::Callback< AgentNode * > AgentNodeCallback
Definition: model.h:1157
bool operator<(const Neighbor< AgentType > &n1, const Neighbor< AgentType > &n2)
Definition: model.h:186
detail::DefaultModel< SyncMode > Model
Definition: model.h:1342
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:1411
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:200
static random::DistributedGenerator rd
Definition: model.h:204
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:1789
Definition: synchro.h:20
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)