43 static absl::StatusOr<std::unique_ptr<SolverInterface>>
New(
46 absl::StatusOr<SolveResultProto>
Solve(
48 const ModelSolveParametersProto& model_parameters,
50 const CallbackRegistrationProto& callback_registration,
Callback cb,
52 absl::StatusOr<bool>
Update(
const ModelUpdateProto& model_update)
override;
53 absl::StatusOr<ComputeInfeasibleSubsystemResultProto>
59 struct SolutionClaims {
60 bool highs_returned_primal_feasible_solution =
false;
61 bool highs_returned_dual_feasible_solution =
false;
62 bool highs_returned_primal_ray =
false;
63 bool highs_returned_dual_ray =
false;
65 struct SolutionsAndClaims {
66 std::vector<SolutionProto> solutions;
68 SolutionClaims solution_claims;
77 struct IndexAndBound {
88 bool bounds_cross()
const {
return lb > ub; }
93 double rounded_lb()
const {
return is_integer ? std::ceil(lb) : lb; }
94 double rounded_ub()
const {
return is_integer ? std::floor(ub) : ub; }
95 bool rounded_bounds_cross()
const {
return rounded_lb() > rounded_ub(); }
97 IndexAndBound(
int index,
double lb,
double ub,
bool is_integer)
98 :
index(
index), lb(lb), ub(ub), is_integer(is_integer) {}
101 absl::flat_hash_map<int64_t, IndexAndBound> variable_data,
102 absl::flat_hash_map<int64_t, IndexAndBound> lin_con_data)
103 : highs_(std::move(highs)),
104 variable_data_(std::move(variable_data)),
105 lin_con_data_(std::move(lin_con_data)) {}
107 absl::StatusOr<bool> PrimalRayReturned()
const;
108 absl::StatusOr<bool> DualRayReturned()
const;
112 absl::StatusOr<SolutionsAndClaims> ExtractSolutionAndRays(
113 const ModelSolveParametersProto& model_params);
115 static absl::StatusOr<FeasibilityStatusProto> PrimalFeasibilityStatus(
116 SolutionClaims solution_claims);
117 static absl::StatusOr<FeasibilityStatusProto> DualFeasibilityStatus(
118 const HighsInfo& highs_info,
bool is_integer,
119 SolutionClaims solution_claims);
120 static absl::StatusOr<TerminationProto> MakeTermination(
121 HighsModelStatus highs_model_status,
const HighsInfo& highs_info,
122 bool is_integer,
bool had_node_limit,
bool had_solution_limit,
123 bool is_maximize, SolutionClaims solution_claims);
127 absl::StatusOr<std::optional<BasisProto>> ExtractBasis();
129 template <
typename T>
130 absl::Status EnsureOneEntryPerVariable(
const std::vector<T>& vec) {
131 if (vec.size() != variable_data_.size()) {
133 <<
"expected one entry per variable, but model had "
134 << variable_data_.size() <<
" variables and found " << vec.size()
137 return absl::OkStatus();
140 template <
typename T>
141 absl::Status EnsureOneEntryPerLinearConstraint(
const std::vector<T>& vec) {
142 if (vec.size() != lin_con_data_.size()) {
144 <<
"expected one entry per linear constraint, but model had "
145 << lin_con_data_.size() <<
" linear constraints and found "
146 << vec.size() <<
" elements";
148 return absl::OkStatus();
157 static SolveResultProto ResultForHighsModelStatusModelEmpty(
158 bool is_maximize,
double objective_offset,
159 const absl::flat_hash_map<int64_t, IndexAndBound>& lin_con_data);
163 std::unique_ptr<Highs> highs_;
166 absl::flat_hash_map<int64_t, IndexAndBound> variable_data_;
169 absl::flat_hash_map<int64_t, IndexAndBound> lin_con_data_;