How to Put Objective and Constraints functions in the same function ?
6 views (last 30 days)
Show older comments
Greetings All,
I am working on an optimization problem with non linear inequality constraints and i wish to put the objective and constraints functions in the same function;
the problem is that my objective function is not an algebriac expression it is rather an implicit value from Look up tables
i define my objective function as follows
function OBJ = Obj(X)
OBJ = X(11); % where x11 is a value from a generated LUT
end
and here is the non linear constraints function
function [C, CEQ] = NonLinCon(X, LUT1, LUT2, IP)
% vectorized design variables
DOF.M(1).N = X(:,1);
DOF.M(2).N = X(:,2);
DOF.M(3).N = X(:,3);
DOF.M(4).N = X(:,4);
DOF.M(5).N = X(:,5);
DOF.M(1).S = X(:,6);
DOF.M(2).S = X(:,7);
DOF.M(3).S = X(:,8);
DOF.M(4).S = X(:,9);
DOF.M(5).S = X(:,10);
DOF.R = IP.R;
DOF.VDS_MARGIN = IP.VDS_MARGIN;
DOF.IB = X(:,11).*1e-3;
DOF.VDD = IP.VDD;
DOF.CL = IP.CL;
DOF.VICM = IP.VICM;
DOF.VOCM = IP.VOCM;
DOF.M(6).N = DOF.M(5).N;
DOF.M(6).S = DOF.M(5).S;
[~, OP] = mainfnc(LUT1,LUT2,DOF);
% Nonlinear Inequality Constraints
C(:,1) = IP.UGF ./ double(OP.UGF) - 1;
C(:,2) = IP.PM ./ double(OP.PM) - 1;
C(:,3) = log10(IP.AVDC) ./ log10(double(OP.AVDC)) - 1;
C(:,4) = IP.FO ./ double(OP.FO) - 1;
C(:,5) = IP.FP1 ./ double(OP.FP1) - 1;
c(:,6) = IP.VO_SWING ./ double(OP.VO_SWING) - 1;
CEQ = [];
end
i cant seem to follow the example provided in the documentation (solver based approach)
2 Comments
Ameer Hamza
on 15 Mar 2020
Please post your objective function and constraints here. Only then can we have some idea what the issue is here.
Answers (1)
Matt J
on 15 Mar 2020
Edited: Matt J
on 15 Mar 2020
I am working on an optimization problem with non linear inequality constraints and i wish to put the objective and constraints functions in the same function;
See this link,
the problem is that my objective function is not an algebriac expression it is rather an implicit value from Look up tables
It is very important that you do not use nearest-neighbor or linear interpolation to perform the table lookup. You must use a twice differentiable interpolatior, like 'cubic' or 'pchip'. Otherwise, your function and gradient evaluations will be rife with discontinuities, which fmincon cannot handle
2 Comments
Matt J
on 16 Mar 2020
Edited: Matt J
on 16 Mar 2020
how will i write the computeall function
The computeall function should be written to calculate any variables you want shared between your objective and constraints. Those variables should also be initialized in the workspace of runobjconstr similar to what is done in these lines
xLast = []; % Last place computeall was called
myf = []; % Use for objective at xLast
myc = []; % Use for nonlinear inequality constraint
myceq = []; % Use for nonlinear equality constraint
what will the value of y (in nested function objectiveconstr( then be in this case ?
y is the result of evaluating the objective function. The lines that compute it can use the shared variables generated by computeall(). In the example, these are [myf,myc,myceq], but they can be any shared quantities that you wish.
See Also
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!