Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
routing_ils.h
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14#ifndef OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_ILS_H_
15#define OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_ILS_H_
16
17#include <cstddef>
18#include <cstdint>
19#include <functional>
20#include <memory>
21#include <random>
22
25#include "ortools/constraint_solver/routing_parameters.pb.h"
26#include "ortools/util/bitset.h"
27
28namespace operations_research {
29
30// Ruin interface.
32 public:
33 virtual ~RuinProcedure() = default;
34 virtual std::function<int64_t(int64_t)> Ruin(
35 const Assignment* assignment) = 0;
36};
37
38// Remove a number of routes that are spatially close together.
40 public:
41 CloseRoutesRemovalRuinProcedure(RoutingModel* model, size_t num_routes);
42 // Returns next accessors where at most num_routes routes have been shortcut,
43 // i.e., next(shortcut route begin) = shortcut route end.
44 // Next accessors for customers belonging to shortcut routes are still set to
45 // their original value and should not be used.
46 std::function<int64_t(int64_t)> Ruin(const Assignment* assignment) override;
47
48 private:
49 // Returns whether the assignment as at least one performed node.
50 bool HasPerformedNodes(const Assignment* assignment);
51
52 const RoutingModel& model_;
53 const RoutingModel::NodeNeighborsByCostClass* const neighbors_manager_;
54 const size_t num_routes_;
55 std::mt19937 rnd_;
56 std::uniform_int_distribution<int64_t> customer_dist_;
57 SparseBitset<int64_t> removed_routes_;
58};
59
60// Returns a DecisionBuilder implementing a perturbation step of an Iterated
61// Local Search approach.
63 const RoutingSearchParameters& parameters, RoutingModel* model,
64 const Assignment* assignment, std::function<bool()> stop_search,
65 LocalSearchFilterManager* filter_manager);
66
67// Neighbor acceptance criterion interface.
69 public:
70 virtual ~NeighborAcceptanceCriterion() = default;
71 // Returns whether `candidate` should replace `reference`.
72 virtual bool Accept(const Assignment* candidate,
73 const Assignment* reference) const = 0;
74};
75
76// Returns a neighbor acceptance criterion based on the given parameters.
77std::unique_ptr<NeighborAcceptanceCriterion> MakeNeighborAcceptanceCriterion(
78 const RoutingSearchParameters& parameters);
79
80} // namespace operations_research
81
82#endif // OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_ILS_H_
Remove a number of routes that are spatially close together.
Definition routing_ils.h:39
CloseRoutesRemovalRuinProcedure(RoutingModel *model, size_t num_routes)
std::function< int64_t(int64_t)> Ruin(const Assignment *assignment) override
Neighbor acceptance criterion interface.
Definition routing_ils.h:68
virtual bool Accept(const Assignment *candidate, const Assignment *reference) const =0
Returns whether candidate should replace reference.
virtual std::function< int64_t(int64_t)> Ruin(const Assignment *assignment)=0
SatParameters parameters
GRBmodel * model
In SWIG mode, we don't want anything besides these top-level includes.
std::unique_ptr< NeighborAcceptanceCriterion > MakeNeighborAcceptanceCriterion(const RoutingSearchParameters &parameters)
Returns a neighbor acceptance criterion based on the given parameters.
DecisionBuilder * MakePerturbationDecisionBuilder(const RoutingSearchParameters &parameters, RoutingModel *model, const Assignment *assignment, std::function< bool()> stop_search, LocalSearchFilterManager *filter_manager)