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 CurrentRouteIsEmpty()
const;
101 void IncrementCurrentRouteToNextNonEmpty();
103 std::function<int64_t(int64_t)> SetupNextAccessorForNeighbor()
override;
117 std::unique_ptr<RoutingFilteredHeuristic> heuristic);
121 return absl::StrCat(
"RelocatePathAndHeuristicInsertUnperformed(",
126 void OnStart()
override;
128 bool IncrementPosition()
override;
129 bool IncrementRoutes();
131 std::function<int64_t(int64_t)> SetupNextAccessorForNeighbor()
override;
133 int route_to_relocate_index_;
134 int last_route_to_relocate_index_;
135 int empty_route_index_;
136 int last_empty_route_index_;
137 std::vector<int> routes_to_relocate_;
138 std::vector<int> empty_routes_;
139 std::vector<int64_t> last_node_on_route_;
140 bool has_unperformed_nodes_;
151 std::unique_ptr<RoutingFilteredHeuristic> heuristic,
152 int num_arcs_to_consider,
153 std::function<int64_t(int64_t, int64_t, int64_t)>
154 arc_cost_for_route_start);
158 return absl::StrCat(
"HeuristicExpensiveChainLNS(",
HeuristicName(),
")");
162 void OnStart()
override;
164 bool IncrementPosition()
override;
165 bool IncrementRoute();
166 bool IncrementCurrentArcIndices();
167 bool FindMostExpensiveChainsOnRemainingRoutes();
169 std::function<int64_t(int64_t)> SetupNextAccessorForNeighbor()
override;
174 const int num_arcs_to_consider_;
175 std::vector<std::pair<int64_t, int>> most_expensive_arc_starts_and_ranks_;
179 current_expensive_arc_indices_;
180 std::function<int64_t( int64_t, int64_t,
182 arc_cost_for_route_start_;
194 std::unique_ptr<RoutingFilteredHeuristic> heuristic,
int num_close_nodes);
198 return absl::StrCat(
"HeuristicCloseNodesLNS(",
HeuristicName(),
")");
204 void OnStart()
override;
206 bool IncrementPosition()
override;
208 std::function<int64_t(int64_t)> SetupNextAccessorForNeighbor()
override;
210 void RemoveNode(int64_t node);
211 void RemoveNodeAndActiveSibling(int64_t node);
213 bool IsActive(int64_t node)
const {
214 DCHECK_LT(node,
model_->Size());
218 int64_t Prev(int64_t node)
const {
220 DCHECK_LT(node, new_prevs_.size());
221 return changed_prevs_[node] ? new_prevs_[node] :
InverseValue(node);
223 int64_t
Next(int64_t node)
const {
224 DCHECK(!
model_->IsEnd(node));
225 return changed_nexts_[node] ? new_nexts_[node] :
Value(node);
228 std::vector<int64_t> GetActiveSiblings(int64_t node)
const;
230 const std::vector<PickupDeliveryPair>& pickup_delivery_pairs_;
237 std::vector<std::vector<int64_t>> close_nodes_;
238 const int num_close_nodes_;
240 std::vector<int64_t> new_nexts_;
241 SparseBitset<> changed_nexts_;
242 std::vector<int64_t> new_prevs_;
243 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
In SWIG mode, we don't want anything besides these top-level includes.