Skip to content

Commit e3fa1ed

Browse files
committed
Cleaned up highsVarTypeToString methods and added get-presolved-mip unit test and code coverage of highsVarTypeToString
1 parent 64de6d0 commit e3fa1ed

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

check/TestMipSolver.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,42 @@ TEST_CASE("get-fixed-lp", "[highs_test_mip_solver]") {
12281228
h.resetGlobalScheduler(true);
12291229
}
12301230

1231+
TEST_CASE("get-presolved-mip", "[highs_test_mip_solver]") {
1232+
HighsLp lp;
1233+
lp.num_col_ = 3;
1234+
lp.num_row_ = 3;
1235+
lp.col_cost_ = {1, 1, 1};
1236+
lp.col_lower_ = {0, -kHighsInf, -kHighsInf};
1237+
lp.col_upper_ = {kHighsInf, kHighsInf, kHighsInf};
1238+
lp.integrality_ = {HighsVarType::kContinuous, HighsVarType::kInteger,
1239+
HighsVarType::kInteger};
1240+
lp.row_lower_ = {2, 6, 8};
1241+
lp.row_upper_ = {2, kHighsInf, kHighsInf};
1242+
lp.a_matrix_.format_ = MatrixFormat::kRowwise;
1243+
lp.a_matrix_.start_ = {0, 3, 6, 9};
1244+
lp.a_matrix_.index_ = {0, 1, 2, 0, 1, 2, 0, 1, 2};
1245+
lp.a_matrix_.value_ = {1, 1, 1, 1, -1, 2, 1, 3, -1};
1246+
Highs h;
1247+
h.setOptionValue("output_flag", dev_run);
1248+
// Code coverage of highsVarTypeToString for all cases
1249+
HighsLogOptions log_options = h.getOptions().log_options;
1250+
for (HighsInt iVarType = -1;
1251+
iVarType < HighsInt(HighsVarType::kImplicitInteger) + 2; iVarType++)
1252+
highsLogUser(log_options, HighsLogType::kInfo, "Variable type %2d is %s\n",
1253+
int(iVarType), highsVarTypeToString(iVarType).c_str());
1254+
h.passModel(lp);
1255+
h.presolve();
1256+
// Presolved MIP has an implied integer, so this tests passing such
1257+
HighsLp presolved_lp = h.getPresolvedModel().lp_;
1258+
h.run();
1259+
const double lp_objective_value = h.getObjectiveValue();
1260+
h.passModel(presolved_lp);
1261+
h.run();
1262+
const double presolved_lp_objective_value = h.getObjectiveValue();
1263+
REQUIRE(presolved_lp_objective_value == lp_objective_value);
1264+
h.resetGlobalScheduler(true);
1265+
}
1266+
12311267
TEST_CASE("get-fixed-lp-semi", "[highs_test_mip_solver]") {
12321268
HighsLp lp;
12331269
lp.num_col_ = 4;
@@ -1245,6 +1281,11 @@ TEST_CASE("get-fixed-lp-semi", "[highs_test_mip_solver]") {
12451281
Highs h;
12461282
h.setOptionValue("output_flag", dev_run);
12471283
h.setOptionValue("presolve", kHighsOffString);
1284+
// Code coverage of highsVarTypeToString for four main types
1285+
for (HighsInt iCol = 0; iCol < lp.num_col_; iCol++)
1286+
highsLogUser(h.getOptions().log_options, HighsLogType::kInfo,
1287+
"Column %d is of type %s\n", int(iCol),
1288+
highsVarTypeToString(lp.integrality_[iCol]).c_str());
12481289
h.passModel(lp);
12491290
h.run();
12501291
double mip_optimal_objective = h.getInfo().objective_function_value;
@@ -1256,6 +1297,7 @@ TEST_CASE("get-fixed-lp-semi", "[highs_test_mip_solver]") {
12561297
REQUIRE(h.run() == HighsStatus::kOk);
12571298

12581299
REQUIRE(h.getInfo().objective_function_value == mip_optimal_objective);
1300+
h.resetGlobalScheduler(true);
12591301
}
12601302

12611303
TEST_CASE("row-fixed-lp", "[highs_test_mip_solver]") {

highs/lp_data/HighsLpUtils.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,26 +3660,16 @@ void getSubVectorsTranspose(const HighsIndexCollection& index_collection,
36603660

36613661
std::string highsVarTypeToString(const HighsVarType type) {
36623662
switch (type) {
3663-
case HighsVarType::kContinuous: {
3663+
case HighsVarType::kContinuous:
36643664
return "continuous";
3665-
break;
3666-
}
3667-
case HighsVarType::kInteger: {
3665+
case HighsVarType::kInteger:
36683666
return "integer";
3669-
break;
3670-
}
3671-
case HighsVarType::kSemiContinuous: {
3667+
case HighsVarType::kSemiContinuous:
36723668
return "semi continuous";
3673-
break;
3674-
}
3675-
case HighsVarType::kSemiInteger: {
3669+
case HighsVarType::kSemiInteger:
36763670
return "semi integer";
3677-
break;
3678-
}
3679-
case HighsVarType::kImplicitInteger: {
3671+
case HighsVarType::kImplicitInteger:
36803672
return "implicit integer";
3681-
break;
3682-
}
36833673
default:
36843674
return "unknown";
36853675
}
@@ -3688,7 +3678,7 @@ std::string highsVarTypeToString(const HighsVarType type) {
36883678
std::string highsVarTypeToString(const HighsInt type) {
36893679
if (type < HighsInt(HighsVarType::kContinuous) ||
36903680
type > HighsInt(HighsVarType::kImplicitInteger))
3691-
return "Unknown";
3681+
return "unknown";
36923682
HighsVarType type_ = HighsVarType(uint8_t(type));
36933683
return highsVarTypeToString(type_);
36943684
}

0 commit comments

Comments
 (0)