-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added check/TestMultiObjective.cpp and check/TestHighsCDouble.cpp
- Loading branch information
Showing
2 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#include "HCheckConfig.h" | ||
#include "catch.hpp" | ||
#include "util/HighsCDouble.h" | ||
#include "util/HighsRandom.h" | ||
|
||
void testCeil(HighsCDouble x) { | ||
double ceil_x; | ||
double double_x; | ||
ceil_x = double(ceil(x)); | ||
double_x = double(x); | ||
REQUIRE(ceil_x >= double_x); | ||
REQUIRE(ceil(x) >= x); | ||
} | ||
|
||
void testFloor(HighsCDouble x) { | ||
double floor_x; | ||
double double_x; | ||
floor_x = double(floor(x)); | ||
double_x = double(x); | ||
REQUIRE(floor_x <= double_x); | ||
REQUIRE(floor(x) <= x); | ||
} | ||
|
||
TEST_CASE("HighsCDouble-ceil", "[util]") { | ||
HighsCDouble x; | ||
x = -1e-34; | ||
testCeil(x); | ||
x = -1e-32; | ||
testCeil(x); | ||
x = -1e-30; | ||
testCeil(x); | ||
x = -1e-23; | ||
testCeil(x); | ||
x = -1e-12; | ||
testCeil(x); | ||
x = -1e-1; | ||
testCeil(x); | ||
x = -0.99; | ||
testCeil(x); | ||
|
||
x = 0.99; | ||
testCeil(x); | ||
x = 1e-1; | ||
testCeil(x); | ||
x = 1e-12; | ||
testCeil(x); | ||
// This and rest failed in #2041 | ||
x = 1e-23; | ||
testCeil(x); | ||
x = 1e-30; | ||
testCeil(x); | ||
x = 1e-32; | ||
testCeil(x); | ||
x = 1e-34; | ||
testCeil(x); | ||
|
||
HighsRandom rand; | ||
for (HighsInt k = 0; k < 1000; k++) { | ||
double man = rand.fraction(); | ||
HighsInt power = 2 - rand.integer(5); | ||
double exp = std::pow(10, power); | ||
x = man * exp; | ||
testCeil(x); | ||
} | ||
} | ||
|
||
TEST_CASE("HighsCDouble-floor", "[util]") { | ||
HighsCDouble x; | ||
|
||
x = 1e-34; | ||
testFloor(x); | ||
x = 1e-32; | ||
testFloor(x); | ||
x = 1e-30; | ||
testFloor(x); | ||
x = 1e-23; | ||
testFloor(x); | ||
x = 1e-12; | ||
testFloor(x); | ||
x = 1e-1; | ||
testFloor(x); | ||
x = 0.99; | ||
testFloor(x); | ||
|
||
x = -0.99; | ||
testFloor(x); | ||
x = -1e-1; | ||
testFloor(x); | ||
x = -1e-12; | ||
testFloor(x); | ||
// This and rest failed in #2041 | ||
x = -1e-23; | ||
testFloor(x); | ||
x = -1e-30; | ||
testFloor(x); | ||
x = -1e-32; | ||
testFloor(x); | ||
x = -1e-34; | ||
testFloor(x); | ||
|
||
HighsRandom rand; | ||
for (HighsInt k = 0; k < 1000; k++) { | ||
double man = rand.fraction(); | ||
HighsInt power = 2 - rand.integer(5); | ||
double exp = std::pow(10, power); | ||
x = man * exp; | ||
testFloor(x); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "Highs.h" | ||
#include "catch.hpp" | ||
|
||
const bool dev_run = true; | ||
|
||
TEST_CASE("multi-objective", "[util]") { | ||
HighsLp lp; | ||
lp.num_col_ = 2; | ||
lp.num_row_ = 3; | ||
lp.col_cost_ = {0, 0}; | ||
lp.col_lower_ = {0, 0}; | ||
lp.col_upper_ = {kHighsInf, kHighsInf}; | ||
lp.row_lower_ = {-kHighsInf, -kHighsInf, -kHighsInf}; | ||
lp.row_upper_ = {18, 8, 14}; | ||
lp.a_matrix_.start_ = {0, 3, 6}; | ||
lp.a_matrix_.index_ = {0, 1, 2, 0, 1, 2}; | ||
lp.a_matrix_.value_ = {3, 1, 1, 1, 1, 2}; | ||
Highs h; | ||
h.setOptionValue("output_flag", dev_run); | ||
h.passModel(lp); | ||
|
||
HighsLinearObjective linear_objective; | ||
std::vector<HighsLinearObjective> linear_objectives; | ||
|
||
// Begin with an illegal linear objective | ||
linear_objective.weight = -1; | ||
linear_objective.offset = -1; | ||
linear_objective.coefficients = {2, 1, 0}; | ||
linear_objective.abs_tolerance = 0.0; | ||
linear_objective.rel_tolerance = 1.0; | ||
linear_objective.priority = 0; | ||
REQUIRE(h.addLinearObjective(linear_objective) == HighsStatus::kError); | ||
|
||
// Now legalise the linear objective so LP has nonunique optimal | ||
// solutions on the line joining (2, 6) and (5, 3) | ||
linear_objective.coefficients = {1, 1}; | ||
REQUIRE(h.addLinearObjective(linear_objective) == HighsStatus::kOk); | ||
|
||
h.run(); | ||
h.writeSolution("", kSolutionStylePretty); | ||
REQUIRE(h.getInfo().objective_function_value == -7); | ||
// Save the linear objective for the next | ||
linear_objectives.push_back(linear_objective); | ||
|
||
// Add a second linear objective with a very small minimization | ||
// weight that should push the optimal solution to (2, 6) | ||
linear_objective.weight = 1e-4; | ||
linear_objective.offset = 0; | ||
linear_objective.coefficients = {-1, 0}; | ||
REQUIRE(h.addLinearObjective(linear_objective) == HighsStatus::kOk); | ||
|
||
h.run(); | ||
h.writeSolution("", kSolutionStylePretty); | ||
// REQUIRE(h.getSolution().col_value[0] == 2); | ||
// REQUIRE(h.getSolution().col_value[1] == 6); | ||
} |