-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_model.cpp
152 lines (140 loc) · 4.28 KB
/
run_model.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "fpmas.h"
#include "metamodel.h"
#include "fpmas/model/spatial/cell_load_balancing.h"
#include "CLI/App.hpp"
#include "CLI/Formatter.hpp"
#include "CLI/Config.hpp"
#include "yaml-cpp/node/parse.h"
FPMAS_BASE_DATAPACK_SET_UP(
GridCell::JsonBase,
GraphCell::JsonBase,
MetaGridAgent::JsonBase,
MetaGridCell::JsonBase,
MetaGraphCell::JsonBase,
MetaGraphAgent::JsonBase
);
FPMAS_BASE_JSON_SET_UP(
GridCell::JsonBase,
GraphCell::JsonBase,
MetaGridAgent::JsonBase,
MetaGridCell::JsonBase,
MetaGraphCell::JsonBase,
MetaGraphAgent::JsonBase
);
using namespace fpmas::synchro;
int main(int argc, char** argv) {
FPMAS_REGISTER_AGENT_TYPES(
GridCell::JsonBase,
GraphCell::JsonBase,
MetaGridAgent::JsonBase,
MetaGridCell::JsonBase,
MetaGraphCell::JsonBase,
MetaGraphAgent::JsonBase
);
CLI::App app("fpmas-metamodel");
std::string config_file;
app.add_option("config_file", config_file, "Metamodel YAML configuration file")
->required();
unsigned long seed = fpmas::random::default_seed;
app.add_option("-s,--seed", seed, "Random seed");
CLI11_PARSE(app, argc, argv);
fpmas::seed(seed);
random_interactions.seed(seed);
fpmas::init(argc, argv);
{
ModelConfig config(YAML::LoadFile(config_file));
if(!config.is_valid)
return EXIT_FAILURE;
MetaModelFactory model_factory(config.environment, config.sync_mode);
for(auto test_case : config.test_cases) {
for(auto lb_period : test_case.lb_periods) {
fpmas::scheduler::Scheduler scheduler;
fpmas::runtime::Runtime runtime(scheduler);
switch(test_case.algorithm) {
case LbAlgorithm::ZOLTAN_LB:
{
ZoltanLoadBalancing zoltan_lb(
fpmas::communication::WORLD, lb_period, config.zoltan_imbalance_tol);
BasicMetaModel* model = model_factory.build(
"zoltan_lb-" + std::to_string(lb_period), config,
scheduler, runtime, zoltan_lb, lb_period
);
model->init()->run();
delete model;
}
break;
case LbAlgorithm::SCHEDULED_LB:
{
ZoltanLoadBalancing zoltan_lb(
fpmas::communication::WORLD, lb_period, config.zoltan_imbalance_tol);
ScheduledLoadBalancing scheduled_load_balancing(
zoltan_lb, scheduler, runtime
);
BasicMetaModel* model = model_factory.build(
"scheduled_lb-" + std::to_string(lb_period), config,
scheduler, runtime, scheduled_load_balancing,
lb_period
);
model->init()->run();
delete model;
}
break;
case LbAlgorithm::GRID_LB:
{
GridLoadBalancing grid_lb(
config.grid_width, config.grid_height,
fpmas::communication::WORLD
);
BasicMetaModel* model = model_factory.build(
"grid_lb-" + std::to_string(lb_period), config,
scheduler, runtime, grid_lb, lb_period
);
model->init()->run();
delete model;
}
break;
case LbAlgorithm::ZOLTAN_CELL_LB:
{
ZoltanLoadBalancing zoltan_lb(
fpmas::communication::WORLD, lb_period, config.zoltan_imbalance_tol);
CellLoadBalancing zoltan_cell_lb(
fpmas::communication::WORLD, zoltan_lb
);
BasicMetaModel* model = model_factory.build(
"zoltan_cell_lb-" + std::to_string(lb_period), config,
scheduler, runtime, zoltan_cell_lb, lb_period
);
model->init()->run();
delete model;
}
break;
case LbAlgorithm::STATIC_ZOLTAN_CELL_LB:
{
ZoltanLoadBalancing zoltan_lb(
fpmas::communication::WORLD, lb_period, config.zoltan_imbalance_tol);
StaticCellLoadBalancing static_cell_lb(fpmas::communication::WORLD, zoltan_lb);
BasicMetaModel* model = model_factory.build(
"static_zoltan_cell_lb-" + std::to_string(lb_period), config,
scheduler, runtime, static_cell_lb, lb_period
);
model->init()->run();
delete model;
}
break;
case LbAlgorithm::RANDOM_LB:
{
RandomLoadBalancing random_lb(fpmas::communication::WORLD);
BasicMetaModel* model = model_factory.build(
"random_lb-" + std::to_string(lb_period), config,
scheduler, runtime, random_lb, lb_period
);
model->init()->run();
delete model;
}
break;
}
}
}
}
fpmas::finalize();
}