Skip to content

Commit 0dde780

Browse files
committed
Now demanding integer knapsack weights, but rounding down any fractional capacity
1 parent 1b5ef6a commit 0dde780

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

check/TestMipSolver.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,25 +1003,30 @@ TEST_CASE("issue-2432", "[highs_test_mip_solver]") {
10031003
}
10041004

10051005
TEST_CASE("knapsack", "[highs_test_mip_solver]") {
1006-
HighsLp lp;
1007-
lp.sense_ = ObjSense::kMaximize;
1008-
lp.num_col_ = 6;
1009-
lp.num_row_ = 1;
1010-
lp.col_cost_ = {10, 20, 25, 40, 60, 70};
1011-
lp.col_lower_.assign(lp.num_col_, 0);
1012-
lp.col_upper_.assign(lp.num_col_, 1);
1013-
lp.integrality_.assign(lp.num_col_, HighsVarType::kInteger);
1014-
lp.row_lower_ = {-kHighsInf};
1015-
lp.row_upper_ = {7};
1016-
lp.a_matrix_.format_ = MatrixFormat::kRowwise;
1017-
lp.a_matrix_.start_ = {0, 6};
1018-
lp.a_matrix_.index_ = {0, 1, 2, 3, 4, 5};
1019-
lp.a_matrix_.value_ = {1, 2, 3, 6, 7, 4};
1020-
Highs h;
1021-
h.setOptionValue("presolve", kHighsOffString);
1022-
h.setOptionValue("threads", 1);
1023-
REQUIRE(h.passModel(lp) == HighsStatus::kOk);
1024-
REQUIRE(h.run() == HighsStatus::kOk);
1006+
std::vector<double> cost = {10, 20, 25, 40, 60, 70};
1007+
std::vector<double> weight = {1, 2, 3, 6, 7, 4};
1008+
HighsInt num_item = cost.size();
1009+
REQUIRE(num_item == weight.size());
1010+
1011+
HighsLp lp;
1012+
lp.sense_ = ObjSense::kMaximize;
1013+
lp.num_col_ = 6;
1014+
lp.num_row_ = 1;
1015+
lp.col_cost_ = cost;
1016+
lp.col_lower_.assign(lp.num_col_, 0);
1017+
lp.col_upper_.assign(lp.num_col_, 1);
1018+
lp.integrality_.assign(lp.num_col_, HighsVarType::kInteger);
1019+
lp.row_lower_ = {-kHighsInf};
1020+
lp.row_upper_ = {7};
1021+
lp.a_matrix_.format_ = MatrixFormat::kRowwise;
1022+
lp.a_matrix_.start_ = {0, 6};
1023+
lp.a_matrix_.index_ = {0, 1, 2, 3, 4, 5};
1024+
lp.a_matrix_.value_ = weight;
1025+
Highs h;
1026+
h.setOptionValue("presolve", kHighsOffString);
1027+
h.setOptionValue("threads", 1);
1028+
REQUIRE(h.passModel(lp) == HighsStatus::kOk);
1029+
REQUIRE(h.run() == HighsStatus::kOk);
10251030
}
10261031

10271032

0 commit comments

Comments
 (0)