19#include "absl/container/flat_hash_map.h"
20#include "absl/log/check.h"
21#include "absl/status/status.h"
22#include "absl/strings/string_view.h"
23#include "absl/types/span.h"
29#include "ortools/math_opt/solution.pb.h"
30#include "ortools/math_opt/sparse_containers.pb.h"
45 return "undetermined";
56 return absl::MakeConstSpan(kSolutionStatusValues);
60 const ModelStorage*
model,
61 const PrimalSolutionProto& primal_solution_proto) {
64 primal_solution.variable_values,
66 _ <<
"invalid variable_values");
67 primal_solution.objective_value = primal_solution_proto.objective_value();
69 primal_solution.auxiliary_objective_values,
71 model, primal_solution_proto.auxiliary_objective_values()),
72 _ <<
"invalid auxiliary_objective_values");
76 return absl::InvalidArgumentError(
"feasibility_status must be specified");
79 return primal_solution;
83 PrimalSolutionProto result;
86 *result.mutable_auxiliary_objective_values() =
107 const ModelStorage*
model,
const PrimalRayProto& primal_ray_proto) {
112 _ <<
"invalid variable_values");
117 PrimalRayProto result;
123 const ModelStorage*
model,
const DualSolutionProto& dual_solution_proto) {
128 _ <<
"invalid dual_values");
131 model, dual_solution_proto.quadratic_dual_values()),
132 _ <<
"invalid quadratic_dual_values");
136 _ <<
"invalid reduced_costs");
137 if (dual_solution_proto.has_objective_value()) {
143 return absl::InvalidArgumentError(
"feasibility_status must be specified");
146 return dual_solution;
150 DualSolutionProto result;
152 *result.mutable_quadratic_dual_values() =
163 const DualRayProto& dual_ray_proto) {
168 _ <<
"invalid dual_values");
172 _ <<
"invalid reduced_costs");
184 const BasisProto& basis_proto) {
189 _ <<
"invalid constraint_status");
193 _ <<
"invalid variable_status");
200 const ModelStorage*
const expected_storage)
const {
205 <<
"invalid variable " << v <<
" in variable_status";
211 <<
"invalid constraint " <<
c <<
" in constraint_status";
213 return absl::OkStatus();
218 *result.mutable_constraint_status() =
226 const ModelStorage*
model,
const SolutionProto& solution_proto) {
228 if (solution_proto.has_primal_solution()) {
232 _ <<
"invalid primal_solution");
234 if (solution_proto.has_dual_solution()) {
238 _ <<
"invalid dual_solution");
240 if (solution_proto.has_basis()) {
243 _ <<
"invalid basis");
249 SolutionProto result;
256 if (
basis.has_value()) {
257 *result.mutable_basis() =
basis->Proto();
#define RETURN_IF_ERROR(expr)
const ModelStorage * storage() const
const ModelStorage * storage() const
Returns a const-pointer to the underlying storage object for the model.
absl::Status CheckModelStorage(const ModelStorage *const storage, const ModelStorage *const expected_storage)
google::protobuf::Map< int64_t, double > AuxiliaryObjectiveValuesToProto(const absl::flat_hash_map< Objective, double > &aux_obj_values)
absl::StatusOr< absl::flat_hash_map< Objective, double > > AuxiliaryObjectiveValuesFromProto(const ModelStorage *const model, const google::protobuf::Map< int64_t, double > &aux_obj_proto)
SparseDoubleVectorProto LinearConstraintValuesToProto(const LinearConstraintMap< double > &linear_constraint_values)
Returns the proto equivalent of linear_constraint_values.
absl::StatusOr< LinearConstraintMap< BasisStatus > > LinearConstraintBasisFromProto(const ModelStorage *const model, const SparseBasisStatusVector &basis_proto)
absl::StatusOr< absl::flat_hash_map< QuadraticConstraint, double > > QuadraticConstraintValuesFromProto(const ModelStorage *const model, const SparseDoubleVectorProto &quad_cons_proto)
absl::StatusOr< LinearConstraintMap< double > > LinearConstraintValuesFromProto(const ModelStorage *const model, const SparseDoubleVectorProto &lin_cons_proto)
std::optional< typename EnumProto< P >::Cpp > EnumFromProto(P proto_value)
absl::StatusOr< VariableMap< double > > VariableValuesFromProto(const ModelStorage *const model, const SparseDoubleVectorProto &vars_proto)
SolutionStatus
Feasibility of a primal or dual solution as claimed by the solver.
@ kUndetermined
Solver does not claim a feasibility status.
@ kFeasible
Solver claims the solution is feasible.
@ kInfeasible
Solver claims the solution is infeasible.
SparseBasisStatusVector VariableBasisToProto(const VariableMap< BasisStatus > &basis_values)
Returns the proto equivalent of basis_values.
SparseBasisStatusVector LinearConstraintBasisToProto(const LinearConstraintMap< BasisStatus > &basis_values)
Returns the proto equivalent of basis_values.
SparseDoubleVectorProto VariableValuesToProto(const VariableMap< double > &variable_values)
Returns the proto equivalent of variable_values.
SparseDoubleVectorProto QuadraticConstraintValuesToProto(const absl::flat_hash_map< QuadraticConstraint, double > &quadratic_constraint_values)
Returns the proto equivalent of quadratic_constraint_values.
Enum< E >::Proto EnumToProto(std::optional< E > value)
absl::StatusOr< VariableMap< BasisStatus > > VariableBasisFromProto(const ModelStorage *const model, const SparseBasisStatusVector &basis_proto)
In SWIG mode, we don't want anything besides these top-level includes.
absl::Status CheckModelStorage(const ModelStorage *expected_storage) const
LinearConstraintMap< BasisStatus > constraint_status
static absl::StatusOr< Basis > FromProto(const ModelStorage *model, const BasisProto &basis_proto)
VariableMap< BasisStatus > variable_status
std::optional< SolutionStatus > basic_dual_feasibility
DualRayProto Proto() const
Returns the proto equivalent of this.
static absl::StatusOr< DualRay > FromProto(const ModelStorage *model, const DualRayProto &dual_ray_proto)
LinearConstraintMap< double > dual_values
VariableMap< double > reduced_costs
static absl::StatusOr< DualSolution > FromProto(const ModelStorage *model, const DualSolutionProto &dual_solution_proto)
LinearConstraintMap< double > dual_values
absl::flat_hash_map< QuadraticConstraint, double > quadratic_dual_values
std::optional< double > objective_value
DualSolutionProto Proto() const
Returns the proto equivalent of this.
SolutionStatus feasibility_status
VariableMap< double > reduced_costs
static absl::Span< const E > AllValues()
Returns all possible values of the enum.
static std::optional< absl::string_view > ToOptString(E value)
PrimalRayProto Proto() const
Returns the proto equivalent of this.
VariableMap< double > variable_values
static absl::StatusOr< PrimalRay > FromProto(const ModelStorage *model, const PrimalRayProto &primal_ray_proto)
absl::flat_hash_map< Objective, double > auxiliary_objective_values
static absl::StatusOr< PrimalSolution > FromProto(const ModelStorage *model, const PrimalSolutionProto &primal_solution_proto)
PrimalSolutionProto Proto() const
Returns the proto equivalent of this.
SolutionStatus feasibility_status
double get_objective_value(Objective objective) const
VariableMap< double > variable_values
std::optional< Basis > basis
std::optional< PrimalSolution > primal_solution
std::optional< DualSolution > dual_solution
SolutionProto Proto() const
Returns the proto equivalent of this.
static absl::StatusOr< Solution > FromProto(const ModelStorage *model, const SolutionProto &solution_proto)
#define OR_ASSIGN_OR_RETURN3(lhs, rexpr, error_expression)