Skip to content

Commit ebf25a4

Browse files
committed
Corrected the IIS LP matrix format when the incumbent LP is rowwise
1 parent defb773 commit ebf25a4

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

check/TestIis.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,23 @@ TEST_CASE("lp-get-iis", "[iis]") {
207207
highs.setOptionValue("output_flag", dev_run);
208208
highs.passModel(lp);
209209
HighsIis iis;
210-
REQUIRE(highs.getIis(iis) == HighsStatus::kOk);
211-
REQUIRE(highs.getModelStatus() == HighsModelStatus::kInfeasible);
212-
REQUIRE(iis.col_index_.size() == 2);
213-
REQUIRE(iis.row_index_.size() == 1);
214-
REQUIRE(iis.col_index_[0] == 0);
215-
REQUIRE(iis.col_index_[1] == 1);
216-
REQUIRE(iis.row_index_[0] == 2);
217-
210+
const HighsLp& highs_lp = highs.getLp();
211+
// First pass with incumbent matrix colwise; second with it
212+
// rowwise
213+
highs.ensureColwise();
214+
REQUIRE(highs_lp.a_matrix_.isColwise());
215+
for (HighsInt k = 0; k < 2; k++) {
216+
REQUIRE(highs.getIis(iis) == HighsStatus::kOk);
217+
REQUIRE(highs.getModelStatus() == HighsModelStatus::kInfeasible);
218+
REQUIRE(iis.col_index_.size() == 2);
219+
REQUIRE(iis.row_index_.size() == 1);
220+
REQUIRE(iis.col_index_[0] == 0);
221+
REQUIRE(iis.col_index_[1] == 1);
222+
REQUIRE(iis.row_index_[0] == 2);
223+
highs.clearSolver();
224+
highs.ensureRowwise();
225+
REQUIRE(highs_lp.a_matrix_.isRowwise());
226+
}
218227
highs.resetGlobalScheduler(true);
219228
}
220229

highs/lp_data/HighsIis.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,17 @@ bool HighsIis::trivial(const HighsLp& lp, const HighsOptions& options) {
124124
}
125125
// Now look for empty rows that cannot have zero activity
126126
std::vector<HighsInt> count;
127-
count.assign(lp.num_row_, 0);
128-
for (HighsInt iCol = 0; iCol < lp.num_col_; iCol++) {
129-
for (HighsInt iEl = lp.a_matrix_.start_[iCol];
130-
iEl < lp.a_matrix_.start_[iCol + 1]; iEl++)
131-
count[lp.a_matrix_.index_[iEl]]++;
127+
// Get the row counts
128+
if (lp.a_matrix_.isColwise()) {
129+
count.assign(lp.num_row_, 0);
130+
for (HighsInt iCol = 0; iCol < lp.num_col_; iCol++) {
131+
for (HighsInt iEl = lp.a_matrix_.start_[iCol];
132+
iEl < lp.a_matrix_.start_[iCol + 1]; iEl++)
133+
count[lp.a_matrix_.index_[iEl]]++;
134+
}
135+
} else {
136+
for (HighsInt iRow = 0; iRow < lp.num_row_; iRow++)
137+
count.push_back(lp.a_matrix_.start_[iRow + 1]-lp.a_matrix_.start_[iRow]);
132138
}
133139
assert(this->row_index_.size() == 0);
134140
for (HighsInt iRow = 0; iRow < lp.num_row_; iRow++) {
@@ -289,6 +295,7 @@ HighsStatus HighsIis::getData(const HighsLp& lp, const HighsOptions& options,
289295
std::vector<HighsInt> from_col;
290296
std::vector<HighsInt> to_row;
291297
to_row.assign(lp.num_row_, -1);
298+
// To get the IIS data needs the matrix to be column-wise
292299
assert(lp.a_matrix_.isColwise());
293300
// Determine how to detect whether a row is in infeasible_row and
294301
// (then) gather information about it
@@ -434,6 +441,8 @@ void HighsIis::getLp(const HighsLp& lp) {
434441
}
435442
iis_lp.num_col_ = iis_lp.col_cost_.size();
436443
iis_lp.num_row_ = iis_lp.row_lower_.size();
444+
// The IIS LP matrix will have the same format as the incumbent LP
445+
iis_lp.a_matrix_.format_ = lp.a_matrix_.format_;
437446
iis_lp.a_matrix_.num_col_ = iis_lp.num_col_;
438447
iis_lp.a_matrix_.num_row_ = iis_lp.num_row_;
439448
iis_lp.model_name_ = lp.model_name_ + "_IIS";

highs/lp_data/HighsInterface.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,8 @@ HighsStatus Highs::getIisInterface() {
19861986
this->iis_.col_status_.assign(lp.num_col_, kIisStatusNotInConflict);
19871987
this->iis_.row_status_.assign(lp.num_row_, kIisStatusNotInConflict);
19881988
} else {
1989+
// To get the IIS data needs the matrix to be column-wise
1990+
model_.lp_.a_matrix_.ensureColwise();
19891991
return_status =
19901992
this->iis_.getData(lp, options_, basis_, infeasible_row_subset);
19911993
if (return_status == HighsStatus::kOk) {

0 commit comments

Comments
 (0)