On Jan 23, 2008 11:56 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> 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?
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
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-forum
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---