forked from rishemjit/CODO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSito.m
95 lines (80 loc) · 3.03 KB
/
Sito.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function [x,fVal] = Sito(funct, nvars, options)
% X = SITO(FITNESSFCN,NVARS) finds a local unconstrained minimum X to the
% FITNESSFCN using SITO. NVARS is the dimension (number of design
% variables) of the FITNESSFCN.
% Right now pass a fitness function for your problem
% Please pass functions having binary inputs i.e {0,1} for bettar results..
% We will be folowing with a continuous version too.
%% create default options if no option has been provided
close all
clc
defaultopt = struct('PopulationType', 'bitString', ...
'PopInitRange', [0;1], ...
'SocietySize', 7, ...
'DiversityFactor',0.95,...
'NeighbourhoodSize',2,...
'InitialPopulation',[], ...
'CreationFcn',[], ...
'Display', 'on', ...
'MaxIteration', 100, ...
'FitnessLimit',[],...
'Tolerance', [],...
'Variant','Osito');
% Check number of input arguments
errmsg = nargchk(1,3,nargin);
if ~isempty(errmsg)
error('SITO:numberOfInputs',...
[errmsg,' SITO requires at least 1 input argument.']);
end
% If just 'defaults' passed in, return the default options in X
if nargin == 1 && nargout <= 1 && isequal(funct,'defaults')
x = defaultopt;
return
end
if nargin < 3
options = [];
end
% One input argument is for problem structure
if nargin == 1
if isa(funct,'struct')
[funct,nvars,options] = separateOptimStruct(funct);
else % Single input and non-structure.
error('SITO:invalidStructInput',['The input should be a structure with valid'...
'fields or provide at least two arguments to SITO.'] );
end
end
% not handling cell arrray because we find it to be weird way of
% calling function
FitnessFcn = funct;
% Only function handles is allowed for FitnessFcn
if isempty(FitnessFcn) || ~isa(FitnessFcn,'function_handle')
error('SITO:needFunctionHandle','Fitness function must be a function handle.');
end
% nvars checking before we call SITO solver
valid = isnumeric(nvars) && isscalar(nvars)&& (nvars > 0) ...
&& (nvars == floor(nvars));
if ~valid
error('SITO:notValidNvars','Number of variables (NVARS) must be a positive integer.');
end
% user_options = options;
% Use default options if options structure is empty
if ~isempty(options) && ~isa(options,'struct')
error('SITO:optionsNotAStruct','Third input argument must be a valid structure created with SITOOPTIMSET.');
elseif isempty(options)
options = defaultopt;
end
% Take defaults for parameters that are not in options structure
avg_neighbors = 5 ;
variant = lower(options.Variant);
if strcmp(variant,'gsito')
if isempty(options.Group)
No_of_Individuals = (options.SocietySize)^2;
options.Group = ceil(No_of_Individuals/avg_neighbors);
end
end
options = SitoOptimset(defaultopt,options);
funcname = str2func(options.Variant);
% call SITOVALIDATE
[options] = SitoValidate(FitnessFcn,nvars,options);
% call SITOSOLVER
[x,fVal] = feval(funcname,FitnessFcn,nvars,options);