optiGTest

PURPOSE ^

% optiGTest class of test functions/problems w/- or w/o constraint(s)

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

% optiGTest class of test functions/problems w/- or w/o constraint(s)
 L. LAURENT --  15/04/2018 -- luc.laurent@lecnam.net

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %% optiGTest class of test functions/problems w/- or w/o constraint(s)
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 
0025 classdef optiGTest < handle
0026     
0027     properties
0028         namePb='';              % chosen problem
0029         typePb='';              % kind of problems ('Un'=unconstrained, 'Cons'= constrained, 'Mult'=multiobjective)
0030         %
0031         nbObj=1;                % number of objective function(s)
0032         nbCons=0;               % number of constrait function(s)
0033         %
0034         funObj={};              % objective function
0035         funCons={};             % list of constraint functions
0036         typeCons={};            % list of type of constraints (<, >, <=, >=, =)
0037         xMin=[];                % lower bound(s)
0038         xMax=[];                % upper bound(s)
0039         dim=0;                  % dimension of the problem (number of design variables)
0040         dimAvailable=0;         % available dimension for the chosen problem
0041         locMinZ                 % list of local minima (responses)
0042         locMinX                 % list of local minima (associated parameters)
0043         globMinZ                % list of global minima (responses)
0044         globMinX                % list of global minima (associated parameters)
0045         Xeval                   % set of parameters used for evaluating the function
0046         %
0047         nSCheck=5;              % number of sample points used for checking the function
0048         forceDisplayGrad=false; % flag to force display of gradients
0049         paranoidCheck=false;    % strict check of function
0050         defaultCheck=false;     % check by default after loading
0051         FDtype='CD8';           % finite difference scheme
0052         FDstep=1e-7;            % finite difference stepsize
0053     end
0054     properties (Access=private)
0055         nameDir={'Constrained','unConstrained','MultiObj','various'}; % names of the folders containing files of functions and useful functions
0056         figureHandle=[];            % handles for figures
0057     end
0058     
0059     methods
0060         
0061         
0062         %% Constructor of optiGTest class
0063         % INPUTS (all are optional):
0064         % - funName: name of the function (list available using method
0065         % dispAvailableFun)
0066         % - XX: sample points
0067         % - dim: dimension of the considered problem
0068         
0069         
0070         function obj=optiGTest(PbName,XX,dim)
0071             %add tree of the class in the path
0072             obj.addTree;
0073             %
0074             Ofprintf('###############################\n');
0075             Ofprintf('### Create optiGTest object ###\n');
0076             Ofprintf('###############################\n');
0077             %
0078             % no input arguments: create the empty class
0079             if nargin==0
0080                 Ofprintf('### Run check process of all problems\n');
0081                 obj.checkAllPb(false);
0082             else
0083                 if ~isempty(PbName)
0084                     %load problem
0085                     obj.namePb=PbName;
0086                     %display details about the considered problem
0087                     obj.dispDetails;
0088                 end
0089             end
0090             % with input arguments: (1) demo mode (if 1D or 2D function),
0091             % (2) run with XX, (3) run with XX in specified dimension
0092             if nargin==1
0093                 %check the requested problem
0094                 if ~isempty(PbName)&&obj.defaultCheck
0095                     obj.checkPb(obj.namePb);
0096                 end
0097             elseif nargin==2
0098                 %prepare sample points
0099                 obj.prepX(XX);
0100                 %evaluate responses and constraints
0101                 obj.evalAll()
0102             elseif nargin==3
0103                 %apply requested dimension
0104                 obj.dim=dim;
0105                 %prepare sample points
0106                 obj.prepX(XX);
0107                 %evaluate responses and constraints
0108                 obj.evalAll()
0109             end
0110         end
0111         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0112         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0113         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0114         %% getters
0115         function Xmax=get.xMax(obj)
0116             [~,Xmax]=obj.loadSpace;
0117         end
0118         function Xmin=get.xMin(obj)
0119             [Xmin,~]=obj.loadSpace;
0120         end
0121         function Z=get.globMinZ(obj)
0122             [~,Z]=obj.loadGlobMin;
0123             if size(Z,2)>obj.dim
0124                 Z=Z(:,1:obj.dim);
0125             end
0126         end
0127         function X=get.globMinX(obj)
0128             [X,~]=obj.loadGlobMin;
0129         end
0130         function T=get.typePb(obj)
0131             T='Un';
0132             %unconstrained
0133             if obj.nbCons>0;T='Cons';end
0134             %multiobjective
0135             if obj.nbObj>1;T='Multi';end
0136         end
0137         % flag of multi-objective problem
0138         function nbF=get.nbObj(obj)
0139             %
0140             nbF=1;
0141             %
0142             if iscellstr(obj.funObj)
0143                 nbF=numel(obj.funObj);
0144             end
0145         end
0146         % flag of constrained problem
0147         function nbC=get.nbCons(obj)
0148             %
0149             nbC=0;
0150             %
0151             if iscellstr(obj.funCons)
0152                 nbC=numel(obj.funCons);
0153             else
0154                 if ~isempty(obj.funCons)
0155                     nbC=1;
0156                 end
0157             end
0158         end
0159         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0160         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0161         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0162         %% setters
0163         function set.namePb(obj,txt)
0164             %if the function is available we store it
0165             if availablePb(txt)
0166                 obj.namePb=txt;
0167                 % load objective function and constraints functions
0168                 obj.loadPb;
0169             else
0170                 Ofprintf('Problem %s unavailable \n',txt);
0171                 dispAvailablePb();
0172             end
0173         end
0174         function set.dim(obj,val)
0175             if isinf(val)
0176                 dimA=obj.getDimAvailable;
0177                 [~,II]=min(abs(dimA-2));
0178                 obj.dim=dimA(II);
0179             else
0180                 obj.dim=val;
0181             end
0182         end
0183         %% add figure handles
0184         function set.figureHandle(obj,hh)
0185             if all(ishandle(hh))
0186                 obj.figureHandle=[obj.figureHandle hh(:)'];
0187             else
0188                 obj.figureHandle(hh)=[];
0189             end
0190         end
0191         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0192         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0193         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0194         %% add functions in matlab's path
0195         addTree(obj);
0196         %% load data about global minimum
0197         [X,Z]=loadGlobMin(obj);
0198         %% load data about the design space
0199         [X,Z]=loadSpace(obj);
0200         %% load objective and constraints functions and type of constraints
0201         loadPb(obj);
0202         %% display details about the defined problem
0203         dispDetails(obj);
0204         %% load the available dimension for the considered test function
0205         loadDimAvailable(obj);
0206         %% get the available dimension for the considered test function
0207         dimA=getDimAvailable(obj);
0208         %% prepare the sample point for evaluation
0209         Xeval=prepX(obj,XX);
0210         %% evaluate all functions
0211         [ZZ,GZ,GG,GGG]=evalAll(obj,XX);
0212         %% evaluate the objective function
0213         [ZZ,GZ,GZreshape]=evalObj(obj,XX,num);
0214         %% evaluate the constraint functions
0215         [ZZ,GZ,GZreshape]=evalCons(obj,XX,num);
0216         %% check constraints status
0217         status=checkCons(obj,XX,num,ZZ);
0218         %% run demo mode (only for 1D or 2D function)
0219         hh=demo(obj);
0220         %% check problem by checking minimum and gradients
0221         isOk=checkPb(obj,pbName,statusPause);
0222         %% check any function
0223         isOk=checkFunObj(obj);
0224         %% check gradients of any function
0225         isOk=checkGradFun(obj,funCheck,funName);
0226         %% check all functions
0227         isOk=checkAllPb(obj,varargin);
0228         %% build table of all problems in Markdown
0229         isOk=funMD(obj,nbCol,type);
0230         %% show 2D function
0231         h=show2D(obj,XX,YY,ZZ,GZ,txt,funName);
0232         %% show 2D function wiyth constraints
0233         h=show2DCons(obj,XX,YY,ZZ,statusZ,txt,funName)
0234         %% show 1D function
0235         h=show1D(obj,XX,ZZ,GZ,txt,funName);
0236         %% close all openned figures
0237         closeFig(obj);
0238         %% show Pareto
0239         h=showPareto(obj,XX)
0240     end
0241 end

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