Ask Your Question

Sage 4.6.2: how to use CPLEX

asked 2011-03-05 11:37:01 -0500

prubin gravatar image

updated 2011-04-28 12:17:55 -0500

Kelvin Li gravatar image

I've just upgraded from 4.6 to 4.6.2. The COIN and CPLEX backends were included (in .../devel/sage-main/sage/numerical/backends), but I can't find a way to import them. The line

lp = MixedIntegerLinearProgram(solver="GLPK");

works, but solver="Coin" and solver="CPLEX" lead to messages that the corresponding _backend module is not found. I tried a few blind guesses to import them but had not luck. The docs seem to be a lap behind (the help for MixedIntegerLinearProgram says the CPLEX interface is not implemented yet, but that COIN's is; on the other hand, asking for help for sage.numerical.backends.xxxx_backend works for xxxx=glpk but not for xxxx=coin or cplex).

Does anybody know the correct incantation?

TIA, Paul

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2011-04-23 07:54:28 -0500

you can install CPLEX Python interface as a "plain" Python package in Sage's python, following the standard instructions for installing CPLEX Python's interface, replacing calls (if I recall right, you need to run "python" in some directory) to python with "sage -python", which will invoke Sage's python interpreter. Then it will be available within Sage (you'd need to do the usual CPLEX Python stuff to call it, though).

edit flag offensive delete link more

answered 2011-04-27 08:56:43 -0500

Nathann gravatar image

As Mike said it earlier, CBC (Coin) and CPLEX are not included in Sage by default. When you install Sage, GLPK is the only solver available and used.

What Sage does contain, however, are backends to GLPK CBC and CPLEX so that you can use them when they are available.

Coin is free, so you can install it by a spkg, but CPLEX is proprietary and you need a license if you want to use it. CPLEX is very expensive, but you can get a free license (without restriction on the size of problems you want to solve, or the number of threads) though IBM's Academic Initiative.

By default, Sage use Cplex if it is available. If not, then is uses CBC. If it is not available, GLPK is used. And you shouldn't have to import backends manually for a normal use of LP in Sage (it may be interesting to do so if you want to use solver-specific functions, though).

edit flag offensive delete link more

answered 2011-03-05 12:24:26 -0500

Mike Hansen gravatar image

In order to use the COIN solver within Sage you have to have the cbc pacakge installed. It can be easily installed with :

sage -i cbc

After the cbc package installed, run

sage -br

to build the new backend module for COIN. Then, you'll be able to run

lp = MixedIntegerLinearProgram(solver="Coin")

CPLEX is a little trickier, but there is documentation you can find documentation at .

edit flag offensive delete link more


Thanks. This made some progress. After following the instructions, I get an undefined symbol error in one of the Cbc object files ( if I use solver="Coin". I don't mind that, as it's really CPLEX that concerns me. Using solver="CPLEX" works fine in a terminal; I can construct and solve a small test problem. In a notebook, though, lp = MixedIntegerLinearProgram(solver="CPLEX") fails silently -- it produces no output (in the terminal I see a license message from CPLEX), no error message, and lp is considered undefined.

prubin gravatar imageprubin ( 2011-03-05 16:01:03 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2011-03-05 11:37:01 -0500

Seen: 993 times

Last updated: Apr 27 '11