17#ifndef OR_TOOLS_MATH_OPT_CPP_SOLVE_RESULT_H_
18#define OR_TOOLS_MATH_OPT_CPP_SOLVE_RESULT_H_
20#include <initializer_list>
27#include "absl/status/status.h"
28#include "absl/status/statusor.h"
29#include "absl/time/time.h"
30#include "ortools/gscip/gscip.pb.h"
35#include "ortools/math_opt/result.pb.h"
90 static absl::StatusOr<ProblemStatus>
FromProto(
91 const ProblemStatusProto& problem_status_proto);
93 ProblemStatusProto
Proto()
const;
113 static absl::StatusOr<SolveStats>
FromProto(
114 const SolveStatsProto& solve_stats_proto);
117 absl::StatusOr<SolveStatsProto>
Proto()
const;
126 kOptimal = TERMINATION_REASON_OPTIMAL,
280 const ObjectiveBoundsProto& objective_bounds_proto);
281 ObjectiveBoundsProto
Proto()
const;
331 bool IsOptimalOrFeasible()
const;
338 absl::Status EnsureIsOptimal()
const;
353 absl::Status EnsureReasonIsAnyOf(
354 std::initializer_list<TerminationReason> reasons)
const;
362 static Termination Optimal(
double primal_objective_value,
363 double dual_objective_value,
414 std::optional<double> optional_dual_objective = std::nullopt,
435 bool is_maximize,
Limit limit,
double finite_primal_objective,
436 std::optional<double> optional_dual_objective = std::nullopt,
443 static absl::StatusOr<Termination> FromProto(
444 const TerminationProto& termination_proto);
445 TerminationProto Proto()
const;
452template <
typename Sink>
466 SolveStats solve_stats;
483 std::vector<Solution> solutions;
488 std::vector<PrimalRay> primal_rays;
493 std::vector<DualRay> dual_rays;
496 GScipOutput gscip_solver_specific_output;
498 SolveResultProto::PdlpOutput pdlp_solver_specific_output;
520 static absl::StatusOr<SolveResult> FromProto(
521 const ModelStorage*
model,
const SolveResultProto& solve_result_proto);
529 absl::StatusOr<SolveResultProto> Proto()
const;
531 absl::Duration solve_time()
const {
return solve_stats.solve_time; }
536 double primal_bound()
const;
541 double dual_bound()
const;
550 bool has_primal_feasible_solution()
const;
585 bool has_ray()
const {
return !primal_rays.empty(); }
646std::ostream&
operator<<(std::ostream& out,
const SolveResult& result);
#define MATH_OPT_DEFINE_ENUM(CppEnum, proto_unspecified_value)
TerminationReason termination
absl::flat_hash_map< Variable, V > VariableMap
TerminationReason
The reason a call to Solve() terminates.
@ kOptimal
A provably optimal solution (up to numerical tolerances) has been found.
absl::flat_hash_map< LinearConstraint, V > LinearConstraintMap
std::string ToString(QpSupportType qp_support)
std::ostream & operator<<(std::ostream &ostr, const IndicatorConstraint &constraint)
@ kUndetermined
Solver does not claim a feasibility status.
@ kFeasible
Solver claims the solution is feasible.
@ kInfeasible
Solver claims the solution is infeasible.
@ kMemory
The algorithm stopped because it ran out of memory.
@ kTime
The algorithm stopped after a user-specified computation time.
@ kNorm
The algorithm stopped because the norm of an iterate became too large.
Matcher< SolveResult > IsOptimal(const std::optional< double > expected_primal_objective, const double tolerance)
@ kUndetermined
Solver does not claim a status.
In SWIG mode, we don't want anything besides these top-level includes.
void AbslStringify(Sink &sink, StrongIndex< T... > arg)
Bounds on the optimal objective value.
static ObjectiveBounds MakeTrivial(bool is_maximize)
ObjectiveBoundsProto Proto() const
static ObjectiveBounds MinimizeMakeTrivial()
static ObjectiveBounds MakeUnbounded(bool is_maximize)
static ObjectiveBounds MinimizeMakeUnbounded()
static ObjectiveBounds MakeOptimal(double objective_value)
Sets both bounds to objective_value.
static ObjectiveBounds FromProto(const ObjectiveBoundsProto &objective_bounds_proto)
static ObjectiveBounds MaximizeMakeTrivial()
static ObjectiveBounds MaximizeMakeUnbounded()
std::string ToString() const
ProblemStatusProto Proto() const
std::string ToString() const
FeasibilityStatus primal_status
Status for the primal problem.
bool primal_or_dual_infeasible
static absl::StatusOr< ProblemStatus > FromProto(const ProblemStatusProto &problem_status_proto)
Returns an error if the primal_status or dual_status is unspecified.
FeasibilityStatus dual_status
Status for the dual problem (or for the dual of a continuous relaxation).
int first_order_iterations
absl::StatusOr< SolveStatsProto > Proto() const
Will return an error if solve_time is not finite.
std::string ToString() const
absl::Duration solve_time
static absl::StatusOr< SolveStats > FromProto(const SolveStatsProto &solve_stats_proto)
Returns an error if converting the problem_status or solve_time fails.
All information regarding why a call to Solve() terminated.
const PrimalSolution & best_primal_solution() const
Termination(bool is_maximize, TerminationReason reason, std::string detail={})
const LinearConstraintMap< double > & dual_values() const
double best_objective_bound() const
absl::Status EnsureIsOptimalOrFeasible() const
const VariableMap< BasisStatus > & variable_status() const
const VariableMap< double > & ray_reduced_costs() const
const VariableMap< double > & reduced_costs() const
bool bounded() const
Returns true only if the problem has been shown to be feasible and bounded.
const LinearConstraintMap< double > & ray_dual_values() const
double objective_value(Objective objective) const
const VariableMap< double > & variable_values() const
const VariableMap< double > & ray_variable_values() const
bool limit_reached() const
double objective_value() const
bool has_dual_ray() const
bool has_basis() const
Indicates if the best solution has an associated basis.
ProblemStatus problem_status
Feasibility statuses for primal and dual problems.
bool has_dual_feasible_solution() const
const LinearConstraintMap< BasisStatus > & constraint_status() const
std::optional< Limit > limit
ObjectiveBounds objective_bounds
Bounds on the optimal objective value.
double objective_value
The value objective_vector^T * (solution - center_point).