evalCons

PURPOSE ^

% Method of optiGTest class

SYNOPSIS ^

function [ZZ,GZ,GZreshape]=evalCons(obj,XX,num)

DESCRIPTION ^

% Method of optiGTest class
 L. LAURENT --  15/04/2018 -- luc.laurent@lecnam.net

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% Method of optiGTest class
0002 % L. LAURENT --  15/04/2018 -- luc.laurent@lecnam.net
0003 
0004 % sources available here:
0005 % https://bitbucket.org/luclaurent/optigtest/
0006 % https://github.com/luclaurent/optigtest/
0007 
0008 % optiGTest - set of testing functions    A toolbox to easy manipulate functions.
0009 % Copyright (C) 2018  Luc LAURENT <luc.laurent@lecnam.net>
0010 %
0011 % This program is free software: you can redistribute it and/or modify
0012 % it under the terms of the GNU General Public License as published by
0013 % the Free Software Foundation, either version 3 of the License, or
0014 % (at your option) any later version.
0015 %
0016 % This program is distributed in the hope that it will be useful,
0017 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0018 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0019 % GNU General Public License for more details.
0020 %
0021 % You should have received a copy of the GNU General Public License
0022 % along with this program.  If not, see <http://www.gnu.org/licenses/>.
0023 
0024 %% evaluate the constraint function(s)
0025 % INPUTS:
0026 %  - XX: sample points on which the constraint function(s) will be evaluate [optional]
0027 %  - num: number of the requested  constraint function(s) in the case of problem with many constraints [optional]
0028 % OUTPUTS (empty if the problem does not have any constraint):
0029 %  - ZZ, GZ: responses and gradients of the constraint function(s) stored in cells (in the case of one requested contraint function problem no cell is used)
0030 %  - GZrehape: specific storage of the gradients for meshgrid
0031 
0032 function [ZZ,GZ,GZreshape]=evalCons(obj,XX,num)
0033 %default values
0034 Xrun=obj.Xeval;
0035 numOk=[];
0036 if nargin>2, if ~isempty(num);numOk=num;end, end
0037 %
0038 if nargin>1
0039     if ~isempty(XX)
0040         Xrun=obj.prepX(XX);
0041     end
0042 end
0043 %
0044 if obj.nbCons>0
0045     %specific constraint function
0046     if ~isempty(numOk)
0047         cellCons=obj.funCons(numOk);
0048     else
0049         cellCons=obj.funCons;
0050     end
0051     %
0052     nbF=numel(cellCons);
0053     %evaluate (all) objective function(s)
0054     funE=@(x,y)feval(['fun' x],y);
0055     %%
0056     if nargout>1
0057         [ZZtmp,GZtmp]=cellfun(@(x)funE(x,Xrun),cellCons,'UniformOutput',false);
0058     else
0059         [ZZtmp]=cellfun(@(x)funE(x,Xrun),cellCons,'UniformOutput',false);
0060     end
0061     %reshape data
0062     if nbF==1
0063         ZZ=ZZtmp{1};
0064         if nargout>1
0065             GZ=GZtmp{1};
0066         end
0067     else
0068         ZZ=ZZtmp;
0069         if nargout>1
0070             GZ=GZtmp;
0071         end
0072     end
0073     if nargout>2
0074         if nbF==1
0075             GZreshape=reshape(GZ,[],size(GZ,3));
0076         else
0077             funR=@(x)reshape(x,[],size(x,3));
0078             GZreshape=cellfun(funR,GZ,'UniformOutput',false);
0079         end
0080     end
0081 else
0082     fprintf('No constraint function(s)\n');
0083     ZZ=NaN;
0084     GZ=NaN;
0085     GZreshape=NaN;
0086 end
0087 end

Generated on Tue 28-May-2019 16:00:34 by m2html © 2005