Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

How can I return the code error for "No solution exists" in pyhton(CPLEX)?

  • 1.  How can I return the code error for "No solution exists" in pyhton(CPLEX)?

    Posted 08/26/11 09:11 AM

    Originally posted by: SystemAdmin


    Hi everybody,

    I will really appreciate you to help me in advances. I write an algorithm with python. In each iteration of my algorithm, CPLEX solver is used to solve the model. But, some times the problem is not feasible and CPLEX get the "No solution exists CPLEX.CpxException: CPLEX Error 1217". So, this solution should be ignored and the heuristic continuing. However, at this stage the CPLEX is finished! How can I return the value of this error that is 1217 in the solution. I tried to use the CPLEX.CpxException that didn't work for me.

    I want a command such as:
    if CPLEX error != 1217 :
    do the following commands
    in the IBM site mention to the following commands that doesn't for me!

    except CplexSolverError as exc:

    if exc.args[2] == cplex.exceptions.error_codes.CPXERR_NO_SOLN:
    ...

    Could you please guide me how to return the code of this error in the solution?

    Regards
    Alan Kurd
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: How can I return the code error for "No solution exists" in pyhton(CPLEX)?

    Posted 08/29/11 01:37 PM

    Originally posted by: SystemAdmin


    Hello Alan,

    The code that you wrote should be the correct way to handle a specific error from the CPLEX callable library through the Python API. One possibility is that you might not have imported CplexSolverError into your current scope. Do you have the line

    from cplex.exceptions import CplexSolverError
    


    at the top of your script?

    If this doesn't resolve your issue, can you tell me what happens when you try the following in your code?

    except cplex.exceptions.CplexSolverError as exc:
        print exc
        print exc.args
    

    Philip Starhill
    CPLEX Research Engineer
    #CPLEXOptimizers
    #DecisionOptimization