Skip to content

Commit

Permalink
Merge pull request #2188 from ERGO-Code/od/solve-error
Browse files Browse the repository at this point in the history
Update model_status when checkOptimality fails
  • Loading branch information
jajhall authored Mar 1, 2025
2 parents ef5be32 + dee36a9 commit 45aa121
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
20 changes: 20 additions & 0 deletions check/TestCAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -1967,6 +1967,25 @@ void test_multiObjective() {
free(col_value);
}

void test_qp_indefinite_failure() {
void* highs = Highs_create();
HighsInt ret;
const double inf = Highs_getInfinity(highs);
ret = Highs_addCol(highs, 0.0, 1.0, inf, 0, NULL, NULL);
assert(ret == 0);
ret = Highs_addCol(highs, 0.0, 1.0, 1.0, 0, NULL, NULL);
HighsInt start[2] = {0, 1};
HighsInt index[1] = {1};
double value[1] = {1.0};
ret = Highs_passHessian(highs, 2, 1, kHighsHessianFormatTriangular, start, index, value);
assert(ret == 0);
HighsInt run_status = Highs_run(highs);
HighsInt model_status = Highs_getModelStatus(highs);
assert(run_status == kHighsStatusError);
assert(model_status == kHighsModelStatusSolveError);
Highs_destroy(highs);
}

/*
The horrible C in this causes problems in some of the CI tests,
so suppress thius test until the C has been improved
Expand Down Expand Up @@ -2032,6 +2051,7 @@ int main() {
test_feasibilityRelaxation();
test_getModel();
test_multiObjective();
test_qp_indefinite_failure();
return 0;
}
// test_setSolution();
27 changes: 21 additions & 6 deletions src/lp_data/Highs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3746,8 +3746,13 @@ HighsStatus Highs::callSolveLp(HighsLp& lp, const string message) {
return_status = solveLp(solver_object, message);
// Extract the model status
model_status_ = solver_object.model_status_;
if (model_status_ == HighsModelStatus::kOptimal)
checkOptimality("LP", return_status);
if (model_status_ == HighsModelStatus::kOptimal) {
HighsStatus check_status = checkOptimality("LP", return_status);
if (check_status == HighsStatus::kError) {
return_status = check_status;
solver_object.model_status_ = HighsModelStatus::kSolveError;
}
}
return return_status;
}

Expand Down Expand Up @@ -3892,8 +3897,13 @@ HighsStatus Highs::callSolveQp() {
info_.simplex_iteration_count += stats.phase1_iterations;
info_.qp_iteration_count += stats.num_iterations;
info_.valid = true;
if (model_status_ == HighsModelStatus::kOptimal)
checkOptimality("QP", return_status);
if (model_status_ == HighsModelStatus::kOptimal) {
HighsStatus check_status = checkOptimality("QP", return_status);
if (check_status == HighsStatus::kError) {
return_status = check_status;
model_status_ = HighsModelStatus::kSolveError;
}
}
return return_status;
}

Expand Down Expand Up @@ -3987,8 +3997,13 @@ HighsStatus Highs::callSolveMip() {
? -1
: HighsInt(mip_total_lp_iterations);
info_.valid = true;
if (model_status_ == HighsModelStatus::kOptimal)
checkOptimality("MIP", return_status);
if (model_status_ == HighsModelStatus::kOptimal) {
HighsStatus check_status = checkOptimality("MIP", return_status);
if (check_status == HighsStatus::kError) {
return_status = check_status;
model_status_ = HighsModelStatus::kSolveError;
}
}
if (use_mip_feasibility_tolerance) {
// Overwrite max infeasibility to include integrality if there is a solution
if (solver.solution_objective_ != kHighsInf) {
Expand Down

0 comments on commit 45aa121

Please sign in to comment.