Don't compute axle weights from a degenerate truck geometry - #543
Open
HansBug wants to merge 1 commit into
Open
Conversation
compute_axle_weights divides by harness_rear_axle_distance and by front_axle_middle_axle_distance. A bin file that gives axle weight limits but no truck geometry leaves both at 0, and boxstacks' read_bin_types flags every bin read from a CSV file as a semi-trailer truck, so the divisions produced an infinite rear axle weight and a NaN middle axle weight. The infinite weight exceeds any finite REAR_AXLE_MAXIMUM_WEIGHT, so Solution::feasible_axle_weights rejected every candidate and the solver returned an empty solution with exit code 0. Skip the axle weights that the geometry cannot produce instead: without harness_rear_axle_distance neither weight can be computed, and without front_axle_middle_axle_distance only the middle axle weight is lost while the rear axle stays constrained. A bin type that provides both distances is unaffected, and a bin type that provides only one of them keeps the constraint that is still computable. Added unit tests for the complete geometry and for both degenerate cases.
HansBug
added a commit
to HansBug/packingsolver
that referenced
this pull request
Aug 31, 2026
Upstream PR fontanf#543, issue fontanf#539.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #539
Summary
compute_axle_weightsdivides byharness_rear_axle_distanceand byfront_axle_middle_axle_distance. A bin file that gives axle weight limits but no truck geometry leaves both at 0, andboxstacks::InstanceBuilder::read_bin_typesflags every bin read from a CSV file as a semi-trailer truck, so the divisions produced an infinite rear axle weight and a NaN middle axle weight. The infinite weight exceeds any finiteREAR_AXLE_MAXIMUM_WEIGHT, soSolution::feasible_axle_weightsrejected every candidate and the solver returned an empty solution with exit code 0 and no message.Changes
include/packingsolver/algorithms/truck.hpp— two guards incompute_axle_weights. Withoutharness_rear_axle_distanceneither weight can be computed, since both are derived fromharness_weight, so the function returns{0, 0}. Withoutfront_axle_middle_axle_distanceonly the middle axle weight is lost, so the rear axle stays constrained. The original expression and its variable-name comments are kept as they are.test/algorithms/truck_test.cpp(new) — three unit tests: the complete geometry, and each of the two degenerate cases. The first passes both before and after this change, which is what shows the change is inert for a well-formed truck.I deliberately left two nearby things alone.
compute_axle_weightsalso divides byweight, which is 0 for an empty bin; that already yields NaN and no violation today. Andread_bin_typesstill flags every bin from a CSV file as a semi-trailer truck, which is why the degenerate state is reachable from an ordinary bin file at all; changing that is a policy decision about existing bin files, so it is yours to make rather than mine.Test plan
masterand pass with this change;Truck.ComputeAxleWeightspasses both ways.-DCMAKE_BUILD_TYPE=Release, CLP and HiGHS both on,liblapack-devandlibbz2-devinstalled, as in.github/workflows/build.yml).ctest --parallel 8inbuild/test: 599 tests pass, which is the 596 onmasterplus the three added here.IS_SEMI_TRAILER_TRUCK=1, a full geometry andFRONT_AXLE_MIDDLE_AXLE_DISTANCE=0still has its rear axle limit enforced,REAR_AXLE_MAXIMUM_WEIGHT=4600giving one bin and4400splitting the load into two, both before and after the change.sequential_onedimensional_rectangle(std::bad_array_new_length) #537: it behaves identically on this branch and onmaster.Environment: Ubuntu 24.04.3 LTS, x86-64, glibc 2.39, GCC 13.3.0, CMake 4.4.3.