Skip to content

Don't compute axle weights from a degenerate truck geometry - #543

Open
HansBug wants to merge 1 commit into
fontanf:masterfrom
HansBug:fix/truck-degenerate-geometry
Open

Don't compute axle weights from a degenerate truck geometry#543
HansBug wants to merge 1 commit into
fontanf:masterfrom
HansBug:fix/truck-degenerate-geometry

Conversation

@HansBug

@HansBug HansBug commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #539

Summary

  • 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::InstanceBuilder::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 and no message.
  • Skip the axle weights the geometry cannot produce instead of computing them from a zero divisor.

Changes

include/packingsolver/algorithms/truck.hpp — two guards in compute_axle_weights. Without harness_rear_axle_distance neither weight can be computed, since both are derived from harness_weight, so the function returns {0, 0}. Without front_axle_middle_axle_distance only 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_weights also divides by weight, which is 0 for an empty bin; that already yields NaN and no violation today. And read_bin_types still 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

Environment: Ubuntu 24.04.3 LTS, x86-64, glibc 2.39, GCC 13.3.0, CMake 4.4.3.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[boxstacks] A bin file with axle weight limits but no truck geometry silently returns an empty solution

1 participant