Does sage support solving integer and combinatorial optimization/ model solving of operational research

59 views
Skip to first unread message

MuLi...@gmail.com

unread,
Jan 24, 2008, 2:56:14 AM1/24/08
to sage-forum
I just check out documents of sage, I can not find content about
operational research/ combinatorial optimization. the problem just
like as follow:
objective: Max/Min f(x1,x2,...,xn)
subject to :
f1(X)<A1
f2(X)<A2
............

some one, any one can tell me, wheter can i use sage to solve those
problem or not?

William Stein

unread,
Jan 24, 2008, 7:56:03 AM1/24/08
to sage-...@googlegroups.com

Yes. Here is an example of minimizing a function subject to constraints
using Sage (via the notebook interface):

minimize 2*x1 + x2
subject to -x1 + x2 <= 1
x1 + x2 >= 2
x2 >= 0
x1 -2*x2 <= 4

{{{
Integer=int; RealNumber=float # turn off integer and real number preparsing

from cvxopt.base import matrix
from cvxopt import solvers
A = matrix([ [-1.0, -1.0, 0.0, 1.0], [1.0, -1.0, -1.0, -2.0] ])
b = matrix([ 1.0, -2.0, 0.0, 4.0 ])
c = matrix([ 2.0, 1.0 ])
sol=solvers.lp(c,A,b)
///
pcost dcost gap pres dres k/t
0: 2.6471e+00 -7.0588e-01 2e+01 8e-01 2e+00 1e+00
1: 3.0726e+00 2.8437e+00 1e+00 1e-01 2e-01 3e-01
2: 2.4891e+00 2.4808e+00 1e-01 1e-02 2e-02 5e-02
3: 2.4999e+00 2.4998e+00 1e-03 1e-04 2e-04 5e-04
4: 2.5000e+00 2.5000e+00 1e-05 1e-06 2e-06 5e-06
5: 2.5000e+00 2.5000e+00 1e-07 1e-08 2e-08 5e-08
}}}

{{{
print sol['x']
///
5.0000e-01
1.5000e+00
}}}

Note that we turn off real and integer preparsing to avoid
confusing cvxopt too much.

Note that you can't yet just make symbolic inequalities in Sage
and have cvxopt get called automatically behind the scenes
to solve your problems. That is _definitely_ planned.

For more about the powerful functionality of cvxopt, see
http://abel.ee.ucla.edu/cvxopt

William

dmitrey

unread,
Feb 8, 2008, 4:35:38 AM2/8/08
to sage-forum, MuLi...@gmail.com
Also, you may be interested in OpenOpt
http://scipy.org/scipy/scikits/wiki/OpenOpt
This BSD-licensed module has some own solvers and connects to dozens
of outer ones (some latter are C or Fortran-written)
Regards, Dmitrey
Reply all
Reply to author
Forward
0 new messages