Skip to content

Fix accidentally quadratic add_slacks_to_basis in crossover - #1268

Merged
rapids-bot[bot] merged 2 commits into
NVIDIA:release/26.06from
nguidotti:fix-time-violation
May 21, 2026
Merged

Fix accidentally quadratic add_slacks_to_basis in crossover#1268
rapids-bot[bot] merged 2 commits into
NVIDIA:release/26.06from
nguidotti:fix-time-violation

Conversation

@nguidotti

@nguidotti nguidotti commented May 21, 2026

Copy link
Copy Markdown
Contributor

When the problem is very large and the basis is extremely rank deficient, the crossover needs to add millions of slack variables to compensate.

This process can take a long time and may violate the time limit set by the user.

This PR fixes the accidentally quadratic add_slacks_to_basis in crossover that was causing the large amount of time.

Signed-off-by: Nicolas L. Guidotti <nguidotti@nvidia.com>
@nguidotti nguidotti added this to the 26.06 milestone May 21, 2026
@nguidotti
nguidotti requested a review from chris-maes May 21, 2026 14:24
@nguidotti nguidotti self-assigned this May 21, 2026
@nguidotti
nguidotti requested a review from a team as a code owner May 21, 2026 14:24
@nguidotti
nguidotti requested a review from Bubullzz May 21, 2026 14:24
@nguidotti nguidotti added bug Something isn't working non-breaking Introduces a non-breaking change mip labels May 21, 2026
@nguidotti
nguidotti changed the base branch from main to release/26.06 May 21, 2026 14:24
@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

add_slacks_to_basis now precomputes a row->singleton-slack-column map and uses it to mark BASIC slack variables for dependent rows. After calling it when rank < m, crossover verifies num_basic + rank == m and returns NUMERICAL_ISSUES if the basis is not full-rank.

Changes

Slack insertion and basis validation

Layer / File(s) Summary
Precompute singleton slack map and assign slacks
cpp/src/dual_simplex/crossover.cpp
add_slacks_to_basis builds a slack_map from singleton slack columns (nz==1) to their row and marks those slack columns BASIC for each dependent_row instead of scanning all candidate columns per row.
Validate full-rank initial basis in crossover
cpp/src/dual_simplex/crossover.cpp
After adding slacks when rank < m, crossover checks num_basic + rank == m; if false it logs an error and returns crossover_status_t::NUMERICAL_ISSUES.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately describes the main change: optimizing the accidentally quadratic add_slacks_to_basis function to be linear, which directly addresses the performance issue documented in the PR objectives.
Description check ✅ Passed The PR description accurately describes the changeset - it identifies a performance issue with quadratic complexity in add_slacks_to_basis and explains the fix to optimize the algorithm.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mlubin

mlubin commented May 21, 2026

Copy link
Copy Markdown
Contributor

How much time can this take for millions of variables? It seems like a simple loop to me unless I'm misreading the code.

@nguidotti

nguidotti commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

How much time can this take for millions of variables? It seems like a simple loop to me unless I'm misreading the code.

It is a $n^2$ loop at the worse case, right? For a time limit of 300s, this loop starts at 255s and do not finish for that time limit. The problem has 7432334 constraints, 5907688 variables

@chris-maes chris-maes added the P0 label May 21, 2026
@chris-maes

chris-maes commented May 21, 2026

Copy link
Copy Markdown
Contributor

@mlubin @nguidotti It's O ( n * | dependent rows | ). Let me fix it so that it is O(m + | dependent rows |) = O(m).

@copy-pr-bot

copy-pr-bot Bot commented May 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2672aefd-da6c-4e35-a248-05094ea273b0

📥 Commits

Reviewing files that changed from the base of the PR and between e35a029 and d59146c.

📒 Files selected for processing (1)
  • cpp/src/dual_simplex/crossover.cpp

Comment thread cpp/src/dual_simplex/crossover.cpp
@chris-maes chris-maes changed the title Add time limit when adding slack variables in crossover Fix accidentally quadratic add_slacks_to_basis in crossover May 21, 2026
@chris-maes

Copy link
Copy Markdown
Contributor

/ok to test d59146c

@chris-maes chris-maes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chris-maes
chris-maes removed the request for review from Bubullzz May 21, 2026 16:23
@chris-maes

Copy link
Copy Markdown
Contributor

/merge

@rapids-bot
rapids-bot Bot merged commit 9ca2f8e into NVIDIA:release/26.06 May 21, 2026
97 checks passed
@nguidotti
nguidotti deleted the fix-time-violation branch May 21, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working mip non-breaking Introduces a non-breaking change P0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants