[439535]: inst / gaoptimset.m  Maximize  Restore  History

Download this file

142 lines (137 with data), 5.0 kB

  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
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
## Copyright (C) 2008 Luca Favatella <slackydeb@gmail.com>
##
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; see the file COPYING. If not, write to the Free
## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
## -*- texinfo -*-
## @deftypefn{Function File} gaoptimset
## @deftypefnx{Function File} {@var{options} =} gaoptimset
## @deftypefnx{Function File} {@var{options} =} gaoptimset ('@var{param1}', @var{value1}, '@var{param2}', @var{value2}, @dots{})
## Create genetic algorithm options structure.
##
## @strong{Inputs}
## @table @var
## @item param
## Parameter to set. Any unspecified parameters are set to their default values.
## @item value
## Value of @var{param}.
## @end table
##
## @strong{Outputs}
## @table @var
## @item options
## The options structure.
## @end table
##
## @strong{Options}
## @table @code
## @item CreationFcn
## @item CrossoverFcn
## @item CrossoverFraction
## @item EliteCount
## @item FitnessLimit
## @item Generations
## @item MutationFcn
## @item PopInitRange
## @item PopulationSize
## @item SelectionFcn
## @end table
##
## @seealso{ga, gaoptimget}
## @end deftypefn
## Author: Luca Favatella <slackydeb@gmail.com>
## Version: 3.0
function options = gaoptimset (varargin)
if (nargout == 0)
warning ("Dovrei mostrare una lista completa dei parametri con i loro argomenti.");
print_usage ();
elseif (nargout > 1)
print_usage ();
else
if (mod (length (varargin), 2) == 1)
print_usage ();
else
%definisco una struttura default_options con tutti i campi di default
default_options.CreationFcn = @gacreationuniform;
default_options.CrossoverFcn = @crossoverscattered;
default_options.CrossoverFraction = 0.8;
default_options.EliteCount = 2;
default_options.FitnessLimit = -Inf;
default_options.Generations = 100;
default_options.MutationFcn = @mutationsinglepoint;
default_options.PopInitRange = [0; 1];
default_options.PopulationSize = 20;
default_options.SelectionFcn = @selectionroulette;
%setto nella variabile di ritorno options i parametri specificati in ingresso alla funzione
i = 1;
while (length (varargin) >= (i + 1))
switch (varargin{i})
case 'CreationFcn'
options.CreationFcn = varargin{i + 1};
case 'CrossoverFcn'
options.CrossoverFcn = varargin{i + 1};
case 'CrossoverFraction'
options.CrossoverFraction = varargin{i + 1};
case 'EliteCount'
options.EliteCount = varargin{i + 1};
case 'FitnessLimit'
options.FitnessLimit = varargin{i + 1};
case 'Generations'
options.Generations = varargin{i + 1};
case 'MutationFcn'
options.MutationFcn = varargin{i + 1};
case 'PopInitRange'
options.PopInitRange = varargin{i + 1};
case 'PopulationSize'
options.PopulationSize = varargin{i + 1};
case 'SelectionFcn'
options.SelectionFcn = varargin{i + 1};
endswitch
i = i + 2;
endwhile
%setto con i valori di default i parametri non settati
if ((! exist ('options', 'var')) || (! isfield (options, 'CreationFcn')))
options.CreationFcn = default_options.CreationFcn;
endif
if ((! exist ('options', 'var')) || (! isfield (options, 'CrossoverFcn')))
options.CrossoverFcn = default_options.CrossoverFcn;
endif
if ((! exist ('options', 'var')) || (! isfield (options, 'CrossoverFraction')))
options.CrossoverFraction = default_options.CrossoverFraction;
endif
if ((! exist ('options', 'var')) || (! isfield (options, 'EliteCount')))
options.EliteCount = default_options.EliteCount;
endif
if ((! exist ('options', 'var')) || (! isfield (options, 'FitnessLimit')))
options.FitnessLimit = default_options.FitnessLimit;
endif
if ((! exist ('options', 'var')) || (! isfield (options, 'Generations')))
options.Generations = default_options.Generations;
endif
if ((! exist ('options', 'var')) || (! isfield (options, 'MutationFcn')))
options.MutationFcn = default_options.MutationFcn;
endif
if ((! exist ('options', 'var')) || (! isfield (options, 'PopInitRange')))
options.PopInitRange = default_options.PopInitRange;
endif
if ((! exist ('options', 'var')) || (! isfield (options, 'PopulationSize')))
options.PopulationSize = default_options.PopulationSize;
endif
if ((! exist ('options', 'var')) || (! isfield (options, 'SelectionFcn')))
options.SelectionFcn = default_options.SelectionFcn;
endif
endif
endif
endfunction

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks