Ticket #14195: trac_14195.patch

File trac_14195.patch, 2.7 KB (added by ncohen, 8 years ago)
  • sage/numerical/backends/cplex_backend.pxd

    # 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  
    206206     int CPX_PARAM_SOLNPOOLINTENSITY = 2107
    207207     int CPX_MAX = -1
    208208     int CPX_MIN = 1
     209
     210cdef 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
  • sage/numerical/backends/cplex_backend.pyx

    diff --git a/sage/numerical/backends/cplex_backend.pyx b/sage/numerical/backends/cplex_backend.pyx
    a b  
    810810        cdef double * c_coeff = <double *> sage_malloc(n * sizeof(double))
    811811        cdef int * c_indices = <int *> sage_malloc(n * sizeof(int))
    812812        cdef int * c_col = <int *> sage_malloc(n * sizeof(int))
    813        
     813
    814814        for 0<= i < n:
    815815            c_coeff[i] = coeffs[i]
    816816            c_indices[i] = indices[i]
     
    849849            ...
    850850            MIPSolverException: ...
    851851        """
    852    
    853852        cdef int status
    854853        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
    856855
    857856        ptype = CPXgetprobtype(self.env, self.lp)
    858857
     
    868867        status = CPXsolninfo(self.env, self.lp, &solnmethod_p, &solntype_p, &pfeasind_p, &dfeasind_p)
    869868        check(status)
    870869
    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")
    876877
    877878        return 0
    878879
    879 
    880880    cpdef get_objective_value(self):
    881881        r"""
    882882        Returns the value of the objective function.