Fix MAX_ELLIPSOID crash for low-dimensional (1D/2D) polytopes #382
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.
This PR fixes a crash that occurs when computing the MAX_ELLIPSOID rounding
for low-dimensional (1D and 2D) polytopes.
Background
The MAX_ELLIPSOID rounding procedure computes the minimum and maximum
eigenvalues of the ellipsoid matrix in order to evaluate the roundness
condition. For performance reasons, this is done using
Spectra::SymEigsSolver, requesting the smallest and largest eigenvalues.
However, Spectra enforces the constraint:
1 <= nev <= d - 1
where d is the matrix dimension.
The previous implementation always requested nev = 2, which is valid for
d >= 3 but invalid for d <= 2. For 2D polytopes (d = 2), this results in
nev > d - 1 and causes Spectra to throw a std::invalid_argument exception,
terminating the program.
Fix
This PR updates the eigenvalue computation logic as follows:
unchanged.
the full spectrum safely.
This avoids invalid Spectra calls and ensures that MAX_ELLIPSOID works
correctly for low-dimensional polytopes, while preserving the original
behavior and performance characteristics for higher dimensions.
Notes
The crash is deterministic for d <= 2 and does not depend on input data.
Although the lp_solve-dependent example could not be run locally due to
environment constraints, the fix removes the exact failure path responsible
for the exception.
Fixes #325.