Skip to content

Commit ebd83e1

Browse files
committed
Verified correctness of reading MIPLIB solution files; added unit test miplib-sol-file
1 parent cf327f2 commit ebd83e1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

check/TestCheckSolution.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,3 +699,42 @@ void runSetLpSolution(const std::string model) {
699699

700700
highs.resetGlobalScheduler(true);
701701
}
702+
703+
TEST_CASE("miplib-sol-file", "[highs_filereader]") {
704+
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
705+
std::string sol_file = test_name + ".sol";
706+
std::string lp_file = test_name + ".lp";
707+
FILE* file = fopen(lp_file.c_str(), "w");
708+
std::string file_content =
709+
"Minimize\n obj: 2 sel_2 + sel_3\nSubject To\nr0: sel_0 - sel_1 + sel_4 "
710+
">= "
711+
"2\nEnd\n";
712+
if (dev_run) printf("Using .lp file\n%s", file_content.c_str());
713+
fprintf(file, "%s", file_content.c_str());
714+
fclose(file);
715+
Highs h;
716+
h.setOptionValue("output_flag", dev_run);
717+
REQUIRE(h.readModel(lp_file) == HighsStatus::kOk);
718+
719+
file = fopen(sol_file.c_str(), "w");
720+
file_content =
721+
"=obj= 203672547.1\nsel_0 1\nsel_1 0\nsel_2 0\nsel_3 0\nsel_4 1\n";
722+
if (dev_run) printf("Using .sol file\n%s", file_content.c_str());
723+
fprintf(file, "%s", file_content.c_str());
724+
fclose(file);
725+
REQUIRE(h.readSolution(sol_file) == HighsStatus::kOk);
726+
727+
std::vector<double> solution = h.getSolution().col_value;
728+
REQUIRE(solution[0] == 0);
729+
REQUIRE(solution[1] == 0);
730+
REQUIRE(solution[2] == 1);
731+
REQUIRE(solution[3] == 0);
732+
REQUIRE(solution[4] == 1);
733+
734+
REQUIRE(h.run() == HighsStatus::kOk);
735+
736+
std::remove(lp_file.c_str());
737+
std::remove(sol_file.c_str());
738+
739+
h.resetGlobalScheduler(true);
740+
}

0 commit comments

Comments
 (0)