CPLEX Error 5002求助:高维度MIQP问题非凸判定异常
Hey there, let's break down how to tackle that CPLEX Error 5002 you're facing when your MIQP problem scales beyond 600 variables. Even though you've confirmed your matrix is semi-positive definite (semi-PSD), high-dimensional problems often introduce numerical quirks that trip up solvers like CPLEX. Here are actionable steps to diagnose and fix the issue:
Double-check numerical semi-PSDness of your matrix
Theoretical semi-PSD doesn't always translate to numerical semi-PSD, especially with high-dimensional matrices. Runeig(Hprim'*Hprim)to inspect the eigenvalues. If you see tiny negative values (like -1e-10 or smaller), that's likely the culprit—CPLEX uses strict checks for convexity, and even minuscule numerical errors can make it flag the matrix as non-convex.Add a tiny regularization term to your Hessian
To fix numerical semi-PSD issues, tweak your matrix to be strictly positive definite with a negligible diagonal term:H = Hprim'*Hprim + 1e-8*eye(size(Hprim,2));Test values between 1e-9 and 1e-7 to find a balance that passes CPLEX's convexity check without altering your problem's optimal solution.
Verify your
ctypevariable type definitions
Even if small problems work, it's easy to mess upctypewhen scaling variables. Make sure the length ofctypematches your total number of variables, and each character correctly marks variables as'C'(continuous) or'B'(binary). A single misplaced character could throw off CPLEX's problem classification.Adjust CPLEX parameters for convexity checks
CPLEX has settings that can relax or refine convexity validation:- Set the
optimalitytargetto 3, which is designed for convex MIQPs:cplex.Param.optimalitytarget = 3; - Widen the convexity tolerance to allow minor numerical deviations:
cplex.Param.qp.tolerances.convexity = 1e-6;
(Note: Don't make this tolerance too large, as it might let truly non-convex problems slip through.)
- Set the
Improve numerical stability for high dimensions
High-dimensional matrices often have poor condition numbers, leading to numerical instability:- Convert dense matrices to sparse storage—CPLEX handles sparse data more reliably for large problems;
- Scale your variables or matrix entries to reduce the range of values (e.g., normalize columns to have similar magnitudes), which improves numerical precision.
Check your inequality constraints for numerical issues
Even with emptyAeq, yourAineqandbineqmight have problems in high dimensions: linear dependent rows, or entries with vastly different magnitudes. Userank(Aineq)to check for linear dependence, and normalize constraint rows to have consistent scales—this can indirectly help CPLEX correctly assess the problem's convexity.
内容的提问来源于stack exchange,提问作者lmbd_a

