Search code examples
python-3.xcplexdocplex

How to install CP Optimizer 20.1 with docplex?


I am installing docplex using pip install docplex and it shows:

Successfully installed docplex-2.22.213

When I run the code it says:

- CP Optimizer 12.10.0.0 -

But since the latest ILOG CPLEX Optimization Studio is 20.1 I would expect to see CP Optimizer 20.1.

What is the reason for pip not installing the latest version?

  • OS : macOS Big Sur version 11.2
  • Python : 3.7.3

Solution

  • In the solve you can select which version of cplex you want to call on your machine.

    Let me show this with the zoo example:

    from docplex.cp.model import CpoModel
    
    mdl = CpoModel(name='buses')
    nbbus40 = mdl.integer_var(0,1000,name='nbBus40')
    nbbus30 = mdl.integer_var(0,1000,name='nbBus30')
    mdl.add(nbbus40*40 + nbbus30*30 >= 300)
    mdl.minimize(nbbus40*500 + nbbus30*400)
    
    msol=mdl.solve(execfile='C:\\ILOG\\CPLEX_Studio201\\cpoptimizer\\bin\\x64_win64\\cpoptimizer.exe')
    msol=mdl.solve(execfile='C:\\ILOG\\CPLEX_Studio1210\\cpoptimizer\\bin\\x64_win64\\cpoptimizer.exe')
    
    print(msol[nbbus40]," buses 40 seats")
    print(msol[nbbus30]," buses 30 seats")