box, boxstacks: handle VariableSizedBinPacking in Solution::operator< - #540
box, boxstacks: handle VariableSizedBinPacking in Solution::operator<#540HansBug wants to merge 2 commits into
Conversation
The objective is advertised for both solvers and is handled all along their optimization pipelines, but neither comparator had a case for it, so every comparison of two feasible solutions fell through to the default branch and threw, making the objective unusable. Added the missing case to both comparators, using the same cost comparison rectangle::Solution and onedimensional::Solution already use. Both places have to be handled: boxstacks solves an internal box subproblem first, so the unpatched boxstacks binary reports box::Solution, and fixing only box moves the failure one level up to boxstacks::Solution. Added a solution comparison test for the objective to both problem types. The existing boxstacks test does set the objective, but it only builds one solution and asserts bin counts, so it never reaches operator<.
Upstream PR fontanf#540, issue fontanf#536.
|
Hi, Thank you for the contribution. For the tests, could you create instance files in |
Replaced the two hand-written solution comparison tests with parametrized tests over instance files, following the other parametrized tests of the project. test/box/box_test.cpp: revived the commented-out BoxOptimizeTest. It now reads the reference certificate through SolutionBuilder::read, since the Solution(instance, path) constructor it used no longer exists, and drops the unused defects_path field, matching tree_search_test.cpp. It is instantiated with a variable-sized bin packing instance whose reference solution is proven optimal, its cost of 10 being equal to the bound. test/boxstacks/optimize_test.cpp: new parametrized suite over the same instance. boxstacks has no SolutionBuilder::read, so the returned solution is checked against its expected cost instead of against a reference certificate.
|
Done, pushed as a second commit.
For box I revived the For boxstacks the suite is new, in Both tests fail on master and pass with the fix. Full build in the default configuration, |
Fixes #536
Summary
Objective::VariableSizedBinPackingis advertised for both theboxand theboxstackssolver and is handled all along their optimization pipelines, but neitherSolution::operator<had a case for it, so every comparison of two feasible solutions fell through to thedefaultbranch and threwstd::logic_error. The objective was unusable in both solvers.rectangle::Solution::operator<andonedimensional::Solution::operator<already use, in the same position in the switch (right afterObjective::Feasibility).Changes
src/box/solution.cpp,src/boxstacks/solution.cpp— two lines each:Both places are needed.
boxstacksfirst computes aboxrelaxation bound (optimize_box_bound,src/boxstacks/optimize.cpp:158), which runs the fullbox::optimize, so the unpatchedboxstacksbinary reportsbox::Solutionin its error message; with onlysrc/box/solution.cppfixed, the failure moves one level up toboxstacks::Solution::operator<.test/box/box_test.cpp,test/boxstacks/boxstacks_test.cpp— one solution comparison test each, built from theInstanceBuilderandSolutionBuilderAPIs so they need no LP solver, no data file and no optimize run. Each test builds two feasible, full solutions of the same instance, one using two bins of cost 7 and one using a single bin of cost 10, and checks that the cheaper one compares as the better solution in both directions.test/box/box_test.cppcurrently has all of its content commented out, so the test comes with the includes it needs, placed at the top of the file with the test itself after the commented-out block, which is left untouched.Test plan
master(std::logic_errorfrom thedefaultbranch) and pass with this change.-DCMAKE_BUILD_TYPE=Release, CLP and HiGHS both on,liblapack-devandlibbz2-devinstalled, as in.github/workflows/build.yml).ctest --output-on-failure --parallel 8inbuild/test: 598 tests pass, which is the 596 onmasterplus the two added here.variable-sized-bin-packingthrows inSolution::operator<as soon as two bin types remain #536 now returns one bin of type 1 with a cost of 10 and 2/2 items packed, for bothpackingsolver_boxandpackingsolver_boxstacks, over 5 runs each.Environment: Ubuntu 24.04.3 LTS, x86-64, glibc 2.39, GCC 13.3.0, CMake 4.4.3.