diff options
Diffstat (limited to 'macros/fgoalattain.sci')
-rw-r--r-- | macros/fgoalattain.sci | 88 |
1 files changed, 56 insertions, 32 deletions
diff --git a/macros/fgoalattain.sci b/macros/fgoalattain.sci index 5f519b4..d6bec24 100644 --- a/macros/fgoalattain.sci +++ b/macros/fgoalattain.sci @@ -89,7 +89,7 @@ function [x,fval,attainfactor,exitflag,output,lambda] = fgoalattain(varargin) // <listitem>Default Values : options = list("MaxIter", [3000], "CpuTime", [600]);</listitem> // </itemizedlist> // - // By default, the gradient options for fminimax are turned off and and fmincon does the gradient opproximation of minmaxObjfun. In case the GradObj option is off and GradConstr option is on, fminimax approximates minmaxObjfun gradient using numderivative toolbox. + // By default, the gradient options for fminimax are turned off and and fmincon does the gradient opproximation of gattainObjfun. In case the GradObj option is off and GradConstr option is on, fminimax approximates gattainObjfun gradient using numderivative toolbox. // // If we can provide exact gradients, we should do so since it improves the convergence speed of the optimization algorithm. // @@ -103,7 +103,7 @@ function [x,fval,attainfactor,exitflag,output,lambda] = fgoalattain(varargin) // <programlisting> // [c, ceq] = confun(x) // </programlisting> - // where x is a n x 1 matrix of dominmaxUbles, c is a 1 x nni matrix of doubles and ceq is a 1 x nne matrix of doubles (nni : number of nonlinear inequality constraints, nne : number of nonlinear equality constraints). + // where x is a n x 1 matrix of doubles, c is a 1 x nni matrix of doubles and ceq is a 1 x nne matrix of doubles (nni : number of nonlinear inequality constraints, nne : number of nonlinear equality constraints). // On input, the variable x contains the current point and, on output, the variable c must contain the nonlinear inequality constraints and ceq must contain the nonlinear equality constraints. // // By default, the gradient options for fminimax are turned off and and fmincon does the gradient opproximation of confun. In case the GradObj option is on and GradCons option is off, fminimax approximates confun gradient using numderivative toolbox. @@ -156,7 +156,7 @@ function [x,fval,attainfactor,exitflag,output,lambda] = fgoalattain(varargin) // </itemizedlist> // // Examples - // function f1 = fun(x) + // function f1 = gattainObjfun(x) // f1(1)=2*x(1)*x(1)+x(2)*x(2)-48*x(1)-40*x(2)+304 // f1(2)=-x(1)*x(1)-3*x(2)*x(2) // f1(3)=x(1)+3*x(2)-18 @@ -167,39 +167,45 @@ function [x,fval,attainfactor,exitflag,output,lambda] = fgoalattain(varargin) // // goal=[-5,-3,-2,-1,-4]; // weight=abs(goal) - // //xopt = [-0.0000011 -63.999998 -2.0000002 -8 3.485D-08] - // //fval = [4 3.99] + // gval = + // [- 0.0000011 + // - 63.999998 + // - 2.0000002 + // - 8. + // 3.485D-08] + // z = + // [4. 3.99] // - // //Run fgoalattain - // [xopt,fval,attainfactor,exitflag,output,lambda]=fgoalattain(fun,x0,goal,weight) + // Run fgoalattain + // [x,fval,attainfactor,exitflag,output,lambda]=fgoalattain(gattainObjfun,x0,goal,weight) // // Authors // Prajwala TM, Sheetal Shalini , 2015 // Check number of input and output arguments [gattainLhs,gattainRhs] = argn() - fgoalattainCheckrhs("fgoalattain", gattainRhs, [4 6 8 10 11 12]) - fgoalattainChecklhs("fgoalattain", gattainLhs, 1:6) + Checkrhs("fgoalattain", gattainRhs, [4 6 8 10 11 12]) + Checklhs("fgoalattain", gattainLhs, 1:6) // initialisation of fun gattainObjfun = varargin(1) - fgoalattainChecktype("fgoalattain", gattainObjfun, "fun", 1, "function") + Checktype("fgoalattain", gattainObjfun, "fun", 1, "function") // initialisation of x0 gattainStartpoint = varargin(2) - fgoalattainChecktype("fgoalattain", gattainStartpoint, "x0", 2, "constant") + Checktype("fgoalattain", gattainStartpoint, "x0", 2, "constant") gattainNumvar = size(gattainStartpoint,"*") - fgoalattainCheckvector("fgoalattain", gattainStartpoint, "x0", 2, gattainNumvar) + Checkvector("fgoalattain", gattainStartpoint, "x0", 2, gattainNumvar) gattainStartpoint = gattainStartpoint(:) // initialisation of goal goal=varargin(3) - fgoalattainChecktype("fgoalattain",goal,"goal",3,"constant") + Checktype("fgoalattain",goal,"goal",3,"constant") // initialisation of weight weight=varargin(4) - fgoalattainChecktype("fgoalattain",weight,"weight",4,"constant") + Checktype("fgoalattain",weight,"weight",4,"constant") //initialisation of A and b if(gattainRhs < 5) then @@ -210,13 +216,13 @@ function [x,fval,attainfactor,exitflag,output,lambda] = fgoalattain(varargin) gattainB = varargin(6) end - fgoalattainChecktype("fgoalattain", gattainA, "A", 5, "constant") - fgoalattainChecktype("fgoalattain", gattainB, "b", 6, "constant") + Checktype("fgoalattain", gattainA, "A", 5, "constant") + Checktype("fgoalattain", gattainB, "b", 6, "constant") gattainNumrowA = size(gattainA,"r") if(gattainA <> []) then - fgoalattainCheckdims("fgoalattain", gattainA, "A", 5, [gattainNumrowA gattainNumvar]) - fgoalattainCheckvector("fgoalattain", gattainB, "b", 6, gattainNumrowA) + Checkdims("fgoalattain", gattainA, "A", 5, [gattainNumrowA gattainNumvar]) + Checkvector("fgoalattain", gattainB, "b", 6, gattainNumrowA) gattainB = gattainB(:) end @@ -229,13 +235,13 @@ function [x,fval,attainfactor,exitflag,output,lambda] = fgoalattain(varargin) gattainBeq = varargin(8) end - fgoalattainChecktype("fgoalattain", gattainAeq, "Aeq", 7, "constant") - fgoalattainChecktype("fgoalattain", gattainBeq, "beq", 8, "constant") + Checktype("fgoalattain", gattainAeq, "Aeq", 7, "constant") + Checktype("fgoalattain", gattainBeq, "beq", 8, "constant") gattainNumrowAeq = size(gattainAeq,"r") if(gattainAeq <> []) then - fgoalattainCheckdims("fgoalattain", gattainAeq, "Aeq", 7, [gattainNumrowAeq gattainNumvar]) - fgoalattainCheckvector("fgoalattain", gattainBeq, "beq", 8, gattainNumrowAeq) + Checkdims("fgoalattain", gattainAeq, "Aeq", 7, [gattainNumrowAeq gattainNumvar]) + Checkvector("fgoalattain", gattainBeq, "beq", 8, gattainNumrowAeq) gattainBeq = gattainBeq(:) end @@ -248,17 +254,17 @@ function [x,fval,attainfactor,exitflag,output,lambda] = fgoalattain(varargin) gattainUb = varargin(10) end - fgoalattainChecktype("fgoalattain", gattainLb, "lb", 9, "constant") - fgoalattainChecktype("fgoalattain", gattainUb, "ub", 10, "constant") + Checktype("fgoalattain", gattainLb, "lb", 9, "constant") + Checktype("fgoalattain", gattainUb, "ub", 10, "constant") // Check dimensions of lb and ub if(gattainLb <> []) then - fgoalattainCheckvector("fgoalattain", gattainLb, "lb", 9, gattainNumvar) + Checkvector("fgoalattain", gattainLb, "lb", 9, gattainNumvar) gattainLb = gattainLb(:) end if(gattainUb <> []) then - fgoalattainCheckvector("fgoalattain", gattainUb, "ub", 10, gattainNumvar) + Checkvector("fgoalattain", gattainUb, "ub", 10, gattainNumvar) gattainUb = gattainUb(:) end @@ -274,7 +280,7 @@ function [x,fval,attainfactor,exitflag,output,lambda] = fgoalattain(varargin) gattainNonlinfun = varargin(11) end - fgoalattainChecktype("fgoalattain", gattainNonlinfun, "nonlcon", 11, "function") + Checktype("fgoalattain", gattainNonlinfun, "nonlcon", 11, "function") // initialisation of default options if(gattainRhs < 12) then @@ -313,12 +319,30 @@ function [x,fval,attainfactor,exitflag,output,lambda] = fgoalattain(varargin) fgaCPU = gattainUserOptions(2*i); //Setting the Maximum CPU Time as per user entry case "GradObj" then - flag1=1; - gattainFGrad = gattainUserOptions(2*i); + if (type(gattainUserOptions(2*i))==10) then + if (convstr(gattainUserOptions(2*i))=="off") then + flag1 = 0; + else + errmsg = msprintf(gettext("%s: Unrecognized String %s entered for the option- %s."), "fgoalattain",gattainUserOptions(2*i), gattainUserOptions(2*i-1)); + error(errmsg); + end + else + flag1 = 1; + gattainFGrad = gattainUserOptions(2*i); + end case "GradCon" then - flag2=1; - gattainCGrad = gattainUserOptions(2*i); + if (type(gattainUserOptions(2*i))==10) then + if (convstr(gattainUserOptions(2*i))=="off") then + flag2 = 0; + else + errmsg = msprintf(gettext("%s: Unrecognized String %s entered for the option- %s."), "fgoalattain",gattainUserOptions(2*i), gattainUserOptions(2*i-1)); + error(errmsg); + end + else + flag2 = 1; + gattainCGrad = gattainUserOptions(2*i); + end else errmsg = msprintf(gettext("%s: Unrecognized gattainUserOptionseter name ''%s''."), "fminimax", gattainUserOptions(2*i-1)); @@ -326,7 +350,7 @@ function [x,fval,attainfactor,exitflag,output,lambda] = fgoalattain(varargin) end end - // Checking if minmaxFGrad and minmaxCGrad are functions + // Checking if gattainFGrad and gattainCGrad are functions if (flag1==1) then if (type(gattainFGrad) ~= 11 & type(gattainFGrad) ~= 13) then errmsg = msprintf(gettext("%s: Expected function for Gradient of Objective"), "fminimax"); |