[Scilab-Dev] Linear optimization and Scilab

Michaël Baudin michael.baudin at scilab.org
Mon Jan 3 11:22:17 CET 2011


Hi,

This message would better fit in the scope of the users at lists.scilab.org 
list.

Anyway, below is a way to solve your problem.

Here is the exact solution:

// Solution
c = [20 24]';
A = [
3 6
4 2
];
b = [60 32]';
xopt = [4 8]';
fopt = c'*xopt // fopt = 272
A*xopt - b // zero

You can try the karmarkar function built in Scilab :

// Use slack variables:
//
// Minimize -20.x1 - 24.x2
// 3.x1 + 6.x2 + x3 = 60
// 4.x1 + 2.x2 + x4 = 32
// x1, x2, x3, x4 >= 0

c = [-20 -24 0 0]';
a = [
3 6 1 0
4 2 0 1
];
b = [60 32]';
[x0,kerA]=linsolve(a,-b)
// x0=lsq(a,b) also works
x1=karmarkar(a,b,c,x0)

This produces :

-->x1=karmarkar(a,b,c,x0)
  1.   -0.269E+03    0.367E-02
  2.   -0.270E+03    0.275E-02
  3.   -0.270E+03    0.207E-02
  4.   -0.271E+03    0.156E-02
  5.   -0.271E+03    0.118E-02
  6.   -0.271E+03    0.896E-03
  7.   -0.271E+03    0.688E-03
  8.   -0.271E+03    0.534E-03
  9.   -0.272E+03    0.419E-03
10.   -0.272E+03    0.333E-03
11.   -0.272E+03    0.267E-03
12.   -0.272E+03    0.216E-03
13.   -0.272E+03    0.174E-03
14.   -0.272E+03    0.139E-03
15.   -0.272E+03    0.110E-03
16.   -0.272E+03    0.862E-04
17.   -0.272E+03    0.668E-04
18.   -0.272E+03    0.513E-04
19.   -0.272E+03    0.392E-04
20.   -0.272E+03    0.297E-04
21.   -0.272E+03    0.225E-04
22.   -0.272E+03    0.170E-04
23.   -0.272E+03    0.128E-04
24.   -0.272E+03    0.960E-05
  x1  =

     3.9996501
     7.999964
     0.0012658
     0.0014716


You can also try the "quapro" module and the linpro function.

// Minimize -20.x1 - 24.x2
// 3.x1 + 6.x2 <= 60
// 4.x1 + 2.x2 <= 32
// 0 <= x1 , x2 <= %inf
atomsInstall("quapro");
atomsLoad("quapro");
p = [-20 -24]';
C = [
3 6
4 2
];
b = [60 32]';
ci=[0 0]';
cs=[%inf %inf]';
[x1,lagr,f]=linpro(p,C,b,ci,cs)

This produces :

-->[x1,lagr,f]=linpro(p,C,b,ci,cs)
  f  =
   - 272.
  lagr  =
     0.
     0.
     3.1111111
     2.6666667
  x1  =
     4.
     8.

The lagrange multipliers indicate that the linear equalities are active. 
The bounds are inactive.

Best regards,

Michaël Baudin

Le 31/12/2010 17:08, Prof. Dr. Reinaldo Golmia Dante a écrit :
> Hi Scilab developers,
> I would like to suggest to you if a simple linear optimization 
> function could be implemented
> in order to solve linear optimization problems.
> I tried to integrate LPSOLVE with Scilab, but unfortunately, it was 
> hard for me.
> The manual called "Optimization in Scilab" seems complex to beginners 
> because starts
> to show nonlinear optimization functions.
> I would like to know how could I solve a simple linear problem using 
> Scilab like that:
> Max 20*x1 + 24*x2;
>
> such as:
> 3*x1 + 6*x2 <= 60;
> 4*x1 + 2*x2 <= 32;
> x1, x2 >= 0;
> Thank you in advance.
> Happy New Year 2011 !
> All best,
> Reinaldo.
> PS: I hope in 2011 Scilab has some owner LP functions. (smiles)
>


-- 
Michaël Baudin
Ingénieur de développement
michael.baudin at scilab.org
-------------------------
Consortium Scilab - Digiteo
Domaine de Voluceau - Rocquencourt
B.P. 105 - 78153 Le Chesnay Cedex
Tel. : 01 39 63 56 87 - Fax : 01 39 63 55 94


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/dev/attachments/20110103/bfa0a3d6/attachment.htm>


More information about the dev mailing list