CPLEX solve()返回false但状态显示Optimal的原因及疑问
CPLEX solve() Returns False but Status Indicates Optimal: What’s Happening?
Core Contradiction Breakdown
- The
cplex.solve()method returnsfalsenot only for infeasible or unbounded models, but also when invalid model data triggers an error during solve initialization or presolve. - Even though
cplex.getCplexStatus()returnsCPX_STAT_OPTIMALandcplex.getStatus()returnsOptimal, this status refers to the trivially empty model left after presolve eliminated all rows and columns—not a valid solved model with variables.
Root Cause: NaN Coefficients
- Your model contained NaN values in coefficients, which are invalid for CPLEX. During presolve, CPLEX detects these invalid entries and removes all associated rows/columns to "resolve" the invalidity, resulting in an empty model.
- The empty model is technically optimal (no constraints to violate, no objective to optimize), hence the status codes. However, the presence of NaNs is an error condition that causes
solve()to returnfalseas a signal that the original model was invalid.
Why getValues() Triggers a Runtime Exception
- After presolve eliminates all variables, there are no variable values to retrieve. Calling
cplex.getValues()in this state attempts to access non-existent data, leading to the runtime error.
Fix Recap
- Removing the NaN coefficients from your model ensures CPLEX can process a valid, non-empty model. Presolve no longer eliminates all rows/columns,
solve()returnstrueon successful solution, andcplex.getValues()works as expected.
内容的提问来源于stack exchange,提问作者thewoz
相关产品推荐
相关产品推荐

