Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use insertion ranks bounds for LS operator pruning #696

Merged
merged 35 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6d6dd41
Put all route_costs occurences behind NDEBUG.
jcoupey Jan 20, 2022
12526ce
Template Solution::setup.
jcoupey Jan 20, 2022
0b091a0
First take at storing insertion range based on TW.
jcoupey Jan 20, 2022
4d37573
Update insertion ranks after local search move.
jcoupey Jan 20, 2022
d4178d5
Prune Relocate moves using insertion ranges.
jcoupey Jan 25, 2022
f8a0002
Prune OrOpt moves using insertion ranges.
jcoupey Jan 25, 2022
4772278
Store weaker insertion range constraints based solely on TW.
jcoupey Feb 2, 2022
d496ca0
Set LOG_LS_OPERATORS for now.
jcoupey Feb 2, 2022
c8a3ac2
Prune IntraRelocate moves with weak insertion range.
jcoupey Feb 2, 2022
628fa2d
Prune TwoOpt moves based on weak insertion ranges.
jcoupey Feb 2, 2022
412ea0e
Prune ReverseTwoOpt moves.
jcoupey Feb 2, 2022
6aa1d44
Prune IntraOrOpt moves.
jcoupey Feb 3, 2022
5b369ae
Prune IntraExchange moves.
jcoupey Feb 3, 2022
34a2441
Prune IntraCrossExchange moves.
jcoupey Feb 3, 2022
8f08721
Prune IntraMixedExchange moves.
jcoupey Feb 3, 2022
57a6dff
Prune MixedExchange moves.
jcoupey Feb 4, 2022
2fef434
Prune CrossExchange moves.
jcoupey Feb 8, 2022
ef1fdca
Switch to stronger insertion ranges for CrossExchange.
jcoupey Feb 8, 2022
eb713a1
Switch to stronger insertion ranges for MixedExchange.
jcoupey Feb 15, 2022
99209bb
Additionnal pruning for MixedExchange.
jcoupey Feb 15, 2022
42751ab
Variables adjustments.
jcoupey Feb 16, 2022
102fccf
Rephrase range insertion comments.
jcoupey Feb 16, 2022
e8c9498
Prune UnassignedExchange moves.
jcoupey Feb 16, 2022
fa2dd98
Pass SolutionState to compute_best_insertion_pd.
jcoupey Feb 16, 2022
6e5e91f
Use insertion ranks in compute_best_insertion_pd.
jcoupey Feb 28, 2022
c22aa87
Prune compute_best_insertion.
jcoupey Mar 1, 2022
3430995
Store SwapChoice options in a vector, fixes #682
jcoupey Mar 3, 2022
8e8aaaf
First take at pruning inside SWAP*.
jcoupey Mar 3, 2022
79cf51b
Further pruning inside SWAP*.
jcoupey Mar 3, 2022
28f7832
Pruning based on weak insertion ranks for SWAP*.
jcoupey Mar 4, 2022
fe87ad8
Merge branch 'master' into enhancement/prune-LS
jcoupey Apr 15, 2022
a0143b3
Correct *insertion_ranks* comments.
jcoupey Apr 27, 2022
5c91ce8
Update changelog.
jcoupey Apr 27, 2022
4e5cc5b
Merge branch 'master' into enhancement/prune-LS
jcoupey Apr 27, 2022
730ec05
Remove debug operators logs.
jcoupey May 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

### Changed

- Prune local search moves based on TW constraints (#583)
- Refactor exception class (#639)
- CI builds now run against `libosrm` v5.26.0 (#651)
- Reduce computing time on PDPTW benchmarks by around 20% (#559)
- Change Input and parser signature to simplify downstream usage (#665)
- Consider move options in SWAP* that were previously wrongly discarded (#682)
- Use cxxopts as command line parser instead of getopt (#602)
- Change polylineencoder usage to submodule instead of plain header (#686)

Expand Down
33 changes: 22 additions & 11 deletions src/algorithms/local_search/insertion_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define INSERTION_SEARCH_H

#include "structures/typedefs.h"
#include "structures/vroom/solution_state.h"
#include "utils/helpers.h"

namespace vroom {
Expand All @@ -19,17 +20,21 @@ constexpr RouteInsertion empty_insert = {std::numeric_limits<Gain>::max(),
0};

template <class Route>
RouteInsertion compute_best_insertion_single(const Input& input,
const Index j,
Index v,
const Route& route) {
RouteInsertion
compute_best_insertion_single(const Input& input,
const utils::SolutionState& sol_state,
const Index j,
Index v,
const Route& route) {
RouteInsertion result = empty_insert;
const auto& current_job = input.jobs[j];
const auto& v_target = input.vehicles[v];

if (input.vehicle_ok_with_job(v, j)) {

for (Index rank = 0; rank <= route.size(); ++rank) {
for (Index rank = sol_state.insertion_ranks_begin[v][j];
rank < sol_state.insertion_ranks_end[v][j];
++rank) {
Gain current_cost =
utils::addition_cost(input, j, v_target, route.route, rank);
if (current_cost < result.cost and
Expand Down Expand Up @@ -71,6 +76,7 @@ bool valid_for_capacity(const Input& input,

template <class Route>
RouteInsertion compute_best_insertion_pd(const Input& input,
const utils::SolutionState& sol_state,
const Index j,
Index v,
const Route& route,
Expand All @@ -87,14 +93,16 @@ RouteInsertion compute_best_insertion_pd(const Input& input,

// Pre-compute cost of addition for matching delivery.
std::vector<Gain> d_adds(route.size() + 1);
std::vector<unsigned char> valid_delivery_insertions(route.size() + 1);
std::vector<unsigned char> valid_delivery_insertions(route.size() + 1, false);

const auto begin_d_rank = sol_state.insertion_ranks_begin[v][j + 1];
const auto end_d_rank = sol_state.insertion_ranks_end[v][j + 1];

bool found_valid = false;
for (unsigned d_rank = 0; d_rank <= route.size(); ++d_rank) {
for (unsigned d_rank = begin_d_rank; d_rank < end_d_rank; ++d_rank) {
d_adds[d_rank] =
utils::addition_cost(input, j + 1, v_target, route.route, d_rank);
if (d_adds[d_rank] > result.cost) {

valid_delivery_insertions[d_rank] = false;
} else {
valid_delivery_insertions[d_rank] =
Expand All @@ -108,7 +116,9 @@ RouteInsertion compute_best_insertion_pd(const Input& input,
return result;
}

for (Index pickup_r = 0; pickup_r <= route.size(); ++pickup_r) {
for (Index pickup_r = sol_state.insertion_ranks_begin[v][j];
pickup_r < sol_state.insertion_ranks_end[v][j];
++pickup_r) {
Gain p_add =
utils::addition_cost(input, j, v_target, route.route, pickup_r);
if (p_add > result.cost) {
Expand All @@ -126,8 +136,9 @@ RouteInsertion compute_best_insertion_pd(const Input& input,
// Build replacement sequence for current insertion.
std::vector<Index> modified_with_pd({j});

for (Index delivery_r = pickup_r; delivery_r <= route.size();
++delivery_r) {
// No need to use begin_d_rank here thanks to
// valid_delivery_insertions values.
for (Index delivery_r = pickup_r; delivery_r < end_d_rank; ++delivery_r) {
// Update state variables along the way before potential
// early abort.
if (pickup_r < delivery_r) {
Expand Down
Loading