Problem on optimization function (Scilab 5.4)

Reinaldo rei.listas at yahoo.com
Fri May 25 14:19:34 CEST 2012


Hi Scilab users,

I use Scilab 5.4 for Mac OS X Lion. My codes ran correctly on Scilab 5.3 (for Windows). But on Scilab 5.4,
it shows errors. I think that "linpro function" has modified on Scilab 5.4 (or it has not included on Scilab optimization function list).

Both ways of solving LP problem are shown, as follows:

// PROJECT PROBLEM: find the optimum value of following LP model. // Maximize 13*x1 + 16*x2 + 16*x3 + 14*x4 + 39*x5 // such as // 11*x1 + 53*x2 + 5*x3 + 5*x4 + 29*x5 <= 40 // 3*x1 + 6*x2 + 5*x3 + x4 + 34*x5 <= 20 // x1 <= 1 // x2 <= 1 // x3 <= 1 // x4 <= 1 // x5 <= 1 // xi >= 0 (i = 1,...,5) // Converting to min LP problem // Minimize -13*x1 - 16*x2 - 16*x3 - 14*x4 - 39*x5 // such as // 11*x1 + 53*x2 + 5*x3 + 5*x4 + 29*x5 <= 40 // 3*x1 + 6*x2 + 5*x3 + x4 + 34*x5 <= 20 // x1 <= 1 // x2 <= 1 // x3 <= 1 // x4 <= 1 // x5 <= 1 // xi >= 0 (i = 1,...,5) // First resolution of LP problem:   (THIS RESOLUTION WORKED !) // You can try the karmarkar function built in Scilab : // Use slack variables: // Minimize -13*x1 - 16*x2 - 16*x3 - 14*x4 - 39*x5 // such as // 11*x1 + 53*x2 + 5*x3 + 5*x4 + 29*x5 + e1                = 40 // 3*x1 +   6*x2 + 5*x3 +   x4 + 34*x5 +   e2              = 20 //   x1 +                                    e3            =  1 //            x2
 +                             e4          =  1 //                   x3 +                        e5        =  1 //                          x4 +                   e6      =  1 //                                  x5 +             e7    =  1 // xi, ej >= 0 (i = 1,...,5) (j = 1,..., 7) // The following script solves the problem. Here, the initial guess x0 is given.  Aeq = [ 11 53 5 5 29 1 0 0 0 0 0 0 3 6 5 1 34 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 ]; // coefficients of constraint matrix beq = [40 20 1 1 1 1 1]'; // vector of independent terms c = [-13 -16 -16 -14 -39 0 0 0 0 0 0 0]'; // coefficients of objective function [n,p]=size(Aeq); // Now, assume that the initial guess x0 is unknown. // To find a feasible point, we solve the following problem :  cc = [zeros(p,1);1]; AAeq = [Aeq,beq-Aeq*ones(p,1)]; bbeq = beq; z0 = ones(p+1,1);
 zopt=karmarkar(AAeq,bbeq,cc,z0,0,0.99) x0=zopt(1:p) // This gives a very small value of zopt(p+1) // The previous script allows to produces the initial guess: x0 // We now plug the initial guess x0 into the original problem and get:  xopt=karmarkar(Aeq,beq,c,x0,1.e-10,0.999) // optimization result // where the components xopt(1:4) are the original variables and xopt(5:) are slack variables. f = c'*xopt // result of objetive function // Second resolution of LP problem:   (THIS RESOLUTION WORKED !) // You can also try the "quapro"module and the linpro function. // Minimize -13*x1 - 16*x2 - 16*x3 - 14*x4 - 39*x5 // such as // 11*x1 + 53*x2 + 5*x3 + 5*x4 + 29*x5 <= 40 // 3*x1 + 6*x2 + 5*x3 + x4 + 34*x5 <= 20 // x1 <= 1 // x2 <= 1 // x3 <= 1 // x4 <= 1 // x5 <= 1 // xi >= 0 (i = 1,...,5) p = [-13 -16 -16 -14 -39]'; // coefficients of objective function C = [ 11 53 5 5 29 3 6 5 1 34 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 ]; // coefficients of
 constraint matrix b = [40 20 1 1 1 1 1]'; // vector of independent terms ci=[0 0 0 0 0]'; // initial values (boundary condition) cs=[%inf %inf %inf %inf %inf]'; // final values [x1,lagr,f]=linpro(p,C,b,ci,cs) // x1 represents the optimum solution // PS:  // [x,lagr,f]=linpro(p,C,b,ci,cs [,x0]) when minimize p'*x under the constraints C*x <= b // [x,lagr,f]=linpro(p,-C,-b,ci,cs [,x0]) when minimize p'*x under the constraints C*x >= b [clean(x1) clean(xopt(1:size(p,1)))] a=0;for i=1:size(p,1); a=a+x1(i);end;a //sum of optimal values using linpro b=0;for i=1:size(p,1); b=b+xopt(i);end;b //sum of optimal values using Karmarkar

The result is shown, as follows:
->Aeq = [
-->       11 53 5 5 29 1 0 0 0 0 0 0
-->        3  6 5 1 34 0 1 0 0 0 0 0
-->        1  0 0 0  0 0 0 1 0 0 0 0
-->        0  1 0 0  0 0 0 0 1 0 0 0
-->        0  0 1 0  0 0 0 0 0 1 0 0
-->        0  0 0 1  0 0 0 0 0 0 1 0
-->        0  0 0 0  1 0 0 0 0 0 0 1
-->      ];   --> -->beq = [40 20 1 1 1 1 1]';     -->c = [-13 -16 -16 -14 -39 0 0 0 0 0 0 0]';      -->[n,p]=size(Aeq); --> -->cc = [zeros(p,1);1]; -->AAeq = [Aeq,beq-Aeq*ones(p,1)]; -->bbeq = beq; -->z0 = ones(p+1,1); -->zopt=karmarkar(AAeq,bbeq,cc,z0,0,0.99) zopt  = 0.4651227   0.3447924   0.4790839   0.4846474   0.3723201   0.9937153   0.9969277   0.5348773   0.6552076   0.5209161   0.5153526   0.6276799   1.00D-162   -->x0=zopt(1:p)   x0  = 0.4651227   0.3447924   0.4790839   0.4846474   0.3723201   0.9937153   0.9969277   0.5348773   0.6552076   0.5209161   0.5153526   0.6276799   --> -->xopt=karmarkar(Aeq,beq,c,x0,1.e-10,0.999)   xopt  = 1.0017139   0.2009097   0.9994057   1.0011172   0.2881802   1.034D-13   3.512D-13   5.532D-16   0.7990812   8.466D-15   8.225D-14   0.7119165   --> -->f = c'*xopt   f  = - 57.481994   --> -->p = [-13 -16 -16 -14 -39]';  --> -->C =  [
-->       11 53 5 5 29
-->        3  6 5 1 34
-->        1  0 0 0  0
-->        0  1 0 0  0
-->        0  0 1 0  0
-->        0  0 0 1  0
-->        0  0 0 0  1
-->      ];   --> -->b = [40 20 1 1 1 1 1]';   --> -->ci=[0 0 0 0 0]';   --> -->cs=[%inf %inf %inf %inf %inf]';  --> -->[x1,lagr,f]=linpro(p,C,b,ci,cs)   !--error 4 
Variável indefinida: linpro --> -->[clean(x1) clean(xopt(1:size(p,1)))] !--error 4 
Variável indefinida: x1 -->a=0;for i=1:size(p,1); a=a+x1(i);end;a  !--error 4 
Variável indefinida: x1 -->b=0;for i=1:size(p,1); b=b+xopt(i);end;b  b  = 3.4913266 


Thank you in advance for suggestions !
All best,
Reinaldo.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20120525/ca8cd277/attachment.htm>


More information about the users mailing list