Skip to content

Commit 75489fd

Browse files
author
Julian Hall
committed
Removed unnecessary tests in TestPresolveRules.cpp
1 parent d87987c commit 75489fd

1 file changed

Lines changed: 71 additions & 37 deletions

File tree

check/TestPresolveRules.cpp

Lines changed: 71 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,10 @@
66

77
const bool dev_run = true;
88

9-
void presolveOffOn(const std::string& message, const HighsLp& lp, Highs& h) {
10-
const HighsRunData& run_data = h.getRunData();
11-
bool presolve_on = false;
12-
for (int k = 0; k < 4; k++) {
13-
std::string solver = kSimplexString;
14-
if (k == 0) {
15-
// Presolve off - to get the optimal solution to debug
16-
// presolve
17-
presolve_on = false;
18-
} else {
19-
presolve_on = true;
20-
if (k == 1) {
21-
solver = kSimplexString;
22-
} else if (k == 2) {
23-
solver = kHipoString;
24-
} else {
25-
solver = kHiPdlpString;
26-
}
27-
}
28-
std::string presolve = presolve_on ? kHighsOnString : kHighsOffString;
29-
h.setOptionValue(kPresolveString, presolve);
30-
h.setOptionValue(kSolverString, solver);
31-
if (dev_run)
32-
printf("\n============\n%s: presolve = %s; solver = %s\n============\n\n",
33-
message.c_str(), presolve.c_str(), solver.c_str());
34-
REQUIRE(h.passModel(lp) == HighsStatus::kOk);
35-
h.run();
36-
if (dev_run) h.writeSolution("", 1);
37-
if (presolve_on) {
38-
REQUIRE(h.getInfo().simplex_iteration_count == 0);
39-
REQUIRE(run_data.presolved_model_num_col == 0);
40-
REQUIRE(run_data.presolved_model_num_row == 0);
41-
REQUIRE(run_data.presolved_model_num_nz == 0);
42-
REQUIRE(run_data.num_simplex_iterations_after_postsolve == 0);
43-
}
44-
}
45-
}
9+
void presolveOffOn(const std::string& message, const HighsLp& lp, Highs& h,
10+
const HighsInt require_presolved_model_num_col = 0,
11+
const HighsInt require_presolved_model_num_row = 0,
12+
const HighsInt require_presolved_model_num_nz = 0);
4613

4714
TEST_CASE("test-col-stuffing", "[highs_test_presolve_rules]") {
4815
HighsLp lp;
@@ -111,3 +78,70 @@ TEST_CASE("test-col-stuffing", "[highs_test_presolve_rules]") {
11178

11279
h.resetGlobalScheduler(true);
11380
}
81+
82+
void presolveOffOn(const std::string& message, const HighsLp& lp, Highs& h,
83+
const HighsInt require_presolved_model_num_col,
84+
const HighsInt require_presolved_model_num_row,
85+
const HighsInt require_presolved_model_num_nz) {
86+
const HighsRunData& run_data = h.getRunData();
87+
bool presolve_on = false;
88+
// If the model reduces to empty, then the output from different
89+
// solvers cannot be tested
90+
const bool reduce_to_empty = require_presolved_model_num_col == 0 &&
91+
require_presolved_model_num_row == 0;
92+
const HighsInt to_k = reduce_to_empty ? 2 : 5;
93+
for (int k = 0; k < to_k; k++) {
94+
std::string solver = kSimplexString;
95+
std::string run_crossover = kHighsOnString;
96+
bool basis_postsolve = true;
97+
if (k == 0) {
98+
// Presolve off - to get the optimal solution to debug
99+
// presolve
100+
presolve_on = false;
101+
} else {
102+
presolve_on = true;
103+
if (k == 1) {
104+
solver = kSimplexString;
105+
} else if (k == 2) {
106+
solver = kIpmString;
107+
} else if (k == 3) {
108+
solver = kIpmString;
109+
run_crossover = kHighsOffString;
110+
basis_postsolve = false;
111+
} else {
112+
solver = kHiPdlpString;
113+
basis_postsolve = false;
114+
}
115+
}
116+
std::string presolve = presolve_on ? kHighsOnString : kHighsOffString;
117+
h.setOptionValue(kPresolveString, presolve);
118+
h.setOptionValue(kRunCrossoverString, run_crossover);
119+
h.setOptionValue(kSolverString, solver);
120+
if (dev_run)
121+
printf(
122+
"\n============\n%s: presolve = %s; solver = %s%s\n============\n\n",
123+
message.c_str(), presolve.c_str(), solver.c_str(),
124+
solver == kIpmString ? ("; run_crossover = " + run_crossover).c_str()
125+
: "");
126+
REQUIRE(h.passModel(lp) == HighsStatus::kOk);
127+
h.run();
128+
if (dev_run) h.writeSolution("", 1);
129+
if (presolve_on) {
130+
// Ensure that the model is reduced to empty
131+
REQUIRE(run_data.presolved_model_num_col ==
132+
require_presolved_model_num_col);
133+
REQUIRE(run_data.presolved_model_num_row ==
134+
require_presolved_model_num_row);
135+
REQUIRE(run_data.presolved_model_num_nz ==
136+
require_presolved_model_num_nz);
137+
// Ensure that dual postsolve is correct
138+
REQUIRE(h.getModelStatus() == HighsModelStatus::kOptimal);
139+
REQUIRE(h.getInfo().num_primal_infeasibilities == 0);
140+
REQUIRE(h.getInfo().num_dual_infeasibilities == 0);
141+
REQUIRE(h.getInfo().simplex_iteration_count == 0);
142+
// Ensure that any basis postsolve is correct
143+
if (basis_postsolve)
144+
REQUIRE(run_data.num_simplex_iterations_after_postsolve == 0);
145+
}
146+
}
147+
}

0 commit comments

Comments
 (0)