summaryrefslogtreecommitdiff
path: root/macros/qpipopt.sci
diff options
context:
space:
mode:
authorHarpreet2015-11-02 16:20:08 +0530
committerHarpreet2015-11-02 16:20:08 +0530
commit29e8e8bbd43892c7fa146c165fdf128f786d6a7b (patch)
treeedeacf24d149d777859c2eff9661d04c7bd2f93d /macros/qpipopt.sci
parenteb054c02e76fa28638b595865f5eda52277b70be (diff)
downloadFOSSEE-Optimization-toolbox-29e8e8bbd43892c7fa146c165fdf128f786d6a7b.tar.gz
FOSSEE-Optimization-toolbox-29e8e8bbd43892c7fa146c165fdf128f786d6a7b.tar.bz2
FOSSEE-Optimization-toolbox-29e8e8bbd43892c7fa146c165fdf128f786d6a7b.zip
README.rst added
Diffstat (limited to 'macros/qpipopt.sci')
-rw-r--r--macros/qpipopt.sci54
1 files changed, 43 insertions, 11 deletions
diff --git a/macros/qpipopt.sci b/macros/qpipopt.sci
index efcca01..8f3945e 100644
--- a/macros/qpipopt.sci
+++ b/macros/qpipopt.sci
@@ -16,16 +16,13 @@ function [xopt,fopt,exitflag,output,lambda] = qpipopt (varargin)
// Calling Sequence
// xopt = qpipopt(nbVar,nbCon,Q,p,LB,UB,conMatrix,conLB,conUB)
// xopt = qpipopt(nbVar,nbCon,Q,p,LB,UB,conMatrix,conLB,conUB,x0)
+ // xopt = qpipopt(nbVar,nbCon,Q,p,LB,UB,conMatrix,conLB,conUB,x0,param)
// [xopt,fopt,exitflag,output,lamda] = qpipopt( ... )
//
// Parameters
// nbVar : a 1 x 1 matrix of doubles, number of variables
// nbCon : a 1 x 1 matrix of doubles, number of constraints
-<<<<<<< HEAD
// Q : a n x n symmetric matrix of doubles, where n is number of variables, represents coefficients of quadratic in the quadratic problem.
-=======
- // Q : a n x n matrix of doubles, where n is number of variables, represents coefficients of quadratic in the quadratic problem.
->>>>>>> c2679735a3443017e003ca095d0476bae2dd8e40
// p : a n x 1 matrix of doubles, where n is number of variables, represents coefficients of linear in the quadratic problem
// LB : a n x 1 matrix of doubles, where n is number of variables, contains lower bounds of the variables.
// UB : a n x 1 matrix of doubles, where n is number of variables, contains upper bounds of the variables.
@@ -33,6 +30,7 @@ function [xopt,fopt,exitflag,output,lambda] = qpipopt (varargin)
// conLB : a m x 1 matrix of doubles, where m is number of constraints, contains lower bounds of the constraints.
// conUB : a m x 1 matrix of doubles, where m is number of constraints, contains upper bounds of the constraints.
// x0 : a m x 1 matrix of doubles, where m is number of constraints, contains initial guess of variables.
+ // param : a list containing the the parameters to be set.
// xopt : a 1xn matrix of doubles, the computed solution of the optimization problem.
// fopt : a 1x1 matrix of doubles, the function value at x.
// exitflag : Integer identifying the reason the algorithm terminated.
@@ -69,7 +67,9 @@ function [xopt,fopt,exitflag,output,lambda] = qpipopt (varargin)
// 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)
+ // x0 = repmat(0,nbVar,1);
+ // param = list("MaxIter", 300, "CpuTime", 100);
+ // [xopt,fopt,exitflag,output,lambda]=qpipopt(nbVar,nbCon,Q,p,lb,ub,conMatrix,conLB,conUB,x0,param)
//
// Examples
// //Find the value of x that minimize following function
@@ -98,8 +98,8 @@ function [xopt,fopt,exitflag,output,lambda] = qpipopt (varargin)
[lhs , rhs] = argn();
//To check the number of argument given by user
- if ( rhs < 9 | rhs > 10 ) then
- errmsg = msprintf(gettext("%s: Unexpected number of input arguments : %d provided while should be 9 or 10"), "qpipopt", rhs);
+ if ( rhs < 9 | rhs > 11 ) then
+ errmsg = msprintf(gettext("%s: Unexpected number of input arguments : %d provided while should be 9, 10 or 11"), "qpipopt", rhs);
error(errmsg)
end
@@ -113,22 +113,53 @@ function [xopt,fopt,exitflag,output,lambda] = qpipopt (varargin)
conMatrix = varargin(7);
conLB = varargin(8);
conUB = varargin(9);
+
- if ( rhs<10 ) then
- x0 = repmat(0,1,nbVar)
+ if ( rhs<10 | size(varargin(10)) ==0 ) then
+ x0 = repmat(0,nbVar,1);
else
x0 = varargin(10);
end
+ if ( rhs<11 ) then
+ param = list();
+ else
+ param =varargin(11);
+ end
+
+ if (modulo(size(param),2)) then
+ errmsg = msprintf(gettext("%s: Size of parameters should be even"), "qpipopt");
+ error(errmsg);
+ end
+
+
+ options = list(..
+ "MaxIter" , [3000], ...
+ "CpuTime" , [600] ...
+ );
+
+ for i = 1:(size(param))/2
+ select param(2*i-1)
+ case "MaxIter" then
+ options(2*i) = param(2*i);
+ case "CpuTime" then
+ options(2*i) = param(2*i);
+ else
+ errmsg = msprintf(gettext("%s: Unrecognized parameter name ''%s''."), "qpipopt", param(2*i-1));
+ error(errmsg)
+ end
+ end
+
//IPOpt wants it in row matrix form
p = p';
LB = LB';
UB = UB';
conLB = conLB';
conUB = conUB';
+ x0 = x0';
//Checking the Q matrix which needs to be a symmetric matrix
- if ( Q~=Q') then
+ if ( ~isequal(Q,Q') ) then
errmsg = msprintf(gettext("%s: Q is not a symmetric matrix"), "qpipopt");
error(errmsg);
end
@@ -182,7 +213,8 @@ function [xopt,fopt,exitflag,output,lambda] = qpipopt (varargin)
error(errmsg);
end
- [xopt,fopt,status,iter,Zl,Zu,lmbda] = solveqp(nbVar,nbCon,Q,p,conMatrix,conLB,conUB,LB,UB,x0);
+
+ [xopt,fopt,status,iter,Zl,Zu,lmbda] = solveqp(nbVar,nbCon,Q,p,conMatrix,conLB,conUB,LB,UB,x0,options);
xopt = xopt';
exitflag = status;