Home > Software engineering >  Running Docplex package in Python "docplex.mp.utils.DOcplexException: Cannot solve model: no CP
Running Docplex package in Python "docplex.mp.utils.DOcplexException: Cannot solve model: no CP

Time:11-26

I wanted to solve my Oprimization model in Python by Cplex so I installed Cplex in my system (Windows 11) and based on Cplex help insttall setup.py with this command: python C:\Program Files\IBM\ILOG\CPLEX_Studio221\python\setup.py install

There are two examples in IBM "Docplex.cp" and "Docplex.mp". I run these exampleas using the vscode and jupyter. All exampleas of "Docplex.cp" run correctly but when I run examples of "Docplex.mp" I see Cplex runtime error.

This is one simple linear model that I have tried:

# Define the Model
    from docplex.mp.model import Model
    MWMS_model=Model(name="Linear Program")

# Variables
    x=MWMS_model.continuous_var(name='x', lb=0)
    y=MWMS_model.continuous_var(name='y', lb=0)

# Constraints
    c1=MWMS_model.add_constraint(x y>=8,ctname="c1")
    c2=MWMS_model.add_constraint(2*x y>=10,ctname="c2")
    c3=MWMS_model.add_constraint(x 4*y>=11,ctname="c3")

# Objective Function 
    obj=5*x 4*y
    MWMS_model.set_objective('min', obj)
    MWMS_model.print_information()

# Solvig
    MWMS_model.solve()

# Output
    MWMS_model.print_solution()

This is the error: "docplex.mp.utils.DOcplexException: Cannot solve model: no CPLEX runtime found."

CodePudding user response:

what you followed (setup.py) is in documentation

CPLEX > CPLEX Optimizers > Getting Started with CPLEX > Tutorials > Python tutorial

and this sets the matrix python api but you want to use the other python interface (docplex)

You should follow

http://ibmdecisionoptimization.github.io/docplex-doc/mp/getting_started_python.html#installing-the-cplex-modeling-library-with-pip

CodePudding user response:

Your packages may be installed incorrectly. In your Python library, you should have 'cplex' package and 'docplex' package (please note that there is a 'docplex' package which is the correct one inside 'docplex' package).

  • Related