Skip to content

Conversation

@cyril23
Copy link

@cyril23 cyril23 commented Oct 7, 2025

Fixes:

Problem

FinalizeAllowedVehicles() uses abs(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:

const int64_t transit = transit_evaluator(node);
if (transit <= 0 || transit <= capacity) continue;

Changes

File: ortools/routing/routing.cc (after merge with main branch - file was moved from ortools/constraint_solver/routing.cc)

1. Pre-processing loop (lines 1414-1421 lines 1413-1420)

for (int callback_index : dimension->class_evaluators_) {
  // Only consider positive transits for capacity checks.
  // Negative transits are used for reload/load tracking and should not
  // trigger vehicle exclusions based on capacity.
  const int64_t transit = UnaryTransitCallbackOrNull(callback_index)(node);
  if (transit > 0) {
    max_node_transit = std::max(max_node_transit, transit);
  }
}

2. Main capacity check (lines 1444-1448 lines 1443-1447)

// Fix for issue #4133: Skip capacity check for negative transits.
// Negative transits are used for reload dimensions and load tracking,
// not actual cargo requirements.
const int64_t transit = transit_evaluator(node);
if (transit <= 0 || transit <= capacity) continue;

Testing

Built and tested with the reproduction script from the issue comment:

Before fix (v9.12.4544):

Dropped customer stops: 13
Tours found: 1

After fix:

Dropped customer stops: 0
Tours found: 4

✅ 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 main branch (v10.0), which includes a routing module reorganization where routing files were moved from ortools/constraint_solver/ to ortools/routing/. The fix has been successfully applied to the new file location.

@google-cla
Copy link

google-cla bot commented Oct 7, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Mizux Mizux assigned Mizux and furnon Oct 7, 2025
@Mizux Mizux added Bug Solver: Routing Uses the Routing library and the original CP solver labels Oct 7, 2025
@Mizux Mizux added this to the v10.0 milestone Oct 7, 2025
…ehicles with negative transits

The FinalizeAllowedVehicles() function was using abs() on transit values to check
against vehicle capacity, which incorrectly excluded vehicles when:
- CARGO_LOAD dimensions use negative constants for cumulative load tracking
- Reload dimensions use negative values at landfills/depots

This fix modifies the capacity check to only apply to positive transit values,
since negative transits are used for algorithmic purposes (reload semantics,
load tracking) rather than actual cargo capacity requirements.

Changes:
- Lines 1414-1421: Pre-processing loop now only considers positive transits
  for max_node_transit calculation
- Lines 1444-1448: Main capacity check now skips negative transits entirely

This resolves the regression introduced in commit 847cfc9 (Dec 1, 2023)
affecting OR-Tools versions 9.9.3963 through 9.14.6206.

Fixes: google#4133
Testing: test_ortools_version_standalone_codex.py (multi-class VRP with load tracking)
@cyril23 cyril23 force-pushed the fix-4133-finalize-allowed-vehicles branch from 5b0e58f to 256574a Compare October 13, 2025 07:27
@cyril23
Copy link
Author

cyril23 commented Oct 13, 2025

OK I've done the CLA and resolved the merge conflict. Ready for review.

@lperron
Copy link
Collaborator

lperron commented Oct 13, 2025

no, this correct is currently is correct.

cumul var needs to be 0 <= var <= max_value

if abs(transit) > max_value, the node can never be visited by that vehicle.

What the code does is change the variable ordering which leads to different solutions.

But the proposed fix is incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Solver: Routing Uses the Routing library and the original CP solver

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants