C++ Reference

C++ Reference: Routing

routing_neighborhoods.h
Go to the documentation of this file.
1 // Copyright 2010-2018 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_NEIGHBORHOODS_H_
15 #define OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_NEIGHBORHOODS_H_
16 
21 
22 namespace operations_research {
23 
44 // TODO(user): Consider merging with standard Relocate in local_search.cc.
46  public:
48  const std::vector<IntVar*>& vars,
49  const std::vector<IntVar*>& secondary_vars,
50  std::function<int(int64)> start_empty_path_class,
51  RoutingTransitCallback2 arc_evaluator);
53 
54  bool MakeNeighbor() override;
55  std::string DebugString() const override { return "RelocateNeighbors"; }
56 
57  private:
64  bool MoveChainAndRepair(int64 before_chain, int64 chain_end,
65  int64 destination);
66 
74  int64 Reposition(int64 before_to_move, int64 up_to);
75 
76  RoutingTransitCallback2 arc_evaluator_;
77 };
78 
83 // TODO(user): Add option to prune neighbords where the order of node pairs
84 // is violated (ie precedence between pickup and delivery nodes).
85 // TODO(user): Move this to local_search.cc if it's generic enough.
86 // TODO(user): Detect pairs automatically by parsing the constraint model;
87 // we could then get rid of the pair API in the RoutingModel
88 // class.
89 
103  public:
104  MakePairActiveOperator(const std::vector<IntVar*>& vars,
105  const std::vector<IntVar*>& secondary_vars,
106  std::function<int(int64)> start_empty_path_class,
107  const RoutingIndexPairs& pairs);
109  bool MakeNeighbor() override;
110  std::string DebugString() const override { return "MakePairActive"; }
111 
112  protected:
113  bool MakeOneNeighbor() override;
114  bool OnSamePathAsPreviousBase(int64 base_index) override {
117  return true;
118  }
119 
120  int64 GetBaseNodeRestartPosition(int base_index) override;
121 
124  bool RestartAtPathStartOnSynchronize() override { return true; }
125 
126  private:
127  void OnNodeInitialization() override;
128  int FindNextInactivePair(int pair_index) const;
129  bool ContainsActiveNodes(const std::vector<int64>& nodes) const;
130 
131  int inactive_pair_;
132  int inactive_pair_first_index_;
133  int inactive_pair_second_index_;
134  const RoutingIndexPairs pairs_;
135 };
136 
139  public:
140  MakePairInactiveOperator(const std::vector<IntVar*>& vars,
141  const std::vector<IntVar*>& secondary_vars,
142  std::function<int(int64)> start_empty_path_class,
143  const RoutingIndexPairs& index_pairs);
144 
145  bool MakeNeighbor() override;
146  std::string DebugString() const override { return "MakePairInActive"; }
147 };
148 
158  public:
159  PairRelocateOperator(const std::vector<IntVar*>& vars,
160  const std::vector<IntVar*>& secondary_vars,
161  std::function<int(int64)> start_empty_path_class,
162  const RoutingIndexPairs& index_pairs);
163  ~PairRelocateOperator() override {}
164 
165  bool MakeNeighbor() override;
166  std::string DebugString() const override { return "PairRelocateOperator"; }
167 
168  protected:
169  bool OnSamePathAsPreviousBase(int64 base_index) override {
171  return base_index == kPairSecondNodeDestination;
172  }
173  int64 GetBaseNodeRestartPosition(int base_index) override;
174 
175  bool ConsiderAlternatives(int64 base_index) const override {
176  return base_index == kPairFirstNode;
177  }
178 
179  private:
180  bool RestartAtPathStartOnSynchronize() override { return true; }
181 
182  static const int kPairFirstNode = 0;
183  static const int kPairFirstNodeDestination = 1;
184  static const int kPairSecondNodeDestination = 2;
185 };
186 
188  public:
189  LightPairRelocateOperator(const std::vector<IntVar*>& vars,
190  const std::vector<IntVar*>& secondary_vars,
191  std::function<int(int64)> start_empty_path_class,
192  const RoutingIndexPairs& index_pairs);
194 
195  bool MakeNeighbor() override;
196  std::string DebugString() const override {
197  return "LightPairRelocateOperator";
198  }
199 };
200 
208  public:
209  PairExchangeOperator(const std::vector<IntVar*>& vars,
210  const std::vector<IntVar*>& secondary_vars,
211  std::function<int(int64)> start_empty_path_class,
212  const RoutingIndexPairs& index_pairs);
213  ~PairExchangeOperator() override {}
214 
215  bool MakeNeighbor() override;
216  std::string DebugString() const override { return "PairExchangeOperator"; }
217 
218  private:
219  bool RestartAtPathStartOnSynchronize() override { return true; }
220  bool ConsiderAlternatives(int64 base_index) const override { return true; }
221  bool GetPreviousAndSibling(int64 node, int64* previous, int64* sibling,
222  int64* sibling_previous) const;
223 };
224 
239  public:
240  PairExchangeRelocateOperator(const std::vector<IntVar*>& vars,
241  const std::vector<IntVar*>& secondary_vars,
242  std::function<int(int64)> start_empty_path_class,
243  const RoutingIndexPairs& index_pairs);
245 
246  bool MakeNeighbor() override;
247  std::string DebugString() const override {
248  return "PairExchangeRelocateOperator";
249  }
250 
251  protected:
252  bool OnSamePathAsPreviousBase(int64 base_index) override;
253  int64 GetBaseNodeRestartPosition(int base_index) override;
254 
255  private:
256  bool RestartAtPathStartOnSynchronize() override { return true; }
257  bool GetPreviousAndSibling(int64 node, int64* previous, int64* sibling,
258  int64* sibling_previous) const;
259  bool MoveNode(int pair, int node, int64 nodes[2][2], int64 dest[2][2],
260  int64 prev[2][2]);
261  bool LoadAndCheckDest(int pair, int node, int64 base_node, int64 nodes[2][2],
262  int64 dest[2][2]) const;
263 
264  static const int kFirstPairFirstNode = 0;
265  static const int kSecondPairFirstNode = 1;
266  static const int kFirstPairFirstNodeDestination = 2;
267  static const int kFirstPairSecondNodeDestination = 3;
268  static const int kSecondPairFirstNodeDestination = 4;
269  static const int kSecondPairSecondNodeDestination = 5;
270 };
271 
283  public:
284  SwapIndexPairOperator(const std::vector<IntVar*>& vars,
285  const std::vector<IntVar*>& path_vars,
286  const RoutingIndexPairs& index_pairs);
288 
289  bool MakeNextNeighbor(Assignment* delta, Assignment* deltadelta) override;
290  void OnStart() override;
291  std::string DebugString() const override { return "SwapIndexPairOperator"; }
292 
293  private:
296  bool UpdateActiveNodes();
298  void SetNext(int64 from, int64 to, int64 path) {
299  DCHECK_LT(from, number_of_nexts_);
300  SetValue(from, to);
301  if (!ignore_path_vars_) {
302  DCHECK_LT(from + number_of_nexts_, Size());
303  SetValue(from + number_of_nexts_, path);
304  }
305  }
306 
307  const RoutingIndexPairs index_pairs_;
308  int pair_index_;
309  int first_index_;
310  int second_index_;
311  int64 first_active_;
312  int64 second_active_;
313  std::vector<int64> prevs_;
314  const int number_of_nexts_;
315  const bool ignore_path_vars_;
316 };
317 
321  public:
322  IndexPairSwapActiveOperator(const std::vector<IntVar*>& vars,
323  const std::vector<IntVar*>& secondary_vars,
324  std::function<int(int64)> start_empty_path_class,
325  const RoutingIndexPairs& index_pairs);
327 
328  bool MakeNextNeighbor(Assignment* delta, Assignment* deltadelta) override;
329  bool MakeNeighbor() override;
330  std::string DebugString() const override {
331  return "IndexPairSwapActiveOperator";
332  }
333 
334  private:
335  void OnNodeInitialization() override;
336 
337  int inactive_node_;
338 };
339 
343  public:
345  std::unique_ptr<RoutingFilteredHeuristic> heuristic);
347 
348  std::string DebugString() const override {
349  std::string heuristic_name = heuristic_->DebugString();
350  const int erase_pos = heuristic_name.find("FilteredHeuristic");
351  if (erase_pos != std::string::npos) {
352  heuristic_name.erase(erase_pos);
353  }
354  return absl::StrCat("HeuristicPathLNS(", heuristic_name, ")");
355  }
356 
357  private:
358  void OnStart() override;
359  bool MakeOneNeighbor() override;
360 
361  bool IncrementRoute();
362  bool CurrentRouteIsEmpty() const;
363  void IncrementCurrentRouteToNextNonEmpty();
364 
365  bool DestroyRouteAndReinsertNodes();
366 
367  int64 VehicleVarIndex(int64 node) const { return model_.Size() + node; }
368 
369  // TODO(user): Remove the dependency from RoutingModel by storing an
370  // IntVarFilteredHeuristic here instead and storing information on path
371  // start/ends like PathOperator does (instead of relying on the model).
372  const std::unique_ptr<RoutingFilteredHeuristic> heuristic_;
373  const RoutingModel& model_;
374  const bool consider_vehicle_vars_;
375  int current_route_;
376  int last_route_;
377  bool just_started_;
378 };
379 
383 // TODO(user): Factor out MakeOneNeighbor() and the common parts of the
384 // Destroy...AndReinsert() methods in a parent class for the two heuristic LNS
385 // operators.
387  : public IntVarLocalSearchOperator {
388  public:
390  std::unique_ptr<RoutingFilteredHeuristic> heuristic,
391  int num_arcs_to_consider,
392  std::function<int64(int64, int64, int64)> arc_cost_for_route_start);
394 
395  std::string DebugString() const override {
396  std::string heuristic_name = heuristic_->DebugString();
397  const int erase_pos = heuristic_name.find("FilteredHeuristic");
398  if (erase_pos != std::string::npos) {
399  heuristic_name.erase(erase_pos);
400  }
401  return absl::StrCat("HeuristicExpensiveChainLNS(", heuristic_name, ")");
402  }
403 
404  private:
405  void OnStart() override;
406  bool MakeOneNeighbor() override;
407 
408  bool IncrementPosition();
409  bool IncrementRoute();
410  bool IncrementCurrentArcIndices();
411  bool FindMostExpensiveChainsOnRemainingRoutes();
412 
413  bool DestroyChainAndReinsertNodes();
414 
415  int64 VehicleVarIndex(int64 node) const { return model_.Size() + node; }
416 
417  const std::unique_ptr<RoutingFilteredHeuristic> heuristic_;
418  const RoutingModel& model_;
419  const bool consider_vehicle_vars_;
420  int current_route_;
421  int last_route_;
422 
423  const int num_arcs_to_consider_;
424  std::vector<std::pair<int64, int>> most_expensive_arc_starts_and_ranks_;
427  std::pair</*first_arc_index*/ int, /*second_arc_index*/ int>
428  current_expensive_arc_indices_;
429  std::function<int64(/*before_node*/ int64, /*after_node*/ int64,
430  /*path_start*/ int64)>
431  arc_cost_for_route_start_;
432 
433  bool just_started_;
434 };
435 
444  public:
446  const std::vector<IntVar*>& vars,
447  const std::vector<IntVar*>& secondary_vars,
448  std::function<int(int64)> start_empty_path_class,
449  int num_arcs_to_consider,
450  std::function<int64(int64, int64, int64)> arc_cost_for_path_start);
452  bool MakeNeighbor() override;
453  bool MakeOneNeighbor() override;
454 
455  std::string DebugString() const override { return "RelocateExpensiveChain"; }
456 
457  private:
458  void OnNodeInitialization() override;
459  void IncrementCurrentPath();
460  bool IncrementCurrentArcIndices();
464  bool FindMostExpensiveChainsOnRemainingPaths();
465 
466  int num_arcs_to_consider_;
467  int current_path_;
468  std::vector<std::pair<int64, int>> most_expensive_arc_starts_and_ranks_;
471  std::pair</*first_arc_index*/ int, /*second_arc_index*/ int>
472  current_expensive_arc_indices_;
473  std::function<int64(/*before_node*/ int64, /*after_node*/ int64,
474  /*path_start*/ int64)>
475  arc_cost_for_path_start_;
476  int end_path_;
479  bool has_non_empty_paths_to_explore_;
480 };
481 
489 template <bool swap_first>
491  public:
492  PairNodeSwapActiveOperator(const std::vector<IntVar*>& vars,
493  const std::vector<IntVar*>& secondary_vars,
494  std::function<int(int64)> start_empty_path_class,
495  const RoutingIndexPairs& index_pairs);
497 
498  bool MakeNextNeighbor(Assignment* delta, Assignment* deltadelta) override;
499  bool MakeNeighbor() override;
500  std::string DebugString() const override {
501  return "PairNodeSwapActiveOperator";
502  }
503 
504  protected:
505  bool OnSamePathAsPreviousBase(int64 base_index) override {
508  return true;
509  }
510 
511  int64 GetBaseNodeRestartPosition(int base_index) override;
512 
515  bool RestartAtPathStartOnSynchronize() override { return true; }
516 
517  private:
518  void OnNodeInitialization() override;
519 
520  int inactive_pair_;
521  RoutingIndexPairs pairs_;
522 };
523 
524 // ==========================================================================
525 // Section: Implementations of the template classes declared above.
526 
527 template <bool swap_first>
529  const std::vector<IntVar*>& vars,
530  const std::vector<IntVar*>& secondary_vars,
531  std::function<int(int64)> start_empty_path_class,
532  const RoutingIndexPairs& index_pairs)
533  : PathOperator(vars, secondary_vars, 2, false, false,
534  std::move(start_empty_path_class)),
535  inactive_pair_(0),
536  pairs_(index_pairs) {}
537 
538 template <bool swap_first>
540  int base_index) {
541  // Base node 1 must be after base node 0 if they are both on the same path.
542  if (base_index == 0 || StartNode(base_index) != StartNode(base_index - 1)) {
543  return StartNode(base_index);
544  } else {
545  return BaseNode(base_index - 1);
546  }
547 }
548 
549 template <bool swap_first>
551  for (int i = 0; i < pairs_.size(); ++i) {
552  if (IsInactive(pairs_[i].first[0]) && IsInactive(pairs_[i].second[0])) {
553  inactive_pair_ = i;
554  return;
555  }
556  }
557  inactive_pair_ = pairs_.size();
558 }
559 
560 template <bool swap_first>
562  Assignment* delta, Assignment* deltadelta) {
563  while (inactive_pair_ < pairs_.size()) {
564  if (!IsInactive(pairs_[inactive_pair_].first[0]) ||
565  !IsInactive(pairs_[inactive_pair_].second[0]) ||
566  !PathOperator::MakeNextNeighbor(delta, deltadelta)) {
567  ResetPosition();
568  ++inactive_pair_;
569  } else {
570  return true;
571  }
572  }
573  return false;
574 }
575 
576 template <bool swap_first>
578  const int64 base = BaseNode(0);
579  if (IsPathEnd(base)) {
580  return false;
581  }
582  const int64 pair_first = pairs_[inactive_pair_].first[0];
583  const int64 pair_second = pairs_[inactive_pair_].second[0];
584  if (swap_first) {
585  return MakeActive(pair_second, BaseNode(1)) &&
586  MakeActive(pair_first, base) &&
587  MakeChainInactive(pair_first, Next(pair_first));
588  } else {
589  return MakeActive(pair_second, BaseNode(1)) &&
590  MakeActive(pair_first, base) &&
591  MakeChainInactive(pair_second, Next(pair_second));
592  }
593 }
594 
607  public:
608  RelocateSubtrip(const std::vector<IntVar*>& vars,
609  const std::vector<IntVar*>& secondary_vars,
610  std::function<int(int64)> start_empty_path_class,
611  const RoutingIndexPairs& pairs);
612 
613  std::string DebugString() const override { return "RelocateSubtrip"; }
614  bool MakeNeighbor() override;
615 
616  private:
617  // Relocates the subtrip starting at chain_first_node. It must be a pickup.
618  bool RelocateSubTripFromPickup(int64 chain_first_node, int64 insertion_node);
620  bool RelocateSubTripFromDelivery(int64 chain_last_node, int64 insertion_node);
621  std::vector<bool> is_pickup_node_;
622  std::vector<bool> is_delivery_node_;
623  std::vector<int> pair_of_node_;
624  // Represents the set of pairs that have been opened during a call to
625  // MakeNeighbor(). This vector must be all false before and after calling
626  // RelocateSubTripFromPickup() and RelocateSubTripFromDelivery().
627  std::vector<bool> opened_pairs_bitset_;
628 
629  std::vector<int64> rejected_nodes_;
630  std::vector<int64> subtrip_nodes_;
631 };
632 
634  public:
635  ExchangeSubtrip(const std::vector<IntVar*>& vars,
636  const std::vector<IntVar*>& secondary_vars,
637  std::function<int(int64)> start_empty_path_class,
638  const RoutingIndexPairs& pairs);
639 
640  std::string DebugString() const override { return "ExchangeSubtrip"; }
641  bool MakeNeighbor() override;
642 
643  private:
644  // Try to extract a subtrip from base_node (see below) and check that the move
645  // will be canonical.
646  // Given a pickup/delivery pair, this operator could generate the same move
647  // twice, the first time with base_node == pickup, the second time with
648  // base_node == delivery. This happens only when no nodes in the subtrip
649  // remain in the original path, i.e. when rejects is empty after
650  // chain extraction. In that case, we keep only a canonical move out of the
651  // two possibilities, the move where base_node is a pickup.
652  bool ExtractChainsAndCheckCanonical(int64 base_node,
653  std::vector<int64>* rejects,
654  std::vector<int64>* subtrip);
655  // Reads the path from base_node forward, collecting subtrip nodes in
656  // subtrip and non-subtrip nodes in rejects.
657  // Non-subtrip nodes will be unmatched delivery nodes.
658  // base_node must be a pickup, and remaining/extracted_nodes must be empty.
659  // Returns true if such chains could be extracted.
660  bool ExtractChainsFromPickup(int64 base_node, std::vector<int64>* rejects,
661  std::vector<int64>* subtrip);
662  // Reads the path from base_node backward, collecting subtrip nodes in
663  // subtrip and non-subtrip nodes in rejects.
664  // Non-subtrip nodes will be unmatched pickup nodes.
665  // base_node must be a delivery, and remaining/extracted_nodes must be empty.
666  // Returns true if such chains could be extracted.
667  bool ExtractChainsFromDelivery(int64 base_node, std::vector<int64>* rejects,
668  std::vector<int64>* subtrip);
669  void SetPath(const std::vector<int64>& path, int path_id);
670 
671  // Precompute some information about nodes.
672  std::vector<bool> is_pickup_node_;
673  std::vector<bool> is_delivery_node_;
674  std::vector<int> pair_of_node_;
675  // Represents the set of opened pairs during ExtractChainsFromXXX().
676  std::vector<bool> opened_pairs_set_;
677  // Keep internal structures under hand to avoid reallocation.
678  std::vector<int64> rejects0_;
679  std::vector<int64> subtrip0_;
680  std::vector<int64> rejects1_;
681  std::vector<int64> subtrip1_;
682  std::vector<int64> path0_;
683  std::vector<int64> path1_;
684 };
685 
686 } // namespace operations_research
687 
688 #endif // OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_NEIGHBORHOODS_H_
FilteredHeuristicExpensiveChainLNSOperator(std::unique_ptr< RoutingFilteredHeuristic > heuristic, int num_arcs_to_consider, std::function< int64(int64, int64, int64)> arc_cost_for_route_start)
Pair-based neighborhood operators, designed to move nodes by pairs (pairs are static and given).
std::string DebugString() const override
std::string DebugString() const override
PairRelocateOperator(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64)> start_empty_path_class, const RoutingIndexPairs &index_pairs)
bool MakeNeighbor() override
RelocateSubtrip(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64)> start_empty_path_class, const RoutingIndexPairs &pairs)
Relocate neighborhood which moves chains of neighbors.
~IndexPairSwapActiveOperator() override
Similar to the move above, but instead of removing one route entirely, the destruction phase consists...
~MakePairActiveOperator() override
std::string DebugString() const override
bool MakeNeighbor() override
std::string DebugString() const override
int64 GetBaseNodeRestartPosition(int base_index) override
Returns the index of the node to which the base node of index base_index must be set to when it reach...
IndexPairSwapActiveOperator(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64)> start_empty_path_class, const RoutingIndexPairs &index_pairs)
PairExchangeOperator(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64)> start_empty_path_class, const RoutingIndexPairs &index_pairs)
bool OnSamePathAsPreviousBase(int64 base_index) override
Returns true if a base node has to be on the same path as the "previous" base node (base node of inde...
Operator which iterates through each alternative of a set of pairs.
~PairNodeSwapActiveOperator() override
bool MakeNeighbor() override
ExchangeSubtrip(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64)> start_empty_path_class, const RoutingIndexPairs &pairs)
bool MakeNeighbor() override
Base class of the local search operators dedicated to path modifications (a path is a set of nodes li...
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
bool MakeNextNeighbor(Assignment *delta, Assignment *deltadelta) override
Redefines MakeNextNeighbor to export a simpler interface.
bool MakeNeighbor() override
std::string DebugString() const override
bool MakeNeighbor() override
std::string DebugString() const override
Operator which exchanges the position of two pairs; for both pairs the first node of the pair must be...
std::string DebugString() const override
~PairExchangeRelocateOperator() override
bool MakeNeighbor() override
Specialization of LocalSearchOperator built from an array of IntVars which specifies the scope of the...
~FilteredHeuristicPathLNSOperator() override
MakePairActiveOperator(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64)> start_empty_path_class, const RoutingIndexPairs &pairs)
bool OnSamePathAsPreviousBase(int64 base_index) override
Returns true if a base node has to be on the same path as the "previous" base node (base node of inde...
bool MakeNeighbor() override
std::string DebugString() const override
PairExchangeRelocateOperator(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64)> start_empty_path_class, const RoutingIndexPairs &index_pairs)
std::string DebugString() const override
std::string DebugString() const override
Operator which inserts inactive nodes into a path and makes a pair of active nodes inactive.
std::string DebugString() const override
LightPairRelocateOperator(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64)> start_empty_path_class, const RoutingIndexPairs &index_pairs)
int64 Size() const
Returns the number of next variables in the model.
Definition: routing.h:1249
PairNodeSwapActiveOperator(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64)> start_empty_path_class, const RoutingIndexPairs &index_pairs)
Operator which moves a pair of nodes to another position where the first node of the pair must be bef...
bool RestartAtPathStartOnSynchronize() override
Required to ensure that after synchronization the operator is in a state compatible with GetBaseNodeR...
SwapIndexPairOperator(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &path_vars, const RoutingIndexPairs &index_pairs)
FilteredHeuristicPathLNSOperator(std::unique_ptr< RoutingFilteredHeuristic > heuristic)
bool RestartAtPathStartOnSynchronize() override
Required to ensure that after synchronization the operator is in a state compatible with GetBaseNodeR...
MakePairInactiveOperator(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64)> start_empty_path_class, const RoutingIndexPairs &index_pairs)
~SwapIndexPairOperator() override
bool MakeOneNeighbor() override
This method should not be overridden. Override MakeNeighbor() instead.
bool MakeNextNeighbor(Assignment *delta, Assignment *deltadelta) override
Redefines MakeNextNeighbor to export a simpler interface.
Operator which makes pairs of active nodes inactive.
~PairExchangeOperator() override
Operator which exchanges the paths of two pairs (path have to be different).
int64 GetBaseNodeRestartPosition(int base_index) override
Returns the index of the node to which the base node of index base_index must be set to when it reach...
bool MakeNeighbor() override
int64 GetBaseNodeRestartPosition(int base_index) override
Returns the index of the node to which the base node of index base_index must be set to when it reach...
Tries to move subtrips after an insertion node.
std::vector< RoutingIndexPair > RoutingIndexPairs
Definition: routing_types.h:45
std::string DebugString() const override
bool MakeNeighbor() override
LNS-like operator based on a filtered first solution heuristic to rebuild the solution,...
~PairRelocateOperator() override
int Size() const
RelocateExpensiveChain(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64)> start_empty_path_class, int num_arcs_to_consider, std::function< int64(int64, int64, int64)> arc_cost_for_path_start)
~MakeRelocateNeighborsOperator() override
int64 GetBaseNodeRestartPosition(int base_index) override
Returns the index of the node to which the base node of index base_index must be set to when it reach...
bool OnSamePathAsPreviousBase(int64 base_index) override
Returns true if a base node has to be on the same path as the "previous" base node (base node of inde...
std::string DebugString() const override
bool MakeOneNeighbor() override
This method should not be overridden. Override MakeNeighbor() instead.
~RelocateExpensiveChain() override
MakeRelocateNeighborsOperator(const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64)> start_empty_path_class, RoutingTransitCallback2 arc_evaluator)
bool OnSamePathAsPreviousBase(int64 base_index) override
Returns true if a base node has to be on the same path as the "previous" base node (base node of inde...
bool ConsiderAlternatives(int64 base_index) const override
Indicates if alternatives should be considered when iterating over base nodes.
std::string DebugString() const override
std::string DebugString() const override
void OnStart() override
Called by Start() after synchronizing the operator with the current assignment.
bool MakeNeighbor() override
void SetValue(int64 index, const int64 &value)
Operator which inserts pairs of inactive nodes into a path and makes an active node inactive.
RelocateExpensiveChain.
bool MakeNeighbor() override
~FilteredHeuristicExpensiveChainLNSOperator() override
std::function< int64(int64, int64)> RoutingTransitCallback2
Definition: routing_types.h:42
~LightPairRelocateOperator() override
bool MakeNextNeighbor(Assignment *delta, Assignment *deltadelta) override
Redefines MakeNextNeighbor to export a simpler interface.
bool MakeNextNeighbor(Assignment *delta, Assignment *deltadelta) override
Redefines MakeNextNeighbor to export a simpler interface.