 |
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/functional/bind_front.h"
171 #include "absl/hash/hash.h"
172 #include "absl/time/time.h"
197 class GlobalDimensionCumulOptimizer;
198 class LocalDimensionCumulOptimizer;
199 class LocalSearchOperator;
201 class IntVarFilteredDecisionBuilder;
202 class IntVarFilteredHeuristic;
203 class IndexNeighborFinder;
205 class RoutingDimension;
307 std::vector<DimensionCost>
315 if (
a.evaluator_index !=
b.evaluator_index) {
316 return a.evaluator_index <
b.evaluator_index;
318 return a.dimension_transit_evaluator_class_and_cost_coefficient <
319 b.dimension_transit_evaluator_class_and_cost_coefficient;
352 #endif // defined(SWIG)
408 CHECK_LT(callback_index, transit_evaluators_.size());
409 return transit_evaluators_[callback_index];
412 CHECK_LT(callback_index, unary_transit_evaluators_.size());
413 return unary_transit_evaluators_[callback_index];
416 int callback_index)
const {
417 CHECK_LT(callback_index, state_dependent_transit_evaluators_.size());
418 return state_dependent_transit_evaluators_[callback_index];
444 bool fix_start_cumul_to_zero,
const std::string&
name);
446 const std::vector<int>& evaluator_indices,
int64 slack_max,
449 std::vector<int64> vehicle_capacities,
450 bool fix_start_cumul_to_zero,
451 const std::string&
name);
453 const std::vector<int>& evaluator_indices,
int64 slack_max,
454 std::vector<int64> vehicle_capacities,
bool fix_start_cumul_to_zero,
455 const std::string&
name);
464 bool fix_start_cumul_to_zero,
465 const std::string&
name);
467 bool fix_start_cumul_to_zero,
468 const std::string&
name) {
470 fix_start_cumul_to_zero,
name);
480 bool fix_start_cumul_to_zero,
481 const std::string&
name);
490 std::vector<std::vector<int64> > values,
499 const std::vector<int>& pure_transits,
500 const std::vector<int>& dependent_transits,
502 std::vector<int64> vehicle_capacities,
bool fix_start_cumul_to_zero,
503 const std::string&
name) {
504 return AddDimensionDependentDimensionWithVehicleCapacityInternal(
505 pure_transits, dependent_transits, base_dimension, slack_max,
506 std::move(vehicle_capacities), fix_start_cumul_to_zero,
name);
512 int64 slack_max, std::vector<int64> vehicle_capacities,
513 bool fix_start_cumul_to_zero,
const std::string&
name);
517 int64 vehicle_capacity,
bool fix_start_cumul_to_zero,
518 const std::string&
name);
520 int pure_transit,
int dependent_transit,
522 int64 vehicle_capacity,
bool fix_start_cumul_to_zero,
523 const std::string&
name);
540 std::vector<IntVar*> spans,
541 std::vector<IntVar*> total_slacks);
548 return dimensions_.get();
555 const std::vector<std::unique_ptr<GlobalDimensionCumulOptimizer> >&
557 return global_dimension_optimizers_;
559 const std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >&
561 return local_dimension_optimizers_;
563 const std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >&
565 return local_dimension_mp_optimizers_;
579 bool HasDimension(
const std::string& dimension_name)
const;
582 const std::string& dimension_name)
const;
586 const std::string& dimension_name)
const;
593 primary_constrained_dimension_ = dimension_name;
597 return primary_constrained_dimension_;
617 int64 max_cardinality = 1);
621 return index_to_disjunctions_[
index];
626 template <
typename F>
630 if (disjunctions_[disjunction].
value.max_cardinality == max_cardinality) {
631 for (
const int64 d_index : disjunctions_[disjunction].indices) {
637 #if !defined(SWIGPYTHON)
642 return disjunctions_[
index].indices;
644 #endif // !defined(SWIGPYTHON)
647 return disjunctions_[
index].value.penalty;
652 return disjunctions_[
index].value.max_cardinality;
683 return allowed_vehicles_[
index].empty() ||
684 allowed_vehicles_[
index].find(vehicle) !=
685 allowed_vehicles_[
index].end();
713 const std::vector<std::pair<int, int> >&
716 const std::vector<std::pair<int, int> >&
735 return pickup_delivery_pairs_;
737 const std::vector<std::pair<DisjunctionIndex, DisjunctionIndex>>&
739 return pickup_delivery_disjunctions_;
747 return implicit_pickup_delivery_pairs_without_alternatives_;
794 return topologically_sorted_visit_types_;
811 return has_hard_type_incompatibilities_;
814 return has_temporal_type_incompatibilities_;
827 int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
833 int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
840 int dependent_type, absl::flat_hash_set<int> required_type_alternatives);
844 const std::vector<absl::flat_hash_set<int> >&
847 const std::vector<absl::flat_hash_set<int> >&
850 const std::vector<absl::flat_hash_set<int> >&
856 return has_same_vehicle_type_requirements_;
859 return has_temporal_type_requirements_;
889 max_active_vehicles_ = max_active_vehicles;
925 int64 quadratic_cost_factor);
928 int64 quadratic_cost_factor,
932 return linear_cost_factor_of_vehicle_;
935 return quadratic_cost_factor_of_vehicle_;
940 consider_empty_route_costs_[vehicle] = consider_costs;
945 return consider_empty_route_costs_[vehicle];
952 return first_solution_evaluator_;
957 first_solution_evaluator_ = std::move(evaluator);
992 const RoutingSearchParameters& search_parameters);
999 const Assignment*
Solve(
const Assignment* assignment =
nullptr);
1008 const RoutingSearchParameters& search_parameters,
1009 std::vector<const Assignment*>* solutions =
nullptr);
1011 const Assignment* assignment,
1012 const RoutingSearchParameters& search_parameters,
1013 std::vector<const Assignment*>* solutions =
nullptr);
1020 Assignment* target_assignment,
const RoutingModel* source_model,
1021 const Assignment* source_assignment);
1073 const std::vector<std::vector<int64>>& routes,
1074 bool ignore_inactive_indices);
1092 bool ignore_inactive_indices,
bool close_routes,
1098 std::vector<std::vector<int64>>*
const routes)
const;
1143 const Assignment* original_assignment, absl::Duration duration_limit);
1158 CHECK(filter !=
nullptr);
1160 LOG(
WARNING) <<
"Model is closed, filter addition will be ignored.";
1170 int64 End(
int vehicle)
const {
return ends_[vehicle]; }
1185 #if !defined(SWIGPYTHON)
1186 const std::vector<IntVar*>&
Nexts()
const {
return nexts_; }
1191 const std::vector<IntVar*>&
VehicleVars()
const {
return vehicle_vars_; }
1193 IntVar* NextVar(int64 index) const { return nexts_[index]; }
1201 return vehicle_active_[vehicle];
1206 return vehicle_costs_considered_[vehicle];
1217 int64 vehicle)
const;
1220 return costs_are_homogeneous_across_vehicles_;
1237 int64 cost_class_index)
const;
1242 DCHECK_LT(vehicle, cost_class_index_of_vehicle_.size());
1243 DCHECK_GE(cost_class_index_of_vehicle_[vehicle], 0);
1244 return cost_class_index_of_vehicle_[vehicle];
1250 if (cost_class_index == kCostClassIndexOfZeroCost) {
1251 return has_vehicle_with_zero_cost_class_;
1253 return cost_class_index < cost_classes_.size();
1263 return vehicle_class_index_of_vehicle_[vehicle];
1270 return same_vehicle_groups_[same_vehicle_group_[node]];
1275 return vehicle_type_container_;
1303 const std::string& dimension_to_print)
const;
1310 std::vector<std::vector<std::pair<int64, int64>>>
GetCumulBounds(
1319 DCHECK(limit_ !=
nullptr);
1320 return limit_->
Check();
1325 DCHECK(limit_ !=
nullptr);
1335 int64 Size()
const {
return nodes_ + vehicles_ - start_end_count_; }
1340 const RoutingSearchParameters& search_parameters)
const;
1342 const RoutingSearchParameters& search_parameters)
const;
1346 return automatic_first_solution_strategy_;
1356 std::function<std::vector<operations_research::IntVar*>(
RoutingModel*)>;
1384 std::vector<IntVar*> variables);
1386 DecisionBuilder* MakeSelfDependentDimensionFinalizer(
1404 enum RoutingLocalSearchOperator {
1407 LIGHT_RELOCATE_PAIR,
1415 GLOBAL_CHEAPEST_INSERTION_CLOSE_NODES_LNS,
1416 LOCAL_CHEAPEST_INSERTION_CLOSE_NODES_LNS,
1417 GLOBAL_CHEAPEST_INSERTION_PATH_LNS,
1418 LOCAL_CHEAPEST_INSERTION_PATH_LNS,
1419 RELOCATE_PATH_GLOBAL_CHEAPEST_INSERTION_INSERT_UNPERFORMED,
1420 GLOBAL_CHEAPEST_INSERTION_EXPENSIVE_CHAIN_LNS,
1421 LOCAL_CHEAPEST_INSERTION_EXPENSIVE_CHAIN_LNS,
1422 RELOCATE_EXPENSIVE_CHAIN,
1426 RELOCATE_AND_MAKE_ACTIVE,
1427 MAKE_ACTIVE_AND_RELOCATE,
1429 MAKE_CHAIN_INACTIVE,
1431 EXTENDED_SWAP_ACTIVE,
1437 EXCHANGE_RELOCATE_PAIR,
1440 LOCAL_SEARCH_OPERATOR_COUNTER
1446 template <
typename T>
1447 struct ValuedNodes {
1448 std::vector<int64> indices;
1451 struct DisjunctionValues {
1453 int64 max_cardinality;
1455 typedef ValuedNodes<DisjunctionValues> Disjunction;
1459 struct CostCacheElement {
1471 void AddNoCycleConstraintInternal();
1472 bool AddDimensionWithCapacityInternal(
1473 const std::vector<int>& evaluator_indices,
int64 slack_max,
1474 std::vector<int64> vehicle_capacities,
bool fix_start_cumul_to_zero,
1475 const std::string&
name);
1476 bool AddDimensionDependentDimensionWithVehicleCapacityInternal(
1477 const std::vector<int>& pure_transits,
1478 const std::vector<int>& dependent_transits,
1480 std::vector<int64> vehicle_capacities,
bool fix_start_cumul_to_zero,
1481 const std::string&
name);
1482 bool InitializeDimensionInternal(
1483 const std::vector<int>& evaluator_indices,
1484 const std::vector<int>& state_dependent_evaluator_indices,
1485 int64 slack_max,
bool fix_start_cumul_to_zero,
1487 DimensionIndex GetDimensionIndex(
const std::string& dimension_name)
const;
1516 void StoreDimensionCumulOptimizers(
const RoutingSearchParameters&
parameters);
1518 void ComputeCostClasses(
const RoutingSearchParameters&
parameters);
1519 void ComputeVehicleClasses();
1527 void ComputeVehicleTypes();
1537 void FinalizeVisitTypes();
1539 void TopologicallySortVisitTypes();
1542 void AppendHomogeneousArcCosts(
const RoutingSearchParameters&
parameters,
1544 std::vector<IntVar*>* cost_elements);
1545 void AppendArcCosts(
const RoutingSearchParameters&
parameters,
int node_index,
1546 std::vector<IntVar*>* cost_elements);
1547 Assignment* DoRestoreAssignment();
1549 int64 SafeGetCostClassInt64OfVehicle(
int64 vehicle)
const {
1552 : kCostClassIndexOfZeroCost)
1556 const CostClass& cost_class)
const;
1560 void AddPickupAndDeliverySetsInternal(
const std::vector<int64>& pickups,
1561 const std::vector<int64>& deliveries);
1564 IntVar* CreateSameVehicleCost(
int vehicle_index);
1567 int FindNextActive(
int index,
const std::vector<int64>& indices)
const;
1571 bool RouteCanBeUsedByVehicle(
const Assignment& assignment,
int start_index,
1580 bool ReplaceUnusedVehicle(
int unused_vehicle,
int active_vehicle,
1581 Assignment* compact_assignment)
const;
1583 void QuietCloseModel();
1584 void QuietCloseModelWithParameters(
1592 bool SolveMatchingModel(Assignment* assignment,
1595 bool AppendAssignmentIfFeasible(
1597 const Assignment& assignment,
1598 std::vector<std::unique_ptr<Assignment>>* assignments);
1600 void LogSolution(
const RoutingSearchParameters&
parameters,
1602 const std::string& description,
int64 solution_cost,
1603 int64 start_time_ms);
1606 Assignment* CompactAssignmentInternal(
const Assignment& assignment,
1607 bool check_compact_assignment)
const;
1612 std::string FindErrorInSearchParametersForModel(
1613 const RoutingSearchParameters& search_parameters)
const;
1615 void SetupSearch(
const RoutingSearchParameters& search_parameters);
1618 Assignment* GetOrCreateAssignment();
1619 Assignment* GetOrCreateTmpAssignment();
1620 RegularLimit* GetOrCreateLimit();
1621 RegularLimit* GetOrCreateLocalSearchLimit();
1622 RegularLimit* GetOrCreateLargeNeighborhoodSearchLimit();
1623 RegularLimit* GetOrCreateFirstSolutionLargeNeighborhoodSearchLimit();
1624 LocalSearchOperator* CreateInsertionOperator();
1625 LocalSearchOperator* CreateMakeInactiveOperator();
1627 LocalSearchOperator* CreateCPOperator(
const T& operator_factory) {
1628 return operator_factory(solver_.get(), nexts_,
1630 ? std::vector<IntVar*>()
1632 vehicle_start_class_callback_);
1635 LocalSearchOperator* CreateCPOperator() {
1636 return CreateCPOperator(absl::bind_front(MakeLocalSearchOperator<T>));
1638 template <
class T,
class Arg>
1639 LocalSearchOperator* CreateOperator(
const Arg& arg) {
1640 return solver_->RevAlloc(
new T(nexts_,
1642 ? std::vector<IntVar*>()
1644 vehicle_start_class_callback_, arg));
1647 LocalSearchOperator* CreatePairOperator() {
1648 return CreateOperator<T>(pickup_delivery_pairs_);
1650 void CreateNeighborhoodOperators(
const RoutingSearchParameters&
parameters);
1651 LocalSearchOperator* ConcatenateOperators(
1652 const RoutingSearchParameters& search_parameters,
1653 const std::vector<LocalSearchOperator*>& operators)
const;
1654 LocalSearchOperator* GetNeighborhoodOperators(
1655 const RoutingSearchParameters& search_parameters)
const;
1656 std::vector<LocalSearchFilterManager::FilterEvent>
1657 GetOrCreateLocalSearchFilters(
const RoutingSearchParameters&
parameters,
1658 bool filter_cost =
true);
1659 LocalSearchFilterManager* GetOrCreateLocalSearchFilterManager(
1661 std::vector<LocalSearchFilterManager::FilterEvent>
1662 GetOrCreateFeasibilityFilters(
const RoutingSearchParameters&
parameters);
1663 LocalSearchFilterManager* GetOrCreateFeasibilityFilterManager(
1665 LocalSearchFilterManager* GetOrCreateStrongFeasibilityFilterManager(
1667 DecisionBuilder* CreateSolutionFinalizer(SearchLimit* lns_limit);
1668 DecisionBuilder* CreateFinalizerForMinimizedAndMaximizedVariables();
1669 void CreateFirstSolutionDecisionBuilders(
1670 const RoutingSearchParameters& search_parameters);
1671 DecisionBuilder* GetFirstSolutionDecisionBuilder(
1672 const RoutingSearchParameters& search_parameters)
const;
1673 IntVarFilteredDecisionBuilder* GetFilteredFirstSolutionDecisionBuilderOrNull(
1674 const RoutingSearchParameters&
parameters)
const;
1675 LocalSearchPhaseParameters* CreateLocalSearchParameters(
1676 const RoutingSearchParameters& search_parameters);
1677 DecisionBuilder* CreateLocalSearchDecisionBuilder(
1678 const RoutingSearchParameters& search_parameters);
1679 void SetupDecisionBuilders(
const RoutingSearchParameters& search_parameters);
1680 void SetupMetaheuristics(
const RoutingSearchParameters& search_parameters);
1681 void SetupAssignmentCollector(
1682 const RoutingSearchParameters& search_parameters);
1683 void SetupTrace(
const RoutingSearchParameters& search_parameters);
1684 void SetupImprovementLimit(
const RoutingSearchParameters& search_parameters);
1685 void SetupSearchMonitors(
const RoutingSearchParameters& search_parameters);
1686 bool UsesLightPropagation(
1687 const RoutingSearchParameters& search_parameters)
const;
1694 void DetectImplicitPickupAndDeliveries();
1696 int GetVehicleStartClass(
int64 start)
const;
1698 void InitSameVehicleGroups(
int number_of_groups) {
1699 same_vehicle_group_.assign(
Size(), 0);
1700 same_vehicle_groups_.assign(number_of_groups, {});
1702 void SetSameVehicleGroup(
int index,
int group) {
1703 same_vehicle_group_[
index] = group;
1704 same_vehicle_groups_[group].push_back(
index);
1708 std::unique_ptr<Solver> solver_;
1711 int max_active_vehicles_;
1712 Constraint* no_cycle_constraint_ =
nullptr;
1714 std::vector<IntVar*> nexts_;
1715 std::vector<IntVar*> vehicle_vars_;
1716 std::vector<IntVar*> active_;
1718 std::vector<IntVar*> vehicle_active_;
1719 std::vector<IntVar*> vehicle_costs_considered_;
1724 std::vector<IntVar*> is_bound_to_end_;
1725 mutable RevSwitch is_bound_to_end_ct_added_;
1727 absl::flat_hash_map<std::string, DimensionIndex> dimension_name_to_index_;
1733 std::vector<std::unique_ptr<GlobalDimensionCumulOptimizer> >
1734 global_dimension_optimizers_;
1736 std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >
1737 local_dimension_optimizers_;
1738 std::vector<std::unique_ptr<LocalDimensionCumulOptimizer> >
1739 local_dimension_mp_optimizers_;
1742 std::string primary_constrained_dimension_;
1744 IntVar* cost_ =
nullptr;
1745 std::vector<int> vehicle_to_transit_cost_;
1746 std::vector<int64> fixed_cost_of_vehicle_;
1747 std::vector<CostClassIndex> cost_class_index_of_vehicle_;
1748 bool has_vehicle_with_zero_cost_class_;
1749 std::vector<int64> linear_cost_factor_of_vehicle_;
1750 std::vector<int64> quadratic_cost_factor_of_vehicle_;
1751 bool vehicle_amortized_cost_factors_set_;
1762 std::vector<bool> consider_empty_route_costs_;
1766 bool costs_are_homogeneous_across_vehicles_;
1767 bool cache_callbacks_;
1768 mutable std::vector<CostCacheElement> cost_cache_;
1769 std::vector<VehicleClassIndex> vehicle_class_index_of_vehicle_;
1773 VehicleTypeContainer vehicle_type_container_;
1774 std::function<int(
int64)> vehicle_start_class_callback_;
1777 std::vector<std::vector<DisjunctionIndex> > index_to_disjunctions_;
1779 std::vector<ValuedNodes<int64> > same_vehicle_costs_;
1782 std::vector<absl::flat_hash_set<int>> allowed_vehicles_;
1786 IndexPairs implicit_pickup_delivery_pairs_without_alternatives_;
1787 std::vector<std::pair<DisjunctionIndex, DisjunctionIndex> >
1788 pickup_delivery_disjunctions_;
1793 std::vector<std::vector<std::pair<int, int> > > index_to_pickup_index_pairs_;
1795 std::vector<std::vector<std::pair<int, int> > >
1796 index_to_delivery_index_pairs_;
1798 std::vector<PickupAndDeliveryPolicy> vehicle_pickup_delivery_policy_;
1800 std::vector<int> same_vehicle_group_;
1802 std::vector<std::vector<int>> same_vehicle_groups_;
1805 std::vector<int> index_to_visit_type_;
1807 std::vector<VisitTypePolicy> index_to_type_policy_;
1809 std::vector<std::vector<int> > single_nodes_of_type_;
1810 std::vector<std::vector<int> > pair_indices_of_type_;
1812 std::vector<absl::flat_hash_set<int> >
1813 hard_incompatible_types_per_type_index_;
1814 bool has_hard_type_incompatibilities_;
1815 std::vector<absl::flat_hash_set<int> >
1816 temporal_incompatible_types_per_type_index_;
1817 bool has_temporal_type_incompatibilities_;
1819 std::vector<std::vector<absl::flat_hash_set<int> > >
1820 same_vehicle_required_type_alternatives_per_type_index_;
1821 bool has_same_vehicle_type_requirements_;
1822 std::vector<std::vector<absl::flat_hash_set<int> > >
1823 required_type_alternatives_when_adding_type_index_;
1824 std::vector<std::vector<absl::flat_hash_set<int> > >
1825 required_type_alternatives_when_removing_type_index_;
1826 bool has_temporal_type_requirements_;
1827 absl::flat_hash_map<int, absl::flat_hash_set<VisitTypePolicy> >
1828 trivially_infeasible_visit_types_to_policies_;
1845 std::vector<std::vector<int> > topologically_sorted_visit_types_;
1847 int num_visit_types_;
1850 std::vector<int> index_to_equivalence_class_;
1851 std::vector<int> index_to_vehicle_;
1852 std::vector<int64> starts_;
1853 std::vector<int64> ends_;
1856 RoutingIndexManager manager_;
1857 int start_end_count_;
1859 bool closed_ =
false;
1861 bool enable_deep_serialization_ =
true;
1864 std::vector<DecisionBuilder*> first_solution_decision_builders_;
1865 std::vector<IntVarFilteredDecisionBuilder*>
1866 first_solution_filtered_decision_builders_;
1869 FirstSolutionStrategy::UNSET;
1870 std::vector<LocalSearchOperator*> local_search_operators_;
1871 std::vector<SearchMonitor*> monitors_;
1872 SolutionCollector* collect_assignments_ =
nullptr;
1873 SolutionCollector* collect_one_assignment_ =
nullptr;
1874 SolutionCollector* packed_dimensions_assignment_collector_ =
nullptr;
1875 DecisionBuilder* solve_db_ =
nullptr;
1876 DecisionBuilder* improve_db_ =
nullptr;
1877 DecisionBuilder* restore_assignment_ =
nullptr;
1878 DecisionBuilder* restore_tmp_assignment_ =
nullptr;
1879 Assignment* assignment_ =
nullptr;
1880 Assignment* preassignment_ =
nullptr;
1881 Assignment* tmp_assignment_ =
nullptr;
1882 std::vector<IntVar*> extra_vars_;
1883 std::vector<IntervalVar*> extra_intervals_;
1884 std::vector<LocalSearchOperator*> extra_operators_;
1885 LocalSearchFilterManager* local_search_filter_manager_ =
nullptr;
1886 LocalSearchFilterManager* feasibility_filter_manager_ =
nullptr;
1887 LocalSearchFilterManager* strong_feasibility_filter_manager_ =
nullptr;
1888 std::vector<LocalSearchFilterManager::FilterEvent> extra_filters_;
1890 std::vector<std::pair<IntVar*, int64>> finalizer_variable_cost_pairs_;
1891 std::vector<std::pair<IntVar*, int64>> finalizer_variable_target_pairs_;
1892 absl::flat_hash_map<IntVar*, int> finalizer_variable_cost_index_;
1893 absl::flat_hash_set<IntVar*> finalizer_variable_target_set_;
1894 std::unique_ptr<SweepArranger> sweep_arranger_;
1897 RegularLimit* limit_ =
nullptr;
1898 RegularLimit* ls_limit_ =
nullptr;
1899 RegularLimit* lns_limit_ =
nullptr;
1900 RegularLimit* first_solution_lns_limit_ =
nullptr;
1902 typedef std::pair<int64, int64> CacheKey;
1903 typedef absl::flat_hash_map<CacheKey, int64> TransitCallbackCache;
1904 typedef absl::flat_hash_map<CacheKey, StateDependentTransit>
1905 StateDependentTransitCallbackCache;
1907 std::vector<TransitCallback1> unary_transit_evaluators_;
1908 std::vector<TransitCallback2> transit_evaluators_;
1919 std::vector<bool> is_transit_evaluator_positive_;
1920 std::vector<VariableIndexEvaluator2> state_dependent_transit_evaluators_;
1921 std::vector<std::unique_ptr<StateDependentTransitCallbackCache>>
1922 state_dependent_transit_evaluators_cache_;
2011 std::vector<int> tasks_by_start_min_;
2012 std::vector<int> tasks_by_end_max_;
2013 std::vector<int> event_of_task_;
2014 std::vector<int> nonchain_tasks_by_start_max_;
2016 std::vector<int64> total_duration_before_;
2034 std::vector<int64>* values);
2038 #endif // !defined(SWIG)
2054 return "GlobalVehicleBreaksConstraint";
2057 void Post()
override;
2061 void PropagateNode(
int node);
2062 void PropagateVehicle(
int vehicle);
2063 void PropagateMaxBreakDistance(
int vehicle);
2067 std::vector<Demon*> vehicle_demons_;
2068 std::vector<int64> path_;
2074 void FillPartialPathOfVehicle(
int vehicle);
2075 void FillPathTravels(
const std::vector<int64>& path);
2087 class TaskTranslator {
2091 before_start_(before_start),
2092 after_start_(after_start) {}
2097 if (start_ !=
nullptr) {
2099 }
else if (interval_ !=
nullptr) {
2100 interval_->SetStartMin(
value);
2104 if (start_ !=
nullptr) {
2106 }
else if (interval_ !=
nullptr) {
2107 interval_->SetStartMax(
value);
2111 if (interval_ !=
nullptr) {
2112 interval_->SetDurationMin(
value);
2116 if (start_ !=
nullptr) {
2118 }
else if (interval_ !=
nullptr) {
2119 interval_->SetEndMin(
value);
2123 if (start_ !=
nullptr) {
2125 }
else if (interval_ !=
nullptr) {
2126 interval_->SetEndMax(
value);
2131 IntVar* start_ =
nullptr;
2132 int64 before_start_;
2134 IntervalVar* interval_ =
nullptr;
2138 std::vector<TaskTranslator> task_translators_;
2141 DisjunctivePropagator disjunctive_propagator_;
2142 DisjunctivePropagator::Tasks tasks_;
2145 TravelBounds travel_bounds_;
2154 const std::function<
int64(
int64)>& next_accessor);
2193 const std::function<
int64(
int64)>& next_accessor);
2203 std::vector<TypePolicyOccurrence> occurrences_of_type_;
2204 std::vector<int64> current_route_visits_;
2211 bool check_hard_incompatibilities);
2215 bool HasRegulationsToCheck()
const override;
2216 bool CheckTypeRegulations(
int type,
VisitTypePolicy policy,
int pos)
override;
2220 bool check_hard_incompatibilities_;
2231 bool HasRegulationsToCheck()
const override;
2232 void OnInitializeCheck()
override {
2233 types_with_same_vehicle_requirements_on_route_.clear();
2238 bool CheckRequiredTypesCurrentlyOnRoute(
2239 const std::vector<absl::flat_hash_set<int> >& required_type_alternatives,
2242 bool CheckTypeRegulations(
int type,
VisitTypePolicy policy,
int pos)
override;
2243 bool FinalizeCheck()
const override;
2245 absl::flat_hash_set<int> types_with_same_vehicle_requirements_on_route_;
2292 void Post()
override;
2296 void PropagateNodeRegulations(
int node);
2297 void CheckRegulationsOnVehicle(
int vehicle);
2302 std::vector<Demon*> vehicle_demons_;
2324 : bound_costs_(num_bounds, default_bound_cost) {}
2327 int Size() {
return bound_costs_.size(); }
2332 std::vector<BoundCost> bound_costs_;
2334 #endif // !defined SWIG
2368 int64 vehicle_class)
const {
2369 return model_->TransitCallback(class_evaluators_[vehicle_class])(from_index,
2379 #if !defined(SWIGPYTHON)
2380 const std::vector<IntVar*>&
cumuls()
const {
return cumuls_; }
2384 const std::vector<IntVar*>&
transits()
const {
return transits_; }
2385 const std::vector<IntVar*>&
slacks()
const {
return slacks_; }
2386 #if !defined(SWIGCSHARP) && !defined(SWIGJAVA)
2389 return forbidden_intervals_;
2394 int64 max_value)
const;
2398 int64 min_value)
const {
2401 forbidden_intervals_[
index];
2402 const auto first_forbidden_interval_it =
2405 min_value >= first_forbidden_interval_it->start) {
2407 return CapAdd(first_forbidden_interval_it->end, 1);
2417 int64 max_value)
const {
2420 forbidden_intervals_[
index];
2421 const auto last_forbidden_interval_it =
2424 max_value <= last_forbidden_interval_it->end) {
2426 return CapSub(last_forbidden_interval_it->start, 1);
2433 return vehicle_capacities_;
2438 return model_->TransitCallback(
2439 class_evaluators_[vehicle_to_class_[vehicle]]);
2445 int vehicle)
const {
2446 return model_->UnaryTransitCallbackOrNull(
2447 class_evaluators_[vehicle_to_class_[vehicle]]);
2452 return model()->is_transit_evaluator_positive_
2453 [class_evaluators_[vehicle_to_class_[vehicle]]];
2458 void SetSpanUpperBoundForVehicle(int64 upper_bound, int vehicle);
2554 #if !defined(SWIGPYTHON)
2556 int pre_travel_evaluator,
2557 int post_travel_evaluator);
2558 #endif // !defined(SWIGPYTHON)
2562 std::vector<int64> node_visit_transits);
2575 #if !defined(SWIGPYTHON)
2579 std::vector<IntervalVar*> breaks,
int vehicle,
2580 std::vector<int64> node_visit_transits,
2589 const std::vector<std::pair<int64, int64> >&
2593 int GetPreTravelEvaluatorOfVehicle(int vehicle) const;
2608 const std::string&
name()
const {
return name_; }
2613 return path_precedence_graph_;
2634 int delivery)
const;
2643 node_precedences_.push_back(precedence);
2646 return node_precedences_;
2655 return vehicle_span_upper_bounds_[vehicle];
2659 return vehicle_span_upper_bounds_;
2663 return vehicle_span_cost_coefficients_[vehicle];
2667 return vehicle_span_cost_coefficients_;
2671 return global_span_cost_coefficient_;
2676 return global_optimizer_offset_;
2679 if (vehicle >= local_optimizer_offset_for_vehicle_.size()) {
2682 DCHECK_GE(local_optimizer_offset_for_vehicle_[vehicle], 0);
2683 return local_optimizer_offset_for_vehicle_[vehicle];
2691 vehicle_soft_span_upper_bound_ = absl::make_unique<SimpleBoundCosts>(
2694 vehicle_soft_span_upper_bound_->bound_cost(vehicle) = bound_cost;
2697 return vehicle_soft_span_upper_bound_ !=
nullptr;
2700 int vehicle)
const {
2702 return vehicle_soft_span_upper_bound_->bound_cost(vehicle);
2709 vehicle_quadratic_cost_soft_span_upper_bound_ =
2710 absl::make_unique<SimpleBoundCosts>(
2713 vehicle_quadratic_cost_soft_span_upper_bound_->bound_cost(vehicle) =
2717 return vehicle_quadratic_cost_soft_span_upper_bound_ !=
nullptr;
2720 int vehicle)
const {
2722 return vehicle_quadratic_cost_soft_span_upper_bound_->bound_cost(vehicle);
2733 struct PiecewiseLinearCost {
2734 PiecewiseLinearCost() :
var(nullptr),
cost(nullptr) {}
2736 std::unique_ptr<PiecewiseLinearFunction>
cost;
2741 const std::string&
name,
2744 const std::string&
name, SelfBased);
2745 void Initialize(
const std::vector<int>& transit_evaluators,
2746 const std::vector<int>& state_dependent_transit_evaluators,
2748 void InitializeCumuls();
2749 void InitializeTransits(
2750 const std::vector<int>& transit_evaluators,
2751 const std::vector<int>& state_dependent_transit_evaluators,
2753 void InitializeTransitVariables(
int64 slack_max);
2755 void SetupCumulVarSoftUpperBoundCosts(
2756 std::vector<IntVar*>* cost_elements)
const;
2758 void SetupCumulVarSoftLowerBoundCosts(
2759 std::vector<IntVar*>* cost_elements)
const;
2760 void SetupCumulVarPiecewiseLinearCosts(
2761 std::vector<IntVar*>* cost_elements)
const;
2764 void SetupGlobalSpanCost(std::vector<IntVar*>* cost_elements)
const;
2765 void SetupSlackAndDependentTransitCosts()
const;
2767 void CloseModel(
bool use_light_propagation);
2769 void SetOffsetForGlobalOptimizer(
int64 offset) {
2773 void SetVehicleOffsetsForLocalOptimizer(std::vector<int64> offsets) {
2775 std::transform(offsets.begin(), offsets.end(), offsets.begin(),
2776 [](
int64 offset) { return std::max(Zero(), offset); });
2777 local_optimizer_offset_for_vehicle_ = std::move(offsets);
2780 std::vector<IntVar*> cumuls_;
2781 std::vector<SortedDisjointIntervalList> forbidden_intervals_;
2782 std::vector<IntVar*> capacity_vars_;
2783 const std::vector<int64> vehicle_capacities_;
2784 std::vector<IntVar*> transits_;
2785 std::vector<IntVar*> fixed_transits_;
2788 std::vector<int> class_evaluators_;
2789 std::vector<int64> vehicle_to_class_;
2791 ReverseArcListGraph<int, int> path_precedence_graph_;
2797 std::vector<NodePrecedence> node_precedences_;
2802 const RoutingDimension*
const base_dimension_;
2807 std::vector<int> state_dependent_class_evaluators_;
2808 std::vector<int64> state_dependent_vehicle_to_class_;
2813 std::vector<PickupToDeliveryLimitFunction>
2814 pickup_to_delivery_limits_per_pair_index_;
2817 bool break_constraints_are_initialized_ =
false;
2819 std::vector<std::vector<IntervalVar*> > vehicle_break_intervals_;
2820 std::vector<std::vector<std::pair<int64, int64> > >
2821 vehicle_break_distance_duration_;
2826 std::vector<int> vehicle_pre_travel_evaluators_;
2827 std::vector<int> vehicle_post_travel_evaluators_;
2829 std::vector<IntVar*> slacks_;
2830 std::vector<IntVar*> dependent_transits_;
2831 std::vector<int64> vehicle_span_upper_bounds_;
2832 int64 global_span_cost_coefficient_;
2833 std::vector<int64> vehicle_span_cost_coefficients_;
2834 std::vector<SoftBound> cumul_var_soft_upper_bound_;
2835 std::vector<SoftBound> cumul_var_soft_lower_bound_;
2836 std::vector<PiecewiseLinearCost> cumul_var_piecewise_linear_cost_;
2838 const std::string name_;
2839 int64 global_optimizer_offset_;
2840 std::vector<int64> local_optimizer_offset_for_vehicle_;
2842 std::unique_ptr<SimpleBoundCosts> vehicle_soft_span_upper_bound_;
2843 std::unique_ptr<SimpleBoundCosts>
2844 vehicle_quadratic_cost_soft_span_upper_bound_;
2848 const std::vector<RoutingDimension*>& dimensions,
2849 const RoutingSearchParameters&
parameters,
bool filter_objective_cost,
2850 std::vector<LocalSearchFilterManager::FilterEvent>* filters);
2860 explicit SweepArranger(
const std::vector<std::pair<int64, int64>>& points);
2866 std::vector<int> coordinates_;
2876 std::vector<IntVar*> variables,
2877 std::vector<int64> targets);
2886 : vehicle_type_container_(&vehicle_type_container) {}
2890 int Type(
int vehicle)
const {
return vehicle_type_container_->
Type(vehicle); }
2893 sorted_vehicle_classes_per_type_ =
2895 const std::vector<std::deque<int>>& vehicles_per_class =
2897 vehicles_per_vehicle_class_.resize(vehicles_per_class.size());
2898 for (
int i = 0; i < vehicles_per_vehicle_class_.size(); i++) {
2899 vehicles_per_vehicle_class_[i].resize(vehicles_per_class[i].size());
2900 std::copy(vehicles_per_class[i].begin(), vehicles_per_class[i].end(),
2901 vehicles_per_vehicle_class_[i].begin());
2907 const std::set<VehicleClassEntry>& vehicle_classes =
2908 sorted_vehicle_classes_per_type_[type];
2909 if (vehicle_classes.empty()) {
2912 const int vehicle_class = (vehicle_classes.begin())->vehicle_class;
2913 DCHECK(!vehicles_per_vehicle_class_[vehicle_class].empty());
2914 return vehicles_per_vehicle_class_[vehicle_class][0];
2919 std::vector<int>& vehicles = vehicles_per_vehicle_class_[vehicle_class];
2920 if (vehicles.empty()) {
2923 std::set<VehicleClassEntry>& vehicle_classes =
2924 sorted_vehicle_classes_per_type_[
Type(vehicle)];
2925 const auto& insertion =
2926 vehicle_classes.insert({vehicle_class, fixed_cost});
2927 DCHECK(insertion.second);
2929 vehicles.push_back(vehicle);
2938 int type, std::function<
bool(
int)> vehicle_is_compatible);
2941 using VehicleClassEntry =
2945 std::vector<std::set<VehicleClassEntry> > sorted_vehicle_classes_per_type_;
2946 std::vector<std::vector<int> > vehicles_per_vehicle_class_;
2969 std::unique_ptr<IntVarFilteredHeuristic> heuristic);
2982 const std::unique_ptr<IntVarFilteredHeuristic> heuristic_;
3002 virtual std::string
DebugString()
const {
return "IntVarFilteredHeuristic"; }
3020 if (!is_in_delta_[
index]) {
3022 delta_indices_.push_back(
index);
3023 is_in_delta_[
index] =
true;
3039 int Size()
const {
return vars_.size(); }
3050 bool FilterAccept();
3053 const std::vector<IntVar*> vars_;
3055 std::vector<int> delta_indices_;
3056 std::vector<bool> is_in_delta_;
3060 int64 number_of_decisions_;
3061 int64 number_of_rejects_;
3072 const std::function<
int64(
int64)>& next_accessor);
3096 bool InitializeSolution()
override;
3099 std::vector<int64> start_chain_ends_;
3100 std::vector<int64> end_chain_starts_;
3108 std::function<
int64(
int64)> penalty_evaluator,
3131 std::vector<std::vector<StartEndValue> >
3138 template <
class Queue>
3140 std::vector<std::vector<StartEndValue> >* start_end_distances_per_node,
3141 Queue* priority_queue);
3155 std::vector<ValuedPosition>* valued_positions);
3164 int64 insert_before,
3207 std::function<
int64(
int64)> penalty_evaluator,
3213 return "GlobalCheapestInsertionFilteredHeuristic";
3219 typedef absl::flat_hash_set<PairEntry*> PairEntries;
3220 typedef absl::flat_hash_set<NodeEntry*> NodeEntries;
3228 void InsertPairsAndNodesByRequirementTopologicalOrder();
3236 void InsertPairs(
const std::vector<int>& pair_indices);
3245 void InsertNodesOnRoutes(
const std::vector<int>& nodes,
3246 const absl::flat_hash_set<int>& vehicles);
3253 void SequentialInsertNodes(
const std::vector<int>& nodes);
3258 void DetectUsedVehicles(std::vector<bool>* is_vehicle_used,
3259 std::vector<int>* unused_vehicles,
3260 absl::flat_hash_set<int>* used_vehicles);
3265 void InsertFarthestNodesAsSeeds();
3275 template <
class Queue>
3277 std::vector<std::vector<StartEndValue>>* start_end_distances_per_node,
3278 Queue* priority_queue, std::vector<bool>* is_vehicle_used);
3283 void InitializePairPositions(
3284 const std::vector<int>& pair_indices,
3286 std::vector<PairEntries>* pickup_to_entries,
3287 std::vector<PairEntries>* delivery_to_entries);
3293 void InitializeInsertionEntriesPerformingPair(
3296 std::vector<PairEntries>* pickup_to_entries,
3297 std::vector<PairEntries>* delivery_to_entries);
3300 void UpdatePairPositions(
const std::vector<int>& pair_indices,
int vehicle,
3303 std::vector<PairEntries>* pickup_to_entries,
3304 std::vector<PairEntries>* delivery_to_entries) {
3305 UpdatePickupPositions(pair_indices, vehicle, insert_after, priority_queue,
3306 pickup_to_entries, delivery_to_entries);
3307 UpdateDeliveryPositions(pair_indices, vehicle, insert_after, priority_queue,
3308 pickup_to_entries, delivery_to_entries);
3312 void UpdatePickupPositions(
const std::vector<int>& pair_indices,
int vehicle,
3313 int64 pickup_insert_after,
3315 std::vector<PairEntries>* pickup_to_entries,
3316 std::vector<PairEntries>* delivery_to_entries);
3319 void UpdateDeliveryPositions(
3320 const std::vector<int>& pair_indices,
int vehicle,
3321 int64 delivery_insert_after,
3323 std::vector<PairEntries>* pickup_to_entries,
3324 std::vector<PairEntries>* delivery_to_entries);
3327 void DeletePairEntry(PairEntry* entry,
3329 std::vector<PairEntries>* pickup_to_entries,
3330 std::vector<PairEntries>* delivery_to_entries);
3333 void InitializePositions(
const std::vector<int>& nodes,
3335 std::vector<NodeEntries>* position_to_node_entries,
3336 const absl::flat_hash_set<int>& vehicles);
3342 void InitializeInsertionEntriesPerformingNode(
3343 int64 node,
int64 penalty,
const absl::flat_hash_set<int>& vehicles,
3345 std::vector<NodeEntries>* position_to_node_entries);
3348 void UpdatePositions(
const std::vector<int>& nodes,
int vehicle,
3349 int64 insert_after,
bool all_vehicles,
3351 std::vector<NodeEntries>* node_entries);
3354 void DeleteNodeEntry(NodeEntry* entry,
3356 std::vector<NodeEntries>* node_entries);
3360 void ComputeNeighborhoods();
3364 bool IsNeighborForCostClass(
int cost_class,
int64 node_index,
3365 int64 neighbor_index)
const;
3368 const std::vector<int64>& GetNeighborsOfNodeForCostClass(
3369 int cost_class,
int64 node_index)
const {
3372 : node_index_to_neighbors_by_cost_class_[node_index][cost_class]
3373 ->PositionsSetAtLeastOnce();
3376 int64 NumNonStartEndNodes()
const {
3380 void ResetVehicleIndices()
override {
3381 node_index_to_vehicle_.assign(node_index_to_vehicle_.size(), -1);
3384 void SetVehicleIndex(
int64 node,
int vehicle)
override {
3385 DCHECK_LT(node, node_index_to_vehicle_.size());
3386 node_index_to_vehicle_[node] = vehicle;
3391 bool CheckVehicleIndices()
const;
3393 GlobalCheapestInsertionParameters gci_params_;
3395 std::vector<int> node_index_to_vehicle_;
3398 std::vector<std::vector<std::unique_ptr<SparseBitset<int64> > > >
3399 node_index_to_neighbors_by_cost_class_;
3405 std::vector<int64> all_nodes_;
3423 return "LocalCheapestInsertionFilteredHeuristic";
3432 void ComputeEvaluatorSortedPositions(
int64 node,
3433 std::vector<int64>* sorted_positions);
3438 void ComputeEvaluatorSortedPositionsOnRouteAfter(
3440 std::vector<int64>* sorted_positions);
3442 std::vector<std::vector<StartEndValue>> start_end_distances_per_node_;
3455 class PartialRoutesAndLargeVehicleIndicesFirst {
3457 explicit PartialRoutesAndLargeVehicleIndicesFirst(
3459 : builder_(builder) {}
3460 bool operator()(
int vehicle1,
int vehicle2)
const;
3466 template <
typename Iterator>
3467 std::vector<int64> GetPossibleNextsFromIterator(
int64 node, Iterator start,
3468 Iterator end)
const {
3470 std::vector<int64> nexts;
3471 for (Iterator it = start; it != end; ++it) {
3474 nexts.push_back(
next);
3480 virtual void SortSuccessors(
int64 node, std::vector<int64>* successors) = 0;
3482 const std::vector<int64>& successors) = 0;
3496 return "EvaluatorCheapestAdditionFilteredHeuristic";
3501 void SortSuccessors(
int64 node, std::vector<int64>* successors)
override;
3503 const std::vector<int64>& successors)
override;
3519 return "ComparatorCheapestAdditionFilteredHeuristic";
3524 void SortSuccessors(
int64 node, std::vector<int64>* successors)
override;
3526 const std::vector<int64>& successors)
override;
3566 template <
typename S>
3575 return saving.second / size_squared_;
3579 return (saving.second % size_squared_) /
Size();
3583 return (saving.second % size_squared_) %
Size();
3611 void AddSymmetricArcsToAdjacencyLists(
3612 std::vector<std::vector<int64> >* adjacency_lists);
3621 void ComputeSavings();
3623 Saving BuildSaving(
int64 saving,
int vehicle_type,
int before_node,
3624 int after_node)
const {
3625 return std::make_pair(saving, vehicle_type * size_squared_ +
3626 before_node *
Size() + after_node);
3632 int64 MaxNumNeighborsPerNode(
int num_vehicle_types)
const;
3635 const SavingsParameters savings_params_;
3636 int64 size_squared_;
3650 return "SequentialSavingsFilteredHeuristic";
3658 void BuildRoutesFromSavings()
override;
3659 double ExtraSavingsMemoryMultiplicativeFactor()
const override {
return 1.0; }
3671 return "ParallelSavingsFilteredHeuristic";
3685 void BuildRoutesFromSavings()
override;
3687 double ExtraSavingsMemoryMultiplicativeFactor()
const override {
return 2.0; }
3693 void MergeRoutes(
int first_vehicle,
int second_vehicle,
int64 before_node,
3697 std::vector<int64> first_node_on_route_;
3698 std::vector<int64> last_node_on_route_;
3702 std::vector<int> vehicle_of_first_or_last_node_;
3713 bool use_minimum_matching);
3717 return "ChristofidesFilteredHeuristic";
3721 const bool use_minimum_matching_;
3730 const RoutingSearchParameters& search_parameters,
3731 const Assignment* initial_solution,
3732 Assignment* solution);
3738 BasePathFilter(
const std::vector<IntVar*>& nexts,
int next_domain_size);
3741 int64 objective_min,
int64 objective_max)
override;
3765 enum Status { UNKNOWN, ENABLED, DISABLED };
3767 virtual bool DisableFiltering()
const {
return false; }
3768 virtual void OnBeforeSynchronizePaths() {}
3769 virtual void OnAfterSynchronizePaths() {}
3770 virtual void OnSynchronizePathFromStart(
int64 start) {}
3771 virtual void InitializeAcceptPath() {}
3772 virtual bool AcceptPath(
int64 path_start,
int64 chain_start,
3773 int64 chain_end) = 0;
3774 virtual bool FinalizeAcceptPath(
const Assignment*
delta,
int64 objective_min,
3775 int64 objective_max) {
3779 void ComputePathStarts(std::vector<int64>* path_starts,
3780 std::vector<int>* index_to_path);
3781 bool HavePathsChanged();
3782 void SynchronizeFullAssignment();
3783 void UpdateAllRanks();
3784 void UpdatePathRanksFromStart(
int start);
3786 std::vector<int64> node_path_starts_;
3787 std::vector<int64> starts_;
3788 std::vector<int> paths_;
3789 SparseBitset<int64> new_synchronized_unperformed_nodes_;
3790 std::vector<int64> new_nexts_;
3791 std::vector<int> delta_touched_;
3792 SparseBitset<> touched_paths_;
3794 std::vector<std::pair<int64, int64> > touched_path_chain_start_ends_;
3796 std::vector<int> ranks_;
3816 std::string
DebugString()
const override {
return "CPFeasibilityFilter"; }
3818 int64 objective_min,
int64 objective_max)
override;
3824 static const int64 kUnassigned;
3835 const RoutingModel& routing_model);
3837 const RoutingModel& routing_model);
3839 const RoutingModel& routing_model);
3841 const RoutingModel& routing_model);
3843 const std::vector<RoutingDimension*>& dimensions,
3844 const RoutingSearchParameters&
parameters,
bool filter_objective_cost,
3845 std::vector<LocalSearchFilterManager::FilterEvent>* filters);
3847 const PathState* path_state,
3848 const std::vector<RoutingDimension*>& dimensions,
3849 std::vector<LocalSearchFilterManager::FilterEvent>* filters);
3851 const RoutingDimension& dimension,
3853 bool propagate_own_objective_value,
bool filter_objective_cost,
3854 bool can_use_lp =
true);
3856 const RoutingDimension& dimension);
3858 GlobalDimensionCumulOptimizer* optimizer,
bool filter_objective_cost);
3861 const std::vector<RoutingModel::PickupAndDeliveryPolicy>& vehicle_policies);
3863 const RoutingModel& routing_model);
3865 const RoutingModel& routing_model,
const RoutingDimension& dimension);
3870 #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
absl::StrongVector< DimensionIndex, int64 > dimension_evaluator_classes
dimension_evaluators[d]->Run(from, to) is the transit value of arc from->to for a dimension d.
~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 if 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...
absl::StrongVector< DimensionIndex, int64 > dimension_end_cumuls_max
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...
absl::StrongVector< DimensionIndex, int64 > dimension_start_cumuls_max
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.
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
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.
absl::StrongVector< DimensionIndex, int64 > dimension_capacities
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...
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...
absl::StrongVector< DimensionIndex, int64 > dimension_start_cumuls_min
Bounds of cumul variables at start and end vehicle nodes.
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.
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
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.
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.
absl::StrongVector< DimensionIndex, int64 > dimension_end_cumuls_min
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.