14 #ifndef OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_LP_SCHEDULING_H_ 15 #define OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_LP_SCHEDULING_H_ 17 #include "absl/memory/memory.h" 19 #include "ortools/glop/lp_solver.h" 42 return propagated_bounds_[PositiveNode(index)];
46 const int64 negated_upper_bound = propagated_bounds_[NegativeNode(index)];
47 return negated_upper_bound == kint64min ? kint64max : -negated_upper_bound;
60 static const int kNoParent;
61 static const int kParentToBePropagated;
65 int PositiveNode(
int index)
const {
return 2 * index; }
66 int NegativeNode(
int index)
const {
return 2 * index + 1; }
68 void AddNodeToQueue(
int node) {
69 if (!node_in_queue_[node]) {
70 bf_queue_.push_back(node);
71 node_in_queue_[node] =
true;
78 void AddArcs(
int first_index,
int second_index, int64 offset);
80 bool InitializeArcsAndBounds(
const std::function<int64(int64)>& next_accessor,
83 bool UpdateCurrentLowerBoundOfNode(
int node, int64 new_lb);
85 bool DisassembleSubtree(
int source,
int target);
87 bool CleanupAndReturnFalse() {
89 for (
int node_to_cleanup : bf_queue_) {
90 node_in_queue_[node_to_cleanup] =
false;
96 const RoutingDimension& dimension_;
97 const int64 num_nodes_;
102 std::vector<std::vector<ArcInfo>> outgoing_arcs_;
104 std::deque<int> bf_queue_;
105 std::vector<bool> node_in_queue_;
106 std::vector<int> tree_parent_node_of_;
110 std::vector<int64> propagated_bounds_;
113 std::vector<int> tmp_dfs_stack_;
116 std::vector<std::pair<int64, int64>>
117 visited_pickup_delivery_indices_for_pair_;
125 bool use_precedence_propagator)
127 visited_pickup_delivery_indices_for_pair_(
128 dimension->model()->GetPickupAndDeliveryPairs().size(), {-1, -1}) {
129 if (use_precedence_propagator) {
130 propagator_ = absl::make_unique<CumulBoundsPropagator>(
dimension);
139 const std::function<int64(int64)>& next_accessor,
140 glop::LinearProgram* linear_program,
141 glop::LPSolver* lp_solver,
142 std::vector<int64>* cumul_values, int64* cost,
143 int64* transit_cost,
bool clear_lp =
true);
145 bool Optimize(
const std::function<int64(int64)>& next_accessor,
146 glop::LinearProgram* linear_program, glop::LPSolver* lp_solver,
147 std::vector<int64>* cumul_values, int64* cost,
148 int64* transit_cost,
bool clear_lp =
true);
151 glop::LinearProgram* linear_program,
152 glop::LPSolver* lp_solver,
153 std::vector<int64>* cumul_values);
156 int vehicle,
const std::function<int64(int64)>& next_accessor,
157 glop::LinearProgram* linear_program, glop::LPSolver* lp_solver,
158 std::vector<int64>* cumul_values);
165 void InitOptimizer(glop::LinearProgram* linear_program);
173 bool ComputeRouteCumulBounds(
const std::vector<int64>& route,
174 const std::vector<int64>& fixed_transits,
181 bool SetRouteCumulConstraints(
182 int vehicle,
const std::function<int64(int64)>& next_accessor,
183 int64 cumul_offset,
bool optimize_costs,
184 glop::LinearProgram* linear_program, int64* route_transit_cost,
185 int64* route_cost_offset);
193 void SetGlobalConstraints(
bool optimize_costs,
194 glop::LinearProgram* linear_program);
196 bool FinalizeAndSolve(glop::LinearProgram* linear_program,
197 glop::LPSolver* lp_solver);
199 void SetCumulValuesFromLP(
const std::vector<glop::ColIndex>& cumul_variables,
200 int64 offset,
const glop::LPSolver& lp_solver,
201 std::vector<int64>* cumul_values);
209 bool PackRoutes(std::vector<int> vehicles,
210 glop::LinearProgram* linear_program,
211 glop::LPSolver* lp_solver);
213 std::unique_ptr<CumulBoundsPropagator> propagator_;
214 std::vector<int64> current_route_min_cumuls_;
215 std::vector<int64> current_route_max_cumuls_;
217 std::vector<glop::ColIndex> current_route_cumul_variables_;
218 std::vector<glop::ColIndex> index_to_cumul_variable_;
219 glop::ColIndex max_end_cumul_;
220 glop::ColIndex min_start_cumul_;
221 std::vector<std::pair<int64, int64>>
222 visited_pickup_delivery_indices_for_pair_;
239 const std::function<int64(int64)>& next_accessor,
240 int64* optimal_cost);
245 int vehicle,
const std::function<int64(int64)>& next_accessor,
246 int64* optimal_cost_without_transits);
253 const std::function<int64(int64)>& next_accessor,
254 std::vector<int64>* optimal_cumuls);
260 int vehicle,
const std::function<int64(int64)>& next_accessor,
261 std::vector<int64>* packed_cumuls);
268 std::vector<std::unique_ptr<glop::LPSolver>> lp_solver_;
269 std::vector<std::unique_ptr<glop::LinearProgram>> linear_program_;
282 const std::function<int64(int64)>& next_accessor,
283 int64* optimal_cost_without_transits);
288 bool ComputeCumuls(
const std::function<int64(int64)>& next_accessor,
289 std::vector<int64>* optimal_cumuls);
293 bool IsFeasible(
const std::function<int64(int64)>& next_accessor);
299 std::vector<int64>* packed_cumuls);
306 glop::LPSolver lp_solver_;
307 glop::LinearProgram linear_program_;
313 #endif // OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_LP_SCHEDULING_H_ bool Optimize(const std::function< int64(int64)> &next_accessor, glop::LinearProgram *linear_program, glop::LPSolver *lp_solver, std::vector< int64 > *cumul_values, int64 *cost, int64 *transit_cost, bool clear_lp=true)
bool OptimizeSingleRoute(int vehicle, const std::function< int64(int64)> &next_accessor, glop::LinearProgram *linear_program, glop::LPSolver *lp_solver, std::vector< int64 > *cumul_values, int64 *cost, int64 *transit_cost, bool clear_lp=true)
const RoutingDimension * dimension() const
bool ComputeCumuls(const std::function< int64(int64)> &next_accessor, std::vector< int64 > *optimal_cumuls)
GlobalDimensionCumulOptimizer(const RoutingDimension *dimension)
bool PropagateCumulBounds(const std::function< int64(int64)> &next_accessor, int64 cumul_offset)
Dimensions represent quantities accumulated at nodes along the routes.
bool ComputeCumulCostWithoutFixedTransits(const std::function< int64(int64)> &next_accessor, int64 *optimal_cost_without_transits)
bool ComputePackedCumuls(const std::function< int64(int64)> &next_accessor, std::vector< int64 > *packed_cumuls)
bool ComputeRouteCumulCostWithoutFixedTransits(int vehicle, const std::function< int64(int64)> &next_accessor, int64 *optimal_cost_without_transits)
bool ComputeRouteCumuls(int vehicle, const std::function< int64(int64)> &next_accessor, std::vector< int64 > *optimal_cumuls)
bool OptimizeAndPackSingleRoute(int vehicle, const std::function< int64(int64)> &next_accessor, glop::LinearProgram *linear_program, glop::LPSolver *lp_solver, std::vector< int64 > *cumul_values)
int64 CumulMin(int index) const
DimensionCumulOptimizerCore(const RoutingDimension *dimension, bool use_precedence_propagator)
const RoutingDimension * dimension() const
bool OptimizeAndPack(const std::function< int64(int64)> &next_accessor, glop::LinearProgram *linear_program, glop::LPSolver *lp_solver, std::vector< int64 > *cumul_values)
bool IsFeasible(const std::function< int64(int64)> &next_accessor)
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
const RoutingDimension * dimension() const
CumulBoundsPropagator(const RoutingDimension *dimension)
bool ComputePackedRouteCumuls(int vehicle, const std::function< int64(int64)> &next_accessor, std::vector< int64 > *packed_cumuls)
bool ComputeRouteCumulCost(int vehicle, const std::function< int64(int64)> &next_accessor, int64 *optimal_cost)
const RoutingDimension & dimension() const
int64 CumulMax(int index) const
LocalDimensionCumulOptimizer(const RoutingDimension *dimension)