14#ifndef OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_LP_SCHEDULING_H_
15#define OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_LP_SCHEDULING_H_
29#include "absl/container/flat_hash_map.h"
30#include "absl/container/flat_hash_set.h"
31#include "absl/log/check.h"
32#include "absl/strings/str_format.h"
33#include "absl/strings/string_view.h"
34#include "absl/time/time.h"
39#include "ortools/constraint_solver/routing_parameters.pb.h"
41#include "ortools/glop/parameters.pb.h"
44#include "ortools/sat/cp_model.pb.h"
47#include "ortools/sat/sat_parameters.pb.h"
68 const std::function<int64_t(int64_t)>& next_accessor,
70 const std::vector<RoutingModel::RouteDimensionTravelInfo>*
71 dimension_travel_info_per_route =
nullptr);
74 return propagated_bounds_[PositiveNode(
index)];
78 const int64_t negated_upper_bound = propagated_bounds_[NegativeNode(
index)];
79 return negated_upper_bound == std::numeric_limits<int64_t>::min()
80 ? std::numeric_limits<int64_t>::max()
81 : -negated_upper_bound;
84 const RoutingDimension&
dimension()
const {
return dimension_; }
94 static const int kNoParent;
95 static const int kParentToBePropagated;
99 int PositiveNode(
int index)
const {
return 2 *
index; }
100 int NegativeNode(
int index)
const {
return 2 *
index + 1; }
102 void AddNodeToQueue(
int node) {
103 if (!node_in_queue_[node]) {
104 bf_queue_.push_back(node);
105 node_in_queue_[node] =
true;
112 void AddArcs(
int first_index,
int second_index, int64_t offset);
114 bool InitializeArcsAndBounds(
115 const std::function<int64_t(int64_t)>& next_accessor,
116 int64_t cumul_offset,
117 const std::vector<RoutingModel::RouteDimensionTravelInfo>*
118 dimension_travel_info_per_route =
nullptr);
120 bool UpdateCurrentLowerBoundOfNode(
int node, int64_t new_lb, int64_t offset);
122 bool DisassembleSubtree(
int source,
int target);
124 bool CleanupAndReturnFalse() {
126 for (
int node_to_cleanup : bf_queue_) {
127 node_in_queue_[node_to_cleanup] =
false;
133 const RoutingDimension& dimension_;
134 const int64_t num_nodes_;
139 std::vector<std::vector<ArcInfo>> outgoing_arcs_;
141 std::deque<int> bf_queue_;
142 std::vector<bool> node_in_queue_;
143 std::vector<int> tree_parent_node_of_;
147 std::vector<int64_t> propagated_bounds_;
150 std::vector<int> tmp_dfs_stack_;
153 std::vector<std::pair<int64_t, int64_t>>
154 visited_pickup_delivery_indices_for_pair_;
176 const std::vector<int64_t>& starts,
177 const std::vector<int64_t>& ends) = 0;
217 absl::Span<
const std::pair<int, double>> variable_coeffs) {
220 for (
const auto& variable_coeff : variable_coeffs) {
230 absl::Span<
const std::pair<int, double>> weighted_variables) {
232 if (std::numeric_limits<int64_t>::min() <
lower_bound) {
238 const int under_lower_bound_ct =
243 if (
upper_bound < std::numeric_limits<int64_t>::max()) {
250 upper_bound + 1, std::numeric_limits<int64_t>::max(),
259 const int within_bounds_ct =
262 return within_bounds;
269 : is_relaxation_(is_relaxation) {
274 linear_program_.
Clear();
276 allowed_intervals_.clear();
290 const int64_t kMaxValue = 1e10;
292 const double lp_max =
294 if (lp_min <= lp_max) {
303 const std::vector<int64_t>& ends)
override {
308 allowed_intervals_[
index] =
309 std::make_unique<SortedDisjointIntervalList>(starts, ends);
328 for (glop::ColIndex i(0); i < linear_program_.
num_variables(); ++i) {
354 double max_coefficient = 0;
355 for (
int variable = 0; variable <
NumVariables(); variable++) {
359 DCHECK_GE(max_coefficient, 0);
360 if (max_coefficient == 0) {
365 double normalized_objective_value = 0;
366 for (
int variable = 0; variable <
NumVariables(); variable++) {
369 const double normalized_coeff =
coefficient / max_coefficient;
371 normalized_objective_value += normalized_coeff *
GetValue(variable);
374 normalized_objective_value = std::max(
377 normalized_objective_value);
380 std::vector<int> )
override {}
382 std::vector<int> )
override {}
386 absl::ToDoubleSeconds(duration_limit));
394 VLOG(2) << linear_program_.
Dump();
400 if (is_relaxation_) {
403 for (
const auto& allowed_interval : allowed_intervals_) {
404 const double value_double =
GetValue(allowed_interval.first);
405 const int64_t
value =
406 (value_double >= std::numeric_limits<int64_t>::max())
407 ? std::numeric_limits<int64_t>::max()
410 allowed_interval.second.get();
430 glop::GlopParameters params;
441 const bool is_relaxation_;
444 absl::flat_hash_map<int, std::unique_ptr<SortedDisjointIntervalList>>
451 parameters_.set_num_search_workers(1);
454 parameters_.set_cp_model_presolve(
true);
455 parameters_.set_max_presolve_iterations(1);
456 parameters_.set_catch_sigint_signal(
false);
457 parameters_.set_mip_max_bound(1e8);
458 parameters_.set_search_branching(sat::SatParameters::LP_SEARCH);
459 parameters_.set_linearization_level(2);
460 parameters_.set_cut_level(0);
461 parameters_.set_use_absl_random(
false);
467 objective_coefficients_.clear();
470 const int index = model_.variables_size();
471 sat::IntegerVariableProto*
const variable = model_.add_variables();
472 variable->add_domain(0);
473 variable->add_domain(
static_cast<int64_t
>(parameters_.mip_max_bound()));
477 model_.mutable_variables(
index)->set_name(
name.data());
482 const int64_t capped_upper_bound =
483 std::min<int64_t>(
upper_bound, parameters_.mip_max_bound());
484 if (
lower_bound > capped_upper_bound)
return false;
485 sat::IntegerVariableProto*
const variable = model_.mutable_variables(
index);
487 variable->set_domain(1, capped_upper_bound);
491 const std::vector<int64_t>& ends)
override {
492 DCHECK_EQ(starts.size(), ends.size());
494 for (
int i = 0; i < starts.size(); ++i) {
498 absl::StrFormat(
"disjoint(%ld, %ld)",
index, i));
504 model_.mutable_constraints(window_ct)->add_enforcement_literal(variable);
508 return model_.variables(
index).domain(0);
511 const auto& domain = model_.variables(
index).domain();
512 return domain[domain.size() - 1];
515 if (
index >= objective_coefficients_.size()) {
516 objective_coefficients_.resize(
index + 1, 0);
519 sat::FloatObjectiveProto*
const objective =
520 model_.mutable_floating_point_objective();
521 objective->add_vars(
index);
525 return (
index < objective_coefficients_.size())
526 ? objective_coefficients_[
index]
530 model_.mutable_floating_point_objective()->Clear();
534 sat::LinearConstraintProto*
const ct =
535 model_.add_constraints()->mutable_linear();
538 return model_.constraints_size() - 1;
541 sat::LinearConstraintProto*
const ct =
542 model_.mutable_constraints(
ct_index)->mutable_linear();
545 ct->add_coeffs(integer_coefficient);
549 const sat::CpObjectiveProto& objective = response_.integer_objective();
550 int64_t activity = 0;
551 for (
int i = 0; i < objective.vars_size(); ++i) {
552 activity += response_.solution(objective.vars(i)) * objective.coeffs(i);
556 for (
int i = 0; i < objective.vars_size(); ++i) {
559 model_.clear_objective();
562 sat::LinearArgumentProto*
const ct =
563 model_.add_constraints()->mutable_lin_max();
564 ct->mutable_target()->add_vars(max_var);
565 ct->mutable_target()->add_coeffs(1);
566 for (
const int var : vars) {
567 sat::LinearExpressionProto*
const expr =
ct->add_exprs();
573 sat::LinearArgumentProto*
const ct =
574 model_.add_constraints()->mutable_int_prod();
575 ct->mutable_target()->add_vars(product_var);
576 ct->mutable_target()->add_coeffs(1);
577 for (
const int var : vars) {
578 sat::LinearExpressionProto* expr =
ct->add_exprs();
584 DCHECK_LT(
ct, model_.constraints_size());
585 model_.mutable_constraints(
ct)->add_enforcement_literal(condition);
588 parameters_.set_max_time_in_seconds(absl::ToDoubleSeconds(duration_limit));
589 VLOG(2) << model_.DebugString();
590 if (hint_.vars_size() == model_.variables_size()) {
591 *model_.mutable_solution_hint() = hint_;
596 VLOG(2) << response_;
597 if (response_.status() == sat::CpSolverStatus::OPTIMAL ||
598 (response_.status() == sat::CpSolverStatus::FEASIBLE &&
599 !model_.has_floating_point_objective())) {
601 for (
int i = 0; i < response_.solution_size(); ++i) {
603 hint_.add_values(response_.solution(i));
613 return response_.solution(
index);
622 bool ModelIsEmpty()
const override {
return model_.ByteSizeLong() == 0; }
628 sat::CpModelProto model_;
629 sat::CpSolverResponse response_;
630 sat::SatParameters parameters_;
631 std::vector<double> objective_coefficients_;
632 sat::PartialVariableAssignment hint_;
638 using RouteDimensionTravelInfo = RoutingModel::RouteDimensionTravelInfo;
639 using Resource = RoutingModel::ResourceGroup::Resource;
643 bool use_precedence_propagator);
648 int vehicle,
const std::function<int64_t(int64_t)>& next_accessor,
649 const RouteDimensionTravelInfo& dimension_travel_info,
650 const Resource* resource,
bool optimize_vehicle_costs,
652 std::vector<int64_t>*
break_values, int64_t* cost_without_transit,
653 int64_t* transit_cost,
bool clear_lp =
true);
659 int vehicle,
const std::function<int64_t(int64_t)>& next_accessor,
660 const RouteDimensionTravelInfo& dimension_travel_info,
662 absl::Span<const int64_t> solution_cumul_values,
663 absl::Span<const int64_t> solution_break_values,
664 int64_t* cost_without_transits, int64_t* cost_offset =
nullptr,
665 bool reuse_previous_model_if_possible =
true,
bool clear_lp =
false,
666 bool clear_solution_constraints =
true,
667 absl::Duration* solve_duration =
nullptr);
674 int vehicle,
const std::function<int64_t(int64_t)>& next_accessor,
675 const std::function<int64_t(int64_t, int64_t)>& transit_accessor,
676 const RouteDimensionTravelInfo& dimension_travel_info,
677 const std::vector<Resource>& resources,
678 const std::vector<int>& resource_indices,
bool optimize_vehicle_costs,
682 std::vector<int64_t>* costs_without_transits, int64_t* transit_cost,
683 bool clear_lp =
true);
691 const std::function<int64_t(int64_t)>& next_accessor,
692 const std::vector<RouteDimensionTravelInfo>&
693 dimension_travel_info_per_route,
696 std::vector<std::vector<int>>* resource_indices_per_group,
697 int64_t* cost_without_transits, int64_t* transit_cost,
698 bool clear_lp =
true,
bool optimize_resource_assignment =
true);
701 const std::function<int64_t(int64_t)>& next_accessor,
702 const std::vector<RouteDimensionTravelInfo>&
703 dimension_travel_info_per_route,
708 int vehicle,
const std::function<int64_t(int64_t)>& next_accessor,
709 const RouteDimensionTravelInfo& dimension_travel_info,
713 const RoutingDimension*
dimension()
const {
return dimension_; }
722 bool ExtractRouteCumulBounds(absl::Span<const int64_t> route,
723 int64_t cumul_offset);
728 bool TightenRouteCumulBounds(
const std::vector<int64_t>& route,
729 const std::vector<int64_t>& min_transits,
730 int64_t cumul_offset);
736 bool SetRouteCumulConstraints(
737 int vehicle,
const std::function<int64_t(int64_t)>& next_accessor,
738 const std::function<int64_t(int64_t, int64_t)>& transit_accessor,
739 const RouteDimensionTravelInfo& dimension_travel_info,
740 int64_t cumul_offset,
bool optimize_costs,
742 int64_t* route_cost_offset);
747 bool SetRouteTravelConstraints(
748 const RouteDimensionTravelInfo& dimension_travel_info,
749 const std::vector<int>& lp_slacks,
750 const std::vector<int64_t>& fixed_transit,
760 bool SetGlobalConstraints(
761 const std::function<int64_t(int64_t)>& next_accessor,
762 int64_t cumul_offset,
bool optimize_costs,
765 bool SetGlobalConstraintsForResourceAssignment(
766 const std::function<int64_t(int64_t)>& next_accessor,
769 void SetValuesFromLP(
const std::vector<int>& lp_variables, int64_t offset,
771 std::vector<int64_t>* lp_values)
const;
773 void SetResourceIndices(
775 std::vector<std::vector<int>>* resource_indices_per_group)
const;
785 const glop::GlopParameters& packing_parameters);
787 std::unique_ptr<CumulBoundsPropagator> propagator_;
788 std::vector<int64_t> current_route_min_cumuls_;
789 std::vector<int64_t> current_route_max_cumuls_;
790 const RoutingDimension*
const dimension_;
792 std::vector<int> current_route_cumul_variables_;
793 std::vector<int> index_to_cumul_variable_;
798 std::vector<int> current_route_break_variables_;
802 std::vector<int> all_break_variables_;
806 std::vector<int> vehicle_to_all_break_variables_offset_;
811 std::vector<std::vector<int>>
812 resource_group_to_resource_to_vehicle_assignment_variables_;
815 int min_start_cumul_;
816 std::vector<std::pair<int64_t, int64_t>>
817 visited_pickup_delivery_indices_for_pair_;
829 RoutingSearchParameters::SchedulingSolver solver_type);
836 int vehicle,
const std::function<int64_t(int64_t)>& next_accessor,
837 int64_t* optimal_cost);
842 int vehicle,
const std::function<int64_t(int64_t)>& next_accessor,
843 int64_t* optimal_cost_without_transits);
845 std::vector<DimensionSchedulingStatus>
847 int vehicle,
const std::function<int64_t(int64_t)>& next_accessor,
848 const std::function<int64_t(int64_t, int64_t)>& transit_accessor,
849 const std::vector<RoutingModel::ResourceGroup::Resource>& resources,
850 const std::vector<int>& resource_indices,
bool optimize_vehicle_costs,
851 std::vector<int64_t>* optimal_costs_without_transits,
852 std::vector<std::vector<int64_t>>* optimal_cumuls,
853 std::vector<std::vector<int64_t>>* optimal_breaks);
861 int vehicle,
const std::function<int64_t(int64_t)>& next_accessor,
862 const RoutingModel::RouteDimensionTravelInfo& dimension_travel_info,
863 const RoutingModel::ResourceGroup::Resource* resource,
864 std::vector<int64_t>* optimal_cumuls,
865 std::vector<int64_t>* optimal_breaks);
870 int vehicle,
const std::function<int64_t(int64_t)>& next_accessor,
871 const RoutingModel::RouteDimensionTravelInfo& dimension_travel_info,
872 std::vector<int64_t>* optimal_cumuls,
873 std::vector<int64_t>* optimal_breaks,
874 int64_t* optimal_cost_without_transits);
879 int vehicle,
const std::function<int64_t(int64_t)>& next_accessor,
880 const RoutingModel::RouteDimensionTravelInfo& dimension_travel_info,
881 const std::vector<int64_t>& solution_cumul_values,
882 const std::vector<int64_t>& solution_break_values, int64_t* solution_cost,
883 int64_t* cost_offset =
nullptr,
884 bool reuse_previous_model_if_possible =
false,
bool clear_lp =
true,
885 absl::Duration* solve_duration =
nullptr);
893 int vehicle,
const std::function<int64_t(int64_t)>& next_accessor,
894 const RoutingModel::RouteDimensionTravelInfo& dimension_travel_info,
895 const RoutingModel::ResourceGroup::Resource* resource,
896 std::vector<int64_t>* packed_cumuls, std::vector<int64_t>* packed_breaks);
903 std::vector<std::unique_ptr<RoutingLinearSolverWrapper>> solver_;
911 RoutingSearchParameters::SchedulingSolver solver_type);
918 const std::function<int64_t(int64_t)>& next_accessor,
919 int64_t* optimal_cost_without_transits);
926 const std::function<int64_t(int64_t)>& next_accessor,
927 const std::vector<RoutingModel::RouteDimensionTravelInfo>&
928 dimension_travel_info_per_route,
929 std::vector<int64_t>* optimal_cumuls,
930 std::vector<int64_t>* optimal_breaks,
931 std::vector<std::vector<int>>* optimal_resource_indices_per_group);
940 const std::function<int64_t(int64_t)>& next_accessor,
941 const std::vector<RoutingModel::RouteDimensionTravelInfo>&
942 dimension_travel_info_per_route,
943 std::vector<int64_t>* packed_cumuls, std::vector<int64_t>* packed_breaks);
950 std::unique_ptr<RoutingLinearSolverWrapper> solver_;
973 const std::vector<int>& vehicles,
975 std::vector<int>>& resource_indices_per_class,
977 absl::flat_hash_set<int>>&
978 ignored_resources_per_class,
979 std::function<
const std::vector<int64_t>*(
int)>
980 vehicle_to_resource_class_assignment_costs,
981 std::vector<int>* resource_indices);
993 int v,
const RoutingModel::ResourceGroup& resource_group,
995 absl::flat_hash_set<int>>&
996 ignored_resources_per_class,
997 const std::function<int64_t(int64_t)>& next_accessor,
998 const std::function<int64_t(int64_t, int64_t)>& transit_accessor,
999 bool optimize_vehicle_costs, LocalDimensionCumulOptimizer* lp_optimizer,
1000 LocalDimensionCumulOptimizer* mp_optimizer,
1019 const RoutingModel::RouteDimensionTravelInfo::TransitionInfo::
1020 PiecewiseLinearFormulation& pwl,
1029 const RoutingModel::RouteDimensionTravelInfo::TransitionInfo::
1030 PiecewiseLinearFormulation& pwl,
1031 int64_t
x,
double delta = 0);
1051 const std::vector<SlopeAndYIntercept>& slope_and_y_intercept);
1057 const RoutingModel::RouteDimensionTravelInfo::TransitionInfo::
1058 PiecewiseLinearFormulation& pwl_function,
1059 int index_start = 0,
int index_end = -1);
CumulBoundsPropagator(const RoutingDimension *dimension)
bool PropagateCumulBounds(const std::function< int64_t(int64_t)> &next_accessor, int64_t cumul_offset, const std::vector< RoutingModel::RouteDimensionTravelInfo > *dimension_travel_info_per_route=nullptr)
int64_t CumulMax(int index) const
int64_t CumulMin(int index) const
const RoutingDimension & dimension() const
DimensionSchedulingStatus Optimize(const std::function< int64_t(int64_t)> &next_accessor, const std::vector< RouteDimensionTravelInfo > &dimension_travel_info_per_route, RoutingLinearSolverWrapper *solver, std::vector< int64_t > *cumul_values, std::vector< int64_t > *break_values, std::vector< std::vector< int > > *resource_indices_per_group, int64_t *cost_without_transits, int64_t *transit_cost, bool clear_lp=true, bool optimize_resource_assignment=true)
const RoutingDimension * dimension() const
DimensionSchedulingStatus OptimizeAndPack(const std::function< int64_t(int64_t)> &next_accessor, const std::vector< RouteDimensionTravelInfo > &dimension_travel_info_per_route, RoutingLinearSolverWrapper *solver, std::vector< int64_t > *cumul_values, std::vector< int64_t > *break_values)
DimensionSchedulingStatus OptimizeSingleRouteWithResource(int vehicle, const std::function< int64_t(int64_t)> &next_accessor, const RouteDimensionTravelInfo &dimension_travel_info, const Resource *resource, bool optimize_vehicle_costs, RoutingLinearSolverWrapper *solver, std::vector< int64_t > *cumul_values, std::vector< int64_t > *break_values, int64_t *cost_without_transit, int64_t *transit_cost, bool clear_lp=true)
DimensionCumulOptimizerCore(const RoutingDimension *dimension, bool use_precedence_propagator)
std::vector< DimensionSchedulingStatus > OptimizeSingleRouteWithResources(int vehicle, const std::function< int64_t(int64_t)> &next_accessor, const std::function< int64_t(int64_t, int64_t)> &transit_accessor, const RouteDimensionTravelInfo &dimension_travel_info, const std::vector< Resource > &resources, const std::vector< int > &resource_indices, bool optimize_vehicle_costs, RoutingLinearSolverWrapper *solver, std::vector< std::vector< int64_t > > *cumul_values, std::vector< std::vector< int64_t > > *break_values, std::vector< int64_t > *costs_without_transits, int64_t *transit_cost, bool clear_lp=true)
DimensionSchedulingStatus OptimizeAndPackSingleRoute(int vehicle, const std::function< int64_t(int64_t)> &next_accessor, const RouteDimensionTravelInfo &dimension_travel_info, const Resource *resource, RoutingLinearSolverWrapper *solver, std::vector< int64_t > *cumul_values, std::vector< int64_t > *break_values)
DimensionSchedulingStatus ComputeSingleRouteSolutionCostWithoutFixedTransits(int vehicle, const std::function< int64_t(int64_t)> &next_accessor, const RouteDimensionTravelInfo &dimension_travel_info, RoutingLinearSolverWrapper *solver, absl::Span< const int64_t > solution_cumul_values, absl::Span< const int64_t > solution_break_values, int64_t *cost_without_transits, int64_t *cost_offset=nullptr, bool reuse_previous_model_if_possible=true, bool clear_lp=false, bool clear_solution_constraints=true, absl::Duration *solve_duration=nullptr)
DimensionSchedulingStatus ComputeCumulCostWithoutFixedTransits(const std::function< int64_t(int64_t)> &next_accessor, int64_t *optimal_cost_without_transits)
GlobalDimensionCumulOptimizer(const RoutingDimension *dimension, RoutingSearchParameters::SchedulingSolver solver_type)
GlobalDimensionCumulOptimizer.
const RoutingDimension * dimension() const
DimensionSchedulingStatus ComputeCumuls(const std::function< int64_t(int64_t)> &next_accessor, const std::vector< RoutingModel::RouteDimensionTravelInfo > &dimension_travel_info_per_route, std::vector< int64_t > *optimal_cumuls, std::vector< int64_t > *optimal_breaks, std::vector< std::vector< int > > *optimal_resource_indices_per_group)
DimensionSchedulingStatus ComputePackedCumuls(const std::function< int64_t(int64_t)> &next_accessor, const std::vector< RoutingModel::RouteDimensionTravelInfo > &dimension_travel_info_per_route, std::vector< int64_t > *packed_cumuls, std::vector< int64_t > *packed_breaks)
DimensionSchedulingStatus ComputeRouteSolutionCostWithoutFixedTransits(int vehicle, const std::function< int64_t(int64_t)> &next_accessor, const RoutingModel::RouteDimensionTravelInfo &dimension_travel_info, const std::vector< int64_t > &solution_cumul_values, const std::vector< int64_t > &solution_break_values, int64_t *solution_cost, int64_t *cost_offset=nullptr, bool reuse_previous_model_if_possible=false, bool clear_lp=true, absl::Duration *solve_duration=nullptr)
const RoutingDimension * dimension() const
DimensionSchedulingStatus ComputeRouteCumulsAndCostWithoutFixedTransits(int vehicle, const std::function< int64_t(int64_t)> &next_accessor, const RoutingModel::RouteDimensionTravelInfo &dimension_travel_info, std::vector< int64_t > *optimal_cumuls, std::vector< int64_t > *optimal_breaks, int64_t *optimal_cost_without_transits)
LocalDimensionCumulOptimizer(const RoutingDimension *dimension, RoutingSearchParameters::SchedulingSolver solver_type)
LocalDimensionCumulOptimizer.
DimensionSchedulingStatus ComputeRouteCumuls(int vehicle, const std::function< int64_t(int64_t)> &next_accessor, const RoutingModel::RouteDimensionTravelInfo &dimension_travel_info, const RoutingModel::ResourceGroup::Resource *resource, std::vector< int64_t > *optimal_cumuls, std::vector< int64_t > *optimal_breaks)
DimensionSchedulingStatus ComputeRouteCumulCost(int vehicle, const std::function< int64_t(int64_t)> &next_accessor, int64_t *optimal_cost)
DimensionSchedulingStatus ComputeRouteCumulCostWithoutFixedTransits(int vehicle, const std::function< int64_t(int64_t)> &next_accessor, int64_t *optimal_cost_without_transits)
std::vector< DimensionSchedulingStatus > ComputeRouteCumulCostsForResourcesWithoutFixedTransits(int vehicle, const std::function< int64_t(int64_t)> &next_accessor, const std::function< int64_t(int64_t, int64_t)> &transit_accessor, const std::vector< RoutingModel::ResourceGroup::Resource > &resources, const std::vector< int > &resource_indices, bool optimize_vehicle_costs, std::vector< int64_t > *optimal_costs_without_transits, std::vector< std::vector< int64_t > > *optimal_cumuls, std::vector< std::vector< int64_t > > *optimal_breaks)
DimensionSchedulingStatus ComputePackedRouteCumuls(int vehicle, const std::function< int64_t(int64_t)> &next_accessor, const RoutingModel::RouteDimensionTravelInfo &dimension_travel_info, const RoutingModel::ResourceGroup::Resource *resource, std::vector< int64_t > *packed_cumuls, std::vector< int64_t > *packed_breaks)
static int64_t FastInt64Round(double x)
void AddMaximumConstraint(int max_var, std::vector< int > vars) override
void AddObjectiveConstraint() override
void SetParameters(const std::string &) override
void SetVariableDisjointBounds(int index, const std::vector< int64_t > &starts, const std::vector< int64_t > &ends) override
int NumVariables() const override
bool IsCPSATSolver() override
double GetValue(int index) const override
int CreateNewConstraint(int64_t lower_bound, int64_t upper_bound) override
int CreateNewPositiveVariable() override
DimensionSchedulingStatus Solve(absl::Duration duration_limit) override
void SetCoefficient(int ct_index, int index, double coefficient) override
void SetVariableName(int index, absl::string_view name) override
bool SetVariableBounds(int index, int64_t lower_bound, int64_t upper_bound) override
void SetObjectiveCoefficient(int index, double coefficient) override
double GetObjectiveCoefficient(int index) const override
std::string PrintModel() const override
Prints an understandable view of the model.
int64_t GetVariableUpperBound(int index) const override
void SetEnforcementLiteral(int ct, int condition) override
void ClearObjective() override
int64_t GetObjectiveValue() const override
int64_t GetVariableLowerBound(int index) const override
bool ModelIsEmpty() const override
Returns if the model is empty or not.
void AddProductConstraint(int product_var, std::vector< int > vars) override
~RoutingCPSatWrapper() override
bool SolutionIsInteger() const override
int64_t GetVariableLowerBound(int index) const override
int NumVariables() const override
void ClearObjective() override
bool SetVariableBounds(int index, int64_t lower_bound, int64_t upper_bound) override
double GetValue(int index) const override
double GetObjectiveCoefficient(int index) const override
int CreateNewPositiveVariable() override
RoutingGlopWrapper(bool is_relaxation, const glop::GlopParameters ¶meters)
std::string PrintModel() const override
void SetObjectiveCoefficient(int index, double coefficient) override
void AddMaximumConstraint(int, std::vector< int >) override
void AddObjectiveConstraint() override
void SetEnforcementLiteral(int, int) override
DimensionSchedulingStatus Solve(absl::Duration duration_limit) override
int64_t GetObjectiveValue() const override
int64_t GetVariableUpperBound(int index) const override
bool IsCPSATSolver() override
bool SolutionIsInteger() const override
void SetVariableDisjointBounds(int index, const std::vector< int64_t > &starts, const std::vector< int64_t > &ends) override
void SetCoefficient(int ct, int index, double coefficient) override
void SetVariableName(int index, absl::string_view name) override
int CreateNewConstraint(int64_t lower_bound, int64_t upper_bound) override
void AddProductConstraint(int, std::vector< int >) override
void SetParameters(const std::string ¶meters) override
This function is meant to override the parameters of the solver.
virtual int NumVariables() const =0
virtual int64_t GetObjectiveValue() const =0
virtual ~RoutingLinearSolverWrapper()
virtual DimensionSchedulingStatus Solve(absl::Duration duration_limit)=0
virtual void SetCoefficient(int ct, int index, double coefficient)=0
virtual int64_t GetVariableUpperBound(int index) const =0
int AddLinearConstraint(int64_t lower_bound, int64_t upper_bound, absl::Span< const std::pair< int, double > > variable_coeffs)
virtual bool SolutionIsInteger() const =0
virtual int CreateNewConstraint(int64_t lower_bound, int64_t upper_bound)=0
virtual void SetEnforcementLiteral(int ct, int condition)=0
virtual void AddProductConstraint(int product_var, std::vector< int > vars)=0
virtual std::string PrintModel() const =0
Prints an understandable view of the model.
virtual double GetValue(int index) const =0
virtual void SetVariableDisjointBounds(int index, const std::vector< int64_t > &starts, const std::vector< int64_t > &ends)=0
int AddReifiedLinearConstraint(int64_t lower_bound, int64_t upper_bound, absl::Span< const std::pair< int, double > > weighted_variables)
virtual void SetObjectiveCoefficient(int index, double coefficient)=0
virtual void ClearObjective()=0
virtual int CreateNewPositiveVariable()=0
virtual bool SetVariableBounds(int index, int64_t lower_bound, int64_t upper_bound)=0
virtual void SetParameters(const std::string ¶meters)=0
This function is meant to override the parameters of the solver.
virtual void AddMaximumConstraint(int max_var, std::vector< int > vars)=0
virtual void SetVariableName(int index, absl::string_view name)=0
virtual void AddObjectiveConstraint()=0
virtual bool ModelIsEmpty() const
Returns if the model is empty or not.
virtual int64_t GetVariableLowerBound(int index) const =0
virtual bool IsCPSATSolver()=0
virtual double GetObjectiveCoefficient(int index) const =0
int AddVariable(int64_t lower_bound, int64_t upper_bound)
Adds a variable with bounds [lower_bound, upper_bound].
Iterator FirstIntervalGreaterOrEqual(int64_t value) const
ConstIterator end() const
A full-fledged linear programming solver.
GlopParameters * GetMutableParameters()
Fractional GetObjectiveValue() const
Returns the objective value of the solution with its offset and scaling.
const DenseRow & variable_values() const
Accessors to information related to variables.
void SetParameters(const GlopParameters ¶meters)
ABSL_MUST_USE_RESULT ProblemStatus Solve(const LinearProgram &lp)
const DenseRow & objective_coefficients() const
Returns the objective coefficients (or cost) of variables as a row vector.
void Clear()
Clears, i.e. reset the object to its initial value.
void NotifyThatColumnsAreClean()
bool SolutionIsInteger(const DenseRow &solution, Fractional absolute_tolerance) const
void SetObjectiveCoefficient(ColIndex col, Fractional value)
const DenseRow & variable_lower_bounds() const
void SetVariableBounds(ColIndex col, Fractional lower_bound, Fractional upper_bound)
void SetConstraintBounds(RowIndex row, Fractional lower_bound, Fractional upper_bound)
void SetCoefficient(RowIndex row, ColIndex col, Fractional value)
Defines the coefficient for col / row.
const DenseRow & variable_upper_bounds() const
void SetVariableName(ColIndex col, absl::string_view name)
RowIndex CreateNewConstraint()
ColIndex num_variables() const
Returns the number of variables.
ColIndex CreateNewVariable()
void SetMaximizationProblem(bool maximize)
T Add(std::function< T(Model *)> f)
const std::string name
A name for logging purposes.
constexpr double kInfinity
Infinity for type Fractional.
ProblemStatus
Different statuses for a given problem.
std::function< SatParameters(Model *)> NewSatParameters(const std::string ¶ms)
CpSolverResponse SolveCpModel(const CpModelProto &model_proto, Model *model)
In SWIG mode, we don't want anything besides these top-level includes.
DimensionSchedulingStatus
@ INFEASIBLE
A solution could not be found.
@ OPTIMAL
An optimal solution was found respecting all constraints.
PiecewiseEvaluationStatus ComputePiecewiseLinearFormulationValue(const RoutingModel::RouteDimensionTravelInfo::TransitionInfo::PiecewiseLinearFormulation &pwl, int64_t x, int64_t *value, double delta)
PiecewiseEvaluationStatus
@ SMALLER_THAN_LOWER_BOUND
@ LARGER_THAN_UPPER_BOUND
std::vector< bool > SlopeAndYInterceptToConvexityRegions(const std::vector< SlopeAndYIntercept > &slope_and_y_intercept)
int64_t ComputeConvexPiecewiseLinearFormulationValue(const RoutingModel::RouteDimensionTravelInfo::TransitionInfo::PiecewiseLinearFormulation &pwl, int64_t x, double delta)
bool ComputeVehicleToResourceClassAssignmentCosts(int v, const RoutingModel::ResourceGroup &resource_group, const util_intops::StrongVector< RoutingModel::ResourceClassIndex, absl::flat_hash_set< int > > &ignored_resources_per_class, const std::function< int64_t(int64_t)> &next_accessor, const std::function< int64_t(int64_t, int64_t)> &transit_accessor, bool optimize_vehicle_costs, LocalDimensionCumulOptimizer *lp_optimizer, LocalDimensionCumulOptimizer *mp_optimizer, std::vector< int64_t > *assignment_costs, std::vector< std::vector< int64_t > > *cumul_values, std::vector< std::vector< int64_t > > *break_values)
std::vector< SlopeAndYIntercept > PiecewiseLinearFormulationToSlopeAndYIntercept(const RoutingModel::RouteDimensionTravelInfo::TransitionInfo::PiecewiseLinearFormulation &pwl_function, int index_start, int index_end)
int64_t ComputeBestVehicleToResourceAssignment(const std::vector< int > &vehicles, const util_intops::StrongVector< RoutingModel::ResourceClassIndex, std::vector< int > > &resource_indices_per_class, const util_intops::StrongVector< RoutingModel::ResourceClassIndex, absl::flat_hash_set< int > > &ignored_resources_per_class, std::function< const std::vector< int64_t > *(int)> vehicle_to_resource_class_assignment_costs, std::vector< int > *resource_indices)
std::vector< int64_t > assignment_costs
std::vector< std::vector< int64_t > > cumul_values
std::vector< std::vector< int64_t > > break_values
Structure to store the slope and y_intercept of a segment.
friend::std::ostream & operator<<(::std::ostream &os, const SlopeAndYIntercept &it)