Skip to content

Commit 7306852

Browse files
committed
Need HighsIis::feasible_
1 parent 2dc77c5 commit 7306852

File tree

4 files changed

+46
-21
lines changed

4 files changed

+46
-21
lines changed

check/TestIis.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ TEST_CASE("lp-feasibility-relaxation", "[iis]") {
491491
h.setOptionValue("output_flag", dev_run);
492492
const HighsSolution& solution = h.getSolution();
493493
h.passModel(lp);
494-
// h.run();
495494

496495
const bool all_tests = false;
497496
const bool test0 = false || all_tests;
@@ -586,7 +585,7 @@ void testMps(std::string& model, const HighsInt iis_strategy,
586585
std::string model_file =
587586
std::string(HIGHS_DIR) + "/check/instances/" + model + ".mps";
588587
Highs highs;
589-
// highs.setOptionValue("output_flag", dev_run);
588+
highs.setOptionValue("output_flag", dev_run);
590589

591590
REQUIRE(highs.readModel(model_file) == HighsStatus::kOk);
592591
// if (iis_strategy == kIisStrategyFromRay ||
@@ -658,7 +657,7 @@ TEST_CASE("feasible-lp-iis", "[iis]") {
658657
lp.a_matrix_.index_ = {0, 1, 0, 1};
659658
lp.a_matrix_.value_ = {1, 1, 2, 4};
660659
Highs h;
661-
h.setOptionValue("output_flag", dev_run);
660+
// h.setOptionValue("output_flag", dev_run);
662661
h.passModel(lp);
663662
HighsIis iis;
664663
// With kIisStrategyLight, feasibility of the LP is not determined

highs/lp_data/HighsIis.cpp

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,28 @@ void HighsIis::setLp(const HighsLp& lp) {
469469
iis_lp.model_name_ = lp.model_name_ + "_IIS";
470470
}
471471

472-
void HighsIis::setStatus(const HighsLp& lp) {
472+
HighsInt HighsIis::nonIsStatus(const HighsModelStatus& model_status) const {
473+
const bool is_feasible =
474+
model_status == HighsModelStatus::kOptimal ||
475+
model_status == HighsModelStatus::kUnbounded;
476+
const bool has_is = this->col_index_.size() || this->row_index_.size();
477+
// If the model is known to be feasible, then there should be no IS,
478+
// and all columns and rows are kIisStatusNotInConflict
479+
if (is_feasible) assert(!has_is);
480+
// If there is an IS, then all columns and rows not in the IS are
481+
// kIisStatusNotInConflict
482+
const HighsInt default_iis_status = is_feasible || has_is ?
483+
kIisStatusNotInConflict :
484+
kIisStatusMaybeInConflict;
485+
return default_iis_status;
486+
}
487+
488+
void HighsIis::setStatus(const HighsLp& lp,
489+
const HighsModelStatus& model_status) {
473490
if (!this->valid_) return;
474-
this->col_status_.assign(lp.num_col_, kIisStatusNotInConflict);
475-
this->row_status_.assign(lp.num_row_, kIisStatusNotInConflict);
491+
const HighsInt non_is_status = nonIsStatus(model_status);
492+
this->col_status_.assign(lp.num_col_, non_is_status);
493+
this->row_status_.assign(lp.num_row_, non_is_status);
476494
HighsInt iis_num_col = this->col_index_.size();
477495
HighsInt iis_num_row = this->row_index_.size();
478496
for (HighsInt iisCol = 0; iisCol < iis_num_col; iisCol++)
@@ -809,7 +827,8 @@ HighsStatus HighsIis::compute(const HighsLp& lp, const HighsOptions& options,
809827

810828
bool indexStatusOkReturn(const bool return_value) { return return_value; }
811829

812-
bool HighsIis::indexStatusOk(const HighsLp& lp) const {
830+
bool HighsIis::indexStatusOk(const HighsLp& lp,
831+
const HighsModelStatus& model_status) const {
813832
HighsInt num_col = lp.num_col_;
814833
HighsInt num_row = lp.num_row_;
815834
bool col_status_size_ok =
@@ -843,26 +862,30 @@ bool HighsIis::indexStatusOk(const HighsLp& lp) const {
843862
// other cols and rows are kIisStatusNotConflict
844863
std::vector<HighsInt> col_status = col_status_;
845864
std::vector<HighsInt> row_status = row_status_;
865+
const HighsInt illegal_status = -99;
846866
for (HighsInt iX = 0; iX < num_iis_col; iX++) {
847867
HighsInt iCol = this->col_index_[iX];
848868
if (col_status_[iCol] != true_iis ? kIisStatusInConflict
849869
: kIisStatusMaybeInConflict)
850870
return indexStatusOkReturn(false);
851-
col_status[iCol] = -1;
871+
col_status[iCol] = illegal_status;
852872
}
853873
for (HighsInt iX = 0; iX < num_iis_row; iX++) {
854874
HighsInt iRow = this->row_index_[iX];
855875
if (row_status_[iRow] != true_iis ? kIisStatusInConflict
856876
: kIisStatusMaybeInConflict)
857877
return indexStatusOkReturn(false);
858-
row_status[iRow] = -1;
878+
row_status[iRow] = illegal_status;
859879
}
880+
const HighsInt non_is_status = nonIsStatus(model_status);
860881
for (HighsInt iCol = 0; iCol < num_col; iCol++) {
861-
if (col_status[iCol] >= 0 && col_status[iCol] != kIisStatusNotInConflict)
882+
if (col_status[iCol] > illegal_status &&
883+
col_status[iCol] != non_is_status)
862884
return indexStatusOkReturn(false);
863885
}
864886
for (HighsInt iRow = 0; iRow < num_row; iRow++) {
865-
if (row_status[iRow] >= 0 && row_status[iRow] != kIisStatusNotInConflict)
887+
if (row_status[iRow] > illegal_status &&
888+
row_status[iRow] != non_is_status)
866889
return indexStatusOkReturn(false);
867890
}
868891
return indexStatusOkReturn(true);

highs/lp_data/HighsIis.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,18 @@ class HighsIis {
4444
HighsStatus deduce(const HighsLp& lp, const HighsOptions& options,
4545
const HighsBasis& basis);
4646
void setLp(const HighsLp& lp);
47-
void setStatus(const HighsLp& lp);
47+
HighsInt nonIsStatus(const HighsModelStatus& model_status) const;
48+
void setStatus(const HighsLp& lp,
49+
const HighsModelStatus& model_status);
4850

4951
HighsStatus compute(const HighsLp& lp, const HighsOptions& options,
5052
const HighsBasis* basis = nullptr);
5153

5254
bool trivial(const HighsLp& lp, const HighsOptions& options);
5355
bool rowValueBounds(const HighsLp& lp, const HighsOptions& options);
5456

55-
bool indexStatusOk(const HighsLp& lp) const;
57+
bool indexStatusOk(const HighsLp& lp,
58+
const HighsModelStatus& model_status) const;
5659
bool lpDataOk(const HighsLp& lp, const HighsOptions& options) const;
5760
bool lpOk(const HighsOptions& options) const;
5861

highs/lp_data/HighsInterface.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,9 +1870,9 @@ HighsStatus Highs::getIisInterfaceReturn(const HighsStatus return_status) {
18701870
}
18711871
// Construct the ISS status vectors for cols and rows of original
18721872
// model
1873-
this->iis_.setStatus(lp);
1873+
this->iis_.setStatus(lp, this->model_status_);
18741874
// Check consistency of the col/row_index_ and col/row_status_
1875-
bool index_status_ok = this->iis_.indexStatusOk(lp);
1875+
bool index_status_ok = this->iis_.indexStatusOk(lp, this->model_status_);
18761876
assert(index_status_ok);
18771877
if (!index_status_ok) return HighsStatus::kError;
18781878

@@ -2102,14 +2102,14 @@ HighsStatus Highs::elasticityFilterReturn(
21022102
getKktFailures(options_, model_, solution_, basis_, info_);
21032103
info_.valid = true;
21042104
}
2105-
2106-
// If the model is feasible, then the status of model is not known
2107-
if (feasible_model) this->model_status_ = HighsModelStatus::kNotset;
2108-
// The
2109-
assert(!feasible_model == (model_status == HighsModelStatus::kInfeasible));
21102105
// The elasticity filter may well have identified infeasiblility, so
21112106
// set this->model_status_
2112-
if (!feasible_model) this->model_status_ = HighsModelStatus::kInfeasible;
2107+
if (!feasible_model) {
2108+
this->model_status_ = HighsModelStatus::kInfeasible;
2109+
} else {
2110+
// If the model is feasible, then the status of model is not known
2111+
this->model_status_ = HighsModelStatus::kNotset;
2112+
}
21132113
this->iis_ = iis;
21142114
return return_status;
21152115
}

0 commit comments

Comments
 (0)