14#ifndef OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_FILTERS_H_
15#define OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_FILTERS_H_
24#include "absl/strings/string_view.h"
29#include "ortools/constraint_solver/routing_parameters.pb.h"
37 const RoutingModel& routing_model);
41 const RoutingModel& routing_model,
bool filter_cost);
45 const RoutingModel& routing_model);
49 const RoutingModel& routing_model);
54 const RoutingModel& routing_model,
55 const std::vector<PickupDeliveryPair>& pairs,
56 const std::vector<RoutingModel::PickupAndDeliveryPolicy>& vehicle_policies);
60 const RoutingModel& routing_model);
64 bool propagate_own_objective_value,
65 bool filter_objective_cost,
70 const RoutingDimension& dimension);
74 GlobalDimensionCumulOptimizer* optimizer,
75 GlobalDimensionCumulOptimizer* mp_optimizer,
bool filter_objective_cost);
80 LocalDimensionCumulOptimizer* optimizer,
81 LocalDimensionCumulOptimizer* mp_optimizer,
82 bool propagate_own_objective_value,
bool filter_objective_cost);
90 const PathState* path_state, std::vector<int> force_class,
91 std::vector<
const std::function<int64_t(int64_t)>*> force_per_class,
92 std::vector<int> distance_class,
93 std::vector<
const std::function<int64_t(int64_t, int64_t)>*>
95 std::vector<int64_t> path_unit_costs,
96 std::vector<bool> path_has_cost_when_empty);
103 int64_t ComputePathCost(int64_t path_start)
const;
105 const std::vector<int> force_class_;
106 const std::vector<int> distance_class_;
107 const std::vector<
const std::function<int64_t(int64_t)>*> force_per_class_;
108 const std::vector<
const std::function<int64_t(int64_t, int64_t)>*>
110 const std::vector<int64_t> path_unit_costs_;
111 const std::vector<bool> path_has_cost_when_empty_;
114 int64_t committed_total_cost_;
115 int64_t accepted_total_cost_;
116 std::vector<int64_t> committed_path_cost_;
120 Solver* solver, std::unique_ptr<PathEnergyCostChecker> checker,
121 absl::string_view dimension_name);
126 const PathState* path_state,
127 const std::vector<RoutingDimension*>&
dimensions,
128 std::vector<LocalSearchFilterManager::FilterEvent>* filters);
131 const std::vector<RoutingDimension*>&
dimensions,
132 const RoutingSearchParameters&
parameters,
bool filter_objective_cost,
133 bool use_chain_cumul_filter,
134 std::vector<LocalSearchFilterManager::FilterEvent>* filters);
140 BasePathFilter(
const std::vector<IntVar*>& nexts,
int next_domain_size);
143 int64_t objective_min, int64_t objective_max)
override;
155 int64_t
Start(
int i)
const {
return starts_[i]; }
156 int GetPath(int64_t node)
const {
return paths_[node]; }
157 int Rank(int64_t node)
const {
return ranks_[node]; }
170 enum Status { UNKNOWN, ENABLED, DISABLED };
172 virtual bool DisableFiltering()
const {
return false; }
173 virtual void OnBeforeSynchronizePaths() {}
174 virtual void OnAfterSynchronizePaths() {}
175 virtual void OnSynchronizePathFromStart(int64_t) {}
176 virtual bool InitializeAcceptPath() {
return true; }
177 virtual bool AcceptPath(int64_t path_start, int64_t chain_start,
178 int64_t chain_end) = 0;
179 virtual bool FinalizeAcceptPath(int64_t, int64_t) {
return true; }
181 void ComputePathStarts(std::vector<int64_t>* path_starts,
182 std::vector<int>* index_to_path);
183 bool HavePathsChanged();
184 void SynchronizeFullAssignment();
185 void UpdateAllRanks();
186 void UpdatePathRanksFromStart(
int start);
188 std::vector<int64_t> node_path_starts_;
189 std::vector<int64_t> starts_;
190 std::vector<int> paths_;
191 SparseBitset<int64_t> new_synchronized_unperformed_nodes_;
192 std::vector<int64_t> new_nexts_;
193 std::vector<int> delta_touched_;
194 SparseBitset<> touched_paths_;
196 std::vector<std::pair<int64_t, int64_t> > touched_path_chain_start_ends_;
198 std::vector<int> ranks_;
std::vector< int > dimensions
Generic path-based filter class.
static const int64_t kUnassigned
bool lns_detected() const
BasePathFilter(const std::vector< IntVar * > &nexts, int next_domain_size)
bool PathStartTouched(int64_t start) const
int64_t GetNext(int64_t node) const
const std::vector< int64_t > & GetTouchedPathStarts() const
bool Accept(const Assignment *delta, const Assignment *deltadelta, int64_t objective_min, int64_t objective_max) override
int GetPath(int64_t node) const
int Rank(int64_t node) const
const std::vector< int64_t > & GetNewSynchronizedUnperformedNodes() const
void OnSynchronize(const Assignment *delta) override
~BasePathFilter() override
int64_t Start(int i) const
int64_t Value(int index) const
bool IsVarSynced(int index) const
int64_t AcceptedCost() const
PathEnergyCostChecker(const PathState *path_state, std::vector< int > force_class, std::vector< const std::function< int64_t(int64_t)> * > force_per_class, std::vector< int > distance_class, std::vector< const std::function< int64_t(int64_t, int64_t)> * > distance_per_class, std::vector< int64_t > path_unit_costs, std::vector< bool > path_has_cost_when_empty)
int64_t CommittedCost() const
const std::vector< IntegerType > & PositionsSetAtLeastOnce() const
In SWIG mode, we don't want anything besides these top-level includes.
IntVarLocalSearchFilter * MakeVehicleAmortizedCostFilter(const RoutingModel &routing_model)
Returns a filter computing vehicle amortized costs.
IntVarLocalSearchFilter * MakeMaxActiveVehiclesFilter(const RoutingModel &routing_model)
Returns a filter ensuring that max active vehicles constraints are enforced.
void AppendLightWeightDimensionFilters(const PathState *path_state, const std::vector< RoutingDimension * > &dimensions, std::vector< LocalSearchFilterManager::FilterEvent > *filters)
IntVarLocalSearchFilter * MakeNodeDisjunctionFilter(const RoutingModel &routing_model, bool filter_cost)
Returns a filter ensuring that node disjunction constraints are enforced.
LocalSearchFilter * MakePathEnergyCostFilter(Solver *solver, std::unique_ptr< PathEnergyCostChecker > checker, absl::string_view dimension_name)
IntVarLocalSearchFilter * MakeCumulBoundsPropagatorFilter(const RoutingDimension &dimension)
Returns a filter handling dimension cumul bounds.
IntVarLocalSearchFilter * MakeGlobalLPCumulFilter(GlobalDimensionCumulOptimizer *optimizer, GlobalDimensionCumulOptimizer *mp_optimizer, bool filter_objective_cost)
Returns a filter checking global linear constraints and costs.
IntVarLocalSearchFilter * MakeCPFeasibilityFilter(RoutingModel *routing_model)
Returns a filter checking the current solution using CP propagation.
IntVarLocalSearchFilter * MakePathCumulFilter(const RoutingDimension &dimension, bool propagate_own_objective_value, bool filter_objective_cost, bool can_use_lp)
Returns a filter handling dimension costs and constraints.
IntVarLocalSearchFilter * MakePickupDeliveryFilter(const RoutingModel &routing_model, const std::vector< PickupDeliveryPair > &pairs, const std::vector< RoutingModel::PickupAndDeliveryPolicy > &vehicle_policies)
void AppendDimensionCumulFilters(const std::vector< RoutingDimension * > &dimensions, const RoutingSearchParameters ¶meters, bool filter_objective_cost, bool use_chain_cumul_filter, std::vector< LocalSearchFilterManager::FilterEvent > *filters)
LocalSearchFilter * MakeResourceAssignmentFilter(LocalDimensionCumulOptimizer *optimizer, LocalDimensionCumulOptimizer *mp_optimizer, bool propagate_own_objective_value, bool filter_objective_cost)
IntVarLocalSearchFilter * MakeVehicleVarFilter(const RoutingModel &routing_model)
Returns a filter checking that vehicle variable domains are respected.
IntVarLocalSearchFilter * MakeTypeRegulationsFilter(const RoutingModel &routing_model)
Returns a filter ensuring type regulation constraints are enforced.