| 591 | } |
| 592 | |
| 593 | void runWriteReadCheckSolution(Highs& highs, const std::string& test_name, |
| 594 | const std::string& model, |
| 595 | const HighsModelStatus require_model_status, |
| 596 | const HighsInt write_solution_style) { |
| 597 | HighsStatus run_status; |
| 598 | HighsStatus return_status; |
| 599 | std::string solution_file; |
| 600 | HighsModelStatus status = HighsModelStatus::kNotset; |
| 601 | if (dev_run) printf("\nSolving model %s from scratch\n", model.c_str()); |
| 602 | run_status = highs.run(); |
| 603 | REQUIRE(run_status == HighsStatus::kOk); |
| 604 | |
| 605 | status = highs.getModelStatus(); |
| 606 | REQUIRE(status == require_model_status); |
| 607 | |
| 608 | solution_file = test_name + model + ".sol"; |
| 609 | if (dev_run) |
| 610 | printf("Writing solution in style %d to %s\n", int(write_solution_style), |
| 611 | solution_file.c_str()); |
| 612 | // For models without names, Highs::writeSolution will return |
| 613 | // HighsStatus::kWarning |
| 614 | HighsStatus require_status = highs.getLp().col_names_.size() |
| 615 | ? HighsStatus::kOk |
| 616 | : HighsStatus::kWarning; |
| 617 | REQUIRE(highs.writeSolution(solution_file, write_solution_style) == |
| 618 | require_status); |
| 619 | if (dev_run) |
| 620 | REQUIRE(highs.writeSolution("", write_solution_style) == HighsStatus::kOk); |
| 621 | |
| 622 | const bool& value_valid = highs.getSolution().value_valid; |
| 623 | bool valid, integral, feasible; |
| 624 | |
| 625 | // primalDualInfeasible1Lp has no values in the solution file so, |
| 626 | // after it's read, HiGHS::solution.value_valid is false |
| 627 | if (dev_run) printf("Reading solution from %s\n", solution_file.c_str()); |
| 628 | return_status = highs.readSolution(solution_file); |
| 629 | if (value_valid) { |
| 630 | REQUIRE(return_status == HighsStatus::kOk); |
| 631 | } else { |
| 632 | REQUIRE(return_status == HighsStatus::kWarning); |
| 633 | } |
| 634 | |
| 635 | return_status = highs.assessPrimalSolution(valid, integral, feasible); |
| 636 | if (value_valid) { |
| 637 | REQUIRE(return_status == HighsStatus::kOk); |
| 638 | } else { |
| 639 | REQUIRE(return_status == HighsStatus::kError); |
| 640 | } |
| 641 | if (dev_run) printf("Solving model from solution read from file\n"); |
| 642 | run_status = highs.run(); |
| 643 | REQUIRE(run_status == HighsStatus::kOk); |
| 644 | |
| 645 | status = highs.getModelStatus(); |
| 646 | REQUIRE(status == require_model_status); |
| 647 | |
| 648 | std::remove(solution_file.c_str()); |
| 649 | |
| 650 | highs.resetGlobalScheduler(true); |
no test coverage detected