0

I am using cplex .dll file in python to solve a well-formulated lp problem using pulp solver. Here is the code

here model is pulp object created using pulp library

When I run a.actualSolve(Model) I get following error from subprocess.py file.

OSError: [WinError 193] %1 is not a valid Win32 application

I tried with python 32 bit and 64 bit but couldn't solve it.

import pulp a = pulp.solvers.CPLEX_CMD("cplex dll file location")

a.actualSolve(model)

I expect the cplex dll file to solve my formulated optimization model and give me a solution for all the variables.

Community
  • 1
  • 1

2 Answers2

0

The CPLEX_CMD solver is a wrapper around the CPLEX Interactive, not the DLL. You can pass the path to the cplex.exe file to the constructor or just make sure that it is in your PATH (see Adding directory to PATH Environment Variable in Windows).

In order to use the CPLEX DLL file, you need to use the CPLEX_DLL solver (see the PuLP source code). You also need to edit the PuLP configuration file to point to the location of the CPLEX DLL file.

For example, on Windows, your pulp.cfg file might look like:

[locations]
...
CplexPath = cplex1290.dll
...

This assumes that the CPLEX binary directory is already in your PATH (exactly as with cplex.exe above). Alternately, you can specify the absolute path to cplex1290.dll in the configuration file.

rkersh
  • 4,447
  • 2
  • 22
  • 31
0

Now pulp has documentation on connecting with several solvers, including CPLEX: https://coin-or.github.io/pulp/guides/how_to_configure_solvers.html

First example for CPLEX_CMD:

path_to_cplex = r'C:\Program Files\IBM\ILOG\CPLEX_Studio128\cplex\bin\x64_win64\cplex.exe'
import pulp as pl
model = pl.LpProblem("Example", pl.LpMinimize)
solver = pl.CPLEX_CMD(path=path_to_cplex)
_var = pl.LpVariable('a')
_var2 = pl.LpVariable('a2')
model += _var + _var2 == 1
result = model.solve(solver)
pchtsp
  • 794
  • 1
  • 6
  • 15