Skip to content

Commit

Permalink
Add missing max_travel_time check in initial_routes, fixes #954.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoupey committed Aug 4, 2023
1 parent 890f5e8 commit 1a7120d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Comparison of index-based and coordinates-based locations (#935)
- `max_travel_time` parameter not taken into account in edge case (#884)
- Meaningless `location_index` provided in output for break steps (#877)
- `max_travel_time` not accounted for with vehicle steps in solving mode (#954)

## [v1.13.0] - 2023-01-31

Expand Down
29 changes: 26 additions & 3 deletions src/algorithms/heuristics/heuristics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,13 @@ template <class T> T initial_routes(const Input& input) {
std::to_string(vehicle.id) + ".");
}

// Startup load is the sum of deliveries for (single) jobs.
// Track load and travel time during the route for validity.
Amount current_load = single_jobs_deliveries;
Eval eval_sum;
std::optional<Index> previous_index;
if (vehicle.has_start()) {
previous_index = vehicle.start.value().index();
}

std::vector<Index> job_ranks;
job_ranks.reserve(vehicle.steps.size());
Expand All @@ -930,6 +935,13 @@ template <class T> T initial_routes(const Input& input) {
std::to_string(job.id) + ".");
}

// Update current travel time.
if (previous_index.has_value()) {
eval_sum += vehicle.eval(previous_index.value(), job.index());
}
previous_index = job.index();

// Handle load.
assert(step.job_type.has_value());
switch (step.job_type.value()) {
case JOB_TYPE::SINGLE: {
Expand Down Expand Up @@ -963,6 +975,17 @@ template <class T> T initial_routes(const Input& input) {
}
}

if (vehicle.has_end() and !job_ranks.empty()) {
// Update with last route leg.
assert(previous_index.has_value());
eval_sum +=
vehicle.eval(previous_index.value(), vehicle.end.value().index());
}
if (!vehicle.ok_for_travel_time(eval_sum.duration)) {
throw InputException("Route over max_travel_time for vehicle " +
std::to_string(vehicle.id) + ".");
}

if (vehicle.max_tasks < job_ranks.size()) {
throw InputException("Too many tasks for vehicle " +
std::to_string(vehicle.id) + ".");
Expand All @@ -973,8 +996,8 @@ template <class T> T initial_routes(const Input& input) {
std::to_string(vehicle.id) + ".");
}

// Now route is OK with regard to capacity, precedence and skills
// constraints.
// Now route is OK with regard to capacity, max_travel_time,
// max_tasks, precedence and skills constraints.
if (!job_ranks.empty()) {
if (!current_r.is_valid_addition_for_tw(input,
single_jobs_deliveries,
Expand Down

0 comments on commit 1a7120d

Please sign in to comment.