-
Notifications
You must be signed in to change notification settings - Fork 412
Expand file tree
/
Copy pathtsp_fix.cpp
More file actions
75 lines (58 loc) · 1.84 KB
/
tsp_fix.cpp
File metadata and controls
75 lines (58 loc) · 1.84 KB
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
/*
This file is part of VROOM.
Copyright (c) 2015-2025, Julien Coupey.
All rights reserved (see LICENSE).
*/
#include "problems/cvrp/operators/tsp_fix.h"
#include "problems/tsp/tsp.h"
namespace vroom::cvrp {
TSPFix::TSPFix(const Input& input,
const utils::SolutionState& sol_state,
RawRoute& s_route,
Index s_vehicle)
// Use dummy 0 values for unused ranks.
: Operator(OperatorName::TSPFix,
input,
sol_state,
s_route,
s_vehicle,
0,
s_route,
s_vehicle,
0),
_s_delivery(source.load_at_step(0)) {
assert(s_route.size() >= 2);
}
void TSPFix::compute_gain() {
std::vector<Index> jobs = s_route;
const TSP tsp(_input, std::move(jobs), s_vehicle);
tsp_route = tsp.raw_solve(1, Timeout());
s_gain = _sol_state.route_evals[s_vehicle] -
utils::route_eval_for_vehicle(_input, s_vehicle, tsp_route);
stored_gain = s_gain;
gain_computed = true;
}
bool TSPFix::is_valid() {
bool valid = is_valid_for_source_range_bounds();
if (valid) {
const RawRoute route(_input, s_vehicle);
valid = route.is_valid_addition_for_capacity_inclusion(_input,
_s_delivery,
tsp_route.begin(),
tsp_route.end(),
0,
0);
}
return valid;
}
void TSPFix::apply() {
s_route = std::move(tsp_route);
source.update_amounts(_input);
}
std::vector<Index> TSPFix::addition_candidates() const {
return {s_vehicle};
}
std::vector<Index> TSPFix::update_candidates() const {
return {s_vehicle};
}
} // namespace vroom::cvrp