14#ifndef OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_INSERTION_LNS_H_
15#define OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_INSERTION_LNS_H_
24#include "absl/log/check.h"
25#include "absl/strings/str_cat.h"
42 std::unique_ptr<RoutingFilteredHeuristic> heuristic,
43 bool keep_inverse_values =
false);
54 std::string heuristic_name = heuristic_->DebugString();
55 const int erase_pos = heuristic_name.find(
"FilteredHeuristic");
56 if (erase_pos != std::string::npos) {
57 const int expected_name_size = heuristic_name.size() - 17;
58 heuristic_name.erase(erase_pos);
61 DCHECK_EQ(heuristic_name.size(), expected_name_size);
63 return heuristic_name;
74 bool MakeOneNeighbor()
override;
75 bool MakeChangesAndInsertNodes();
77 int64_t VehicleVarIndex(int64_t node)
const {
return model_->Size() + node; }
79 const std::unique_ptr<RoutingFilteredHeuristic> heuristic_;
80 const bool consider_vehicle_vars_;
89 std::unique_ptr<RoutingFilteredHeuristic> heuristic);
93 return absl::StrCat(
"HeuristicPathLNS(",
HeuristicName(),
")");
97 void OnStart()
override;
99 bool IncrementPosition()
override;
100 bool RouteIsEmpty(
int route)
const;
101 int GetNextRoute(
int route)
const {
102 return route + 1 < num_routes_ ? route + 1 : 0;
104 int GetFirstNonEmptyRouteAfterCurrentRoute()
const;
106 std::function<int64_t(int64_t)> SetupNextAccessorForNeighbor()
override;
108 const int num_routes_;
121 std::unique_ptr<RoutingFilteredHeuristic> heuristic);
125 return absl::StrCat(
"RelocatePathAndHeuristicInsertUnperformed(",
130 void OnStart()
override;
132 bool IncrementPosition()
override;
133 bool IncrementRoutes();
135 std::function<int64_t(int64_t)> SetupNextAccessorForNeighbor()
override;
137 int route_to_relocate_index_;
138 int last_route_to_relocate_index_;
139 int empty_route_index_;
140 int last_empty_route_index_;
141 std::vector<int> routes_to_relocate_;
142 std::vector<int> empty_routes_;
143 std::vector<int64_t> last_node_on_route_;
144 bool has_unperformed_nodes_;
155 std::unique_ptr<RoutingFilteredHeuristic> heuristic,
156 int num_arcs_to_consider,
157 std::function<int64_t(int64_t, int64_t, int64_t)>
158 arc_cost_for_route_start);
162 return absl::StrCat(
"HeuristicExpensiveChainLNS(",
HeuristicName(),
")");
166 void OnStart()
override;
168 bool IncrementPosition()
override;
169 bool IncrementRoute();
170 bool IncrementCurrentArcIndices();
171 bool FindMostExpensiveChainsOnRemainingRoutes();
173 std::function<int64_t(int64_t)> SetupNextAccessorForNeighbor()
override;
178 const int num_arcs_to_consider_;
179 std::vector<std::pair<int64_t, int>> most_expensive_arc_starts_and_ranks_;
183 current_expensive_arc_indices_;
184 std::function<int64_t( int64_t, int64_t,
186 arc_cost_for_route_start_;
198 std::unique_ptr<RoutingFilteredHeuristic> heuristic,
int num_close_nodes);
202 return absl::StrCat(
"HeuristicCloseNodesLNS(",
HeuristicName(),
")");
208 void OnStart()
override;
210 bool IncrementPosition()
override;
212 std::function<int64_t(int64_t)> SetupNextAccessorForNeighbor()
override;
214 void RemoveNode(int64_t node);
215 void RemoveNodeAndActiveSibling(int64_t node);
217 bool IsActive(int64_t node)
const {
218 DCHECK_LT(node,
model_->Size());
222 int64_t Prev(int64_t node)
const {
224 DCHECK_LT(node, new_prevs_.size());
225 return changed_prevs_[node] ? new_prevs_[node] :
InverseValue(node);
227 int64_t
Next(int64_t node)
const {
228 DCHECK(!
model_->IsEnd(node));
229 return changed_nexts_[node] ? new_nexts_[node] :
Value(node);
232 std::vector<int64_t> GetActiveSiblings(int64_t node)
const;
234 const std::vector<PickupDeliveryPair>& pickup_delivery_pairs_;
241 std::vector<std::vector<int64_t>> close_nodes_;
242 const int num_close_nodes_;
244 std::vector<int64_t> new_nexts_;
245 SparseBitset<> changed_nexts_;
246 std::vector<int64_t> new_prevs_;
247 SparseBitset<> changed_prevs_;
std::string DebugString() const override
~FilteredHeuristicCloseNodesLNSOperator() override
FilteredHeuristicCloseNodesLNSOperator(std::unique_ptr< RoutingFilteredHeuristic > heuristic, int num_close_nodes)
FilteredHeuristicCloseNodesLNSOperator.
std::string DebugString() const override
~FilteredHeuristicExpensiveChainLNSOperator() override
FilteredHeuristicExpensiveChainLNSOperator(std::unique_ptr< RoutingFilteredHeuristic > heuristic, int num_arcs_to_consider, std::function< int64_t(int64_t, int64_t, int64_t)> arc_cost_for_route_start)
FilteredHeuristicExpensiveChainLNSOperator.
~FilteredHeuristicLocalSearchOperator() override
RoutingModel *const model_
SparseBitset removed_nodes_
Keeps track of removed nodes when making a neighbor.
virtual std::function< int64_t(int64_t)> SetupNextAccessorForNeighbor()=0
virtual bool IncrementPosition()=0
FilteredHeuristicLocalSearchOperator(std::unique_ptr< RoutingFilteredHeuristic > heuristic, bool keep_inverse_values=false)
FilteredHeuristicLocalSearchOperator.
std::string HeuristicName() const
~FilteredHeuristicPathLNSOperator() override
FilteredHeuristicPathLNSOperator(std::unique_ptr< RoutingFilteredHeuristic > heuristic)
FilteredHeuristicPathLNSOperator.
std::string DebugString() const override
int64_t Value(int64_t index) const
int64_t InverseValue(int64_t index) const
IntVarLocalSearchOperator(const std::vector< IntVar * > &vars, bool keep_inverse_values=false)
In SWIG mode, we don't want anything besides these top-level includes.