I am trying to porting the benders algorithm [1] using Python wrapper.
But I get stuck in the following function.
I cannot find a suitable mapping from the C++ code to the Python code.
Could you give me some hints about the implementation following C++ functions in ortools Python:
1. second_stage_result.ray_reduced_costs()
2. second_stage_result.ray_dual_values()
Thank you very much.
//////////////
absl::StatusOr<Cut> SecondStageSolver::FeasibilityCut(
const math_opt::SolveResult& second_stage_result) {
const int num_facilities = network_.num_facilities();
Cut result;
if (!second_stage_result.has_dual_ray()) {
// MathOpt does not require solvers to return a dual solution on optimal,
// but most LP solvers always will, see go/mathopt-solver-contracts for
// details.
return util::InternalErrorBuilder()
<< "no dual ray available for feasibility cut";
}
for (int facility = 0; facility < num_facilities; ++facility) {
double coefficient = 0.0;
for (const auto& edge : network_.edges_incident_to_facility(facility)) {
const double reduced_cost =
second_stage_result.ray_reduced_costs().at(x_.at(edge));
coefficient += location_fraction_ * std::min(reduced_cost, 0.0);
}
const double dual_value =
second_stage_result.ray_dual_values().at(supply_constraints_[facility]);
coefficient += std::min(dual_value, 0.0);
result.z_coefficients.push_back(coefficient);
}
result.constant = 0.0;
for (const auto& constraint : demand_constraints_) {
const double dual_value =
second_stage_result.ray_dual_values().at(constraint);
result.constant += std::max(dual_value, 0.0);
}
result.w_coefficient = 0.0;
return result;
}
[1]
https://github.com/google/or-tools/blob/master/ortools/math_opt/samples/facility_lp_benders_mo.cc