diff options
author | Harpreet | 2015-10-20 14:23:25 +0530 |
---|---|---|
committer | Harpreet | 2015-10-20 14:23:25 +0530 |
commit | e4b59ea62dd9903445375c2aa1f52a52c5eab99f (patch) | |
tree | d761e8819990b031344e58c9016562bea157c05b /macros/qpipopt.sci | |
parent | e34332a406e4f3fba9b99c6f9ec5138edfcc6aa2 (diff) | |
download | FOSSEE-Optimization-toolbox-e4b59ea62dd9903445375c2aa1f52a52c5eab99f.tar.gz FOSSEE-Optimization-toolbox-e4b59ea62dd9903445375c2aa1f52a52c5eab99f.tar.bz2 FOSSEE-Optimization-toolbox-e4b59ea62dd9903445375c2aa1f52a52c5eab99f.zip |
qpipopt_mat added
Diffstat (limited to 'macros/qpipopt.sci')
-rw-r--r-- | macros/qpipopt.sci | 78 |
1 files changed, 43 insertions, 35 deletions
diff --git a/macros/qpipopt.sci b/macros/qpipopt.sci index 0d1b6b6..4f8c535 100644 --- a/macros/qpipopt.sci +++ b/macros/qpipopt.sci @@ -20,7 +20,7 @@ function [xopt,fopt,exitflag,output,lambda] = qpipopt (varargin) // Parameters // nbVar : a 1 x 1 matrix of doubles, number of variables // nbCon : a 1 x 1 matrix of doubles, number of constraints - // Q : a n x n matrix of doubles, where n is number of variables, represents coefficients of quadratic in the quadratic problem. + // Q : a n x n symmetric matrix of doubles, where n is number of variables, represents coefficients of quadratic in the quadratic problem. // p : a 1 x n matrix of doubles, where n is number of variables, represents coefficients of linear in the quadratic problem // LB : a 1 x n matrix of doubles, where n is number of variables, contains lower bounds of the variables. // UB : a 1 x n matrix of doubles, where n is number of variables, contains upper bounds of the variables. @@ -50,42 +50,39 @@ function [xopt,fopt,exitflag,output,lambda] = qpipopt (varargin) // // Examples // //Find x in R^6 such that: - // // conMatrix= [1,-1,1,0,3,1; // -1,0,-3,-4,5,6; // 2,5,3,0,1,0 // 0,1,0,1,2,-1; // -1,0,2,1,1,0]; - // conLB=[1 2 3 -%inf -%inf]'; - // conUB = [1 2 3 -1 2.5]'; - // //with x between ci and cs: - // lb=[-1000 -10000 0 -1000 -1000 -1000]; - // ub=[10000 100 1.5 100 100 1000]; + // conLB=[1;2;3;-%inf;-%inf]; + // conUB = [1;2;3;-1;2.5]; + // lb=[-1000;-10000; 0; -1000; -1000; -1000]; + // ub=[10000; 100; 1.5; 100; 100; 1000]; // //and minimize 0.5*x'*Q*x + p'*x with - // p=[1 2 3 4 5 6]; Q=eye(6,6); + // p=[1; 2; 3; 4; 5; 6]; Q=eye(6,6); // nbVar = 6; // nbCon = 5; // [xopt,fopt,exitflag,output,lambda]=qpipopt(nbVar,nbCon,Q,p,lb,ub,conMatrix,conLB,conUB) // // Examples - // //min. -8*x1 -16*x2 + x1^2 + 4* x2^2 - // // such that - // // x1 + x2 <= 5, - // // x1 <= 3, - // // x1 >= 0, - // // x2 >= 0 - // conMatrix= [1 1]; - // conLB=[-%inf]; - // conUB = [5]; - // //with x between ci and cs: - // lb=[0,0]; - // ub=[3,%inf]; - // //and minimize 0.5*x'*Q*x + p'*x with - // p=[-8,-16]; - // Q=[1,0;0,4]; - // nbVar = 2; - // nbCon = 1; - // [xopt,fopt,exitflag,output,lambda] = qpipopt(nbVar,nbCon,Q,p,lb,ub,conMatrix,conLB,conUB) + // //Find the value of x that minimize following function + // // f(x) = 0.5*x1^2 + x2^2 - x1*x2 - 2*x1 - 6*x2 + // // Subject to: + // // x1 + x2 ≤ 2 + // // –x1 + 2x2 ≤ 2 + // // 2x1 + x2 ≤ 3 + // // 0 ≤ x1, 0 ≤ x2. + // Q = [1 -1; -1 2]; + // p = [-2; -6]; + // conMatrix = [1 1; -1 2; 2 1]; + // conUB = [2; 2; 3]; + // conLB = [-%inf; -%inf; -%inf]; + // lb = [0; 0]; + // ub = [%inf; %inf]; + // nbVar = 2; + // nbCon = 3; + // [xopt,fopt,exitflag,output,lambda] = qpipopt(nbVar,nbCon,Q,p,lb,ub,conMatrix,conLB,conUB) // // Authors // Keyur Joshi, Saikiran, Iswarya, Harpreet Singh @@ -109,10 +106,21 @@ function [xopt,fopt,exitflag,output,lambda] = qpipopt (varargin) UB = varargin(6); conMatrix = varargin(7); conLB = varargin(8); - conLB = conLB'; //IPOpt wants it in row matrix form conUB = varargin(9); - conUB = conUB'; //IPOpt wants it in row matrix form + //IPOpt wants it in row matrix form + p = p'; + LB = LB'; + UB = UB'; + conLB = conLB'; + conUB = conUB'; + + //Checking the Q matrix which needs to be a symmetric matrix + if ( Q~=Q') then + errmsg = msprintf(gettext("%s: Q is not a symmetric matrix"), "qpipopt"); + error(errmsg); + end + //Check the size of Q which should equal to the number of variable if ( size(Q) ~= [nbVar nbVar]) then errmsg = msprintf(gettext("%s: The Size of Q is not equal to the number of variables"), "qpipopt"); @@ -126,31 +134,31 @@ function [xopt,fopt,exitflag,output,lambda] = qpipopt (varargin) end -//Check the size of constraint which should equal to the number of constraints - if ( size(conMatrix,1) ~= nbCon) then - errmsg = msprintf(gettext("%s: The Lower Bound is not equal to the number of variables"), "qpipopt"); + //Check the size of constraint which should equal to the number of variables + if ( size(conMatrix,2) ~= nbVar) then + errmsg = msprintf(gettext("%s: The size of constraints is not equal to the number of variables"), "qpipopt"); error(errmsg); end -//Check the size of Lower Bound which should equal to the number of variables + //Check the size of Lower Bound which should equal to the number of variables if ( size(LB,2) ~= nbVar) then errmsg = msprintf(gettext("%s: The Lower Bound is not equal to the number of variables"), "qpipopt"); error(errmsg); end -//Check the size of Upper Bound which should equal to the number of variables + //Check the size of Upper Bound which should equal to the number of variables if ( size(UB,2) ~= nbVar) then errmsg = msprintf(gettext("%s: The Upper Bound is not equal to the number of variables"), "qpipopt"); error(errmsg); end -//Check the size of constraints of Lower Bound which should equal to the number of constraints + //Check the size of constraints of Lower Bound which should equal to the number of constraints if ( size(conLB,2) ~= nbCon) then errmsg = msprintf(gettext("%s: The Lower Bound of constraints is not equal to the number of constraints"), "qpipopt"); error(errmsg); end -//Check the size of constraints of Upper Bound which should equal to the number of constraints + //Check the size of constraints of Upper Bound which should equal to the number of constraints if ( size(conUB,2) ~= nbCon) then errmsg = msprintf(gettext("%s: The Upper Bound of constraints is not equal to the number of constraints"), "qp_ipopt"); error(errmsg); |