-
Notifications
You must be signed in to change notification settings - Fork 2
/
ga_output.m
56 lines (52 loc) · 2.13 KB
/
ga_output.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
function [state, options,optchanged] = ga_output(options,state,flag)
%GA_OUTPUT Template to write custom OutputFcn for GA.
% [STATE, OPTIONS, OPTCHANGED] = GAOUTPUTFCNTEMPLATE(OPTIONS,STATE,FLAG)
% where OPTIONS is an options structure used by GA.
%
% STATE: A structure containing the following information about the state
% of the optimization:
% Population: Population in the current generation
% Score: Scores of the current population
% Generation: Current generation number
% StartTime: Time when GA started
% StopFlag: String containing the reason for stopping
% Selection: Indices of individuals selected for elite,
% crossover and mutation
% Expectation: Expectation for selection of individuals
% Best: Vector containing the best score in each generation
% LastImprovement: Generation at which the last improvement in
% fitness value occurred
% LastImprovementTime: Time at which last improvement occurred
%
% FLAG: Current state in which OutputFcn is called. Possible values are:
% init: initialization state
% iter: iteration state
% interrupt: intermediate state
% done: final state
%
% STATE: Structure containing information about the state of the
% optimization.
%
% OPTCHANGED: Boolean indicating if the options have changed.
%
% See also PATTERNSEARCH, GA, OPTIMOPTIONS
% Copyright 2004-2015 The MathWorks, Inc.
global history;
optchanged = false;
switch flag
case 'init'
% disp('Starting the algorithm');
history.best = [];
history.mean = [];
history.gen = [];
case {'iter','interrupt'}
% disp('Iterating ...')
% Concatenate current point and objective function
% value with history. x must be a row vector.
%history.best = [history.best; state.Best];
history.mean = [history.mean; mean(state.Score)];
history.gen = [history.gen; state.Generation];
case 'done'
history.best = state.Best';
% disp('Performing final task');
end