Skip to content

Commit

Permalink
printf and other logging conditionally silenced by kIisDevReport
Browse files Browse the repository at this point in the history
  • Loading branch information
jajhall committed Jun 14, 2024
1 parent b20db8d commit d68df22
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 49 deletions.
7 changes: 4 additions & 3 deletions check/TestIis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "catch.hpp"
//#include "io/FilereaderLp.h"

const bool dev_run = true;
const bool dev_run = false;
const double inf = kHighsInf;

void testIis(const std::string& model, const HighsIis& iis);
Expand Down Expand Up @@ -248,8 +248,9 @@ void testIis(const std::string& model, const HighsIis& iis) {
} else if (iis_bound == kIisBoundStatusUpper) {
to_upper = inf;
} else if (iis_bound == kIisBoundStatusFree) {
printf("IIS Col %2d (LP col %6d) status %s\n", int(iisCol), int(iCol),
iis.iisBoundStatusToString(iis_bound).c_str());
if (dev_run)
printf("IIS Col %2d (LP col %6d) status %s\n", int(iisCol), int(iCol),
iis.iisBoundStatusToString(iis_bound).c_str());
continue;
}
REQUIRE(highs.changeColBounds(iCol, to_lower, to_upper) ==
Expand Down
13 changes: 8 additions & 5 deletions src/lp_data/HighsIis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ HighsStatus HighsIis::getData(const HighsLp& lp, const HighsOptions& options,
this->col_index_[iCol] = from_col[this->col_index_[iCol]];
for (HighsInt iRow = 0; iRow < HighsInt(this->row_index_.size()); iRow++)
this->row_index_[iRow] = from_row[this->row_index_[iRow]];
this->report("On exit", lp);
if (kIisDevReport) this->report("On exit", lp);
return HighsStatus::kOk;
}

Expand All @@ -225,7 +225,7 @@ HighsStatus HighsIis::compute(const HighsLp& lp, const HighsOptions& options,
for (HighsInt iCol = 0; iCol < lp.num_col_; iCol++) this->addCol(iCol);
for (HighsInt iRow = 0; iRow < lp.num_row_; iRow++) this->addRow(iRow);
Highs highs;
// highs.setOptionValue("output_flag", false);
highs.setOptionValue("output_flag", kIisDevReport);
highs.setOptionValue("presolve", kHighsOffString);
const HighsLp& incumbent_lp = highs.getLp();
HighsStatus run_status = highs.passModel(lp);
Expand All @@ -246,12 +246,15 @@ HighsStatus HighsIis::compute(const HighsLp& lp, const HighsOptions& options,

const bool use_sensitivity_filter = false;
if (use_sensitivity_filter) {
bool output_flag;
highs.getOptionValue("output_flag", output_flag);
highs.setOptionValue("simplex_strategy", kSimplexStrategyPrimal);
//
highs.setOptionValue("output_flag", true);
// Solve the LP
run_status = highs.run();
highs.writeSolution("", kSolutionStylePretty);
highs.setOptionValue("output_flag", output_flag);
}

// Pass twice: rows before columns, or columns before rows, according to
Expand Down Expand Up @@ -384,7 +387,7 @@ HighsStatus HighsIis::compute(const HighsLp& lp, const HighsOptions& options,
}
if (k == 1) continue;
// End of first pass: look to simplify second pass
this->report("End of deletion", incumbent_lp);
if (kIisDevReport) this->report("End of deletion", incumbent_lp);
if (row_deletion) {
// Mark empty columns as dropped
for (HighsInt iCol = 0; iCol < lp.num_col_; iCol++) {
Expand All @@ -406,9 +409,9 @@ HighsStatus HighsIis::compute(const HighsLp& lp, const HighsOptions& options,
}
}
}
this->report("End of pass 1", incumbent_lp);
if (kIisDevReport) this->report("End of pass 1", incumbent_lp);
}
this->report("End of pass 2", incumbent_lp);
if (kIisDevReport) this->report("End of pass 2", incumbent_lp);
HighsInt iss_num_col = 0;
for (HighsInt iCol = 0; iCol < lp.num_col_; iCol++) {
if (this->col_bound_[iCol] != kIisBoundStatusDropped) {
Expand Down
2 changes: 2 additions & 0 deletions src/lp_data/HighsIis.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "lp_data/HighsLp.h"

const bool kIisDevReport = false;

enum IisBoundStatus {
kIisBoundStatusDropped = -1,
kIisBoundStatusNull, // 0
Expand Down
88 changes: 47 additions & 41 deletions src/lp_data/HighsInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ HighsStatus Highs::computeInfeasibleRows(
const HighsLp& lp = this->model_.lp_;
HighsInt evar_ix = lp.num_col_;
HighsStatus run_status;
const bool write_model = true;
const bool write_model = false;
HighsInt col_ecol_offset;
const HighsInt original_num_col = lp.num_col_;
const HighsInt original_num_row = lp.num_row_;
Expand All @@ -1691,8 +1691,6 @@ HighsStatus Highs::computeInfeasibleRows(
run_status = this->changeColsCost(0, lp.num_col_ - 1, zero_costs.data());
assert(run_status == HighsStatus::kOk);

printf("Highs::computeInfeasibleRows: After entry - model status is %s\n",
this->modelStatusToString(this->model_status_).c_str());
if (elastic_columns) {
// When defining names, need to know the column number
HighsInt previous_num_col = lp.num_col_;
Expand Down Expand Up @@ -1743,11 +1741,11 @@ HighsStatus Highs::computeInfeasibleRows(
HighsInt num_new_col = col_of_ecol.size();
HighsInt num_new_row = erow_start.size() - 1;
HighsInt num_new_nz = erow_start[num_new_row];
printf(
"Elasticity filter: For columns there are %d variables and %d "
"constraints\n",
int(num_new_col), int(num_new_row));
const bool write_model = true;
if (kIisDevReport)
printf(
"Elasticity filter: For columns there are %d variables and %d"
"constraints\n",
int(num_new_col), int(num_new_row));
// Free the original columns
std::vector<double> col_lower;
std::vector<double> col_upper;
Expand Down Expand Up @@ -1847,27 +1845,30 @@ HighsStatus Highs::computeInfeasibleRows(
}
run_status = this->run();
assert(run_status == HighsStatus::kOk);
this->writeSolution("", kSolutionStylePretty);
if (kIisDevReport) this->writeSolution("", kSolutionStylePretty);
HighsModelStatus model_status = this->getModelStatus();
assert(model_status == HighsModelStatus::kOptimal);

const HighsSolution& solution = this->getSolution();
// Now fix e-variables that are positive and re-solve until e-LP is infeasible
HighsInt loop_k = 0;
for (;;) {
printf("\nElasticity filter pass %d\n==============\n", int(loop_k));
if (kIisDevReport)
printf("\nElasticity filter pass %d\n==============\n", int(loop_k));
HighsInt num_fixed = 0;
if (elastic_columns) {
for (HighsInt eCol = 0; eCol < col_of_ecol.size(); eCol++) {
HighsInt iCol = col_of_ecol[eCol];
if (solution.col_value[col_ecol_offset + eCol] >
this->options_.primal_feasibility_tolerance) {
printf(
"E-col %2d (column %2d) corresponds to column %2d with bound %g "
"and has solution value %g\n",
int(eCol), int(col_ecol_offset + eCol), int(iCol),
bound_of_col_of_ecol[eCol],
solution.col_value[col_ecol_offset + eCol]);
if (kIisDevReport)
printf(
"E-col %2d (column %2d) corresponds to column %2d with bound "
"%g "
"and has solution value %g\n",
int(eCol), int(col_ecol_offset + eCol), int(iCol),
bound_of_col_of_ecol[eCol],
solution.col_value[col_ecol_offset + eCol]);
this->changeColBounds(col_ecol_offset + eCol, 0, 0);
num_fixed++;
}
Expand All @@ -1877,20 +1878,21 @@ HighsStatus Highs::computeInfeasibleRows(
HighsInt iRow = row_of_ecol[eCol];
if (solution.col_value[row_ecol_offset + eCol] >
this->options_.primal_feasibility_tolerance) {
printf(
"E-row %2d (column %2d) corresponds to row %2d with bound %g "
"and has solution value %g\n",
int(eCol), int(row_ecol_offset + eCol), int(iRow),
bound_of_row_of_ecol[eCol],
solution.col_value[row_ecol_offset + eCol]);
if (kIisDevReport)
printf(
"E-row %2d (column %2d) corresponds to row %2d with bound %g "
"and has solution value %g\n",
int(eCol), int(row_ecol_offset + eCol), int(iRow),
bound_of_row_of_ecol[eCol],
solution.col_value[row_ecol_offset + eCol]);
this->changeColBounds(row_ecol_offset + eCol, 0, 0);
num_fixed++;
}
}
assert(num_fixed > 0);
run_status = this->run();
assert(run_status == HighsStatus::kOk);
this->writeSolution("", kSolutionStylePretty);
if (kIisDevReport) this->writeSolution("", kSolutionStylePretty);
HighsModelStatus model_status = this->getModelStatus();
if (model_status == HighsModelStatus::kInfeasible) break;
loop_k++;
Expand All @@ -1915,23 +1917,26 @@ HighsStatus Highs::computeInfeasibleRows(
HighsInt iRow = row_of_ecol[eCol];
if (lp.col_upper_[row_ecol_offset + eCol] == 0) {
num_enforced_row_ecol++;
printf(
"Row e-col %2d (column %2d) corresponds to row %2d with bound %g "
"and is enforced\n",
int(eCol), int(row_ecol_offset + eCol), int(iRow),
bound_of_row_of_ecol[eCol]);
if (kIisDevReport)
printf(
"Row e-col %2d (column %2d) corresponds to row %2d with bound "
"%g "
"and is enforced\n",
int(eCol), int(row_ecol_offset + eCol), int(iRow),
bound_of_row_of_ecol[eCol]);
infeasible_row_subset.push_back(iRow);
}
}
printf(
"\nElasticity filter after %d passes enforces bounds on %d cols and %d "
"rows\n",
int(loop_k), int(num_enforced_col_ecol), int(num_enforced_row_ecol));

printf(
"Highs::computeInfeasibleRows: Before clearing additional rows and "
"columns - model status is %s\n",
this->modelStatusToString(this->model_status_).c_str());
if (kIisDevReport) {
printf(
"\nElasticity filter after %d passes enforces bounds on %d cols and %d "
"rows\n",
int(loop_k), int(num_enforced_col_ecol), int(num_enforced_row_ecol));
printf(
"Highs::computeInfeasibleRows: Before clearing additional rows and "
"columns - model status is %s\n",
this->modelStatusToString(this->model_status_).c_str());
}
// Delete any additional rows and columns, and restore the original
// column costs and bounds
run_status = this->deleteRows(original_num_row, lp.num_row_ - 1);
Expand All @@ -1952,10 +1957,11 @@ HighsStatus Highs::computeInfeasibleRows(
assert(lp.num_col_ == original_num_col);
assert(lp.num_row_ == original_num_row);

printf(
"Highs::computeInfeasibleRows: After clearing additional rows and "
"columns - model status is %s\n",
this->modelStatusToString(this->model_status_).c_str());
if (kIisDevReport)
printf(
"Highs::computeInfeasibleRows: After clearing additional rows and "
"columns - model status is %s\n",
this->modelStatusToString(this->model_status_).c_str());
return HighsStatus::kOk;
}

Expand Down

0 comments on commit d68df22

Please sign in to comment.