Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions check/TestLpSolvers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,27 @@ TEST_CASE("issue-2300", "[highs_lp_solver]") {

h.resetThreadScheduler(true);
}

TEST_CASE("issue-3564", "[highs_lp_solver]") {
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
std::string model_file = test_name + ".lp";
FILE* file = fopen(model_file.c_str(), "w");
fprintf(file, "%s",
"min\n obj: +230.9345703125 x12 \nst\n r0: +0.34375 x1 +0.03125 x3 "
">= -849.4453125\n r4: +0.015625 x0 +224 x6 = +76.37109375\n r9: "
"+2.75 x1 +84 x3 -0.0283203125 x6 +72 x12 = -1445.8564453125\n "
"r17lo: -0.0390625 x0 +452 x3 >= -6094.146484375\n r17up: -0.0390625 "
"x0 +452 x3 <= -6058.146484375\nbounds\n -2 <= x0\n -inf <= x1 <= "
"9\n x3 free\n x6 free\n -inf <= x12 <= 39\nend\n");
fclose(file);
Highs h;
h.setOptionValue("output_flag", dev_run);
h.setOptionValue("log_dev_level", 1);
REQUIRE(h.readModel(model_file) == HighsStatus::kOk);
REQUIRE(h.run() == HighsStatus::kOk);
REQUIRE(h.getModelStatus() == HighsModelStatus::kUnbounded);

std::remove(model_file.c_str());

h.resetThreadScheduler(true);
}
5 changes: 3 additions & 2 deletions highs/lp_data/HConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ enum class HighsPresolveStatus {
kOptionsError, // V2.0: Delete since it's not used!
kNotSet,
kOutOfMemory, // V2.0: Move above kNotSet
kException // V2.0: Move above kNotSet
kException, // V2.0: Move above kNotSet
kMatrixValueError
};

enum class HighsPostsolveStatus { // V2.0: Delete if not used!
Expand All @@ -220,7 +221,7 @@ enum class HighsModelStatus {
kNotset = 0,
kLoadError, // V2.0: Delete since it's not used!
kModelError,
kPresolveError, // V2.0: Delete since it's not used!
kPresolveError,
kSolveError,
kPostsolveError, // V2.0: Delete if not used! Add to documentation if used
kModelEmpty,
Expand Down
28 changes: 21 additions & 7 deletions highs/lp_data/Highs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,9 +1188,15 @@ HighsStatus Highs::presolve() {
}
default: {
assert(model_presolve_status_ == HighsPresolveStatus::kOutOfMemory ||
model_presolve_status_ == HighsPresolveStatus::kException);
setHighsModelStatusAndClearSolutionAndBasis(
HighsModelStatus::kPresolveError);
model_presolve_status_ == HighsPresolveStatus::kException ||
model_presolve_status_ == HighsPresolveStatus::kMatrixValueError);
HighsModelStatus model_status;
if (model_presolve_status_ == HighsPresolveStatus::kOutOfMemory) {
model_status = HighsModelStatus::kMemoryLimit;
} else {
model_status = HighsModelStatus::kPresolveError;
}
setHighsModelStatusAndClearSolutionAndBasis(model_status);
return_status = HighsStatus::kError;
}
}
Expand Down Expand Up @@ -1803,8 +1809,9 @@ HighsStatus Highs::calledOptimizeModel() {
// ToDo. Analyse the extent of small value creation. See #1187
assert(assessLp(reduced_lp, options_) == HighsStatus::kOk);
} else {
reduced_lp.a_matrix_.assessSmallValues(options_.log_options,
options_.small_matrix_value);
// Just analyse extreme values: none is changed
reduced_lp.a_matrix_.assessExtremeValues("of presolved problem ",
options_);
}
call_status = cleanBounds(options_, reduced_lp);
// Ignore any warning from clean bounds since the original LP
Expand Down Expand Up @@ -1945,13 +1952,18 @@ HighsStatus Highs::calledOptimizeModel() {
HighsModelStatus::kSolveError);
return returnFromOptimizeModel(HighsStatus::kError, undo_mods);
}
case HighsPresolveStatus::kMatrixValueError: {
setHighsModelStatusAndClearSolutionAndBasis(
HighsModelStatus::kPresolveError);
return returnFromOptimizeModel(HighsStatus::kError, undo_mods);
}
default: {
assert(model_presolve_status_ == HighsPresolveStatus::kNullError);
setHighsModelStatusAndClearSolutionAndBasis(
HighsModelStatus::kPresolveError);
highsLogDev(log_options, HighsLogType::kError,
"Presolve returned status %d\n",
(int)model_presolve_status_);
"Presolve returned status %s\n",
presolveStatusToString(model_presolve_status_).c_str());
return returnFromOptimizeModel(HighsStatus::kError, undo_mods);
}
}
Expand Down Expand Up @@ -3924,6 +3936,8 @@ std::string Highs::presolveStatusToString(
return "Memory allocation error";
case HighsPresolveStatus::kException:
return "Exception error";
case HighsPresolveStatus::kMatrixValueError:
return "Matrix value error";
default:
assert(1 == 0);
return "Unrecognised presolve status";
Expand Down
3 changes: 2 additions & 1 deletion highs/lp_data/HighsLpUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3218,7 +3218,8 @@ void reportPresolveReductions(const HighsLogOptions& log_options,
}
default: {
assert(presolve_status == HighsPresolveStatus::kOutOfMemory ||
presolve_status == HighsPresolveStatus::kException);
presolve_status == HighsPresolveStatus::kException ||
presolve_status == HighsPresolveStatus::kMatrixValueError);
return;
}
}
Expand Down
30 changes: 24 additions & 6 deletions highs/mip/HighsMipSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,27 @@ void HighsMipSolver::run() {
if (profiling_->mip_ && !submip)
highsLogUser(options_mip_->log_options, HighsLogType::kInfo,
"MIP-Timing: %11.2g - completed presolve\n", timer_.read());
// Identify whether time limit has been reached (in presolve)
if (modelstatus_ == HighsModelStatus::kNotset &&
timer_.read() >= options_mip_->time_limit)
modelstatus_ = HighsModelStatus::kTimeLimit;

if (modelstatus_ == HighsModelStatus::kNotset) {
// Time limit has been reached (in presolve)
if (mipdata_->presolve_status == HighsPresolveStatus::kTimeout
// I think this is a legacy timeout check dataing from before there was
// a timeout in presolve
//
// || timer_.read() >= options_mip_->time_limit
) {
modelstatus_ = HighsModelStatus::kTimeLimit;
} else if (mipdata_->presolve_status == HighsPresolveStatus::kOutOfMemory ||
mipdata_->presolve_status == HighsPresolveStatus::kException ||
mipdata_->presolve_status ==
HighsPresolveStatus::kMatrixValueError) {
// Handle failures in presolve
if (mipdata_->presolve_status == HighsPresolveStatus::kOutOfMemory) {
modelstatus_ = HighsModelStatus::kMemoryLimit;
} else {
modelstatus_ = HighsModelStatus::kPresolveError;
}
}
}
if (modelstatus_ != HighsModelStatus::kNotset) {
HighsModelStatus presolveStatus = modelstatus_;
if (presolveStatus == HighsModelStatus::kInfeasible &&
Expand Down Expand Up @@ -1305,7 +1321,9 @@ void HighsMipSolver::solvingReport(const std::string& solutionstatus) const {
highsLogUser(options_mip_->log_options, HighsLogType::kInfo,
" Status %s\n",
utilModelStatusToString(modelstatus_).c_str());
if (modelstatus_ != HighsModelStatus::kSolveError) {
if (modelstatus_ != HighsModelStatus::kSolveError &&
modelstatus_ != HighsModelStatus::kMemoryLimit &&
modelstatus_ != HighsModelStatus::kPresolveError) {
highsLogUser(options_mip_->log_options, HighsLogType::kInfo,
" Primal bound %.12g\n"
" Dual bound %.12g\n"
Expand Down
4 changes: 1 addition & 3 deletions highs/mip/HighsMipSolverData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,7 @@ void HighsMipSolverData::runMipPresolve(
presolve_status = presolve.getPresolveStatus();
mipsolver.timer_.stop(mipsolver.timer_.presolve_clock);

if (presolve_status == HighsPresolveStatus::kOutOfMemory ||
presolve_status == HighsPresolveStatus::kException)
return;
if (presolve.failed()) return;
// Report the final presolve reductions unless this is a restart
if (mipsolver.options_mip_->presolve != kHighsOffString && numRestarts == 0)
reportPresolveReductions(mipsolver.options_mip_->log_options,
Expand Down
5 changes: 3 additions & 2 deletions highs/model/HighsHessian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,9 @@ HighsStatus HighsHessian::trimDimensions(const HighsLogOptions& log_options) {
hessian_p_end, this->index_, this->value_);
}

HighsStatus HighsHessian::assess(const HighsOptions& options) {
return assessHessian(*this, options);
HighsStatus HighsHessian::assess(const HighsOptions& options,
const std::string* col_names) {
return assessHessian(*this, options, col_names);
}

HighsStatus HighsHessian::checkOracle(const HighsLogOptions& log_options,
Expand Down
3 changes: 2 additions & 1 deletion highs/model/HighsHessian.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class HighsHessian {
void print(const std::string& message = "") const;
bool legalDimensions(const HighsLogOptions& log_options) const;
HighsStatus trimDimensions(const HighsLogOptions& log_options);
HighsStatus assess(const HighsOptions& options);
HighsStatus assess(const HighsOptions& options,
const std::string* col_names = nullptr);
};

#endif
14 changes: 8 additions & 6 deletions highs/model/HighsHessianUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

using std::fabs;

HighsStatus assessHessian(HighsHessian& hessian, const HighsOptions& options) {
HighsStatus assessHessian(HighsHessian& hessian, const HighsOptions& options,
const std::string* col_names) {
if (hessian.isOracle()) return HighsStatus::kOk;
const HighsLogOptions& log_options = options.log_options;
if (!hessian.legalDimensions(log_options)) return HighsStatus::kError;
Expand All @@ -46,7 +47,7 @@ HighsStatus assessHessian(HighsHessian& hessian, const HighsOptions& options) {
HighsStatus call_status =
assessMatrix(log_options, "HighsHessian", hessian.name_, hessian.dim_,
hessian.dim_, hessian.start_, hessian.index_, hessian.value_,
0, kHighsInf, sum_duplicates);
0, kHighsInf, sum_duplicates, col_names, col_names);
return_status = interpretCallStatus(log_options, call_status, return_status,
"assessMatrix");
if (return_status == HighsStatus::kError) return return_status;
Expand All @@ -57,10 +58,11 @@ HighsStatus assessHessian(HighsHessian& hessian, const HighsOptions& options) {
if (return_status == HighsStatus::kError) return return_status;
// Assess values in Q
sum_duplicates = false;
call_status = assessMatrix(
log_options, "HighsHessian", hessian.name_, hessian.dim_, hessian.dim_,
hessian.start_, hessian.index_, hessian.value_,
options.small_matrix_value, options.large_matrix_value, sum_duplicates);
call_status =
assessMatrix(log_options, "HighsHessian", hessian.name_, hessian.dim_,
hessian.dim_, hessian.start_, hessian.index_, hessian.value_,
options.small_matrix_value, options.large_matrix_value,
sum_duplicates, col_names, col_names);
return_status = interpretCallStatus(log_options, call_status, return_status,
"assessMatrix");
if (return_status == HighsStatus::kError) return return_status;
Expand Down
3 changes: 2 additions & 1 deletion highs/model/HighsHessianUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

using std::vector;

HighsStatus assessHessian(HighsHessian& hessian, const HighsOptions& options);
HighsStatus assessHessian(HighsHessian& hessian, const HighsOptions& options,
const std::string* col_names = nullptr);
void completeHessianDiagonal(const HighsOptions& options,
HighsHessian& hessian);
bool okHessianDiagonal(const HighsOptions& options, HighsHessian& hessian,
Expand Down
25 changes: 25 additions & 0 deletions highs/presolve/HPresolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4671,6 +4671,31 @@ HighsModelStatus HPresolve::run(HighsPostsolveStack& postsolve_stack) {
} else if (postsolve_stack.numReductions() > 0) {
// Reductions performed
presolve_status_ = HighsPresolveStatus::kReduced;
const bool kCheckReducedMatrix = false;
if (kCheckReducedMatrix) {
// Although presolve can yield small nonzero values in the matrix,
// they may play a meaningful role in postsolve so they are
// retained. However, they offer some risk to the simplex solver,
// so HighsSparseMatrix::assessExtremeValues logs a warning and
// returns HighsStatus::kWarning.
//
// Presolve should never generate explicit zeros or large values
// in the matrix, and these cannot be permitted in the simplex
// solver, so HighsSparseMatrix::assessExtremeValues logs an error
// in either case, and returns HighsStatus::kError, triggering a
// presolve error
if (model->a_matrix_.assessExtremeValues(
"of presolved problem ", *(options)) == HighsStatus::kError) {
presolve_status_ = HighsPresolveStatus::kMatrixValueError;
} else {
// The reduced LP constraint matrix is set up in presolve, so
// should be valid structurally, so assert this now - AFTER
// assessing extreme values, since explicit zeros are removed
// silently in HighsSparseMatrix::assessStructure
assert(model->a_matrix_.assessStructure(*(options)) ==
HighsStatus::kOk);
}
}
} else {
// No reductions performed
presolve_status_ = HighsPresolveStatus::kNotReduced;
Expand Down
6 changes: 6 additions & 0 deletions highs/presolve/HPresolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ class HPresolve {

HighsPresolveStatus getPresolveStatus() const { return presolve_status_; }

bool failed() const {
return presolve_status_ == HighsPresolveStatus::kOutOfMemory ||
presolve_status_ == HighsPresolveStatus::kException ||
presolve_status_ == HighsPresolveStatus::kMatrixValueError;
}

bool zeroRowActivityFeasible() const;

HighsInt debugGetCheckCol() const;
Expand Down
4 changes: 1 addition & 3 deletions highs/presolve/PresolveComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ HighsPresolveStatus PresolveComponent::run() {
options_->presolve_reduction_limit, timer);
presolve.run(data_.postSolveStack);
presolve_status_ = presolve.getPresolveStatus();
if (presolve_status_ != HighsPresolveStatus::kOutOfMemory &&
presolve_status_ != HighsPresolveStatus::kException)
data_.presolve_log_ = presolve.getPresolveLog();
if (!presolve.failed()) data_.presolve_log_ = presolve.getPresolveLog();
return presolve_status_;
}

Expand Down
11 changes: 8 additions & 3 deletions highs/simplex/HEkk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2298,11 +2298,16 @@ void HEkk::initialisePartitionedRowwiseMatrix() {
analysis_.simplexTimerStart(matrixSetupClock);
ar_matrix_.createRowwisePartitioned(lp_.a_matrix_,
basis_.nonbasicFlag_.data());
ar_matrix_.name_ = "partitioned row-wise constraint";
// The partitioned row-wise matrix is generated from an accepted
// constraint matrix, so it is OK so long as it's been constructed
// correctly.
assert(ar_matrix_.legalDimensions(options_->log_options));
assert(ar_matrix_.trimDimensions(options_->log_options) == HighsStatus::kOk);
assert(ar_matrix_.assess(options_->log_options, options_->small_matrix_value,
options_->large_matrix_value,
false) == HighsStatus::kOk);
// In particular, only its structure should be assessed, as its
// values are inherited from the constraint matrix, and may contain
// small values from presolve
assert(ar_matrix_.assessStructure(*options_) == HighsStatus::kOk);
assert(ar_matrix_.debugPartitionOk(basis_.nonbasicFlag_.data()));
analysis_.simplexTimerStop(matrixSetupClock);
status_.has_ar_matrix = true;
Expand Down
Loading
Loading