# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1361965853 -3600
# Node ID a9c57315b4a0a0d401eba4f7cac837b193c4a727
# Parent ef19ff1169d9f44ce696b467c65421494040b22c
Bad error management in the CPLEX interface
diff --git a/sage/numerical/backends/cplex_backend.pxd b/sage/numerical/backends/cplex_backend.pxd
a
|
b
|
|
206 | 206 | int CPX_PARAM_SOLNPOOLINTENSITY = 2107 |
207 | 207 | int CPX_MAX = -1 |
208 | 208 | int CPX_MIN = 1 |
| 209 | |
| 210 | cdef extern from "../../local/include/cpxconst.h": |
| 211 | |
| 212 | # Solution quality |
| 213 | # |
| 214 | # The problem either has a simplex basis |
| 215 | int CPX_BASIC_SOLN |
| 216 | |
| 217 | # The problem has a primal and dual solution but no basis |
| 218 | int CPX_NONBASIC_SOLN |
| 219 | |
| 220 | # The problem has a primal solution but no corresponding dual solution |
| 221 | int CPX_PRIMAL_SOLN |
| 222 | |
| 223 | # The problem has no solution |
| 224 | int CPX_NO_SOLN |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
diff --git a/sage/numerical/backends/cplex_backend.pyx b/sage/numerical/backends/cplex_backend.pyx
a
|
b
|
|
810 | 810 | cdef double * c_coeff = <double *> sage_malloc(n * sizeof(double)) |
811 | 811 | cdef int * c_indices = <int *> sage_malloc(n * sizeof(int)) |
812 | 812 | cdef int * c_col = <int *> sage_malloc(n * sizeof(int)) |
813 | | |
| 813 | |
814 | 814 | for 0<= i < n: |
815 | 815 | c_coeff[i] = coeffs[i] |
816 | 816 | c_indices[i] = indices[i] |
… |
… |
|
849 | 849 | ... |
850 | 850 | MIPSolverException: ... |
851 | 851 | """ |
852 | | |
853 | 852 | cdef int status |
854 | 853 | cdef int ptype |
855 | | cdef int solnmethod_p, solntype_p, pfeasind_p, dfeasind_p |
| 854 | cdef int solnmethod_p, solntype_p, pfeasind_p, dfeasind_p |
856 | 855 | |
857 | 856 | ptype = CPXgetprobtype(self.env, self.lp) |
858 | 857 | |
… |
… |
|
868 | 867 | status = CPXsolninfo(self.env, self.lp, &solnmethod_p, &solntype_p, &pfeasind_p, &dfeasind_p) |
869 | 868 | check(status) |
870 | 869 | |
871 | | if not pfeasind_p: |
872 | | raise MIPSolverException("CPLEX: The primal has no feasible solution") |
873 | | if not dfeasind_p: |
874 | | raise MIPSolverException("CPLEX: The problem is unbounded") |
875 | | |
| 870 | if solntype_p == CPX_NO_SOLN: |
| 871 | if not pfeasind_p: |
| 872 | raise MIPSolverException("CPLEX: The primal has no feasible solution") |
| 873 | elif not dfeasind_p: |
| 874 | raise MIPSolverException("CPLEX: The problem is unbounded") |
| 875 | else: |
| 876 | raise MIPSolverException("CPLEX: No solution has been found, but no idea why") |
876 | 877 | |
877 | 878 | return 0 |
878 | 879 | |
879 | | |
880 | 880 | cpdef get_objective_value(self): |
881 | 881 | r""" |
882 | 882 | Returns the value of the objective function. |