forked from Kei18/lacam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
114 lines (96 loc) · 4.29 KB
/
main.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
#include <argparse/argparse.hpp>
#include <chrono>
#include <calmapf.hpp>
int main(int argc, char* argv[])
{
// Set up logger
auto console = spdlog::stderr_color_mt("console");
console->set_level(spdlog::level::info);
// Initialization
// Parser
Parser parser(argc, argv);
// Deadline
auto deadline = Deadline(parser.time_limit_sec * 1000);
// Instance
auto ins = Instance(&parser);
// Log
Log log(&parser);
// Timer
auto timer = std::chrono::steady_clock::now();
auto start = std::chrono::steady_clock::now();
// solving
uint nagents_with_new_goals = 0;
uint makespan = 1;
uint cache_hit = 0;
uint cache_access = 0;
uint batch_idx = 0;
uint throughput_index_cnt = 0;
for (uint i = 0; i < parser.num_goals; i += nagents_with_new_goals) {
batch_idx++;
// info output
auto current_time = std::chrono::steady_clock::now();
auto elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(current_time - timer).count();
if (!parser.debug_log && batch_idx % 100 == 0 && cache_access > 0 && is_cache(parser.cache_type)) {
double cacheRate = static_cast<double>(cache_hit) / cache_access * 100.0;
console->info("Elapsed Time: {:5}ms | Goals Reached: {:5} | Cache Hit Rate: {:2.2f}% | Steps Used: {:5}", elapsed_time, i, cacheRate, makespan);
// Reset the timer
timer = std::chrono::steady_clock::now();
}
else if (!parser.debug_log && batch_idx % 100 == 0 && !is_cache(parser.cache_type)) {
console->info("Elapsed Time: {:5}ms | Goals Reached: {:5} | Steps Used: {:5}", elapsed_time, i, makespan);
// Reset the timer
timer = std::chrono::steady_clock::now();
}
log.make_throughput_log(i, &throughput_index_cnt, makespan);
// Ternimal log
console->debug("--------------------------------------------------------------------------------------------------------------");
console->debug("STEP: {}", makespan);
console->debug("STARTS: {}", ins.starts);
console->debug("GOALS: {}", ins.goals);
// Reset time clock
assert(deadline.reset());
// Get solution
auto solution = solve(ins, &deadline, &parser.MT);
const auto comp_time_ms = deadline.elapsed_ms();
// Failure
if (solution.empty()) {
log.make_csv_log(.0, 0, nullptr, parser.num_goals, elapsed_time, true);
console->error("failed to solve");
return 1;
}
// Update step solution
log.update_solution(solution, ins.bit_status);
// Check feasibility
if (!log.is_feasible_solution(ins)) {
console->error("invalid solution");
return 1;
}
// Statistics
makespan += (solution.size() - 1);
// Post processing
log.print_stats(ins, comp_time_ms);
log.make_step_log(ins, parser.output_step_file, comp_time_ms, parser.map_file, parser.random_seed, parser.short_log_format);
// Assign new goals
if (is_cache(parser.cache_type)) {
nagents_with_new_goals = ins.update_on_reaching_goals_with_cache(solution, parser.num_goals - i, cache_access, cache_hit);
}
else {
nagents_with_new_goals = ins.update_on_reaching_goals_without_cache(solution, parser.num_goals - i);
}
console->debug("Reached Goals: {}", nagents_with_new_goals);
}
// Get percentiles
std::vector<uint> step_percentiles = ins.compute_percentiles();
double total_cache_rate = is_cache(parser.cache_type) ? static_cast<double>(cache_hit) / cache_access * 100.0 : .0;
if (is_cache(parser.cache_type)) {
console->info("Total Goals Reached: {:5} | Total Cache Hit Rate: {:2.2f}% | Makespan: {:5} | P0 Steps: {:5} | P50 Steps: {:5} | P99 Steps: {:5}", parser.num_goals, total_cache_rate, makespan, step_percentiles[0], step_percentiles[2], step_percentiles[6]);
}
else {
console->info("Total Goals Reached: {:5} | Makespan: {:5} | P0 Steps: {:5} | P50 Steps: {:5} | P99 Steps: {:5}", parser.num_goals, makespan, step_percentiles[0], step_percentiles[2], step_percentiles[6]);
}
auto end_time = std::chrono::steady_clock::now();
auto running_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start).count();
log.make_life_long_log(ins, parser.output_visual_file);
log.make_csv_log(total_cache_rate, makespan, &step_percentiles, parser.num_goals, running_time, false);
return 0;
}