ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 27 Apr 2011 08:56:43 -0500Sage 4.6.2: how to use CPLEXhttps://ask.sagemath.org/question/7986/sage-462-how-to-use-cplex/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, PaulSat, 05 Mar 2011 11:37:01 -0600https://ask.sagemath.org/question/7986/sage-462-how-to-use-cplex/Answer by Dima for <p>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</p>
<pre><code>lp = MixedIntegerLinearProgram(solver="GLPK");
</code></pre>
<p>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).</p>
<p>Does anybody know the correct incantation?</p>
<p>TIA, Paul</p>
https://ask.sagemath.org/question/7986/sage-462-how-to-use-cplex/?answer=12315#post-id-12315you 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 setup.py" 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).
Sat, 23 Apr 2011 07:54:28 -0500https://ask.sagemath.org/question/7986/sage-462-how-to-use-cplex/?answer=12315#post-id-12315Answer by Nathann for <p>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</p>
<pre><code>lp = MixedIntegerLinearProgram(solver="GLPK");
</code></pre>
<p>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).</p>
<p>Does anybody know the correct incantation?</p>
<p>TIA, Paul</p>
https://ask.sagemath.org/question/7986/sage-462-how-to-use-cplex/?answer=12320#post-id-12320As 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).Wed, 27 Apr 2011 08:56:43 -0500https://ask.sagemath.org/question/7986/sage-462-how-to-use-cplex/?answer=12320#post-id-12320Answer by Mike Hansen for <p>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</p>
<pre><code>lp = MixedIntegerLinearProgram(solver="GLPK");
</code></pre>
<p>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).</p>
<p>Does anybody know the correct incantation?</p>
<p>TIA, Paul</p>
https://ask.sagemath.org/question/7986/sage-462-how-to-use-cplex/?answer=12175#post-id-12175In 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 [http://www.sagemath.org/doc/thematic_tutorials/linear_programming.html#installing-cplex](http://www.sagemath.org/doc/thematic_tutorials/linear_programming.html#installing-cplex) . Sat, 05 Mar 2011 12:24:26 -0600https://ask.sagemath.org/question/7986/sage-462-how-to-use-cplex/?answer=12175#post-id-12175Comment by prubin for <p>In order to use the COIN solver within Sage you have to have the <code>cbc</code> pacakge installed. It can be easily installed with :</p>
<pre><code>sage -i cbc
</code></pre>
<p>After the <code>cbc</code> package installed, run</p>
<pre><code>sage -br
</code></pre>
<p>to build the new backend module for COIN. Then, you'll be able to run</p>
<pre><code>lp = MixedIntegerLinearProgram(solver="Coin")
</code></pre>
<p>CPLEX is a little trickier, but there is documentation you can find documentation at <a href="http://www.sagemath.org/doc/thematic_tutorials/linear_programming.html#installing-cplex">http://www.sagemath.org/doc/thematic_tutorials/linear_programming.html#installing-cplex</a> . </p>
https://ask.sagemath.org/question/7986/sage-462-how-to-use-cplex/?comment=22016#post-id-22016Thanks. This made some progress. After following the instructions, I get an undefined symbol error in one of the Cbc object files (libCbcSolver.so.0) 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.Sat, 05 Mar 2011 16:01:03 -0600https://ask.sagemath.org/question/7986/sage-462-how-to-use-cplex/?comment=22016#post-id-22016