157 #ifndef OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_H_ 158 #define OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_H_ 162 #include <functional> 170 #include "absl/container/flat_hash_map.h" 171 #include "absl/container/flat_hash_set.h" 172 #include "absl/functional/bind_front.h" 173 #include "absl/memory/memory.h" 174 #include "absl/time/time.h" 197 class GlobalDimensionCumulOptimizer;
198 class LocalDimensionCumulOptimizer;
199 class LocalSearchPhaseParameters;
201 class IndexNeighborFinder;
202 class IntVarFilteredDecisionBuilder;
204 class RoutingDimension;
305 std::vector<DimensionCost>
313 if (
a.evaluator_index !=
b.evaluator_index) {
314 return a.evaluator_index <
b.evaluator_index;
316 return a.dimension_transit_evaluator_class_and_cost_coefficient <
317 b.dimension_transit_evaluator_class_and_cost_coefficient;
354 #endif // defined(SWIG) 429 absl::flat_hash_map<DimensionIndex, ResourceGroup::Attributes>
430 dimension_attributes_;
448 return vehicles_requiring_resource_;
452 return vehicle_requires_resource_[vehicle];
455 const std::vector<Resource>&
GetResources()
const {
return resources_; }
457 DCHECK_LT(resource_index, resources_.size());
458 return resources_[resource_index];
462 return affected_dimension_indices_;
464 int Size()
const {
return resources_.size(); }
468 std::vector<Resource> resources_;
469 std::vector<bool> vehicle_requires_resource_;
470 std::vector<int> vehicles_requiring_resource_;
472 absl::flat_hash_set<DimensionIndex> affected_dimension_indices_;
500 std::vector<std::vector<int64_t> > values);
506 CHECK_LT(callback_index, transit_evaluators_.size());
507 return transit_evaluators_[callback_index];
510 CHECK_LT(callback_index, unary_transit_evaluators_.size());
511 return unary_transit_evaluators_[callback_index];
514 int callback_index)
const {
515 CHECK_LT(callback_index, state_dependent_transit_evaluators_.size());
516 return state_dependent_transit_evaluators_[callback_index];
542 bool fix_start_cumul_to_zero,
const std::string&
name);
544 const std::vector<int>& evaluator_indices, int64_t slack_max,
545 int64_t
capacity,
bool fix_start_cumul_to_zero,
const std::string&
name);
547 std::vector<int64_t> vehicle_capacities,
548 bool fix_start_cumul_to_zero,
549 const std::string&
name);
551 const std::vector<int>& evaluator_indices, int64_t slack_max,
552 std::vector<int64_t> vehicle_capacities,
bool fix_start_cumul_to_zero,
553 const std::string&
name);
564 bool fix_start_cumul_to_zero,
const std::string&
name);
566 bool fix_start_cumul_to_zero,
567 const std::string&
name) {
569 fix_start_cumul_to_zero,
name);
582 bool fix_start_cumul_to_zero,
583 const std::string&
name);
594 std::vector<std::vector<int64_t> > values,
595 int64_t
capacity,
bool fix_start_cumul_to_zero,
const std::string&
name);
603 const std::vector<int>& pure_transits,
604 const std::vector<int>& dependent_transits,
606 std::vector<int64_t> vehicle_capacities,
bool fix_start_cumul_to_zero,
607 const std::string&
name) {
608 return AddDimensionDependentDimensionWithVehicleCapacityInternal(
609 pure_transits, dependent_transits, base_dimension, slack_max,
610 std::move(vehicle_capacities), fix_start_cumul_to_zero,
name);
616 int64_t slack_max, std::vector<int64_t> vehicle_capacities,
617 bool fix_start_cumul_to_zero,
const std::string&
name);
621 int64_t vehicle_capacity,
bool fix_start_cumul_to_zero,
622 const std::string&
name);
624 int pure_transit,
int dependent_transit,
626 int64_t vehicle_capacity,
bool fix_start_cumul_to_zero,
627 const std::string&
name);
631 const std::function<int64_t(int64_t)>& f, int64_t domain_start,
644 std::vector<IntVar*> spans,
645 std::vector<IntVar*> total_slacks);
652 return dimensions_.get();
659 const std::vector<std::unique_ptr<GlobalDimensionCumulOptimizer> >&
661 return global_dimension_optimizers_;
663 const std::vector<std::unique_ptr<GlobalDimensionCumulOptimizer> >&
665 return global_dimension_mp_optimizers_;
667 const std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >&
669 return local_dimension_optimizers_;
671 const std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >&
673 return local_dimension_mp_optimizers_;
689 bool HasDimension(
const std::string& dimension_name)
const;
692 const std::string& dimension_name)
const;
696 const std::string& dimension_name)
const;
703 primary_constrained_dimension_ = dimension_name;
707 return primary_constrained_dimension_;
716 return resource_groups_;
720 DCHECK_LT(rg_index, resource_groups_.size());
721 return resource_groups_[rg_index].get();
754 int64_t max_cardinality = 1);
757 int64_t
index)
const {
758 return index_to_disjunctions_[
index];
763 template <
typename F>
765 int64_t
index, int64_t max_cardinality, F f)
const {
767 if (disjunctions_[disjunction].
value.max_cardinality == max_cardinality) {
768 for (
const int64_t d_index : disjunctions_[disjunction].indices) {
774 #if !defined(SWIGPYTHON) 779 return disjunctions_[
index].indices;
781 #endif // !defined(SWIGPYTHON) 784 return disjunctions_[
index].value.penalty;
789 return disjunctions_[
index].value.max_cardinality;
826 return allowed_vehicles_[
index].empty() ||
827 allowed_vehicles_[
index].find(vehicle) !=
828 allowed_vehicles_[
index].end();
856 const std::vector<std::pair<int, int> >&
859 const std::vector<std::pair<int, int> >&
878 return pickup_delivery_pairs_;
880 const std::vector<std::pair<DisjunctionIndex, DisjunctionIndex>>&
882 return pickup_delivery_disjunctions_;
890 return implicit_pickup_delivery_pairs_without_alternatives_;
937 return topologically_sorted_visit_types_;
954 return has_hard_type_incompatibilities_;
957 return has_temporal_type_incompatibilities_;
970 int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
976 int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
983 int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
987 const std::vector<absl::flat_hash_set<int> >&
990 const std::vector<absl::flat_hash_set<int> >&
993 const std::vector<absl::flat_hash_set<int> >&
999 return has_same_vehicle_type_requirements_;
1002 return has_temporal_type_requirements_;
1022 int64_t var_index)
const;
1033 max_active_vehicles_ = max_active_vehicles;
1069 int64_t quadratic_cost_factor);
1072 int64_t quadratic_cost_factor,
1076 return linear_cost_factor_of_vehicle_;
1080 return quadratic_cost_factor_of_vehicle_;
1085 vehicle_used_when_empty_[vehicle] = is_used;
1090 return vehicle_used_when_empty_[vehicle];
1097 return first_solution_evaluator_;
1102 first_solution_evaluator_ = std::move(evaluator);
1137 const RoutingSearchParameters& search_parameters);
1144 const Assignment*
Solve(
const Assignment* assignment =
nullptr);
1153 const RoutingSearchParameters& search_parameters,
1154 std::vector<const Assignment*>* solutions =
nullptr);
1158 const Assignment* assignment,
1159 const RoutingSearchParameters& search_parameters,
1160 std::vector<const Assignment*>* solutions =
nullptr);
1164 const std::vector<const Assignment*>& assignments,
1165 const RoutingSearchParameters& search_parameters,
1166 std::vector<const Assignment*>* solutions =
nullptr);
1173 Assignment* target_assignment,
const RoutingModel* source_model,
1174 const Assignment* source_assignment);
1226 const std::vector<std::vector<int64_t>>& routes,
1227 bool ignore_inactive_indices);
1245 bool ignore_inactive_indices,
bool close_routes,
1252 std::vector<std::vector<int64_t>>*
const routes)
const;
1297 const Assignment* original_assignment, absl::Duration duration_limit);
1310 CHECK(filter !=
nullptr);
1312 LOG(
WARNING) <<
"Model is closed, filter addition will be ignored.";
1320 int64_t
Start(
int vehicle)
const {
return starts_[vehicle]; }
1322 int64_t
End(
int vehicle)
const {
return ends_[vehicle]; }
1337 #if !defined(SWIGPYTHON) 1338 const std::vector<IntVar*>&
Nexts()
const {
return nexts_; }
1343 const std::vector<IntVar*>&
VehicleVars()
const {
return vehicle_vars_; }
1348 return resource_vars_[resource_group];
1351 IntVar* NextVar(int64_t index) const { return nexts_[index]; } 1359 return vehicle_active_[vehicle];
1365 return vehicle_route_considered_[vehicle];
1374 DCHECK_LT(resource_group, resource_vars_.size());
1375 DCHECK_LT(vehicle, resource_vars_[resource_group].size());
1376 return resource_vars_[resource_group][vehicle];
1384 int64_t vehicle)
const;
1387 return costs_are_homogeneous_across_vehicles_;
1397 int64_t to_index)
const;
1405 int64_t cost_class_index)
const;
1410 DCHECK_LT(vehicle, cost_class_index_of_vehicle_.size());
1411 DCHECK_GE(cost_class_index_of_vehicle_[vehicle], 0);
1412 return cost_class_index_of_vehicle_[vehicle];
1418 if (cost_class_index == kCostClassIndexOfZeroCost) {
1419 return has_vehicle_with_zero_cost_class_;
1421 return cost_class_index < cost_classes_.size();
1431 return vehicle_class_index_of_vehicle_[vehicle];
1444 return vehicle_type_container
1453 return same_vehicle_groups_[same_vehicle_group_[node]];
1458 return vehicle_type_container_;
1486 const std::string& dimension_to_print)
const;
1493 std::vector<std::vector<std::pair<int64_t, int64_t>>>
GetCumulBounds(
1509 return limit_->AbsoluteSolverDeadline() - solver_->Now();
1518 int64_t
Size()
const {
return nodes_ + vehicles_ - start_end_count_; }
1529 return automatic_first_solution_strategy_;
1559 std::function<int64_t(int64_t)> initializer);
1567 std::vector<IntVar*> variables);
1573 DecisionBuilder* MakeSelfDependentDimensionFinalizer( 1591 enum RoutingLocalSearchOperator {
1594 LIGHT_RELOCATE_PAIR,
1602 GLOBAL_CHEAPEST_INSERTION_CLOSE_NODES_LNS,
1603 LOCAL_CHEAPEST_INSERTION_CLOSE_NODES_LNS,
1604 GLOBAL_CHEAPEST_INSERTION_PATH_LNS,
1605 LOCAL_CHEAPEST_INSERTION_PATH_LNS,
1606 RELOCATE_PATH_GLOBAL_CHEAPEST_INSERTION_INSERT_UNPERFORMED,
1607 GLOBAL_CHEAPEST_INSERTION_EXPENSIVE_CHAIN_LNS,
1608 LOCAL_CHEAPEST_INSERTION_EXPENSIVE_CHAIN_LNS,
1609 RELOCATE_EXPENSIVE_CHAIN,
1613 RELOCATE_AND_MAKE_ACTIVE,
1614 MAKE_ACTIVE_AND_RELOCATE,
1616 MAKE_CHAIN_INACTIVE,
1618 EXTENDED_SWAP_ACTIVE,
1624 EXCHANGE_RELOCATE_PAIR,
1627 LOCAL_SEARCH_OPERATOR_COUNTER
1633 template <
typename T>
1634 struct ValuedNodes {
1635 std::vector<int64_t> indices;
1638 struct DisjunctionValues {
1640 int64_t max_cardinality;
1642 typedef ValuedNodes<DisjunctionValues> Disjunction;
1646 struct CostCacheElement {
1659 void AddNoCycleConstraintInternal();
1660 bool AddDimensionWithCapacityInternal(
1661 const std::vector<int>& evaluator_indices, int64_t slack_max,
1662 std::vector<int64_t> vehicle_capacities,
bool fix_start_cumul_to_zero,
1663 const std::string&
name);
1664 bool AddDimensionDependentDimensionWithVehicleCapacityInternal(
1665 const std::vector<int>& pure_transits,
1666 const std::vector<int>& dependent_transits,
1668 std::vector<int64_t> vehicle_capacities,
bool fix_start_cumul_to_zero,
1669 const std::string&
name);
1670 bool InitializeDimensionInternal(
1671 const std::vector<int>& evaluator_indices,
1672 const std::vector<int>& state_dependent_evaluator_indices,
1673 int64_t slack_max,
bool fix_start_cumul_to_zero,
1675 DimensionIndex GetDimensionIndex(
const std::string& dimension_name)
const;
1704 void StoreDimensionCumulOptimizers(
const RoutingSearchParameters&
parameters);
1706 void ComputeCostClasses(
const RoutingSearchParameters&
parameters);
1707 void ComputeVehicleClasses();
1715 void ComputeVehicleTypes();
1725 void FinalizeVisitTypes();
1727 void TopologicallySortVisitTypes();
1728 int64_t GetArcCostForClassInternal(int64_t from_index, int64_t to_index,
1730 void AppendHomogeneousArcCosts(
const RoutingSearchParameters&
parameters,
1732 std::vector<IntVar*>* cost_elements);
1733 void AppendArcCosts(
const RoutingSearchParameters&
parameters,
int node_index,
1734 std::vector<IntVar*>* cost_elements);
1735 Assignment* DoRestoreAssignment();
1737 int64_t SafeGetCostClassInt64OfVehicle(int64_t vehicle)
const {
1740 : kCostClassIndexOfZeroCost)
1743 int64_t GetDimensionTransitCostSum(int64_t i, int64_t j,
1744 const CostClass& cost_class)
const;
1748 void AddPickupAndDeliverySetsInternal(
const std::vector<int64_t>& pickups,
1749 const std::vector<int64_t>& deliveries);
1752 IntVar* CreateSameVehicleCost(
int vehicle_index);
1755 int FindNextActive(
int index,
const std::vector<int64_t>& indices)
const;
1759 bool RouteCanBeUsedByVehicle(
const Assignment& assignment,
int start_index,
1768 bool ReplaceUnusedVehicle(
int unused_vehicle,
int active_vehicle,
1769 Assignment* compact_assignment)
const;
1771 void QuietCloseModel();
1772 void QuietCloseModelWithParameters(
1780 bool SolveMatchingModel(Assignment* assignment,
1783 bool AppendAssignmentIfFeasible(
1785 const Assignment& assignment,
1786 std::vector<std::unique_ptr<Assignment>>* assignments);
1788 void LogSolution(
const RoutingSearchParameters&
parameters,
1790 const std::string& description, int64_t solution_cost,
1791 int64_t start_time_ms);
1794 Assignment* CompactAssignmentInternal(
const Assignment& assignment,
1795 bool check_compact_assignment)
const;
1800 std::string FindErrorInSearchParametersForModel(
1801 const RoutingSearchParameters& search_parameters)
const;
1803 void SetupSearch(
const RoutingSearchParameters& search_parameters);
1806 Assignment* GetOrCreateAssignment();
1807 Assignment* GetOrCreateTmpAssignment();
1808 RegularLimit* GetOrCreateLimit();
1809 RegularLimit* GetOrCreateLocalSearchLimit();
1810 RegularLimit* GetOrCreateLargeNeighborhoodSearchLimit();
1811 RegularLimit* GetOrCreateFirstSolutionLargeNeighborhoodSearchLimit();
1812 LocalSearchOperator* CreateInsertionOperator();
1813 LocalSearchOperator* CreateMakeInactiveOperator();
1815 LocalSearchOperator* CreateCPOperator(
const T& operator_factory) {
1816 return operator_factory(solver_.get(), nexts_,
1818 ? std::vector<IntVar*>()
1820 vehicle_start_class_callback_);
1823 LocalSearchOperator* CreateCPOperator() {
1824 return CreateCPOperator(MakeLocalSearchOperator<T>);
1826 template <
class T,
class Arg>
1827 LocalSearchOperator* CreateOperator(
const Arg& arg) {
1828 return solver_->RevAlloc(
new T(nexts_,
1830 ? std::vector<IntVar*>()
1832 vehicle_start_class_callback_, arg));
1835 LocalSearchOperator* CreatePairOperator() {
1836 return CreateOperator<T>(pickup_delivery_pairs_);
1838 void CreateNeighborhoodOperators(
const RoutingSearchParameters&
parameters);
1839 LocalSearchOperator* ConcatenateOperators(
1840 const RoutingSearchParameters& search_parameters,
1841 const std::vector<LocalSearchOperator*>& operators)
const;
1842 LocalSearchOperator* GetNeighborhoodOperators(
1843 const RoutingSearchParameters& search_parameters)
const;
1844 std::vector<LocalSearchFilterManager::FilterEvent>
1845 GetOrCreateLocalSearchFilters(
const RoutingSearchParameters&
parameters,
1846 bool filter_cost =
true);
1847 LocalSearchFilterManager* GetOrCreateLocalSearchFilterManager(
1849 std::vector<LocalSearchFilterManager::FilterEvent>
1850 GetOrCreateFeasibilityFilters(
const RoutingSearchParameters&
parameters);
1851 LocalSearchFilterManager* GetOrCreateFeasibilityFilterManager(
1853 LocalSearchFilterManager* GetOrCreateStrongFeasibilityFilterManager(
1855 DecisionBuilder* CreateSolutionFinalizer(SearchLimit* lns_limit);
1856 DecisionBuilder* CreateFinalizerForMinimizedAndMaximizedVariables();
1857 void CreateFirstSolutionDecisionBuilders(
1858 const RoutingSearchParameters& search_parameters);
1859 DecisionBuilder* GetFirstSolutionDecisionBuilder(
1860 const RoutingSearchParameters& search_parameters)
const;
1861 IntVarFilteredDecisionBuilder* GetFilteredFirstSolutionDecisionBuilderOrNull(
1862 const RoutingSearchParameters&
parameters)
const;
1863 LocalSearchPhaseParameters* CreateLocalSearchParameters(
1864 const RoutingSearchParameters& search_parameters);
1865 DecisionBuilder* CreateLocalSearchDecisionBuilder(
1866 const RoutingSearchParameters& search_parameters);
1867 void SetupDecisionBuilders(
const RoutingSearchParameters& search_parameters);
1868 void SetupMetaheuristics(
const RoutingSearchParameters& search_parameters);
1869 void SetupAssignmentCollector(
1870 const RoutingSearchParameters& search_parameters);
1871 void SetupTrace(
const RoutingSearchParameters& search_parameters);
1872 void SetupImprovementLimit(
const RoutingSearchParameters& search_parameters);
1873 void SetupSearchMonitors(
const RoutingSearchParameters& search_parameters);
1874 bool UsesLightPropagation(
1875 const RoutingSearchParameters& search_parameters)
const;
1882 void DetectImplicitPickupAndDeliveries();
1884 int GetVehicleStartClass(int64_t start)
const;
1886 void InitSameVehicleGroups(
int number_of_groups) {
1887 same_vehicle_group_.assign(
Size(), 0);
1888 same_vehicle_groups_.assign(number_of_groups, {});
1890 void SetSameVehicleGroup(
int index,
int group) {
1891 same_vehicle_group_[
index] = group;
1892 same_vehicle_groups_[group].push_back(
index);
1896 std::unique_ptr<Solver> solver_;
1899 int max_active_vehicles_;
1900 Constraint* no_cycle_constraint_ =
nullptr;
1902 std::vector<IntVar*> nexts_;
1903 std::vector<IntVar*> vehicle_vars_;
1904 std::vector<IntVar*> active_;
1908 std::vector<std::vector<IntVar*> > resource_vars_;
1911 std::vector<IntVar*> vehicle_active_;
1912 std::vector<IntVar*> vehicle_route_considered_;
1917 std::vector<IntVar*> is_bound_to_end_;
1918 mutable RevSwitch is_bound_to_end_ct_added_;
1920 absl::flat_hash_map<std::string, DimensionIndex> dimension_name_to_index_;
1927 std::vector<std::unique_ptr<ResourceGroup> > resource_groups_;
1930 dimension_resource_group_indices_;
1935 std::vector<std::unique_ptr<GlobalDimensionCumulOptimizer> >
1936 global_dimension_optimizers_;
1937 std::vector<std::unique_ptr<GlobalDimensionCumulOptimizer> >
1938 global_dimension_mp_optimizers_;
1940 std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >
1941 local_dimension_optimizers_;
1942 std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >
1943 local_dimension_mp_optimizers_;
1946 std::string primary_constrained_dimension_;
1948 IntVar* cost_ =
nullptr;
1949 std::vector<int> vehicle_to_transit_cost_;
1950 std::vector<int64_t> fixed_cost_of_vehicle_;
1951 std::vector<CostClassIndex> cost_class_index_of_vehicle_;
1952 bool has_vehicle_with_zero_cost_class_;
1953 std::vector<int64_t> linear_cost_factor_of_vehicle_;
1954 std::vector<int64_t> quadratic_cost_factor_of_vehicle_;
1955 bool vehicle_amortized_cost_factors_set_;
1967 std::vector<bool> vehicle_used_when_empty_;
1971 bool costs_are_homogeneous_across_vehicles_;
1972 bool cache_callbacks_;
1973 mutable std::vector<CostCacheElement> cost_cache_;
1974 std::vector<VehicleClassIndex> vehicle_class_index_of_vehicle_;
1978 VehicleTypeContainer vehicle_type_container_;
1979 std::function<int(int64_t)> vehicle_start_class_callback_;
1982 std::vector<std::vector<DisjunctionIndex> > index_to_disjunctions_;
1984 std::vector<ValuedNodes<int64_t> > same_vehicle_costs_;
1987 std::vector<absl::flat_hash_set<int>> allowed_vehicles_;
1991 IndexPairs implicit_pickup_delivery_pairs_without_alternatives_;
1992 std::vector<std::pair<DisjunctionIndex, DisjunctionIndex> >
1993 pickup_delivery_disjunctions_;
1998 std::vector<std::vector<std::pair<int, int> > > index_to_pickup_index_pairs_;
2000 std::vector<std::vector<std::pair<int, int> > >
2001 index_to_delivery_index_pairs_;
2003 std::vector<PickupAndDeliveryPolicy> vehicle_pickup_delivery_policy_;
2005 std::vector<int> same_vehicle_group_;
2007 std::vector<std::vector<int>> same_vehicle_groups_;
2010 std::vector<int> index_to_visit_type_;
2012 std::vector<VisitTypePolicy> index_to_type_policy_;
2014 std::vector<std::vector<int> > single_nodes_of_type_;
2015 std::vector<std::vector<int> > pair_indices_of_type_;
2017 std::vector<absl::flat_hash_set<int> >
2018 hard_incompatible_types_per_type_index_;
2019 bool has_hard_type_incompatibilities_;
2020 std::vector<absl::flat_hash_set<int> >
2021 temporal_incompatible_types_per_type_index_;
2022 bool has_temporal_type_incompatibilities_;
2024 std::vector<std::vector<absl::flat_hash_set<int> > >
2025 same_vehicle_required_type_alternatives_per_type_index_;
2026 bool has_same_vehicle_type_requirements_;
2027 std::vector<std::vector<absl::flat_hash_set<int> > >
2028 required_type_alternatives_when_adding_type_index_;
2029 std::vector<std::vector<absl::flat_hash_set<int> > >
2030 required_type_alternatives_when_removing_type_index_;
2031 bool has_temporal_type_requirements_;
2032 absl::flat_hash_map<int, absl::flat_hash_set<VisitTypePolicy> >
2033 trivially_infeasible_visit_types_to_policies_;
2050 std::vector<std::vector<int> > topologically_sorted_visit_types_;
2052 int num_visit_types_;
2055 std::vector<int> index_to_equivalence_class_;
2056 std::vector<int> index_to_vehicle_;
2057 std::vector<int64_t> starts_;
2058 std::vector<int64_t> ends_;
2061 RoutingIndexManager manager_;
2062 int start_end_count_;
2064 bool closed_ =
false;
2066 bool enable_deep_serialization_ =
true;
2069 std::vector<DecisionBuilder*> first_solution_decision_builders_;
2070 std::vector<IntVarFilteredDecisionBuilder*>
2071 first_solution_filtered_decision_builders_;
2075 std::vector<LocalSearchOperator*> local_search_operators_;
2076 std::vector<SearchMonitor*> monitors_;
2077 SolutionCollector* collect_assignments_ =
nullptr;
2078 SolutionCollector* collect_one_assignment_ =
nullptr;
2079 SolutionCollector* packed_dimensions_assignment_collector_ =
nullptr;
2080 DecisionBuilder* solve_db_ =
nullptr;
2081 DecisionBuilder* improve_db_ =
nullptr;
2082 DecisionBuilder* restore_assignment_ =
nullptr;
2083 DecisionBuilder* restore_tmp_assignment_ =
nullptr;
2084 Assignment* assignment_ =
nullptr;
2085 Assignment* preassignment_ =
nullptr;
2086 Assignment* tmp_assignment_ =
nullptr;
2087 std::vector<IntVar*> extra_vars_;
2088 std::vector<IntervalVar*> extra_intervals_;
2089 std::vector<LocalSearchOperator*> extra_operators_;
2090 LocalSearchFilterManager* local_search_filter_manager_ =
nullptr;
2091 LocalSearchFilterManager* feasibility_filter_manager_ =
nullptr;
2092 LocalSearchFilterManager* strong_feasibility_filter_manager_ =
nullptr;
2093 std::vector<LocalSearchFilterManager::FilterEvent> extra_filters_;
2095 std::vector<std::pair<IntVar*, int64_t>> finalizer_variable_cost_pairs_;
2096 std::vector<std::pair<IntVar*, int64_t>> finalizer_variable_target_pairs_;
2097 absl::flat_hash_map<IntVar*, int> finalizer_variable_cost_index_;
2098 absl::flat_hash_set<IntVar*> finalizer_variable_target_set_;
2099 std::unique_ptr<SweepArranger> sweep_arranger_;
2102 RegularLimit* limit_ =
nullptr;
2103 RegularLimit* ls_limit_ =
nullptr;
2104 RegularLimit* lns_limit_ =
nullptr;
2105 RegularLimit* first_solution_lns_limit_ =
nullptr;
2107 typedef std::pair<int64_t, int64_t> CacheKey;
2108 typedef absl::flat_hash_map<CacheKey, int64_t> TransitCallbackCache;
2109 typedef absl::flat_hash_map<CacheKey, StateDependentTransit>
2110 StateDependentTransitCallbackCache;
2112 std::vector<TransitCallback1> unary_transit_evaluators_;
2113 std::vector<TransitCallback2> transit_evaluators_;
2124 std::vector<bool> is_transit_evaluator_positive_;
2125 std::vector<VariableIndexEvaluator2> state_dependent_transit_evaluators_;
2126 std::vector<std::unique_ptr<StateDependentTransitCallbackCache>>
2127 state_dependent_transit_evaluators_cache_;
2217 std::vector<int> tasks_by_start_min_;
2218 std::vector<int> tasks_by_end_max_;
2219 std::vector<int> event_of_task_;
2220 std::vector<int> nonchain_tasks_by_start_max_;
2222 std::vector<int64_t> total_duration_before_;
2240 std::vector<int64_t>* values);
2244 #endif // !defined(SWIG) 2260 return "GlobalVehicleBreaksConstraint";
2263 void Post()
override;
2267 void PropagateNode(
int node);
2268 void PropagateVehicle(
int vehicle);
2269 void PropagateMaxBreakDistance(
int vehicle);
2273 std::vector<Demon*> vehicle_demons_;
2274 std::vector<int64_t> path_;
2280 void FillPartialPathOfVehicle(
int vehicle);
2281 void FillPathTravels(
const std::vector<int64_t>& path);
2293 class TaskTranslator {
2295 TaskTranslator(
IntVar* start, int64_t before_start, int64_t after_start)
2297 before_start_(before_start),
2298 after_start_(after_start) {}
2302 void SetStartMin(int64_t
value) {
2303 if (start_ !=
nullptr) {
2305 }
else if (interval_ !=
nullptr) {
2306 interval_->SetStartMin(
value);
2309 void SetStartMax(int64_t
value) {
2310 if (start_ !=
nullptr) {
2312 }
else if (interval_ !=
nullptr) {
2313 interval_->SetStartMax(
value);
2316 void SetDurationMin(int64_t
value) {
2317 if (interval_ !=
nullptr) {
2318 interval_->SetDurationMin(
value);
2321 void SetEndMin(int64_t
value) {
2322 if (start_ !=
nullptr) {
2324 }
else if (interval_ !=
nullptr) {
2325 interval_->SetEndMin(
value);
2328 void SetEndMax(int64_t
value) {
2329 if (start_ !=
nullptr) {
2331 }
else if (interval_ !=
nullptr) {
2332 interval_->SetEndMax(
value);
2337 IntVar* start_ =
nullptr;
2338 int64_t before_start_;
2339 int64_t after_start_;
2340 IntervalVar* interval_ =
nullptr;
2344 std::vector<TaskTranslator> task_translators_;
2347 DisjunctivePropagator disjunctive_propagator_;
2348 DisjunctivePropagator::Tasks tasks_;
2351 TravelBounds travel_bounds_;
2360 const std::function<int64_t(int64_t)>& next_accessor);
2399 const std::function<int64_t(int64_t)>& next_accessor);
2409 std::vector<TypePolicyOccurrence> occurrences_of_type_;
2410 std::vector<int64_t> current_route_visits_;
2417 bool check_hard_incompatibilities);
2421 bool HasRegulationsToCheck()
const override;
2422 bool CheckTypeRegulations(
int type,
VisitTypePolicy policy,
int pos)
override;
2426 bool check_hard_incompatibilities_;
2437 bool HasRegulationsToCheck()
const override;
2438 void OnInitializeCheck()
override {
2439 types_with_same_vehicle_requirements_on_route_.clear();
2444 bool CheckRequiredTypesCurrentlyOnRoute(
2445 const std::vector<absl::flat_hash_set<int> >& required_type_alternatives,
2448 bool CheckTypeRegulations(
int type,
VisitTypePolicy policy,
int pos)
override;
2449 bool FinalizeCheck()
const override;
2451 absl::flat_hash_set<int> types_with_same_vehicle_requirements_on_route_;
2498 void Post()
override;
2502 void PropagateNodeRegulations(
int node);
2503 void CheckRegulationsOnVehicle(
int vehicle);
2508 std::vector<Demon*> vehicle_demons_;
2530 : bound_costs_(num_bounds, default_bound_cost) {}
2533 int Size() {
return bound_costs_.size(); }
2538 std::vector<BoundCost> bound_costs_;
2540 #endif // !defined SWIG 2571 int64_t vehicle)
const;
2576 return model_->TransitCallback(class_evaluators_[
vehicle_class])(from_index,
2584 return fixed_transits_[
index];
2588 #if !defined(SWIGPYTHON) 2589 const std::vector<IntVar*>&
cumuls()
const {
return cumuls_; }
2593 const std::vector<IntVar*>&
transits()
const {
return transits_; }
2594 const std::vector<IntVar*>&
slacks()
const {
return slacks_; }
2595 #if !defined(SWIGCSHARP) && !defined(SWIGJAVA) 2598 return forbidden_intervals_;
2602 int64_t
index, int64_t min_value, int64_t max_value)
const;
2606 int64_t min_value)
const {
2609 forbidden_intervals_[
index];
2610 const auto first_forbidden_interval_it =
2613 min_value >= first_forbidden_interval_it->start) {
2615 return CapAdd(first_forbidden_interval_it->end, 1);
2625 int64_t max_value)
const {
2628 forbidden_intervals_[
index];
2629 const auto last_forbidden_interval_it =
2632 max_value <= last_forbidden_interval_it->end) {
2634 return CapSub(last_forbidden_interval_it->start, 1);
2641 return vehicle_capacities_;
2646 return model_->TransitCallback(
2647 class_evaluators_[vehicle_to_class_[vehicle]]);
2654 const int vehicle = model_->GetVehicleOfClass(
vehicle_class);
2663 int vehicle)
const {
2664 return model_->UnaryTransitCallbackOrNull(
2665 class_evaluators_[vehicle_to_class_[vehicle]]);
2670 return model()->is_transit_evaluator_positive_
2671 [class_evaluators_[vehicle_to_class_[vehicle]]];
2676 void SetSpanUpperBoundForVehicle(int64_t upper_bound, int vehicle); 2709 int64_t
index)
const;
2772 #if !defined(SWIGPYTHON) 2774 int pre_travel_evaluator,
2775 int post_travel_evaluator);
2776 #endif // !defined(SWIGPYTHON) 2780 std::vector<int64_t> node_visit_transits);
2793 #if !defined(SWIGPYTHON) 2797 std::vector<IntervalVar*> breaks,
int vehicle,
2798 std::vector<int64_t> node_visit_transits,
2799 std::function<int64_t(int64_t, int64_t)> delays);
2807 const std::vector<std::pair<int64_t, int64_t> >&
2811 int GetPreTravelEvaluatorOfVehicle(int vehicle) const; 2826 const std::string&
name()
const {
return name_; }
2831 return path_precedence_graph_;
2852 int delivery)
const;
2861 node_precedences_.push_back(precedence);
2864 return node_precedences_;
2874 return vehicle_span_upper_bounds_[vehicle];
2878 return vehicle_span_upper_bounds_;
2882 return vehicle_span_cost_coefficients_[vehicle];
2887 const int vehicle = model_->GetVehicleOfClass(
vehicle_class);
2894 return vehicle_span_cost_coefficients_;
2898 return global_span_cost_coefficient_;
2903 return global_optimizer_offset_;
2906 if (vehicle >= local_optimizer_offset_for_vehicle_.size()) {
2909 DCHECK_GE(local_optimizer_offset_for_vehicle_[vehicle], 0);
2910 return local_optimizer_offset_for_vehicle_[vehicle];
2918 vehicle_soft_span_upper_bound_ = absl::make_unique<SimpleBoundCosts>(
2921 vehicle_soft_span_upper_bound_->bound_cost(vehicle) = bound_cost;
2924 return vehicle_soft_span_upper_bound_ !=
nullptr;
2927 int vehicle)
const {
2929 return vehicle_soft_span_upper_bound_->bound_cost(vehicle);
2936 vehicle_quadratic_cost_soft_span_upper_bound_ =
2937 absl::make_unique<SimpleBoundCosts>(
2940 vehicle_quadratic_cost_soft_span_upper_bound_->bound_cost(vehicle) =
2944 return vehicle_quadratic_cost_soft_span_upper_bound_ !=
nullptr;
2947 int vehicle)
const {
2949 return vehicle_quadratic_cost_soft_span_upper_bound_->bound_cost(vehicle);
2960 struct PiecewiseLinearCost {
2961 PiecewiseLinearCost() :
var(nullptr),
cost(nullptr) {}
2963 std::unique_ptr<PiecewiseLinearFunction>
cost;
2968 const std::string&
name,
2971 const std::string&
name, SelfBased);
2972 void Initialize(
const std::vector<int>& transit_evaluators,
2973 const std::vector<int>& state_dependent_transit_evaluators,
2975 void InitializeCumuls();
2976 void InitializeTransits(
2977 const std::vector<int>& transit_evaluators,
2978 const std::vector<int>& state_dependent_transit_evaluators,
2980 void InitializeTransitVariables(int64_t slack_max);
2982 void SetupCumulVarSoftUpperBoundCosts(
2983 std::vector<IntVar*>* cost_elements)
const;
2985 void SetupCumulVarSoftLowerBoundCosts(
2986 std::vector<IntVar*>* cost_elements)
const;
2987 void SetupCumulVarPiecewiseLinearCosts(
2988 std::vector<IntVar*>* cost_elements)
const;
2991 void SetupGlobalSpanCost(std::vector<IntVar*>* cost_elements)
const;
2992 void SetupSlackAndDependentTransitCosts()
const;
2994 void CloseModel(
bool use_light_propagation);
2996 void SetOffsetForGlobalOptimizer(int64_t offset) {
3000 void SetVehicleOffsetsForLocalOptimizer(std::vector<int64_t> offsets) {
3002 std::transform(offsets.begin(), offsets.end(), offsets.begin(),
3003 [](int64_t offset) {
return std::max(
Zero(), offset); });
3004 local_optimizer_offset_for_vehicle_ = std::move(offsets);
3007 std::vector<IntVar*> cumuls_;
3008 std::vector<SortedDisjointIntervalList> forbidden_intervals_;
3009 std::vector<IntVar*> capacity_vars_;
3010 const std::vector<int64_t> vehicle_capacities_;
3011 std::vector<IntVar*> transits_;
3012 std::vector<IntVar*> fixed_transits_;
3015 std::vector<int> class_evaluators_;
3016 std::vector<int64_t> vehicle_to_class_;
3018 ReverseArcListGraph<int, int> path_precedence_graph_;
3024 std::vector<NodePrecedence> node_precedences_;
3029 const RoutingDimension*
const base_dimension_;
3034 std::vector<int> state_dependent_class_evaluators_;
3035 std::vector<int64_t> state_dependent_vehicle_to_class_;
3040 std::vector<PickupToDeliveryLimitFunction>
3041 pickup_to_delivery_limits_per_pair_index_;
3044 bool break_constraints_are_initialized_ =
false;
3046 std::vector<std::vector<IntervalVar*> > vehicle_break_intervals_;
3047 std::vector<std::vector<std::pair<int64_t, int64_t> > >
3048 vehicle_break_distance_duration_;
3053 std::vector<int> vehicle_pre_travel_evaluators_;
3054 std::vector<int> vehicle_post_travel_evaluators_;
3056 std::vector<IntVar*> slacks_;
3057 std::vector<IntVar*> dependent_transits_;
3058 std::vector<int64_t> vehicle_span_upper_bounds_;
3059 int64_t global_span_cost_coefficient_;
3060 std::vector<int64_t> vehicle_span_cost_coefficients_;
3061 std::vector<SoftBound> cumul_var_soft_upper_bound_;
3062 std::vector<SoftBound> cumul_var_soft_lower_bound_;
3063 std::vector<PiecewiseLinearCost> cumul_var_piecewise_linear_cost_;
3065 const std::string name_;
3066 int64_t global_optimizer_offset_;
3067 std::vector<int64_t> local_optimizer_offset_for_vehicle_;
3069 std::unique_ptr<SimpleBoundCosts> vehicle_soft_span_upper_bound_;
3070 std::unique_ptr<SimpleBoundCosts>
3071 vehicle_quadratic_cost_soft_span_upper_bound_;
3075 const std::vector<RoutingDimension*>&
dimensions,
3077 std::vector<LocalSearchFilterManager::FilterEvent>* filters);
3085 std::vector<IntVar*> variables,
3086 std::vector<int64_t> targets);
3116 #endif // OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_H_ Assignment * ReadAssignment(const std::string &file_name)
Reads an assignment from a file and returns the current solution.
void SetPickupAndDeliveryPolicyOfAllVehicles(PickupAndDeliveryPolicy policy)
Sets the Pickup and delivery policy of all vehicles.
CostClass(int evaluator_index)
bool VehicleRequiresAResource(int vehicle) const
int Type(int vehicle) const
RoutingTransitCallback1 TransitCallback1
Status
Status of the search.
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< std::vector< int > > & GetTopologicallySortedVisitTypes() const
void Post() override
This method is called when the constraint is processed by the solver.
int64_t GetCumulVarSoftUpperBoundCoefficient(int64_t index) const
Returns the cost coefficient of the soft upper bound of a cumul variable for a given variable index.
void IgnoreDisjunctionsAlreadyForcedToZero()
SPECIAL: Makes the solver ignore all the disjunctions whose active variables are all trivially zero (...
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_,...
Solver * solver() const
Returns the underlying constraint solver.
int64_t CapSub(int64_t x, int64_t y)
int RegisterStateDependentTransitCallback(VariableIndexEvaluator2 callback)
When visited, one instance of type 'T' previously added to the route (TYPE_ADDED_TO_VEHICLE),...
std::vector< int > required_resource_group_indices
Sorted set of resource groups for which the vehicle requires a resource.
FirstSolutionStrategy_Value Value
int64_t GetNumberOfRejectsInFirstSolution(const RoutingSearchParameters &search_parameters) const
std::vector< int64_t > post_travels
int64_t UnperformedPenaltyOrValue(int64_t default_value, int64_t var_index) const
Same as above except that it returns default_value instead of 0 when penalty is not well defined (def...
std::function< int64_t(int, int)> PickupToDeliveryLimitFunction
Limits, in terms of maximum difference between the cumul variables, between the pickup and delivery a...
const PiecewiseLinearFunction * GetCumulVarPiecewiseLinearCost(int64_t index) const
Returns the piecewise linear cost of a cumul variable for a given variable index.
absl::Duration RemainingTime() const
Returns the time left in the search limit.
std::vector< int > type_index_of_vehicle
const absl::flat_hash_set< DimensionIndex > & GetAffectedDimensionIndices() const
SimpleBoundCosts(int num_bounds, BoundCost default_bound_cost)
void AddPickupAndDelivery(int64_t pickup, int64_t delivery)
Notifies that index1 and index2 form a pair of nodes which should belong to the same route.
static std::unique_ptr< LocalSearchOperator > MakeGreedyDescentLSOperator(std::vector< IntVar * > variables)
Perhaps move it to constraint_solver.h.
int64_t GetSpanCostCoefficientForVehicleClass(RoutingVehicleClassIndex vehicle_class) const
TypeRegulationsConstraint(const RoutingModel &model)
const Assignment * SolveFromAssignmentWithParameters(const Assignment *assignment, const RoutingSearchParameters &search_parameters, std::vector< const Assignment * > *solutions=nullptr)
Same as above, except that if assignment is not null, it will be used as the initial solution.
int64_t Next(const Assignment &assignment, int64_t index) const
Assignment inspection Returns the variable index of the node directly after the node corresponding to...
RoutingCostClassIndex CostClassIndex
int64_t GetCumulVarSoftUpperBound(int64_t index) const
Returns the soft upper bound of a cumul variable for a given variable index.
TypeRegulationsChecker(const RoutingModel &model)
const std::vector< IntVar * > & cumuls() const
Like CumulVar(), TransitVar(), SlackVar() but return the whole variable vectors instead (indexed by i...
int64_t GetArcCostForClass(int64_t from_index, int64_t to_index, int64_t cost_class_index) const
Returns the cost of the segment between two nodes for a given cost class.
GlobalDimensionCumulOptimizer * GetMutableGlobalCumulMPOptimizer(const RoutingDimension &dimension) const
void SetSpanCostCoefficientForAllVehicles(int64_t coefficient)
const IndexPairs & GetImplicitUniquePickupAndDeliveryPairs() const
Returns implicit pickup and delivery pairs currently in the model.
void SetPickupToDeliveryLimitFunctionForPair(PickupToDeliveryLimitFunction limit_function, int pair_index)
int GetNumberOfDisjunctions() const
Returns the number of node disjunctions in the model.
void AssignmentToRoutes(const Assignment &assignment, std::vector< std::vector< int64_t >> *const routes) const
Converts the solution in the given assignment to routes for all vehicles.
bool HasCumulVarPiecewiseLinearCost(int64_t index) const
Returns true if a piecewise linear cost has been set for a given variable index.
const absl::flat_hash_set< int > & GetHardTypeIncompatibilitiesOfType(int type) const
Returns visit types incompatible with a given type.
int64_t GetLocalOptimizerOffsetForVehicle(int vehicle) const
ResourceGroup * GetResourceGroup(int rg_index) const
const VariableIndexEvaluator2 & StateDependentTransitCallback(int callback_index) const
void CloseModel()
Closes the current routing model; after this method is called, no modification to the model can be do...
const RoutingDimension * dimension
Manager for any NodeIndex <-> variable index conversion.
bool operator<(const DimensionCost &cost) const
int64_t ShortestTransitionSlack(int64_t node) const
It makes sense to use the function only for self-dependent dimension.
bool HasBreakConstraints() const
Returns true if any break interval or break distance was defined.
bool AddDimensionWithVehicleTransitAndCapacity(const std::vector< int > &evaluator_indices, int64_t slack_max, std::vector< int64_t > vehicle_capacities, bool fix_start_cumul_to_zero, const std::string &name)
bool operator<(const VehicleClassEntry &other) const
std::vector< bool > is_preemptible
ResourceGroup(const RoutingModel *model)
const std::vector< DisjunctionIndex > & GetDisjunctionIndices(int64_t index) const
Returns the indices of the disjunctions to which an index belongs.
void InitializeBreaks()
Sets up vehicle_break_intervals_, vehicle_break_distance_duration_, pre_travel_evaluators and post_tr...
std::vector< RoutingIndexPair > RoutingIndexPairs
IntVar * VehicleVar(int64_t index) const
Returns the vehicle variable of the node corresponding to index.
const std::vector< int > & GetPairIndicesOfType(int type) const
void SetVisitType(int64_t index, int type, VisitTypePolicy type_policy)
BoundCost & bound_cost(int element)
bool HasSameVehicleTypeRequirements() const
Returns true iff any same-route (resp.
bool IsVehicleAllowedForIndex(int vehicle, int64_t index)
Returns true if a vehicle is allowed to visit a given node.
std::vector< int64_t > end_max
int AddResourceGroup()
Adds a resource group to the routing model.
std::pair< int, bool > AddConstantDimension(int64_t value, int64_t capacity, bool fix_start_cumul_to_zero, const std::string &name)
bool HasVehicleWithCostClassIndex(CostClassIndex cost_class_index) const
Returns true iff the model contains a vehicle with the given cost_class_index.
absl::StrongVector< DimensionIndex, int64_t > dimension_start_cumuls_min
Bounds of cumul variables at start and end vehicle nodes.
IntVar * CostVar() const
Returns the global cost variable which is being minimized.
void SetSpanCostCoefficientForVehicle(int64_t coefficient, int vehicle)
Sets a cost proportional to the dimension span on a given vehicle, or on all vehicles at once.
absl::StrongVector< DimensionIndex, int64_t > dimension_evaluator_classes
dimension_evaluators[d]->Run(from, to) is the transit value of arc from->to for a dimension d.
int64_t GetCumulVarSoftLowerBoundCoefficient(int64_t index) const
Returns the cost coefficient of the soft lower bound of a cumul variable for a given variable index.
SortedDisjointIntervalList GetAllowedIntervalsInRange(int64_t index, int64_t min_value, int64_t max_value) const
Returns allowed intervals for a given node in a given interval.
void AddVariableMaximizedByFinalizer(IntVar *var)
Adds a variable to maximize in the solution finalizer (see above for information on the solution fina...
const RoutingDimension & GetDimensionOrDie(const std::string &dimension_name) const
Returns a dimension from its name. Dies if the dimension does not exist.
friend void AppendDimensionCumulFilters(const std::vector< RoutingDimension * > &dimensions, const RoutingSearchParameters ¶meters, bool filter_objective_cost, std::vector< LocalSearchFilterManager::FilterEvent > *filters)
int64_t GetArcCostForFirstSolution(int64_t from_index, int64_t to_index) const
Returns the cost of the arc in the context of the first solution strategy.
std::vector< RoutingDimension * > GetDimensionsWithSoftOrSpanCosts() const
Returns dimensions with soft or vehicle span costs.
const std::vector< int64_t > & GetDisjunctionNodeIndices(DisjunctionIndex index) const
Returns the variable indices of the nodes in the disjunction of index 'index'.
void SetPrimaryConstrainedDimension(const std::string &dimension_name)
Set the given dimension as "primary constrained".
void SetTabuVarsCallback(GetTabuVarsCallback tabu_var_callback)
int64_t global_span_cost_coefficient() const
const std::vector< IntVar * > & fixed_transits() const
RoutingModel * model() const
Returns the model on which the dimension was created.
int64_t GetDisjunctionPenalty(DisjunctionIndex index) const
Returns the penalty of the node disjunction of index 'index'.
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...
std::vector< int64_t > start_min
int RegisterTransitMatrix(std::vector< std::vector< int64_t > > values)
void AddLocalSearchOperator(LocalSearchOperator *ls_operator)
Adds a local search operator to the set of operators used to solve the vehicle routing problem.
std::vector< std::pair< int64_t, int64_t > > GetPerfectBinaryDisjunctions() const
Returns the list of all perfect binary disjunctions, as pairs of variable indices: a disjunction is "...
virtual bool CheckTypeRegulations(int type, VisitTypePolicy policy, int pos)=0
int AddResource(Attributes attributes, const RoutingDimension *dimension)
Adds a Resource with the given attributes for the corresponding dimension.
DecisionBuilder * MakeRestoreDimensionValuesForUnchangedRoutes(RoutingModel *model)
const std::vector< std::unique_ptr< ResourceGroup > > & GetResourceGroups() const
const TransitCallback1 & UnaryTransitCallbackOrNull(int callback_index) const
std::vector< int64_t > end_min
void AddSearchMonitor(SearchMonitor *const monitor)
Adds a search monitor to the search used to solve the routing model.
Checker for type incompatibilities.
bool Propagate(Tasks *tasks)
Computes new bounds for all tasks, returns false if infeasible.
bool ChainSpanMin(Tasks *tasks)
Propagates a lower bound of the chain span, end[num_chain_tasks] - start[0], to span_min.
void AddWeightedVariableMinimizedByFinalizer(IntVar *var, int64_t cost)
Adds a variable to minimize in the solution finalizer, with a weighted priority: the higher the more ...
Time limit reached before finding a solution with RoutingModel::Solve().
A constraint is the main modeling object.
Dimensions represent quantities accumulated at nodes along the routes.
bool HasMandatoryDisjunctions() const
Returns true if the model contains mandatory disjunctions (ones with kNoPenalty as penalty).
int64_t End(int vehicle) const
Returns the variable index of the ending node of a vehicle route.
Constraint * MakePathSpansAndTotalSlacks(const RoutingDimension *dimension, std::vector< IntVar * > spans, std::vector< IntVar * > total_slacks)
For every vehicle of the routing model:
std::vector< int64_t > pre_travels
void SetPickupAndDeliveryPolicyOfVehicle(PickupAndDeliveryPolicy policy, int vehicle)
bool ForbiddenIntervals(Tasks *tasks)
Tasks might have holes in their domain, this enforces such holes.
Status status() const
Returns the current status of the routing model.
absl::StrongVector< DimensionIndex, int64_t > dimension_capacities
bool HasDimension(const std::string &dimension_name) const
Returns true if a dimension exists for a given dimension name.
int64_t GetSpanUpperBoundForVehicle(int vehicle) const
friend class RoutingModel
bool MirrorTasks(Tasks *tasks)
Transforms the problem with a time symmetry centered in 0.
absl::StrongVector< DimensionIndex, int64_t > dimension_end_cumuls_min
int64_t GetHomogeneousCost(int64_t from_index, int64_t to_index) const
Returns the cost of the segment between two nodes supposing all vehicle costs are the same (returns t...
const Solver::IndexEvaluator2 & first_solution_evaluator() const
Gets/sets the evaluator used during the search.
const std::vector< std::unique_ptr< GlobalDimensionCumulOptimizer > > & GetGlobalDimensionCumulOptimizers() const
Returns [global|local]_dimension_optimizers_, which are empty if the model has not been closed.
int64_t transit_evaluator_class
IntVar * FixedTransitVar(int64_t index) const
const std::vector< IntVar * > & transits() const
const IndexPairs & GetPickupAndDeliveryPairs() const
Returns pickup and delivery pairs currently in the model.
A DecisionBuilder is responsible for creating the search tree.
const RoutingModel::TransitCallback2 & class_transit_evaluator(RoutingVehicleClassIndex vehicle_class) const
Returns the callback evaluating the transit value between two node indices for a given vehicle class.
void FillPathEvaluation(const std::vector< int64_t > &path, const RoutingModel::TransitCallback2 &evaluator, std::vector< int64_t > *values)
const ReverseArcListGraph< int, int > & GetPathPrecedenceGraph() const
Accessors.
A structure meant to store soft bounds and associated violation constants.
uint64_t unvisitable_nodes_fprint
Fingerprint of unvisitable non-start/end nodes.
bool AddDimensionDependentDimensionWithVehicleCapacity(const std::vector< int > &pure_transits, const std::vector< int > &dependent_transits, const RoutingDimension *base_dimension, int64_t slack_max, std::vector< int64_t > vehicle_capacities, bool fix_start_cumul_to_zero, const std::string &name)
Creates a dimension with transits depending on the cumuls of another dimension.
Problem solved successfully after calling RoutingModel::Solve().
bool RoutesToAssignment(const std::vector< std::vector< int64_t >> &routes, bool ignore_inactive_indices, bool close_routes, Assignment *const assignment) const
Fills an assignment from a specification of the routes of the vehicles.
GlobalVehicleBreaksConstraint(const RoutingDimension *dimension)
int64_t GetPickupToDeliveryLimitForPair(int pair_index, int pickup, int delivery) const
void FillTravelBoundsOfVehicle(int vehicle, const std::vector< int64_t > &path, const RoutingDimension &dimension, TravelBounds *travel_bounds)
const std::vector< int64_t > & vehicle_span_cost_coefficients() const
bool HasHardTypeIncompatibilities() const
Returns true iff any hard (resp.
IntVar * ActiveVehicleVar(int vehicle) const
Returns the active variable of the vehicle.
bool HasPickupToDeliveryLimits() const
Deliveries must be performed in the same order as pickups.
Attributes for a dimension.
bool ArcIsMoreConstrainedThanArc(int64_t from, int64_t to1, int64_t to2)
Returns whether the arc from->to1 is more constrained than from->to2, taking into account,...
No solution found to the problem after calling RoutingModel::Solve().
#define CHECK_LT(val1, val2)
Interval variables are often used in scheduling.
static const char kLightElement[]
Constraint types.
void AddToAssignment(IntVar *const var)
Adds an extra variable to the vehicle routing assignment.
const std::vector< std::unique_ptr< LocalDimensionCumulOptimizer > > & GetLocalDimensionCumulOptimizers() 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 AddNodePrecedence(NodePrecedence precedence)
int RegisterTransitCallback(TransitCallback2 callback)
virtual ~TypeRegulationsChecker()
int GetNumOfSingletonNodes() const
Returns the number of non-start/end nodes which do not appear in a pickup/delivery pair.
const Assignment * SolveWithParameters(const RoutingSearchParameters &search_parameters, std::vector< const Assignment * > *solutions=nullptr)
Solves the current routing model with the given parameters.
int64_t GetCumulVarSoftLowerBound(int64_t index) const
Returns the soft lower bound of a cumul variable for a given variable index.
const std::vector< IntVar * > & ResourceVars(int resource_group) const
Returns vehicle resource variables for a given resource group, such that ResourceVars(r_g)[v] is the ...
const std::vector< int64_t > & vehicle_span_upper_bounds() const
void CloseVisitTypes()
This function should be called once all node visit types have been set and prior to adding any incomp...
int64_t GetTransitValueFromClass(int64_t from_index, int64_t to_index, int64_t vehicle_class) const
Same as above but taking a vehicle class of the dimension instead of a vehicle (the class of a vehicl...
int64_t ComputeLowerBound()
Computes a lower bound to the routing problem solving a linear assignment problem.
friend class RoutingDimension
DecisionBuilder * MakeSetValuesFromTargets(Solver *solver, std::vector< IntVar * > variables, std::vector< int64_t > targets)
A decision builder which tries to assign values to variables as close as possible to target values fi...
IntVar * CumulVar(int64_t index) const
Get the cumul, transit and slack variables for the given node (given as int64_t var index).
int GetDimensionResourceGroupIndex(const RoutingDimension *dimension) const
Returns the index of the resource group attached to the dimension.
int nodes() const
Sizes and indices Returns the number of nodes in the model.
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,...
With the following policy, the visit enforces that type 'T' is considered on the route from its start...
const std::vector< std::pair< int, int > > & GetPickupIndexPairs(int64_t node_index) const
Returns pairs for which the node is a pickup; the first element of each pair is the index in the pick...
const std::vector< Resource > & GetResources() const
int RegisterUnaryTransitVector(std::vector< int64_t > values)
Registers 'callback' and returns its index.
const Assignment * Solve(const Assignment *assignment=nullptr)
Solves the current routing model; closes the current model.
const std::string & name() const
Returns the name of the dimension.
const std::vector< int > & GetSameVehicleIndicesOfIndex(int node) const
Returns variable indices of nodes constrained to be on the same route.
Assignment * ReadAssignmentFromRoutes(const std::vector< std::vector< int64_t >> &routes, bool ignore_inactive_indices)
Restores the routes as the current solution.
VisitTypePolicy GetVisitTypePolicy(int64_t index) const
Assignment * CompactAndCheckAssignment(const Assignment &assignment) const
Same as CompactAssignment() but also checks the validity of the final compact solution; if it is not ...
absl::StrongVector< DimensionIndex, int64_t > dimension_end_cumuls_max
std::vector< int64_t > duration_max
const absl::flat_hash_set< int > & GetTemporalTypeIncompatibilitiesOfType(int type) const
std::vector< std::string > GetAllDimensionNames() const
Outputs the names of all dimensions added to the routing engine.
bool AddDimension(int evaluator_index, int64_t slack_max, int64_t capacity, bool fix_start_cumul_to_zero, const std::string &name)
Model creation.
const Resource & GetResource(int resource_index) const
int64_t GetArcCostForVehicle(int64_t from_index, int64_t to_index, int64_t vehicle) const
Returns the cost of the transit arc between two nodes for a given vehicle.
static const int64_t kint64max
TypeRequirementChecker(const RoutingModel &model)
int RegisterUnaryTransitCallback(TransitCallback1 callback)
void NotifyVehicleRequiresAResource(int vehicle)
Notifies that the given vehicle index requires a resource from this group if the vehicle is used (i....
int64_t CapAdd(int64_t x, int64_t y)
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.
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.
const std::vector< absl::flat_hash_set< int > > & GetRequiredTypeAlternativesWhenAddingType(int type) const
Returns the set of requirement alternatives when adding the given type.
Deliveries must be performed in reverse order of pickups.
IntVarLocalSearchFilter * MakeVehicleBreaksFilter(const RoutingModel &routing_model, const RoutingDimension &dimension)
int RegisterPositiveUnaryTransitCallback(TransitCallback1 callback)
RoutingDimensionIndex DimensionIndex
Assignment * RestoreAssignment(const Assignment &solution)
Restores an assignment as a solution in the routing model and returns the new solution.
std::vector< int64_t > start_max
LocalDimensionCumulOptimizer * GetMutableLocalCumulOptimizer(const RoutingDimension &dimension) const
std::vector< int64_t > min_travels
void AddIntervalToAssignment(IntervalVar *const interval)
PickupAndDeliveryPolicy GetPickupAndDeliveryPolicyOfVehicle(int vehicle) const
void SetAllowedVehiclesForIndex(const std::vector< int > &vehicles, int64_t index)
Sets the vehicles which can visit a given node.
void SetVehicleUsedWhenEmpty(bool is_used, int vehicle)
#define DCHECK_NE(val1, val2)
bool DetectablePrecedencesWithChain(Tasks *tasks)
Does detectable precedences deductions on tasks in the chain precedence, taking the time windows of n...
Checker for type requirements.
int64_t GetSpanCostCoefficientForVehicle(int vehicle) const
A Resource sets attributes (costs/constraints) for a set of dimensions.
const std::vector< std::pair< int, int > > & GetDeliveryIndexPairs(int64_t node_index) const
Same as above for deliveries.
Problem not solved yet (before calling RoutingModel::Solve()).
int GetMaximumNumberOfActiveVehicles() const
Returns the maximum number of active vehicles.
std::vector< int > dimensions
bool IsStart(int64_t index) const
Returns true if 'index' represents the first node of a route.
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...
This class represents a sorted list of disjoint, closed intervals.
const std::string & GetPrimaryConstrainedDimension() const
Get the primary constrained dimension, or an empty string if it is unset.
int64_t GetNumberOfDecisionsInFirstSolution(const RoutingSearchParameters &search_parameters) const
Returns statistics on first solution search, number of decisions sent to filters, number of decisions...
Assignment * CompactAssignment(const Assignment &assignment) const
Returns a compacted version of the given assignment, in which all vehicles with id lower or equal to ...
const std::vector< absl::flat_hash_set< int > > & GetRequiredTypeAlternativesWhenRemovingType(int type) const
Returns the set of requirement alternatives when removing the given type.
std::function< StateDependentTransit(int64_t, int64_t)> VariableIndexEvaluator2
bool CostsAreHomogeneousAcrossVehicles() const
Whether costs are homogeneous across all vehicles.
static RoutingModel::StateDependentTransit MakeStateDependentTransit(const std::function< int64_t(int64_t)> &f, int64_t domain_start, int64_t domain_end)
Creates a cached StateDependentTransit from an std::function.
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...
virtual bool FinalizeCheck() const
VisitTypePolicy
Set the node visit types and incompatibilities/requirements between the types (see below).
const std::vector< SortedDisjointIntervalList > & forbidden_intervals() const
Returns forbidden intervals for each node.
SimpleBoundCosts operator=(const SimpleBoundCosts &)=delete
bool HasCumulVarSoftUpperBound(int64_t index) const
Returns true if a soft upper bound has been set for a given variable index.
void AddTemporalTypeIncompatibility(int type1, int type2)
static bool LessThan(const VehicleClass &a, const VehicleClass &b)
Comparator for STL containers and algorithms.
void SetAmortizedCostFactorsOfVehicle(int64_t linear_cost_factor, int64_t quadratic_cost_factor, int vehicle)
Sets the linear and quadratic cost factor of the given vehicle.
Assignment * MutablePreAssignment()
static const char kRemoveValues[]
bool AreVehicleTransitsPositive(int vehicle) const
Returns true iff the transit evaluator of 'vehicle' is positive for all arcs.
int GetVehicleClassesCount() const
Returns the number of different vehicle classes in the model.
int GetVehicleOfClass(VehicleClassIndex vehicle_class) const
Returns a vehicle of the given vehicle class, and -1 if there are no vehicles for this class.
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 * (...
void SetFirstSolutionEvaluator(Solver::IndexEvaluator2 evaluator)
Takes ownership of evaluator.
const std::vector< SearchMonitor * > & GetSearchMonitors() const
void AddVariableTargetToFinalizer(IntVar *var, int64_t target)
Add a variable to set the closest possible to the target value in the solution finalizer.
RoutingDisjunctionIndex DisjunctionIndex
PickupAndDeliveryPolicy
Types of precedence policy applied to pickup and delivery pairs.
void AddAtSolutionCallback(std::function< void()> callback)
Adds a callback called each time a solution is found during the search.
const RoutingDimension * base_dimension() const
Returns the parent in the dependency tree if any or nullptr otherwise.
static const DisjunctionIndex kNoDisjunction
Constant used to express the "no disjunction" index, returned when a node does not appear in any disj...
void ForEachNodeInDisjunctionWithMaxCardinalityFromIndex(int64_t index, int64_t max_cardinality, F f) const
Calls f for each variable index of indices in the same disjunctions as the node corresponding to the ...
GlobalVehicleBreaksConstraint ensures breaks constraints are enforced on all vehicles in the dimensio...
An Assignment is a variable -> domains mapping, used to report solutions to the user.
int num_type_removed_from_vehicle
Number of ADDED_TYPE_REMOVED_FROM_VEHICLE (effectively removing a type from the route) and TYPE_SIMUL...
CostClassIndex GetCostClassIndexOfVehicle(int64_t vehicle) const
Get the cost class index of the given vehicle.
int GetNumberOfVisitTypes() const
std::function< std::vector< operations_research::IntVar * >(RoutingModel *)> GetTabuVarsCallback
Sets the callback returning the variable to use for the Tabu Search metaheuristic.
LocalDimensionCumulOptimizer * GetMutableLocalCumulMPOptimizer(const RoutingDimension &dimension) const
VehicleClassIndex GetVehicleClassIndexOfVehicle(int64_t vehicle) const
int GetCostClassesCount() const
Returns the number of different cost classes in the model.
A BaseObject is the root of all reversibly allocated objects.
RangeIntToIntFunction * transit
std::function< int64_t(int64_t, int64_t)> RoutingTransitCallback2
std::pair< int, bool > AddConstantDimensionWithSlack(int64_t value, int64_t capacity, int64_t 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...
The class IntVar is a subset of IntExpr.
bool CheckVehicle(int vehicle, const std::function< int64_t(int64_t)> &next_accessor)
#define DCHECK_GE(val1, val2)
When visited, the number of types 'T' on the vehicle increases by one.
std::vector< std::deque< int > > vehicles_per_vehicle_class
const RoutingModel::TransitCallback2 & transit_evaluator(int vehicle) const
Returns the callback evaluating the transit value between two node indices for a given vehicle.
A ResourceGroup defines a set of available Resources with attributes on one or multiple dimensions.
std::pair< int, bool > AddVectorDimension(std::vector< int64_t > values, int64_t 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 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,...
SimpleBoundCosts::BoundCost GetSoftSpanUpperBoundForVehicle(int vehicle) const
bool IsVehicleUsedWhenEmpty(int vehicle) const
static const int64_t kNoPenalty
Constant used to express a hard constraint instead of a soft penalty.
int start_equivalence_class
Vehicle start and end equivalence classes.
bool HasCumulVarSoftLowerBound(int64_t index) const
Returns true if a soft lower bound has been set for a given variable index.
const VehicleTypeContainer & GetVehicleTypeContainer() const
virtual void OnInitializeCheck()
This class acts like a CP propagator: it takes a set of tasks given by their start/duration/end featu...
bool DistanceDuration(Tasks *tasks)
Propagates distance_duration constraints, if any.
const Assignment *const PreAssignment() const
Returns an assignment used to fix some of the variables of the problem.
SUBTLE: The vehicle's fixed cost is skipped on purpose here, because we can afford to do so:
IntVar * ApplyLocks(const std::vector< int64_t > &locks)
Applies a lock chain to the next search.
const std::vector< std::unique_ptr< LocalDimensionCumulOptimizer > > & GetLocalDimensionCumulMPOptimizers() const
std::function< int64_t(int64_t, int64_t)> IndexEvaluator2
const RoutingModel & model_
void AddNodePrecedence(int64_t first_node, int64_t second_node, int64_t offset)
FirstSolutionStrategy_Value
const std::vector< IntVar * > & slacks() const
int64_t GetTransitValue(int64_t from_index, int64_t to_index, int64_t vehicle) const
Returns the transition value for a given pair of nodes (as var index); this value is the one taken by...
std::vector< std::vector< int64_t > > GetRoutesFromAssignment(const Assignment &assignment)
Converts the solution in the given assignment to routes for all vehicles.
virtual bool HasRegulationsToCheck() const =0
void SetAmortizedCostFactorsOfAllVehicles(int64_t linear_cost_factor, int64_t quadratic_cost_factor)
The following methods set the linear and quadratic cost factors of vehicles (must be positive values)...
RoutingIndexPairs IndexPairs
RangeMinMaxIndexFunction * transit_plus_identity
f(x)
static const DimensionIndex kNoDimension
Constant used to express the "no dimension" index, returned when a dimension name does not correspond...
std::vector< std::vector< std::pair< int64_t, int64_t > > > 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...
bool used_when_empty
Whether or not the vehicle is used when empty.
operations_research::FirstSolutionStrategy::Value GetAutomaticFirstSolutionStrategy() const
Returns the automatic first solution strategy selected.
std::vector< std::set< VehicleClassEntry > > sorted_vehicle_classes_per_type
#define DCHECK(condition)
static constexpr Value UNSET
int64_t GetFirstPossibleGreaterOrEqualValueForNode(int64_t index, int64_t min_value) const
Returns the smallest value outside the forbidden intervals of node 'index' that is greater than or eq...
BoundCost bound_cost(int element) const
const std::vector< std::pair< int64_t, int64_t > > & GetBreakDistanceDurationOfVehicle(int vehicle) const
Returns the pairs (distance, duration) specified by break distance constraints.
int GetPostTravelEvaluatorOfVehicle(int vehicle) const
void AppendTasksFromIntervals(const std::vector< IntervalVar * > &intervals, DisjunctivePropagator::Tasks *tasks)
We call domain any subset of Int64 = [kint64min, kint64max].
std::function< int64_t(int64_t)> RoutingTransitCallback1
int GetNonZeroCostClassesCount() const
Ditto, minus the 'always zero', built-in cost class.
void SetSweepArranger(SweepArranger *sweep_arranger)
int vehicle_to_class(int vehicle) const
int vehicles() const
Returns the number of vehicle routes in the model.
RoutingIndexPair IndexPair
void SetFixedCostOfVehicle(int64_t cost, int vehicle)
Sets the fixed cost of one vehicle route.
const std::vector< int > & GetVehiclesRequiringAResource() const
bool AddDimensionWithVehicleCapacity(int evaluator_index, int64_t slack_max, std::vector< int64_t > vehicle_capacities, bool fix_start_cumul_to_zero, const std::string &name)
Model, model parameters or flags are not valid.
#define DCHECK_EQ(val1, val2)
const ResourceGroup::Attributes & GetDimensionAttributes(const RoutingDimension *dimension) const
void SetMaximumNumberOfActiveVehicles(int max_active_vehicles)
Constrains the maximum number of active vehicles, aka the number of vehicles which do not have an emp...
const std::vector< std::pair< DisjunctionIndex, DisjunctionIndex > > & GetPickupAndDeliveryDisjunctions() const
void SetGlobalSpanCostCoefficient(int64_t coefficient)
Sets a cost proportional to the global dimension span, that is the difference between the largest val...
void InitialPropagate() override
This method performs the initial propagation of the constraint.
RoutingModel(const RoutingIndexManager &index_manager)
Constructor taking an index manager.
const std::vector< NodePrecedence > & GetNodePrecedences() const
const std::vector< absl::flat_hash_set< int > > & GetSameVehicleRequiredTypeAlternativesOfType(int type) const
Returns the set of same-vehicle requirement alternatives for the given type.
std::vector< std::pair< int64_t, int64_t > > distance_duration
RoutingTransitCallback2 TransitCallback2
The following constraint ensures that incompatibilities and requirements between types are respected.
DecisionBuilder * MakeGuidedSlackFinalizer(const RoutingDimension *dimension, std::function< int64_t(int64_t)> initializer)
The next few members are in the public section only for testing purposes.
bool HasMaxCardinalityConstrainedDisjunctions() const
Returns true if the model contains at least one disjunction which is constrained by its max_cardinali...
int64_t fixed_cost
Contrarily to CostClass, here we need strict equivalence.
void SetFixedCostOfAllVehicles(int64_t cost)
Sets the fixed cost of all vehicle routes.
void Post() override
This method is called when the constraint is processed by the solver.
std::vector< DimensionCost > dimension_transit_evaluator_class_and_cost_coefficient
RoutingDimension * GetMutableDimension(const std::string &dimension_name) const
Returns a dimension from its name.
int64_t GetDepot() const
Returns the variable index of the first starting or ending node of all routes.
void SetCumulVarSoftLowerBound(int64_t index, int64_t lower_bound, int64_t coefficient)
Sets a soft lower bound to the cumul variable of a given variable index.
void AddSoftSameVehicleConstraint(const std::vector< int64_t > &indices, int64_t cost)
Adds a soft constraint to force a set of variable indices to be on the same vehicle.
Struct used to sort and store vehicles by their type.
int num_type_added_to_vehicle
Number of TYPE_ADDED_TO_VEHICLE and TYPE_SIMULTANEOUSLY_ADDED_AND_REMOVED node type policies seen on ...
bool HasTemporalTypeIncompatibilities() const
const std::vector< int > & GetSingleNodesOfType(int type) const
The visit doesn't have an impact on the number of types 'T' on the route, as it's (virtually) added a...
~TypeRequirementChecker() override
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...
bool HasQuadraticCostSoftSpanUpperBounds() const
SweepArranger * sweep_arranger() const
Returns the sweep arranger to be used by routing heuristics.
IntVar * SlackVar(int64_t index) const
Collection of objects used to extend the Constraint Solver library.
int evaluator_index
Index of the arc cost evaluator, registered in the RoutingModel class.
int VehicleIndex(int64_t index) const
Returns the vehicle of the given start/end index, and -1 if the given index is not a vehicle start/en...
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...
void SetBreakDistanceDurationOfVehicle(int64_t distance, int64_t duration, int vehicle)
With breaks supposed to be consecutive, this forces the distance between breaks of size at least mini...
static bool LessThan(const CostClass &a, const CostClass &b)
Comparator for STL containers and algorithms.
void AddHardTypeIncompatibility(int type1, int type2)
Incompatibilities: Two nodes with "hard" incompatible types cannot share the same route at all,...
CostClassIndex cost_class_index
The cost class of the vehicle.
void SetCumulVarPiecewiseLinearCost(int64_t index, const PiecewiseLinearFunction &cost)
Sets a piecewise linear cost on the cumul variable of a given variable index.
int64_t GetGlobalOptimizerOffset() const
bool TypeOccursOnRoute(int type) const
Returns true iff any occurrence of the given type was seen on the route, i.e.
IntVar * VehicleRouteConsideredVar(int vehicle) const
Returns the variable specifying whether or not the given vehicle route is considered for costs and co...
bool EdgeFinding(Tasks *tasks)
Does edge-finding deductions on all tasks.
const std::vector< RoutingDimension * > & GetDimensions() const
Returns all dimensions of the model.
static const char kLightElement2[]
int64_t Size() const
Returns the number of next variables in the model.
const std::vector< IntervalVar * > & GetBreakIntervalsOfVehicle(int vehicle) const
Returns the break intervals set by SetBreakIntervalsOfVehicle().
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 GetVisitType(int64_t index) const
std::vector< const SortedDisjointIntervalList * > forbidden_intervals
int64_t GetFixedCostOfVehicle(int vehicle) const
Returns the route fixed cost taken into account if the route of the vehicle is not empty,...
RoutingModel::VisitTypePolicy VisitTypePolicy
int RegisterPositiveTransitCallback(TransitCallback2 callback)
const std::vector< int64_t > & GetAmortizedQuadraticCostFactorOfVehicles() const
bool HasTemporalTypeRequirements() const
std::vector< int64_t > duration_min
const TransitCallback2 & TransitCallback(int callback_index) const
std::pair< int, bool > AddMatrixDimension(std::vector< std::vector< int64_t > > values, int64_t 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...
What follows is relevant for models with time/state dependent transits.
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...
const Assignment * SolveFromAssignmentsWithParameters(const std::vector< const Assignment * > &assignments, const RoutingSearchParameters &search_parameters, std::vector< const Assignment * > *solutions=nullptr)
Same as above but will try all assignments in order as first solutions until one succeeds.
bool IsEnd(int64_t index) const
Returns true if 'index' represents the last node of a route.
A structure to hold tasks described by their features.
bool HasSoftSpanUpperBounds() const
bool IsMatchingModel() const
Returns true if a vehicle/node matching problem is detected.
bool CheckLimit()
Returns true if the search limit has been crossed.
bool WriteAssignment(const std::string &file_name) const
Writes the current solution to a file containing an AssignmentProto.
bool ChainSpanMinDynamic(Tasks *tasks)
Computes a lower bound of the span of the chain, taking into account only the first nonchain task.
void AppendTasksFromPath(const std::vector< int64_t > &path, const TravelBounds &travel_bounds, const RoutingDimension &dimension, DisjunctivePropagator::Tasks *tasks)
RoutingVehicleClassIndex VehicleClassIndex
void AddLocalSearchFilter(LocalSearchFilter *filter)
Adds a custom local search filter to the list of filters used to speed up local search by pruning unf...
~TypeIncompatibilityChecker() override
bool IsVehicleUsed(const Assignment &assignment, int vehicle) const
Returns true if the route of 'vehicle' is non empty in 'assignment'.
TypeIncompatibilityChecker(const RoutingModel &model, bool check_hard_incompatibilities)
const Domain & start_domain() const
void InitialPropagate() override
This method performs the initial propagation of the constraint.
bool ApplyLocksToAllVehicles(const std::vector< std::vector< int64_t >> &locks, bool close_routes)
Applies lock chains to all vehicles to the next search, such that locks[p] is the lock chain for rout...
const Domain & end_domain() const
void AddVariableMinimizedByFinalizer(IntVar *var)
Adds a variable to minimize in the solution finalizer.
bool AddDimensionWithVehicleTransits(const std::vector< int > &evaluator_indices, int64_t slack_max, int64_t capacity, bool fix_start_cumul_to_zero, const std::string &name)
const std::vector< int > & GetDimensionResourceGroupIndices(const RoutingDimension *dimension) const
Returns the indices of resource groups for this dimension.
std::vector< int64_t > max_travels
Local Search Filters are used for fast neighbor pruning.
bool Precedences(Tasks *tasks)
Propagates the deductions from the chain of precedences, if there is one.
DisjunctionIndex AddDisjunction(const std::vector< int64_t > &indices, int64_t penalty=kNoPenalty, int64_t max_cardinality=1)
Adds a disjunction constraint on the indices: exactly 'max_cardinality' of the indices are active.
void SetBreakIntervalsOfVehicle(std::vector< IntervalVar * > breaks, int vehicle, int pre_travel_evaluator, int post_travel_evaluator)
Sets the breaks for a given vehicle.
void SetCumulVarSoftUpperBound(int64_t index, int64_t upper_bound, int64_t coefficient)
Sets a soft upper bound to the cumul variable of a given variable index.
const std::vector< int64_t > & vehicle_capacities() const
Returns the capacities for all vehicles.
int end_equivalence_class
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...
void AddPickupAndDeliverySets(DisjunctionIndex pickup_disjunction, DisjunctionIndex delivery_disjunction)
Same as AddPickupAndDelivery but notifying that the performed node from the disjunction of index 'pic...
int64_t GetLastPossibleLessOrEqualValueForNode(int64_t index, int64_t max_value) const
Returns the largest value outside the forbidden intervals of node 'index' that is less than or equal ...
std::pair< std::vector< int64_t >, std::vector< int64_t > > RoutingIndexPair
bool HasTypeRegulations() const
Returns true iff the model has any incompatibilities or requirements set on node types.
GlobalDimensionCumulOptimizer * GetMutableGlobalCumulOptimizer(const RoutingDimension &dimension) const
Returns the global/local dimension cumul optimizer for a given dimension, or nullptr if there is none...
const std::vector< int64_t > & GetAmortizedLinearCostFactorOfVehicles() const
Class to arrange indices by by their distance and their angles from the depot.
void InitializeCheck(int vehicle, const std::function< int64_t(int64_t)> &next_accessor)
absl::StrongVector< DimensionIndex, int64_t > dimension_start_cumuls_max
SimpleBoundCosts::BoundCost GetQuadraticCostSoftSpanUpperBoundForVehicle(int vehicle) const
IntVar * ActiveVar(int64_t index) const
Returns the active variable of the node corresponding to index.
void SetArcCostEvaluatorOfVehicle(int evaluator_index, int vehicle)
Sets the cost function for a given vehicle route.
Any precedence is accepted.
#define DCHECK_LT(val1, val2)
IntVar * TransitVar(int64_t index) const
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
std::string DebugString() const override
int64_t Start(int vehicle) const
Model inspection.
IntVar * ResourceVar(int vehicle, int resource_group) const
Returns the resource variable for the given vehicle index in the given resource group.
int64_t UnperformedPenalty(int64_t var_index) const
Get the "unperformed" penalty of a node.
const std::vector< std::unique_ptr< GlobalDimensionCumulOptimizer > > & GetGlobalDimensionCumulMPOptimizers() const
int64_t GetDisjunctionMaxCardinality(DisjunctionIndex index) const
Returns the maximum number of possible active nodes of the node disjunction of index 'index'.