38 const std::atomic<bool>* interrupt_solve) {
39 pdlp::PrimalDualHybridGradientParams params;
40 if (request->enable_internal_solver_output()) {
41 params.set_verbosity_level(3);
43 params.set_verbosity_level(0);
46 MPSolutionResponse response;
50 MPSolverResponseStatus::MPSOLVER_MODEL_INVALID_SOLVER_PARAMETERS);
53 if (interrupt_solve !=
nullptr && interrupt_solve->load() ==
true) {
54 response.set_status(MPSolverResponseStatus::MPSOLVER_NOT_SOLVED);
57 if (request->has_solver_time_limit_seconds()) {
58 params.mutable_termination_criteria()->set_time_sec_limit(
59 request->solver_time_limit_seconds());
62 std::optional<LazyMutableCopy<MPModelProto>> optional_model =
64 if (!optional_model)
return response;
71 std::move(request).dispose();
72 optional_model.reset();
80 switch (pdhg_result.
solve_log.termination_reason()) {
81 case pdlp::TERMINATION_REASON_OPTIMAL:
82 response.set_status(MPSOLVER_OPTIMAL);
84 case pdlp::TERMINATION_REASON_NUMERICAL_ERROR:
85 response.set_status(MPSOLVER_ABNORMAL);
87 case pdlp::TERMINATION_REASON_PRIMAL_INFEASIBLE:
88 response.set_status(MPSOLVER_INFEASIBLE);
90 case pdlp::TERMINATION_REASON_INTERRUPTED_BY_USER:
91 response.set_status(MPSOLVER_CANCELLED_BY_USER);
94 response.set_status(MPSOLVER_NOT_SOLVED);
97 if (pdhg_result.
solve_log.has_termination_string()) {
98 response.set_status_str(pdhg_result.
solve_log.termination_string());
101 const std::optional<pdlp::ConvergenceInformation> convergence_information =
105 if (convergence_information.has_value()) {
106 response.set_objective_value(convergence_information->primal_objective());
112 response.add_variable_value(v);
120 response.add_dual_value(objective_scaling_factor * v);
124 response.add_reduced_cost(objective_scaling_factor * v);
127 response.set_solver_specific_info(pdhg_result.
solve_log.SerializeAsString());
SolverResult PrimalDualHybridGradient(QuadraticProgram qp, const PrimalDualHybridGradientParams ¶ms, const std::atomic< bool > *interrupt_solve, std::function< void(const std::string &)> message_callback, IterationStatsCallback iteration_stats_callback)