 |
OR-Tools
8.1
|
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;
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_;
746 return implicit_pickup_delivery_pairs_without_alternatives_;
793 return topologically_sorted_visit_types_;
810 return has_hard_type_incompatibilities_;
813 return has_temporal_type_incompatibilities_;
826 int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
832 int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
839 int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
843 const std::vector<absl::flat_hash_set<int> >&
846 const std::vector<absl::flat_hash_set<int> >&
849 const std::vector<absl::flat_hash_set<int> >&
855 return has_same_vehicle_type_requirements_;
858 return has_temporal_type_requirements_;
888 max_active_vehicles_ = max_active_vehicles;
924 int64 quadratic_cost_factor);
927 int64 quadratic_cost_factor,
931 return linear_cost_factor_of_vehicle_;
934 return quadratic_cost_factor_of_vehicle_;
939 consider_empty_route_costs_[vehicle] = consider_costs;
944 return consider_empty_route_costs_[vehicle];
951 return first_solution_evaluator_;
956 first_solution_evaluator_ = std::move(evaluator);
991 const RoutingSearchParameters& search_parameters);
998 const Assignment*
Solve(
const Assignment* assignment =
nullptr);
1007 const RoutingSearchParameters& search_parameters,
1008 std::vector<const Assignment*>* solutions =
nullptr);
1010 const Assignment* assignment,
1011 const RoutingSearchParameters& search_parameters,
1012 std::vector<const Assignment*>* solutions =
nullptr);
1019 Assignment* target_assignment,
const RoutingModel* source_model,
1020 const Assignment* source_assignment);
1072 const std::vector<std::vector<int64>>& routes,
1073 bool ignore_inactive_indices);
1091 bool ignore_inactive_indices,
bool close_routes,
1097 std::vector<std::vector<int64>>*
const routes)
const;
1142 const Assignment* original_assignment, absl::Duration duration_limit);
1157 CHECK(filter !=
nullptr);
1159 LOG(
WARNING) <<
"Model is closed, filter addition will be ignored.";
1169 int64 End(
int vehicle)
const {
return ends_[vehicle]; }
1184 #if !defined(SWIGPYTHON)
1185 const std::vector<IntVar*>&
Nexts()
const {
return nexts_; }
1190 const std::vector<IntVar*>&
VehicleVars()
const {
return vehicle_vars_; }
1192 IntVar* NextVar(int64 index) const { return nexts_[index]; }
1200 return vehicle_active_[vehicle];
1205 return vehicle_costs_considered_[vehicle];
1216 int64 vehicle)
const;
1219 return costs_are_homogeneous_across_vehicles_;
1236 int64 cost_class_index)
const;
1241 DCHECK_LT(vehicle, cost_class_index_of_vehicle_.size());
1242 DCHECK_GE(cost_class_index_of_vehicle_[vehicle], 0);
1243 return cost_class_index_of_vehicle_[vehicle];
1249 if (cost_class_index == kCostClassIndexOfZeroCost) {
1250 return has_vehicle_with_zero_cost_class_;
1252 return cost_class_index < cost_classes_.size();
1262 return vehicle_class_index_of_vehicle_[vehicle];
1269 return same_vehicle_groups_[same_vehicle_group_[node]];
1274 return vehicle_type_container_;
1302 const std::string& dimension_to_print)
const;
1309 std::vector<std::vector<std::pair<int64, int64>>>
GetCumulBounds(
1318 DCHECK(limit_ !=
nullptr);
1319 return limit_->
Check();
1324 DCHECK(limit_ !=
nullptr);
1334 int64 Size()
const {
return nodes_ + vehicles_ - start_end_count_; }
1339 const RoutingSearchParameters& search_parameters)
const;
1341 const RoutingSearchParameters& search_parameters)
const;
1345 return automatic_first_solution_strategy_;
1355 std::function<std::vector<operations_research::IntVar*>(
RoutingModel*)>;
1383 std::vector<IntVar*> variables);
1385 DecisionBuilder* MakeSelfDependentDimensionFinalizer(
1403 enum RoutingLocalSearchOperator {
1406 LIGHT_RELOCATE_PAIR,
1414 GLOBAL_CHEAPEST_INSERTION_CLOSE_NODES_LNS,
1415 LOCAL_CHEAPEST_INSERTION_CLOSE_NODES_LNS,
1416 GLOBAL_CHEAPEST_INSERTION_PATH_LNS,
1417 LOCAL_CHEAPEST_INSERTION_PATH_LNS,
1418 RELOCATE_PATH_GLOBAL_CHEAPEST_INSERTION_INSERT_UNPERFORMED,
1419 GLOBAL_CHEAPEST_INSERTION_EXPENSIVE_CHAIN_LNS,
1420 LOCAL_CHEAPEST_INSERTION_EXPENSIVE_CHAIN_LNS,
1421 RELOCATE_EXPENSIVE_CHAIN,
1425 RELOCATE_AND_MAKE_ACTIVE,
1426 MAKE_ACTIVE_AND_RELOCATE,
1428 MAKE_CHAIN_INACTIVE,
1430 EXTENDED_SWAP_ACTIVE,
1436 EXCHANGE_RELOCATE_PAIR,
1439 LOCAL_SEARCH_OPERATOR_COUNTER
1445 template <
typename T>
1446 struct ValuedNodes {
1447 std::vector<int64> indices;
1450 struct DisjunctionValues {
1452 int64 max_cardinality;
1454 typedef ValuedNodes<DisjunctionValues> Disjunction;
1458 struct CostCacheElement {
1470 void AddNoCycleConstraintInternal();
1471 bool AddDimensionWithCapacityInternal(
1472 const std::vector<int>& evaluator_indices,
int64 slack_max,
1473 std::vector<int64> vehicle_capacities,
bool fix_start_cumul_to_zero,
1474 const std::string&
name);
1475 bool AddDimensionDependentDimensionWithVehicleCapacityInternal(
1476 const std::vector<int>& pure_transits,
1477 const std::vector<int>& dependent_transits,
1479 std::vector<int64> vehicle_capacities,
bool fix_start_cumul_to_zero,
1480 const std::string&
name);
1481 bool InitializeDimensionInternal(
1482 const std::vector<int>& evaluator_indices,
1483 const std::vector<int>& state_dependent_evaluator_indices,
1484 int64 slack_max,
bool fix_start_cumul_to_zero,
1486 DimensionIndex GetDimensionIndex(
const std::string& dimension_name)
const;
1515 void StoreDimensionCumulOptimizers(
const RoutingSearchParameters&
parameters);
1517 void ComputeCostClasses(
const RoutingSearchParameters&
parameters);
1518 void ComputeVehicleClasses();
1526 void ComputeVehicleTypes();
1536 void FinalizeVisitTypes();
1538 void TopologicallySortVisitTypes();
1541 void AppendHomogeneousArcCosts(
const RoutingSearchParameters&
parameters,
1543 std::vector<IntVar*>* cost_elements);
1544 void AppendArcCosts(
const RoutingSearchParameters&
parameters,
int node_index,
1545 std::vector<IntVar*>* cost_elements);
1546 Assignment* DoRestoreAssignment();
1548 int64 SafeGetCostClassInt64OfVehicle(
int64 vehicle)
const {
1551 : kCostClassIndexOfZeroCost)
1555 const CostClass& cost_class)
const;
1559 void AddPickupAndDeliverySetsInternal(
const std::vector<int64>& pickups,
1560 const std::vector<int64>& deliveries);
1563 IntVar* CreateSameVehicleCost(
int vehicle_index);
1566 int FindNextActive(
int index,
const std::vector<int64>& indices)
const;
1570 bool RouteCanBeUsedByVehicle(
const Assignment& assignment,
int start_index,
1579 bool ReplaceUnusedVehicle(
int unused_vehicle,
int active_vehicle,
1580 Assignment* compact_assignment)
const;
1582 void QuietCloseModel();
1583 void QuietCloseModelWithParameters(
1591 bool SolveMatchingModel(Assignment* assignment,
1594 bool AppendAssignmentIfFeasible(
1596 const Assignment& assignment,
1597 std::vector<std::unique_ptr<Assignment>>* assignments);
1599 void LogSolution(
const RoutingSearchParameters&
parameters,
1601 const std::string& description,
int64 solution_cost,
1602 int64 start_time_ms);
1605 Assignment* CompactAssignmentInternal(
const Assignment& assignment,
1606 bool check_compact_assignment)
const;
1611 std::string FindErrorInSearchParametersForModel(
1612 const RoutingSearchParameters& search_parameters)
const;
1614 void SetupSearch(
const RoutingSearchParameters& search_parameters);
1617 Assignment* GetOrCreateAssignment();
1618 Assignment* GetOrCreateTmpAssignment();
1619 RegularLimit* GetOrCreateLimit();
1620 RegularLimit* GetOrCreateLocalSearchLimit();
1621 RegularLimit* GetOrCreateLargeNeighborhoodSearchLimit();
1622 RegularLimit* GetOrCreateFirstSolutionLargeNeighborhoodSearchLimit();
1623 LocalSearchOperator* CreateInsertionOperator();
1624 LocalSearchOperator* CreateMakeInactiveOperator();
1625 void CreateNeighborhoodOperators(
const RoutingSearchParameters&
parameters);
1626 LocalSearchOperator* ConcatenateOperators(
1627 const RoutingSearchParameters& search_parameters,
1628 const std::vector<LocalSearchOperator*>& operators)
const;
1629 LocalSearchOperator* GetNeighborhoodOperators(
1630 const RoutingSearchParameters& search_parameters)
const;
1631 std::vector<LocalSearchFilterManager::FilterEvent>
1632 GetOrCreateLocalSearchFilters(
const RoutingSearchParameters&
parameters,
1633 bool filter_cost =
true);
1634 LocalSearchFilterManager* GetOrCreateLocalSearchFilterManager(
1636 std::vector<LocalSearchFilterManager::FilterEvent>
1637 GetOrCreateFeasibilityFilters(
const RoutingSearchParameters&
parameters);
1638 LocalSearchFilterManager* GetOrCreateFeasibilityFilterManager(
1640 LocalSearchFilterManager* GetOrCreateStrongFeasibilityFilterManager(
1642 DecisionBuilder* CreateSolutionFinalizer(SearchLimit* lns_limit);
1643 DecisionBuilder* CreateFinalizerForMinimizedAndMaximizedVariables();
1644 void CreateFirstSolutionDecisionBuilders(
1645 const RoutingSearchParameters& search_parameters);
1646 DecisionBuilder* GetFirstSolutionDecisionBuilder(
1647 const RoutingSearchParameters& search_parameters)
const;
1648 IntVarFilteredDecisionBuilder* GetFilteredFirstSolutionDecisionBuilderOrNull(
1649 const RoutingSearchParameters&
parameters)
const;
1650 LocalSearchPhaseParameters* CreateLocalSearchParameters(
1651 const RoutingSearchParameters& search_parameters);
1652 DecisionBuilder* CreateLocalSearchDecisionBuilder(
1653 const RoutingSearchParameters& search_parameters);
1654 void SetupDecisionBuilders(
const RoutingSearchParameters& search_parameters);
1655 void SetupMetaheuristics(
const RoutingSearchParameters& search_parameters);
1656 void SetupAssignmentCollector(
1657 const RoutingSearchParameters& search_parameters);
1658 void SetupTrace(
const RoutingSearchParameters& search_parameters);
1659 void SetupImprovementLimit(
const RoutingSearchParameters& search_parameters);
1660 void SetupSearchMonitors(
const RoutingSearchParameters& search_parameters);
1661 bool UsesLightPropagation(
1662 const RoutingSearchParameters& search_parameters)
const;
1669 void DetectImplicitPickupAndDeliveries();
1671 int GetVehicleStartClass(
int64 start)
const;
1673 void InitSameVehicleGroups(
int number_of_groups) {
1674 same_vehicle_group_.assign(
Size(), 0);
1675 same_vehicle_groups_.assign(number_of_groups, {});
1677 void SetSameVehicleGroup(
int index,
int group) {
1678 same_vehicle_group_[
index] = group;
1679 same_vehicle_groups_[group].push_back(
index);
1683 std::unique_ptr<Solver> solver_;
1686 int max_active_vehicles_;
1687 Constraint* no_cycle_constraint_ =
nullptr;
1689 std::vector<IntVar*> nexts_;
1690 std::vector<IntVar*> vehicle_vars_;
1691 std::vector<IntVar*> active_;
1693 std::vector<IntVar*> vehicle_active_;
1694 std::vector<IntVar*> vehicle_costs_considered_;
1699 std::vector<IntVar*> is_bound_to_end_;
1700 mutable RevSwitch is_bound_to_end_ct_added_;
1702 absl::flat_hash_map<std::string, DimensionIndex> dimension_name_to_index_;
1708 std::vector<std::unique_ptr<GlobalDimensionCumulOptimizer> >
1709 global_dimension_optimizers_;
1711 std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >
1712 local_dimension_optimizers_;
1713 std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >
1714 local_dimension_mp_optimizers_;
1717 std::string primary_constrained_dimension_;
1719 IntVar* cost_ =
nullptr;
1720 std::vector<int> vehicle_to_transit_cost_;
1721 std::vector<int64> fixed_cost_of_vehicle_;
1722 std::vector<CostClassIndex> cost_class_index_of_vehicle_;
1723 bool has_vehicle_with_zero_cost_class_;
1724 std::vector<int64> linear_cost_factor_of_vehicle_;
1725 std::vector<int64> quadratic_cost_factor_of_vehicle_;
1726 bool vehicle_amortized_cost_factors_set_;
1737 std::vector<bool> consider_empty_route_costs_;
1741 bool costs_are_homogeneous_across_vehicles_;
1742 bool cache_callbacks_;
1743 mutable std::vector<CostCacheElement> cost_cache_;
1744 std::vector<VehicleClassIndex> vehicle_class_index_of_vehicle_;
1748 VehicleTypeContainer vehicle_type_container_;
1749 std::function<int(
int64)> vehicle_start_class_callback_;
1752 std::vector<std::vector<DisjunctionIndex> > index_to_disjunctions_;
1754 std::vector<ValuedNodes<int64> > same_vehicle_costs_;
1757 std::vector<absl::flat_hash_set<int>> allowed_vehicles_;
1761 IndexPairs implicit_pickup_delivery_pairs_without_alternatives_;
1762 std::vector<std::pair<DisjunctionIndex, DisjunctionIndex> >
1763 pickup_delivery_disjunctions_;
1768 std::vector<std::vector<std::pair<int, int> > > index_to_pickup_index_pairs_;
1770 std::vector<std::vector<std::pair<int, int> > >
1771 index_to_delivery_index_pairs_;
1773 std::vector<PickupAndDeliveryPolicy> vehicle_pickup_delivery_policy_;
1775 std::vector<int> same_vehicle_group_;
1777 std::vector<std::vector<int>> same_vehicle_groups_;
1780 std::vector<int> index_to_visit_type_;
1782 std::vector<VisitTypePolicy> index_to_type_policy_;
1784 std::vector<std::vector<int> > single_nodes_of_type_;
1785 std::vector<std::vector<int> > pair_indices_of_type_;
1787 std::vector<absl::flat_hash_set<int> >
1788 hard_incompatible_types_per_type_index_;
1789 bool has_hard_type_incompatibilities_;
1790 std::vector<absl::flat_hash_set<int> >
1791 temporal_incompatible_types_per_type_index_;
1792 bool has_temporal_type_incompatibilities_;
1794 std::vector<std::vector<absl::flat_hash_set<int> > >
1795 same_vehicle_required_type_alternatives_per_type_index_;
1796 bool has_same_vehicle_type_requirements_;
1797 std::vector<std::vector<absl::flat_hash_set<int> > >
1798 required_type_alternatives_when_adding_type_index_;
1799 std::vector<std::vector<absl::flat_hash_set<int> > >
1800 required_type_alternatives_when_removing_type_index_;
1801 bool has_temporal_type_requirements_;
1802 absl::flat_hash_map<int, absl::flat_hash_set<VisitTypePolicy> >
1803 trivially_infeasible_visit_types_to_policies_;
1820 std::vector<std::vector<int> > topologically_sorted_visit_types_;
1822 int num_visit_types_;
1825 std::vector<int> index_to_equivalence_class_;
1826 std::vector<int> index_to_vehicle_;
1827 std::vector<int64> starts_;
1828 std::vector<int64> ends_;
1831 RoutingIndexManager manager_;
1832 int start_end_count_;
1834 bool closed_ =
false;
1836 bool enable_deep_serialization_ =
true;
1839 std::vector<DecisionBuilder*> first_solution_decision_builders_;
1840 std::vector<IntVarFilteredDecisionBuilder*>
1841 first_solution_filtered_decision_builders_;
1844 FirstSolutionStrategy::UNSET;
1845 std::vector<LocalSearchOperator*> local_search_operators_;
1846 std::vector<SearchMonitor*> monitors_;
1847 SolutionCollector* collect_assignments_ =
nullptr;
1848 SolutionCollector* collect_one_assignment_ =
nullptr;
1849 SolutionCollector* packed_dimensions_assignment_collector_ =
nullptr;
1850 DecisionBuilder* solve_db_ =
nullptr;
1851 DecisionBuilder* improve_db_ =
nullptr;
1852 DecisionBuilder* restore_assignment_ =
nullptr;
1853 DecisionBuilder* restore_tmp_assignment_ =
nullptr;
1854 Assignment* assignment_ =
nullptr;
1855 Assignment* preassignment_ =
nullptr;
1856 Assignment* tmp_assignment_ =
nullptr;
1857 std::vector<IntVar*> extra_vars_;
1858 std::vector<IntervalVar*> extra_intervals_;
1859 std::vector<LocalSearchOperator*> extra_operators_;
1860 LocalSearchFilterManager* local_search_filter_manager_ =
nullptr;
1861 LocalSearchFilterManager* feasibility_filter_manager_ =
nullptr;
1862 LocalSearchFilterManager* strong_feasibility_filter_manager_ =
nullptr;
1863 std::vector<LocalSearchFilterManager::FilterEvent> extra_filters_;
1865 std::vector<std::pair<IntVar*, int64>> finalizer_variable_cost_pairs_;
1866 std::vector<std::pair<IntVar*, int64>> finalizer_variable_target_pairs_;
1867 absl::flat_hash_map<IntVar*, int> finalizer_variable_cost_index_;
1868 absl::flat_hash_set<IntVar*> finalizer_variable_target_set_;
1869 std::unique_ptr<SweepArranger> sweep_arranger_;
1872 RegularLimit* limit_ =
nullptr;
1873 RegularLimit* ls_limit_ =
nullptr;
1874 RegularLimit* lns_limit_ =
nullptr;
1875 RegularLimit* first_solution_lns_limit_ =
nullptr;
1877 typedef std::pair<int64, int64> CacheKey;
1878 typedef absl::flat_hash_map<CacheKey, int64> TransitCallbackCache;
1879 typedef absl::flat_hash_map<CacheKey, StateDependentTransit>
1880 StateDependentTransitCallbackCache;
1882 std::vector<TransitCallback1> unary_transit_evaluators_;
1883 std::vector<TransitCallback2> transit_evaluators_;
1894 std::vector<bool> is_transit_evaluator_positive_;
1895 std::vector<VariableIndexEvaluator2> state_dependent_transit_evaluators_;
1896 std::vector<std::unique_ptr<StateDependentTransitCallbackCache>>
1897 state_dependent_transit_evaluators_cache_;
1986 std::vector<int> tasks_by_start_min_;
1987 std::vector<int> tasks_by_end_max_;
1988 std::vector<int> event_of_task_;
1989 std::vector<int> nonchain_tasks_by_start_max_;
1991 std::vector<int64> total_duration_before_;
2009 std::vector<int64>* values);
2013 #endif // !defined(SWIG)
2029 return "GlobalVehicleBreaksConstraint";
2032 void Post()
override;
2036 void PropagateNode(
int node);
2037 void PropagateVehicle(
int vehicle);
2038 void PropagateMaxBreakDistance(
int vehicle);
2042 std::vector<Demon*> vehicle_demons_;
2043 std::vector<int64> path_;
2049 void FillPartialPathOfVehicle(
int vehicle);
2050 void FillPathTravels(
const std::vector<int64>& path);
2062 class TaskTranslator {
2066 before_start_(before_start),
2067 after_start_(after_start) {}
2072 if (start_ !=
nullptr) {
2074 }
else if (interval_ !=
nullptr) {
2075 interval_->SetStartMin(
value);
2079 if (start_ !=
nullptr) {
2081 }
else if (interval_ !=
nullptr) {
2082 interval_->SetStartMax(
value);
2086 if (interval_ !=
nullptr) {
2087 interval_->SetDurationMin(
value);
2091 if (start_ !=
nullptr) {
2093 }
else if (interval_ !=
nullptr) {
2094 interval_->SetEndMin(
value);
2098 if (start_ !=
nullptr) {
2100 }
else if (interval_ !=
nullptr) {
2101 interval_->SetEndMax(
value);
2106 IntVar* start_ =
nullptr;
2107 int64 before_start_;
2109 IntervalVar* interval_ =
nullptr;
2113 std::vector<TaskTranslator> task_translators_;
2116 DisjunctivePropagator disjunctive_propagator_;
2117 DisjunctivePropagator::Tasks tasks_;
2120 TravelBounds travel_bounds_;
2129 const std::function<
int64(
int64)>& next_accessor);
2168 const std::function<
int64(
int64)>& next_accessor);
2178 std::vector<TypePolicyOccurrence> occurrences_of_type_;
2179 std::vector<int64> current_route_visits_;
2186 bool check_hard_incompatibilities);
2190 bool HasRegulationsToCheck()
const override;
2191 bool CheckTypeRegulations(
int type,
VisitTypePolicy policy,
int pos)
override;
2195 bool check_hard_incompatibilities_;
2206 bool HasRegulationsToCheck()
const override;
2207 void OnInitializeCheck()
override {
2208 types_with_same_vehicle_requirements_on_route_.clear();
2213 bool CheckRequiredTypesCurrentlyOnRoute(
2214 const std::vector<absl::flat_hash_set<int> >& required_type_alternatives,
2217 bool CheckTypeRegulations(
int type,
VisitTypePolicy policy,
int pos)
override;
2218 bool FinalizeCheck()
const override;
2220 absl::flat_hash_set<int> types_with_same_vehicle_requirements_on_route_;
2267 void Post()
override;
2271 void PropagateNodeRegulations(
int node);
2272 void CheckRegulationsOnVehicle(
int vehicle);
2277 std::vector<Demon*> vehicle_demons_;
2299 : bound_costs_(num_bounds, default_bound_cost) {}
2302 int Size() {
return bound_costs_.size(); }
2307 std::vector<BoundCost> bound_costs_;
2309 #endif // !defined SWIG
2343 int64 vehicle_class)
const {
2344 return model_->TransitCallback(class_evaluators_[vehicle_class])(from_index,
2354 #if !defined(SWIGPYTHON)
2355 const std::vector<IntVar*>&
cumuls()
const {
return cumuls_; }
2359 const std::vector<IntVar*>&
transits()
const {
return transits_; }
2360 const std::vector<IntVar*>&
slacks()
const {
return slacks_; }
2361 #if !defined(SWIGCSHARP) && !defined(SWIGJAVA)
2364 return forbidden_intervals_;
2369 int64 max_value)
const;
2373 int64 min_value)
const {
2376 forbidden_intervals_[
index];
2377 const auto first_forbidden_interval_it =
2380 min_value >= first_forbidden_interval_it->start) {
2382 return CapAdd(first_forbidden_interval_it->end, 1);
2392 int64 max_value)
const {
2395 forbidden_intervals_[
index];
2396 const auto last_forbidden_interval_it =
2399 max_value <= last_forbidden_interval_it->end) {
2401 return CapSub(last_forbidden_interval_it->start, 1);
2408 return vehicle_capacities_;
2413 return model_->TransitCallback(
2414 class_evaluators_[vehicle_to_class_[vehicle]]);
2420 int vehicle)
const {
2421 return model_->UnaryTransitCallbackOrNull(
2422 class_evaluators_[vehicle_to_class_[vehicle]]);
2427 return model()->is_transit_evaluator_positive_
2428 [class_evaluators_[vehicle_to_class_[vehicle]]];
2433 void SetSpanUpperBoundForVehicle(int64 upper_bound, int vehicle);
2529 #if !defined(SWIGPYTHON)
2531 int pre_travel_evaluator,
2532 int post_travel_evaluator);
2533 #endif // !defined(SWIGPYTHON)
2537 std::vector<int64> node_visit_transits);
2550 #if !defined(SWIGPYTHON)
2554 std::vector<IntervalVar*> breaks,
int vehicle,
2555 std::vector<int64> node_visit_transits,
2564 const std::vector<std::pair<int64, int64> >&
2568 int GetPreTravelEvaluatorOfVehicle(int vehicle) const;
2583 const std::string&
name()
const {
return name_; }
2588 return path_precedence_graph_;
2609 int delivery)
const;
2618 node_precedences_.push_back(precedence);
2621 return node_precedences_;
2630 return vehicle_span_upper_bounds_[vehicle];
2634 return vehicle_span_upper_bounds_;
2638 return vehicle_span_cost_coefficients_[vehicle];
2642 return vehicle_span_cost_coefficients_;
2646 return global_span_cost_coefficient_;
2651 return global_optimizer_offset_;
2654 if (vehicle >= local_optimizer_offset_for_vehicle_.size()) {
2657 DCHECK_GE(local_optimizer_offset_for_vehicle_[vehicle], 0);
2658 return local_optimizer_offset_for_vehicle_[vehicle];
2666 vehicle_soft_span_upper_bound_ = absl::make_unique<SimpleBoundCosts>(
2669 vehicle_soft_span_upper_bound_->bound_cost(vehicle) = bound_cost;
2672 return vehicle_soft_span_upper_bound_ !=
nullptr;
2675 int vehicle)
const {
2677 return vehicle_soft_span_upper_bound_->bound_cost(vehicle);
2684 vehicle_quadratic_cost_soft_span_upper_bound_ =
2685 absl::make_unique<SimpleBoundCosts>(
2688 vehicle_quadratic_cost_soft_span_upper_bound_->bound_cost(vehicle) =
2692 return vehicle_quadratic_cost_soft_span_upper_bound_ !=
nullptr;
2695 int vehicle)
const {
2697 return vehicle_quadratic_cost_soft_span_upper_bound_->bound_cost(vehicle);
2708 struct PiecewiseLinearCost {
2709 PiecewiseLinearCost() :
var(nullptr),
cost(nullptr) {}
2711 std::unique_ptr<PiecewiseLinearFunction>
cost;
2716 const std::string&
name,
2719 const std::string&
name, SelfBased);
2720 void Initialize(
const std::vector<int>& transit_evaluators,
2721 const std::vector<int>& state_dependent_transit_evaluators,
2723 void InitializeCumuls();
2724 void InitializeTransits(
2725 const std::vector<int>& transit_evaluators,
2726 const std::vector<int>& state_dependent_transit_evaluators,
2728 void InitializeTransitVariables(
int64 slack_max);
2730 void SetupCumulVarSoftUpperBoundCosts(
2731 std::vector<IntVar*>* cost_elements)
const;
2733 void SetupCumulVarSoftLowerBoundCosts(
2734 std::vector<IntVar*>* cost_elements)
const;
2735 void SetupCumulVarPiecewiseLinearCosts(
2736 std::vector<IntVar*>* cost_elements)
const;
2739 void SetupGlobalSpanCost(std::vector<IntVar*>* cost_elements)
const;
2740 void SetupSlackAndDependentTransitCosts()
const;
2742 void CloseModel(
bool use_light_propagation);
2744 void SetOffsetForGlobalOptimizer(
int64 offset) {
2748 void SetVehicleOffsetsForLocalOptimizer(std::vector<int64> offsets) {
2750 std::transform(offsets.begin(), offsets.end(), offsets.begin(),
2751 [](
int64 offset) { return std::max(Zero(), offset); });
2752 local_optimizer_offset_for_vehicle_ = std::move(offsets);
2755 std::vector<IntVar*> cumuls_;
2756 std::vector<SortedDisjointIntervalList> forbidden_intervals_;
2757 std::vector<IntVar*> capacity_vars_;
2758 const std::vector<int64> vehicle_capacities_;
2759 std::vector<IntVar*> transits_;
2760 std::vector<IntVar*> fixed_transits_;
2763 std::vector<int> class_evaluators_;
2764 std::vector<int64> vehicle_to_class_;
2766 ReverseArcListGraph<int, int> path_precedence_graph_;
2772 std::vector<NodePrecedence> node_precedences_;
2777 const RoutingDimension*
const base_dimension_;
2782 std::vector<int> state_dependent_class_evaluators_;
2783 std::vector<int64> state_dependent_vehicle_to_class_;
2788 std::vector<PickupToDeliveryLimitFunction>
2789 pickup_to_delivery_limits_per_pair_index_;
2792 bool break_constraints_are_initialized_ =
false;
2794 std::vector<std::vector<IntervalVar*> > vehicle_break_intervals_;
2795 std::vector<std::vector<std::pair<int64, int64> > >
2796 vehicle_break_distance_duration_;
2801 std::vector<int> vehicle_pre_travel_evaluators_;
2802 std::vector<int> vehicle_post_travel_evaluators_;
2804 std::vector<IntVar*> slacks_;
2805 std::vector<IntVar*> dependent_transits_;
2806 std::vector<int64> vehicle_span_upper_bounds_;
2807 int64 global_span_cost_coefficient_;
2808 std::vector<int64> vehicle_span_cost_coefficients_;
2809 std::vector<SoftBound> cumul_var_soft_upper_bound_;
2810 std::vector<SoftBound> cumul_var_soft_lower_bound_;
2811 std::vector<PiecewiseLinearCost> cumul_var_piecewise_linear_cost_;
2813 const std::string name_;
2814 int64 global_optimizer_offset_;
2815 std::vector<int64> local_optimizer_offset_for_vehicle_;
2817 std::unique_ptr<SimpleBoundCosts> vehicle_soft_span_upper_bound_;
2818 std::unique_ptr<SimpleBoundCosts>
2819 vehicle_quadratic_cost_soft_span_upper_bound_;
2823 const std::vector<RoutingDimension*>& dimensions,
2824 const RoutingSearchParameters&
parameters,
bool filter_objective_cost,
2825 std::vector<LocalSearchFilterManager::FilterEvent>* filters);
2835 explicit SweepArranger(
const std::vector<std::pair<int64, int64>>& points);
2841 std::vector<int> coordinates_;
2851 std::vector<IntVar*> variables,
2852 std::vector<int64> targets);
2861 : vehicle_type_container_(&vehicle_type_container) {}
2865 int Type(
int vehicle)
const {
return vehicle_type_container_->
Type(vehicle); }
2868 sorted_vehicle_classes_per_type_ =
2870 const std::vector<std::deque<int>>& vehicles_per_class =
2872 vehicles_per_vehicle_class_.resize(vehicles_per_class.size());
2873 for (
int i = 0; i < vehicles_per_vehicle_class_.size(); i++) {
2874 vehicles_per_vehicle_class_[i].resize(vehicles_per_class[i].size());
2875 std::copy(vehicles_per_class[i].begin(), vehicles_per_class[i].end(),
2876 vehicles_per_vehicle_class_[i].begin());
2882 const std::set<VehicleClassEntry>& vehicle_classes =
2883 sorted_vehicle_classes_per_type_[type];
2884 if (vehicle_classes.empty()) {
2887 const int vehicle_class = (vehicle_classes.begin())->vehicle_class;
2888 DCHECK(!vehicles_per_vehicle_class_[vehicle_class].empty());
2889 return vehicles_per_vehicle_class_[vehicle_class][0];
2894 std::vector<int>& vehicles = vehicles_per_vehicle_class_[vehicle_class];
2895 if (vehicles.empty()) {
2898 std::set<VehicleClassEntry>& vehicle_classes =
2899 sorted_vehicle_classes_per_type_[
Type(vehicle)];
2900 const auto& insertion =
2901 vehicle_classes.insert({vehicle_class, fixed_cost});
2902 DCHECK(insertion.second);
2904 vehicles.push_back(vehicle);
2913 int type, std::function<
bool(
int)> vehicle_is_compatible);
2916 using VehicleClassEntry =
2920 std::vector<std::set<VehicleClassEntry> > sorted_vehicle_classes_per_type_;
2921 std::vector<std::vector<int> > vehicles_per_vehicle_class_;
2944 std::unique_ptr<IntVarFilteredHeuristic> heuristic);
2957 const std::unique_ptr<IntVarFilteredHeuristic> heuristic_;
2977 virtual std::string
DebugString()
const {
return "IntVarFilteredHeuristic"; }
2995 if (!is_in_delta_[
index]) {
2997 delta_indices_.push_back(
index);
2998 is_in_delta_[
index] =
true;
3014 int Size()
const {
return vars_.size(); }
3025 bool FilterAccept();
3028 const std::vector<IntVar*> vars_;
3030 std::vector<int> delta_indices_;
3031 std::vector<bool> is_in_delta_;
3035 int64 number_of_decisions_;
3036 int64 number_of_rejects_;
3047 const std::function<
int64(
int64)>& next_accessor);
3071 bool InitializeSolution()
override;
3074 std::vector<int64> start_chain_ends_;
3075 std::vector<int64> end_chain_starts_;
3083 std::function<
int64(
int64)> penalty_evaluator,
3106 std::vector<std::vector<StartEndValue> >
3113 template <
class Queue>
3115 std::vector<std::vector<StartEndValue> >* start_end_distances_per_node,
3116 Queue* priority_queue);
3130 std::vector<ValuedPosition>* valued_positions);
3139 int64 insert_before,
3182 std::function<
int64(
int64)> penalty_evaluator,
3188 return "GlobalCheapestInsertionFilteredHeuristic";
3194 typedef absl::flat_hash_set<PairEntry*> PairEntries;
3195 typedef absl::flat_hash_set<NodeEntry*> NodeEntries;
3203 void InsertPairsAndNodesByRequirementTopologicalOrder();
3211 void InsertPairs(
const std::vector<int>& pair_indices);
3220 void InsertNodesOnRoutes(
const std::vector<int>& nodes,
3221 const absl::flat_hash_set<int>& vehicles);
3228 void SequentialInsertNodes(
const std::vector<int>& nodes);
3233 void DetectUsedVehicles(std::vector<bool>* is_vehicle_used,
3234 std::vector<int>* unused_vehicles,
3235 absl::flat_hash_set<int>* used_vehicles);
3240 void InsertFarthestNodesAsSeeds();
3250 template <
class Queue>
3252 std::vector<std::vector<StartEndValue>>* start_end_distances_per_node,
3253 Queue* priority_queue, std::vector<bool>* is_vehicle_used);
3258 void InitializePairPositions(
3259 const std::vector<int>& pair_indices,
3261 std::vector<PairEntries>* pickup_to_entries,
3262 std::vector<PairEntries>* delivery_to_entries);
3268 void InitializeInsertionEntriesPerformingPair(
3271 std::vector<PairEntries>* pickup_to_entries,
3272 std::vector<PairEntries>* delivery_to_entries);
3275 void UpdatePairPositions(
const std::vector<int>& pair_indices,
int vehicle,
3278 std::vector<PairEntries>* pickup_to_entries,
3279 std::vector<PairEntries>* delivery_to_entries) {
3280 UpdatePickupPositions(pair_indices, vehicle, insert_after, priority_queue,
3281 pickup_to_entries, delivery_to_entries);
3282 UpdateDeliveryPositions(pair_indices, vehicle, insert_after, priority_queue,
3283 pickup_to_entries, delivery_to_entries);
3287 void UpdatePickupPositions(
const std::vector<int>& pair_indices,
int vehicle,
3288 int64 pickup_insert_after,
3290 std::vector<PairEntries>* pickup_to_entries,
3291 std::vector<PairEntries>* delivery_to_entries);
3294 void UpdateDeliveryPositions(
3295 const std::vector<int>& pair_indices,
int vehicle,
3296 int64 delivery_insert_after,
3298 std::vector<PairEntries>* pickup_to_entries,
3299 std::vector<PairEntries>* delivery_to_entries);
3302 void DeletePairEntry(PairEntry* entry,
3304 std::vector<PairEntries>* pickup_to_entries,
3305 std::vector<PairEntries>* delivery_to_entries);
3308 void InitializePositions(
const std::vector<int>& nodes,
3310 std::vector<NodeEntries>* position_to_node_entries,
3311 const absl::flat_hash_set<int>& vehicles);
3317 void InitializeInsertionEntriesPerformingNode(
3318 int64 node,
int64 penalty,
const absl::flat_hash_set<int>& vehicles,
3320 std::vector<NodeEntries>* position_to_node_entries);
3323 void UpdatePositions(
const std::vector<int>& nodes,
int vehicle,
3326 std::vector<NodeEntries>* node_entries);
3329 void DeleteNodeEntry(NodeEntry* entry,
3331 std::vector<NodeEntries>* node_entries);
3335 void ComputeNeighborhoods();
3339 bool IsNeighborForCostClass(
int cost_class,
int64 node_index,
3340 int64 neighbor_index)
const;
3343 const std::vector<int64>& GetNeighborsOfNodeForCostClass(
3344 int cost_class,
int64 node_index)
const {
3347 : node_index_to_neighbors_by_cost_class_[node_index][cost_class]
3348 ->PositionsSetAtLeastOnce();
3351 void ResetVehicleIndices()
override {
3352 node_index_to_vehicle_.assign(node_index_to_vehicle_.size(), -1);
3355 void SetVehicleIndex(
int64 node,
int vehicle)
override {
3356 DCHECK_LT(node, node_index_to_vehicle_.size());
3357 node_index_to_vehicle_[node] = vehicle;
3362 bool CheckVehicleIndices()
const;
3364 GlobalCheapestInsertionParameters gci_params_;
3366 std::vector<int> node_index_to_vehicle_;
3369 std::vector<std::vector<std::unique_ptr<SparseBitset<int64> > > >
3370 node_index_to_neighbors_by_cost_class_;
3376 std::vector<int64> all_nodes_;
3394 return "LocalCheapestInsertionFilteredHeuristic";
3403 void ComputeEvaluatorSortedPositions(
int64 node,
3404 std::vector<int64>* sorted_positions);
3409 void ComputeEvaluatorSortedPositionsOnRouteAfter(
3411 std::vector<int64>* sorted_positions);
3413 std::vector<std::vector<StartEndValue>> start_end_distances_per_node_;
3426 class PartialRoutesAndLargeVehicleIndicesFirst {
3428 explicit PartialRoutesAndLargeVehicleIndicesFirst(
3430 : builder_(builder) {}
3431 bool operator()(
int vehicle1,
int vehicle2)
const;
3437 template <
typename Iterator>
3438 std::vector<int64> GetPossibleNextsFromIterator(
int64 node, Iterator start,
3439 Iterator end)
const {
3441 std::vector<int64> nexts;
3442 for (Iterator it = start; it != end; ++it) {
3445 nexts.push_back(
next);
3451 virtual void SortSuccessors(
int64 node, std::vector<int64>* successors) = 0;
3453 const std::vector<int64>& successors) = 0;
3467 return "EvaluatorCheapestAdditionFilteredHeuristic";
3472 void SortSuccessors(
int64 node, std::vector<int64>* successors)
override;
3474 const std::vector<int64>& successors)
override;
3490 return "ComparatorCheapestAdditionFilteredHeuristic";
3495 void SortSuccessors(
int64 node, std::vector<int64>* successors)
override;
3497 const std::vector<int64>& successors)
override;
3537 template <
typename S>
3546 return saving.second / size_squared_;
3550 return (saving.second % size_squared_) /
Size();
3554 return (saving.second % size_squared_) %
Size();
3582 void AddSymmetricArcsToAdjacencyLists(
3583 std::vector<std::vector<int64> >* adjacency_lists);
3592 void ComputeSavings();
3594 Saving BuildSaving(
int64 saving,
int vehicle_type,
int before_node,
3595 int after_node)
const {
3596 return std::make_pair(saving, vehicle_type * size_squared_ +
3597 before_node *
Size() + after_node);
3603 int64 MaxNumNeighborsPerNode(
int num_vehicle_types)
const;
3606 const SavingsParameters savings_params_;
3607 int64 size_squared_;
3621 return "SequentialSavingsFilteredHeuristic";
3629 void BuildRoutesFromSavings()
override;
3630 double ExtraSavingsMemoryMultiplicativeFactor()
const override {
return 1.0; }
3642 return "ParallelSavingsFilteredHeuristic";
3656 void BuildRoutesFromSavings()
override;
3658 double ExtraSavingsMemoryMultiplicativeFactor()
const override {
return 2.0; }
3664 void MergeRoutes(
int first_vehicle,
int second_vehicle,
int64 before_node,
3668 std::vector<int64> first_node_on_route_;
3669 std::vector<int64> last_node_on_route_;
3673 std::vector<int> vehicle_of_first_or_last_node_;
3684 bool use_minimum_matching);
3688 return "ChristofidesFilteredHeuristic";
3692 const bool use_minimum_matching_;
3701 const RoutingSearchParameters& search_parameters,
3702 const Assignment* initial_solution,
3703 Assignment* solution);
3709 BasePathFilter(
const std::vector<IntVar*>& nexts,
int next_domain_size);
3712 int64 objective_min,
int64 objective_max)
override;
3736 enum Status { UNKNOWN, ENABLED, DISABLED };
3738 virtual bool DisableFiltering()
const {
return false; }
3739 virtual void OnBeforeSynchronizePaths() {}
3740 virtual void OnAfterSynchronizePaths() {}
3741 virtual void OnSynchronizePathFromStart(
int64 start) {}
3742 virtual void InitializeAcceptPath() {}
3743 virtual bool AcceptPath(
int64 path_start,
int64 chain_start,
3744 int64 chain_end) = 0;
3745 virtual bool FinalizeAcceptPath(
const Assignment*
delta,
int64 objective_min,
3746 int64 objective_max) {
3750 void ComputePathStarts(std::vector<int64>* path_starts,
3751 std::vector<int>* index_to_path);
3752 bool HavePathsChanged();
3753 void SynchronizeFullAssignment();
3754 void UpdateAllRanks();
3755 void UpdatePathRanksFromStart(
int start);
3757 std::vector<int64> node_path_starts_;
3758 std::vector<int64> starts_;
3759 std::vector<int> paths_;
3760 SparseBitset<int64> new_synchronized_unperformed_nodes_;
3761 std::vector<int64> new_nexts_;
3762 std::vector<int> delta_touched_;
3763 SparseBitset<> touched_paths_;
3765 std::vector<std::pair<int64, int64> > touched_path_chain_start_ends_;
3767 std::vector<int> ranks_;
3787 std::string
DebugString()
const override {
return "CPFeasibilityFilter"; }
3789 int64 objective_min,
int64 objective_max)
override;
3795 static const int64 kUnassigned;
3806 const RoutingModel& routing_model);
3808 const RoutingModel& routing_model);
3810 const RoutingModel& routing_model);
3812 const RoutingModel& routing_model);
3814 const std::vector<RoutingDimension*>& dimensions,
3815 const RoutingSearchParameters&
parameters,
bool filter_objective_cost,
3816 std::vector<LocalSearchFilterManager::FilterEvent>* filters);
3818 const PathState* path_state,
3819 const std::vector<RoutingDimension*>& dimensions,
3820 std::vector<LocalSearchFilterManager::FilterEvent>* filters);
3822 const RoutingDimension& dimension,
3824 bool propagate_own_objective_value,
bool filter_objective_cost,
3825 bool can_use_lp =
true);
3827 const RoutingDimension& dimension);
3829 GlobalDimensionCumulOptimizer* optimizer,
bool filter_objective_cost);
3832 const std::vector<RoutingModel::PickupAndDeliveryPolicy>& vehicle_policies);
3834 const RoutingModel& routing_model);
3836 const RoutingModel& routing_model,
const RoutingDimension& dimension);
3841 #endif // OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_H_
std::function< StateDependentTransit(int64, int64)> VariableIndexEvaluator2
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
void SetPrimaryConstrainedDimension(const std::string &dimension_name)
Set the given dimension as "primary constrained".
Decision * Next(Solver *solver) override
This is the main method of the decision builder class.
friend class RoutingModel
TypeRegulationsConstraint(const RoutingModel &model)
The class IntVar is a subset of IntExpr.
const absl::flat_hash_set< int > & GetHardTypeIncompatibilitiesOfType(int type) const
Returns visit types incompatible with a given type.
bool operator<(const DimensionCost &cost) const
static const DisjunctionIndex kNoDisjunction
Constant used to express the "no disjunction" index, returned when a node does not appear in any disj...
virtual ~IntVarFilteredHeuristic()
void AddHardTypeIncompatibility(int type1, int type2)
Incompatibilities: Two nodes with "hard" incompatible types cannot share the same route at all,...
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.
std::vector< int64 > pre_travels
RoutingVehicleClassIndex VehicleClassIndex
bool Check() override
This method is called to check the status of the limit.
void InsertBetween(int64 node, int64 predecessor, int64 successor)
Inserts 'node' just after 'predecessor', and just before 'successor', resulting in the following subs...
double neighbors_ratio
If neighbors_ratio < 1 then for each node only this ratio of its neighbors leading to the smallest ar...
std::vector< RoutingDimension * > GetDimensionsWithSoftOrSpanCosts() const
Returns dimensions with soft or vehicle span costs.
RoutingTransitCallback1 TransitCallback1
Filter-based heuristic dedicated to routing.
The following constraint ensures that incompatibilities and requirements between types are respected.
bool IsVarSynced(int index) const
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.
std::function< int64(int64, int64)> IndexEvaluator2
int64 transit_evaluator_class
void IgnoreDisjunctionsAlreadyForcedToZero()
SPECIAL: Makes the solver ignore all the disjunctions whose active variables are all trivially zero (...
const std::vector< std::vector< int > > & GetTopologicallySortedVisitTypes() const
IntVarLocalSearchFilter * MakeCPFeasibilityFilter(RoutingModel *routing_model)
@ PICKUP_AND_DELIVERY_NO_ORDER
Any precedence is accepted.
std::vector< std::deque< int > > vehicles_per_vehicle_class
bool EdgeFinding(Tasks *tasks)
Does edge-finding deductions on all tasks.
int64 GetAfterNodeFromSaving(const Saving &saving) const
Returns the "after node" from a saving.
void SetSweepArranger(SweepArranger *sweep_arranger)
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...
bool DistanceDuration(Tasks *tasks)
Propagates distance_duration constraints, if any.
int RegisterUnaryTransitCallback(TransitCallback1 callback)
Registers 'callback' and returns its index.
int vehicles() const
Returns the number of vehicle routes in the model.
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.
Assignment *const assignment_
@ 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...
#define DCHECK_LT(val1, val2)
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...
double arc_coefficient
arc_coefficient is a strictly positive parameter indicating the coefficient of the arc being consider...
const std::vector< IntVar * > & fixed_transits() const
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)...
int64 CapSub(int64 x, int64 y)
Constraint * MakePathSpansAndTotalSlacks(const RoutingDimension *dimension, std::vector< IntVar * > spans, std::vector< IntVar * > total_slacks)
For every vehicle of the routing model:
bool HasQuadraticCostSoftSpanUpperBounds() const
const std::vector< int64 > & GetTouchedPathStarts() const
const IntContainer & IntVarContainer() const
int GetVehicleClassesCount() const
Returns the number of different vehicle classes in the model.
int64 GetCumulVarSoftLowerBoundCoefficient(int64 index) const
Returns the cost coefficient of the soft lower bound of a cumul variable for a given variable index.
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...
SweepArranger * sweep_arranger() const
Returns the sweep arranger to be used by routing heuristics.
int64 GetDepot() const
Returns the variable index of the first starting or ending node of all routes.
void ArrangeIndices(std::vector< int64 > *indices)
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...
std::string DebugString() const override
RoutingTransitCallback2 TransitCallback2
std::string DebugString() const override
const RoutingDimension & GetDimensionOrDie(const std::string &dimension_name) const
Returns a dimension from its name. Dies if the dimension does not exist.
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 ...
bool ForbiddenIntervals(Tasks *tasks)
Tasks might have holes in their domain, this enforces such holes.
void SetAmortizedCostFactorsOfVehicle(int64 linear_cost_factor, int64 quadratic_cost_factor, int vehicle)
Sets the linear and quadratic cost factor of the given vehicle.
bool AddConstantDimension(int64 value, int64 capacity, bool fix_start_cumul_to_zero, const std::string &name)
int GetVisitType(int64 index) const
std::function< int64(int64)> RoutingTransitCallback1
Christofides addition heuristic.
bool DetectablePrecedencesWithChain(Tasks *tasks)
Does detectable precedences deductions on tasks in the chain precedence, taking the time windows of n...
int Type(int vehicle) const
int GetVehicleOfType(int type) const
std::vector< std::set< VehicleClassEntry > > sorted_vehicle_classes_per_type
int evaluator_index
Index of the arc cost evaluator, registered in the RoutingModel class.
void InitialPropagate() override
This method performs the initial propagation of the constraint.
const std::vector< int64 > & GetNewSynchronizedUnperformedNodes() const
int64 number_of_rejects() const
~CheapestAdditionFilteredHeuristic() override
~GlobalCheapestInsertionFilteredHeuristic() override
void OnSynchronize(const Assignment *delta) override
IntVar * ActiveVehicleVar(int vehicle) const
Returns the active variable of the vehicle.
int RegisterPositiveTransitCallback(TransitCallback2 callback)
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...
bool Contains(int64 index) const
Returns true if the variable of index 'index' is in the current solution.
virtual std::string DebugString() const
bool HasBreakConstraints() const
Returns true if any break interval or break distance was defined.
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...
void FillPathEvaluation(const std::vector< int64 > &path, const RoutingModel::TransitCallback2 &evaluator, std::vector< int64 > *values)
void SetArcCostEvaluatorOfVehicle(int evaluator_index, int vehicle)
Sets the cost function for a given vehicle route.
SweepArranger(const std::vector< std::pair< int64, int64 >> &points)
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 * (...
static const char kRemoveValues[]
int64 fixed_cost
Contrarily to CostClass, here we need strict equivalence.
bool HasVehicleWithCostClassIndex(CostClassIndex cost_class_index) const
Returns true iff the model contains a vehicle with the given cost_class_index.
ComparatorCheapestAdditionFilteredHeuristic(RoutingModel *model, Solver::VariableValueComparator comparator, LocalSearchFilterManager *filter_manager)
Takes ownership of evaluator.
const std::vector< int > & GetSingleNodesOfType(int type) const
IntVar * FixedTransitVar(int64 index) const
int64 GetNumberOfRejectsInFirstSolution(const RoutingSearchParameters &search_parameters) const
IntVarLocalSearchFilter * MakeTypeRegulationsFilter(const RoutingModel &routing_model)
VisitTypePolicy GetVisitTypePolicy(int64 index) const
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)
CheapestAdditionFilteredHeuristic(RoutingModel *model, LocalSearchFilterManager *filter_manager)
void AppendLightWeightDimensionFilters(const PathState *path_state, const std::vector< RoutingDimension * > &dimensions, std::vector< LocalSearchFilterManager::FilterEvent > *filters)
const std::vector< int64 > & vehicle_span_cost_coefficients() const
PickupAndDeliveryPolicy GetPickupAndDeliveryPolicyOfVehicle(int vehicle) const
int64 GetSavingValue(const Saving &saving) const
Returns the saving value from a saving.
const RoutingModel::TransitCallback1 & GetUnaryTransitEvaluator(int vehicle) const
Returns the unary callback evaluating the transit value between two node indices for a given vehicle.
const PiecewiseLinearFunction * GetCumulVarPiecewiseLinearCost(int64 index) const
Returns the piecewise linear cost of a cumul variable for a given variable index.
const std::vector< IntVar * > & VehicleVars() const
Returns all vehicle variables of the model, such that VehicleVars(i) is the vehicle variable of the n...
std::function< int64(int, int)> PickupToDeliveryLimitFunction
Limits, in terms of maximum difference between the cumul variables, between the pickup and delivery a...
Class to arrange indices by by their distance and their angles from the depot.
virtual bool InitializeSolution()
Virtual method to initialize the solution.
@ PICKUP_AND_DELIVERY_LIFO
Deliveries must be performed in reverse order of pickups.
std::function< std::vector< operations_research::IntVar * >(RoutingModel *)> GetTabuVarsCallback
Sets the callback returning the variable to use for the Tabu Search metaheuristic.
BoundCost bound_cost(int element) const
int GetNumberOfDisjunctions() const
Returns the number of node disjunctions in the model.
LocalDimensionCumulOptimizer * GetMutableLocalCumulMPOptimizer(const RoutingDimension &dimension) const
const IndexPairs & GetImplicitUniquePickupAndDeliveryPairs() const
Returns implicit pickup and delivery pairs currently in the model.
bool operator<(const VehicleClassEntry &other) const
friend class RoutingDimension
const std::vector< std::pair< int64, int64 > > & GetBreakDistanceDurationOfVehicle(int vehicle) const
Returns the pairs (distance, duration) specified by break distance constraints.
DecisionBuilder * MakeGuidedSlackFinalizer(const RoutingDimension *dimension, std::function< int64(int64)> initializer)
The next few members are in the public section only for testing purposes.
EvaluatorCheapestAdditionFilteredHeuristic(RoutingModel *model, std::function< int64(int64, int64)> evaluator, LocalSearchFilterManager *filter_manager)
Takes ownership of evaluator.
const VariableIndexEvaluator2 & StateDependentTransitCallback(int callback_index) const
void SetValue(const IntVar *const var, int64 value)
RoutingModel(const RoutingIndexManager &index_manager)
Constructor taking an index manager.
bool IsStart(int64 index) const
Returns true if 'index' represents the first node of a route.
static const int64 kUnassigned
~SequentialSavingsFilteredHeuristic() override
std::function< bool(int64, int64, int64)> VariableValueComparator
const std::vector< IntVar * > & slacks() const
void ResetSolution()
Resets the data members for a new solution.
#define CHECK_LT(val1, val2)
bool use_neighbors_ratio_for_initialization
If true, only closest neighbors (see neighbors_ratio) are considered as insertion positions during in...
void MakeDisjunctionNodesUnperformed(int64 node)
Make nodes in the same disjunction as 'node' unperformed.
RoutingIndexPair IndexPair
@ ROUTING_FAIL
No solution found to the problem after calling RoutingModel::Solve().
int64 GetSpanUpperBoundForVehicle(int vehicle) const
int64 GetCumulVarSoftUpperBound(int64 index) const
Returns the soft upper bound of a cumul variable for a given variable index.
int GetPath(int64 node) const
void AddPickupAndDeliverySets(DisjunctionIndex pickup_disjunction, DisjunctionIndex delivery_disjunction)
Same as AddPickupAndDelivery but notifying that the performed node from the disjunction of index 'pic...
int GetEndChainStart(int vehicle) const
Returns the start of the end chain of vehicle,.
const std::vector< std::unique_ptr< LocalDimensionCumulOptimizer > > & GetLocalDimensionCumulMPOptimizers() const
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
~ChristofidesFilteredHeuristic() override
const std::vector< std::unique_ptr< LocalDimensionCumulOptimizer > > & GetLocalDimensionCumulOptimizers() const
const RoutingModel::TransitCallback2 & transit_evaluator(int vehicle) const
Returns the callback evaluating the transit value between two node indices for a given vehicle.
RangeMinMaxIndexFunction * transit_plus_identity
f(x)
~RoutingFilteredHeuristic() override
std::vector< bool > is_preemptible
bool is_sequential
Whether the routes are constructed sequentially or in parallel.
SimpleBoundCosts::BoundCost GetSoftSpanUpperBoundForVehicle(int vehicle) const
const Assignment * SolveWithParameters(const RoutingSearchParameters &search_parameters, std::vector< const Assignment * > *solutions=nullptr)
Solves the current routing model with the given parameters.
bool IsVehicleAllowedForIndex(int vehicle, int64 index)
Returns true if a vehicle is allowed to visit a given node.
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...
Status status() const
Returns the current status of the routing model.
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.
A structure to hold tasks described by their features.
int GetCompatibleVehicleOfType(int type, std::function< bool(int)> vehicle_is_compatible)
@ PICKUP_AND_DELIVERY_FIFO
Deliveries must be performed in the same order as pickups.
A CheapestAdditionFilteredHeuristic where the notion of 'cheapest arc' comes from an arc comparator.
std::vector< int64 > max_travels
Filter-base decision builder which builds a solution by inserting nodes at their cheapest position.
bool AddDimensionWithVehicleTransits(const std::vector< int > &evaluator_indices, int64 slack_max, int64 capacity, bool fix_start_cumul_to_zero, const std::string &name)
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.
bool IsVehicleUsed(const Assignment &assignment, int vehicle) const
Returns true if the route of 'vehicle' is non empty in 'assignment'.
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 MirrorTasks(Tasks *tasks)
Transforms the problem with a time symmetry centered in 0.
CostClassIndex cost_class_index
The cost class of the vehicle.
IntVarLocalSearchFilter * MakeMaxActiveVehiclesFilter(const RoutingModel &routing_model)
int64 GetSpanCostCoefficientForVehicle(int vehicle) const
virtual void SetVehicleIndex(int64 node, int vehicle)
CPFeasibilityFilter(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 AppendEvaluatedPositionsAfter(int64 node_to_insert, int64 start, int64 next_after_start, int64 vehicle, std::vector< ValuedPosition > *valued_positions)
Helper method to the ComputeEvaluatorSortedPositions* methods.
bool TypeOccursOnRoute(int type) const
Returns true iff any occurrence of the given type was seen on the route, i.e.
Assignment * CompactAssignment(const Assignment &assignment) const
Returns a compacted version of the given assignment, in which all vehicles with id lower or equal to ...
Assignment * ReadAssignment(const std::string &file_name)
Reads an assignment from a file and returns the current solution.
void SetPickupToDeliveryLimitFunctionForPair(PickupToDeliveryLimitFunction limit_function, int pair_index)
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...
RoutingDimension * GetMutableDimension(const std::string &dimension_name) const
Returns a dimension from its name.
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...
Status
Status of the search.
bool CostsAreHomogeneousAcrossVehicles() const
Whether costs are homogeneous across all vehicles.
std::pair< int64, int64 > ValuedPosition
std::vector< int64 > end_max
std::vector< std::pair< int64, int64 > > distance_duration
friend void AppendDimensionCumulFilters(const std::vector< RoutingDimension * > &dimensions, const RoutingSearchParameters ¶meters, bool filter_objective_cost, std::vector< LocalSearchFilterManager::FilterEvent > *filters)
int64 Value(int64 index) const
Returns the value of the variable of index 'index' in the last committed solution.
std::vector< std::vector< int64 > > GetRoutesFromAssignment(const Assignment &assignment)
Converts the solution in the given assignment to routes for all vehicles.
bool HasHardTypeIncompatibilities() const
Returns true iff any hard (resp.
void SynchronizeFilters()
Synchronizes filters with an assignment (the current solution).
void AddTemporalTypeIncompatibility(int type1, int type2)
VehicleClassIndex GetVehicleClassIndexOfVehicle(int64 vehicle) const
void InitialPropagate() override
This method performs the initial propagation of the constraint.
std::string DebugString() const override
void FillTravelBoundsOfVehicle(int vehicle, const std::vector< int64 > &path, const RoutingDimension &dimension, TravelBounds *travel_bounds)
const std::string & name() const
Returns the name of the dimension.
@ TYPE_ON_VEHICLE_UP_TO_VISIT
With the following policy, the visit enforces that type 'T' is considered on the route from its start...
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 ...
virtual ~TypeRegulationsChecker()
~CPFeasibilityFilter() override
IntVarFilteredDecisionBuilder(std::unique_ptr< IntVarFilteredHeuristic > heuristic)
void SetPickupAndDeliveryPolicyOfAllVehicles(PickupAndDeliveryPolicy policy)
Sets the Pickup and delivery policy of all vehicles.
void AddLocalSearchFilter(LocalSearchFilter *filter)
Adds a custom local search filter to the list of filters used to speed up local search by pruning unf...
A BaseObject is the root of all reversibly allocated objects.
const ReverseArcListGraph< int, int > & GetPathPrecedenceGraph() const
Accessors.
bool Precedences(Tasks *tasks)
Propagates the deductions from the chain of precedences, if there is one.
void AddToAssignment(IntVar *const var)
Adds an extra variable to the vehicle routing assignment.
IntVar * SlackVar(int64 index) const
virtual bool StopSearch()
Returns true if the search must be stopped.
BasePathFilter(const std::vector< IntVar * > &nexts, int next_domain_size)
const std::vector< RoutingDimension * > & GetDimensions() const
Returns all dimensions of the model.
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...
TypeRequirementChecker(const RoutingModel &model)
IntVarLocalSearchFilter * MakeVehicleAmortizedCostFilter(const RoutingModel &routing_model)
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...
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 SetFirstSolutionEvaluator(Solver::IndexEvaluator2 evaluator)
Takes ownership of evaluator.
Decision builder building a solution using heuristics with local search filters to evaluate its feasi...
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...
double farthest_seeds_ratio
The ratio of routes on which to insert farthest nodes as seeds before starting the cheapest insertion...
Manager for any NodeIndex <-> variable index conversion.
int GetCostClassesCount() const
Returns the number of different cost classes in the model.
Local Search Filters are used for fast neighbor pruning.
gtl::ITIVector< DimensionIndex, int64 > dimension_capacities
int64 Size() const
Returns the number of next variables in the model.
void AddPickupAndDelivery(int64 pickup, int64 delivery)
Notifies that index1 and index2 form a pair of nodes which should belong to the same route.
LocalCheapestInsertionFilteredHeuristic(RoutingModel *model, std::function< int64(int64, int64, int64)> evaluator, LocalSearchFilterManager *filter_manager)
Takes ownership of evaluator.
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
int64 GetNext(int64 node) const
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...
std::vector< std::string > GetAllDimensionNames() const
Outputs the names of all dimensions added to the routing engine.
uint64 unvisitable_nodes_fprint
Fingerprint of unvisitable non-start/end nodes.
bool AddDimension(int evaluator_index, int64 slack_max, int64 capacity, bool fix_start_cumul_to_zero, const std::string &name)
Model creation.
SimpleBoundCosts operator=(const SimpleBoundCosts &)=delete
IntVar * TransitVar(int64 index) const
bool CheckLimit()
Returns true if the search limit has been crossed.
std::unique_ptr< VehicleTypeCurator > vehicle_type_curator_
absl::Time AbsoluteSolverDeadline() const
IntVarLocalSearchFilter * MakeCumulBoundsPropagatorFilter(const RoutingDimension &dimension)
This class represents a sorted list of disjoint, closed intervals.
void SetCumulVarPiecewiseLinearCost(int64 index, const PiecewiseLinearFunction &cost)
Sets a piecewise linear cost on the cumul variable of a given variable index.
int Size() const
Returns the number of variables the decision builder is trying to instantiate.
ChristofidesFilteredHeuristic(RoutingModel *model, LocalSearchFilterManager *filter_manager, bool use_minimum_matching)
const std::vector< IntVar * > & transits() const
void AddVariableTargetToFinalizer(IntVar *var, int64 target)
Add a variable to set the closest possible to the target value in the solution finalizer.
An Assignment is a variable -> domains mapping, used to report solutions to the user.
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...
Struct used to sort and store vehicles by their type.
const E & Element(const V *const var) const
void InitializeCheck(int vehicle, const std::function< int64(int64)> &next_accessor)
const std::vector< absl::flat_hash_set< int > > & GetSameVehicleRequiredTypeAlternativesOfType(int type) const
Returns the set of same-vehicle requirement alternatives for the given type.
Assignment * ReadAssignmentFromRoutes(const std::vector< std::vector< int64 >> &routes, bool ignore_inactive_indices)
Restores the routes as the current solution.
CheapestInsertionFilteredHeuristic(RoutingModel *model, std::function< int64(int64, int64, int64)> evaluator, std::function< int64(int64)> penalty_evaluator, LocalSearchFilterManager *filter_manager)
Takes ownership of evaluator.
PickupAndDeliveryPolicy
Types of precedence policy applied to pickup and delivery pairs.
VehicleTypeCurator(const RoutingModel::VehicleTypeContainer &vehicle_type_container)
RoutingDisjunctionIndex DisjunctionIndex
bool StopSearch() override
Returns true if the search must be stopped.
This filter accepts deltas for which the assignment satisfies the constraints of the Solver.
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...
Checker for type requirements.
int64 global_span_cost_coefficient() const
int GetMaximumNumberOfActiveVehicles() const
Returns the maximum number of active vehicles.
int64 CapAdd(int64 x, int64 y)
static const DimensionIndex kNoDimension
Constant used to express the "no dimension" index, returned when a dimension name does not correspond...
Generic filter-based heuristic applied to IntVars.
int64 GetArcCostForFirstSolution(int64 from_index, int64 to_index) const
Returns the cost of the arc in the context of the first solution strategy.
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
TypeIncompatibilityChecker(const RoutingModel &model, bool check_hard_incompatibilities)
const std::vector< int64 > & vehicle_capacities() const
Returns the capacities for all vehicles.
std::string DebugString() const override
bool HasSoftSpanUpperBounds() const
void SetFixedCostOfAllVehicles(int64 cost)
Sets the fixed cost of all vehicle routes.
~BasePathFilter() override
bool Propagate(Tasks *tasks)
Computes new bounds for all tasks, returns false if infeasible.
int64 Value(int index) const
bool ArcIsMoreConstrainedThanArc(int64 from, int64 to1, int64 to2)
Returns whether the arc from->to1 is more constrained than from->to2, taking into account,...
const TransitCallback2 & TransitCallback(int callback_index) const
const std::vector< int64 > & GetAmortizedLinearCostFactorOfVehicles() const
const TransitCallback1 & UnaryTransitCallbackOrNull(int callback_index) const
A structure meant to store soft bounds and associated violation constants.
GlobalVehicleBreaksConstraint ensures breaks constraints are enforced on all vehicles in the dimensio...
int64 GetUnperformedValue(int64 node_to_insert) const
Returns the cost of unperforming node 'node_to_insert'.
IntVar * CostVar() const
Returns the global cost variable which is being minimized.
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.
int64 GetDisjunctionPenalty(DisjunctionIndex index) const
Returns the penalty of the node disjunction of index 'index'.
void InitializeBreaks()
Sets up vehicle_break_intervals_, vehicle_break_distance_duration_, pre_travel_evaluators and post_tr...
Filter-based decision builder which builds a solution by using Clarke & Wright's Savings heuristic.
void ReinjectVehicleOfClass(int vehicle, int vehicle_class, int64 fixed_cost)
int Rank(int64 node) const
int64 ComputeLowerBound()
Computes a lower bound to the routing problem solving a linear assignment problem.
bool WriteAssignment(const std::string &file_name) const
Writes the current solution to a file containing an AssignmentProto.
RoutingCostClassIndex CostClassIndex
IntVar * VehicleCostsConsideredVar(int vehicle) const
Returns the variable specifying whether or not costs are considered for vehicle.
TypeRegulationsChecker(const RoutingModel &model)
bool operator<(const StartEndValue &other) const
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...
const std::vector< int > & GetPairIndicesOfType(int type) const
void SetAllowedVehiclesForIndex(const std::vector< int > &vehicles, int64 index)
Sets the vehicles which can visit a given node.
const std::vector< IntegerType > & PositionsSetAtLeastOnce() const
gtl::ITIVector< DimensionIndex, int64 > dimension_end_cumuls_max
ParallelSavingsFilteredHeuristic(RoutingModel *model, const RoutingIndexManager *manager, SavingsParameters parameters, LocalSearchFilterManager *filter_manager)
int64 UnperformedPenalty(int64 var_index) const
Get the "unperformed" penalty of a node.
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...
Filtered-base decision builder based on the addition heuristic, extending a path from its start node ...
Assignment *const BuildSolution()
Builds a solution.
bool add_unperformed_entries
If true, entries are created for making the nodes/pairs unperformed, and when the cost of making a no...
@ TYPE_ADDED_TO_VEHICLE
When visited, the number of types 'T' on the vehicle increases by one.
virtual void BuildRoutesFromSavings()=0
~LocalCheapestInsertionFilteredHeuristic() override
A DecisionBuilder is responsible for creating the search tree.
const Solver::IndexEvaluator2 & first_solution_evaluator() const
Gets/sets the evaluator used during the search.
IntVarFilteredHeuristic(Solver *solver, const std::vector< IntVar * > &vars, LocalSearchFilterManager *filter_manager)
IntVar * CumulVar(int64 index) const
Get the cumul, transit and slack variables for the given node (given as int64 var index).
const RoutingModel & model_
int start_equivalence_class
Vehicle start and end equivalence classes.
IntVarLocalSearchFilter * MakeVehicleVarFilter(const RoutingModel &routing_model)
void AddSearchMonitor(SearchMonitor *const monitor)
Adds a search monitor to the search used to solve the routing model.
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...
double max_memory_usage_bytes
The number of neighbors considered for each node is also adapted so that the stored Savings don't use...
RoutingIndexPairs IndexPairs
RoutingModel::VisitTypePolicy VisitTypePolicy
operations_research::FirstSolutionStrategy::Value GetAutomaticFirstSolutionStrategy() const
Returns the automatic first solution strategy selected.
RoutingModel * model() const
Returns the model on which the dimension was created.
int Type(int vehicle) const
@ ROUTING_NOT_SOLVED
Problem not solved yet (before calling RoutingModel::Solve()).
bool IsEnd(int64 index) const
Returns true if 'index' represents the last node of a route.
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::string DebugString() const override
bool HasSameVehicleTypeRequirements() const
Returns true iff any same-route (resp.
absl::Duration RemainingTime() const
Returns the time left in the search limit.
void AppendTasksFromIntervals(const std::vector< IntervalVar * > &intervals, DisjunctivePropagator::Tasks *tasks)
std::vector< int64 > start_min
virtual bool FinalizeCheck() const
std::pair< StartEndValue, int > Seed
void Post() override
This method is called when the constraint is processed by the solver.
IntVarLocalSearchFilter * MakeGlobalLPCumulFilter(GlobalDimensionCumulOptimizer *optimizer, bool filter_objective_cost)
std::function< int64(const Model &)> Value(IntegerVariable v)
SUBTLE: The vehicle's fixed cost is skipped on purpose here, because we can afford to do so:
~CheapestInsertionFilteredHeuristic() override
int GetNonZeroCostClassesCount() const
Ditto, minus the 'always zero', built-in cost class.
int64 GetVehicleTypeFromSaving(const Saving &saving) const
Returns the cost class from a saving.
std::string DebugString() const override
const std::vector< int64 > & vehicle_span_upper_bounds() const
~SavingsFilteredHeuristic() override
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...
#define DCHECK(condition)
VisitTypePolicy
Set the node visit types and incompatibilities/requirements between the types (see below).
const VehicleTypeContainer & GetVehicleTypeContainer() const
@ ROUTING_SUCCESS
Problem solved successfully after calling RoutingModel::Solve().
void SetVisitType(int64 index, int type, VisitTypePolicy type_policy)
int num_type_removed_from_vehicle
Number of ADDED_TYPE_REMOVED_FROM_VEHICLE (effectively removing a type from the route) and TYPE_SIMUL...
static const char kLightElement[]
Constraint types.
static bool LessThan(const VehicleClass &a, const VehicleClass &b)
Comparator for STL containers and algorithms.
std::pair< std::vector< int64 >, std::vector< int64 > > RoutingIndexPair
void SetSpanCostCoefficientForVehicle(int64 coefficient, int vehicle)
Sets a cost proportional to the dimension span on a given vehicle, or on all vehicles at once.
Interval variables are often used in scheduling.
const std::vector< DisjunctionIndex > & GetDisjunctionIndices(int64 index) const
Returns the indices of the disjunctions to which an index belongs.
bool IsMatchingModel() const
Returns true if a vehicle/node matching problem is detected.
Assignment * MutablePreAssignment()
std::pair< int64, int64 > Saving
const std::vector< IntervalVar * > & GetBreakIntervalsOfVehicle(int vehicle) const
Returns the break intervals set by SetBreakIntervalsOfVehicle().
void AddNodePrecedence(NodePrecedence precedence)
bool HasPickupToDeliveryLimits() const
int RegisterTransitCallback(TransitCallback2 callback)
std::vector< int64 > duration_min
int RegisterPositiveUnaryTransitCallback(TransitCallback1 callback)
std::string DebugString() const override
bool AddDimensionWithVehicleCapacity(int evaluator_index, int64 slack_max, std::vector< int64 > vehicle_capacities, bool fix_start_cumul_to_zero, const std::string &name)
void SetBreakIntervalsOfVehicle(std::vector< IntervalVar * > breaks, int vehicle, int pre_travel_evaluator, int post_travel_evaluator)
Sets the breaks for a given vehicle.
std::vector< RoutingIndexPair > RoutingIndexPairs
A CheapestAdditionFilteredHeuristic where the notion of 'cheapest arc' comes from an arc evaluator.
const std::vector< SortedDisjointIntervalList > & forbidden_intervals() const
Returns forbidden intervals for each node.
virtual void OnInitializeCheck()
const std::vector< std::pair< int, int > > & GetDeliveryIndexPairs(int64 node_index) const
Same as above for deliveries.
std::vector< int64 > start_max
int end_equivalence_class
std::vector< int64 > duration_max
int64 GetGlobalOptimizerOffset() const
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...
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
const std::vector< std::unique_ptr< GlobalDimensionCumulOptimizer > > & GetGlobalDimensionCumulOptimizers() const
Returns [global|local]_dimension_optimizers_, which are empty if the model has not been closed.
IntVarElement * FastAdd(IntVar *const var)
Adds without checking if variable has been previously added.
void AddLocalSearchOperator(LocalSearchOperator *ls_operator)
Adds a local search operator to the set of operators used to solve the vehicle routing problem.
std::vector< int > type_index_of_vehicle
#define DCHECK_GE(val1, val2)
int64 GetDisjunctionMaxCardinality(DisjunctionIndex index) const
Returns the maximum number of possible active nodes of the node disjunction of index 'index'.
void SetSpanCostCoefficientForAllVehicles(int64 coefficient)
A constraint is the main modeling object.
RoutingModel * model() const
std::string DebugString() const override
void SetCumulVarSoftUpperBound(int64 index, int64 upper_bound, int64 coefficient)
Sets a soft upper bound to the cumul variable of a given variable index.
~TypeIncompatibilityChecker() override
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,...
~ComparatorCheapestAdditionFilteredHeuristic() override
virtual bool HasRegulationsToCheck() const =0
void OnSynchronize(const Assignment *delta) override
IntVarLocalSearchFilter * MakePathCumulFilter(const RoutingDimension &dimension, const RoutingSearchParameters ¶meters, bool propagate_own_objective_value, bool filter_objective_cost, bool can_use_lp=true)
virtual bool BuildSolutionInternal()=0
Virtual method to redefine how to build a solution.
std::vector< int64 > post_travels
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.
void AppendTasksFromPath(const std::vector< int64 > &path, const TravelBounds &travel_bounds, const RoutingDimension &dimension, DisjunctivePropagator::Tasks *tasks)
bool HasTemporalTypeIncompatibilities() const
const std::vector< absl::flat_hash_set< int > > & GetRequiredTypeAlternativesWhenRemovingType(int type) const
Returns the set of requirement alternatives when removing the given type.
IntVarLocalSearchFilter * MakeVehicleBreaksFilter(const RoutingModel &routing_model, const RoutingDimension &dimension)
int vehicle_to_class(int vehicle) const
CostClass(int evaluator_index)
SimpleBoundCosts(const SimpleBoundCosts &)=delete
~ParallelSavingsFilteredHeuristic() override
int64 GetNumberOfDecisionsInFirstSolution(const RoutingSearchParameters &search_parameters) const
Returns statistics on first solution search, number of decisions sent to filters, number of decisions...
Filter manager: when a move is made, filters are executed to decide whether the solution is feasible ...
RangeIntToIntFunction * transit
GlobalVehicleBreaksConstraint(const RoutingDimension *dimension)
const std::vector< NodePrecedence > & GetNodePrecedences() const
double neighbors_ratio
If neighbors_ratio < 1 then for each node only this ratio of its neighbors leading to the smallest ar...
gtl::ITIVector< DimensionIndex, int64 > dimension_end_cumuls_min
std::vector< int64 > end_min
const Assignment *const PreAssignment() const
Returns an assignment used to fix some of the variables of the problem.
Checker for type incompatibilities.
const std::vector< std::pair< DisjunctionIndex, DisjunctionIndex > > & GetPickupAndDeliveryDisjunctions() const
const std::vector< int64 > & GetAmortizedQuadraticCostFactorOfVehicles() const
bool AreVehicleTransitsPositive(int vehicle) const
Returns true iff the transit evaluator of 'vehicle' is positive for all arcs.
int64 End(int vehicle) const
Returns the variable index of the ending node of a vehicle route.
void MakePartiallyPerformedPairsUnperformed()
Make all partially performed pickup and delivery pairs unperformed.
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...
void AddVariableMinimizedByFinalizer(IntVar *var)
Adds a variable to minimize in the solution finalizer.
void AddNodePrecedence(int64 first_node, int64 second_node, int64 offset)
bool HasCumulVarSoftUpperBound(int64 index) const
Returns true if a soft upper bound has been set for a given variable index.
std::string DebugString() const override
Generic path-based filter class.
void CloseVisitTypes()
This function should be called once all node visit types have been set and prior to adding any incomp...
CostClassIndex GetCostClassIndexOfVehicle(int64 vehicle) const
Get the cost class index of the given vehicle.
void AddWeightedVariableMinimizedByFinalizer(IntVar *var, int64 cost)
Adds a variable to minimize in the solution finalizer, with a weighted priority: the higher the more ...
std::vector< std::pair< int64, int64 > > GetPerfectBinaryDisjunctions() const
Returns the list of all perfect binary disjunctions, as pairs of variable indices: a disjunction is "...
IntVarLocalSearchFilter * MakePickupDeliveryFilter(const RoutingModel &routing_model, const RoutingModel::IndexPairs &pairs, const std::vector< RoutingModel::PickupAndDeliveryPolicy > &vehicle_policies)
int64 Next(const Assignment &assignment, int64 index) const
Assignment inspection Returns the variable index of the node directly after the node corresponding to...
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,...
@ ADDED_TYPE_REMOVED_FROM_VEHICLE
When visited, one instance of type 'T' previously added to the route (TYPE_ADDED_TO_VEHICLE),...
virtual double ExtraSavingsMemoryMultiplicativeFactor() const =0
bool AreEmptyRouteCostsConsideredForVehicle(int vehicle) const
const std::vector< int > & GetSameVehicleIndicesOfIndex(int node) const
Returns variable indices of nodes constrained to be on the same route.
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.
int64 Start(int vehicle) const
Model inspection.
IntVar * VehicleVar(int64 index) const
Returns the vehicle variable of the node corresponding to index.
void AddIntervalToAssignment(IntervalVar *const interval)
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,...
void SetValue(int64 index, int64 value)
Modifies the current solution by setting the variable of index 'index' to value 'value'.
bool Commit()
Commits the modifications to the current solution if these modifications are "filter-feasible",...
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 * (...
int64 GetFixedCostOfVehicle(int vehicle) const
Returns the route fixed cost taken into account if the route of the vehicle is not empty,...
std::vector< int64 > min_travels
std::string DebugString() const override
gtl::ITIVector< DimensionIndex, int64 > dimension_start_cumuls_min
Bounds of cumul variables at start and end vehicle nodes.
const Assignment * SolveFromAssignmentWithParameters(const Assignment *assignment, const RoutingSearchParameters &search_parameters, std::vector< const Assignment * > *solutions=nullptr)
int64 GetCumulVarSoftUpperBoundCoefficient(int64 index) const
Returns the cost coefficient of the soft upper bound of a cumul variable for a given variable index.
IntVar * ApplyLocks(const std::vector< int64 > &locks)
Applies a lock chain to the next search.
const Assignment * BuildSolutionFromRoutes(const std::function< int64(int64)> &next_accessor)
Builds a solution starting from the routes formed by the next accessor.
int64 GetPickupToDeliveryLimitForPair(int pair_index, int pickup, int delivery) const
SimpleBoundCosts(int num_bounds, BoundCost default_bound_cost)
~IntVarFilteredDecisionBuilder() override
void AppendDimensionCumulFilters(const std::vector< RoutingDimension * > &dimensions, const RoutingSearchParameters ¶meters, bool filter_objective_cost, std::vector< LocalSearchFilterManager::FilterEvent > *filters)
void CloseModel()
Closes the current routing model; after this method is called, no modification to the model can be do...
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
void SetMaximumNumberOfActiveVehicles(int max_active_vehicles)
Constrains the maximum number of active vehicles, aka the number of vehicles which do not have an emp...
@ ROUTING_INVALID
Model, model parameters or flags are not valid.
int64 number_of_rejects() const
int num_type_added_to_vehicle
Number of TYPE_ADDED_TO_VEHICLE and TYPE_SIMULTANEOUSLY_ADDED_AND_REMOVED node type policies seen on ...
SavingsFilteredHeuristic(RoutingModel *model, const RoutingIndexManager *manager, SavingsParameters parameters, LocalSearchFilterManager *filter_manager)
int64 number_of_decisions() const
Returns statistics from its underlying heuristic.
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_,...
const IndexPairs & GetPickupAndDeliveryPairs() const
Returns pickup and delivery pairs currently in the model.
~TypeRequirementChecker() override
Solver * solver() const
Returns the underlying constraint solver.
void ConsiderEmptyRouteCostsForVehicle(bool consider_costs, int vehicle)
Dimensions represent quantities accumulated at nodes along the routes.
const Assignment * Solve(const Assignment *assignment=nullptr)
Solves the current routing model; closes the current model.
bool CheckVehicle(int vehicle, const std::function< int64(int64)> &next_accessor)
std::unique_ptr< SavingsContainer< Saving > > savings_container_
const RoutingDimension * dimension
int GetStartChainEnd(int vehicle) const
Returns the end of the start chain of vehicle,.
Filter-based decision builder which builds a solution by inserting nodes at their cheapest position o...
void Post() override
This method is called when the constraint is processed by the solver.
bool HasCumulVarPiecewiseLinearCost(int64 index) const
Returns true if a piecewise linear cost has been set for a given variable index.
virtual void ResetVehicleIndices()
const std::string & GetPrimaryConstrainedDimension() const
Get the primary constrained dimension, or an empty string if it is unset.
void MakeUnassignedNodesUnperformed()
Make all unassigned nodes unperformed.
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.
const std::vector< absl::flat_hash_set< int > > & GetRequiredTypeAlternativesWhenAddingType(int type) const
Returns the set of requirement alternatives when adding the given type.
const absl::flat_hash_set< int > & GetTemporalTypeIncompatibilitiesOfType(int type) const
void SetGlobalSpanCostCoefficient(int64 coefficient)
Sets a cost proportional to the global dimension span, that is the difference between the largest val...
static bool LessThan(const CostClass &a, const CostClass &b)
Comparator for STL containers and algorithms.
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...
IntVar * Var(int64 index) const
Returns the variable of index 'index'.
void SetPickupAndDeliveryPolicyOfVehicle(PickupAndDeliveryPolicy policy, int vehicle)
SequentialSavingsFilteredHeuristic(RoutingModel *model, const RoutingIndexManager *manager, SavingsParameters parameters, LocalSearchFilterManager *filter_manager)
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< DimensionCost > dimension_transit_evaluator_class_and_cost_coefficient
void SetTabuVarsCallback(GetTabuVarsCallback tabu_var_callback)
void SetCumulVarSoftLowerBound(int64 index, int64 lower_bound, int64 coefficient)
Sets a soft lower bound to the cumul variable of a given variable index.
void SetFixedCostOfVehicle(int64 cost, int vehicle)
Sets the fixed cost of one vehicle route.
bool ChainSpanMinDynamic(Tasks *tasks)
Computes a lower bound of the span of the chain, taking into account only the first nonchain task.
int64 GetCumulVarSoftLowerBound(int64 index) const
Returns the soft lower bound of a cumul variable for a given variable index.
RoutingDimensionIndex DimensionIndex
Assignment * RestoreAssignment(const Assignment &solution)
Restores an assignment as a solution in the routing model and returns the new solution.
gtl::ITIVector< DimensionIndex, int64 > dimension_start_cumuls_max
SortedDisjointIntervalList GetAllowedIntervalsInRange(int64 index, int64 min_value, int64 max_value) const
Returns allowed intervals for a given node in a given interval.
SimpleBoundCosts::BoundCost GetQuadraticCostSoftSpanUpperBoundForVehicle(int vehicle) const
bool add_reverse_arcs
If add_reverse_arcs is true, the neighborhood relationships are considered symmetrically.
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; ...
std::function< int64(int64, int64, int64)> evaluator_
What follows is relevant for models with time/state dependent transits.
bool ChainSpanMin(Tasks *tasks)
Propagates a lower bound of the chain span, end[num_chain_tasks] - start[0], to span_min.
This class acts like a CP propagator: it takes a set of tasks given by their start/duration/end featu...
int64 GetBeforeNodeFromSaving(const Saving &saving) const
Returns the "before node" from a saving.
void AddAtSolutionCallback(std::function< void()> callback)
Adds a callback called each time a solution is found during the search.
bool HasDimension(const std::string &dimension_name) const
Returns true if a dimension exists for a given dimension name.
int RegisterStateDependentTransitCallback(VariableIndexEvaluator2 callback)
bool BuildSolutionInternal() override
Virtual method to redefine how to build a solution.
static const char kLightElement2[]
@ ROUTING_FAIL_TIMEOUT
Time limit reached before finding a solution with RoutingModel::Solve().
void SetSectors(int sectors)
RoutingFilteredHeuristic(RoutingModel *model, LocalSearchFilterManager *filter_manager)
int64 ShortestTransitionSlack(int64 node) const
It makes sense to use the function only for self-dependent dimension.
std::function< int64(int64, int64)> RoutingTransitCallback2
IntVarLocalSearchFilter * MakeNodeDisjunctionFilter(const RoutingModel &routing_model)
Base class of all search limits.
static const int64 kNoPenalty
Constant used to express a hard constraint instead of a soft penalty.
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.
const std::vector< IntVar * > & cumuls() const
Like CumulVar(), TransitVar(), SlackVar() but return the whole variable vectors instead (indexed by i...
int nodes() const
Sizes and indices Returns the number of nodes in the model.
bool HasTemporalTypeRequirements() const
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...
friend class SavingsFilteredHeuristicTestPeer
int GetNumberOfVisitTypes() const
const RoutingDimension * base_dimension() const
Returns the parent in the dependency tree if any or nullptr otherwise.
bool HasCumulVarSoftLowerBound(int64 index) const
Returns true if a soft lower bound has been set for a given variable index.
virtual bool CheckTypeRegulations(int type, VisitTypePolicy policy, int pos)=0
static std::unique_ptr< LocalSearchOperator > MakeGreedyDescentLSOperator(std::vector< IntVar * > variables)
Perhaps move it to constraint_solver.h.
int64 number_of_decisions() const
Returns statistics on search, number of decisions sent to filters, number of decisions rejected by fi...
static const int64 kint64max
int GetNumOfSingletonNodes() const
Returns the number of non-start/end nodes which do not appear in a pickup/delivery pair.
BoundCost & bound_cost(int element)
Assignment * CompactAndCheckAssignment(const Assignment &assignment) const
Same as CompactAssignment() but also checks the validity of the final compact solution; if it is not ...
LocalDimensionCumulOptimizer * GetMutableLocalCumulOptimizer(const RoutingDimension &dimension) const
int64 GetLocalOptimizerOffsetForVehicle(int vehicle) const
std::function< int64(int64)> penalty_evaluator_
std::vector< const SortedDisjointIntervalList * > forbidden_intervals
void AddVariableMaximizedByFinalizer(IntVar *var)
Adds a variable to maximize in the solution finalizer (see above for information on the solution fina...
IntVar * ActiveVar(int64 index) const
Returns the active variable of the node corresponding to index.
int GetPostTravelEvaluatorOfVehicle(int vehicle) const
~EvaluatorCheapestAdditionFilteredHeuristic() override
A Decision represents a choice point in the search tree.