C++ Reference

C++ Reference: Routing

routing.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 
68 // TODO(user): Add a section on costs (vehicle arc costs, span costs,
69 // disjunctions costs).
70 //
156 
157 #ifndef OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_H_
158 #define OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_H_
159 
160 #include <cstddef>
161 #include <functional>
162 #include <memory>
163 #include <queue>
164 #include <string>
165 #include <utility>
166 #include <vector>
167 
168 #include "absl/container/flat_hash_map.h"
169 #include "absl/container/flat_hash_set.h"
170 #include "absl/hash/hash.h"
171 #include "absl/time/time.h"
172 #include "ortools/base/adjustable_priority_queue-inl.h"
173 #include "ortools/base/adjustable_priority_queue.h"
174 #include "ortools/base/commandlineflags.h"
175 #include "ortools/base/hash.h"
176 #include "ortools/base/int_type_indexed_vector.h"
177 #include "ortools/base/logging.h"
178 #include "ortools/base/macros.h"
185 #include "ortools/glop/lp_solver.h"
186 #include "ortools/glop/parameters.pb.h"
187 #include "ortools/graph/graph.h"
188 #include "ortools/lp_data/lp_data.h"
189 #include "ortools/lp_data/lp_types.h"
190 #include "ortools/sat/theta_tree.h"
191 #include "ortools/util/range_query_function.h"
192 #include "ortools/util/sorted_interval_list.h"
193 
194 namespace operations_research {
195 
196 class GlobalDimensionCumulOptimizer;
197 class LocalDimensionCumulOptimizer;
198 class LocalSearchOperator;
199 #ifndef SWIG
200 class IntVarFilteredDecisionBuilder;
201 class IntVarFilteredHeuristic;
202 class IndexNeighborFinder;
203 #endif
204 class RoutingDimension;
205 #ifndef SWIG
206 using util::ReverseArcListGraph;
207 class SweepArranger;
208 #endif
209 struct SweepIndex;
210 
212  public:
214  enum Status {
225  };
226 
235  };
236  typedef RoutingCostClassIndex CostClassIndex;
237  typedef RoutingDimensionIndex DimensionIndex;
238  typedef RoutingDisjunctionIndex DisjunctionIndex;
239  typedef RoutingVehicleClassIndex VehicleClassIndex;
242 
243 // TODO(user): Remove all SWIG guards by adding the @ignore in .i.
244 #if !defined(SWIG)
247 #endif // SWIG
248 
249 #if !defined(SWIG)
250  struct StateDependentTransit {
263  RangeIntToIntFunction* transit;
264  RangeMinMaxIndexFunction* transit_plus_identity;
265  };
266  typedef std::function<StateDependentTransit(int64, int64)>
268 #endif // SWIG
269 
270 #if !defined(SWIG)
271  struct CostClass {
274 
289 
295  struct DimensionCost {
299  bool operator<(const DimensionCost& cost) const {
302  }
303  return cost_coefficient < cost.cost_coefficient;
304  }
305  };
306  std::vector<DimensionCost>
308 
311 
313  static bool LessThan(const CostClass& a, const CostClass& b) {
314  if (a.evaluator_index != b.evaluator_index) {
315  return a.evaluator_index < b.evaluator_index;
316  }
319  }
320  };
321 
322  struct VehicleClass {
326  int64 fixed_cost;
331  // TODO(user): Find equivalent start/end nodes wrt dimensions and
332  // callbacks.
337  gtl::ITIVector<DimensionIndex, int64> dimension_start_cumuls_min;
338  gtl::ITIVector<DimensionIndex, int64> dimension_start_cumuls_max;
339  gtl::ITIVector<DimensionIndex, int64> dimension_end_cumuls_min;
340  gtl::ITIVector<DimensionIndex, int64> dimension_end_cumuls_max;
341  gtl::ITIVector<DimensionIndex, int64> dimension_capacities;
344  gtl::ITIVector<DimensionIndex, int64> dimension_evaluator_classes;
347 
349  static bool LessThan(const VehicleClass& a, const VehicleClass& b);
350  };
351 #endif // defined(SWIG)
352 
354  static const int64 kNoPenalty;
355 
359 
363 
367  explicit RoutingModel(const RoutingIndexManager& index_manager);
368  RoutingModel(const RoutingIndexManager& index_manager,
369  const RoutingModelParameters& parameters);
371 
378  const TransitCallback2& TransitCallback(int callback_index) const {
379  CHECK_LT(callback_index, transit_evaluators_.size());
380  return transit_evaluators_[callback_index];
381  }
382  const TransitCallback1& UnaryTransitCallbackOrNull(int callback_index) const {
383  CHECK_LT(callback_index, unary_transit_evaluators_.size());
384  return unary_transit_evaluators_[callback_index];
385  }
387  int callback_index) const {
388  CHECK_LT(callback_index, state_dependent_transit_evaluators_.size());
389  return state_dependent_transit_evaluators_[callback_index];
390  }
391 
393 
405 
414  bool AddDimension(int evaluator_index, int64 slack_max, int64 capacity,
415  bool fix_start_cumul_to_zero, const std::string& name);
417  const std::vector<int>& evaluator_indices, int64 slack_max,
418  int64 capacity, bool fix_start_cumul_to_zero, const std::string& name);
419  bool AddDimensionWithVehicleCapacity(int evaluator_index, int64 slack_max,
420  std::vector<int64> vehicle_capacities,
421  bool fix_start_cumul_to_zero,
422  const std::string& name);
424  const std::vector<int>& evaluator_indices, int64 slack_max,
425  std::vector<int64> vehicle_capacities, bool fix_start_cumul_to_zero,
426  const std::string& name);
433  bool AddConstantDimensionWithSlack(int64 value, int64 capacity,
434  int64 slack_max,
435  bool fix_start_cumul_to_zero,
436  const std::string& name);
437  bool AddConstantDimension(int64 value, int64 capacity,
438  bool fix_start_cumul_to_zero,
439  const std::string& name) {
440  return AddConstantDimensionWithSlack(value, capacity, 0,
441  fix_start_cumul_to_zero, name);
442  }
450  bool AddVectorDimension(std::vector<int64> values, int64 capacity,
451  bool fix_start_cumul_to_zero,
452  const std::string& name);
461  std::vector<std::vector<int64> /*needed_for_swig*/> values,
462  int64 capacity, bool fix_start_cumul_to_zero, const std::string& name);
470  const std::vector<int>& pure_transits,
471  const std::vector<int>& dependent_transits,
472  const RoutingDimension* base_dimension, int64 slack_max,
473  std::vector<int64> vehicle_capacities, bool fix_start_cumul_to_zero,
474  const std::string& name) {
475  return AddDimensionDependentDimensionWithVehicleCapacityInternal(
476  pure_transits, dependent_transits, base_dimension, slack_max,
477  std::move(vehicle_capacities), fix_start_cumul_to_zero, name);
478  }
479 
482  const std::vector<int>& transits, const RoutingDimension* base_dimension,
483  int64 slack_max, std::vector<int64> vehicle_capacities,
484  bool fix_start_cumul_to_zero, const std::string& name);
487  int transit, const RoutingDimension* base_dimension, int64 slack_max,
488  int64 vehicle_capacity, bool fix_start_cumul_to_zero,
489  const std::string& name);
491  int pure_transit, int dependent_transit,
492  const RoutingDimension* base_dimension, int64 slack_max,
493  int64 vehicle_capacity, bool fix_start_cumul_to_zero,
494  const std::string& name);
495 
498  const std::function<int64(int64)>& f, int64 domain_start,
499  int64 domain_end);
500 
510  Constraint* MakePathSpansAndTotalSlacks(const RoutingDimension* dimension,
511  std::vector<IntVar*> spans,
512  std::vector<IntVar*> total_slacks);
513 
515  // TODO(user): rename.
516  std::vector<std::string> GetAllDimensionNames() const;
518  const std::vector<RoutingDimension*>& GetDimensions() const {
519  return dimensions_.get();
520  }
522  std::vector<RoutingDimension*> GetDimensionsWithSoftOrSpanCosts() const;
523  // clang-format off
526  const std::vector<std::unique_ptr<GlobalDimensionCumulOptimizer> >&
528  return global_dimension_optimizers_;
529  }
530  const std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >&
532  return local_dimension_optimizers_;
533  }
534  const std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >&
536  return local_dimension_mp_optimizers_;
537  }
538  // clang-format on
539 
543  const RoutingDimension& dimension) const;
545  const RoutingDimension& dimension) const;
547  const RoutingDimension& dimension) const;
548 
550  bool HasDimension(const std::string& dimension_name) const;
553  const std::string& dimension_name) const;
557  const std::string& dimension_name) const;
562  void SetPrimaryConstrainedDimension(const std::string& dimension_name) {
563  DCHECK(dimension_name.empty() || HasDimension(dimension_name));
564  primary_constrained_dimension_ = dimension_name;
565  }
567  const std::string& GetPrimaryConstrainedDimension() const {
568  return primary_constrained_dimension_;
569  }
586  DisjunctionIndex AddDisjunction(const std::vector<int64>& indices,
587  int64 penalty = kNoPenalty,
588  int64 max_cardinality = 1);
590  const std::vector<DisjunctionIndex>& GetDisjunctionIndices(
591  int64 index) const {
592  return index_to_disjunctions_[index];
593  }
597  template <typename F>
599  int64 index, int64 max_cardinality, F f) const {
600  for (const DisjunctionIndex disjunction : GetDisjunctionIndices(index)) {
601  if (disjunctions_[disjunction].value.max_cardinality == max_cardinality) {
602  for (const int64 d_index : disjunctions_[disjunction].indices) {
603  f(d_index);
604  }
605  }
606  }
607  }
608 #if !defined(SWIGPYTHON)
609  const std::vector<int64>& GetDisjunctionIndices(
612  DisjunctionIndex index) const {
613  return disjunctions_[index].indices;
614  }
615 #endif // !defined(SWIGPYTHON)
616  int64 GetDisjunctionPenalty(DisjunctionIndex index) const {
618  return disjunctions_[index].value.penalty;
619  }
623  return disjunctions_[index].value.max_cardinality;
624  }
626  int GetNumberOfDisjunctions() const { return disjunctions_.size(); }
631  std::vector<std::pair<int64, int64>> GetPerfectBinaryDisjunctions() const;
638 
642  void AddSoftSameVehicleConstraint(const std::vector<int64>& indices,
643  int64 cost);
644 
649  void SetAllowedVehiclesForIndex(const std::vector<int>& vehicles,
650  int64 index);
651 
653  bool IsVehicleAllowedForIndex(int vehicle, int64 index) {
654  return allowed_vehicles_[index].empty() ||
655  allowed_vehicles_[index].find(vehicle) !=
656  allowed_vehicles_[index].end();
657  }
658 
673  // TODO(user): Remove this when model introspection detects linked nodes.
674  void AddPickupAndDelivery(int64 pickup, int64 delivery);
679  DisjunctionIndex delivery_disjunction);
680  // clang-format off
684  const std::vector<std::pair<int, int> >&
685  GetPickupIndexPairs(int64 node_index) const;
687  const std::vector<std::pair<int, int> >&
688  GetDeliveryIndexPairs(int64 node_index) const;
689  // clang-format on
690 
695  int vehicle);
697  int vehicle) const;
700 
702 
703 #ifndef SWIG
704  const IndexPairs& GetPickupAndDeliveryPairs() const {
706  return pickup_delivery_pairs_;
707  }
708  const std::vector<std::pair<DisjunctionIndex, DisjunctionIndex>>&
710  return pickup_delivery_disjunctions_;
711  }
712 #endif // SWIG
713  enum VisitTypePolicy {
740  };
741  // TODO(user): Support multiple visit types per node?
742  void SetVisitType(int64 index, int type, VisitTypePolicy type_policy);
743  int GetVisitType(int64 index) const;
747  // TODO(user): Reconsider the logic and potentially remove the need to
750  int GetNumberOfVisitTypes() const { return num_visit_types_; }
755  void AddHardTypeIncompatibility(int type1, int type2);
756  void AddTemporalTypeIncompatibility(int type1, int type2);
758  const absl::flat_hash_set<int>& GetHardTypeIncompatibilitiesOfType(
759  int type) const;
760  const absl::flat_hash_set<int>& GetTemporalTypeIncompatibilitiesOfType(
761  int type) const;
765  return has_hard_type_incompatibilities_;
766  }
768  return has_temporal_type_incompatibilities_;
769  }
781  int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
787  int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
794  int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
795  // clang-format off
798  const std::vector<absl::flat_hash_set<int> >&
801  const std::vector<absl::flat_hash_set<int> >&
804  const std::vector<absl::flat_hash_set<int> >&
806  // clang-format on
810  return has_same_vehicle_type_requirements_;
811  }
813  return has_temporal_type_requirements_;
814  }
815 
818  bool HasTypeRegulations() const {
822  }
823 
828  int64 UnperformedPenalty(int64 var_index) const;
832  int64 UnperformedPenaltyOrValue(int64 default_value, int64 var_index) const;
836  int64 GetDepot() const;
837 
841  void SetArcCostEvaluatorOfAllVehicles(int evaluator_index);
843  void SetArcCostEvaluatorOfVehicle(int evaluator_index, int vehicle);
846  void SetFixedCostOfAllVehicles(int64 cost);
848  void SetFixedCostOfVehicle(int64 cost, int vehicle);
852  int64 GetFixedCostOfVehicle(int vehicle) const;
853 
869  void SetAmortizedCostFactorsOfAllVehicles(int64 linear_cost_factor,
870  int64 quadratic_cost_factor);
872  void SetAmortizedCostFactorsOfVehicle(int64 linear_cost_factor,
873  int64 quadratic_cost_factor,
874  int vehicle);
875 
876  const std::vector<int64>& GetAmortizedLinearCostFactorOfVehicles() const {
877  return linear_cost_factor_of_vehicle_;
878  }
879  const std::vector<int64>& GetAmortizedQuadraticCostFactorOfVehicles() const {
880  return quadratic_cost_factor_of_vehicle_;
881  }
882 
883  void ConsiderEmptyRouteCostsForVehicle(bool consider_costs, int vehicle) {
884  DCHECK_LT(vehicle, vehicles_);
885  consider_empty_route_costs_[vehicle] = consider_costs;
886  }
887 
888  bool AreEmptyRouteCostsConsideredForVehicle(int vehicle) const {
889  DCHECK_LT(vehicle, vehicles_);
890  return consider_empty_route_costs_[vehicle];
891  }
892 
895 #ifndef SWIG
896  const Solver::IndexEvaluator2& first_solution_evaluator() const {
897  return first_solution_evaluator_;
898  }
899 #endif
900  void SetFirstSolutionEvaluator(Solver::IndexEvaluator2 evaluator) {
902  first_solution_evaluator_ = std::move(evaluator);
903  }
908  void AddSearchMonitor(SearchMonitor* const monitor);
912  void AddAtSolutionCallback(std::function<void()> callback);
923  void AddWeightedVariableMinimizedByFinalizer(IntVar* var, int64 cost);
926  void AddVariableTargetToFinalizer(IntVar* var, int64 target);
933  void CloseModel();
937  const RoutingSearchParameters& search_parameters);
944  const Assignment* Solve(const Assignment* assignment = nullptr);
952  const Assignment* SolveWithParameters(
953  const RoutingSearchParameters& search_parameters,
954  std::vector<const Assignment*>* solutions = nullptr);
956  const Assignment* assignment,
957  const RoutingSearchParameters& search_parameters,
958  std::vector<const Assignment*>* solutions = nullptr);
965  Assignment* target_assignment, const RoutingModel* source_model,
966  const Assignment* source_assignment);
972  // TODO(user): Add support for non-homogeneous costs and disjunctions.
975  Status status() const { return status_; }
984  IntVar* ApplyLocks(const std::vector<int64>& locks);
993  bool ApplyLocksToAllVehicles(const std::vector<std::vector<int64>>& locks,
994  bool close_routes);
999  const Assignment* const PreAssignment() const { return preassignment_; }
1000  Assignment* MutablePreAssignment() { return preassignment_; }
1004  bool WriteAssignment(const std::string& file_name) const;
1008  Assignment* ReadAssignment(const std::string& file_name);
1011  Assignment* RestoreAssignment(const Assignment& solution);
1018  const std::vector<std::vector<int64>>& routes,
1019  bool ignore_inactive_indices);
1036  bool RoutesToAssignment(const std::vector<std::vector<int64>>& routes,
1037  bool ignore_inactive_indices, bool close_routes,
1038  Assignment* const assignment) const;
1042  void AssignmentToRoutes(const Assignment& assignment,
1043  std::vector<std::vector<int64>>* const routes) const;
1061  Assignment* CompactAssignment(const Assignment& assignment) const;
1065  Assignment* CompactAndCheckAssignment(const Assignment& assignment) const;
1067  void AddToAssignment(IntVar* const var);
1068  void AddIntervalToAssignment(IntervalVar* const interval);
1080  const Assignment* original_assignment, absl::Duration duration_limit);
1081 #ifndef SWIG
1082  // TODO(user): Revisit if coordinates are added to the RoutingModel class.
1084  sweep_arranger_.reset(sweep_arranger);
1085  }
1087  SweepArranger* sweep_arranger() const { return sweep_arranger_.get(); }
1088 #endif
1089  void AddLocalSearchFilter(LocalSearchFilter* filter) {
1095  CHECK(filter != nullptr);
1096  if (closed_) {
1097  LOG(WARNING) << "Model is closed, filter addition will be ignored.";
1098  }
1099  extra_filters_.push_back(filter);
1100  }
1101 
1104  int64 Start(int vehicle) const { return starts_[vehicle]; }
1106  int64 End(int vehicle) const { return ends_[vehicle]; }
1108  bool IsStart(int64 index) const;
1110  bool IsEnd(int64 index) const { return index >= Size(); }
1113  int VehicleIndex(int index) const { return index_to_vehicle_[index]; }
1117  int64 Next(const Assignment& assignment, int64 index) const;
1119  bool IsVehicleUsed(const Assignment& assignment, int vehicle) const;
1120 
1121 #if !defined(SWIGPYTHON)
1122  const std::vector<IntVar*>& Nexts() const { return nexts_; }
1127  const std::vector<IntVar*>& VehicleVars() const { return vehicle_vars_; }
1128 #endif
1129  IntVar* NextVar(int64 index) const { return nexts_[index]; }
1132  IntVar* ActiveVar(int64 index) const { return active_[index]; }
1136  IntVar* VehicleCostsConsideredVar(int vehicle) const {
1137  return vehicle_costs_considered_[vehicle];
1138  }
1141  IntVar* VehicleVar(int64 index) const { return vehicle_vars_[index]; }
1143  IntVar* CostVar() const { return cost_; }
1144 
1147  int64 GetArcCostForVehicle(int64 from_index, int64 to_index,
1148  int64 vehicle) const;
1151  return costs_are_homogeneous_across_vehicles_;
1152  }
1155  int64 GetHomogeneousCost(int64 from_index, int64 to_index) const {
1156  return GetArcCostForVehicle(from_index, to_index, /*vehicle=*/0);
1157  }
1160  int64 GetArcCostForFirstSolution(int64 from_index, int64 to_index) const;
1167  int64 GetArcCostForClass(int64 from_index, int64 to_index,
1168  int64 /*CostClassIndex*/ cost_class_index) const;
1171  DCHECK(closed_);
1172  return cost_class_index_of_vehicle_[vehicle];
1173  }
1176  bool HasVehicleWithCostClassIndex(CostClassIndex cost_class_index) const {
1177  DCHECK(closed_);
1178  if (cost_class_index == kCostClassIndexOfZeroCost) {
1179  return has_vehicle_with_zero_cost_class_;
1180  }
1181  return cost_class_index < cost_classes_.size();
1182  }
1184  int GetCostClassesCount() const { return cost_classes_.size(); }
1187  return std::max(0, GetCostClassesCount() - 1);
1188  }
1190  DCHECK(closed_);
1191  return vehicle_class_index_of_vehicle_[vehicle];
1192  }
1194  int GetVehicleClassesCount() const { return vehicle_classes_.size(); }
1196  const std::vector<int>& GetSameVehicleIndicesOfIndex(int node) const {
1197  DCHECK(closed_);
1198  return same_vehicle_groups_[same_vehicle_group_[node]];
1199  }
1218  bool ArcIsMoreConstrainedThanArc(int64 from, int64 to1, int64 to2);
1224  const Assignment& solution_assignment,
1225  const std::string& dimension_to_print) const;
1226 
1229  Solver* solver() const { return solver_.get(); }
1230 
1232  bool CheckLimit() {
1233  DCHECK(limit_ != nullptr);
1234  return limit_->Check();
1235  }
1236 
1238  absl::Duration RemainingTime() const {
1239  DCHECK(limit_ != nullptr);
1240  return limit_->AbsoluteSolverDeadline() - solver_->Now();
1241  }
1242 
1245  int nodes() const { return nodes_; }
1247  int vehicles() const { return vehicles_; }
1249  int64 Size() const { return nodes_ + vehicles_ - start_end_count_; }
1250 
1254  const RoutingSearchParameters& search_parameters) const;
1256  const RoutingSearchParameters& search_parameters) const;
1258  operations_research::FirstSolutionStrategy::Value
1260  return automatic_first_solution_strategy_;
1261  }
1262 
1264  bool IsMatchingModel() const;
1265 
1266 #ifndef SWIG
1267  using GetTabuVarsCallback =
1270  std::function<std::vector<operations_research::IntVar*>(RoutingModel*)>;
1271 
1272  void SetTabuVarsCallback(GetTabuVarsCallback tabu_var_callback);
1273 #endif // SWIG
1274 
1276  // TODO(user): Find a way to test and restrict the access at the same time.
1288  DecisionBuilder* MakeGuidedSlackFinalizer(
1289  const RoutingDimension* dimension,
1290  std::function<int64(int64)> initializer);
1291 #ifndef SWIG
1292  // TODO(user): MakeGreedyDescentLSOperator is too general for routing.h.
1297  static std::unique_ptr<LocalSearchOperator> MakeGreedyDescentLSOperator(
1298  std::vector<IntVar*> variables);
1299 #endif
1300  DecisionBuilder* MakeSelfDependentDimensionFinalizer(
1314  const RoutingDimension* dimension);
1315 
1316  private:
1318  enum RoutingLocalSearchOperator {
1319  RELOCATE = 0,
1320  RELOCATE_PAIR,
1321  LIGHT_RELOCATE_PAIR,
1322  RELOCATE_NEIGHBORS,
1323  EXCHANGE,
1324  EXCHANGE_PAIR,
1325  CROSS,
1326  CROSS_EXCHANGE,
1327  TWO_OPT,
1328  OR_OPT,
1329  GLOBAL_CHEAPEST_INSERTION_PATH_LNS,
1330  LOCAL_CHEAPEST_INSERTION_PATH_LNS,
1331  GLOBAL_CHEAPEST_INSERTION_EXPENSIVE_CHAIN_LNS,
1332  LOCAL_CHEAPEST_INSERTION_EXPENSIVE_CHAIN_LNS,
1333  RELOCATE_EXPENSIVE_CHAIN,
1334  LIN_KERNIGHAN,
1335  TSP_OPT,
1336  MAKE_ACTIVE,
1337  RELOCATE_AND_MAKE_ACTIVE,
1338  MAKE_ACTIVE_AND_RELOCATE,
1339  MAKE_INACTIVE,
1340  MAKE_CHAIN_INACTIVE,
1341  SWAP_ACTIVE,
1342  EXTENDED_SWAP_ACTIVE,
1343  NODE_PAIR_SWAP,
1344  PATH_LNS,
1345  FULL_PATH_LNS,
1346  TSP_LNS,
1347  INACTIVE_LNS,
1348  EXCHANGE_RELOCATE_PAIR,
1349  RELOCATE_SUBTRIP,
1350  EXCHANGE_SUBTRIP,
1351  LOCAL_SEARCH_OPERATOR_COUNTER
1352  };
1353 
1357  template <typename T>
1358  struct ValuedNodes {
1359  std::vector<int64> indices;
1360  T value;
1361  };
1362  struct DisjunctionValues {
1363  int64 penalty;
1364  int64 max_cardinality;
1365  };
1366  typedef ValuedNodes<DisjunctionValues> Disjunction;
1367 
1370  struct CostCacheElement {
1375  int index;
1376  CostClassIndex cost_class_index;
1377  int64 cost;
1378  };
1379 
1381  void Initialize();
1382  void AddNoCycleConstraintInternal();
1383  bool AddDimensionWithCapacityInternal(
1384  const std::vector<int>& evaluator_indices, int64 slack_max,
1385  std::vector<int64> vehicle_capacities, bool fix_start_cumul_to_zero,
1386  const std::string& name);
1387  bool AddDimensionDependentDimensionWithVehicleCapacityInternal(
1388  const std::vector<int>& pure_transits,
1389  const std::vector<int>& dependent_transits,
1390  const RoutingDimension* base_dimension, int64 slack_max,
1391  std::vector<int64> vehicle_capacities, bool fix_start_cumul_to_zero,
1392  const std::string& name);
1393  bool InitializeDimensionInternal(
1394  const std::vector<int>& evaluator_indices,
1395  const std::vector<int>& state_dependent_evaluator_indices,
1396  int64 slack_max, bool fix_start_cumul_to_zero,
1397  RoutingDimension* dimension);
1398  DimensionIndex GetDimensionIndex(const std::string& dimension_name) const;
1399 
1427  void StoreDimensionCumulOptimizers(const RoutingSearchParameters& parameters);
1428 
1429  void ComputeCostClasses(const RoutingSearchParameters& parameters);
1430  void ComputeVehicleClasses();
1431  int64 GetArcCostForClassInternal(int64 from_index, int64 to_index,
1432  CostClassIndex cost_class_index) const;
1433  void AppendHomogeneousArcCosts(const RoutingSearchParameters& parameters,
1434  int node_index,
1435  std::vector<IntVar*>* cost_elements);
1436  void AppendArcCosts(const RoutingSearchParameters& parameters, int node_index,
1437  std::vector<IntVar*>* cost_elements);
1438  Assignment* DoRestoreAssignment();
1439  static const CostClassIndex kCostClassIndexOfZeroCost;
1440  int64 SafeGetCostClassInt64OfVehicle(int64 vehicle) const {
1441  DCHECK_LT(0, vehicles_);
1442  return (vehicle >= 0 ? GetCostClassIndexOfVehicle(vehicle)
1443  : kCostClassIndexOfZeroCost)
1444  .value();
1445  }
1446  int64 GetDimensionTransitCostSum(int64 i, int64 j,
1447  const CostClass& cost_class) const;
1449  IntVar* CreateDisjunction(DisjunctionIndex disjunction);
1451  void AddPickupAndDeliverySetsInternal(const std::vector<int64>& pickups,
1452  const std::vector<int64>& deliveries);
1455  IntVar* CreateSameVehicleCost(int vehicle_index);
1458  int FindNextActive(int index, const std::vector<int64>& indices) const;
1459 
1462  bool RouteCanBeUsedByVehicle(const Assignment& assignment, int start_index,
1463  int vehicle) const;
1471  bool ReplaceUnusedVehicle(int unused_vehicle, int active_vehicle,
1472  Assignment* compact_assignment) const;
1473 
1474  void QuietCloseModel();
1475  void QuietCloseModelWithParameters(
1476  const RoutingSearchParameters& parameters) {
1477  if (!closed_) {
1478  CloseModelWithParameters(parameters);
1479  }
1480  }
1481 
1483  bool SolveMatchingModel(Assignment* assignment,
1484  const RoutingSearchParameters& parameters);
1485 #ifndef SWIG
1486  bool AppendAssignmentIfFeasible(
1488  const Assignment& assignment,
1489  std::vector<std::unique_ptr<Assignment>>* assignments);
1490 #endif
1491  void LogSolution(const RoutingSearchParameters& parameters,
1493  const std::string& description, int64 solution_cost,
1494  int64 start_time_ms);
1497  Assignment* CompactAssignmentInternal(const Assignment& assignment,
1498  bool check_compact_assignment) const;
1503  std::string FindErrorInSearchParametersForModel(
1504  const RoutingSearchParameters& search_parameters) const;
1506  void SetupSearch(const RoutingSearchParameters& search_parameters);
1508  // TODO(user): Document each auxiliary method.
1509  Assignment* GetOrCreateAssignment();
1510  Assignment* GetOrCreateTmpAssignment();
1511  RegularLimit* GetOrCreateLimit();
1512  RegularLimit* GetOrCreateLocalSearchLimit();
1513  RegularLimit* GetOrCreateLargeNeighborhoodSearchLimit();
1514  RegularLimit* GetOrCreateFirstSolutionLargeNeighborhoodSearchLimit();
1515  LocalSearchOperator* CreateInsertionOperator();
1516  LocalSearchOperator* CreateMakeInactiveOperator();
1517  void CreateNeighborhoodOperators(const RoutingSearchParameters& parameters);
1518  LocalSearchOperator* GetNeighborhoodOperators(
1519  const RoutingSearchParameters& search_parameters) const;
1520  const std::vector<LocalSearchFilter*>& GetOrCreateLocalSearchFilters(
1521  const RoutingSearchParameters& parameters);
1522  const std::vector<LocalSearchFilter*>& GetOrCreateFeasibilityFilters(
1523  const RoutingSearchParameters& parameters);
1524  DecisionBuilder* CreateSolutionFinalizer(SearchLimit* lns_limit);
1525  DecisionBuilder* CreateFinalizerForMinimizedAndMaximizedVariables();
1526  void CreateFirstSolutionDecisionBuilders(
1527  const RoutingSearchParameters& search_parameters);
1528  DecisionBuilder* GetFirstSolutionDecisionBuilder(
1529  const RoutingSearchParameters& search_parameters) const;
1530  IntVarFilteredDecisionBuilder* GetFilteredFirstSolutionDecisionBuilderOrNull(
1531  const RoutingSearchParameters& parameters) const;
1532  LocalSearchPhaseParameters* CreateLocalSearchParameters(
1533  const RoutingSearchParameters& search_parameters);
1534  DecisionBuilder* CreateLocalSearchDecisionBuilder(
1535  const RoutingSearchParameters& search_parameters);
1536  void SetupDecisionBuilders(const RoutingSearchParameters& search_parameters);
1537  void SetupMetaheuristics(const RoutingSearchParameters& search_parameters);
1538  void SetupAssignmentCollector(
1539  const RoutingSearchParameters& search_parameters);
1540  void SetupTrace(const RoutingSearchParameters& search_parameters);
1541  void SetupSearchMonitors(const RoutingSearchParameters& search_parameters);
1542  bool UsesLightPropagation(
1543  const RoutingSearchParameters& search_parameters) const;
1544  GetTabuVarsCallback tabu_var_callback_;
1545 
1546  int GetVehicleStartClass(int64 start) const;
1547 
1548  void InitSameVehicleGroups(int number_of_groups) {
1549  same_vehicle_group_.assign(Size(), 0);
1550  same_vehicle_groups_.assign(number_of_groups, {});
1551  }
1552  void SetSameVehicleGroup(int index, int group) {
1553  same_vehicle_group_[index] = group;
1554  same_vehicle_groups_[group].push_back(index);
1555  }
1556 
1558  std::unique_ptr<Solver> solver_;
1559  int nodes_;
1560  int vehicles_;
1561  Constraint* no_cycle_constraint_ = nullptr;
1563  std::vector<IntVar*> nexts_;
1564  std::vector<IntVar*> vehicle_vars_;
1565  std::vector<IntVar*> active_;
1566  std::vector<IntVar*> vehicle_costs_considered_;
1571  std::vector<IntVar*> is_bound_to_end_;
1572  mutable RevSwitch is_bound_to_end_ct_added_;
1574  absl::flat_hash_map<std::string, DimensionIndex> dimension_name_to_index_;
1575  gtl::ITIVector<DimensionIndex, RoutingDimension*> dimensions_;
1576  // clang-format off
1580  std::vector<std::unique_ptr<GlobalDimensionCumulOptimizer> >
1581  global_dimension_optimizers_;
1582  gtl::ITIVector<DimensionIndex, int> global_optimizer_index_;
1583  std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >
1584  local_dimension_optimizers_;
1585  std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >
1586  local_dimension_mp_optimizers_;
1587  // clang-format off
1588  gtl::ITIVector<DimensionIndex, int> local_optimizer_index_;
1589  std::string primary_constrained_dimension_;
1591  IntVar* cost_ = nullptr;
1592  std::vector<int> vehicle_to_transit_cost_;
1593  std::vector<int64> fixed_cost_of_vehicle_;
1594  std::vector<CostClassIndex> cost_class_index_of_vehicle_;
1595  bool has_vehicle_with_zero_cost_class_;
1596  std::vector<int64> linear_cost_factor_of_vehicle_;
1597  std::vector<int64> quadratic_cost_factor_of_vehicle_;
1598  bool vehicle_amortized_cost_factors_set_;
1609  std::vector<bool> consider_empty_route_costs_;
1610 #ifndef SWIG
1611  gtl::ITIVector<CostClassIndex, CostClass> cost_classes_;
1612 #endif // SWIG
1613  bool costs_are_homogeneous_across_vehicles_;
1614  bool cache_callbacks_;
1615  mutable std::vector<CostCacheElement> cost_cache_;
1616  std::vector<VehicleClassIndex> vehicle_class_index_of_vehicle_;
1617 #ifndef SWIG
1618  gtl::ITIVector<VehicleClassIndex, VehicleClass> vehicle_classes_;
1619 #endif // SWIG
1620  std::function<int(int64)> vehicle_start_class_callback_;
1622  gtl::ITIVector<DisjunctionIndex, Disjunction> disjunctions_;
1623  std::vector<std::vector<DisjunctionIndex> > index_to_disjunctions_;
1625  std::vector<ValuedNodes<int64> > same_vehicle_costs_;
1627 #ifndef SWIG
1628  std::vector<absl::flat_hash_set<int>> allowed_vehicles_;
1629 #endif // SWIG
1630  IndexPairs pickup_delivery_pairs_;
1632  std::vector<std::pair<DisjunctionIndex, DisjunctionIndex> >
1633  pickup_delivery_disjunctions_;
1634  // clang-format off
1635  // If node_index is a pickup, index_to_pickup_index_pairs_[node_index] is the
1636  // vector of pairs {pair_index, pickup_index} such that
1637  // (pickup_delivery_pairs_[pair_index].first)[pickup_index] == node_index
1638  std::vector<std::vector<std::pair<int, int> > > index_to_pickup_index_pairs_;
1639  // Same as above for deliveries.
1640  std::vector<std::vector<std::pair<int, int> > >
1641  index_to_delivery_index_pairs_;
1642  // clang-format on
1643  std::vector<PickupAndDeliveryPolicy> vehicle_pickup_delivery_policy_;
1644  // Same vehicle group to which a node belongs.
1645  std::vector<int> same_vehicle_group_;
1646  // Same vehicle node groups.
1647  std::vector<std::vector<int>> same_vehicle_groups_;
1648  // Node visit types
1649  // Variable index to visit type index.
1650  std::vector<int> index_to_visit_type_;
1651  // Variable index to VisitTypePolicy.
1652  std::vector<VisitTypePolicy> index_to_type_policy_;
1653  // clang-format off
1654  std::vector<absl::flat_hash_set<int> >
1655  hard_incompatible_types_per_type_index_;
1656  bool has_hard_type_incompatibilities_;
1657  std::vector<absl::flat_hash_set<int> >
1658  temporal_incompatible_types_per_type_index_;
1659  bool has_temporal_type_incompatibilities_;
1660 
1661  std::vector<std::vector<absl::flat_hash_set<int> > >
1662  same_vehicle_required_type_alternatives_per_type_index_;
1663  bool has_same_vehicle_type_requirements_;
1664  std::vector<std::vector<absl::flat_hash_set<int> > >
1665  required_type_alternatives_when_adding_type_index_;
1666  std::vector<std::vector<absl::flat_hash_set<int> > >
1667  required_type_alternatives_when_removing_type_index_;
1668  bool has_temporal_type_requirements_;
1669  absl::flat_hash_map</*type*/int, absl::flat_hash_set<VisitTypePolicy> >
1670  trivially_infeasible_visit_types_to_policies_;
1671  // clang-format on
1672  int num_visit_types_;
1673  // Two indices are equivalent if they correspond to the same node (as given
1674  // to the constructors taking a RoutingIndexManager).
1675  std::vector<int> index_to_equivalence_class_;
1676  std::vector<int> index_to_vehicle_;
1677  std::vector<int64> starts_;
1678  std::vector<int64> ends_;
1679  // TODO(user): b/62478706 Once the port is done, this shouldn't be needed
1680  // anymore.
1681  RoutingIndexManager manager_;
1682  int start_end_count_;
1683  // Model status
1684  bool closed_ = false;
1685  Status status_ = ROUTING_NOT_SOLVED;
1686  bool enable_deep_serialization_ = true;
1687 
1688  // Search data
1689  std::vector<DecisionBuilder*> first_solution_decision_builders_;
1690  std::vector<IntVarFilteredDecisionBuilder*>
1691  first_solution_filtered_decision_builders_;
1692  Solver::IndexEvaluator2 first_solution_evaluator_;
1693  FirstSolutionStrategy::Value automatic_first_solution_strategy_ =
1694  FirstSolutionStrategy::UNSET;
1695  std::vector<LocalSearchOperator*> local_search_operators_;
1696  std::vector<SearchMonitor*> monitors_;
1697  SolutionCollector* collect_assignments_ = nullptr;
1698  SolutionCollector* collect_one_assignment_ = nullptr;
1699  SolutionCollector* packed_dimensions_assignment_collector_ = nullptr;
1700  DecisionBuilder* solve_db_ = nullptr;
1701  DecisionBuilder* improve_db_ = nullptr;
1702  DecisionBuilder* restore_assignment_ = nullptr;
1703  DecisionBuilder* restore_tmp_assignment_ = nullptr;
1704  Assignment* assignment_ = nullptr;
1705  Assignment* preassignment_ = nullptr;
1706  Assignment* tmp_assignment_ = nullptr;
1707  std::vector<IntVar*> extra_vars_;
1708  std::vector<IntervalVar*> extra_intervals_;
1709  std::vector<LocalSearchOperator*> extra_operators_;
1710  std::vector<LocalSearchFilter*> filters_;
1711  std::vector<LocalSearchFilter*> feasibility_filters_;
1712  std::vector<LocalSearchFilter*> extra_filters_;
1713 #ifndef SWIG
1714  std::vector<std::pair<IntVar*, int64>> finalizer_variable_cost_pairs_;
1715  std::vector<std::pair<IntVar*, int64>> finalizer_variable_target_pairs_;
1716  absl::flat_hash_map<IntVar*, int> finalizer_variable_cost_index_;
1717  absl::flat_hash_set<IntVar*> finalizer_variable_target_set_;
1718  std::unique_ptr<SweepArranger> sweep_arranger_;
1719 #endif
1720 
1721  RegularLimit* limit_ = nullptr;
1722  RegularLimit* ls_limit_ = nullptr;
1723  RegularLimit* lns_limit_ = nullptr;
1724  RegularLimit* first_solution_lns_limit_ = nullptr;
1725 
1726  typedef std::pair<int64, int64> CacheKey;
1727  typedef absl::flat_hash_map<CacheKey, int64> TransitCallbackCache;
1728  typedef absl::flat_hash_map<CacheKey, StateDependentTransit>
1729  StateDependentTransitCallbackCache;
1730 
1731  std::vector<TransitCallback1> unary_transit_evaluators_;
1732  std::vector<TransitCallback2> transit_evaluators_;
1733  // The following vector stores a boolean per transit_evaluator_, indicating
1734  // whether the transits are all positive.
1735  // is_transit_evaluator_positive_ will be set to true only when registering a
1736  // callback via RegisterPositiveTransitCallback(), and to false otherwise.
1737  // The actual positivity of the transit values will only be checked in debug
1738  // mode, when calling RegisterPositiveTransitCallback().
1739  // Therefore, RegisterPositiveTransitCallback() should only be called when the
1740  // transits are known to be positive, as the positivity of a callback will
1741  // allow some improvements in the solver, but will entail in errors if the
1742  // transits are falsely assumed positive.
1743  std::vector<bool> is_transit_evaluator_positive_;
1744  std::vector<VariableIndexEvaluator2> state_dependent_transit_evaluators_;
1745  std::vector<std::unique_ptr<StateDependentTransitCallbackCache>>
1746  state_dependent_transit_evaluators_cache_;
1747 
1748  friend class RoutingDimension;
1750 
1751  DISALLOW_COPY_AND_ASSIGN(RoutingModel);
1752 };
1753 
1755 class RoutingModelVisitor : public BaseObject {
1756  public:
1758  static const char kLightElement[];
1759  static const char kLightElement2[];
1760  static const char kRemoveValues[];
1761 };
1762 
1763 #if !defined(SWIG)
1764 class DisjunctivePropagator {
1767  public:
1773  struct Tasks {
1775  std::vector<int64> start_min;
1776  std::vector<int64> start_max;
1777  std::vector<int64> duration_min;
1778  std::vector<int64> duration_max;
1779  std::vector<int64> end_min;
1780  std::vector<int64> end_max;
1781  std::vector<bool> is_preemptible;
1782  std::vector<const SortedDisjointIntervalList*> forbidden_intervals;
1783  std::vector<std::pair<int64, int64>> distance_duration;
1784 
1785  void Clear() {
1786  start_min.clear();
1787  start_max.clear();
1788  duration_min.clear();
1789  duration_max.clear();
1790  end_min.clear();
1791  end_max.clear();
1792  is_preemptible.clear();
1793  forbidden_intervals.clear();
1794  distance_duration.clear();
1795  }
1796  };
1797 
1800  bool Propagate(Tasks* tasks);
1801 
1803  bool Precedences(Tasks* tasks);
1806  bool MirrorTasks(Tasks* tasks);
1808  bool EdgeFinding(Tasks* tasks);
1814  bool DistanceDuration(Tasks* tasks);
1815 
1816  private:
1819  sat::ThetaLambdaTree<int64> theta_lambda_tree_;
1821  std::vector<int> tasks_by_start_min_;
1822  std::vector<int> tasks_by_end_max_;
1823  std::vector<int> event_of_task_;
1824  std::vector<int> nonchain_tasks_by_start_max_;
1825 };
1826 
1827 void AppendTasksFromPath(const std::vector<int64>& path,
1828  const std::vector<int64>& min_travels,
1829  const std::vector<int64>& max_travels,
1830  const std::vector<int64>& pre_travels,
1831  const std::vector<int64>& post_travels,
1832  const RoutingDimension& dimension,
1834 void AppendTasksFromIntervals(const std::vector<IntervalVar*>& intervals,
1836 void FillPathEvaluation(const std::vector<int64>& path,
1837  const RoutingModel::TransitCallback2& evaluator,
1838  std::vector<int64>* values);
1839 #endif // !defined(SWIG)
1840 
1851 class GlobalVehicleBreaksConstraint : public Constraint {
1852  public:
1854  std::string DebugString() const override {
1855  return "GlobalVehicleBreaksConstraint";
1856  }
1857 
1858  void Post() override;
1859  void InitialPropagate() override;
1860 
1861  private:
1862  void PropagateNode(int node);
1863  void PropagateVehicle(int vehicle);
1864  void PropagateMaxBreakDistance(int vehicle);
1865 
1866  const RoutingModel* model_;
1867  const RoutingDimension* const dimension_;
1868  std::vector<Demon*> vehicle_demons_;
1869  std::vector<int64> path_;
1870 
1875  void FillPartialPathOfVehicle(int vehicle);
1876  void FillPathTravels(const std::vector<int64>& path);
1877 
1888  class TaskTranslator {
1889  public:
1890  TaskTranslator(IntVar* start, int64 before_start, int64 after_start)
1891  : start_(start),
1892  before_start_(before_start),
1893  after_start_(after_start) {}
1894  explicit TaskTranslator(IntervalVar* interval) : interval_(interval) {}
1895  TaskTranslator() {}
1896 
1897  void SetStartMin(int64 value) {
1898  if (start_ != nullptr) {
1899  start_->SetMin(CapAdd(before_start_, value));
1900  } else if (interval_ != nullptr) {
1901  interval_->SetStartMin(value);
1902  }
1903  }
1904  void SetStartMax(int64 value) {
1905  if (start_ != nullptr) {
1906  start_->SetMax(CapAdd(before_start_, value));
1907  } else if (interval_ != nullptr) {
1908  interval_->SetStartMax(value);
1909  }
1910  }
1911  void SetDurationMin(int64 value) {
1912  if (interval_ != nullptr) {
1913  interval_->SetDurationMin(value);
1914  }
1915  }
1916  void SetEndMin(int64 value) {
1917  if (start_ != nullptr) {
1918  start_->SetMin(CapSub(value, after_start_));
1919  } else if (interval_ != nullptr) {
1920  interval_->SetEndMin(value);
1921  }
1922  }
1923  void SetEndMax(int64 value) {
1924  if (start_ != nullptr) {
1925  start_->SetMax(CapSub(value, after_start_));
1926  } else if (interval_ != nullptr) {
1927  interval_->SetEndMax(value);
1928  }
1929  }
1930 
1931  private:
1932  IntVar* start_ = nullptr;
1933  int64 before_start_;
1934  int64 after_start_;
1935  IntervalVar* interval_ = nullptr;
1936  };
1937 
1939  std::vector<TaskTranslator> task_translators_;
1940 
1942  DisjunctivePropagator disjunctive_propagator_;
1943  DisjunctivePropagator::Tasks tasks_;
1944 
1946  std::vector<int64> min_travel_;
1947  std::vector<int64> max_travel_;
1948  std::vector<int64> pre_travel_;
1949  std::vector<int64> post_travel_;
1950 };
1951 
1953  public:
1954  explicit TypeRegulationsChecker(const RoutingModel& model);
1956 
1957  bool CheckVehicle(int vehicle,
1958  const std::function<int64(int64)>& next_accessor);
1959 
1960  protected:
1961 #ifndef SWIG
1963 #endif // SWIG
1964 
1981  };
1982 
1987  bool TypeOccursOnRoute(int type) const;
1994  bool TypeCurrentlyOnRoute(int type, int pos) const;
1995 
1996  void InitializeCheck(int vehicle,
1997  const std::function<int64(int64)>& next_accessor);
1998  virtual void OnInitializeCheck() {}
1999  virtual bool HasRegulationsToCheck() const = 0;
2000  virtual bool CheckTypeRegulations(int type, VisitTypePolicy policy,
2001  int pos) = 0;
2002  virtual bool FinalizeCheck() const { return true; }
2003 
2005 
2006  private:
2007  std::vector<TypePolicyOccurrence> occurrences_of_type_;
2008  std::vector<int64> current_route_visits_;
2009 };
2010 
2013  public:
2015  bool check_hard_incompatibilities);
2017 
2018  private:
2019  bool HasRegulationsToCheck() const override;
2020  bool CheckTypeRegulations(int type, VisitTypePolicy policy, int pos) override;
2024  bool check_hard_incompatibilities_;
2025 };
2026 
2029  public:
2030  explicit TypeRequirementChecker(const RoutingModel& model)
2031  : TypeRegulationsChecker(model) {}
2033 
2034  private:
2035  bool HasRegulationsToCheck() const override;
2036  void OnInitializeCheck() override {
2037  types_with_same_vehicle_requirements_on_route_.clear();
2038  }
2039  // clang-format off
2042  bool CheckRequiredTypesCurrentlyOnRoute(
2043  const std::vector<absl::flat_hash_set<int> >& required_type_alternatives,
2044  int pos);
2045  // clang-format on
2046  bool CheckTypeRegulations(int type, VisitTypePolicy policy, int pos) override;
2047  bool FinalizeCheck() const override;
2048 
2049  absl::flat_hash_set<int> types_with_same_vehicle_requirements_on_route_;
2050 };
2051 
2092 class TypeRegulationsConstraint : public Constraint {
2093  public:
2094  explicit TypeRegulationsConstraint(const RoutingModel& model);
2095 
2096  void Post() override;
2097  void InitialPropagate() override;
2098 
2099  private:
2100  void PropagateNodeRegulations(int node);
2101  void CheckRegulationsOnVehicle(int vehicle);
2102 
2103  const RoutingModel& model_;
2104  TypeIncompatibilityChecker incompatibility_checker_;
2105  TypeRequirementChecker requirement_checker_;
2106  std::vector<Demon*> vehicle_demons_;
2107 };
2108 #if !defined SWIG
2109 class SimpleBoundCosts {
2122  public:
2123  struct BoundCost {
2124  int64 bound;
2125  int64 cost;
2126  };
2127  SimpleBoundCosts(int num_bounds, BoundCost default_bound_cost)
2128  : bound_costs_(num_bounds, default_bound_cost) {}
2129  BoundCost& bound_cost(int element) { return bound_costs_[element]; }
2130  BoundCost bound_cost(int element) const { return bound_costs_[element]; }
2131  int Size() { return bound_costs_.size(); }
2134 
2135  private:
2136  std::vector<BoundCost> bound_costs_;
2137 };
2138 #endif // !defined SWIG
2139 
2157 // TODO(user): Break constraints need to know the service time of nodes
2161  public:
2164  RoutingModel* model() const { return model_; }
2168  int64 GetTransitValue(int64 from_index, int64 to_index, int64 vehicle) const;
2171  int64 GetTransitValueFromClass(int64 from_index, int64 to_index,
2172  int64 vehicle_class) const {
2173  return model_->TransitCallback(class_evaluators_[vehicle_class])(from_index,
2174  to_index);
2175  }
2178  IntVar* CumulVar(int64 index) const { return cumuls_[index]; }
2179  IntVar* TransitVar(int64 index) const { return transits_[index]; }
2180  IntVar* FixedTransitVar(int64 index) const { return fixed_transits_[index]; }
2181  IntVar* SlackVar(int64 index) const { return slacks_[index]; }
2182 
2183 #if !defined(SWIGPYTHON)
2184  const std::vector<IntVar*>& cumuls() const { return cumuls_; }
2187  const std::vector<IntVar*>& fixed_transits() const { return fixed_transits_; }
2188  const std::vector<IntVar*>& transits() const { return transits_; }
2189  const std::vector<IntVar*>& slacks() const { return slacks_; }
2190 #if !defined(SWIGCSHARP) && !defined(SWIGJAVA)
2191  const std::vector<SortedDisjointIntervalList>& forbidden_intervals() const {
2193  return forbidden_intervals_;
2194  }
2196  SortedDisjointIntervalList GetAllowedIntervalsInRange(int64 index,
2197  int64 min_value,
2198  int64 max_value) const;
2202  int64 min_value) const {
2203  DCHECK_LT(index, forbidden_intervals_.size());
2204  const SortedDisjointIntervalList& forbidden_intervals =
2205  forbidden_intervals_[index];
2206  const auto first_forbidden_interval_it =
2207  forbidden_intervals.FirstIntervalGreaterOrEqual(min_value);
2208  if (first_forbidden_interval_it != forbidden_intervals.end() &&
2209  min_value >= first_forbidden_interval_it->start) {
2211  return CapAdd(first_forbidden_interval_it->end, 1);
2212  }
2214  return min_value;
2215  }
2221  int64 max_value) const {
2222  DCHECK_LT(index, forbidden_intervals_.size());
2223  const SortedDisjointIntervalList& forbidden_intervals =
2224  forbidden_intervals_[index];
2225  const auto last_forbidden_interval_it =
2226  forbidden_intervals.LastIntervalLessOrEqual(max_value);
2227  if (last_forbidden_interval_it != forbidden_intervals.end() &&
2228  max_value <= last_forbidden_interval_it->end) {
2230  return CapSub(last_forbidden_interval_it->start, 1);
2231  }
2233  return max_value;
2234  }
2236  const std::vector<int64>& vehicle_capacities() const {
2237  return vehicle_capacities_;
2238  }
2242  return model_->TransitCallback(
2243  class_evaluators_[vehicle_to_class_[vehicle]]);
2244  }
2249  int vehicle) const {
2250  return model_->UnaryTransitCallbackOrNull(
2251  class_evaluators_[vehicle_to_class_[vehicle]]);
2252  }
2255  bool AreVehicleTransitsPositive(int vehicle) const {
2256  return model()->is_transit_evaluator_positive_
2257  [class_evaluators_[vehicle_to_class_[vehicle]]];
2258  }
2259  int vehicle_to_class(int vehicle) const { return vehicle_to_class_[vehicle]; }
2260 #endif
2261 #endif
2262  void SetSpanUpperBoundForVehicle(int64 upper_bound, int vehicle);
2266  void SetSpanCostCoefficientForVehicle(int64 coefficient, int vehicle);
2273  void SetSpanCostCoefficientForAllVehicles(int64 coefficient);
2280  void SetGlobalSpanCostCoefficient(int64 coefficient);
2281 
2282 #ifndef SWIG
2283  void SetCumulVarPiecewiseLinearCost(int64 index,
2288  const PiecewiseLinearFunction& cost);
2291  bool HasCumulVarPiecewiseLinearCost(int64 index) const;
2294  const PiecewiseLinearFunction* GetCumulVarPiecewiseLinearCost(
2295  int64 index) const;
2296 #endif
2297 
2306  void SetCumulVarSoftUpperBound(int64 index, int64 upper_bound,
2307  int64 coefficient);
2310  bool HasCumulVarSoftUpperBound(int64 index) const;
2314  int64 GetCumulVarSoftUpperBound(int64 index) const;
2318  int64 GetCumulVarSoftUpperBoundCoefficient(int64 index) const;
2319 
2332  void SetCumulVarSoftLowerBound(int64 index, int64 lower_bound,
2333  int64 coefficient);
2336  bool HasCumulVarSoftLowerBound(int64 index) const;
2340  int64 GetCumulVarSoftLowerBound(int64 index) const;
2344  int64 GetCumulVarSoftLowerBoundCoefficient(int64 index) const;
2360  // TODO(user): Remove if !defined when routing.i is repaired.
2361 #if !defined(SWIGPYTHON)
2362  void SetBreakIntervalsOfVehicle(std::vector<IntervalVar*> breaks, int vehicle,
2363  int pre_travel_evaluator,
2364  int post_travel_evaluator);
2365 #endif // !defined(SWIGPYTHON)
2366 
2368  void SetBreakIntervalsOfVehicle(std::vector<IntervalVar*> breaks, int vehicle,
2369  std::vector<int64> node_visit_transits);
2370 
2375  void SetBreakDistanceDurationOfVehicle(int64 distance, int64 duration,
2376  int vehicle);
2381  bool HasBreakConstraints() const;
2382 #if !defined(SWIGPYTHON)
2386  std::vector<IntervalVar*> breaks, int vehicle,
2387  std::vector<int64> node_visit_transits,
2388  std::function<int64(int64, int64)> group_delays);
2389 
2391  const std::vector<IntervalVar*>& GetBreakIntervalsOfVehicle(
2392  int vehicle) const;
2395  // clang-format off
2396  const std::vector<std::pair<int64, int64> >&
2398  // clang-format on
2399 #endif
2400  int GetPreTravelEvaluatorOfVehicle(int vehicle) const;
2401  int GetPostTravelEvaluatorOfVehicle(int vehicle) const;
2402 
2404  const RoutingDimension* base_dimension() const { return base_dimension_; }
2412  int64 ShortestTransitionSlack(int64 node) const;
2413 
2415  const std::string& name() const { return name_; }
2416 
2418 #ifndef SWIG
2419  const ReverseArcListGraph<int, int>& GetPathPrecedenceGraph() const {
2420  return path_precedence_graph_;
2421  }
2422 #endif // SWIG
2423 
2433  typedef std::function<int64(int, int)> PickupToDeliveryLimitFunction;
2434 
2436  PickupToDeliveryLimitFunction limit_function, int pair_index);
2437 
2439 #ifndef SWIG
2440  int64 GetPickupToDeliveryLimitForPair(int pair_index, int pickup,
2441  int delivery) const;
2442 
2444  int64 first_node;
2446  int64 offset;
2447  };
2448 
2450  node_precedences_.push_back(precedence);
2451  }
2452  const std::vector<NodePrecedence>& GetNodePrecedences() const {
2453  return node_precedences_;
2454  }
2455 #endif // SWIG
2456 
2457  void AddNodePrecedence(int64 first_node, int64 second_node, int64 offset) {
2458  AddNodePrecedence({first_node, second_node, offset});
2459  }
2460 
2461  int64 GetSpanUpperBoundForVehicle(int vehicle) const {
2462  return vehicle_span_upper_bounds_[vehicle];
2463  }
2464 #ifndef SWIG
2465  const std::vector<int64>& vehicle_span_upper_bounds() const {
2466  return vehicle_span_upper_bounds_;
2467  }
2468 #endif // SWIG
2469  int64 GetSpanCostCoefficientForVehicle(int vehicle) const {
2470  return vehicle_span_cost_coefficients_[vehicle];
2471  }
2472 #ifndef SWIG
2473  const std::vector<int64>& vehicle_span_cost_coefficients() const {
2474  return vehicle_span_cost_coefficients_;
2475  }
2476 #endif // SWIG
2478  return global_span_cost_coefficient_;
2479  }
2480 
2482  DCHECK_GE(global_optimizer_offset_, 0);
2483  return global_optimizer_offset_;
2484  }
2485  int64 GetLocalOptimizerOffsetForVehicle(int vehicle) const {
2486  if (vehicle >= local_optimizer_offset_for_vehicle_.size()) {
2487  return 0;
2488  }
2489  DCHECK_GE(local_optimizer_offset_for_vehicle_[vehicle], 0);
2490  return local_optimizer_offset_for_vehicle_[vehicle];
2491  }
2492 #if !defined SWIG
2496  int vehicle) {
2497  if (!HasSoftSpanUpperBounds()) {
2498  vehicle_soft_span_upper_bound_ = absl::make_unique<SimpleBoundCosts>(
2499  model_->vehicles(), SimpleBoundCosts::BoundCost{kint64max, 0});
2500  }
2501  vehicle_soft_span_upper_bound_->bound_cost(vehicle) = bound_cost;
2502  }
2503  bool HasSoftSpanUpperBounds() const {
2504  return vehicle_soft_span_upper_bound_ != nullptr;
2505  }
2507  int vehicle) const {
2508  DCHECK(HasSoftSpanUpperBounds());
2509  return vehicle_soft_span_upper_bound_->bound_cost(vehicle);
2510  }
2511 #endif
2512 
2513  private:
2514  struct SoftBound {
2515  IntVar* var;
2516  int64 bound;
2517  int64 coefficient;
2518  };
2519 
2520  struct PiecewiseLinearCost {
2521  PiecewiseLinearCost() : var(nullptr), cost(nullptr) {}
2522  IntVar* var;
2523  std::unique_ptr<PiecewiseLinearFunction> cost;
2524  };
2525 
2526  class SelfBased {};
2527  RoutingDimension(RoutingModel* model, std::vector<int64> vehicle_capacities,
2528  const std::string& name,
2529  const RoutingDimension* base_dimension);
2530  RoutingDimension(RoutingModel* model, std::vector<int64> vehicle_capacities,
2531  const std::string& name, SelfBased);
2532  void Initialize(const std::vector<int>& transit_evaluators,
2533  const std::vector<int>& state_dependent_transit_evaluators,
2534  int64 slack_max);
2535  void InitializeCumuls();
2536  void InitializeTransits(
2537  const std::vector<int>& transit_evaluators,
2538  const std::vector<int>& state_dependent_transit_evaluators,
2539  int64 slack_max);
2540  void InitializeTransitVariables(int64 slack_max);
2542  void SetupCumulVarSoftUpperBoundCosts(
2543  std::vector<IntVar*>* cost_elements) const;
2545  void SetupCumulVarSoftLowerBoundCosts(
2546  std::vector<IntVar*>* cost_elements) const;
2547  void SetupCumulVarPiecewiseLinearCosts(
2548  std::vector<IntVar*>* cost_elements) const;
2551  void SetupGlobalSpanCost(std::vector<IntVar*>* cost_elements) const;
2552  void SetupSlackAndDependentTransitCosts() const;
2554  void CloseModel(bool use_light_propagation);
2555 
2556  void SetOffsetForGlobalOptimizer(int64 offset) {
2557  global_optimizer_offset_ = std::max(Zero(), offset);
2558  }
2560  void SetVehicleOffsetsForLocalOptimizer(std::vector<int64> offsets) {
2562  std::transform(offsets.begin(), offsets.end(), offsets.begin(),
2563  [](int64 offset) { return std::max(Zero(), offset); });
2564  local_optimizer_offset_for_vehicle_ = std::move(offsets);
2565  }
2566 
2567  std::vector<IntVar*> cumuls_;
2568  std::vector<SortedDisjointIntervalList> forbidden_intervals_;
2569  std::vector<IntVar*> capacity_vars_;
2570  const std::vector<int64> vehicle_capacities_;
2571  std::vector<IntVar*> transits_;
2572  std::vector<IntVar*> fixed_transits_;
2575  std::vector<int> class_evaluators_;
2576  std::vector<int64> vehicle_to_class_;
2577 #ifndef SWIG
2578  ReverseArcListGraph<int, int> path_precedence_graph_;
2579 #endif
2580  // For every {first_node, second_node, offset} element in node_precedences_,
2581  // if both first_node and second_node are performed, then
2582  // cumuls_[second_node] must be greater than (or equal to)
2583  // cumuls_[first_node] + offset.
2584  std::vector<NodePrecedence> node_precedences_;
2585 
2586  // The transits of a dimension may depend on its cumuls or the cumuls of
2587  // another dimension. There can be no cycles, except for self loops, a
2588  // typical example for this is a time dimension.
2589  const RoutingDimension* const base_dimension_;
2590 
2591  // Values in state_dependent_class_evaluators_ correspond to the evaluators
2592  // in RoutingModel::state_dependent_transit_evaluators_ for each vehicle
2593  // class.
2594  std::vector<int> state_dependent_class_evaluators_;
2595  std::vector<int64> state_dependent_vehicle_to_class_;
2596 
2597  // For each pickup/delivery pair_index for which limits have been set,
2598  // pickup_to_delivery_limits_per_pair_index_[pair_index] contains the
2599  // PickupToDeliveryLimitFunction for the pickup and deliveries in this pair.
2600  std::vector<PickupToDeliveryLimitFunction>
2601  pickup_to_delivery_limits_per_pair_index_;
2602 
2603  // Used if some vehicle has breaks in this dimension, typically time.
2604  bool break_constraints_are_initialized_ = false;
2605  // clang-format off
2606  std::vector<std::vector<IntervalVar*> > vehicle_break_intervals_;
2607  std::vector<std::vector<std::pair<int64, int64> > >
2608  vehicle_break_distance_duration_;
2609  // clang-format on
2610  // For each vehicle, stores the part of travel that is made directly
2611  // after (before) the departure (arrival) node of the travel.
2612  // These parts of the travel are non-interruptible, in particular by a break.
2613  std::vector<int> vehicle_pre_travel_evaluators_;
2614  std::vector<int> vehicle_post_travel_evaluators_;
2615 
2616  std::vector<IntVar*> slacks_;
2617  std::vector<IntVar*> dependent_transits_;
2618  std::vector<int64> vehicle_span_upper_bounds_;
2619  int64 global_span_cost_coefficient_;
2620  std::vector<int64> vehicle_span_cost_coefficients_;
2621  std::vector<SoftBound> cumul_var_soft_upper_bound_;
2622  std::vector<SoftBound> cumul_var_soft_lower_bound_;
2623  std::vector<PiecewiseLinearCost> cumul_var_piecewise_linear_cost_;
2624  RoutingModel* const model_;
2625  const std::string name_;
2626  int64 global_optimizer_offset_;
2627  std::vector<int64> local_optimizer_offset_for_vehicle_;
2629  std::unique_ptr<SimpleBoundCosts> vehicle_soft_span_upper_bound_;
2630  friend class RoutingModel;
2632 
2633  DISALLOW_COPY_AND_ASSIGN(RoutingDimension);
2634 };
2635 
2636 #ifndef SWIG
2637 class SweepArranger {
2640  public:
2641  explicit SweepArranger(const std::vector<std::pair<int64, int64>>& points);
2642  virtual ~SweepArranger() {}
2643  void ArrangeIndices(std::vector<int64>* indices);
2644  void SetSectors(int sectors) { sectors_ = sectors; }
2645 
2646  private:
2647  std::vector<int> coordinates_;
2648  int sectors_;
2649 
2650  DISALLOW_COPY_AND_ASSIGN(SweepArranger);
2651 };
2652 #endif
2653 
2656 DecisionBuilder* MakeSetValuesFromTargets(Solver* solver,
2657  std::vector<IntVar*> variables,
2658  std::vector<int64> targets);
2659 
2660 #ifndef SWIG
2661 
2675 // TODO(user): Eventually move this to the core CP solver library
2677 class IntVarFilteredDecisionBuilder : public DecisionBuilder {
2678  public:
2680  std::unique_ptr<IntVarFilteredHeuristic> heuristic);
2681 
2683 
2684  Decision* Next(Solver* solver) override;
2685 
2686  std::string DebugString() const override;
2687 
2689  int64 number_of_decisions() const;
2690  int64 number_of_rejects() const;
2691 
2692  private:
2693  const std::unique_ptr<IntVarFilteredHeuristic> heuristic_;
2694 };
2695 
2698  public:
2699  IntVarFilteredHeuristic(Solver* solver, const std::vector<IntVar*>& vars,
2700  const std::vector<LocalSearchFilter*>& filters);
2701 
2703 
2706  Assignment* const BuildSolution();
2707 
2710  int64 number_of_decisions() const { return number_of_decisions_; }
2711  int64 number_of_rejects() const { return number_of_rejects_; }
2712 
2713  virtual std::string DebugString() const { return "IntVarFilteredHeuristic"; }
2714 
2715  protected:
2719  virtual bool InitializeSolution() { return true; }
2721  virtual bool BuildSolutionInternal() = 0;
2725  bool Commit();
2727  virtual bool StopSearch() { return false; }
2730  void SetValue(int64 index, int64 value) {
2731  if (!is_in_delta_[index]) {
2732  delta_->FastAdd(vars_[index])->SetValue(value);
2733  delta_indices_.push_back(index);
2734  is_in_delta_[index] = true;
2735  } else {
2736  delta_->SetValue(vars_[index], value);
2737  }
2738  }
2741  int64 Value(int64 index) const {
2742  return assignment_->IntVarContainer().Element(index).Value();
2743  }
2745  bool Contains(int64 index) const {
2746  return assignment_->IntVarContainer().Element(index).Var() != nullptr;
2747  }
2750  int Size() const { return vars_.size(); }
2752  IntVar* Var(int64 index) const { return vars_[index]; }
2755 
2756  Assignment* const assignment_;
2757 
2758  private:
2761  bool FilterAccept();
2762 
2763  const std::vector<IntVar*> vars_;
2764  Assignment* const delta_;
2765  std::vector<int> delta_indices_;
2766  std::vector<bool> is_in_delta_;
2767  Assignment* const empty_;
2768  LocalSearchFilterManager filter_manager_;
2770  int64 number_of_decisions_;
2771  int64 number_of_rejects_;
2772 };
2773 
2776  public:
2778  const std::vector<LocalSearchFilter*>& filters);
2781  const Assignment* BuildSolutionFromRoutes(
2782  const std::function<int64(int64)>& next_accessor);
2783  RoutingModel* model() const { return model_; }
2785  int GetStartChainEnd(int vehicle) const { return start_chain_ends_[vehicle]; }
2787  int GetEndChainStart(int vehicle) const { return end_chain_starts_[vehicle]; }
2793 
2794  protected:
2795  bool StopSearch() override { return model_->CheckLimit(); }
2796  virtual void SetVehicleIndex(int64 node, int vehicle) {}
2797  virtual void ResetVehicleIndices() {}
2798 
2799  private:
2801  bool InitializeSolution() override;
2802 
2803  RoutingModel* const model_;
2804  std::vector<int64> start_chain_ends_;
2805  std::vector<int64> end_chain_starts_;
2806 };
2807 
2809  public:
2812  RoutingModel* model, std::function<int64(int64, int64, int64)> evaluator,
2813  std::function<int64(int64)> penalty_evaluator,
2814  const std::vector<LocalSearchFilter*>& filters);
2816 
2817  protected:
2818  typedef std::pair<int64, int64> ValuedPosition;
2819  struct StartEndValue {
2820  int64 distance;
2821  int vehicle;
2822 
2823  bool operator<(const StartEndValue& other) const {
2824  return std::tie(distance, vehicle) <
2825  std::tie(other.distance, other.vehicle);
2826  }
2827  };
2828  typedef std::pair<StartEndValue, /*seed_node*/ int> Seed;
2829 
2835  // clang-format off
2836  std::vector<std::vector<StartEndValue> >
2837  ComputeStartEndDistanceForVehicles(const std::vector<int>& vehicles);
2838 
2843  template <class Queue>
2845  std::vector<std::vector<StartEndValue> >* start_end_distances_per_node,
2846  Queue* priority_queue);
2847  // clang-format on
2848 
2853  void InsertBetween(int64 node, int64 predecessor, int64 successor);
2859  int64 node_to_insert, int64 start, int64 next_after_start, int64 vehicle,
2860  std::vector<ValuedPosition>* valued_positions);
2865  int64 GetInsertionCostForNodeAtPosition(int64 node_to_insert,
2866  int64 insert_after,
2867  int64 insert_before,
2868  int vehicle) const;
2871  int64 GetUnperformedValue(int64 node_to_insert) const;
2872 
2873  std::function<int64(int64, int64, int64)> evaluator_;
2874  std::function<int64(int64)> penalty_evaluator_;
2875 };
2876 
2886  public:
2900  };
2901 
2904  RoutingModel* model, std::function<int64(int64, int64, int64)> evaluator,
2905  std::function<int64(int64)> penalty_evaluator,
2906  const std::vector<LocalSearchFilter*>& filters,
2909  bool BuildSolutionInternal() override;
2910  std::string DebugString() const override {
2911  return "GlobalCheapestInsertionFilteredHeuristic";
2912  }
2913 
2914  private:
2915  class PairEntry;
2916  class NodeEntry;
2917  typedef absl::flat_hash_set<PairEntry*> PairEntries;
2918  typedef absl::flat_hash_set<NodeEntry*> NodeEntries;
2919 
2926  void InsertPairs();
2927 
2935  void InsertNodesOnRoutes(const std::vector<int>& nodes,
2936  const absl::flat_hash_set<int>& vehicles);
2937 
2943  void SequentialInsertNodes(const std::vector<int>& nodes);
2944 
2948  void DetectUsedVehicles(std::vector<bool>* is_vehicle_used,
2949  std::vector<int>* unused_vehicles,
2950  absl::flat_hash_set<int>* used_vehicles);
2951 
2955  void InsertFarthestNodesAsSeeds();
2956 
2965  template <class Queue>
2966  int InsertSeedNode(
2967  std::vector<std::vector<StartEndValue>>* start_end_distances_per_node,
2968  Queue* priority_queue, std::vector<bool>* is_vehicle_used);
2969  // clang-format on
2970 
2973  void InitializePairPositions(
2974  AdjustablePriorityQueue<PairEntry>* priority_queue,
2975  std::vector<PairEntries>* pickup_to_entries,
2976  std::vector<PairEntries>* delivery_to_entries);
2982  void InitializeInsertionEntriesPerformingPair(
2983  int64 pickup, int64 delivery, int64 penalty,
2984  AdjustablePriorityQueue<PairEntry>* priority_queue,
2985  std::vector<PairEntries>* pickup_to_entries,
2986  std::vector<PairEntries>* delivery_to_entries);
2989  void UpdatePairPositions(int vehicle, int64 insert_after,
2990  AdjustablePriorityQueue<PairEntry>* priority_queue,
2991  std::vector<PairEntries>* pickup_to_entries,
2992  std::vector<PairEntries>* delivery_to_entries) {
2993  UpdatePickupPositions(vehicle, insert_after, priority_queue,
2994  pickup_to_entries, delivery_to_entries);
2995  UpdateDeliveryPositions(vehicle, insert_after, priority_queue,
2996  pickup_to_entries, delivery_to_entries);
2997  }
3000  void UpdatePickupPositions(int vehicle, int64 pickup_insert_after,
3001  AdjustablePriorityQueue<PairEntry>* priority_queue,
3002  std::vector<PairEntries>* pickup_to_entries,
3003  std::vector<PairEntries>* delivery_to_entries);
3006  void UpdateDeliveryPositions(
3007  int vehicle, int64 delivery_insert_after,
3008  AdjustablePriorityQueue<PairEntry>* priority_queue,
3009  std::vector<PairEntries>* pickup_to_entries,
3010  std::vector<PairEntries>* delivery_to_entries);
3013  void DeletePairEntry(PairEntry* entry,
3014  AdjustablePriorityQueue<PairEntry>* priority_queue,
3015  std::vector<PairEntries>* pickup_to_entries,
3016  std::vector<PairEntries>* delivery_to_entries);
3019  void InitializePositions(const std::vector<int>& nodes,
3020  AdjustablePriorityQueue<NodeEntry>* priority_queue,
3021  std::vector<NodeEntries>* position_to_node_entries,
3022  const absl::flat_hash_set<int>& vehicles);
3028  void InitializeInsertionEntriesPerformingNode(
3029  int64 node, int64 penalty, const absl::flat_hash_set<int>& vehicles,
3030  AdjustablePriorityQueue<NodeEntry>* priority_queue,
3031  std::vector<NodeEntries>* position_to_node_entries);
3034  void UpdatePositions(const std::vector<int>& nodes, int vehicle,
3035  int64 insert_after,
3036  AdjustablePriorityQueue<NodeEntry>* priority_queue,
3037  std::vector<NodeEntries>* node_entries);
3040  void DeleteNodeEntry(NodeEntry* entry,
3041  AdjustablePriorityQueue<NodeEntry>* priority_queue,
3042  std::vector<NodeEntries>* node_entries);
3043 
3046  void ComputeNeighborhoods();
3047 
3052  void AddNeighborForCostClass(int cost_class, int64 node_index,
3053  int64 neighbor_index, bool neighbor_is_pickup,
3054  bool neighbor_is_delivery);
3055 
3058  bool IsNeighborForCostClass(int cost_class, int64 node_index,
3059  int64 neighbor_index) const;
3060 
3062  const std::vector<int64>& GetPickupNeighborsOfNodeForCostClass(
3063  int cost_class, int64 node_index) const {
3064  if (gci_params_.neighbors_ratio == 1) {
3065  return pickup_nodes_;
3066  }
3067  return node_index_to_pickup_neighbors_by_cost_class_[node_index][cost_class]
3068  ->PositionsSetAtLeastOnce();
3069  }
3070 
3072  const std::vector<int64>& GetDeliveryNeighborsOfNodeForCostClass(
3073  int cost_class, int64 node_index) const {
3074  if (gci_params_.neighbors_ratio == 1) {
3075  return delivery_nodes_;
3076  }
3077  return node_index_to_delivery_neighbors_by_cost_class_
3078  [node_index][cost_class]
3079  ->PositionsSetAtLeastOnce();
3080  }
3081 
3083  const std::vector<int64>& GetSingleNeighborsOfNodeForCostClass(
3084  int cost_class, int64 node_index) const {
3085  if (gci_params_.neighbors_ratio == 1) {
3086  return single_nodes_;
3087  }
3088  return node_index_to_single_neighbors_by_cost_class_[node_index][cost_class]
3089  ->PositionsSetAtLeastOnce();
3090  }
3091 
3093  std::vector<const std::vector<int64>*> GetNeighborsOfNodeForCostClass(
3094  int cost_class, int64 node_index) const {
3095  return {&GetSingleNeighborsOfNodeForCostClass(cost_class, node_index),
3096  &GetPickupNeighborsOfNodeForCostClass(cost_class, node_index),
3097  &GetDeliveryNeighborsOfNodeForCostClass(cost_class, node_index)};
3098  }
3099 
3100  void ResetVehicleIndices() override {
3101  node_index_to_vehicle_.assign(node_index_to_vehicle_.size(), -1);
3102  }
3103 
3104  void SetVehicleIndex(int64 node, int vehicle) override {
3105  DCHECK_LT(node, node_index_to_vehicle_.size());
3106  node_index_to_vehicle_[node] = vehicle;
3107  }
3108 
3111  bool CheckVehicleIndices() const;
3112 
3113  GlobalCheapestInsertionParameters gci_params_;
3115  std::vector<int> node_index_to_vehicle_;
3116 
3117  // clang-format off
3118  std::vector<std::vector<std::unique_ptr<SparseBitset<int64> > > >
3119  node_index_to_single_neighbors_by_cost_class_;
3120  std::vector<std::vector<std::unique_ptr<SparseBitset<int64> > > >
3121  node_index_to_pickup_neighbors_by_cost_class_;
3122  std::vector<std::vector<std::unique_ptr<SparseBitset<int64> > > >
3123  node_index_to_delivery_neighbors_by_cost_class_;
3124  // clang-format on
3125 
3129  std::vector<int64> single_nodes_;
3130  std::vector<int64> pickup_nodes_;
3131  std::vector<int64> delivery_nodes_;
3132 };
3133 
3141  public:
3144  RoutingModel* model, std::function<int64(int64, int64, int64)> evaluator,
3145  const std::vector<LocalSearchFilter*>& filters);
3147  bool BuildSolutionInternal() override;
3148  std::string DebugString() const override {
3149  return "LocalCheapestInsertionFilteredHeuristic";
3150  }
3151 
3152  private:
3158  void ComputeEvaluatorSortedPositions(int64 node,
3159  std::vector<int64>* sorted_positions);
3164  void ComputeEvaluatorSortedPositionsOnRouteAfter(
3165  int64 node, int64 start, int64 next_after_start,
3166  std::vector<int64>* sorted_positions);
3167 
3168  std::vector<std::vector<StartEndValue>> start_end_distances_per_node_;
3169 };
3170 
3174  public:
3176  RoutingModel* model, const std::vector<LocalSearchFilter*>& filters);
3178  bool BuildSolutionInternal() override;
3179 
3180  private:
3181  class PartialRoutesAndLargeVehicleIndicesFirst {
3182  public:
3183  explicit PartialRoutesAndLargeVehicleIndicesFirst(
3184  const CheapestAdditionFilteredHeuristic& builder)
3185  : builder_(builder) {}
3186  bool operator()(int vehicle1, int vehicle2) const;
3187 
3188  private:
3189  const CheapestAdditionFilteredHeuristic& builder_;
3190  };
3192  template <typename Iterator>
3193  std::vector<int64> GetPossibleNextsFromIterator(int64 node, Iterator start,
3194  Iterator end) const {
3195  const int size = model()->Size();
3196  std::vector<int64> nexts;
3197  for (Iterator it = start; it != end; ++it) {
3198  const int64 next = *it;
3199  if (next != node && (next >= size || !Contains(next))) {
3200  nexts.push_back(next);
3201  }
3202  }
3203  return nexts;
3204  }
3206  virtual void SortSuccessors(int64 node, std::vector<int64>* successors) = 0;
3207  virtual int64 FindTopSuccessor(int64 node,
3208  const std::vector<int64>& successors) = 0;
3209 };
3210 
3215  public:
3218  RoutingModel* model, std::function<int64(int64, int64)> evaluator,
3219  const std::vector<LocalSearchFilter*>& filters);
3221  std::string DebugString() const override {
3222  return "EvaluatorCheapestAdditionFilteredHeuristic";
3223  }
3224 
3225  private:
3227  void SortSuccessors(int64 node, std::vector<int64>* successors) override;
3228  int64 FindTopSuccessor(int64 node,
3229  const std::vector<int64>& successors) override;
3230 
3231  std::function<int64(int64, int64)> evaluator_;
3232 };
3233 
3238  public:
3241  RoutingModel* model, Solver::VariableValueComparator comparator,
3242  const std::vector<LocalSearchFilter*>& filters);
3244  std::string DebugString() const override {
3245  return "ComparatorCheapestAdditionFilteredHeuristic";
3246  }
3247 
3248  private:
3250  void SortSuccessors(int64 node, std::vector<int64>* successors) override;
3251  int64 FindTopSuccessor(int64 node,
3252  const std::vector<int64>& successors) override;
3253 
3254  Solver::VariableValueComparator comparator_;
3255 };
3256 
3266  public:
3270  double neighbors_ratio = 1.0;
3276  bool add_reverse_arcs = false;
3279  double arc_coefficient = 1.0;
3280  };
3281 
3283  const RoutingIndexManager* manager,
3284  SavingsParameters parameters,
3285  const std::vector<LocalSearchFilter*>& filters);
3287  bool BuildSolutionInternal() override;
3288 
3289  protected:
3290  typedef std::pair</*saving*/ int64, /*saving index*/ int64> Saving;
3291 
3292  template <typename S>
3294 
3297  int64 fixed_cost;
3298 
3299  bool operator<(const VehicleClassEntry& other) const {
3300  return std::tie(fixed_cost, vehicle_class) <
3301  std::tie(other.fixed_cost, other.vehicle_class);
3302  }
3303  };
3304 
3305  virtual double ExtraSavingsMemoryMultiplicativeFactor() const = 0;
3306 
3307  virtual void BuildRoutesFromSavings() = 0;
3308 
3310  int64 GetVehicleTypeFromSaving(const Saving& saving) const {
3311  return saving.second / size_squared_;
3312  }
3314  int64 GetBeforeNodeFromSaving(const Saving& saving) const {
3315  return (saving.second % size_squared_) / Size();
3316  }
3318  int64 GetAfterNodeFromSaving(const Saving& saving) const {
3319  return (saving.second % size_squared_) % Size();
3320  }
3322  int64 GetSavingValue(const Saving& saving) const { return saving.first; }
3323 
3333  int StartNewRouteWithBestVehicleOfType(int type, int64 before_node,
3334  int64 after_node);
3335 
3336  std::vector<int> type_index_of_vehicle_;
3337  // clang-format off
3338  std::vector<std::set<VehicleClassEntry> > sorted_vehicle_classes_per_type_;
3339  std::vector<std::deque<int> > vehicles_per_vehicle_class_;
3340  std::unique_ptr<SavingsContainer<Saving> > savings_container_;
3341  // clang-format on
3342 
3343  private:
3348  // clang-format off
3349  void AddSymmetricArcsToAdjacencyLists(
3350  std::vector<std::vector<int64> >* adjacency_lists);
3351  // clang-format on
3352 
3359  void ComputeSavings();
3361  Saving BuildSaving(int64 saving, int vehicle_type, int before_node,
3362  int after_node) const {
3363  return std::make_pair(saving, vehicle_type * size_squared_ +
3364  before_node * Size() + after_node);
3365  }
3366 
3374  void ComputeVehicleTypes();
3375 
3379  int64 MaxNumNeighborsPerNode(int num_vehicle_types) const;
3380 
3381  const RoutingIndexManager* const manager_;
3382  const SavingsParameters savings_params_;
3383  int64 size_squared_;
3384 
3386 };
3387 
3389  public:
3391  RoutingModel* model, const RoutingIndexManager* manager,
3392  SavingsParameters parameters,
3393  const std::vector<LocalSearchFilter*>& filters)
3394  : SavingsFilteredHeuristic(model, manager, parameters, filters) {}
3396  std::string DebugString() const override {
3397  return "SequentialSavingsFilteredHeuristic";
3398  }
3399 
3400  private:
3405  void BuildRoutesFromSavings() override;
3406  double ExtraSavingsMemoryMultiplicativeFactor() const override { return 1.0; }
3407 };
3408 
3410  public:
3412  RoutingModel* model, const RoutingIndexManager* manager,
3413  SavingsParameters parameters,
3414  const std::vector<LocalSearchFilter*>& filters)
3415  : SavingsFilteredHeuristic(model, manager, parameters, filters) {}
3417  std::string DebugString() const override {
3418  return "ParallelSavingsFilteredHeuristic";
3419  }
3420 
3421  private:
3432  void BuildRoutesFromSavings() override;
3433 
3434  double ExtraSavingsMemoryMultiplicativeFactor() const override { return 2.0; }
3435 
3440  void MergeRoutes(int first_vehicle, int second_vehicle, int64 before_node,
3441  int64 after_node);
3442 
3444  std::vector<int64> first_node_on_route_;
3445  std::vector<int64> last_node_on_route_;
3449  std::vector<int> vehicle_of_first_or_last_node_;
3450 };
3451 
3455 
3457  public:
3459  const std::vector<LocalSearchFilter*>& filters,
3460  bool use_minimum_matching);
3462  bool BuildSolutionInternal() override;
3463  std::string DebugString() const override {
3464  return "ChristofidesFilteredHeuristic";
3465  }
3466 
3467  private:
3468  const bool use_minimum_matching_;
3469 };
3470 #endif // SWIG
3471 
3477  const RoutingSearchParameters& search_parameters,
3478  const Assignment* initial_solution,
3479  Assignment* solution);
3480 
3482 
3484  public:
3485  BasePathFilter(const std::vector<IntVar*>& nexts, int next_domain_size);
3486  ~BasePathFilter() override {}
3487  bool Accept(const Assignment* delta, const Assignment* deltadelta,
3488  int64 objective_min, int64 objective_max) override;
3489  void OnSynchronize(const Assignment* delta) override;
3490 
3491  protected:
3492  static const int64 kUnassigned;
3493 
3494  int64 GetNext(int64 node) const {
3495  return (new_nexts_[node] == kUnassigned)
3496  ? (IsVarSynced(node) ? Value(node) : kUnassigned)
3497  : new_nexts_[node];
3498  }
3499  int NumPaths() const { return starts_.size(); }
3500  int64 Start(int i) const { return starts_[i]; }
3501  int GetPath(int64 node) const { return paths_[node]; }
3502  int Rank(int64 node) const { return ranks_[node]; }
3503  bool IsDisabled() const { return status_ == DISABLED; }
3504  const std::vector<int64>& GetTouchedPathStarts() const {
3505  return touched_paths_.PositionsSetAtLeastOnce();
3506  }
3507  const std::vector<int64>& GetNewSynchronizedUnperformedNodes() const {
3508  return new_synchronized_unperformed_nodes_.PositionsSetAtLeastOnce();
3509  }
3510 
3511  private:
3512  enum Status { UNKNOWN, ENABLED, DISABLED };
3513 
3514  virtual bool DisableFiltering() const { return false; }
3515  virtual void OnBeforeSynchronizePaths() {}
3516  virtual void OnAfterSynchronizePaths() {}
3517  virtual void OnSynchronizePathFromStart(int64 start) {}
3518  virtual void InitializeAcceptPath() {}
3519  virtual bool AcceptPath(int64 path_start, int64 chain_start,
3520  int64 chain_end) = 0;
3521  virtual bool FinalizeAcceptPath(const Assignment* delta, int64 objective_min,
3522  int64 objective_max) {
3523  return true;
3524  }
3526  void ComputePathStarts(std::vector<int64>* path_starts,
3527  std::vector<int>* index_to_path);
3528  bool HavePathsChanged();
3529  void SynchronizeFullAssignment();
3530  void UpdateAllRanks();
3531  void UpdatePathRanksFromStart(int start);
3532 
3533  std::vector<int64> node_path_starts_;
3534  std::vector<int64> starts_;
3535  std::vector<int> paths_;
3536  SparseBitset<int64> new_synchronized_unperformed_nodes_;
3537  std::vector<int64> new_nexts_;
3538  std::vector<int> delta_touched_;
3539  SparseBitset<> touched_paths_;
3540  SparseBitset<> touched_path_nodes_;
3541  std::vector<int> ranks_;
3542 
3543  Status status_;
3544 };
3545 
3550 // TODO(user): Also call the solution finalizer on variables, with the
3556 // TODO(user): Avoid such false negatives.
3558  public:
3559  explicit CPFeasibilityFilter(const RoutingModel* routing_model);
3560  ~CPFeasibilityFilter() override {}
3561  std::string DebugString() const override { return "CPFeasibilityFilter"; }
3562  bool Accept(const Assignment* delta, const Assignment* deltadelta,
3563  int64 objective_min, int64 objective_max) override;
3564  void OnSynchronize(const Assignment* delta) override;
3565 
3566  private:
3567  void AddDeltaToAssignment(const Assignment* delta, Assignment* assignment);
3568 
3569  static const int64 kUnassigned;
3570  const RoutingModel* const model_;
3571  Solver* const solver_;
3572  Assignment* const assignment_;
3573  Assignment* const temp_assignment_;
3574  DecisionBuilder* const restore_;
3575 };
3576 
3577 #if !defined(SWIG)
3579  const RoutingModel& routing_model);
3581  const RoutingModel& routing_model);
3583  const RoutingModel& routing_model);
3585  const std::vector<RoutingDimension*>& dimensions,
3586  const RoutingSearchParameters& parameters, bool filter_objective_cost,
3587  std::vector<LocalSearchFilter*>* filters);
3589  const RoutingDimension& dimension,
3590  const RoutingSearchParameters& parameters,
3591  bool propagate_own_objective_value, bool filter_objective_cost);
3593  const RoutingDimension& dimension);
3595  GlobalDimensionCumulOptimizer* optimizer, bool filter_objective_cost);
3597  const RoutingModel& routing_model, const RoutingModel::IndexPairs& pairs,
3598  const std::vector<RoutingModel::PickupAndDeliveryPolicy>& vehicle_policies);
3600  const RoutingModel& routing_model);
3602  const RoutingModel& routing_model, const RoutingDimension& dimension);
3604  const RoutingModel* routing_model);
3605 #endif
3606 
3607 } // namespace operations_research
3608 #endif // OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_H_
void SetSpanCostCoefficientForVehicle(int64 coefficient, int vehicle)
Sets a cost proportional to the dimension span on a given vehicle, or on all vehicles at once.
RoutingIndexPair IndexPair
Definition: routing.h:245
virtual bool InitializeSolution()
Virtual method to initialize the solution.
Definition: routing.h:2719
TypeIncompatibilityChecker(const RoutingModel &model, bool check_hard_incompatibilities)
LocalDimensionCumulOptimizer * GetMutableLocalCumulOptimizer(const RoutingDimension &dimension) const
std::string DebugString() const override
Definition: routing.h:3463
ParallelSavingsFilteredHeuristic(RoutingModel *model, const RoutingIndexManager *manager, SavingsParameters parameters, const std::vector< LocalSearchFilter * > &filters)
Definition: routing.h:3411
bool ArcIsMoreConstrainedThanArc(int64 from, int64 to1, int64 to2)
Returns whether the arc from->to1 is more constrained than from->to2, taking into account,...
Generic filter-based heuristic applied to IntVars.
Definition: routing.h:2697
void AddLocalSearchOperator(LocalSearchOperator *ls_operator)
Adds a local search operator to the set of operators used to solve the vehicle routing problem.
int64 UnperformedPenaltyOrValue(int64 default_value, int64 var_index) const
Same as above except that it returns default_value instead of 0 when penalty is not well defined (def...
bool IsMatchingModel() const
Returns true if a vehicle/node matching problem is detected.
~ComparatorCheapestAdditionFilteredHeuristic() override
Definition: routing.h:3243
void AddNodePrecedence(int64 first_node, int64 second_node, int64 offset)
Definition: routing.h:2457
const std::vector< std::pair< int, int > > & GetPickupIndexPairs(int64 node_index) const
Returns pairs for which the node is a pickup; the first element of each pair is the index in the pick...
int64 GetCumulVarSoftLowerBound(int64 index) const
Returns the soft lower bound of a cumul variable for a given variable index.
int64 first_node
Definition: routing.h:2444
CostClassIndex GetCostClassIndexOfVehicle(int64 vehicle) const
Get the cost class index of the given vehicle.
Definition: routing.h:1170
int64 GetTransitValueFromClass(int64 from_index, int64 to_index, int64 vehicle_class) const
Same as above but taking a vehicle class of the dimension instead of a vehicle (the class of a vehicl...
Definition: routing.h:2171
void ForEachNodeInDisjunctionWithMaxCardinalityFromIndex(int64 index, int64 max_cardinality, F f) const
Calls f for each variable index of indices in the same disjunctions as the node corresponding to the ...
Definition: routing.h:598
@ PICKUP_AND_DELIVERY_NO_ORDER
Any precedence is accepted.
Definition: routing.h:230
void AddVariableTargetToFinalizer(IntVar *var, int64 target)
Add a variable to set the closest possible to the target value in the solution finalizer.
const std::vector< int64 > & vehicle_span_upper_bounds() const
Definition: routing.h:2465
const std::vector< int64 > & GetTouchedPathStarts() const
Definition: routing.h:3504
bool operator<(const StartEndValue &other) const
Definition: routing.h:2823
std::vector< int64 > start_max
Definition: routing.h:1776
const TransitCallback1 & UnaryTransitCallbackOrNull(int callback_index) const
Definition: routing.h:382
bool HasPickupToDeliveryLimits() const
Solver * solver() const
Returns the underlying constraint solver.
Definition: routing.h:1229
bool AddVectorDimension(std::vector< int64 > values, int64 capacity, bool fix_start_cumul_to_zero, const std::string &name)
Creates a dimension where the transit variable is constrained to be equal to 'values[i]' for node i; ...
const PiecewiseLinearFunction * GetCumulVarPiecewiseLinearCost(int64 index) const
Returns the piecewise linear cost of a cumul variable for a given variable index.
void AddRequiredTypeAlternativesWhenRemovingType(int dependent_type, absl::flat_hash_set< int > required_type_alternatives)
The following requirements apply when visiting dependent nodes that remove their type from the route,...
void SetBreakIntervalsOfVehicle(std::vector< IntervalVar * > breaks, int vehicle, int pre_travel_evaluator, int post_travel_evaluator)
Sets the breaks for a given vehicle.
int64 Value(int index) const
void ConsiderEmptyRouteCostsForVehicle(bool consider_costs, int vehicle)
Definition: routing.h:883
int64 GetLastPossibleLessOrEqualValueForNode(int64 index, int64 max_value) const
Returns the largest value outside the forbidden intervals of node 'index' that is less than or equal ...
Definition: routing.h:2220
RoutingModel * model() const
Returns the model on which the dimension was created.
Definition: routing.h:2164
std::string DebugString() const override
Definition: routing.h:3561
bool HasTypeRegulations() const
Returns true iff the model has any incompatibilities or requirements set on node types.
Definition: routing.h:818
const ReverseArcListGraph< int, int > & GetPathPrecedenceGraph() const
Accessors.
Definition: routing.h:2419
RangeMinMaxIndexFunction * transit_plus_identity
f(x)
Definition: routing.h:264
std::pair< int64, int64 > ValuedPosition
Definition: routing.h:2818
void AddSearchMonitor(SearchMonitor *const monitor)
Adds a search monitor to the search used to solve the routing model.
bool HasCumulVarPiecewiseLinearCost(int64 index) const
Returns true if a piecewise linear cost has been set for a given variable index.
bool AddDimensionWithVehicleCapacity(int evaluator_index, int64 slack_max, std::vector< int64 > vehicle_capacities, bool fix_start_cumul_to_zero, const std::string &name)
void AddIntervalToAssignment(IntervalVar *const interval)
int RegisterPositiveUnaryTransitCallback(TransitCallback1 callback)
int vehicle_class
Definition: routing.h:3296
bool TypeCurrentlyOnRoute(int type, int pos) const
Returns true iff there's at least one instance of the given type on the route when scanning the route...
friend class RoutingDimension
Definition: routing.h:1748
std::vector< int > type_index_of_vehicle_
Definition: routing.h:3336
virtual ~SweepArranger()
Definition: routing.h:2642
std::function< int64(int64)> RoutingTransitCallback1
Definition: routing_types.h:41
BasePathFilter(const std::vector< IntVar * > &nexts, int next_domain_size)
const std::vector< absl::flat_hash_set< int > > & GetSameVehicleRequiredTypeAlternativesOfType(int type) const
Returns the set of same-vehicle requirement alternatives for the given type.
void SetBreakDistanceDurationOfVehicle(int64 distance, int64 duration, int vehicle)
With breaks supposed to be consecutive, this forces the distance between breaks of size at least mini...
int VehicleIndex(int index) const
Returns the vehicle of the given start/end index, and -1 if the given index is not a vehicle start/en...
Definition: routing.h:1113
int64 distance
Definition: routing.h:2820
static const DimensionIndex kNoDimension
Constant used to express the "no dimension" index, returned when a dimension name does not correspond...
Definition: routing.h:362
std::string DebugString() const override
Definition: routing.h:3221
int GetStartChainEnd(int vehicle) const
Returns the end of the start chain of vehicle,.
Definition: routing.h:2785
void AddSoftSameVehicleConstraint(const std::vector< int64 > &indices, int64 cost)
Adds a soft contraint to force a set of variable indices to be on the same vehicle.
Definition: routing.h:211
int64 cost_coefficient
Definition: routing.h:297
void AddToAssignment(IntVar *const var)
Adds an extra variable to the vehicle routing assignment.
IntVarFilteredHeuristic(Solver *solver, const std::vector< IntVar * > &vars, const std::vector< LocalSearchFilter * > &filters)
int64 End(int vehicle) const
Returns the variable index of the ending node of a vehicle route.
Definition: routing.h:1106
void InitialPropagate() override
~CheapestInsertionFilteredHeuristic() override
Definition: routing.h:2815
virtual ~IntVarFilteredHeuristic()
Definition: routing.h:2702
VehicleClassIndex GetVehicleClassIndexOfVehicle(int64 vehicle) const
Definition: routing.h:1189
IntVarLocalSearchFilter * MakeVehicleAmortizedCostFilter(const RoutingModel &routing_model)
bool Commit()
Commits the modifications to the current solution if these modifications are "filter-feasible",...
GlobalVehicleBreaksConstraint ensures breaks constraints are enforced on all vehicles in the dimensio...
Definition: routing.h:1851
DecisionBuilder * MakeGuidedSlackFinalizer(const RoutingDimension *dimension, std::function< int64(int64)> initializer)
The next few members are in the public section only for testing purposes.
void Clear()
Definition: routing.h:1785
int64 number_of_decisions() const
Returns statistics from its underlying heuristic.
bool CostsAreHomogeneousAcrossVehicles() const
Whether costs are homogeneous across all vehicles.
Definition: routing.h:1150
~GlobalCheapestInsertionFilteredHeuristic() override
Definition: routing.h:2908
virtual bool StopSearch()
Returns true if the search must be stopped.
Definition: routing.h:2727
const std::vector< IntVar * > & fixed_transits() const
Definition: routing.h:2187
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
static bool LessThan(const CostClass &a, const CostClass &b)
Comparator for STL containers and algorithms.
Definition: routing.h:313
RoutingTransitCallback1 TransitCallback1
Definition: routing.h:240
Filter-based heuristic dedicated to routing.
Definition: routing.h:2775
const std::vector< std::unique_ptr< GlobalDimensionCumulOptimizer > > & GetGlobalDimensionCumulOptimizers() const
Returns [global|local]_dimension_optimizers_, which are empty if the model has not been closed.
Definition: routing.h:527
gtl::ITIVector< DimensionIndex, int64 > dimension_capacities
Definition: routing.h:341
LocalCheapestInsertionFilteredHeuristic(RoutingModel *model, std::function< int64(int64, int64, int64)> evaluator, const std::vector< LocalSearchFilter * > &filters)
Takes ownership of evaluator.
std::function< int64(int64)> penalty_evaluator_
Definition: routing.h:2874
RoutingDisjunctionIndex DisjunctionIndex
Definition: routing.h:238
IntVarLocalSearchFilter * MakeCPFeasibilityFilter(const RoutingModel *routing_model)
virtual void BuildRoutesFromSavings()=0
const absl::flat_hash_set< int > & GetTemporalTypeIncompatibilitiesOfType(int type) const
~TypeIncompatibilityChecker() override
Definition: routing.h:2016
int64 GetDisjunctionPenalty(DisjunctionIndex index) const
Returns the penalty of the node disjunction of index 'index'.
Definition: routing.h:617
bool IsVarSynced(int index) const
IntVar * SlackVar(int64 index) const
Definition: routing.h:2181
The following constraint ensures that incompatibilities and requirements between types are respected.
Definition: routing.h:2092
static const int64 kUnassigned
Definition: routing.h:3492
void SetSpanCostCoefficientForAllVehicles(int64 coefficient)
Definition: routing.h:3293
RoutingCostClassIndex CostClassIndex
Definition: routing.h:236
RangeIntToIntFunction * transit
Definition: routing.h:263
VisitTypePolicy GetVisitTypePolicy(int64 index) const
std::string DebugString() const override
Definition: routing.h:3148
int64 GetCumulVarSoftUpperBoundCoefficient(int64 index) const
Returns the cost coefficient of the soft upper bound of a cumul variable for a given variable index.
int64 GetCumulVarSoftLowerBoundCoefficient(int64 index) const
Returns the cost coefficient of the soft lower bound of a cumul variable for a given variable index.
bool SolveModelWithSat(const RoutingModel &model, const RoutingSearchParameters &search_parameters, const Assignment *initial_solution, Assignment *solution)
Attempts to solve the model using the cp-sat solver.
void AddVariableMinimizedByFinalizer(IntVar *var)
Adds a variable to minimize in the solution finalizer.
double max_memory_usage_bytes
The number of neighbors considered for each node is also adapted so that the stored Savings don't use...
Definition: routing.h:3273
Manager for any NodeIndex <-> variable index conversion.
const std::vector< std::pair< DisjunctionIndex, DisjunctionIndex > > & GetPickupAndDeliveryDisjunctions() const
Definition: routing.h:709
std::string DebugString() const override
Definition: routing.h:3244
What follows is relevant for models with time/state dependent transits.
Definition: routing.h:262
bool IsEnd(int64 index) const
Returns true if 'index' represents the last node of a route.
Definition: routing.h:1110
int GetNumberOfVisitTypes() const
Definition: routing.h:750
TypeRequirementChecker(const RoutingModel &model)
Definition: routing.h:2030
int64 GetSpanCostCoefficientForVehicle(int vehicle) const
Definition: routing.h:2469
bool AddDimensionDependentDimensionWithVehicleCapacity(int transit, const RoutingDimension *base_dimension, int64 slack_max, int64 vehicle_capacity, bool fix_start_cumul_to_zero, const std::string &name)
Homogeneous versions of the functions above.
static std::unique_ptr< LocalSearchOperator > MakeGreedyDescentLSOperator(std::vector< IntVar * > variables)
Perhaps move it to constraint_solver.h.
void SetBreakIntervalsOfVehicle(std::vector< IntervalVar * > breaks, int vehicle, std::vector< int64 > node_visit_transits)
Deprecated, sets pre_travel(i, j) = node_visit_transit[i].
int position_of_last_type_on_vehicle_up_to_visit
Position of the last node of policy TYPE_ON_VEHICLE_UP_TO_VISIT visited on the route.
Definition: routing.h:1980
uint64 unvisitable_nodes_fprint
Fingerprint of unvisitable non-start/end nodes.
Definition: routing.h:346
@ TYPE_SIMULTANEOUSLY_ADDED_AND_REMOVED
The visit doesn't have an impact on the number of types 'T' on the route, as it's (virtually) added a...
Definition: routing.h:739
bool HasTemporalTypeRequirements() const
Definition: routing.h:812
int64 GetInsertionCostForNodeAtPosition(int64 node_to_insert, int64 insert_after, int64 insert_before, int vehicle) const
Returns the cost of inserting 'node_to_insert' between 'insert_after' and 'insert_before' on the 'veh...
bool HasBreakConstraints() const
Returns true if any break interval or break distance was defined.
~LocalCheapestInsertionFilteredHeuristic() override
Definition: routing.h:3146
double farthest_seeds_ratio
The ratio of routes on which to insert farthest nodes as seeds before starting the cheapest insertion...
Definition: routing.h:2892
ChristofidesFilteredHeuristic(RoutingModel *model, const std::vector< LocalSearchFilter * > &filters, bool use_minimum_matching)
const RoutingModel::TransitCallback1 & GetUnaryTransitEvaluator(int vehicle) const
Returns the unary callback evaluating the transit value between two node indices for a given vehicle.
Definition: routing.h:2248
const std::vector< absl::flat_hash_set< int > > & GetRequiredTypeAlternativesWhenAddingType(int type) const
Returns the set of requirement alternatives when adding the given type.
bool DetectablePrecedencesWithChain(Tasks *tasks)
Does detectable precedences deductions on tasks in the chain precedence, taking the time windows of n...
int Rank(int64 node) const
Definition: routing.h:3502
bool AddDimension(int evaluator_index, int64 slack_max, int64 capacity, bool fix_start_cumul_to_zero, const std::string &name)
Model creation.
virtual double ExtraSavingsMemoryMultiplicativeFactor() const =0
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
virtual bool HasRegulationsToCheck() const =0
IntVar * FixedTransitVar(int64 index) const
Definition: routing.h:2180
A structure meant to store soft bounds and associated violation constants.
Definition: routing.h:2121
int GetCostClassesCount() const
Returns the number of different cost classes in the model.
Definition: routing.h:1184
RoutingVehicleClassIndex VehicleClassIndex
Definition: routing.h:239
@ TYPE_ADDED_TO_VEHICLE
When visited, the number of types 'T' on the vehicle increases by one.
Definition: routing.h:726
~RoutingFilteredHeuristic() override
Definition: routing.h:2779
bool StopSearch() override
Returns true if the search must be stopped.
Definition: routing.h:2795
BoundCost bound_cost(int element) const
Definition: routing.h:2130
Filter-base decision builder which builds a solution by inserting nodes at their cheapest position.
Definition: routing.h:3140
std::string DebugString() const override
bool add_reverse_arcs
If add_reverse_arcs is true, the neighborhood relationships are considered symmetrically.
Definition: routing.h:3276
Assignment * RestoreAssignment(const Assignment &solution)
Restores an assignment as a solution in the routing model and returns the new solution.
void AddTemporalTypeIncompatibility(int type1, int type2)
DisjunctionIndex AddDisjunction(const std::vector< int64 > &indices, int64 penalty=kNoPenalty, int64 max_cardinality=1)
Adds a disjunction constraint on the indices: exactly 'max_cardinality' of the indices are active.
void AddPickupAndDeliverySets(DisjunctionIndex pickup_disjunction, DisjunctionIndex delivery_disjunction)
Same as AddPickupAndDelivery but notifying that the performed node from the disjunction of index 'pic...
@ ROUTING_INVALID
Model, model parameters or flags are not valid.
Definition: routing.h:224
int64 GetDisjunctionMaxCardinality(DisjunctionIndex index) const
Returns the maximum number of possible active nodes of the node disjunction of index 'index'.
Definition: routing.h:622
gtl::ITIVector< DimensionIndex, int64 > dimension_evaluator_classes
dimension_evaluators[d]->Run(from, to) is the transit value of arc from->to for a dimension d.
Definition: routing.h:344
std::pair< int64, int64 > Saving
Definition: routing.h:3290
bool HasDimension(const std::string &dimension_name) const
Returns true if a dimension exists for a given dimension name.
LocalDimensionCumulOptimizer * GetMutableLocalCumulMPOptimizer(const RoutingDimension &dimension) const
bool ForbiddenIntervals(Tasks *tasks)
Tasks might have holes in their domain, this enforces such holes.
int64 GetUnperformedValue(int64 node_to_insert) const
Returns the cost of unperforming node 'node_to_insert'.
bool HasCumulVarSoftLowerBound(int64 index) const
Returns true if a soft lower bound has been set for a given variable index.
int num_chain_tasks
Definition: routing.h:1774
SimpleBoundCosts operator=(const SimpleBoundCosts &)=delete
IntVar * CumulVar(int64 index) const
Get the cumul, transit and slack variables for the given node (given as int64 var index).
Definition: routing.h:2178
SimpleBoundCosts(int num_bounds, BoundCost default_bound_cost)
Definition: routing.h:2127
std::unique_ptr< SavingsContainer< Saving > > savings_container_
Definition: routing.h:3340
int64 GetLocalOptimizerOffsetForVehicle(int vehicle) const
Definition: routing.h:2485
int RegisterUnaryTransitCallback(TransitCallback1 callback)
Registers 'callback' and returns its index.
std::string DebugString() const override
Definition: routing.h:3396
double neighbors_ratio
If neighbors_ratio < 1 then for each node only this ratio of its neighbors leading to the smallest ar...
Definition: routing.h:2895
std::vector< const SortedDisjointIntervalList * > forbidden_intervals
Definition: routing.h:1782
CostClass(int evaluator_index)
Definition: routing.h:309
int64 second_node
Definition: routing.h:2445
std::function< int64(int, int)> PickupToDeliveryLimitFunction
Limits, in terms of maximum difference between the cumul variables, between the pickup and delivery a...
Definition: routing.h:2433
std::vector< int64 > start_min
Definition: routing.h:1775
IntVarLocalSearchFilter * MakeVehicleVarFilter(const RoutingModel &routing_model)
const std::string & name() const
Returns the name of the dimension.
Definition: routing.h:2415
void SetValue(int64 index, int64 value)
Modifies the current solution by setting the variable of index 'index' to value 'value'.
Definition: routing.h:2730
int64 GetCumulVarSoftUpperBound(int64 index) const
Returns the soft upper bound of a cumul variable for a given variable index.
int64 fixed_cost
Definition: routing.h:3297
static const char kLightElement[]
Constraint types.
Definition: routing.h:1758
int64 GetSavingValue(const Saving &saving) const
Returns the saving value from a saving.
Definition: routing.h:3322
~IntVarFilteredDecisionBuilder() override
Definition: routing.h:2682
int start_equivalence_class
Vehicle start and end equivalence classes.
Definition: routing.h:333
void IgnoreDisjunctionsAlreadyForcedToZero()
SPECIAL: Makes the solver ignore all the disjunctions whose active variables are all trivially zero (...
int64 ShortestTransitionSlack(int64 node) const
It makes sense to use the function only for self-dependent dimension.
int GetPath(int64 node) const
Definition: routing.h:3501
void FillPathEvaluation(const std::vector< int64 > &path, const RoutingModel::TransitCallback2 &evaluator, std::vector< int64 > *values)
virtual void ResetVehicleIndices()
Definition: routing.h:2797
int vehicles() const
Returns the number of vehicle routes in the model.
Definition: routing.h:1247
IntVar * ActiveVar(int64 index) const
Returns the active variable of the node corresponding to index.
Definition: routing.h:1133
@ ROUTING_SUCCESS
Problem solved successfully after calling RoutingModel::Solve().
Definition: routing.h:218
int NumPaths() const
Definition: routing.h:3499
Filter manager: when a move is made, filters are executed to decide whether the solution is feasible ...
RoutingModel::VisitTypePolicy VisitTypePolicy
Definition: routing.h:1962
const std::vector< absl::flat_hash_set< int > > & GetRequiredTypeAlternativesWhenRemovingType(int type) const
Returns the set of requirement alternatives when removing the given type.
int64 GetGlobalOptimizerOffset() const
Definition: routing.h:2481
const std::vector< std::pair< int, int > > & GetDeliveryIndexPairs(int64 node_index) const
Same as above for deliveries.
const std::vector< IntVar * > & Nexts() const
Returns all next variables of the model, such that Nexts(i) is the next variable of the node correspo...
Definition: routing.h:1124
SweepArranger * sweep_arranger() const
Returns the sweep arranger to be used by routing heuristics.
Definition: routing.h:1087
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
void SetVisitType(int64 index, int type, VisitTypePolicy type_policy)
@ ROUTING_NOT_SOLVED
Problem not solved yet (before calling RoutingModel::Solve()).
Definition: routing.h:216
const std::vector< std::pair< int64, int64 > > & GetBreakDistanceDurationOfVehicle(int vehicle) const
Returns the pairs (distance, duration) specified by break distance constraints.
int64 Value(int64 index) const
Returns the value of the variable of index 'index' in the last committed solution.
Definition: routing.h:2741
virtual ~TypeRegulationsChecker()
Definition: routing.h:1955
void SetAllowedVehiclesForIndex(const std::vector< int > &vehicles, int64 index)
Sets the vehicles which can visit a given node.
int64 GetBeforeNodeFromSaving(const Saving &saving) const
Returns the "before node" from a saving.
Definition: routing.h:3314
std::vector< RoutingDimension * > GetDimensionsWithSoftOrSpanCosts() const
Returns dimensions with soft or vehicle span costs.
gtl::ITIVector< DimensionIndex, int64 > dimension_start_cumuls_min
Bounds of cumul variables at start and end vehicle nodes.
Definition: routing.h:337
~BasePathFilter() override
Definition: routing.h:3486
~ChristofidesFilteredHeuristic() override
Definition: routing.h:3461
Constraint * MakePathSpansAndTotalSlacks(const RoutingDimension *dimension, std::vector< IntVar * > spans, std::vector< IntVar * > total_slacks)
For every vehicle of the routing model:
int num_type_added_to_vehicle
Number of TYPE_ADDED_TO_VEHICLE and TYPE_SIMULTANEOUSLY_ADDED_AND_REMOVED node type policies seen on ...
Definition: routing.h:1969
const Assignment *const PreAssignment() const
Returns an assignment used to fix some of the variables of the problem.
Definition: routing.h:999
bool MirrorTasks(Tasks *tasks)
Transforms the problem with a time symmetry centered in 0.
void AddAtSolutionCallback(std::function< void()> callback)
Adds a callback called each time a solution is found during the search.
Status
Status of the search.
Definition: routing.h:214
Assignment * CompactAssignment(const Assignment &assignment) const
Returns a compacted version of the given assignment, in which all vehicles with id lower or equal to ...
const Assignment * Solve(const Assignment *assignment=nullptr)
Solves the current routing model; closes the current model.
const RoutingModel::TransitCallback2 & transit_evaluator(int vehicle) const
Returns the callback evaluating the transit value between two node indices for a given vehicle.
Definition: routing.h:2241
Filtered-base decision builder based on the addition heuristic, extending a path from its start node ...
Definition: routing.h:3173
std::function< StateDependentTransit(int64, int64)> VariableIndexEvaluator2
Definition: routing.h:267
void SetTabuVarsCallback(GetTabuVarsCallback tabu_var_callback)
int64 GetArcCostForFirstSolution(int64 from_index, int64 to_index) const
Returns the cost of the arc in the context of the first solution strategy.
RoutingTransitCallback2 TransitCallback2
Definition: routing.h:241
GlobalCheapestInsertionFilteredHeuristic(RoutingModel *model, std::function< int64(int64, int64, int64)> evaluator, std::function< int64(int64)> penalty_evaluator, const std::vector< LocalSearchFilter * > &filters, GlobalCheapestInsertionParameters parameters)
Takes ownership of evaluators.
Definition: routing.h:2443
EvaluatorCheapestAdditionFilteredHeuristic(RoutingModel *model, std::function< int64(int64, int64)> evaluator, const std::vector< LocalSearchFilter * > &filters)
Takes ownership of evaluator.
const std::vector< std::unique_ptr< LocalDimensionCumulOptimizer > > & GetLocalDimensionCumulMPOptimizers() const
Definition: routing.h:535
TypeRegulationsChecker(const RoutingModel &model)
std::function< int64(int64, int64, int64)> evaluator_
Definition: routing.h:2873
int64 bound
Definition: routing.h:2124
A structure to hold tasks described by their features.
Definition: routing.h:1773
int num_type_removed_from_vehicle
Number of ADDED_TYPE_REMOVED_FROM_VEHICLE (effectively removing a type from the route) and TYPE_SIMUL...
Definition: routing.h:1975
int RegisterStateDependentTransitCallback(VariableIndexEvaluator2 callback)
IntVarFilteredDecisionBuilder(std::unique_ptr< IntVarFilteredHeuristic > heuristic)
The base class for all local search operators.
void SetAmortizedCostFactorsOfAllVehicles(int64 linear_cost_factor, int64 quadratic_cost_factor)
The following methods set the linear and quadratic cost factors of vehicles (must be positive values)...
int StartNewRouteWithBestVehicleOfType(int type, int64 before_node, int64 after_node)
Finds the best available vehicle of type "type" to start a new route to serve the arc before_node-->a...
GlobalDimensionCumulOptimizer * GetMutableGlobalCumulOptimizer(const RoutingDimension &dimension) const
Returns the global/local dimension cumul optimizer for a given dimension, or nullptr if there is none...
Definition: routing.h:1952
CostClassIndex cost_class_index
The cost class of the vehicle.
Definition: routing.h:324
bool IsDisabled() const
Definition: routing.h:3503
const Solver::IndexEvaluator2 & first_solution_evaluator() const
Gets/sets the evaluator used during the search.
Definition: routing.h:896
friend class RoutingModel
Definition: routing.h:2630
void InitialPropagate() override
std::vector< std::set< VehicleClassEntry > > sorted_vehicle_classes_per_type_
Definition: routing.h:3338
friend class SavingsFilteredHeuristicTestPeer
Definition: routing.h:3385
PickupAndDeliveryPolicy GetPickupAndDeliveryPolicyOfVehicle(int vehicle) const
bool ApplyLocksToAllVehicles(const std::vector< std::vector< int64 >> &locks, bool close_routes)
Applies lock chains to all vehicles to the next search, such that locks[p] is the lock chain for rout...
Definition: routing.h:271
bool WriteAssignment(const std::string &file_name) const
Writes the current solution to a file containing an AssignmentProto.
RoutingFilteredHeuristic(RoutingModel *model, const std::vector< LocalSearchFilter * > &filters)
bool AddMatrixDimension(std::vector< std::vector< int64 > > values, int64 capacity, bool fix_start_cumul_to_zero, const std::string &name)
Creates a dimension where the transit variable is constrained to be equal to 'values[i][next(i)]' for...
bool AreEmptyRouteCostsConsideredForVehicle(int vehicle) const
Definition: routing.h:888
virtual bool FinalizeCheck() const
Definition: routing.h:2002
void SetPickupAndDeliveryPolicyOfVehicle(PickupAndDeliveryPolicy policy, int vehicle)
bool Accept(const Assignment *delta, const Assignment *deltadelta, int64 objective_min, int64 objective_max) override
Accepts a "delta" given the assignment with which the filter has been synchronized; the delta holds t...
const RoutingDimension * dimension
Definition: routing.h:298
@ PICKUP_AND_DELIVERY_LIFO
Deliveries must be performed in reverse order of pickups.
Definition: routing.h:232
Checker for type requirements.
Definition: routing.h:2028
bool use_neighbors_ratio_for_initialization
If true, only closest neighbors (see neighbors_ratio) are considered as insertion positions during in...
Definition: routing.h:2899
void OnSynchronize(const Assignment *delta) override
int vehicle
Definition: routing.h:2821
std::vector< std::string > GetAllDimensionNames() const
Outputs the names of all dimensions added to the routing engine.
const TransitCallback2 & TransitCallback(int callback_index) const
Definition: routing.h:378
const std::vector< IntervalVar * > & GetBreakIntervalsOfVehicle(int vehicle) const
Returns the break intervals set by SetBreakIntervalsOfVehicle().
int64 number_of_rejects() const
Definition: routing.h:2711
void AddHardTypeIncompatibility(int type1, int type2)
Incompatibilities: Two nodes with "hard" incompatible types cannot share the same route at all,...
void AddLocalSearchFilter(LocalSearchFilter *filter)
Adds a custom local search filter to the list of filters used to speed up local search by pruning unf...
Definition: routing.h:1094
Definition: routing.h:3267
void AddRequiredTypeAlternativesWhenAddingType(int dependent_type, absl::flat_hash_set< int > required_type_alternatives)
If type_D depends on type_R when adding type_D, any node_D of type_D and VisitTypePolicy TYPE_ADDED_T...
int64 number_of_decisions() const
Returns statistics on search, number of decisions sent to filters, number of decisions rejected by fi...
Definition: routing.h:2710
void AddVariableMaximizedByFinalizer(IntVar *var)
Adds a variable to maximize in the solution finalizer (see above for information on the solution fina...
int64 Size() const
Returns the number of next variables in the model.
Definition: routing.h:1249
std::vector< std::vector< StartEndValue > > ComputeStartEndDistanceForVehicles(const std::vector< int > &vehicles)
Computes and returns the distance of each uninserted node to every vehicle in "vehicles" as a std::ve...
int64 GetVehicleTypeFromSaving(const Saving &saving) const
Returns the cost class from a saving.
Definition: routing.h:3310
void OnSynchronize(const Assignment *delta) override
const std::vector< int64 > & GetAmortizedQuadraticCostFactorOfVehicles() const
Definition: routing.h:879
int64 ComputeLowerBound()
Computes a lower bound to the routing problem solving a linear assignment problem.
bool Precedences(Tasks *tasks)
Propagates the deductions from the chain of precedences, if there is one.
void SetAssignmentFromOtherModelAssignment(Assignment *target_assignment, const RoutingModel *source_model, const Assignment *source_assignment)
Given a "source_model" and its "source_assignment", resets "target_assignment" with the IntVar variab...
int GetEndChainStart(int vehicle) const
Returns the start of the end chain of vehicle,.
Definition: routing.h:2787
SweepArranger(const std::vector< std::pair< int64, int64 >> &points)
bool IsStart(int64 index) const
Returns true if 'index' represents the first node of a route.
void SetCumulVarSoftLowerBound(int64 index, int64 lower_bound, int64 coefficient)
Sets a soft lower bound to the cumul variable of a given variable index.
std::string DebugString() const override
Definition: routing.h:1854
Filter-based decision builder which builds a solution by inserting nodes at their cheapest position o...
Definition: routing.h:2885
Assignment * MutablePreAssignment()
Definition: routing.h:1000
void AppendEvaluatedPositionsAfter(int64 node_to_insert, int64 start, int64 next_after_start, int64 vehicle, std::vector< ValuedPosition > *valued_positions)
Helper method to the ComputeEvaluatorSortedPositions* methods.
int GetNumOfSingletonNodes() const
Returns the number of non-start/end nodes which do not appear in a pickup/delivery pair.
BoundCost & bound_cost(int element)
Definition: routing.h:2129
gtl::ITIVector< DimensionIndex, int64 > dimension_end_cumuls_max
Definition: routing.h:340
void MakeDisjunctionNodesUnperformed(int64 node)
Make nodes in the same disjunction as 'node' unperformed.
void AssignmentToRoutes(const Assignment &assignment, std::vector< std::vector< int64 >> *const routes) const
Converts the solution in the given assignment to routes for all vehicles.
VisitTypePolicy
Set the node visit types and incompatibilities/requirements between the types (see below).
Definition: routing.h:724
std::vector< bool > is_preemptible
Definition: routing.h:1781
int64 GetArcCostForVehicle(int64 from_index, int64 to_index, int64 vehicle) const
Returns the cost of the transit arc between two nodes for a given vehicle.
int GetNumberOfDisjunctions() const
Returns the number of node disjunctions in the model.
Definition: routing.h:626
void SetSoftSpanUpperBoundForVehicle(SimpleBoundCosts::BoundCost bound_cost, int vehicle)
If the span of vehicle on this dimension is larger than bound, the cost will be increased by cost * (...
Definition: routing.h:2495
int64 GetFixedCostOfVehicle(int vehicle) const
Returns the route fixed cost taken into account if the route of the vehicle is not empty,...
IntVarLocalSearchFilter * MakePickupDeliveryFilter(const RoutingModel &routing_model, const RoutingModel::IndexPairs &pairs, const std::vector< RoutingModel::PickupAndDeliveryPolicy > &vehicle_policies)
void SetCumulVarSoftUpperBound(int64 index, int64 upper_bound, int64 coefficient)
Sets a soft upper bound to the cumul variable of a given variable index.
virtual bool BuildSolutionInternal()=0
Virtual method to redefine how to build a solution.
Class to arrange indices by by their distance and their angles from the depot.
Definition: routing.h:2639
Dimensions represent quantities accumulated at nodes along the routes.
Definition: routing.h:2160
IntVar * ApplyLocks(const std::vector< int64 > &locks)
Applies a lock chain to the next search.
static const char kLightElement2[]
Definition: routing.h:1759
RoutingModel(const RoutingIndexManager &index_manager, const RoutingModelParameters &parameters)
bool AddDimensionWithVehicleTransits(const std::vector< int > &evaluator_indices, int64 slack_max, int64 capacity, bool fix_start_cumul_to_zero, const std::string &name)
bool HasSoftSpanUpperBounds() const
Definition: routing.h:2503
int64 GetAfterNodeFromSaving(const Saving &saving) const
Returns the "after node" from a saving.
Definition: routing.h:3318
bool CheckLimit()
Returns true if the search limit has been crossed.
Definition: routing.h:1232
void SetFirstSolutionEvaluator(Solver::IndexEvaluator2 evaluator)
Takes ownership of evaluator.
Definition: routing.h:901
~EvaluatorCheapestAdditionFilteredHeuristic() override
Definition: routing.h:3220
bool operator<(const VehicleClassEntry &other) const
Definition: routing.h:3299
std::vector< int64 > duration_min
Definition: routing.h:1777
const RoutingModel & model_
Definition: routing.h:2004
int64 UnperformedPenalty(int64 var_index) const
Get the "unperformed" penalty of a node.
bool AddDimensionDependentDimensionWithVehicleCapacity(const std::vector< int > &pure_transits, const std::vector< int > &dependent_transits, const RoutingDimension *base_dimension, int64 slack_max, std::vector< int64 > vehicle_capacities, bool fix_start_cumul_to_zero, const std::string &name)
Creates a dimension with transits depending on the cumuls of another dimension.
Definition: routing.h:469
int64 fixed_cost
Contrarily to CostClass, here we need strict equivalence.
Definition: routing.h:326
static RoutingModel::StateDependentTransit MakeStateDependentTransit(const std::function< int64(int64)> &f, int64 domain_start, int64 domain_end)
Creates a cached StateDependentTransit from an std::function.
IntVar * VehicleVar(int64 index) const
Returns the vehicle variable of the node corresponding to index.
Definition: routing.h:1141
void SetSweepArranger(SweepArranger *sweep_arranger)
Definition: routing.h:1083
bool AddDimensionDependentDimensionWithVehicleCapacity(int pure_transit, int dependent_transit, const RoutingDimension *base_dimension, int64 slack_max, int64 vehicle_capacity, bool fix_start_cumul_to_zero, const std::string &name)
IntVar * TransitVar(int64 index) const
Definition: routing.h:2179
void InitializeBreaks()
Sets up vehicle_break_intervals_, vehicle_break_distance_duration_, pre_travel_evaluators and post_tr...
This class acts like a CP propagator: it takes a set of tasks given by their start/duration/end featu...
Definition: routing.h:1766
const std::vector< RoutingDimension * > & GetDimensions() const
Returns all dimensions of the model.
Definition: routing.h:518
void SetFixedCostOfVehicle(int64 cost, int vehicle)
Sets the fixed cost of one vehicle route.
IntVarLocalSearchFilter * MakeNodeDisjunctionFilter(const RoutingModel &routing_model)
SimpleBoundCosts(const SimpleBoundCosts &)=delete
IntVarLocalSearchFilter * MakeTypeRegulationsFilter(const RoutingModel &routing_model)
std::function< std::vector< operations_research::IntVar * >(RoutingModel *)> GetTabuVarsCallback
Sets the callback returning the variable to use for the Tabu Search metaheuristic.
Definition: routing.h:1270
~ParallelSavingsFilteredHeuristic() override
Definition: routing.h:3416
RoutingModel(const RoutingIndexManager &index_manager)
Constructor taking an index manager.
int GetPostTravelEvaluatorOfVehicle(int vehicle) const
const std::string & GetPrimaryConstrainedDimension() const
Get the primary constrained dimension, or an empty string if it is unset.
Definition: routing.h:567
std::vector< int64 > duration_max
Definition: routing.h:1778
IntVarLocalSearchFilter * MakeCumulBoundsPropagatorFilter(const RoutingDimension &dimension)
RoutingDimensionIndex DimensionIndex
Definition: routing.h:237
bool AddConstantDimension(int64 value, int64 capacity, bool fix_start_cumul_to_zero, const std::string &name)
Definition: routing.h:437
std::vector< int64 > end_max
Definition: routing.h:1780
Filter-based decision builder which builds a solution by using Clarke & Wright's Savings heuristic.
Definition: routing.h:3265
const std::vector< IntVar * > & transits() const
Definition: routing.h:2188
CheapestAdditionFilteredHeuristic(RoutingModel *model, const std::vector< LocalSearchFilter * > &filters)
void InsertBetween(int64 node, int64 predecessor, int64 successor)
Inserts 'node' just after 'predecessor', and just before 'successor', resulting in the following subs...
operations_research::FirstSolutionStrategy::Value GetAutomaticFirstSolutionStrategy() const
Returns the automatic first solution strategy selected.
Definition: routing.h:1259
const Assignment * PackCumulsOfOptimizerDimensionsFromAssignment(const Assignment *original_assignment, absl::Duration duration_limit)
For every dimension in the model with an optimizer in local/global_dimension_optimizers_,...
void SetPickupAndDeliveryPolicyOfAllVehicles(PickupAndDeliveryPolicy policy)
Sets the Pickup and delivery policy of all vehicles.
int64 GetSpanUpperBoundForVehicle(int vehicle) const
Definition: routing.h:2461
std::pair< std::vector< int64 >, std::vector< int64 > > RoutingIndexPair
Definition: routing_types.h:44
void SetCumulVarPiecewiseLinearCost(int64 index, const PiecewiseLinearFunction &cost)
Sets a piecewise linear cost on the cumul variable of a given variable index.
int64 GetNumberOfRejectsInFirstSolution(const RoutingSearchParameters &search_parameters) const
double arc_coefficient
arc_coefficient is a strictly positive parameter indicating the coefficient of the arc being consider...
Definition: routing.h:3279
PickupAndDeliveryPolicy
Types of precedence policy applied to pickup and delivery pairs.
Definition: routing.h:228
Generic path-based filter class.
Definition: routing.h:3483
~TypeRequirementChecker() override
Definition: routing.h:2032
void CloseVisitTypes()
This function should be called once all node visit types have been set and prior to adding any incomp...
int64 global_span_cost_coefficient() const
Definition: routing.h:2477
void ResetSolution()
Resets the data members for a new solution.
std::vector< RoutingIndexPair > RoutingIndexPairs
Definition: routing_types.h:45
Routing model visitor.
Definition: routing.h:1755
absl::Duration RemainingTime() const
Returns the time left in the search limit.
Definition: routing.h:1238
IntVar * Var(int64 index) const
Returns the variable of index 'index'.
Definition: routing.h:2752
int64 transit_evaluator_class
Definition: routing.h:296
void SetAmortizedCostFactorsOfVehicle(int64 linear_cost_factor, int64 quadratic_cost_factor, int vehicle)
Sets the linear and quadratic cost factor of the given vehicle.
This filter accepts deltas for which the assignment satisfies the constraints of the Solver.
Definition: routing.h:3557
Decision * Next(Solver *solver) override
void SetArcCostEvaluatorOfVehicle(int evaluator_index, int vehicle)
Sets the cost function for a given vehicle route.
Assignment * ReadAssignmentFromRoutes(const std::vector< std::vector< int64 >> &routes, bool ignore_inactive_indices)
Restores the routes as the current solution.
void SetFixedCostOfAllVehicles(int64 cost)
Sets the fixed cost of all vehicle routes.
const std::vector< int64 > & GetAmortizedLinearCostFactorOfVehicles() const
Definition: routing.h:876
Definition: routing.h:2887
static const DisjunctionIndex kNoDisjunction
Constant used to express the "no disjunction" index, returned when a node does not appear in any disj...
Definition: routing.h:358
std::vector< std::deque< int > > vehicles_per_vehicle_class_
Definition: routing.h:3339
virtual void SetVehicleIndex(int64 node, int vehicle)
Definition: routing.h:2796
int nodes() const
Sizes and indices Returns the number of nodes in the model.
Definition: routing.h:1245
bool AddDimensionDependentDimensionWithVehicleCapacity(const std::vector< int > &transits, const RoutingDimension *base_dimension, int64 slack_max, std::vector< int64 > vehicle_capacities, bool fix_start_cumul_to_zero, const std::string &name)
As above, but pure_transits are taken to be zero evaluators.
Definition: routing.h:3409
SUBTLE: The vehicle's fixed cost is skipped on purpose here, because we can afford to do so:
Definition: routing.h:295
~CheapestAdditionFilteredHeuristic() override
Definition: routing.h:3177
bool HasCumulVarSoftUpperBound(int64 index) const
Returns true if a soft upper bound has been set for a given variable index.
DecisionBuilder * MakeSetValuesFromTargets(Solver *solver, std::vector< IntVar * > variables, std::vector< int64 > targets)
A decision builder which tries to assign values to variables as close as possible to target values fi...
int64 offset
Definition: routing.h:2446
int GetVisitType(int64 index) const
int64 GetArcCostForClass(int64 from_index, int64 to_index, int64 cost_class_index) const
Returns the cost of the segment between two nodes for a given cost class.
gtl::ITIVector< DimensionIndex, int64 > dimension_end_cumuls_min
Definition: routing.h:339
void MakeUnassignedNodesUnperformed()
Make all unassigned nodes unperformed.
bool TypeOccursOnRoute(int type) const
Returns true iff any occurrence of the given type was seen on the route, i.e.
bool CheckVehicle(int vehicle, const std::function< int64(int64)> &next_accessor)
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
friend class RoutingModelInspector
Definition: routing.h:1749
Definition: routing.h:1965
bool Propagate(Tasks *tasks)
Computes new bounds for all tasks, returns false if infeasible.
const RoutingDimension * base_dimension() const
Returns the parent in the dependency tree if any or nullptr otherwise.
Definition: routing.h:2404
bool AreVehicleTransitsPositive(int vehicle) const
Returns true iff the transit evaluator of 'vehicle' is positive for all arcs.
Definition: routing.h:2255
RoutingModel * model() const
Definition: routing.h:2783
int Size() const
Returns the number of variables the decision builder is trying to instantiate.
Definition: routing.h:2750
const std::vector< IntVar * > & cumuls() const
Like CumulVar(), TransitVar(), SlackVar() but return the whole variable vectors instead (indexed by i...
Definition: routing.h:2186
@ TYPE_ON_VEHICLE_UP_TO_VISIT
With the following policy, the visit enforces that type 'T' is considered on the route from its start...
Definition: routing.h:734
@ ROUTING_FAIL
No solution found to the problem after calling RoutingModel::Solve().
Definition: routing.h:220
void CloseModel()
Closes the current routing model; after this method is called, no modification to the model can be do...
int64 cost
Definition: routing.h:2125
std::vector< std::pair< int64, int64 > > distance_duration
Definition: routing.h:1783
const RoutingDimension & GetDimensionOrDie(const std::string &dimension_name) const
Returns a dimension from its name. Dies if the dimension does not exist.
Local Search Filters are used for fast neighbor pruning.
int RegisterPositiveTransitCallback(TransitCallback2 callback)
const Assignment * BuildSolutionFromRoutes(const std::function< int64(int64)> &next_accessor)
Builds a solution starting from the routes formed by the next accessor.
~RoutingDimension()
bool AddDimensionWithVehicleTransitAndCapacity(const std::vector< int > &evaluator_indices, int64 slack_max, std::vector< int64 > vehicle_capacities, bool fix_start_cumul_to_zero, const std::string &name)
void CloseModelWithParameters(const RoutingSearchParameters &search_parameters)
Same as above taking search parameters (as of 10/2015 some the parameters have to be set when closing...
const VariableIndexEvaluator2 & StateDependentTransitCallback(int callback_index) const
Definition: routing.h:386
int64 GetPickupToDeliveryLimitForPair(int pair_index, int pickup, int delivery) const
const IndexPairs & GetPickupAndDeliveryPairs() const
Returns pickup and delivery pairs currently in the model.
Definition: routing.h:705
double neighbors_ratio
If neighbors_ratio < 1 then for each node only this ratio of its neighbors leading to the smallest ar...
Definition: routing.h:3270
void AppendTasksFromIntervals(const std::vector< IntervalVar * > &intervals, DisjunctivePropagator::Tasks *tasks)
int64 GetNumberOfDecisionsInFirstSolution(const RoutingSearchParameters &search_parameters) const
Returns statistics on first solution search, number of decisions sent to filters, number of decisions...
int64 Start(int i) const
Definition: routing.h:3500
int64 GetTransitValue(int64 from_index, int64 to_index, int64 vehicle) const
Returns the transition value for a given pair of nodes (as var index); this value is the one taken by...
TypeRegulationsConstraint(const RoutingModel &model)
static bool LessThan(const VehicleClass &a, const VehicleClass &b)
Comparator for STL containers and algorithms.
void InitializePriorityQueue(std::vector< std::vector< StartEndValue > > *start_end_distances_per_node, Queue *priority_queue)
Initializes the priority_queue by inserting the best entry corresponding to each node,...
Definition: routing.h:3295
bool Accept(const Assignment *delta, const Assignment *deltadelta, int64 objective_min, int64 objective_max) override
Accepts a "delta" given the assignment with which the filter has been synchronized; the delta holds t...
SimpleBoundCosts::BoundCost GetSoftSpanUpperBoundForVehicle(int vehicle) const
Definition: routing.h:2506
~SequentialSavingsFilteredHeuristic() override
Definition: routing.h:3395
const Assignment * SolveWithParameters(const RoutingSearchParameters &search_parameters, std::vector< const Assignment * > *solutions=nullptr)
Solves the current routing model with the given parameters.
const std::vector< int64 > & vehicle_span_cost_coefficients() const
Definition: routing.h:2473
int evaluator_index
Index of the arc cost evaluator, registered in the RoutingModel class.
Definition: routing.h:273
void Post() override
static const int64 kNoPenalty
Constant used to express a hard constraint instead of a soft penalty.
Definition: routing.h:354
@ ROUTING_FAIL_TIMEOUT
Time limit reached before finding a solution with RoutingModel::Solve().
Definition: routing.h:222
const std::vector< std::unique_ptr< LocalDimensionCumulOptimizer > > & GetLocalDimensionCumulOptimizers() const
Definition: routing.h:531
Christofides addition heuristic.
Definition: routing.h:3456
void AddWeightedVariableMinimizedByFinalizer(IntVar *var, int64 cost)
Adds a variable to minimize in the solution finalizer, with a weighted priority: the higher the more ...
const std::vector< NodePrecedence > & GetNodePrecedences() const
Definition: routing.h:2452
IntVarLocalSearchFilter * MakeVehicleBreaksFilter(const RoutingModel &routing_model, const RoutingDimension &dimension)
std::string DebugString() const override
Definition: routing.h:2910
RoutingIndexPairs IndexPairs
Definition: routing.h:246
const absl::flat_hash_set< int > & GetHardTypeIncompatibilitiesOfType(int type) const
Returns visit types incompatible with a given type.
const std::vector< IntVar * > & slacks() const
Definition: routing.h:2189
void SetPrimaryConstrainedDimension(const std::string &dimension_name)
Set the given dimension as "primary constrained".
Definition: routing.h:562
SortedDisjointIntervalList GetAllowedIntervalsInRange(int64 index, int64 min_value, int64 max_value) const
Returns allowed intervals for a given node in a given interval.
void InitializeCheck(int vehicle, const std::function< int64(int64)> &next_accessor)
friend class RoutingModelInspector
Definition: routing.h:2631
int GetVehicleClassesCount() const
Returns the number of different vehicle classes in the model.
Definition: routing.h:1194
void SetPickupToDeliveryLimitFunctionForPair(PickupToDeliveryLimitFunction limit_function, int pair_index)
Definition: routing.h:2123
int64 Next(const Assignment &assignment, int64 index) const
Assignment inspection Returns the variable index of the node directly after the node corresponding to...
Definition: routing.h:2819
std::string DebugOutputAssignment(const Assignment &solution_assignment, const std::string &dimension_to_print) const
Print some debugging information about an assignment, including the feasible intervals of the CumulVa...
ComparatorCheapestAdditionFilteredHeuristic(RoutingModel *model, Solver::VariableValueComparator comparator, const std::vector< LocalSearchFilter * > &filters)
Takes ownership of evaluator.
~RoutingModel()
Checker for type incompatibilities.
Definition: routing.h:2012
void AddPickupAndDelivery(int64 pickup, int64 delivery)
Notifies that index1 and index2 form a pair of nodes which should belong to the same route.
bool EdgeFinding(Tasks *tasks)
Does edge-finding deductions on all tasks.
int64 GetDepot() const
Returns the variable index of the first starting or ending node of all routes.
GlobalVehicleBreaksConstraint(const RoutingDimension *dimension)
CPFeasibilityFilter(const RoutingModel *routing_model)
int64 GetFirstPossibleGreaterOrEqualValueForNode(int64 index, int64 min_value) const
Returns the smallest value outside the forbidden intervals of node 'index' that is greater than or eq...
Definition: routing.h:2201
IntVar * CostVar() const
Returns the global cost variable which is being minimized.
Definition: routing.h:1143
bool Contains(int64 index) const
Returns true if the variable of index 'index' is in the current solution.
Definition: routing.h:2745
virtual bool CheckTypeRegulations(int type, VisitTypePolicy policy, int pos)=0
bool is_sequential
Whether the routes are constructed sequentially or in parallel.
Definition: routing.h:2889
const std::vector< DisjunctionIndex > & GetDisjunctionIndices(int64 index) const
Returns the indices of the disjunctions to which an index belongs.
Definition: routing.h:590
void SetGlobalSpanCostCoefficient(int64 coefficient)
Sets a cost proportional to the global dimension span, that is the difference between the largest val...
int64 GetNext(int64 node) const
Definition: routing.h:3494
const std::vector< IntVar * > & VehicleVars() const
Returns all vehicle variables of the model, such that VehicleVars(i) is the vehicle variable of the n...
Definition: routing.h:1127
void ArrangeIndices(std::vector< int64 > *indices)
void AppendTasksFromPath(const std::vector< int64 > &path, const std::vector< int64 > &min_travels, const std::vector< int64 > &max_travels, const std::vector< int64 > &pre_travels, const std::vector< int64 > &post_travels, const RoutingDimension &dimension, DisjunctivePropagator::Tasks *tasks)
@ PICKUP_AND_DELIVERY_FIFO
Deliveries must be performed in the same order as pickups.
Definition: routing.h:234
bool RoutesToAssignment(const std::vector< std::vector< int64 >> &routes, bool ignore_inactive_indices, bool close_routes, Assignment *const assignment) const
Fills an assignment from a specification of the routes of the vehicles.
const std::vector< int64 > & vehicle_capacities() const
Returns the capacities for all vehicles.
Definition: routing.h:2236
const std::vector< int64 > & GetNewSynchronizedUnperformedNodes() const
Definition: routing.h:3507
void SetArcCostEvaluatorOfAllVehicles(int evaluator_index)
Sets the cost function of the model such that the cost of a segment of a route between node 'from' an...
Assignment *const assignment_
Definition: routing.h:2756
A CheapestAdditionFilteredHeuristic where the notion of 'cheapest arc' comes from an arc comparator.
Definition: routing.h:3237
bool HasVehicleWithCostClassIndex(CostClassIndex cost_class_index) const
Returns true iff the model contains a vehicle with the given cost_class_index.
Definition: routing.h:1176
int64 GetHomogeneousCost(int64 from_index, int64 to_index) const
Returns the cost of the segment between two nodes supposing all vehicle costs are the same (returns t...
Definition: routing.h:1155
bool HasHardTypeIncompatibilities() const
Returns true iff any hard (resp.
Definition: routing.h:764
int64 number_of_rejects() const
std::vector< std::pair< int64, int64 > > GetPerfectBinaryDisjunctions() const
Returns the list of all perfect binary disjunctions, as pairs of variable indices: a disjunction is "...
bool AddConstantDimensionWithSlack(int64 value, int64 capacity, int64 slack_max, bool fix_start_cumul_to_zero, const std::string &name)
Creates a dimension where the transit variable is constrained to be equal to 'value'; 'capacity' is t...
SavingsFilteredHeuristic(RoutingModel *model, const RoutingIndexManager *manager, SavingsParameters parameters, const std::vector< LocalSearchFilter * > &filters)
~CPFeasibilityFilter() override
Definition: routing.h:3560
virtual std::string DebugString() const
Definition: routing.h:2713
A CheapestAdditionFilteredHeuristic where the notion of 'cheapest arc' comes from an arc evaluator.
Definition: routing.h:3214
gtl::ITIVector< DimensionIndex, int64 > dimension_start_cumuls_max
Definition: routing.h:338
bool HasSameVehicleTypeRequirements() const
Returns true iff any same-route (resp.
Definition: routing.h:809
CheapestInsertionFilteredHeuristic(RoutingModel *model, std::function< int64(int64, int64, int64)> evaluator, std::function< int64(int64)> penalty_evaluator, const std::vector< LocalSearchFilter * > &filters)
Takes ownership of evaluator.
const std::vector< int > & GetSameVehicleIndicesOfIndex(int node) const
Returns variable indices of nodes constrained to be on the same route.
Definition: routing.h:1196
int GetNonZeroCostClassesCount() const
Ditto, minus the 'always zero', built-in cost class.
Definition: routing.h:1186
int end_equivalence_class
Definition: routing.h:334
bool operator<(const DimensionCost &cost) const
Definition: routing.h:299
bool DistanceDuration(Tasks *tasks)
Assignment *const BuildSolution()
Builds a solution.
bool IsVehicleAllowedForIndex(int vehicle, int64 index)
Returns true if a vehicle is allowed to visit a given node.
Definition: routing.h:653
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
IntVarLocalSearchFilter * MakeGlobalLPCumulFilter(GlobalDimensionCumulOptimizer *optimizer, bool filter_objective_cost)
~SavingsFilteredHeuristic() override
void AddSameVehicleRequiredTypeAlternatives(int dependent_type, absl::flat_hash_set< int > required_type_alternatives)
Requirements: NOTE: As of 2019-04, cycles in the requirement graph are not supported,...
Assignment * CompactAndCheckAssignment(const Assignment &assignment) const
Same as CompactAssignment() but also checks the validity of the final compact solution; if it is not ...
int64 Start(int vehicle) const
Model inspection.
Definition: routing.h:1104
Assignment * ReadAssignment(const std::string &file_name)
Reads an assignment from a file and returns the current solution.
const std::vector< SortedDisjointIntervalList > & forbidden_intervals() const
Returns forbidden intervals for each node.
Definition: routing.h:2192
int vehicle_to_class(int vehicle) const
Definition: routing.h:2259
std::pair< StartEndValue, int > Seed
Definition: routing.h:2828
Decision builder building a solution using heuristics with local search filters to evaluate its feasi...
Definition: routing.h:2677
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
Definition: routing.h:2808
SequentialSavingsFilteredHeuristic(RoutingModel *model, const RoutingIndexManager *manager, SavingsParameters parameters, const std::vector< LocalSearchFilter * > &filters)
Definition: routing.h:3390
const Assignment * SolveFromAssignmentWithParameters(const Assignment *assignment, const RoutingSearchParameters &search_parameters, std::vector< const Assignment * > *solutions=nullptr)
std::vector< int64 > end_min
Definition: routing.h:1779
std::function< int64(int64, int64)> RoutingTransitCallback2
Definition: routing_types.h:42
RoutingDimension * GetMutableDimension(const std::string &dimension_name) const
Returns a dimension from its name.
Definition: routing.h:322
void SetSectors(int sectors)
Definition: routing.h:2644
int RegisterTransitCallback(TransitCallback2 callback)
void AppendDimensionCumulFilters(const std::vector< RoutingDimension * > &dimensions, const RoutingSearchParameters &parameters, bool filter_objective_cost, std::vector< LocalSearchFilter * > *filters)
IntVarLocalSearchFilter * MakePathCumulFilter(const RoutingDimension &dimension, const RoutingSearchParameters &parameters, bool propagate_own_objective_value, bool filter_objective_cost)
IntVar * VehicleCostsConsideredVar(int vehicle) const
Returns the variable specifying whether or not costs are considered for vehicle.
Definition: routing.h:1136
bool HasTemporalTypeIncompatibilities() const
Definition: routing.h:767
virtual void OnInitializeCheck()
Definition: routing.h:1998
std::vector< DimensionCost > dimension_transit_evaluator_class_and_cost_coefficient
Definition: routing.h:307
Status status() const
Returns the current status of the routing model.
Definition: routing.h:975
@ ADDED_TYPE_REMOVED_FROM_VEHICLE
When visited, one instance of type 'T' previously added to the route (TYPE_ADDED_TO_VEHICLE),...
Definition: routing.h:731
bool IsVehicleUsed(const Assignment &assignment, int vehicle) const
Returns true if the route of 'vehicle' is non empty in 'assignment'.
void Post() override
int Size()
Definition: routing.h:2131
std::string DebugString() const override
Definition: routing.h:3417
void AddNodePrecedence(NodePrecedence precedence)
Definition: routing.h:2449
Definition: routing.h:3388
static const char kRemoveValues[]
Definition: routing.h:1760
void SynchronizeFilters()
Synchronizes filters with an assignment (the current solution).