-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvss_generation_timetable_mip_iterative_vss_testing.cpp
104 lines (91 loc) · 4.01 KB
/
vss_generation_timetable_mip_iterative_vss_testing.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
#include "Definitions.hpp"
#include "VSSModel.hpp"
#include "plog/Init.h"
#include "plog/Logger.h"
#include "plog/Severity.h"
#include "solver/mip-based/VSSGenTimetableSolver.hpp"
#include <cstdlib>
#include <gsl/span>
#include <plog/Appenders/ColorConsoleAppender.h>
#include <plog/Formatters/TxtFormatter.h>
#include <plog/Log.h>
#include <string>
// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay)
int main(int argc, char** argv) {
// Only log to console using std::cerr and std::cout respectively unless
// initialized differently
if (plog::get() == nullptr) {
static plog::ColorConsoleAppender<plog::TxtFormatter> console_appender;
plog::init(plog::debug, &console_appender);
}
if (argc < 12 || argc > 13) {
PLOGE << "Expected 11 or 12 arguments, got " << argc - 1;
std::exit(-1);
}
auto args = gsl::span<char*>(argv, argc);
const std::string model_name = args[1];
const std::string instance_path = args[2];
cda_rail::solver::mip_based::VSSGenTimetableSolver solver(instance_path);
PLOGI << "Instance " << model_name << " loaded at " << instance_path;
const int delta_t = std::stoi(args[3]);
const bool fix_routes = std::stoi(args[4]) != 0;
const bool include_train_dynamics = std::stoi(args[5]) != 0;
const bool include_braking_curves = std::stoi(args[6]) != 0;
const bool use_pwl = std::stoi(args[7]) != 0;
const bool use_schedule_cuts = std::stoi(args[8]) != 0;
const bool iterate_vss = std::stoi(args[9]) != 0;
const int optimality_strategy_int = std::stoi(args[10]);
const auto optimality_strategy =
static_cast<cda_rail::OptimalityStrategy>(optimality_strategy_int);
const int timeout = std::stoi(args[11]);
const std::string output_path = (argc == 13 ? args[12] : "");
PLOGI << "The following parameters were passed to the toolkit:";
PLOGI << " delta_t: " << delta_t;
if (fix_routes) {
PLOGI << " routes are fixed";
}
if (include_train_dynamics) {
PLOGI << " acceleration and deceleration are included";
}
if (include_braking_curves) {
PLOGI << " braking distance is included";
}
if (use_pwl) {
PLOGI << " piecewise linear functions are used";
}
if (use_schedule_cuts) {
PLOGI << " schedule cuts are used";
}
if (iterate_vss) {
PLOGI << " VSS is iterated";
}
if (optimality_strategy == cda_rail::OptimalityStrategy::Optimal) {
PLOGI << " optimality strategy: optimal";
} else if (optimality_strategy == cda_rail::OptimalityStrategy::TradeOff) {
PLOGI << " optimality strategy: trade-off";
} else if (optimality_strategy == cda_rail::OptimalityStrategy::Feasible) {
PLOGI << " optimality strategy: feasible";
} else {
PLOGI << " optimality strategy: unknown";
}
PLOGI << " timeout: " << timeout << "s";
const std::string file_name =
model_name + "_" + std::to_string(delta_t) + "_" +
std::to_string(static_cast<int>(fix_routes)) + "_" +
std::to_string(static_cast<int>(include_train_dynamics)) + "_" +
std::to_string(static_cast<int>(include_braking_curves)) + "_" +
std::to_string(static_cast<int>(use_pwl)) + "_" +
std::to_string(static_cast<int>(use_schedule_cuts)) + "_" +
std::to_string(static_cast<int>(iterate_vss)) + "_" +
std::to_string(static_cast<int>(optimality_strategy_int)) + "_" +
std::to_string(timeout);
const cda_rail::vss::Model vss_model(cda_rail::vss::ModelType::Continuous);
// NOLINTNEXTLINE(clang-diagnostic-unused-result)
solver.solve(
{delta_t, fix_routes, include_train_dynamics, include_braking_curves},
{vss_model, use_pwl, use_schedule_cuts},
{iterate_vss, optimality_strategy},
{false, cda_rail::ExportOption::ExportSolution, file_name, output_path},
timeout, true);
}
// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay)