Fix issue #4133: FinalizeAllowedVehicles incorrectly excludes vehicles with negative transits #4853
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:
Problem
FinalizeAllowedVehicles()usesabs(transit)when checking if a vehicle can serve a node, which incorrectly excludes vehicles when dimensions use negative transit values for algorithmic purposes (reload dimensions, load tracking).Detailed analysis: #4133 (comment)
Solution
Skip capacity checks for non-positive transits, since only positive transits represent actual cargo/capacity requirements:
Changes
File:
ortools/routing/routing.cc(after merge with main branch - file was moved fromortools/constraint_solver/routing.cc)1. Pre-processing loop (
lines 1414-1421lines 1413-1420)2. Main capacity check (
lines 1444-1448lines 1443-1447)Testing
Built and tested with the reproduction script from the issue comment:
Before fix (v9.12.4544):
After fix:
✅ All customer stops served, all vehicle classes utilized correctly
Backward compatibility: Only affects models using negative transits in unary dimensions. Standard capacity models are unaffected.
edit: Merge Note
This PR has been rebased on the current
mainbranch (v10.0), which includes a routing module reorganization where routing files were moved fromortools/constraint_solver/toortools/routing/. The fix has been successfully applied to the new file location.