 |
OR-Tools
8.0
|
Go to the documentation of this file.
157 #ifndef OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_H_
158 #define OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_H_
161 #include <functional>
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"
196 class GlobalDimensionCumulOptimizer;
197 class LocalDimensionCumulOptimizer;
198 class LocalSearchOperator;
200 class IntVarFilteredDecisionBuilder;
201 class IntVarFilteredHeuristic;
202 class IndexNeighborFinder;
204 class RoutingDimension;
306 std::vector<DimensionCost>
314 if (
a.evaluator_index !=
b.evaluator_index) {
315 return a.evaluator_index <
b.evaluator_index;
317 return a.dimension_transit_evaluator_class_and_cost_coefficient <
318 b.dimension_transit_evaluator_class_and_cost_coefficient;
351 #endif // defined(SWIG)
407 CHECK_LT(callback_index, transit_evaluators_.size());
408 return transit_evaluators_[callback_index];
411 CHECK_LT(callback_index, unary_transit_evaluators_.size());
412 return unary_transit_evaluators_[callback_index];
415 int callback_index)
const {
416 CHECK_LT(callback_index, state_dependent_transit_evaluators_.size());
417 return state_dependent_transit_evaluators_[callback_index];
443 bool fix_start_cumul_to_zero,
const std::string&
name);
445 const std::vector<int>& evaluator_indices,
int64 slack_max,
448 std::vector<int64> vehicle_capacities,
449 bool fix_start_cumul_to_zero,
450 const std::string&
name);
452 const std::vector<int>& evaluator_indices,
int64 slack_max,
453 std::vector<int64> vehicle_capacities,
bool fix_start_cumul_to_zero,
454 const std::string&
name);
463 bool fix_start_cumul_to_zero,
464 const std::string&
name);
466 bool fix_start_cumul_to_zero,
467 const std::string&
name) {
469 fix_start_cumul_to_zero,
name);
479 bool fix_start_cumul_to_zero,
480 const std::string&
name);
489 std::vector<std::vector<int64> > values,
498 const std::vector<int>& pure_transits,
499 const std::vector<int>& dependent_transits,
501 std::vector<int64> vehicle_capacities,
bool fix_start_cumul_to_zero,
502 const std::string&
name) {
503 return AddDimensionDependentDimensionWithVehicleCapacityInternal(
504 pure_transits, dependent_transits, base_dimension, slack_max,
505 std::move(vehicle_capacities), fix_start_cumul_to_zero,
name);
511 int64 slack_max, std::vector<int64> vehicle_capacities,
512 bool fix_start_cumul_to_zero,
const std::string&
name);
516 int64 vehicle_capacity,
bool fix_start_cumul_to_zero,
517 const std::string&
name);
519 int pure_transit,
int dependent_transit,
521 int64 vehicle_capacity,
bool fix_start_cumul_to_zero,
522 const std::string&
name);
539 std::vector<IntVar*> spans,
540 std::vector<IntVar*> total_slacks);
547 return dimensions_.get();
554 const std::vector<std::unique_ptr<GlobalDimensionCumulOptimizer> >&
556 return global_dimension_optimizers_;
558 const std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >&
560 return local_dimension_optimizers_;
562 const std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >&
564 return local_dimension_mp_optimizers_;
578 bool HasDimension(
const std::string& dimension_name)
const;
581 const std::string& dimension_name)
const;
585 const std::string& dimension_name)
const;
591 DCHECK(dimension_name.empty() ||
HasDimension(dimension_name));
592 primary_constrained_dimension_ = dimension_name;
596 return primary_constrained_dimension_;
616 int64 max_cardinality = 1);
620 return index_to_disjunctions_[
index];
625 template <
typename F>
629 if (disjunctions_[disjunction].
value.max_cardinality == max_cardinality) {
630 for (
const int64 d_index : disjunctions_[disjunction].indices) {
636 #if !defined(SWIGPYTHON)
641 return disjunctions_[
index].indices;
643 #endif // !defined(SWIGPYTHON)
646 return disjunctions_[
index].value.penalty;
651 return disjunctions_[
index].value.max_cardinality;
682 return allowed_vehicles_[
index].empty() ||
683 allowed_vehicles_[
index].find(vehicle) !=
684 allowed_vehicles_[
index].end();
712 const std::vector<std::pair<int, int> >&
715 const std::vector<std::pair<int, int> >&
734 return pickup_delivery_pairs_;
736 const std::vector<std::pair<DisjunctionIndex, DisjunctionIndex>>&
738 return pickup_delivery_disjunctions_;
783 return topologically_sorted_visit_types_;
799 return has_hard_type_incompatibilities_;
802 return has_temporal_type_incompatibilities_;
815 int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
821 int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
828 int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
832 const std::vector<absl::flat_hash_set<int> >&
835 const std::vector<absl::flat_hash_set<int> >&
838 const std::vector<absl::flat_hash_set<int> >&
844 return has_same_vehicle_type_requirements_;
847 return has_temporal_type_requirements_;
877 max_active_vehicles_ = max_active_vehicles;
913 int64 quadratic_cost_factor);
916 int64 quadratic_cost_factor,
920 return linear_cost_factor_of_vehicle_;
923 return quadratic_cost_factor_of_vehicle_;
927 DCHECK_LT(vehicle, vehicles_);
928 consider_empty_route_costs_[vehicle] = consider_costs;
932 DCHECK_LT(vehicle, vehicles_);
933 return consider_empty_route_costs_[vehicle];
940 return first_solution_evaluator_;
945 first_solution_evaluator_ = std::move(evaluator);
980 const RoutingSearchParameters& search_parameters);
987 const Assignment*
Solve(
const Assignment* assignment =
nullptr);
996 const RoutingSearchParameters& search_parameters,
997 std::vector<const Assignment*>* solutions =
nullptr);
999 const Assignment* assignment,
1000 const RoutingSearchParameters& search_parameters,
1001 std::vector<const Assignment*>* solutions =
nullptr);
1008 Assignment* target_assignment,
const RoutingModel* source_model,
1009 const Assignment* source_assignment);
1027 IntVar*
ApplyLocks(
const std::vector<int64>& locks);
1061 const std::vector<std::vector<int64>>& routes,
1062 bool ignore_inactive_indices);
1080 bool ignore_inactive_indices,
bool close_routes,
1081 Assignment*
const assignment)
const;
1086 std::vector<std::vector<int64>>*
const routes)
const;
1093 const Assignment& assignment);
1131 const Assignment* original_assignment, absl::Duration duration_limit);
1146 CHECK(filter !=
nullptr);
1148 LOG(WARNING) <<
"Model is closed, filter addition will be ignored.";
1150 extra_filters_.push_back(filter);
1157 int64 End(
int vehicle)
const {
return ends_[vehicle]; }
1170 bool IsVehicleUsed(
const Assignment& assignment,
int vehicle)
const;
1172 #if !defined(SWIGPYTHON)
1173 const std::vector<IntVar*>&
Nexts()
const {
return nexts_; }
1178 const std::vector<IntVar*>&
VehicleVars()
const {
return vehicle_vars_; }
1180 IntVar* NextVar(int64 index) const { return nexts_[index]; }
1188 return vehicle_active_[vehicle];
1193 return vehicle_costs_considered_[vehicle];
1204 int64 vehicle)
const;
1207 return costs_are_homogeneous_across_vehicles_;
1224 int64 cost_class_index)
const;
1228 return cost_class_index_of_vehicle_[vehicle];
1234 if (cost_class_index == kCostClassIndexOfZeroCost) {
1235 return has_vehicle_with_zero_cost_class_;
1237 return cost_class_index < cost_classes_.size();
1247 return vehicle_class_index_of_vehicle_[vehicle];
1254 return same_vehicle_groups_[same_vehicle_group_[node]];
1259 return vehicle_type_container_;
1286 const Assignment& solution_assignment,
1287 const std::string& dimension_to_print)
const;
1294 std::vector<std::vector<std::pair<int64, int64>>>
GetCumulBounds(
1297 Solver*
solver()
const {
return solver_.get(); }
1303 DCHECK(limit_ !=
nullptr);
1304 return limit_->Check();
1309 DCHECK(limit_ !=
nullptr);
1310 return limit_->AbsoluteSolverDeadline() - solver_->Now();
1319 int64 Size()
const {
return nodes_ + vehicles_ - start_end_count_; }
1324 const RoutingSearchParameters& search_parameters)
const;
1326 const RoutingSearchParameters& search_parameters)
const;
1330 return automatic_first_solution_strategy_;
1340 std::function<std::vector<operations_research::IntVar*>(
RoutingModel*)>;
1368 std::vector<IntVar*> variables);
1370 DecisionBuilder* MakeSelfDependentDimensionFinalizer(
1388 enum RoutingLocalSearchOperator {
1391 LIGHT_RELOCATE_PAIR,
1399 GLOBAL_CHEAPEST_INSERTION_CLOSE_NODES_LNS,
1400 LOCAL_CHEAPEST_INSERTION_CLOSE_NODES_LNS,
1401 GLOBAL_CHEAPEST_INSERTION_PATH_LNS,
1402 LOCAL_CHEAPEST_INSERTION_PATH_LNS,
1403 GLOBAL_CHEAPEST_INSERTION_EXPENSIVE_CHAIN_LNS,
1404 LOCAL_CHEAPEST_INSERTION_EXPENSIVE_CHAIN_LNS,
1405 RELOCATE_EXPENSIVE_CHAIN,
1409 RELOCATE_AND_MAKE_ACTIVE,
1410 MAKE_ACTIVE_AND_RELOCATE,
1412 MAKE_CHAIN_INACTIVE,
1414 EXTENDED_SWAP_ACTIVE,
1420 EXCHANGE_RELOCATE_PAIR,
1423 LOCAL_SEARCH_OPERATOR_COUNTER
1429 template <
typename T>
1430 struct ValuedNodes {
1431 std::vector<int64> indices;
1434 struct DisjunctionValues {
1436 int64 max_cardinality;
1438 typedef ValuedNodes<DisjunctionValues> Disjunction;
1442 struct CostCacheElement {
1454 void AddNoCycleConstraintInternal();
1455 bool AddDimensionWithCapacityInternal(
1456 const std::vector<int>& evaluator_indices,
int64 slack_max,
1457 std::vector<int64> vehicle_capacities,
bool fix_start_cumul_to_zero,
1458 const std::string&
name);
1459 bool AddDimensionDependentDimensionWithVehicleCapacityInternal(
1460 const std::vector<int>& pure_transits,
1461 const std::vector<int>& dependent_transits,
1463 std::vector<int64> vehicle_capacities,
bool fix_start_cumul_to_zero,
1464 const std::string&
name);
1465 bool InitializeDimensionInternal(
1466 const std::vector<int>& evaluator_indices,
1467 const std::vector<int>& state_dependent_evaluator_indices,
1468 int64 slack_max,
bool fix_start_cumul_to_zero,
1470 DimensionIndex GetDimensionIndex(
const std::string& dimension_name)
const;
1499 void StoreDimensionCumulOptimizers(
const RoutingSearchParameters&
parameters);
1501 void ComputeCostClasses(
const RoutingSearchParameters&
parameters);
1502 void ComputeVehicleClasses();
1510 void ComputeVehicleTypes();
1520 void FinalizeVisitTypes();
1523 void AppendHomogeneousArcCosts(
const RoutingSearchParameters&
parameters,
1525 std::vector<IntVar*>* cost_elements);
1526 void AppendArcCosts(
const RoutingSearchParameters&
parameters,
int node_index,
1527 std::vector<IntVar*>* cost_elements);
1528 Assignment* DoRestoreAssignment();
1530 int64 SafeGetCostClassInt64OfVehicle(
int64 vehicle)
const {
1531 DCHECK_LT(0, vehicles_);
1533 : kCostClassIndexOfZeroCost)
1537 const CostClass& cost_class)
const;
1541 void AddPickupAndDeliverySetsInternal(
const std::vector<int64>& pickups,
1542 const std::vector<int64>& deliveries);
1545 IntVar* CreateSameVehicleCost(
int vehicle_index);
1548 int FindNextActive(
int index,
const std::vector<int64>& indices)
const;
1552 bool RouteCanBeUsedByVehicle(
const Assignment& assignment,
int start_index,
1561 bool ReplaceUnusedVehicle(
int unused_vehicle,
int active_vehicle,
1562 Assignment* compact_assignment)
const;
1564 void QuietCloseModel();
1565 void QuietCloseModelWithParameters(
1573 bool SolveMatchingModel(Assignment* assignment,
1576 bool AppendAssignmentIfFeasible(
1578 const Assignment& assignment,
1579 std::vector<std::unique_ptr<Assignment>>* assignments);
1581 void LogSolution(
const RoutingSearchParameters&
parameters,
1583 const std::string& description,
int64 solution_cost,
1584 int64 start_time_ms);
1587 Assignment* CompactAssignmentInternal(
const Assignment& assignment,
1588 bool check_compact_assignment)
const;
1593 std::string FindErrorInSearchParametersForModel(
1594 const RoutingSearchParameters& search_parameters)
const;
1596 void SetupSearch(
const RoutingSearchParameters& search_parameters);
1599 Assignment* GetOrCreateAssignment();
1600 Assignment* GetOrCreateTmpAssignment();
1601 RegularLimit* GetOrCreateLimit();
1602 RegularLimit* GetOrCreateLocalSearchLimit();
1603 RegularLimit* GetOrCreateLargeNeighborhoodSearchLimit();
1604 RegularLimit* GetOrCreateFirstSolutionLargeNeighborhoodSearchLimit();
1605 LocalSearchOperator* CreateInsertionOperator();
1606 LocalSearchOperator* CreateMakeInactiveOperator();
1607 void CreateNeighborhoodOperators(
const RoutingSearchParameters&
parameters);
1608 LocalSearchOperator* GetNeighborhoodOperators(
1609 const RoutingSearchParameters& search_parameters)
const;
1610 std::vector<LocalSearchFilter*> GetOrCreateLocalSearchFilters(
1612 LocalSearchFilterManager* GetOrCreateLocalSearchFilterManager(
1614 std::vector<LocalSearchFilter*> GetOrCreateFeasibilityFilters(
1616 LocalSearchFilterManager* GetOrCreateFeasibilityFilterManager(
1618 LocalSearchFilterManager* GetOrCreateStrongFeasibilityFilterManager(
1620 DecisionBuilder* CreateSolutionFinalizer(SearchLimit* lns_limit);
1621 DecisionBuilder* CreateFinalizerForMinimizedAndMaximizedVariables();
1622 void CreateFirstSolutionDecisionBuilders(
1623 const RoutingSearchParameters& search_parameters);
1624 DecisionBuilder* GetFirstSolutionDecisionBuilder(
1625 const RoutingSearchParameters& search_parameters)
const;
1626 IntVarFilteredDecisionBuilder* GetFilteredFirstSolutionDecisionBuilderOrNull(
1627 const RoutingSearchParameters&
parameters)
const;
1628 LocalSearchPhaseParameters* CreateLocalSearchParameters(
1629 const RoutingSearchParameters& search_parameters);
1630 DecisionBuilder* CreateLocalSearchDecisionBuilder(
1631 const RoutingSearchParameters& search_parameters);
1632 void SetupDecisionBuilders(
const RoutingSearchParameters& search_parameters);
1633 void SetupMetaheuristics(
const RoutingSearchParameters& search_parameters);
1634 void SetupAssignmentCollector(
1635 const RoutingSearchParameters& search_parameters);
1636 void SetupTrace(
const RoutingSearchParameters& search_parameters);
1637 void SetupSearchMonitors(
const RoutingSearchParameters& search_parameters);
1638 bool UsesLightPropagation(
1639 const RoutingSearchParameters& search_parameters)
const;
1642 int GetVehicleStartClass(
int64 start)
const;
1644 void InitSameVehicleGroups(
int number_of_groups) {
1645 same_vehicle_group_.assign(
Size(), 0);
1646 same_vehicle_groups_.assign(number_of_groups, {});
1648 void SetSameVehicleGroup(
int index,
int group) {
1649 same_vehicle_group_[
index] = group;
1650 same_vehicle_groups_[group].push_back(
index);
1654 std::unique_ptr<Solver> solver_;
1657 int max_active_vehicles_;
1658 Constraint* no_cycle_constraint_ =
nullptr;
1660 std::vector<IntVar*> nexts_;
1661 std::vector<IntVar*> vehicle_vars_;
1662 std::vector<IntVar*> active_;
1664 std::vector<IntVar*> vehicle_active_;
1665 std::vector<IntVar*> vehicle_costs_considered_;
1670 std::vector<IntVar*> is_bound_to_end_;
1671 mutable RevSwitch is_bound_to_end_ct_added_;
1673 absl::flat_hash_map<std::string, DimensionIndex> dimension_name_to_index_;
1679 std::vector<std::unique_ptr<GlobalDimensionCumulOptimizer> >
1680 global_dimension_optimizers_;
1682 std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >
1683 local_dimension_optimizers_;
1684 std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >
1685 local_dimension_mp_optimizers_;
1688 std::string primary_constrained_dimension_;
1690 IntVar* cost_ =
nullptr;
1691 std::vector<int> vehicle_to_transit_cost_;
1692 std::vector<int64> fixed_cost_of_vehicle_;
1693 std::vector<CostClassIndex> cost_class_index_of_vehicle_;
1694 bool has_vehicle_with_zero_cost_class_;
1695 std::vector<int64> linear_cost_factor_of_vehicle_;
1696 std::vector<int64> quadratic_cost_factor_of_vehicle_;
1697 bool vehicle_amortized_cost_factors_set_;
1708 std::vector<bool> consider_empty_route_costs_;
1712 bool costs_are_homogeneous_across_vehicles_;
1713 bool cache_callbacks_;
1714 mutable std::vector<CostCacheElement> cost_cache_;
1715 std::vector<VehicleClassIndex> vehicle_class_index_of_vehicle_;
1719 VehicleTypeContainer vehicle_type_container_;
1720 std::function<int(
int64)> vehicle_start_class_callback_;
1723 std::vector<std::vector<DisjunctionIndex> > index_to_disjunctions_;
1725 std::vector<ValuedNodes<int64> > same_vehicle_costs_;
1728 std::vector<absl::flat_hash_set<int>> allowed_vehicles_;
1732 std::vector<std::pair<DisjunctionIndex, DisjunctionIndex> >
1733 pickup_delivery_disjunctions_;
1738 std::vector<std::vector<std::pair<int, int> > > index_to_pickup_index_pairs_;
1740 std::vector<std::vector<std::pair<int, int> > >
1741 index_to_delivery_index_pairs_;
1743 std::vector<PickupAndDeliveryPolicy> vehicle_pickup_delivery_policy_;
1745 std::vector<int> same_vehicle_group_;
1747 std::vector<std::vector<int>> same_vehicle_groups_;
1750 std::vector<int> index_to_visit_type_;
1752 std::vector<VisitTypePolicy> index_to_type_policy_;
1754 std::vector<std::vector<int> > single_nodes_of_type_;
1755 std::vector<std::vector<int> > pair_indices_of_type_;
1757 std::vector<absl::flat_hash_set<int> >
1758 hard_incompatible_types_per_type_index_;
1759 bool has_hard_type_incompatibilities_;
1760 std::vector<absl::flat_hash_set<int> >
1761 temporal_incompatible_types_per_type_index_;
1762 bool has_temporal_type_incompatibilities_;
1764 std::vector<std::vector<absl::flat_hash_set<int> > >
1765 same_vehicle_required_type_alternatives_per_type_index_;
1766 bool has_same_vehicle_type_requirements_;
1767 std::vector<std::vector<absl::flat_hash_set<int> > >
1768 required_type_alternatives_when_adding_type_index_;
1769 std::vector<std::vector<absl::flat_hash_set<int> > >
1770 required_type_alternatives_when_removing_type_index_;
1771 bool has_temporal_type_requirements_;
1772 absl::flat_hash_map<int, absl::flat_hash_set<VisitTypePolicy> >
1773 trivially_infeasible_visit_types_to_policies_;
1778 std::vector<int> topologically_sorted_visit_types_;
1779 int num_visit_types_;
1782 std::vector<int> index_to_equivalence_class_;
1783 std::vector<int> index_to_vehicle_;
1784 std::vector<int64> starts_;
1785 std::vector<int64> ends_;
1788 RoutingIndexManager manager_;
1789 int start_end_count_;
1791 bool closed_ =
false;
1793 bool enable_deep_serialization_ =
true;
1796 std::vector<DecisionBuilder*> first_solution_decision_builders_;
1797 std::vector<IntVarFilteredDecisionBuilder*>
1798 first_solution_filtered_decision_builders_;
1799 Solver::IndexEvaluator2 first_solution_evaluator_;
1801 FirstSolutionStrategy::UNSET;
1802 std::vector<LocalSearchOperator*> local_search_operators_;
1803 std::vector<SearchMonitor*> monitors_;
1804 SolutionCollector* collect_assignments_ =
nullptr;
1805 SolutionCollector* collect_one_assignment_ =
nullptr;
1806 SolutionCollector* packed_dimensions_assignment_collector_ =
nullptr;
1807 DecisionBuilder* solve_db_ =
nullptr;
1808 DecisionBuilder* improve_db_ =
nullptr;
1809 DecisionBuilder* restore_assignment_ =
nullptr;
1810 DecisionBuilder* restore_tmp_assignment_ =
nullptr;
1811 Assignment* assignment_ =
nullptr;
1812 Assignment* preassignment_ =
nullptr;
1813 Assignment* tmp_assignment_ =
nullptr;
1814 std::vector<IntVar*> extra_vars_;
1815 std::vector<IntervalVar*> extra_intervals_;
1816 std::vector<LocalSearchOperator*> extra_operators_;
1817 LocalSearchFilterManager* local_search_filter_manager_ =
nullptr;
1818 LocalSearchFilterManager* feasibility_filter_manager_ =
nullptr;
1819 LocalSearchFilterManager* strong_feasibility_filter_manager_ =
nullptr;
1820 std::vector<LocalSearchFilter*> extra_filters_;
1822 std::vector<std::pair<IntVar*, int64>> finalizer_variable_cost_pairs_;
1823 std::vector<std::pair<IntVar*, int64>> finalizer_variable_target_pairs_;
1824 absl::flat_hash_map<IntVar*, int> finalizer_variable_cost_index_;
1825 absl::flat_hash_set<IntVar*> finalizer_variable_target_set_;
1826 std::unique_ptr<SweepArranger> sweep_arranger_;
1829 RegularLimit* limit_ =
nullptr;
1830 RegularLimit* ls_limit_ =
nullptr;
1831 RegularLimit* lns_limit_ =
nullptr;
1832 RegularLimit* first_solution_lns_limit_ =
nullptr;
1834 typedef std::pair<int64, int64> CacheKey;
1835 typedef absl::flat_hash_map<CacheKey, int64> TransitCallbackCache;
1836 typedef absl::flat_hash_map<CacheKey, StateDependentTransit>
1837 StateDependentTransitCallbackCache;
1839 std::vector<TransitCallback1> unary_transit_evaluators_;
1840 std::vector<TransitCallback2> transit_evaluators_;
1851 std::vector<bool> is_transit_evaluator_positive_;
1852 std::vector<VariableIndexEvaluator2> state_dependent_transit_evaluators_;
1853 std::vector<std::unique_ptr<StateDependentTransitCallbackCache>>
1854 state_dependent_transit_evaluators_cache_;
1943 std::vector<int> tasks_by_start_min_;
1944 std::vector<int> tasks_by_end_max_;
1945 std::vector<int> event_of_task_;
1946 std::vector<int> nonchain_tasks_by_start_max_;
1948 std::vector<int64> total_duration_before_;
1966 std::vector<int64>* values);
1970 #endif // !defined(SWIG)
1986 return "GlobalVehicleBreaksConstraint";
1989 void Post()
override;
1993 void PropagateNode(
int node);
1994 void PropagateVehicle(
int vehicle);
1995 void PropagateMaxBreakDistance(
int vehicle);
1999 std::vector<Demon*> vehicle_demons_;
2000 std::vector<int64> path_;
2006 void FillPartialPathOfVehicle(
int vehicle);
2007 void FillPathTravels(
const std::vector<int64>& path);
2019 class TaskTranslator {
2021 TaskTranslator(IntVar* start,
int64 before_start,
int64 after_start)
2023 before_start_(before_start),
2024 after_start_(after_start) {}
2029 if (start_ !=
nullptr) {
2031 }
else if (interval_ !=
nullptr) {
2032 interval_->SetStartMin(
value);
2036 if (start_ !=
nullptr) {
2038 }
else if (interval_ !=
nullptr) {
2039 interval_->SetStartMax(
value);
2043 if (interval_ !=
nullptr) {
2044 interval_->SetDurationMin(
value);
2048 if (start_ !=
nullptr) {
2050 }
else if (interval_ !=
nullptr) {
2051 interval_->SetEndMin(
value);
2055 if (start_ !=
nullptr) {
2057 }
else if (interval_ !=
nullptr) {
2058 interval_->SetEndMax(
value);
2063 IntVar* start_ =
nullptr;
2064 int64 before_start_;
2066 IntervalVar* interval_ =
nullptr;
2070 std::vector<TaskTranslator> task_translators_;
2073 DisjunctivePropagator disjunctive_propagator_;
2074 DisjunctivePropagator::Tasks tasks_;
2077 TravelBounds travel_bounds_;
2086 const std::function<
int64(
int64)>& next_accessor);
2125 const std::function<
int64(
int64)>& next_accessor);
2135 std::vector<TypePolicyOccurrence> occurrences_of_type_;
2136 std::vector<int64> current_route_visits_;
2143 bool check_hard_incompatibilities);
2147 bool HasRegulationsToCheck()
const override;
2148 bool CheckTypeRegulations(
int type,
VisitTypePolicy policy,
int pos)
override;
2152 bool check_hard_incompatibilities_;
2163 bool HasRegulationsToCheck()
const override;
2164 void OnInitializeCheck()
override {
2165 types_with_same_vehicle_requirements_on_route_.clear();
2170 bool CheckRequiredTypesCurrentlyOnRoute(
2171 const std::vector<absl::flat_hash_set<int> >& required_type_alternatives,
2174 bool CheckTypeRegulations(
int type,
VisitTypePolicy policy,
int pos)
override;
2175 bool FinalizeCheck()
const override;
2177 absl::flat_hash_set<int> types_with_same_vehicle_requirements_on_route_;
2224 void Post()
override;
2228 void PropagateNodeRegulations(
int node);
2229 void CheckRegulationsOnVehicle(
int vehicle);
2234 std::vector<Demon*> vehicle_demons_;
2256 : bound_costs_(num_bounds, default_bound_cost) {}
2259 int Size() {
return bound_costs_.size(); }
2264 std::vector<BoundCost> bound_costs_;
2266 #endif // !defined SWIG
2300 int64 vehicle_class)
const {
2301 return model_->TransitCallback(class_evaluators_[vehicle_class])(from_index,
2311 #if !defined(SWIGPYTHON)
2312 const std::vector<IntVar*>&
cumuls()
const {
return cumuls_; }
2316 const std::vector<IntVar*>&
transits()
const {
return transits_; }
2317 const std::vector<IntVar*>&
slacks()
const {
return slacks_; }
2318 #if !defined(SWIGCSHARP) && !defined(SWIGJAVA)
2321 return forbidden_intervals_;
2326 int64 max_value)
const;
2330 int64 min_value)
const {
2331 DCHECK_LT(
index, forbidden_intervals_.size());
2333 forbidden_intervals_[
index];
2334 const auto first_forbidden_interval_it =
2337 min_value >= first_forbidden_interval_it->start) {
2339 return CapAdd(first_forbidden_interval_it->end, 1);
2349 int64 max_value)
const {
2350 DCHECK_LT(
index, forbidden_intervals_.size());
2352 forbidden_intervals_[
index];
2353 const auto last_forbidden_interval_it =
2356 max_value <= last_forbidden_interval_it->end) {
2358 return CapSub(last_forbidden_interval_it->start, 1);
2365 return vehicle_capacities_;
2370 return model_->TransitCallback(
2371 class_evaluators_[vehicle_to_class_[vehicle]]);
2377 int vehicle)
const {
2378 return model_->UnaryTransitCallbackOrNull(
2379 class_evaluators_[vehicle_to_class_[vehicle]]);
2384 return model()->is_transit_evaluator_positive_
2385 [class_evaluators_[vehicle_to_class_[vehicle]]];
2390 void SetSpanUpperBoundForVehicle(int64 upper_bound, int vehicle);
2489 #if !defined(SWIGPYTHON)
2491 int pre_travel_evaluator,
2492 int post_travel_evaluator);
2493 #endif // !defined(SWIGPYTHON)
2497 std::vector<int64> node_visit_transits);
2510 #if !defined(SWIGPYTHON)
2514 std::vector<IntervalVar*> breaks,
int vehicle,
2515 std::vector<int64> node_visit_transits,
2524 const std::vector<std::pair<int64, int64> >&
2528 int GetPreTravelEvaluatorOfVehicle(int vehicle) const;
2543 const std::string&
name()
const {
return name_; }
2548 return path_precedence_graph_;
2569 int delivery)
const;
2578 node_precedences_.push_back(precedence);
2581 return node_precedences_;
2590 return vehicle_span_upper_bounds_[vehicle];
2594 return vehicle_span_upper_bounds_;
2598 return vehicle_span_cost_coefficients_[vehicle];
2602 return vehicle_span_cost_coefficients_;
2606 return global_span_cost_coefficient_;
2610 DCHECK_GE(global_optimizer_offset_, 0);
2611 return global_optimizer_offset_;
2614 if (vehicle >= local_optimizer_offset_for_vehicle_.size()) {
2617 DCHECK_GE(local_optimizer_offset_for_vehicle_[vehicle], 0);
2618 return local_optimizer_offset_for_vehicle_[vehicle];
2626 vehicle_soft_span_upper_bound_ = absl::make_unique<SimpleBoundCosts>(
2629 vehicle_soft_span_upper_bound_->bound_cost(vehicle) = bound_cost;
2632 return vehicle_soft_span_upper_bound_ !=
nullptr;
2635 int vehicle)
const {
2637 return vehicle_soft_span_upper_bound_->bound_cost(vehicle);
2644 vehicle_quadratic_cost_soft_span_upper_bound_ =
2645 absl::make_unique<SimpleBoundCosts>(
2648 vehicle_quadratic_cost_soft_span_upper_bound_->bound_cost(vehicle) =
2652 return vehicle_quadratic_cost_soft_span_upper_bound_ !=
nullptr;
2655 int vehicle)
const {
2657 return vehicle_quadratic_cost_soft_span_upper_bound_->bound_cost(vehicle);
2668 struct PiecewiseLinearCost {
2669 PiecewiseLinearCost() :
var(nullptr),
cost(nullptr) {}
2671 std::unique_ptr<PiecewiseLinearFunction>
cost;
2676 const std::string&
name,
2679 const std::string&
name, SelfBased);
2680 void Initialize(
const std::vector<int>& transit_evaluators,
2681 const std::vector<int>& state_dependent_transit_evaluators,
2683 void InitializeCumuls();
2684 void InitializeTransits(
2685 const std::vector<int>& transit_evaluators,
2686 const std::vector<int>& state_dependent_transit_evaluators,
2688 void InitializeTransitVariables(
int64 slack_max);
2690 void SetupCumulVarSoftUpperBoundCosts(
2691 std::vector<IntVar*>* cost_elements)
const;
2693 void SetupCumulVarSoftLowerBoundCosts(
2694 std::vector<IntVar*>* cost_elements)
const;
2695 void SetupCumulVarPiecewiseLinearCosts(
2696 std::vector<IntVar*>* cost_elements)
const;
2699 void SetupGlobalSpanCost(std::vector<IntVar*>* cost_elements)
const;
2700 void SetupSlackAndDependentTransitCosts()
const;
2702 void CloseModel(
bool use_light_propagation);
2704 void SetOffsetForGlobalOptimizer(
int64 offset) {
2705 global_optimizer_offset_ =
std::max(Zero(), offset);
2708 void SetVehicleOffsetsForLocalOptimizer(std::vector<int64> offsets) {
2710 std::transform(offsets.begin(), offsets.end(), offsets.begin(),
2711 [](
int64 offset) { return std::max(Zero(), offset); });
2712 local_optimizer_offset_for_vehicle_ = std::move(offsets);
2715 std::vector<IntVar*> cumuls_;
2716 std::vector<SortedDisjointIntervalList> forbidden_intervals_;
2717 std::vector<IntVar*> capacity_vars_;
2718 const std::vector<int64> vehicle_capacities_;
2719 std::vector<IntVar*> transits_;
2720 std::vector<IntVar*> fixed_transits_;
2723 std::vector<int> class_evaluators_;
2724 std::vector<int64> vehicle_to_class_;
2726 ReverseArcListGraph<int, int> path_precedence_graph_;
2732 std::vector<NodePrecedence> node_precedences_;
2737 const RoutingDimension*
const base_dimension_;
2742 std::vector<int> state_dependent_class_evaluators_;
2743 std::vector<int64> state_dependent_vehicle_to_class_;
2748 std::vector<PickupToDeliveryLimitFunction>
2749 pickup_to_delivery_limits_per_pair_index_;
2752 bool break_constraints_are_initialized_ =
false;
2754 std::vector<std::vector<IntervalVar*> > vehicle_break_intervals_;
2755 std::vector<std::vector<std::pair<int64, int64> > >
2756 vehicle_break_distance_duration_;
2761 std::vector<int> vehicle_pre_travel_evaluators_;
2762 std::vector<int> vehicle_post_travel_evaluators_;
2764 std::vector<IntVar*> slacks_;
2765 std::vector<IntVar*> dependent_transits_;
2766 std::vector<int64> vehicle_span_upper_bounds_;
2767 int64 global_span_cost_coefficient_;
2768 std::vector<int64> vehicle_span_cost_coefficients_;
2769 std::vector<SoftBound> cumul_var_soft_upper_bound_;
2770 std::vector<SoftBound> cumul_var_soft_lower_bound_;
2771 std::vector<PiecewiseLinearCost> cumul_var_piecewise_linear_cost_;
2773 const std::string name_;
2774 int64 global_optimizer_offset_;
2775 std::vector<int64> local_optimizer_offset_for_vehicle_;
2777 std::unique_ptr<SimpleBoundCosts> vehicle_soft_span_upper_bound_;
2778 std::unique_ptr<SimpleBoundCosts>
2779 vehicle_quadratic_cost_soft_span_upper_bound_;
2791 explicit SweepArranger(
const std::vector<std::pair<int64, int64>>& points);
2797 std::vector<int> coordinates_;
2807 std::vector<IntVar*> variables,
2808 std::vector<int64> targets);
2817 : vehicle_type_container_(&vehicle_type_container) {}
2821 int Type(
int vehicle)
const {
return vehicle_type_container_->
Type(vehicle); }
2824 sorted_vehicle_classes_per_type_ =
2826 const std::vector<std::deque<int>>& vehicles_per_class =
2828 vehicles_per_vehicle_class_.resize(vehicles_per_class.size());
2829 for (
int i = 0; i < vehicles_per_vehicle_class_.size(); i++) {
2830 vehicles_per_vehicle_class_[i].resize(vehicles_per_class[i].size());
2831 std::copy(vehicles_per_class[i].begin(), vehicles_per_class[i].end(),
2832 vehicles_per_vehicle_class_[i].begin());
2838 const std::set<VehicleClassEntry>& vehicle_classes =
2839 sorted_vehicle_classes_per_type_[type];
2840 if (vehicle_classes.empty()) {
2843 const int vehicle_class = (vehicle_classes.begin())->vehicle_class;
2844 DCHECK(!vehicles_per_vehicle_class_[vehicle_class].empty());
2845 return vehicles_per_vehicle_class_[vehicle_class][0];
2850 std::vector<int>& vehicles = vehicles_per_vehicle_class_[vehicle_class];
2851 if (vehicles.empty()) {
2854 std::set<VehicleClassEntry>& vehicle_classes =
2855 sorted_vehicle_classes_per_type_[
Type(vehicle)];
2856 const auto& insertion =
2857 vehicle_classes.insert({vehicle_class, fixed_cost});
2858 DCHECK(insertion.second);
2860 vehicles.push_back(vehicle);
2869 int type, std::function<
bool(
int)> vehicle_is_compatible);
2872 using VehicleClassEntry =
2876 std::vector<std::set<VehicleClassEntry> > sorted_vehicle_classes_per_type_;
2877 std::vector<std::vector<int> > vehicles_per_vehicle_class_;
2900 std::unique_ptr<IntVarFilteredHeuristic> heuristic);
2904 Decision*
Next(Solver* solver)
override;
2913 const std::unique_ptr<IntVarFilteredHeuristic> heuristic_;
2933 virtual std::string
DebugString()
const {
return "IntVarFilteredHeuristic"; }
2951 if (!is_in_delta_[
index]) {
2952 delta_->FastAdd(vars_[
index])->SetValue(
value);
2953 delta_indices_.push_back(
index);
2954 is_in_delta_[
index] =
true;
2970 int Size()
const {
return vars_.size(); }
2981 bool FilterAccept();
2984 const std::vector<IntVar*> vars_;
2985 Assignment*
const delta_;
2986 std::vector<int> delta_indices_;
2987 std::vector<bool> is_in_delta_;
2988 Assignment*
const empty_;
2991 int64 number_of_decisions_;
2992 int64 number_of_rejects_;
3003 const std::function<
int64(
int64)>& next_accessor);
3022 bool InitializeSolution()
override;
3025 std::vector<int64> start_chain_ends_;
3026 std::vector<int64> end_chain_starts_;
3034 std::function<
int64(
int64)> penalty_evaluator,
3057 std::vector<std::vector<StartEndValue> >
3064 template <
class Queue>
3066 std::vector<std::vector<StartEndValue> >* start_end_distances_per_node,
3067 Queue* priority_queue);
3081 std::vector<ValuedPosition>* valued_positions);
3088 int64 insert_before,
3126 std::function<
int64(
int64)> penalty_evaluator,
3132 return "GlobalCheapestInsertionFilteredHeuristic";
3138 typedef absl::flat_hash_set<PairEntry*> PairEntries;
3139 typedef absl::flat_hash_set<NodeEntry*> NodeEntries;
3148 void InsertNodesByRequirementTopologicalOrder();
3165 void InsertNodesOnRoutes(
const std::vector<int>& nodes,
3166 const absl::flat_hash_set<int>& vehicles);
3173 void SequentialInsertNodes(
const std::vector<int>& nodes);
3178 void DetectUsedVehicles(std::vector<bool>* is_vehicle_used,
3179 std::vector<int>* unused_vehicles,
3180 absl::flat_hash_set<int>* used_vehicles);
3185 void InsertFarthestNodesAsSeeds();
3195 template <
class Queue>
3197 std::vector<std::vector<StartEndValue>>* start_end_distances_per_node,
3198 Queue* priority_queue, std::vector<bool>* is_vehicle_used);
3203 void InitializePairPositions(
3205 std::vector<PairEntries>* pickup_to_entries,
3206 std::vector<PairEntries>* delivery_to_entries);
3212 void InitializeInsertionEntriesPerformingPair(
3215 std::vector<PairEntries>* pickup_to_entries,
3216 std::vector<PairEntries>* delivery_to_entries);
3219 void UpdatePairPositions(
int vehicle,
int64 insert_after,
3221 std::vector<PairEntries>* pickup_to_entries,
3222 std::vector<PairEntries>* delivery_to_entries) {
3223 UpdatePickupPositions(vehicle, insert_after, priority_queue,
3224 pickup_to_entries, delivery_to_entries);
3225 UpdateDeliveryPositions(vehicle, insert_after, priority_queue,
3226 pickup_to_entries, delivery_to_entries);
3230 void UpdatePickupPositions(
int vehicle,
int64 pickup_insert_after,
3232 std::vector<PairEntries>* pickup_to_entries,
3233 std::vector<PairEntries>* delivery_to_entries);
3236 void UpdateDeliveryPositions(
3237 int vehicle,
int64 delivery_insert_after,
3239 std::vector<PairEntries>* pickup_to_entries,
3240 std::vector<PairEntries>* delivery_to_entries);
3243 void DeletePairEntry(PairEntry* entry,
3245 std::vector<PairEntries>* pickup_to_entries,
3246 std::vector<PairEntries>* delivery_to_entries);
3249 void InitializePositions(
const std::vector<int>& nodes,
3251 std::vector<NodeEntries>* position_to_node_entries,
3252 const absl::flat_hash_set<int>& vehicles);
3258 void InitializeInsertionEntriesPerformingNode(
3259 int64 node,
int64 penalty,
const absl::flat_hash_set<int>& vehicles,
3261 std::vector<NodeEntries>* position_to_node_entries);
3264 void UpdatePositions(
const std::vector<int>& nodes,
int vehicle,
3267 std::vector<NodeEntries>* node_entries);
3270 void DeleteNodeEntry(NodeEntry* entry,
3272 std::vector<NodeEntries>* node_entries);
3276 void ComputeNeighborhoods();
3282 void AddNeighborForCostClass(
int cost_class,
int64 node_index,
3283 int64 neighbor_index,
bool neighbor_is_pickup,
3284 bool neighbor_is_delivery);
3288 bool IsNeighborForCostClass(
int cost_class,
int64 node_index,
3289 int64 neighbor_index)
const;
3292 const std::vector<int64>& GetPickupNeighborsOfNodeForCostClass(
3293 int cost_class,
int64 node_index)
const {
3295 return pickup_nodes_;
3297 return node_index_to_pickup_neighbors_by_cost_class_[node_index][cost_class]
3298 ->PositionsSetAtLeastOnce();
3302 const std::vector<int64>& GetDeliveryNeighborsOfNodeForCostClass(
3303 int cost_class,
int64 node_index)
const {
3305 return delivery_nodes_;
3307 return node_index_to_delivery_neighbors_by_cost_class_
3308 [node_index][cost_class]
3309 ->PositionsSetAtLeastOnce();
3313 const std::vector<int64>& GetSingleNeighborsOfNodeForCostClass(
3314 int cost_class,
int64 node_index)
const {
3316 return single_nodes_;
3318 return node_index_to_single_neighbors_by_cost_class_[node_index][cost_class]
3319 ->PositionsSetAtLeastOnce();
3323 std::vector<const std::vector<int64>*> GetNeighborsOfNodeForCostClass(
3324 int cost_class,
int64 node_index)
const {
3325 return {&GetSingleNeighborsOfNodeForCostClass(cost_class, node_index),
3326 &GetPickupNeighborsOfNodeForCostClass(cost_class, node_index),
3327 &GetDeliveryNeighborsOfNodeForCostClass(cost_class, node_index)};
3330 void ResetVehicleIndices()
override {
3331 node_index_to_vehicle_.assign(node_index_to_vehicle_.size(), -1);
3334 void SetVehicleIndex(
int64 node,
int vehicle)
override {
3335 DCHECK_LT(node, node_index_to_vehicle_.size());
3336 node_index_to_vehicle_[node] = vehicle;
3341 bool CheckVehicleIndices()
const;
3343 GlobalCheapestInsertionParameters gci_params_;
3345 std::vector<int> node_index_to_vehicle_;
3348 std::vector<std::vector<std::unique_ptr<SparseBitset<int64> > > >
3349 node_index_to_single_neighbors_by_cost_class_;
3350 std::vector<std::vector<std::unique_ptr<SparseBitset<int64> > > >
3351 node_index_to_pickup_neighbors_by_cost_class_;
3352 std::vector<std::vector<std::unique_ptr<SparseBitset<int64> > > >
3353 node_index_to_delivery_neighbors_by_cost_class_;
3359 std::vector<int64> single_nodes_;
3360 std::vector<int64> pickup_nodes_;
3361 std::vector<int64> delivery_nodes_;
3379 return "LocalCheapestInsertionFilteredHeuristic";
3388 void ComputeEvaluatorSortedPositions(
int64 node,
3389 std::vector<int64>* sorted_positions);
3394 void ComputeEvaluatorSortedPositionsOnRouteAfter(
3396 std::vector<int64>* sorted_positions);
3398 std::vector<std::vector<StartEndValue>> start_end_distances_per_node_;
3411 class PartialRoutesAndLargeVehicleIndicesFirst {
3413 explicit PartialRoutesAndLargeVehicleIndicesFirst(
3415 : builder_(builder) {}
3416 bool operator()(
int vehicle1,
int vehicle2)
const;
3422 template <
typename Iterator>
3423 std::vector<int64> GetPossibleNextsFromIterator(
int64 node, Iterator start,
3424 Iterator end)
const {
3426 std::vector<int64> nexts;
3427 for (Iterator it = start; it != end; ++it) {
3430 nexts.push_back(
next);
3436 virtual void SortSuccessors(
int64 node, std::vector<int64>* successors) = 0;
3438 const std::vector<int64>& successors) = 0;
3452 return "EvaluatorCheapestAdditionFilteredHeuristic";
3457 void SortSuccessors(
int64 node, std::vector<int64>* successors)
override;
3459 const std::vector<int64>& successors)
override;
3475 return "ComparatorCheapestAdditionFilteredHeuristic";
3480 void SortSuccessors(
int64 node, std::vector<int64>* successors)
override;
3482 const std::vector<int64>& successors)
override;
3484 Solver::VariableValueComparator comparator_;
3522 template <
typename S>
3531 return saving.second / size_squared_;
3535 return (saving.second % size_squared_) /
Size();
3539 return (saving.second % size_squared_) %
Size();
3567 void AddSymmetricArcsToAdjacencyLists(
3568 std::vector<std::vector<int64> >* adjacency_lists);
3577 void ComputeSavings();
3579 Saving BuildSaving(
int64 saving,
int vehicle_type,
int before_node,
3580 int after_node)
const {
3581 return std::make_pair(saving, vehicle_type * size_squared_ +
3582 before_node *
Size() + after_node);
3588 int64 MaxNumNeighborsPerNode(
int num_vehicle_types)
const;
3591 const SavingsParameters savings_params_;
3592 int64 size_squared_;
3606 return "SequentialSavingsFilteredHeuristic";
3614 void BuildRoutesFromSavings()
override;
3615 double ExtraSavingsMemoryMultiplicativeFactor()
const override {
return 1.0; }
3627 return "ParallelSavingsFilteredHeuristic";
3641 void BuildRoutesFromSavings()
override;
3643 double ExtraSavingsMemoryMultiplicativeFactor()
const override {
return 2.0; }
3649 void MergeRoutes(
int first_vehicle,
int second_vehicle,
int64 before_node,
3653 std::vector<int64> first_node_on_route_;
3654 std::vector<int64> last_node_on_route_;
3658 std::vector<int> vehicle_of_first_or_last_node_;
3669 bool use_minimum_matching);
3673 return "ChristofidesFilteredHeuristic";
3677 const bool use_minimum_matching_;
3686 const RoutingSearchParameters& search_parameters,
3687 const Assignment* initial_solution,
3688 Assignment* solution);
3694 BasePathFilter(
const std::vector<IntVar*>& nexts,
int next_domain_size);
3696 bool Accept(
const Assignment*
delta,
const Assignment* deltadelta,
3697 int64 objective_min,
int64 objective_max)
override;
3721 enum Status { UNKNOWN, ENABLED, DISABLED };
3723 virtual bool DisableFiltering()
const {
return false; }
3724 virtual void OnBeforeSynchronizePaths() {}
3725 virtual void OnAfterSynchronizePaths() {}
3726 virtual void OnSynchronizePathFromStart(
int64 start) {}
3727 virtual void InitializeAcceptPath() {}
3728 virtual bool AcceptPath(
int64 path_start,
int64 chain_start,
3729 int64 chain_end) = 0;
3730 virtual bool FinalizeAcceptPath(
const Assignment*
delta,
int64 objective_min,
3731 int64 objective_max) {
3735 void ComputePathStarts(std::vector<int64>* path_starts,
3736 std::vector<int>* index_to_path);
3737 bool HavePathsChanged();
3738 void SynchronizeFullAssignment();
3739 void UpdateAllRanks();
3740 void UpdatePathRanksFromStart(
int start);
3742 std::vector<int64> node_path_starts_;
3743 std::vector<int64> starts_;
3744 std::vector<int> paths_;
3745 SparseBitset<int64> new_synchronized_unperformed_nodes_;
3746 std::vector<int64> new_nexts_;
3747 std::vector<int> delta_touched_;
3748 SparseBitset<> touched_paths_;
3749 SparseBitset<> touched_path_nodes_;
3750 std::vector<int> ranks_;
3770 std::string
DebugString()
const override {
return "CPFeasibilityFilter"; }
3771 bool Accept(
const Assignment*
delta,
const Assignment* deltadelta,
3772 int64 objective_min,
int64 objective_max)
override;
3776 void AddDeltaToAssignment(
const Assignment*
delta, Assignment* assignment);
3778 static const int64 kUnassigned;
3780 Solver*
const solver_;
3781 Assignment*
const assignment_;
3782 Assignment*
const temp_assignment_;
3783 DecisionBuilder*
const restore_;
3788 const RoutingModel& routing_model);
3790 const RoutingModel& routing_model);
3792 const RoutingModel& routing_model);
3794 const RoutingModel& routing_model);
3796 const std::vector<RoutingDimension*>& dimensions,
3797 const RoutingSearchParameters&
parameters,
bool filter_objective_cost,
3798 std::vector<LocalSearchFilter*>* filters);
3800 const RoutingDimension& dimension,
3802 bool propagate_own_objective_value,
bool filter_objective_cost,
3803 bool can_use_lp =
true);
3805 const RoutingDimension& dimension);
3807 GlobalDimensionCumulOptimizer* optimizer,
bool filter_objective_cost);
3810 const std::vector<RoutingModel::PickupAndDeliveryPolicy>& vehicle_policies);
3812 const RoutingModel& routing_model);
3814 const RoutingModel& routing_model,
const RoutingDimension& dimension);
3816 const RoutingModel* routing_model);
3820 #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.
std::unique_ptr< VehicleTypeCurator > vehicle_type_curator_
RoutingIndexPair IndexPair
virtual bool InitializeSolution()
Virtual method to initialize the solution.
TypeIncompatibilityChecker(const RoutingModel &model, bool check_hard_incompatibilities)
std::string DebugString() const override
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.
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
void AddNodePrecedence(int64 first_node, int64 second_node, int64 offset)
int64 GetCumulVarSoftLowerBound(int64 index) const
Returns the soft lower bound of a cumul variable for a given variable index.
CostClassIndex GetCostClassIndexOfVehicle(int64 vehicle) const
Get the cost class index of the given vehicle.
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...
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 ...
int Type(int vehicle) const
std::vector< int64 > pre_travels
@ PICKUP_AND_DELIVERY_NO_ORDER
Any precedence is accepted.
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
const std::vector< int64 > & GetTouchedPathStarts() const
bool operator<(const StartEndValue &other) const
Assignment * RestoreAssignment(const Assignment &solution)
Restores an assignment as a solution in the routing model and returns the new solution.
std::vector< int64 > start_max
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.
const TransitCallback1 & UnaryTransitCallbackOrNull(int callback_index) const
bool HasPickupToDeliveryLimits() const
Solver * solver() const
Returns the underlying constraint solver.
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; ...
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)
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 ...
int64 CapSub(int64 x, int64 y)
static const char kLightElement[]
Constraint types.
RoutingModel * model() const
Returns the model on which the dimension was created.
static std::unique_ptr< LocalSearchOperator > MakeGreedyDescentLSOperator(std::vector< IntVar * > variables)
Perhaps move it to constraint_solver.h.
std::string DebugString() const override
bool HasTypeRegulations() const
Returns true iff the model has any incompatibilities or requirements set on node types.
const ReverseArcListGraph< int, int > & GetPathPrecedenceGraph() const
Accessors.
RangeMinMaxIndexFunction * transit_plus_identity
f(x)
std::pair< int64, int64 > ValuedPosition
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)
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
std::function< int64(int64)> RoutingTransitCallback1
BasePathFilter(const std::vector< IntVar * > &nexts, int next_domain_size)
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...
ComparatorCheapestAdditionFilteredHeuristic(RoutingModel *model, Solver::VariableValueComparator comparator, LocalSearchFilterManager *filter_manager)
Takes ownership of evaluator.
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...
std::string DebugString() const override
int GetStartChainEnd(int vehicle) const
Returns the end of the start chain of vehicle,.
std::vector< int > type_index_of_vehicle
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.
void AddToAssignment(IntVar *const var)
Adds an extra variable to the vehicle routing assignment.
int64 End(int vehicle) const
Returns the variable index of the ending node of a vehicle route.
void InitialPropagate() override
~CheapestInsertionFilteredHeuristic() override
virtual ~IntVarFilteredHeuristic()
int GetCompatibleVehicleOfType(int type, std::function< bool(int)> vehicle_is_compatible)
VehicleClassIndex GetVehicleClassIndexOfVehicle(int64 vehicle) const
const std::vector< int > & GetSingleNodesOfType(int type) const
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...
void FillPathEvaluation(const std::vector< int64 > &path, const RoutingModel::TransitCallback2 &evaluator, std::vector< int64 > *values)
int64 number_of_decisions() const
Returns statistics from its underlying heuristic.
bool CostsAreHomogeneousAcrossVehicles() const
Whether costs are homogeneous across all vehicles.
~GlobalCheapestInsertionFilteredHeuristic() override
virtual bool StopSearch()
Returns true if the search must be stopped.
const std::vector< IntVar * > & fixed_transits() const
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.
const std::vector< std::pair< int, int > > & GetDeliveryIndexPairs(int64 node_index) const
Same as above for deliveries.
RoutingTransitCallback1 TransitCallback1
Filter-based heuristic dedicated to routing.
const std::vector< std::unique_ptr< GlobalDimensionCumulOptimizer > > & GetGlobalDimensionCumulOptimizers() const
Returns [global|local]_dimension_optimizers_, which are empty if the model has not been closed.
gtl::ITIVector< DimensionIndex, int64 > dimension_capacities
IntVarLocalSearchFilter * MakeTypeRegulationsFilter(const RoutingModel &routing_model)
std::function< int64(int64)> penalty_evaluator_
RoutingDisjunctionIndex DisjunctionIndex
virtual void BuildRoutesFromSavings()=0
const Assignment * SolveWithParameters(const RoutingSearchParameters &search_parameters, std::vector< const Assignment * > *solutions=nullptr)
Solves the current routing model with the given parameters.
CheapestInsertionFilteredHeuristic(RoutingModel *model, std::function< int64(int64, int64, int64)> evaluator, std::function< int64(int64)> penalty_evaluator, LocalSearchFilterManager *filter_manager)
Takes ownership of evaluator.
~TypeIncompatibilityChecker() override
int64 GetDisjunctionPenalty(DisjunctionIndex index) const
Returns the penalty of the node disjunction of index 'index'.
bool IsVarSynced(int index) const
RoutingDimension * GetMutableDimension(const std::string &dimension_name) const
Returns a dimension from its name.
IntVar * SlackVar(int64 index) const
The following constraint ensures that incompatibilities and requirements between types are respected.
static const int64 kUnassigned
void SetSpanCostCoefficientForAllVehicles(int64 coefficient)
RoutingCostClassIndex CostClassIndex
RangeIntToIntFunction * transit
std::vector< int64 > max_travels
std::string DebugString() const override
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.
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...
Manager for any NodeIndex <-> variable index conversion.
const std::vector< std::pair< DisjunctionIndex, DisjunctionIndex > > & GetPickupAndDeliveryDisjunctions() const
std::string DebugString() const override
What follows is relevant for models with time/state dependent transits.
bool IsEnd(int64 index) const
Returns true if 'index' represents the last node of a route.
int GetNumberOfVisitTypes() const
VisitTypePolicy GetVisitTypePolicy(int64 index) const
TypeRequirementChecker(const RoutingModel &model)
const RoutingDimension & GetDimensionOrDie(const std::string &dimension_name) const
Returns a dimension from its name. Dies if the dimension does not exist.
int64 GetSpanCostCoefficientForVehicle(int vehicle) const
void SetQuadraticCostSoftSpanUpperBoundForVehicle(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 * (...
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.
uint64 unvisitable_nodes_fprint
Fingerprint of unvisitable non-start/end nodes.
@ 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...
bool HasTemporalTypeRequirements() const
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
double farthest_seeds_ratio
The ratio of routes on which to insert farthest nodes as seeds before starting the cheapest insertion...
const RoutingModel::TransitCallback1 & GetUnaryTransitEvaluator(int vehicle) const
Returns the unary callback evaluating the transit value between two node indices for a given vehicle.
const std::vector< IntervalVar * > & GetBreakIntervalsOfVehicle(int vehicle) const
Returns the break intervals set by SetBreakIntervalsOfVehicle().
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
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
A structure meant to store soft bounds and associated violation constants.
LocalDimensionCumulOptimizer * GetMutableLocalCumulMPOptimizer(const RoutingDimension &dimension) const
int GetCostClassesCount() const
Returns the number of different cost classes in the model.
std::vector< std::string > GetAllDimensionNames() const
Outputs the names of all dimensions added to the routing engine.
RoutingVehicleClassIndex VehicleClassIndex
@ TYPE_ADDED_TO_VEHICLE
When visited, the number of types 'T' on the vehicle increases by one.
~RoutingFilteredHeuristic() override
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 StopSearch() override
Returns true if the search must be stopped.
BoundCost bound_cost(int element) const
Filter-base decision builder which builds a solution by inserting nodes at their cheapest position.
std::string DebugString() const override
bool add_reverse_arcs
If add_reverse_arcs is true, the neighborhood relationships are considered symmetrically.
void AddTemporalTypeIncompatibility(int type1, int type2)
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.
int64 GetDisjunctionMaxCardinality(DisjunctionIndex index) const
Returns the maximum number of possible active nodes of the node disjunction of index 'index'.
const std::vector< absl::flat_hash_set< int > > & GetRequiredTypeAlternativesWhenAddingType(int type) const
Returns the set of requirement alternatives when adding the given type.
const Assignment * SolveFromAssignmentWithParameters(const Assignment *assignment, const RoutingSearchParameters &search_parameters, std::vector< const Assignment * > *solutions=nullptr)
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.
std::pair< int64, int64 > Saving
IntVarLocalSearchFilter * MakeMaxActiveVehiclesFilter(const RoutingModel &routing_model)
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_,...
bool HasDimension(const std::string &dimension_name) const
Returns true if a dimension exists for a given dimension name.
Constraint * MakePathSpansAndTotalSlacks(const RoutingDimension *dimension, std::vector< IntVar * > spans, std::vector< IntVar * > total_slacks)
For every vehicle of the routing model:
GlobalDimensionCumulOptimizer * GetMutableGlobalCumulOptimizer(const RoutingDimension &dimension) const
Returns the global/local dimension cumul optimizer for a given dimension, or nullptr if there is none...
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'.
SimpleBoundCosts::BoundCost GetQuadraticCostSoftSpanUpperBoundForVehicle(int vehicle) const
bool HasCumulVarSoftLowerBound(int64 index) const
Returns true if a soft lower bound has been set for a given variable index.
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).
SimpleBoundCosts(int num_bounds, BoundCost default_bound_cost)
std::unique_ptr< SavingsContainer< Saving > > savings_container_
int64 GetLocalOptimizerOffsetForVehicle(int vehicle) const
int RegisterUnaryTransitCallback(TransitCallback1 callback)
Registers 'callback' and returns its index.
int GetMaximumNumberOfActiveVehicles() const
Returns the maximum number of active vehicles.
std::string DebugString() const override
double neighbors_ratio
If neighbors_ratio < 1 then for each node only this ratio of its neighbors leading to the smallest ar...
std::vector< const SortedDisjointIntervalList * > forbidden_intervals
CostClass(int evaluator_index)
const absl::flat_hash_set< int > & GetTemporalTypeIncompatibilitiesOfType(int type) const
std::function< int64(int, int)> PickupToDeliveryLimitFunction
Limits, in terms of maximum difference between the cumul variables, between the pickup and delivery a...
std::vector< int64 > start_min
const std::string & name() const
Returns the name of the dimension.
void SetValue(int64 index, int64 value)
Modifies the current solution by setting the variable of index 'index' to value 'value'.
int64 GetCumulVarSoftUpperBound(int64 index) const
Returns the soft upper bound of a cumul variable for a given variable index.
int64 GetSavingValue(const Saving &saving) const
Returns the saving value from a saving.
~IntVarFilteredDecisionBuilder() override
int start_equivalence_class
Vehicle start and end equivalence classes.
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.
IntVarLocalSearchFilter * MakeCPFeasibilityFilter(const RoutingModel *routing_model)
int GetPath(int64 node) const
virtual void ResetVehicleIndices()
int vehicles() const
Returns the number of vehicle routes in the model.
IntVar * ActiveVar(int64 index) const
Returns the active variable of the node corresponding to index.
@ ROUTING_SUCCESS
Problem solved successfully after calling RoutingModel::Solve().
void FillTravelBoundsOfVehicle(int vehicle, const std::vector< int64 > &path, const RoutingDimension &dimension, TravelBounds *travel_bounds)
Filter manager: when a move is made, filters are executed to decide whether the solution is feasible ...
RoutingModel::VisitTypePolicy VisitTypePolicy
int64 GetGlobalOptimizerOffset() const
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...
SweepArranger * sweep_arranger() const
Returns the sweep arranger to be used by routing heuristics.
const absl::flat_hash_set< int > & GetHardTypeIncompatibilitiesOfType(int type) const
Returns visit types incompatible with a given type.
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
This class represents a sorted list of disjoint, closed intervals.
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 SetVisitType(int64 index, int type, VisitTypePolicy type_policy)
@ ROUTING_NOT_SOLVED
Problem not solved yet (before calling RoutingModel::Solve()).
std::vector< RoutingDimension * > GetDimensionsWithSoftOrSpanCosts() const
Returns dimensions with soft or vehicle span costs.
int64 Value(int64 index) const
Returns the value of the variable of index 'index' in the last committed solution.
virtual ~TypeRegulationsChecker()
IntVarLocalSearchFilter * MakeVehicleAmortizedCostFilter(const RoutingModel &routing_model)
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.
gtl::ITIVector< DimensionIndex, int64 > dimension_start_cumuls_min
Bounds of cumul variables at start and end vehicle nodes.
~BasePathFilter() override
~ChristofidesFilteredHeuristic() override
int num_type_added_to_vehicle
Number of TYPE_ADDED_TO_VEHICLE and TYPE_SIMULTANEOUSLY_ADDED_AND_REMOVED node type policies seen on ...
const Assignment *const PreAssignment() const
Returns an assignment used to fix some of the variables of the problem.
bool MirrorTasks(Tasks *tasks)
Transforms the problem with a time symmetry centered in 0.
Decision * Next(Solver *solver) override
void AddAtSolutionCallback(std::function< void()> callback)
Adds a callback called each time a solution is found during the search.
Status
Status of the search.
const RoutingModel::TransitCallback2 & transit_evaluator(int vehicle) const
Returns the callback evaluating the transit value between two node indices for a given vehicle.
Filtered-base decision builder based on the addition heuristic, extending a path from its start node ...
std::function< StateDependentTransit(int64, int64)> VariableIndexEvaluator2
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
const std::vector< std::pair< int64, int64 > > & GetBreakDistanceDurationOfVehicle(int vehicle) const
Returns the pairs (distance, duration) specified by break distance constraints.
const std::vector< std::unique_ptr< LocalDimensionCumulOptimizer > > & GetLocalDimensionCumulMPOptimizers() const
TypeRegulationsChecker(const RoutingModel &model)
void ReinjectVehicleOfClass(int vehicle, int vehicle_class, int64 fixed_cost)
int GetVehicleOfType(int type) const
std::function< int64(int64, int64, int64)> evaluator_
A structure to hold tasks described by their features.
int num_type_removed_from_vehicle
Number of ADDED_TYPE_REMOVED_FROM_VEHICLE (effectively removing a type from the route) and TYPE_SIMUL...
int RegisterStateDependentTransitCallback(VariableIndexEvaluator2 callback)
IntVarFilteredDecisionBuilder(std::unique_ptr< IntVarFilteredHeuristic > heuristic)
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)...
static const char kLightElement2[]
void SetMaximumNumberOfActiveVehicles(int max_active_vehicles)
Constrains the maximum number of active vehicles, aka the number of vehicles which do not have an emp...
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...
CostClassIndex cost_class_index
The cost class of the vehicle.
const Solver::IndexEvaluator2 & first_solution_evaluator() const
Gets/sets the evaluator used during the search.
IntVarLocalSearchFilter * MakeCumulBoundsPropagatorFilter(const RoutingDimension &dimension)
friend class RoutingModel
EvaluatorCheapestAdditionFilteredHeuristic(RoutingModel *model, std::function< int64(int64, int64)> evaluator, LocalSearchFilterManager *filter_manager)
Takes ownership of evaluator.
void InitialPropagate() override
friend class SavingsFilteredHeuristicTestPeer
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...
bool WriteAssignment(const std::string &file_name) const
Writes the current solution to a file containing an AssignmentProto.
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
virtual bool FinalizeCheck() const
void AppendDimensionCumulFilters(const std::vector< RoutingDimension * > &dimensions, const RoutingSearchParameters ¶meters, bool filter_objective_cost, std::vector< LocalSearchFilter * > *filters)
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...
std::vector< std::set< VehicleClassEntry > > sorted_vehicle_classes_per_type
const RoutingDimension * dimension
@ PICKUP_AND_DELIVERY_LIFO
Deliveries must be performed in reverse order of pickups.
Checker for type requirements.
bool use_neighbors_ratio_for_initialization
If true, only closest neighbors (see neighbors_ratio) are considered as insertion positions during in...
void OnSynchronize(const Assignment *delta) override
const TransitCallback2 & TransitCallback(int callback_index) const
std::vector< std::vector< int64 > > GetRoutesFromAssignment(const Assignment &assignment)
Converts the solution in the given assignment to routes for all vehicles.
int64 number_of_rejects() const
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...
int64 CapAdd(int64 x, int64 y)
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...
ChristofidesFilteredHeuristic(RoutingModel *model, LocalSearchFilterManager *filter_manager, bool use_minimum_matching)
int64 number_of_decisions() const
Returns statistics on search, number of decisions sent to filters, number of decisions rejected by fi...
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.
const Assignment * Solve(const Assignment *assignment=nullptr)
Solves the current routing model; closes the current model.
int64 GetVehicleTypeFromSaving(const Saving &saving) const
Returns the cost class from a saving.
void OnSynchronize(const Assignment *delta) override
const std::vector< int64 > & GetAmortizedQuadraticCostFactorOfVehicles() const
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,.
SweepArranger(const std::vector< std::pair< int64, int64 >> &points)
DecisionBuilder * MakeGuidedSlackFinalizer(const RoutingDimension *dimension, std::function< int64(int64)> initializer)
The next few members are in the public section only for testing purposes.
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
Filter-based decision builder which builds a solution by inserting nodes at their cheapest position o...
Assignment * MutablePreAssignment()
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.
std::vector< int64 > post_travels
BoundCost & bound_cost(int element)
gtl::ITIVector< DimensionIndex, int64 > dimension_end_cumuls_max
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).
std::vector< bool > is_preemptible
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.
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 * (...
int64 GetFixedCostOfVehicle(int vehicle) const
Returns the route fixed cost taken into account if the route of the vehicle is not empty,...
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.
Dimensions represent quantities accumulated at nodes along the routes.
static const DimensionIndex kNoDimension
Constant used to express the "no dimension" index, returned when a dimension name does not correspond...
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
int64 GetAfterNodeFromSaving(const Saving &saving) const
Returns the "after node" from a saving.
bool CheckLimit()
Returns true if the search limit has been crossed.
void SetFirstSolutionEvaluator(Solver::IndexEvaluator2 evaluator)
Takes ownership of evaluator.
~EvaluatorCheapestAdditionFilteredHeuristic() override
bool operator<(const VehicleClassEntry &other) const
std::vector< int64 > duration_min
const RoutingModel & model_
VehicleTypeCurator(const RoutingModel::VehicleTypeContainer &vehicle_type_container)
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.
int64 fixed_cost
Contrarily to CostClass, here we need strict equivalence.
IntVarLocalSearchFilter * MakeVehicleVarFilter(const RoutingModel &routing_model)
IntVar * VehicleVar(int64 index) const
Returns the vehicle variable of the node corresponding to index.
void SetSweepArranger(SweepArranger *sweep_arranger)
const std::vector< IntegerType > & PositionsSetAtLeastOnce() const
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...
IntVar * TransitVar(int64 index) const
void InitializeBreaks()
Sets up vehicle_break_intervals_, vehicle_break_distance_duration_, pre_travel_evaluators and post_tr...
std::vector< int64 > min_travels
This class acts like a CP propagator: it takes a set of tasks given by their start/duration/end featu...
const std::vector< RoutingDimension * > & GetDimensions() const
Returns all dimensions of the model.
void AppendTasksFromIntervals(const std::vector< IntervalVar * > &intervals, DisjunctivePropagator::Tasks *tasks)
void SetFixedCostOfVehicle(int64 cost, int vehicle)
Sets the fixed cost of one vehicle route.
SimpleBoundCosts(const SimpleBoundCosts &)=delete
std::function< std::vector< operations_research::IntVar * >(RoutingModel *)> GetTabuVarsCallback
Sets the callback returning the variable to use for the Tabu Search metaheuristic.
~ParallelSavingsFilteredHeuristic() override
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.
std::vector< int64 > duration_max
IntVarLocalSearchFilter * MakeGlobalLPCumulFilter(GlobalDimensionCumulOptimizer *optimizer, bool filter_objective_cost)
static const DisjunctionIndex kNoDisjunction
Constant used to express the "no disjunction" index, returned when a node does not appear in any disj...
std::function< int64(const Model &)> Value(IntegerVariable v)
IntVar * ActiveVehicleVar(int vehicle) const
Returns the active variable of the vehicle.
RoutingDimensionIndex DimensionIndex
bool AddConstantDimension(int64 value, int64 capacity, bool fix_start_cumul_to_zero, const std::string &name)
std::vector< int64 > end_max
Filter-based decision builder which builds a solution by using Clarke & Wright's Savings heuristic.
const std::vector< IntVar * > & transits() const
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.
int Type(int vehicle) const
void SetPickupAndDeliveryPolicyOfAllVehicles(PickupAndDeliveryPolicy policy)
Sets the Pickup and delivery policy of all vehicles.
int64 GetSpanUpperBoundForVehicle(int vehicle) const
std::pair< std::vector< int64 >, std::vector< int64 > > RoutingIndexPair
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
RoutingFilteredHeuristic(RoutingModel *model, LocalSearchFilterManager *filter_manager)
double arc_coefficient
arc_coefficient is a strictly positive parameter indicating the coefficient of the arc being consider...
PickupAndDeliveryPolicy
Types of precedence policy applied to pickup and delivery pairs.
bool ChainSpanMin(Tasks *tasks)
Propagates a lower bound of the chain span, end[num_chain_tasks] - start[0], to span_min.
Generic path-based filter class.
static bool LessThan(const VehicleClass &a, const VehicleClass &b)
Comparator for STL containers and algorithms.
~TypeRequirementChecker() override
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
void ResetSolution()
Resets the data members for a new solution.
IntVar * ApplyLocks(const std::vector< int64 > &locks)
Applies a lock chain to the next search.
std::vector< RoutingIndexPair > RoutingIndexPairs
absl::Duration RemainingTime() const
Returns the time left in the search limit.
IntVar * Var(int64 index) const
Returns the variable of index 'index'.
int64 transit_evaluator_class
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.
void SetArcCostEvaluatorOfVehicle(int evaluator_index, int vehicle)
Sets the cost function for a given vehicle route.
void SetFixedCostOfAllVehicles(int64 cost)
Sets the fixed cost of all vehicle routes.
const std::vector< int64 > & GetAmortizedLinearCostFactorOfVehicles() const
virtual void SetVehicleIndex(int64 node, int vehicle)
int nodes() const
Sizes and indices Returns the number of nodes in the model.
SUBTLE: The vehicle's fixed cost is skipped on purpose here, because we can afford to do so:
IntVarLocalSearchFilter * MakePathCumulFilter(const RoutingDimension &dimension, const RoutingSearchParameters ¶meters, bool propagate_own_objective_value, bool filter_objective_cost, bool can_use_lp=true)
~CheapestAdditionFilteredHeuristic() override
Assignment * CompactAndCheckAssignment(const Assignment &assignment) const
Same as CompactAssignment() but also checks the validity of the final compact solution; if it is not ...
bool HasCumulVarSoftUpperBound(int64 index) const
Returns true if a soft upper bound has been set for a given variable index.
void AppendTasksFromPath(const std::vector< int64 > &path, const TravelBounds &travel_bounds, const RoutingDimension &dimension, DisjunctivePropagator::Tasks *tasks)
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
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.
IntVarLocalSearchFilter * MakeVehicleBreaksFilter(const RoutingModel &routing_model, const RoutingDimension &dimension)
bool CheckVehicle(int vehicle, const std::function< int64(int64)> &next_accessor)
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
bool Propagate(Tasks *tasks)
Computes new bounds for all tasks, returns false if infeasible.
PickupAndDeliveryPolicy GetPickupAndDeliveryPolicyOfVehicle(int vehicle) const
const RoutingDimension * base_dimension() const
Returns the parent in the dependency tree if any or nullptr otherwise.
bool AreVehicleTransitsPositive(int vehicle) const
Returns true iff the transit evaluator of 'vehicle' is positive for all arcs.
RoutingModel * model() const
int Size() const
Returns the number of variables the decision builder is trying to instantiate.
LocalDimensionCumulOptimizer * GetMutableLocalCumulOptimizer(const RoutingDimension &dimension) const
const std::vector< IntVar * > & cumuls() const
Like CumulVar(), TransitVar(), SlackVar() but return the whole variable vectors instead (indexed by i...
@ TYPE_ON_VEHICLE_UP_TO_VISIT
With the following policy, the visit enforces that type 'T' is considered on the route from its start...
@ ROUTING_FAIL
No solution found to the problem after calling RoutingModel::Solve().
void CloseModel()
Closes the current routing model; after this method is called, no modification to the model can be do...
Struct used to sort and store vehicles by their type.
std::vector< std::pair< int64, int64 > > distance_duration
Local Search Filters are used for fast neighbor pruning.
int RegisterPositiveTransitCallback(TransitCallback2 callback)
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
int64 GetPickupToDeliveryLimitForPair(int pair_index, int pickup, int delivery) const
const IndexPairs & GetPickupAndDeliveryPairs() const
Returns pickup and delivery pairs currently in the model.
static const char kRemoveValues[]
double neighbors_ratio
If neighbors_ratio < 1 then for each node only this ratio of its neighbors leading to the smallest ar...
int64 GetNumberOfDecisionsInFirstSolution(const RoutingSearchParameters &search_parameters) const
Returns statistics on first solution search, number of decisions sent to filters, number of decisions...
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)
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...
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,...
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.
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
~SequentialSavingsFilteredHeuristic() override
IntVarLocalSearchFilter * MakePickupDeliveryFilter(const RoutingModel &routing_model, const RoutingModel::IndexPairs &pairs, const std::vector< RoutingModel::PickupAndDeliveryPolicy > &vehicle_policies)
const std::vector< int64 > & vehicle_span_cost_coefficients() const
int evaluator_index
Index of the arc cost evaluator, registered in the RoutingModel class.
const Assignment * BuildSolutionFromRoutes(const std::function< int64(int64)> &next_accessor)
Builds a solution starting from the routes formed by the next accessor.
GlobalCheapestInsertionFilteredHeuristic(RoutingModel *model, std::function< int64(int64, int64, int64)> evaluator, std::function< int64(int64)> penalty_evaluator, LocalSearchFilterManager *filter_manager, GlobalCheapestInsertionParameters parameters)
Takes ownership of evaluators.
static const int64 kNoPenalty
Constant used to express a hard constraint instead of a soft penalty.
@ ROUTING_FAIL_TIMEOUT
Time limit reached before finding a solution with RoutingModel::Solve().
const std::vector< std::unique_ptr< LocalDimensionCumulOptimizer > > & GetLocalDimensionCumulOptimizers() const
Christofides addition heuristic.
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
std::string DebugString() const override
RoutingIndexPairs IndexPairs
const VehicleTypeContainer & GetVehicleTypeContainer() const
const std::vector< IntVar * > & slacks() const
void SetPrimaryConstrainedDimension(const std::string &dimension_name)
Set the given dimension as "primary constrained".
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)
SequentialSavingsFilteredHeuristic(RoutingModel *model, const RoutingIndexManager *manager, SavingsParameters parameters, LocalSearchFilterManager *filter_manager)
int GetVehicleClassesCount() const
Returns the number of different vehicle classes in the model.
void SetPickupToDeliveryLimitFunctionForPair(PickupToDeliveryLimitFunction limit_function, int pair_index)
int64 Next(const Assignment &assignment, int64 index) const
Assignment inspection Returns the variable index of the node directly after the node corresponding to...
bool ChainSpanMinDynamic(Tasks *tasks)
Computes a lower bound of the span of the chain, taking into account only the first nonchain task.
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...
Checker for type incompatibilities.
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)
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
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...
IntVar * CostVar() const
Returns the global cost variable which is being minimized.
bool Contains(int64 index) const
Returns true if the variable of index 'index' is in the current solution.
virtual bool CheckTypeRegulations(int type, VisitTypePolicy policy, int pos)=0
bool is_sequential
Whether the routes are constructed sequentially or in parallel.
const std::vector< DisjunctionIndex > & GetDisjunctionIndices(int64 index) const
Returns the indices of the disjunctions to which an index belongs.
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
const std::vector< IntVar * > & VehicleVars() const
Returns all vehicle variables of the model, such that VehicleVars(i) is the vehicle variable of the n...
void ArrangeIndices(std::vector< int64 > *indices)
@ PICKUP_AND_DELIVERY_FIFO
Deliveries must be performed in the same order as pickups.
Assignment * CompactAssignment(const Assignment &assignment) const
Returns a compacted version of the given assignment, in which all vehicles with id lower or equal to ...
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.
ParallelSavingsFilteredHeuristic(RoutingModel *model, const RoutingIndexManager *manager, SavingsParameters parameters, LocalSearchFilterManager *filter_manager)
const std::vector< int64 > & GetNewSynchronizedUnperformedNodes() const
Assignment * ReadAssignmentFromRoutes(const std::vector< std::vector< int64 >> &routes, bool ignore_inactive_indices)
Restores the routes as the current solution.
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_
IntVarFilteredHeuristic(Solver *solver, const std::vector< IntVar * > &vars, LocalSearchFilterManager *filter_manager)
A CheapestAdditionFilteredHeuristic where the notion of 'cheapest arc' comes from an arc comparator.
bool HasVehicleWithCostClassIndex(CostClassIndex cost_class_index) const
Returns true iff the model contains a vehicle with the given cost_class_index.
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...
bool HasHardTypeIncompatibilities() const
Returns true iff any hard (resp.
int64 number_of_rejects() const
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...
const std::vector< absl::flat_hash_set< int > > & GetRequiredTypeAlternativesWhenRemovingType(int type) const
Returns the set of requirement alternatives when removing the given type.
const std::vector< int > & GetPairIndicesOfType(int type) const
~CPFeasibilityFilter() override
virtual std::string DebugString() const
A CheapestAdditionFilteredHeuristic where the notion of 'cheapest arc' comes from an arc evaluator.
gtl::ITIVector< DimensionIndex, int64 > dimension_start_cumuls_max
bool HasSameVehicleTypeRequirements() const
Returns true iff any same-route (resp.
const std::vector< int > & GetSameVehicleIndicesOfIndex(int node) const
Returns variable indices of nodes constrained to be on the same route.
int GetNonZeroCostClassesCount() const
Ditto, minus the 'always zero', built-in cost class.
int end_equivalence_class
bool operator<(const DimensionCost &cost) const
bool DistanceDuration(Tasks *tasks)
Propagates distance_duration constraints, if any.
SavingsFilteredHeuristic(RoutingModel *model, const RoutingIndexManager *manager, SavingsParameters parameters, LocalSearchFilterManager *filter_manager)
bool IsVehicleAllowedForIndex(int vehicle, int64 index)
Returns true if a vehicle is allowed to visit a given node.
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
~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,...
std::vector< std::vector< std::pair< int64, int64 > > > GetCumulBounds(const Assignment &solution_assignment, const RoutingDimension &dimension)
Returns a vector cumul_bounds, for which cumul_bounds[i][j] is a pair containing the minimum and maxi...
int64 Start(int vehicle) const
Model inspection.
const std::vector< SortedDisjointIntervalList > & forbidden_intervals() const
Returns forbidden intervals for each node.
int vehicle_to_class(int vehicle) const
std::pair< StartEndValue, int > Seed
Decision builder building a solution using heuristics with local search filters to evaluate its feasi...
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
const PiecewiseLinearFunction * GetCumulVarPiecewiseLinearCost(int64 index) const
Returns the piecewise linear cost of a cumul variable for a given variable index.
bool HasQuadraticCostSoftSpanUpperBounds() const
const std::vector< int > & GetTopologicallySortedVisitTypes() const
std::vector< int64 > end_min
Assignment *const BuildSolution()
Builds a solution.
std::function< int64(int64, int64)> RoutingTransitCallback2
IntVarLocalSearchFilter * MakeNodeDisjunctionFilter(const RoutingModel &routing_model)
static RoutingModel::StateDependentTransit MakeStateDependentTransit(const std::function< int64(int64)> &f, int64 domain_start, int64 domain_end)
Creates a cached StateDependentTransit from an std::function.
void SetSectors(int sectors)
int RegisterTransitCallback(TransitCallback2 callback)
CheapestAdditionFilteredHeuristic(RoutingModel *model, LocalSearchFilterManager *filter_manager)
IntVar * VehicleCostsConsideredVar(int vehicle) const
Returns the variable specifying whether or not costs are considered for vehicle.
bool HasTemporalTypeIncompatibilities() const
virtual void OnInitializeCheck()
std::vector< DimensionCost > dimension_transit_evaluator_class_and_cost_coefficient
Status status() const
Returns the current status of the routing model.
@ ADDED_TYPE_REMOVED_FROM_VEHICLE
When visited, one instance of type 'T' previously added to the route (TYPE_ADDED_TO_VEHICLE),...
static const int64 kint64max
bool IsVehicleUsed(const Assignment &assignment, int vehicle) const
Returns true if the route of 'vehicle' is non empty in 'assignment'.
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...
std::vector< std::deque< int > > vehicles_per_vehicle_class
Assignment * ReadAssignment(const std::string &file_name)
Reads an assignment from a file and returns the current solution.
LocalCheapestInsertionFilteredHeuristic(RoutingModel *model, std::function< int64(int64, int64, int64)> evaluator, LocalSearchFilterManager *filter_manager)
Takes ownership of evaluator.
std::string DebugString() const override
void AddNodePrecedence(NodePrecedence precedence)
void SynchronizeFilters()
Synchronizes filters with an assignment (the current solution).