checkCons

PURPOSE ^

% Method of optiGTest class

SYNOPSIS ^

function status=checkCons(obj,XX,num,ZZ)

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 %% check constraints status (violation of constraints)
0025 % INPUTS:
0026 %  - XX: sample points [optional]
0027 %  - num: number of the checked constraint function(s) [optional]
0028 %  - ZZ: provided values of the constraint(s) [optional]
0029 % OUTPUT:
0030 %  - status: status of the constraints violation stored in cells (in the case of one constraint no cell is used)
0031 
0032 function status=checkCons(obj,XX,num,ZZ)
0033 %default values
0034 numOk=[];
0035 status=true;
0036 if obj.nbCons>0
0037     availResp=false;availPts=false;
0038     %deal with input arguments
0039     if nargin==4, if ~isempty(ZZ);availResp=true;ZZOk=ZZ;end, end
0040     if nargin>1, if ~isempty(XX);availPts=true;end, end
0041     if nargin>2, if ~isempty(num);numOk=num;end, end
0042     %available sample points
0043     if availPts
0044         obj.prepX(XX);
0045         availResp=false; % priority on new sample points
0046     end
0047     % with no values of constraints
0048     if ~availResp
0049         %evaluation contraint(s)
0050         ZZOk=obj.evalCons([],numOk);
0051     end
0052     
0053     %% check constraints
0054     %specific constraint test
0055     if ~isempty(numOk)
0056         cellType=obj.typeCons(numOk);
0057     else
0058         cellType=obj.typeCons;
0059     end
0060     %obtain right function name
0061     testFun=cellfun(@(x)boolFun(x),cellType,'UniformOutput',false);
0062     %many constraints
0063     funCheck=@(x,y)y(x,0);
0064     if iscell(ZZOk)
0065         status=cellfun(funCheck,ZZOk,testFun,'UniformOutput',false);
0066     else
0067         status=feval(funCheck,ZZOk,testFun{1});
0068     end
0069 else
0070     Ofprintf('No constraint function(s)\n');
0071 end
0072 end

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