Upload original Matlab程序设计 course files (part 7)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/DOC/GATBXA1.PS +0 -0
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/DOC/GATBXA2.PS +0 -0
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/BS2RV.M +115 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/CONTENTS.M +54 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/CRTBASE.M +47 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/CRTBP.M +72 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/CRTRP.M +53 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/MIGRATE.M +149 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/MPGA.M +119 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/MUT.M +54 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/MUTATE.M +82 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/MUTBGA.M +113 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/OBJFUN1.M +71 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/OBJHARV.M +78 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RANKING.M +125 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RECDIS.M +52 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RECINT.M +55 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RECLIN.M +57 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RECMUT.M +118 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RECOMBIN.M +69 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/REINS.M +123 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/REP.M +46 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RESPLOT.M +56 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RWS.M +31 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/SCALING.M +52 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/SELECT.M +69 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/SGA.M +69 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/SUS.M +41 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/DEMOGA1.M +118 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/MPGA.M +127 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJBRAN.M +69 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJDOPI.M +107 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJEASO.M +69 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN1.M +71 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN1A.M +68 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN1B.M +66 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN2.M +72 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN6.M +73 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN7.M +68 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN8.M +72 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN9.M +67 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJGOLD.M +71 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJHARV.M +78 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJLINQ.M +86 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJLINQ2.M +105 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJPUSH.M +75 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJSIXH.M +68 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/RESPLOT.M +55 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/SGA.M +67 -3
- matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/SIMDOPI1.M +80 -3
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/DOC/GATBXA1.PS
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/DOC/GATBXA2.PS
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/BS2RV.M
CHANGED
|
@@ -1,3 +1,115 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% BS2RV.m - Binary string to real vector
|
| 2 |
+
%
|
| 3 |
+
% This function decodes binary chromosomes into vectors of reals. The
|
| 4 |
+
% chromosomes are seen as the concatenation of binary strings of given
|
| 5 |
+
% length, and decoded into real numbers in a specified interval using
|
| 6 |
+
% either standard binary or Gray decoding.
|
| 7 |
+
%
|
| 8 |
+
% Syntax: Phen = bs2rv(Chrom,FieldD)
|
| 9 |
+
%
|
| 10 |
+
% Input parameters:
|
| 11 |
+
%
|
| 12 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 13 |
+
% population. Each line corresponds to one
|
| 14 |
+
% individual's concatenated binary string
|
| 15 |
+
% representation. Leftmost bits are MSb and
|
| 16 |
+
% rightmost are LSb.
|
| 17 |
+
%
|
| 18 |
+
% FieldD - Matrix describing the length and how to decode
|
| 19 |
+
% each substring in the chromosome. It has the
|
| 20 |
+
% following structure:
|
| 21 |
+
%
|
| 22 |
+
% [len; (num)
|
| 23 |
+
% lb; (num)
|
| 24 |
+
% ub; (num)
|
| 25 |
+
% code; (0=binary | 1=gray)
|
| 26 |
+
% scale; (0=arithmetic | 1=logarithmic)
|
| 27 |
+
% lbin; (0=excluded | 1=included)
|
| 28 |
+
% ubin]; (0=excluded | 1=included)
|
| 29 |
+
%
|
| 30 |
+
% where
|
| 31 |
+
% len - row vector containing the length of
|
| 32 |
+
% each substring in Chrom. sum(len)
|
| 33 |
+
% should equal the individual length.
|
| 34 |
+
% lb,
|
| 35 |
+
% ub - Lower and upper bounds for each
|
| 36 |
+
% variable.
|
| 37 |
+
% code - binary row vector indicating how each
|
| 38 |
+
% substring is to be decoded.
|
| 39 |
+
% scale - binary row vector indicating where to
|
| 40 |
+
% use arithmetic and/or logarithmic
|
| 41 |
+
% scaling.
|
| 42 |
+
% lbin,
|
| 43 |
+
% ubin - binary row vectors indicating whether
|
| 44 |
+
% or not to include each bound in the
|
| 45 |
+
% representation range
|
| 46 |
+
%
|
| 47 |
+
% Output parameter:
|
| 48 |
+
%
|
| 49 |
+
% Phen - Real matrix containing the population phenotypes.
|
| 50 |
+
|
| 51 |
+
%
|
| 52 |
+
% Author: Carlos Fonseca, Updated: Andrew Chipperfield
|
| 53 |
+
% Date: 08/06/93, Date: 26-Jan-94
|
| 54 |
+
|
| 55 |
+
function Phen = bs2rv(Chrom,FieldD)
|
| 56 |
+
|
| 57 |
+
% Identify the population size (Nind)
|
| 58 |
+
% and the chromosome length (Lind)
|
| 59 |
+
[Nind,Lind] = size(Chrom);
|
| 60 |
+
|
| 61 |
+
% Identify the number of decision variables (Nvar)
|
| 62 |
+
[seven,Nvar] = size(FieldD);
|
| 63 |
+
|
| 64 |
+
if seven ~= 7
|
| 65 |
+
error('FieldD must have 7 rows.');
|
| 66 |
+
end
|
| 67 |
+
|
| 68 |
+
% Get substring properties
|
| 69 |
+
len = FieldD(1,:);
|
| 70 |
+
lb = FieldD(2,:);
|
| 71 |
+
ub = FieldD(3,:);
|
| 72 |
+
code = ~(~FieldD(4,:));
|
| 73 |
+
scale = ~(~FieldD(5,:));
|
| 74 |
+
lin = ~(~FieldD(6,:));
|
| 75 |
+
uin = ~(~FieldD(7,:));
|
| 76 |
+
|
| 77 |
+
% Check substring properties for consistency
|
| 78 |
+
if sum(len) ~= Lind,
|
| 79 |
+
error('Data in FieldD must agree with chromosome length');
|
| 80 |
+
end
|
| 81 |
+
|
| 82 |
+
if ~all(lb(scale).*ub(scale)>0)
|
| 83 |
+
error('Log-scaled variables must not include 0 in their range');
|
| 84 |
+
end
|
| 85 |
+
|
| 86 |
+
% Decode chromosomes
|
| 87 |
+
Phen = zeros(Nind,Nvar);
|
| 88 |
+
|
| 89 |
+
lf = cumsum(len);
|
| 90 |
+
li = cumsum([1 len]);
|
| 91 |
+
Prec = .5 .^ len;
|
| 92 |
+
|
| 93 |
+
logsgn = sign(lb(scale));
|
| 94 |
+
lb(scale) = log( abs(lb(scale)) );
|
| 95 |
+
ub(scale) = log( abs(ub(scale)) );
|
| 96 |
+
delta = ub - lb;
|
| 97 |
+
|
| 98 |
+
Prec = .5 .^ len;
|
| 99 |
+
num = (~lin) .* Prec;
|
| 100 |
+
den = (lin + uin - 1) .* Prec;
|
| 101 |
+
|
| 102 |
+
for i = 1:Nvar,
|
| 103 |
+
idx = li(i):lf(i);
|
| 104 |
+
if code(i) % Gray decoding
|
| 105 |
+
Chrom(:,idx)=rem(cumsum(Chrom(:,idx)')',2);
|
| 106 |
+
end
|
| 107 |
+
Phen(:,i) = Chrom(:,idx) * [ (.5).^(1:len(i))' ];
|
| 108 |
+
Phen(:,i) = lb(i) + delta(i) * (Phen(:,i) + num(i)) ./ (1 - den(i));
|
| 109 |
+
end
|
| 110 |
+
|
| 111 |
+
expand = ones(Nind,1);
|
| 112 |
+
if any(scale)
|
| 113 |
+
Phen(:,scale) = logsgn(expand,:) .* exp(Phen(:,scale));
|
| 114 |
+
end
|
| 115 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/CONTENTS.M
CHANGED
|
@@ -1,3 +1,54 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% Genetic Algorithm Toolbox.
|
| 2 |
+
% Version 1.2 15-Apr-94
|
| 3 |
+
% Department of Automatic Control and Systems Engineering
|
| 4 |
+
% University of Sheffield, England
|
| 5 |
+
%
|
| 6 |
+
% Creating populations
|
| 7 |
+
% crtbase - create a base vector
|
| 8 |
+
% crtbp - create a binary population
|
| 9 |
+
% crtrp - create a real-valued population
|
| 10 |
+
%
|
| 11 |
+
% Fitness assignment
|
| 12 |
+
% ranking - rank-based fitness assignment
|
| 13 |
+
% scaling - proportional fitness-scaling
|
| 14 |
+
%
|
| 15 |
+
% Selection and reinsertion
|
| 16 |
+
% reins - uniform random and fitness-based reinsertion
|
| 17 |
+
% rws - roulette wheel selection
|
| 18 |
+
% select - high-level selection routine
|
| 19 |
+
% sues - stochastic universal sampling
|
| 20 |
+
%
|
| 21 |
+
% Mutation operators
|
| 22 |
+
% mut - discrete mutation
|
| 23 |
+
% mutate - high-level mutation function
|
| 24 |
+
% mutbga - real-value mutation
|
| 25 |
+
%
|
| 26 |
+
% Crossover operators
|
| 27 |
+
% recdis - discrete recombination
|
| 28 |
+
% recint - intermediate recombination
|
| 29 |
+
% reclin - line recombination
|
| 30 |
+
% recmut - line recombination with mutation features
|
| 31 |
+
% recombin - high-level recombination function
|
| 32 |
+
% xovdp - double-point crossover
|
| 33 |
+
% xovdprs - double-point reduced surrogate crossover
|
| 34 |
+
% xovmp - general multi-point crossover
|
| 35 |
+
% xovsh - shuffle crossover
|
| 36 |
+
% xovshrs - shuffle reduced surrogate crossover
|
| 37 |
+
% xovsp - single-point crossover
|
| 38 |
+
% xovsprs - single-point reduced surrogate crossover
|
| 39 |
+
%
|
| 40 |
+
% Subpopulation support
|
| 41 |
+
% migrate - exchange individuals between subpopulations
|
| 42 |
+
%
|
| 43 |
+
%
|
| 44 |
+
% Utility functions
|
| 45 |
+
% bs2rv - binary string to real-value conversion
|
| 46 |
+
% rep - matrix replication
|
| 47 |
+
%
|
| 48 |
+
% Demonstration and other functions
|
| 49 |
+
% mpga - multi-population genetic algorithm demonstration
|
| 50 |
+
% objfun1 - De Jongs first test function (used by sga)
|
| 51 |
+
% objharv - harvest function (used in mpga)
|
| 52 |
+
% resplot - result plotting (used in mpga)
|
| 53 |
+
% sga - simple genetic algorithm demonstration
|
| 54 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/CRTBASE.M
CHANGED
|
@@ -1,3 +1,47 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% CRTBASE.m - Create base vector
|
| 2 |
+
%
|
| 3 |
+
% This function creates a vector containing the base of the loci
|
| 4 |
+
% in a chromosome.
|
| 5 |
+
%
|
| 6 |
+
% Syntax: BaseVec = crtbase(Lind, Base)
|
| 7 |
+
%
|
| 8 |
+
% Input Parameters:
|
| 9 |
+
%
|
| 10 |
+
% Lind - A scalar or vector containing the lengths
|
| 11 |
+
% of the alleles. Sum(Lind) is the length of
|
| 12 |
+
% the corresponding chromosome.
|
| 13 |
+
%
|
| 14 |
+
% Base - A scalar or vector containing the base of
|
| 15 |
+
% the loci contained in the Alleles.
|
| 16 |
+
%
|
| 17 |
+
% Output Parameters:
|
| 18 |
+
%
|
| 19 |
+
% BaseVec - A vector whose elements correspond to the base
|
| 20 |
+
% of the loci of the associated chromosome structure.
|
| 21 |
+
|
| 22 |
+
% Author: Andrew Chipperfield
|
| 23 |
+
% Date: 19-Jan-94
|
| 24 |
+
|
| 25 |
+
function BaseVec = crtbase(Lind, Base)
|
| 26 |
+
|
| 27 |
+
[ml LenL] = size(Lind) ;
|
| 28 |
+
if nargin < 2
|
| 29 |
+
Base = 2 * ones(LenL,1) ; % default to base 2
|
| 30 |
+
end
|
| 31 |
+
[mb LenB] = size(Base) ;
|
| 32 |
+
|
| 33 |
+
% check parameter consistency
|
| 34 |
+
if ml > 1 | mb > 1
|
| 35 |
+
error( 'Lind or Base is not a vector') ;
|
| 36 |
+
elseif (LenL > 1 & LenB > 1 & LenL ~= LenB) | (LenL == 1 & LenB > 1 )
|
| 37 |
+
error( 'Vector dimensions must agree' ) ;
|
| 38 |
+
elseif LenB == 1 & LenL > 1
|
| 39 |
+
Base = Base * ones(LenL,1) ;
|
| 40 |
+
|
| 41 |
+
end
|
| 42 |
+
|
| 43 |
+
BaseVec = [] ;
|
| 44 |
+
for i = 1:LenL
|
| 45 |
+
BaseVec = [BaseVec, Base(i)*ones(Lind(i),1)'];
|
| 46 |
+
end
|
| 47 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/CRTBP.M
CHANGED
|
@@ -1,3 +1,72 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
size
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% CRTP.m - Create an initial population
|
| 2 |
+
%
|
| 3 |
+
% This function creates a binary population of given size and structure.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: [Chrom Lind BaseV] = crtbp(Nind, Lind, Base)
|
| 6 |
+
%
|
| 7 |
+
% Input Parameters:
|
| 8 |
+
%
|
| 9 |
+
% Nind - Either a scalar containing the number of individuals
|
| 10 |
+
% in the new population or a row vector of length two
|
| 11 |
+
% containing the number of individuals and their length.
|
| 12 |
+
%
|
| 13 |
+
% Lind - A scalar containing the length of the individual
|
| 14 |
+
% chromosomes.
|
| 15 |
+
%
|
| 16 |
+
% Base - A scalar containing the base of the chromosome
|
| 17 |
+
% elements or a row vector containing the base(s)
|
| 18 |
+
% of the loci of the chromosomes.
|
| 19 |
+
%
|
| 20 |
+
% Output Parameters:
|
| 21 |
+
%
|
| 22 |
+
% Chrom - A matrix containing the random valued chromosomes
|
| 23 |
+
% row wise.
|
| 24 |
+
%
|
| 25 |
+
% Lind - A scalar containing the length of the chromosome.
|
| 26 |
+
%
|
| 27 |
+
% BaseV - A row vector containing the base of the
|
| 28 |
+
% chromosome loci.
|
| 29 |
+
|
| 30 |
+
% Author: Andrew Chipperfield
|
| 31 |
+
% Date: 19-Jan-94
|
| 32 |
+
|
| 33 |
+
function [Chrom, Lind, BaseV] = crtbp(Nind, Lind, Base)
|
| 34 |
+
nargs = nargin ;
|
| 35 |
+
|
| 36 |
+
% Check parameter consistency
|
| 37 |
+
|
| 38 |
+
if nargs >= 1, [mN, nN] = size(Nind) ; end
|
| 39 |
+
if nargs >= 2, [mL, nL] = size(Lind) ; end
|
| 40 |
+
if nargs == 3, [mB, nB] = size(Base) ; end
|
| 41 |
+
|
| 42 |
+
if nN == 2
|
| 43 |
+
if (nargs == 1)
|
| 44 |
+
Lind = Nind(2) ; Nind = Nind(1) ; BaseV = crtbase(Lind) ;
|
| 45 |
+
elseif (nargs == 2 & nL == 1)
|
| 46 |
+
BaseV = crtbase(Nind(2),Lind) ; Lind = Nind(2) ; Nind = Nind(1) ;
|
| 47 |
+
elseif (nargs == 2 & nL > 1)
|
| 48 |
+
if Lind ~= length(Lind), error('Lind and Base disagree'); end
|
| 49 |
+
BaseV = Lind ; Lind = Nind(2) ; Nind = Nind(1) ;
|
| 50 |
+
end
|
| 51 |
+
elseif nN == 1
|
| 52 |
+
if nargs == 2
|
| 53 |
+
if nL == 1, BaseV = crtbase(Lind) ;
|
| 54 |
+
else, BaseV = Lind ; Lind = nL ; end
|
| 55 |
+
elseif nargs == 3
|
| 56 |
+
if nB == 1, BaseV = crtbase(Lind,Base) ;
|
| 57 |
+
elseif nB ~= Lind, error('Lind and Base disagree') ;
|
| 58 |
+
else BaseV = Base ; end
|
| 59 |
+
end
|
| 60 |
+
else
|
| 61 |
+
error('Input parameters inconsistent') ;
|
| 62 |
+
end
|
| 63 |
+
|
| 64 |
+
% Create a structure of random chromosomes in row wise order, dimensions
|
| 65 |
+
% Nind by Lind. The base of each chromosomes loci is given by the value
|
| 66 |
+
% of the corresponding element of the row vector base.
|
| 67 |
+
|
| 68 |
+
Chrom = floor(rand(Nind,Lind).*BaseV(ones(Nind,1),:)) ;
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
% End of file
|
| 72 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/CRTRP.M
CHANGED
|
@@ -1,3 +1,53 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
size
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% CRTRP.M (CReaTe an initial (Real-value) Population)
|
| 2 |
+
%
|
| 3 |
+
% This function creates a population of given size of random real-values.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: Chrom = crtrp(Nind,FieldDR);
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Nind - A scalar containing the number of individuals in the new
|
| 9 |
+
% population.
|
| 10 |
+
%
|
| 11 |
+
% FieldDR - A matrix of size 2 by number of variables describing the
|
| 12 |
+
% boundaries of each variable. It has the following structure:
|
| 13 |
+
% [lower_bound; (vector with lower bound for each veriable)
|
| 14 |
+
% upper_bound] (vector with upper bound for each veriable)
|
| 15 |
+
% [lower_bound_var_1 lower_bound_var_2 ... lower_bound_var_Nvar;
|
| 16 |
+
% upper_bound_var_1 upper_bound_var_2 ... upper_bound_var_Nvar]
|
| 17 |
+
% example - each individuals consists of 4 variables:
|
| 18 |
+
% FieldDR = [-100 -50 -30 -20; % lower bound
|
| 19 |
+
% 100 50 30 20] % upper bound
|
| 20 |
+
%
|
| 21 |
+
% Output parameter:
|
| 22 |
+
% Chrom - A matrix containing the random valued individuals of the
|
| 23 |
+
% new population of size Nind by number of variables.
|
| 24 |
+
|
| 25 |
+
% Author: Hartmut Pohlheim
|
| 26 |
+
% History: 23.11.93 file created
|
| 27 |
+
% 25.02.94 clean up, check parameter consistency
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
function Chrom = crtrp(Nind,FieldDR);
|
| 31 |
+
|
| 32 |
+
% Check parameter consistency
|
| 33 |
+
if nargin < 2, error('parameter FieldDR missing'); end
|
| 34 |
+
if nargin > 2, nargin = 2; end
|
| 35 |
+
|
| 36 |
+
[mN, nN] = size(Nind);
|
| 37 |
+
[mF, Nvar] = size(FieldDR);
|
| 38 |
+
|
| 39 |
+
if (mN ~= 1 & nN ~= 1), error('Nind has to be a scalar'); end
|
| 40 |
+
if mF ~= 2, error('FieldDR must be a matrix with 2 rows'); end
|
| 41 |
+
|
| 42 |
+
% Compute Matrix with Range of variables and Matrix with Lower value
|
| 43 |
+
Range = rep((FieldDR(2,:)-FieldDR(1,:)),[Nind 1]);
|
| 44 |
+
Lower = rep(FieldDR(1,:), [Nind 1]);
|
| 45 |
+
|
| 46 |
+
% Create initial population
|
| 47 |
+
% Each row contains one individual, the values of each variable uniformly
|
| 48 |
+
% distributed between lower and upper bound (given by FieldDR)
|
| 49 |
+
Chrom = rand(Nind,Nvar) .* Range + Lower;
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
% End of function
|
| 53 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/MIGRATE.M
CHANGED
|
@@ -1,3 +1,149 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% MIGRATE.M (MIGRATion of individuals between subpopulations)
|
| 2 |
+
%
|
| 3 |
+
% This function performs migration of individuals.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: [Chrom, ObjV] = migrate(Chrom, SUBPOP, MigOpt, ObjV)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the individuals of the current
|
| 9 |
+
% population. Each row corresponds to one individual.
|
| 10 |
+
% SUBPOP - Number of subpopulations
|
| 11 |
+
% MigOpt - (optional) Vector containing migration parameters
|
| 12 |
+
% MigOpt(1): MIGR - Rate of individuals to be migrated per
|
| 13 |
+
% subpopulation (% of subpopulation)
|
| 14 |
+
% if omitted or NaN, 0.2 (20%) is assumed
|
| 15 |
+
% MigOpt(2): Select - number indicating the selection method
|
| 16 |
+
% of replacing individuals
|
| 17 |
+
% 0 - uniform selection
|
| 18 |
+
% 1 - fitness-based selection (replace worst
|
| 19 |
+
% individuals)
|
| 20 |
+
% if omitted or NaN, 0 is assumed
|
| 21 |
+
% MigOpt(3): Structure - number indicating the structure
|
| 22 |
+
% of the subpopulations for migration
|
| 23 |
+
% 0 - net structure (unconstrained migration)
|
| 24 |
+
% 1 - neighbourhood structure
|
| 25 |
+
% 2 - ring structure
|
| 26 |
+
% if omitted or NaN, 0 is assumed
|
| 27 |
+
% ObjV - (optional) Column vector containing the objective values
|
| 28 |
+
% of the individuals in the current population, needed for
|
| 29 |
+
% fitness-based migration, this saves the
|
| 30 |
+
% recalculation of objective values for population.
|
| 31 |
+
%
|
| 32 |
+
% Output parameters:
|
| 33 |
+
% Chrom - Matrix containing the individuals of the current
|
| 34 |
+
% population after migration.
|
| 35 |
+
% ObjV - if ObjV is input parameter, than column vector containing
|
| 36 |
+
% the objective values of the individuals of the current
|
| 37 |
+
% generation after migration.
|
| 38 |
+
|
| 39 |
+
% Author: Hartmut Pohlheim
|
| 40 |
+
% History: 16.02.94 file created
|
| 41 |
+
% 18.02.94 comments at the beginning added
|
| 42 |
+
% exchange of ObjV too
|
| 43 |
+
% 25.02.94 clean up
|
| 44 |
+
% 26.02.94 ObjV optional input parameter
|
| 45 |
+
% Select and Structure added, parameter reordered
|
| 46 |
+
% 17.03.94 renamed to migrate.m, more parameter checks
|
| 47 |
+
|
| 48 |
+
function [Chrom, ObjV] = migrate(Chrom, SUBPOP, MigOpt, ObjV);
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
% Check parameter consistency
|
| 52 |
+
if nargin < 2, error('Input parameter SUBPOP missing'); end
|
| 53 |
+
if (nargout == 2 & nargin < 4), error('Input parameter ObjV missing'); end
|
| 54 |
+
|
| 55 |
+
[Nind, Nvar] = size(Chrom);
|
| 56 |
+
if length(SUBPOP) ~= 1, error('SUBPOP must be a scalar'); end
|
| 57 |
+
if SUBPOP == 1, return; end
|
| 58 |
+
if (Nind/SUBPOP) ~= fix(Nind/SUBPOP), error('Chrom and SUBPOP disagree'); end
|
| 59 |
+
NIND = Nind/SUBPOP; % Compute number of individuals per subpopulation
|
| 60 |
+
|
| 61 |
+
if nargin > 3,
|
| 62 |
+
[mO, nO] = size(ObjV);
|
| 63 |
+
if nO ~= 1, error('ObjV must be a column vector'); end
|
| 64 |
+
if Nind ~= mO, error('Chrom and ObjV disagree'); end
|
| 65 |
+
IsObjV = 1;
|
| 66 |
+
else IsObjV = 0; ObjV = [];
|
| 67 |
+
end
|
| 68 |
+
|
| 69 |
+
if nargin < 3, MIGR = 0.2; Select = 0; Structure = 0; end
|
| 70 |
+
if nargin > 2,
|
| 71 |
+
if isempty(MigOpt), MIGR = 0.2; Select = 0; Structure = 0;
|
| 72 |
+
elseif isnan(MigOpt), MIGR = 0.2; Select = 0; Structure = 0;
|
| 73 |
+
else
|
| 74 |
+
MIGR = NaN; Select = NaN; Structure = NaN;
|
| 75 |
+
if length(MigOpt) > 3, error('Parameter MigOpt is too long'); end
|
| 76 |
+
if length(MigOpt) >= 1, MIGR = MigOpt(1); end
|
| 77 |
+
if length(MigOpt) >= 2, Select = MigOpt(2); end
|
| 78 |
+
if length(MigOpt) >= 3, Structure = MigOpt(3); end
|
| 79 |
+
if isnan(MIGR), MIGR =0.2; end
|
| 80 |
+
if isnan(Select), Select = 0; end
|
| 81 |
+
if isnan(Structure), Structure = 0; end
|
| 82 |
+
end
|
| 83 |
+
end
|
| 84 |
+
|
| 85 |
+
if (MIGR < 0 | MIGR > 1), error('Parameter for migration rate must be a scalar in [0 1]'); end
|
| 86 |
+
if (Select ~= 0 & Select ~= 1), error('Parameter for selection method must be 0 or 1'); end
|
| 87 |
+
if (Structure < 0 | Structure > 2), error ('Parameter for structure must be 0, 1 or 2'); end
|
| 88 |
+
if (Select == 1 & IsObjV == 0), error('ObjV for fitness-based migration needed');end
|
| 89 |
+
|
| 90 |
+
if MIGR == 0, return; end
|
| 91 |
+
MigTeil = max(floor(NIND * MIGR), 1); % Number of individuals to migrate
|
| 92 |
+
|
| 93 |
+
% Perform migration between subpopulations --> create a matrix for migration
|
| 94 |
+
% in every subpopulation from best individuals of the other subpopulations
|
| 95 |
+
|
| 96 |
+
% Clear storing matrices
|
| 97 |
+
ChromMigAll = [];
|
| 98 |
+
if IsObjV == 1, ObjVAll = []; end
|
| 99 |
+
|
| 100 |
+
% Create matrix with best/uniform individuals of all subpopulations
|
| 101 |
+
for irun = 1:SUBPOP
|
| 102 |
+
% sort ObjV of actual subpopulation
|
| 103 |
+
if Select == 1, % fitness-based selection
|
| 104 |
+
[Dummy, IndMigSo]=sort(ObjV((irun-1)*NIND+1:irun*NIND));
|
| 105 |
+
else % if Select == 0 % uniform selection
|
| 106 |
+
[Dummy, IndMigSo]=sort(rand(NIND, 1));
|
| 107 |
+
end
|
| 108 |
+
% take MigTeil (best) individuals, copy individuals and objective values
|
| 109 |
+
IndMigTeil=IndMigSo(1:MigTeil)+(irun-1)*NIND;
|
| 110 |
+
ChromMigAll = [ChromMigAll; Chrom(IndMigTeil,:)];
|
| 111 |
+
if IsObjV == 1, ObjVAll = [ObjVAll; ObjV(IndMigTeil,:)]; end
|
| 112 |
+
end
|
| 113 |
+
|
| 114 |
+
% perform migration
|
| 115 |
+
for irun = 1:SUBPOP
|
| 116 |
+
ChromMig = ChromMigAll;
|
| 117 |
+
if IsObjV == 1, ObjVMig = ObjVAll; end
|
| 118 |
+
if Structure == 1, % neighbourhood
|
| 119 |
+
% select individuals of neighbourhood subpopulations for ChromMig and ObjVMig
|
| 120 |
+
popnum = [SUBPOP 1:SUBPOP 1];
|
| 121 |
+
ins1 = popnum(irun); ins2 = popnum(irun + 2);
|
| 122 |
+
InsRows = [(ins1-1)*MigTeil+1:ins1*MigTeil (ins2-1)*MigTeil+1:ins2*MigTeil];
|
| 123 |
+
ChromMig = ChromMig(InsRows,:);
|
| 124 |
+
if IsObjV == 1, ObjVMig = ObjVMig(InsRows,:); end
|
| 125 |
+
elseif Structure == 2, % ring
|
| 126 |
+
% select individuals of actual-1 subpopulation for ChromMig and ObjVMig
|
| 127 |
+
popnum = [SUBPOP 1:SUBPOP 1];
|
| 128 |
+
ins1 = popnum(irun);
|
| 129 |
+
InsRows = (ins1-1)*MigTeil+1:ins1*MigTeil;
|
| 130 |
+
ChromMig = ChromMig(InsRows,:);
|
| 131 |
+
if IsObjV == 1, ObjVMig = ObjVMig(InsRows,:); end
|
| 132 |
+
else % if Structure == 0, % complete net
|
| 133 |
+
% delete individuals of actual subpopulation from ChromMig and ObjVMig
|
| 134 |
+
DelRows = (irun-1)*MigTeil+1:irun*MigTeil;
|
| 135 |
+
ChromMig(DelRows,:) = [];
|
| 136 |
+
if IsObjV == 1, ObjVMig(DelRows,:) = []; end
|
| 137 |
+
end
|
| 138 |
+
% Create an index from a sorted vector with random numbers
|
| 139 |
+
[Dummy,IndMigRa]=sort(rand(size(ChromMig,1),1));
|
| 140 |
+
% Take MigTeil numbers from the random vector
|
| 141 |
+
IndMigN=IndMigRa((1:MigTeil)');
|
| 142 |
+
% copy MigTeil individuals into Chrom and ObjV
|
| 143 |
+
Chrom((1:MigTeil)+(irun-1)*NIND,:) = ChromMig(IndMigN,:);
|
| 144 |
+
if IsObjV == 1, ObjV((1:MigTeil)+(irun-1)*NIND,:) = ObjVMig(IndMigN,:); end
|
| 145 |
+
end
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
% End of function
|
| 149 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/MPGA.M
CHANGED
|
@@ -1,3 +1,119 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% mpga multi population genetic algorithm
|
| 2 |
+
%
|
| 3 |
+
% This script implements the Multi Population Genetic Algorithm.
|
| 4 |
+
% A real-valued representation of the individuals is used.
|
| 5 |
+
%
|
| 6 |
+
|
| 7 |
+
% Author: Andrew Chipperfield
|
| 8 |
+
% History: 30-Mar-94 file created
|
| 9 |
+
|
| 10 |
+
NVAR = 20; % No. of decision variables (control steps)
|
| 11 |
+
RANGE = [0;200]; % Bounds on decision variables
|
| 12 |
+
|
| 13 |
+
% Set field descriptor
|
| 14 |
+
FieldD = rep(RANGE,[1,NVAR]);
|
| 15 |
+
|
| 16 |
+
% Define GA Parameters
|
| 17 |
+
GGAP = .8; % Generation gap, how many new individuals are created
|
| 18 |
+
XOVR = 1; % Crossover rate
|
| 19 |
+
MUTR = 1/NVAR; % Mutation rate depending on NVAR
|
| 20 |
+
MAXGEN = 1200; % Maximum number of generations
|
| 21 |
+
TERMEXACT = 1e-4; % Value for termination if minimum reached
|
| 22 |
+
INSR = .9; % Insertion rate, how many of the offspring are inserted
|
| 23 |
+
SUBPOP = 8; % Number of subpopulations
|
| 24 |
+
MIGR = 0.2; % Migration rate between subpopulations
|
| 25 |
+
MIGGEN = 20; % Number of generations between migration
|
| 26 |
+
NIND = 20; % Number of individuals per subpopulation
|
| 27 |
+
|
| 28 |
+
% Specify other routines as strings
|
| 29 |
+
SEL_F = 'sus'; % Name of selection function
|
| 30 |
+
XOV_F = 'recdis'; % Name of recombination function for individuals
|
| 31 |
+
MUT_F = 'mutbga'; % Name of mutation function
|
| 32 |
+
OBJ_F = 'objharv'; % Name of function for objective values
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
% Get value of minimum, defined in objective function
|
| 36 |
+
GlobalMin = feval(OBJ_F,[],3);
|
| 37 |
+
|
| 38 |
+
% Get title of objective function, defined in objective function
|
| 39 |
+
FigTitle = [feval(OBJ_F,[],2) ' (' int2str(SUBPOP) ':' int2str(MAXGEN) ') '];
|
| 40 |
+
|
| 41 |
+
% Clear Best and storing matrix
|
| 42 |
+
% Initialise Matrix for storing best results
|
| 43 |
+
Best = NaN * ones(MAXGEN,3);
|
| 44 |
+
Best(:,3) = zeros(size(Best,1),1);
|
| 45 |
+
% Matrix for storing best individuals
|
| 46 |
+
IndAll = [];
|
| 47 |
+
|
| 48 |
+
% Create real population
|
| 49 |
+
Chrom = crtrp(SUBPOP*NIND,FieldD);
|
| 50 |
+
|
| 51 |
+
% reset count variables
|
| 52 |
+
gen = 0;
|
| 53 |
+
|
| 54 |
+
% Calculate objective function for population
|
| 55 |
+
ObjV = feval(OBJ_F,Chrom);
|
| 56 |
+
% count number of objective function evaluations
|
| 57 |
+
Best(gen+1,3) = Best(gen+1,3) + NIND;
|
| 58 |
+
|
| 59 |
+
% Generational loop
|
| 60 |
+
while gen < MAXGEN,
|
| 61 |
+
|
| 62 |
+
% Save the best and average objective values and the best individual
|
| 63 |
+
[Best(gen+1,1),ix] = min(ObjV);
|
| 64 |
+
Best(gen+1,2) = mean(ObjV);
|
| 65 |
+
IndAll = [IndAll; Chrom(ix,:)];
|
| 66 |
+
|
| 67 |
+
% Fitness assignment to whole population
|
| 68 |
+
FitnV = ranking(ObjV,2 ,SUBPOP);
|
| 69 |
+
|
| 70 |
+
% Select individuals from population
|
| 71 |
+
SelCh = select(SEL_F, Chrom, FitnV, GGAP, SUBPOP);
|
| 72 |
+
|
| 73 |
+
% Recombine selected individuals
|
| 74 |
+
SelCh=recombin(XOV_F, SelCh, XOVR, SUBPOP);
|
| 75 |
+
|
| 76 |
+
% Mutate offspring
|
| 77 |
+
SelCh=mutate(MUT_F, SelCh, FieldD, [MUTR], SUBPOP);
|
| 78 |
+
|
| 79 |
+
% Calculate objective function for offsprings
|
| 80 |
+
ObjVOff = feval(OBJ_F,SelCh);
|
| 81 |
+
Best(gen+1,3) = Best(gen+1,3) + size(SelCh,1);
|
| 82 |
+
|
| 83 |
+
% Insert best offspring in population replacing worst parents
|
| 84 |
+
[Chrom, ObjV] = reins(Chrom, SelCh, SUBPOP, [1 INSR], ObjV, ObjVOff);
|
| 85 |
+
|
| 86 |
+
gen=gen+1;
|
| 87 |
+
|
| 88 |
+
% Plot some results, rename title of figure for graphic output
|
| 89 |
+
if ((rem(gen,20) == 1) | (rem(gen,MAXGEN) == 0)),
|
| 90 |
+
set(gcf,'Name',[FigTitle ' in ' int2str(gen)]);
|
| 91 |
+
resplot(Chrom(1:2:size(Chrom,1),:),...
|
| 92 |
+
IndAll(max(1,gen-39):size(IndAll,1),:),...
|
| 93 |
+
[ObjV; GlobalMin], Best(max(1,gen-19):gen,[1 2]), gen);
|
| 94 |
+
end
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
% migrate individuals between subpopulations
|
| 98 |
+
if (rem(gen,MIGGEN) == 0)
|
| 99 |
+
[Chrom, ObjV] = migrate(Chrom, SUBPOP, [MIGR, 1, 0], ObjV);
|
| 100 |
+
end
|
| 101 |
+
|
| 102 |
+
end
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
% Results
|
| 106 |
+
% add number of objective function evaluations
|
| 107 |
+
Results = cumsum(Best(1:gen,3));
|
| 108 |
+
% number of function evaluation, mean and best results
|
| 109 |
+
Results = [Results Best(1:gen,2) Best(1:gen,1)];
|
| 110 |
+
|
| 111 |
+
% Plot Results and show best individuals => optimum
|
| 112 |
+
figure('Name',['Results of ' FigTitle]);
|
| 113 |
+
subplot(2,1,1), plot(Results(:,1),Results(:,2),'-',Results(:,1),Results(:,3),':');
|
| 114 |
+
subplot(2,1,2), plot(IndAll(gen-4:gen,:)');
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
% End of script
|
| 118 |
+
|
| 119 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/MUT.M
CHANGED
|
@@ -1,3 +1,54 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% MUT.m
|
| 2 |
+
%
|
| 3 |
+
% This function takes the representation of the current population,
|
| 4 |
+
% mutates each element with given probability and returns the resulting
|
| 5 |
+
% population.
|
| 6 |
+
%
|
| 7 |
+
% Syntax: NewChrom = mut(OldChrom,Pm,BaseV)
|
| 8 |
+
%
|
| 9 |
+
% Input parameters:
|
| 10 |
+
%
|
| 11 |
+
% OldChrom - A matrix containing the chromosomes of the
|
| 12 |
+
% current population. Each row corresponds to
|
| 13 |
+
% an individuals string representation.
|
| 14 |
+
%
|
| 15 |
+
% Pm - Mutation probability (scalar). Default value
|
| 16 |
+
% of Pm = 0.7/Lind, where Lind is the chromosome
|
| 17 |
+
% length is assumed if omitted.
|
| 18 |
+
%
|
| 19 |
+
% BaseV - Optional row vector of the same length as the
|
| 20 |
+
% chromosome structure defining the base of the
|
| 21 |
+
% individual elements of the chromosome. Binary
|
| 22 |
+
% representation is assumed if omitted.
|
| 23 |
+
%
|
| 24 |
+
% Output parameter:
|
| 25 |
+
%
|
| 26 |
+
% NewChrom - A Matrix containing a mutated version of
|
| 27 |
+
% OldChrom.
|
| 28 |
+
%
|
| 29 |
+
|
| 30 |
+
% Author: Andrew Chipperfield
|
| 31 |
+
% Date: 25-Jan-94
|
| 32 |
+
|
| 33 |
+
function NewChrom = mut(OldChrom,Pm,BaseV)
|
| 34 |
+
|
| 35 |
+
% get population size (Nind) and chromosome length (Lind)
|
| 36 |
+
[Nind, Lind] = size(OldChrom) ;
|
| 37 |
+
|
| 38 |
+
% check input parameters
|
| 39 |
+
if nargin < 2, Pm = 0.7/Lind ; end
|
| 40 |
+
if isnan(Pm), Pm = 0.7/Lind; end
|
| 41 |
+
|
| 42 |
+
if (nargin < 3), BaseV = crtbase(Lind); end
|
| 43 |
+
if (isnan(BaseV)), BaseV = crtbase(Lind); end
|
| 44 |
+
if (isempty(BaseV)), BaseV = crtbase(Lind); end
|
| 45 |
+
|
| 46 |
+
if (nargin == 3) & (Lind ~= length(BaseV))
|
| 47 |
+
error('OldChrom and BaseV are incompatible'), end
|
| 48 |
+
|
| 49 |
+
% create mutation mask matrix
|
| 50 |
+
BaseM = BaseV(ones(Nind,1),:) ;
|
| 51 |
+
|
| 52 |
+
% perform mutation on chromosome structure
|
| 53 |
+
NewChrom = rem(OldChrom+(rand(Nind,Lind)<Pm).*ceil(rand(Nind,Lind).*(BaseM-1)),BaseM);
|
| 54 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/MUTATE.M
CHANGED
|
@@ -1,3 +1,82 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% MUTATE.M (MUTATion high-level function)
|
| 2 |
+
%
|
| 3 |
+
% This function takes a matrix OldChrom containing the
|
| 4 |
+
% representation of the individuals in the current population,
|
| 5 |
+
% mutates the individuals and returns the resulting population.
|
| 6 |
+
%
|
| 7 |
+
% The function handles multiple populations and calls the low-level
|
| 8 |
+
% mutation function for the actual mutation process.
|
| 9 |
+
%
|
| 10 |
+
% Syntax: NewChrom = mutate(MUT_F, OldChrom, FieldDR, MutOpt, SUBPOP)
|
| 11 |
+
%
|
| 12 |
+
% Input parameter:
|
| 13 |
+
% MUT_F - String containing the name of the mutation function
|
| 14 |
+
% OldChrom - Matrix containing the chromosomes of the old
|
| 15 |
+
% population. Each line corresponds to one individual.
|
| 16 |
+
% FieldDR - Matrix describing the boundaries of each variable
|
| 17 |
+
% (real-values) or defining the base of the variables of
|
| 18 |
+
% each individual (discrete values).
|
| 19 |
+
% optional for (binary) discrete values
|
| 20 |
+
% MutOpt - (optional) Vector containing mutation rate and shrink value
|
| 21 |
+
% if omitted or NaN, MutOpt = NaN is assumed
|
| 22 |
+
% MutOpt(1): MutR - number containing the mutation rate -
|
| 23 |
+
% probability for mutation of a variable
|
| 24 |
+
% MutOpt(2): MutShrink - (optional) number for shrinking the
|
| 25 |
+
% mutation range in the range [0, 1], possibility to
|
| 26 |
+
% shrink the range of the mutation depending on,
|
| 27 |
+
% for instance actual generation (only for
|
| 28 |
+
% real-values).
|
| 29 |
+
% SUBPOP - (optional) Number of subpopulations
|
| 30 |
+
% if omitted or NaN, 1 subpopulation is assumed
|
| 31 |
+
%
|
| 32 |
+
% Output parameter:
|
| 33 |
+
% NewChrom - Matrix containing the chromosomes of the population
|
| 34 |
+
% after mutation in the same format as OldChrom.
|
| 35 |
+
|
| 36 |
+
% Author: Hartmut Pohlheim
|
| 37 |
+
% History: 19.03.94 file created
|
| 38 |
+
|
| 39 |
+
function NewChrom = mutate(MUT_F, OldChrom, FieldDR, MutOpt, SUBPOP);
|
| 40 |
+
|
| 41 |
+
% Check parameter consistency
|
| 42 |
+
if nargin < 2, error('Not enough input parameter'); end
|
| 43 |
+
|
| 44 |
+
% Identify the population size (Nind) and the number of variables (Nvar)
|
| 45 |
+
[Nind,Nvar] = size(OldChrom);
|
| 46 |
+
|
| 47 |
+
if nargin < 3, IsDiscret = 1; FieldDR = [];
|
| 48 |
+
elseif isempty(FieldDR), IsDiscret = 1; FieldDR = [];
|
| 49 |
+
elseif isnan(FieldDR), IsDiscret = 1; FieldDR = [];
|
| 50 |
+
else
|
| 51 |
+
[mF, nF] = size(FieldDR);
|
| 52 |
+
if nF ~= Nvar, error('FieldDR and OldChrom disagree'); end
|
| 53 |
+
if mF == 2, IsDiscret = 0;
|
| 54 |
+
elseif mF == 1, IsDiscret = 1;
|
| 55 |
+
else error('FieldDR must be a matrix with 1 or 2 rows'); end
|
| 56 |
+
end
|
| 57 |
+
|
| 58 |
+
if nargin < 4, MutOpt = NaN; end
|
| 59 |
+
|
| 60 |
+
if nargin < 5, SUBPOP = 1;
|
| 61 |
+
elseif nargin > 4,
|
| 62 |
+
if isempty(SUBPOP), SUBPOP = 1;
|
| 63 |
+
elseif isnan(SUBPOP), SUBPOP = 1;
|
| 64 |
+
elseif length(SUBPOP) ~= 1, error('SUBPOP must be a scalar'); end
|
| 65 |
+
end
|
| 66 |
+
|
| 67 |
+
if (Nind/SUBPOP) ~= fix(Nind/SUBPOP), error('OldChrom and SUBPOP disagree'); end
|
| 68 |
+
Nind = Nind/SUBPOP; % Compute number of individuals per subpopulation
|
| 69 |
+
|
| 70 |
+
% Select individuals of one subpopulation and call low level function
|
| 71 |
+
NewChrom = [];
|
| 72 |
+
for irun = 1:SUBPOP,
|
| 73 |
+
ChromSub = OldChrom((irun-1)*Nind+1:irun*Nind,:);
|
| 74 |
+
if IsDiscret == 1, NewChromSub = feval(MUT_F, ChromSub, MutOpt, FieldDR);
|
| 75 |
+
elseif IsDiscret == 0, NewChromSub = feval(MUT_F, ChromSub, FieldDR, MutOpt); end
|
| 76 |
+
NewChrom=[NewChrom; NewChromSub];
|
| 77 |
+
end
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
% End of function
|
| 81 |
+
|
| 82 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/MUTBGA.M
CHANGED
|
@@ -1,3 +1,113 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% MUTBGA.M (real-value MUTation like Breeder Genetic Algorithm)
|
| 2 |
+
%
|
| 3 |
+
% This function takes a matrix OldChrom containing the real
|
| 4 |
+
% representation of the individuals in the current population,
|
| 5 |
+
% mutates the individuals with probability MutR and returns
|
| 6 |
+
% the resulting population.
|
| 7 |
+
%
|
| 8 |
+
% This function implements the mutation operator of the Breeder Genetic
|
| 9 |
+
% Algorithm. (Muehlenbein et. al.)
|
| 10 |
+
%
|
| 11 |
+
% Syntax: NewChrom = mutbga(OldChrom, FieldDR, MutOpt)
|
| 12 |
+
%
|
| 13 |
+
% Input parameter:
|
| 14 |
+
% OldChrom - Matrix containing the chromosomes of the old
|
| 15 |
+
% population. Each line corresponds to one individual.
|
| 16 |
+
% FieldDR - Matrix describing the boundaries of each variable.
|
| 17 |
+
% MutOpt - (optional) Vector containing mutation rate and shrink value
|
| 18 |
+
% MutOpt(1): MutR - number containing the mutation rate -
|
| 19 |
+
% probability for mutation of a variable
|
| 20 |
+
% if omitted or NaN, MutR = 1/variables per individual
|
| 21 |
+
% is assumed
|
| 22 |
+
% MutOpt(2): MutShrink - (optional) number for shrinking the
|
| 23 |
+
% mutation range in the range [0 1], possibility to
|
| 24 |
+
% shrink the range of the mutation depending on,
|
| 25 |
+
% for instance actual generation.
|
| 26 |
+
% if omitted or NaN, MutShrink = 1 is assumed
|
| 27 |
+
%
|
| 28 |
+
% Output parameter:
|
| 29 |
+
% NewChrom - Matrix containing the chromosomes of the population
|
| 30 |
+
% after mutation in the same format as OldChrom.
|
| 31 |
+
|
| 32 |
+
% Author: Hartmut Pohlheim
|
| 33 |
+
% History: 23.11.93 file created
|
| 34 |
+
% 24.11.93 function optimised (for,for-loop to for-loop)
|
| 35 |
+
% mutation rate included
|
| 36 |
+
% style improved
|
| 37 |
+
% 06.12.93 change of function name
|
| 38 |
+
% check of boundaries after mutation out of loop
|
| 39 |
+
% 16.12.93 NewMutMat and OldMutMat included for compability
|
| 40 |
+
% 16.02.94 preparation for multi-subpopulations at once
|
| 41 |
+
% 25.02.94 NewMutMat and OldMutMat removed (now in mutran10.m)
|
| 42 |
+
% clean up
|
| 43 |
+
% change of function name in mutbga.m
|
| 44 |
+
% 03.03.94 Lower and Upper directly used (less memory)
|
| 45 |
+
% 19.03.94 multipopulation support removed
|
| 46 |
+
% more parameter checks
|
| 47 |
+
% 27.03.94 Delta exact calculated, for loop saved
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
function NewChrom = mutbga(OldChrom, FieldDR, MutOpt);
|
| 51 |
+
|
| 52 |
+
% Check parameter consistency
|
| 53 |
+
if nargin < 2, error('Not enough input parameter'); end
|
| 54 |
+
|
| 55 |
+
% Identify the population size (Nind) and the number of variables (Nvar)
|
| 56 |
+
[Nind,Nvar] = size(OldChrom);
|
| 57 |
+
|
| 58 |
+
[mF, nF] = size(FieldDR);
|
| 59 |
+
if mF ~= 2, error('FieldDR must be a matrix with 2 rows'); end
|
| 60 |
+
if Nvar ~= nF, error('FieldDR and OldChrom disagree'); end
|
| 61 |
+
|
| 62 |
+
if nargin < 3, MutR = 1/Nvar; MutShrink = 1;
|
| 63 |
+
elseif isempty(MutOpt), MutR = 1/Nvar; MutShrink = 1;
|
| 64 |
+
elseif isnan(MutOpt), MutR = 1/Nvar; MutShrink = 1;
|
| 65 |
+
else
|
| 66 |
+
if length(MutOpt) == 1, MutR = MutOpt; MutShrink = 1;
|
| 67 |
+
elseif length(MutOpt) == 2, MutR = MutOpt(1); MutShrink = MutOpt(2);
|
| 68 |
+
else, error(' Too many parameter in MutOpt'); end
|
| 69 |
+
end
|
| 70 |
+
|
| 71 |
+
if isempty(MutR), MutR = 1/Nvar;
|
| 72 |
+
elseif isnan(MutR), MutR = 1/Nvar;
|
| 73 |
+
elseif length(MutR) ~= 1, error('Parameter for mutation rate must be a scalar');
|
| 74 |
+
elseif (MutR < 0 | MutR > 1), error('Parameter for mutation rate must be a scalar in [0, 1]'); end
|
| 75 |
+
|
| 76 |
+
if isempty(MutShrink), MutShrink = 1;
|
| 77 |
+
elseif isnan(MutShrink), MutShrink = 1;
|
| 78 |
+
elseif length(MutShrink) ~= 1, error('Parameter for shrinking mutation range must be a scalar');
|
| 79 |
+
elseif (MutShrink < 0 | MutShrink > 1),
|
| 80 |
+
error('Parameter for shrinking mutation range must be a scalar in [0, 1]');
|
| 81 |
+
end
|
| 82 |
+
|
| 83 |
+
% the variables are mutated with probability MutR
|
| 84 |
+
% NewChrom = OldChrom (+ or -) * Range * MutShrink * Delta
|
| 85 |
+
% Range = 0.5 * (upperbound - lowerbound)
|
| 86 |
+
% Delta = Sum(Alpha_i * 2^-i) from 0 to ACCUR; Alpha_i = rand(ACCUR,1) < 1/ACCUR
|
| 87 |
+
|
| 88 |
+
% Matrix with range values for every variable
|
| 89 |
+
Range = rep(0.5 * MutShrink *(FieldDR(2,:)-FieldDR(1,:)),[Nind 1]);
|
| 90 |
+
|
| 91 |
+
% zeros and ones for mutate or not this variable, together with Range
|
| 92 |
+
Range = Range .* (rand(Nind,Nvar) < MutR);
|
| 93 |
+
|
| 94 |
+
% compute, if + or - sign
|
| 95 |
+
Range = Range .* (1 - 2 * (rand(Nind,Nvar) < 0.5));
|
| 96 |
+
|
| 97 |
+
% used for later computing, here only ones computed
|
| 98 |
+
ACCUR = 20;
|
| 99 |
+
Vect = 2 .^ (-(0:(ACCUR-1))');
|
| 100 |
+
Delta = (rand(Nind,ACCUR) < 1/ACCUR) * Vect;
|
| 101 |
+
Delta = rep(Delta, [1 Nvar]);
|
| 102 |
+
|
| 103 |
+
% perform mutation
|
| 104 |
+
NewChrom = OldChrom + Range .* Delta;
|
| 105 |
+
|
| 106 |
+
% Ensure variables boundaries, compare with lower and upper boundaries
|
| 107 |
+
NewChrom = max(rep(FieldDR(1,:),[Nind 1]), NewChrom);
|
| 108 |
+
NewChrom = min(rep(FieldDR(2,:),[Nind 1]), NewChrom);
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
% End of function
|
| 112 |
+
|
| 113 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/OBJFUN1.M
CHANGED
|
@@ -1,3 +1,71 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJFUN1.M (OBJective function for De Jong's FUNction 1)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the De Jong function 1.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objfun1(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then special values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 26.11.93 file created
|
| 28 |
+
% 27.11.93 text of title and switch added
|
| 29 |
+
% 30.11.93 show Dim in figure title
|
| 30 |
+
% 16.12.93 switch == 3, return value of global minimum
|
| 31 |
+
% 01.03.94 name changed in obj*
|
| 32 |
+
|
| 33 |
+
function ObjVal = objfun1(Chrom,switch);
|
| 34 |
+
|
| 35 |
+
% Dimension of objective function
|
| 36 |
+
Dim = 20;
|
| 37 |
+
|
| 38 |
+
% Compute population parameters
|
| 39 |
+
[Nind,Nvar] = size(Chrom);
|
| 40 |
+
|
| 41 |
+
% Check size of Chrom and do the appropriate thing
|
| 42 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 43 |
+
if Nind == 0
|
| 44 |
+
% return text of title for graphic output
|
| 45 |
+
if switch == 2
|
| 46 |
+
ObjVal = ['DE JONG function 1-' int2str(Dim)];
|
| 47 |
+
% return value of global minimum
|
| 48 |
+
elseif switch == 3
|
| 49 |
+
ObjVal = 0;
|
| 50 |
+
% define size of boundary-matrix and values
|
| 51 |
+
else
|
| 52 |
+
% lower and upper bound, identical for all n variables
|
| 53 |
+
ObjVal = 100*[-5.12; 5.12];
|
| 54 |
+
ObjVal = ObjVal(1:2,ones(Dim,1));
|
| 55 |
+
end
|
| 56 |
+
% if Dim variables, compute values of function
|
| 57 |
+
elseif Nvar == Dim
|
| 58 |
+
% function 1, sum of xi^2 for i = 1:Dim (Dim=30)
|
| 59 |
+
% n = Dim, -5.12 <= xi <= 5.12
|
| 60 |
+
% global minimum at (xi)=(0) ; fmin=0
|
| 61 |
+
ObjVal = sum((Chrom .* Chrom)')';
|
| 62 |
+
% ObjVal = diag(Chrom * Chrom'); % both lines produce the same
|
| 63 |
+
% otherwise error, wrong format of Chrom
|
| 64 |
+
else
|
| 65 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 66 |
+
end
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
% End of function
|
| 70 |
+
|
| 71 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/OBJHARV.M
CHANGED
|
@@ -1,3 +1,78 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJHARV.M (OBJective function for HARVest problem)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the HARVEST PROBLEM.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objharv(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then special values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 18.02.94 file created (copy of vallinq.m)
|
| 28 |
+
% 01.03.94 name changed in obj*
|
| 29 |
+
|
| 30 |
+
function ObjVal = objharv(Chrom,switch);
|
| 31 |
+
|
| 32 |
+
% global gen;
|
| 33 |
+
|
| 34 |
+
% Dimension of objective function
|
| 35 |
+
Dim = 20;
|
| 36 |
+
|
| 37 |
+
% values from MICHALEWICZ
|
| 38 |
+
a = 1.1;
|
| 39 |
+
x0 = 100;
|
| 40 |
+
xend = x0;
|
| 41 |
+
XENDWEIGHT = 0.4/(Dim^0.6);
|
| 42 |
+
|
| 43 |
+
% Compute population parameters
|
| 44 |
+
[Nind,Nvar] = size(Chrom);
|
| 45 |
+
|
| 46 |
+
% Check size of Chrom and do the appropriate thing
|
| 47 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 48 |
+
if Nind == 0
|
| 49 |
+
% return text of title for graphic output
|
| 50 |
+
if switch == 2
|
| 51 |
+
ObjVal = ['HARVEST PROBLEM-' int2str(Dim)];
|
| 52 |
+
% return value of global minimum
|
| 53 |
+
elseif switch == 3
|
| 54 |
+
ObjVal = -sqrt(x0*(a^Dim-1)^2/(a^(Dim-1)*(a-1)));
|
| 55 |
+
% define size of boundary-matrix and values
|
| 56 |
+
else
|
| 57 |
+
% lower and upper bound, identical for all n variables
|
| 58 |
+
ObjVal1 = [0; 10*Dim];
|
| 59 |
+
ObjVal = rep(ObjVal1,[1 Dim]);
|
| 60 |
+
end
|
| 61 |
+
% if Dim variables, compute values of function
|
| 62 |
+
elseif Nvar == Dim
|
| 63 |
+
ObjVal = zeros(Nind,1);
|
| 64 |
+
X = rep(x0,[Nind 1]);
|
| 65 |
+
for irun = 1:Nvar,
|
| 66 |
+
X = a*X - Chrom(:,irun);
|
| 67 |
+
end
|
| 68 |
+
X;
|
| 69 |
+
ObjVal = -(sum(sqrt(Chrom)')' - XENDWEIGHT * abs(X-x0));
|
| 70 |
+
% otherwise error, wrong format of Chrom
|
| 71 |
+
else
|
| 72 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 73 |
+
end
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
% End of function
|
| 77 |
+
|
| 78 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RANKING.M
CHANGED
|
@@ -1,3 +1,125 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% RANKING.M (RANK-based fitness assignment)
|
| 2 |
+
%
|
| 3 |
+
% This function performs ranking of individuals.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: FitnV = ranking(ObjV, RFun, SUBPOP)
|
| 6 |
+
%
|
| 7 |
+
% This function ranks individuals represented by their associated
|
| 8 |
+
% cost, to be *minimized*, and returns a column vector FitnV
|
| 9 |
+
% containing the corresponding individual fitnesses. For multiple
|
| 10 |
+
% subpopulations the ranking is performed separately for each
|
| 11 |
+
% subpopulation.
|
| 12 |
+
%
|
| 13 |
+
% Input parameters:
|
| 14 |
+
% ObjV - Column vector containing the objective values of the
|
| 15 |
+
% individuals in the current population (cost values).
|
| 16 |
+
% RFun - (optional) If RFun is a scalar in [1, 2] linear ranking is
|
| 17 |
+
% assumed and the scalar indicates the selective pressure.
|
| 18 |
+
% If RFun is a 2 element vector:
|
| 19 |
+
% RFun(1): SP - scalar indicating the selective pressure
|
| 20 |
+
% RFun(2): RM - ranking method
|
| 21 |
+
% RM = 0: linear ranking
|
| 22 |
+
% RM = 1: non-linear ranking
|
| 23 |
+
% If RFun is a vector with length(Rfun) > 2 it contains
|
| 24 |
+
% the fitness to be assigned to each rank. It should have
|
| 25 |
+
% the same length as ObjV. Usually RFun is monotonously
|
| 26 |
+
% increasing.
|
| 27 |
+
% If RFun is omitted or NaN, linear ranking
|
| 28 |
+
% and a selective pressure of 2 are assumed.
|
| 29 |
+
% SUBPOP - (optional) Number of subpopulations
|
| 30 |
+
% if omitted or NaN, 1 subpopulation is assumed
|
| 31 |
+
%
|
| 32 |
+
% Output parameters:
|
| 33 |
+
% FitnV - Column vector containing the fitness values of the
|
| 34 |
+
% individuals in the current population.
|
| 35 |
+
%
|
| 36 |
+
|
| 37 |
+
% Author: Hartmut Pohlheim (Carlos Fonseca)
|
| 38 |
+
% History: 01.03.94 non-linear ranking
|
| 39 |
+
% 10.03.94 multiple populations
|
| 40 |
+
|
| 41 |
+
function FitnV = ranking(ObjV, RFun, SUBPOP);
|
| 42 |
+
|
| 43 |
+
% Identify the vector size (Nind)
|
| 44 |
+
[Nind,ans] = size(ObjV);
|
| 45 |
+
|
| 46 |
+
if nargin < 2, RFun = []; end
|
| 47 |
+
if nargin > 1, if isnan(RFun), RFun = []; end, end
|
| 48 |
+
if prod(size(RFun)) == 2,
|
| 49 |
+
if RFun(2) == 1, NonLin = 1;
|
| 50 |
+
elseif RFun(2) == 0, NonLin = 0;
|
| 51 |
+
else error('Parameter for ranking method must be 0 or 1'); end
|
| 52 |
+
RFun = RFun(1);
|
| 53 |
+
if isnan(RFun), RFun = 2; end
|
| 54 |
+
elseif prod(size(RFun)) > 2,
|
| 55 |
+
if prod(size(RFun)) ~= Nind, error('ObjV and RFun disagree'); end
|
| 56 |
+
end
|
| 57 |
+
|
| 58 |
+
if nargin < 3, SUBPOP = 1; end
|
| 59 |
+
if nargin > 2,
|
| 60 |
+
if isempty(SUBPOP), SUBPOP = 1;
|
| 61 |
+
elseif isnan(SUBPOP), SUBPOP = 1;
|
| 62 |
+
elseif length(SUBPOP) ~= 1, error('SUBPOP must be a scalar'); end
|
| 63 |
+
end
|
| 64 |
+
|
| 65 |
+
if (Nind/SUBPOP) ~= fix(Nind/SUBPOP), error('ObjV and SUBPOP disagree'); end
|
| 66 |
+
Nind = Nind/SUBPOP; % Compute number of individuals per subpopulation
|
| 67 |
+
|
| 68 |
+
% Check ranking function and use default values if necessary
|
| 69 |
+
if isempty(RFun),
|
| 70 |
+
% linear ranking with selective pressure 2
|
| 71 |
+
RFun = 2*[0:Nind-1]'/(Nind-1);
|
| 72 |
+
elseif prod(size(RFun)) == 1
|
| 73 |
+
if NonLin == 1,
|
| 74 |
+
% non-linear ranking
|
| 75 |
+
if RFun(1) < 1, error('Selective pressure must be greater than 1');
|
| 76 |
+
elseif RFun(1) > Nind-2, error('Selective pressure too big'); end
|
| 77 |
+
Root1 = roots([RFun(1)-Nind [RFun(1)*ones(1,Nind-1)]]);
|
| 78 |
+
RFun = (abs(Root1(1)) * ones(Nind,1)) .^ [(0:Nind-1)'];
|
| 79 |
+
RFun = RFun / sum(RFun) * Nind;
|
| 80 |
+
else
|
| 81 |
+
% linear ranking with SP between 1 and 2
|
| 82 |
+
if (RFun(1) < 1 | RFun(1) > 2),
|
| 83 |
+
error('Selective pressure for linear ranking must be between 1 and 2');
|
| 84 |
+
end
|
| 85 |
+
RFun = 2-RFun + 2*(RFun-1)*[0:Nind-1]'/(Nind-1);
|
| 86 |
+
end
|
| 87 |
+
end;
|
| 88 |
+
|
| 89 |
+
FitnV = [];
|
| 90 |
+
|
| 91 |
+
% loop over all subpopulations
|
| 92 |
+
for irun = 1:SUBPOP,
|
| 93 |
+
% Copy objective values of actual subpopulation
|
| 94 |
+
ObjVSub = ObjV((irun-1)*Nind+1:irun*Nind);
|
| 95 |
+
% Sort does not handle NaN values as required. So, find those...
|
| 96 |
+
NaNix = isnan(ObjVSub);
|
| 97 |
+
Validix = find(~NaNix);
|
| 98 |
+
% ... and sort only numeric values (smaller is better).
|
| 99 |
+
[ans,ix] = sort(-ObjVSub(Validix));
|
| 100 |
+
|
| 101 |
+
% Now build indexing vector assuming NaN are worse than numbers,
|
| 102 |
+
% (including Inf!)...
|
| 103 |
+
ix = [find(NaNix) ; Validix(ix)];
|
| 104 |
+
% ... and obtain a sorted version of ObjV
|
| 105 |
+
Sorted = ObjVSub(ix);
|
| 106 |
+
|
| 107 |
+
% Assign fitness according to RFun.
|
| 108 |
+
i = 1;
|
| 109 |
+
FitnVSub = zeros(Nind,1);
|
| 110 |
+
for j = [find(Sorted(1:Nind-1) ~= Sorted(2:Nind)); Nind]',
|
| 111 |
+
FitnVSub(i:j) = sum(RFun(i:j)) * ones(j-i+1,1) / (j-i+1);
|
| 112 |
+
i =j+1;
|
| 113 |
+
end
|
| 114 |
+
|
| 115 |
+
% Finally, return unsorted vector.
|
| 116 |
+
[ans,uix] = sort(ix);
|
| 117 |
+
FitnVSub = FitnVSub(uix);
|
| 118 |
+
|
| 119 |
+
% Add FitnVSub to FitnV
|
| 120 |
+
FitnV = [FitnV; FitnVSub];
|
| 121 |
+
end
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
% End of function
|
| 125 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RECDIS.M
CHANGED
|
@@ -1,3 +1,52 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% RECDIS.M (RECombination DIScrete)
|
| 2 |
+
%
|
| 3 |
+
% This function performs discret recombination between pairs of individuals
|
| 4 |
+
% and returns the new individuals after mating.
|
| 5 |
+
%
|
| 6 |
+
% Syntax: NewChrom = recdis(OldChrom, XOVR)
|
| 7 |
+
%
|
| 8 |
+
% Input parameters:
|
| 9 |
+
% OldChrom - Matrix containing the chromosomes of the old
|
| 10 |
+
% population. Each line corresponds to one individual
|
| 11 |
+
% (in any form, not necessarily real-values).
|
| 12 |
+
% XOVR - Probability of recombination occurring between pairs
|
| 13 |
+
% of individuals. (not used, only for compatibility)
|
| 14 |
+
%
|
| 15 |
+
% Output parameter:
|
| 16 |
+
% NewChrom - Matrix containing the chromosomes of the population
|
| 17 |
+
% after mating, ready to be mutated and/or evaluated,
|
| 18 |
+
% in the same format as OldChrom.
|
| 19 |
+
|
| 20 |
+
% Author: Hartmut Pohlheim
|
| 21 |
+
% History: 23.11.93 file created
|
| 22 |
+
% 24.11.93 style improved
|
| 23 |
+
% 06.12.93 change of name of function
|
| 24 |
+
% 25.02.94 clean up
|
| 25 |
+
% 19.03.94 multipopulation support removed
|
| 26 |
+
|
| 27 |
+
function NewChrom = recdis(OldChrom, XOVR);
|
| 28 |
+
|
| 29 |
+
% Identify the population size (Nind) and the number of variables (Nvar)
|
| 30 |
+
[Nind,Nvar] = size(OldChrom);
|
| 31 |
+
|
| 32 |
+
% Identify the number of matings
|
| 33 |
+
Xops = floor(Nind/2);
|
| 34 |
+
|
| 35 |
+
% which parent gives the value
|
| 36 |
+
Mask1 = (rand(Xops,Nvar)<0.5);
|
| 37 |
+
Mask2 = (rand(Xops,Nvar)<0.5);
|
| 38 |
+
|
| 39 |
+
% Performs crossover
|
| 40 |
+
odd = 1:2:Nind-1;
|
| 41 |
+
even= 2:2:Nind;
|
| 42 |
+
NewChrom(odd,:) = (OldChrom(odd,:).* Mask1) + (OldChrom(even,:).*(~Mask1));
|
| 43 |
+
NewChrom(even,:) = (OldChrom(odd,:).* Mask2) + (OldChrom(even,:).*(~Mask2));
|
| 44 |
+
|
| 45 |
+
% If the number of individuals is odd, the last individual cannot be mated
|
| 46 |
+
% but must be included in the new population
|
| 47 |
+
if rem(Nind,2), NewChrom(Nind,:)=OldChrom(Nind,:); end
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
% End of function
|
| 51 |
+
|
| 52 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RECINT.M
CHANGED
|
@@ -1,3 +1,55 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% RECINT.M (RECombination extended INTermediate)
|
| 2 |
+
%
|
| 3 |
+
% This function performs extended intermediate recombination between
|
| 4 |
+
% pairs of individuals and returns the new individuals after mating.
|
| 5 |
+
%
|
| 6 |
+
% Syntax: NewChrom = recint(OldChrom, XOVR)
|
| 7 |
+
%
|
| 8 |
+
% Input parameters:
|
| 9 |
+
% OldChrom - Matrix containing the chromosomes of the old
|
| 10 |
+
% population. Each line corresponds to one
|
| 11 |
+
% individual
|
| 12 |
+
% XOVR - Probability of crossover occurring between pairs
|
| 13 |
+
% of individuals. (not used, only for compatibility)
|
| 14 |
+
%
|
| 15 |
+
% Output parameter:
|
| 16 |
+
% NewChrom - Matrix containing the chromosomes of the population
|
| 17 |
+
% after mating, ready to be mutated and/or evaluated,
|
| 18 |
+
% in the same format as OldChrom.
|
| 19 |
+
|
| 20 |
+
% Author: Hartmut Pohlheim
|
| 21 |
+
% History: 25.11.93 file created
|
| 22 |
+
% 06.12.93 change of name of function
|
| 23 |
+
% 25.02.94 clean up
|
| 24 |
+
% 19.03.94 multipopulation support removed
|
| 25 |
+
|
| 26 |
+
function NewChrom = recint(OldChrom, XOVR);
|
| 27 |
+
|
| 28 |
+
% Identify the population size (Nind) and the number of variables (Nvar)
|
| 29 |
+
[Nind,Nvar] = size(OldChrom);
|
| 30 |
+
|
| 31 |
+
% Identify the number of matings
|
| 32 |
+
Xops = floor(Nind/2);
|
| 33 |
+
|
| 34 |
+
% Performs recombination
|
| 35 |
+
odd = 1:2:Nind-1;
|
| 36 |
+
even= 2:2:Nind;
|
| 37 |
+
|
| 38 |
+
% position of value of offspring compared to parents
|
| 39 |
+
Alpha = -0.25 + 1.5 * rand(Xops,Nvar);
|
| 40 |
+
|
| 41 |
+
% recombination
|
| 42 |
+
NewChrom(odd,:) = OldChrom(odd,:) + Alpha .* (OldChrom(even,:) - OldChrom(odd,:));
|
| 43 |
+
|
| 44 |
+
% the same ones more for second half of offspring
|
| 45 |
+
Alpha = -0.25 + 1.5 * rand(Xops,Nvar);
|
| 46 |
+
NewChrom(even,:) = OldChrom(odd,:) + Alpha .* (OldChrom(even,:) - OldChrom(odd,:));
|
| 47 |
+
|
| 48 |
+
% If the number of individuals is odd, the last individual cannot be mated
|
| 49 |
+
% but must be included in the new population
|
| 50 |
+
if rem(Nind,2), NewChrom(Nind,:)=OldChrom(Nind,:); end
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
% End of function
|
| 54 |
+
|
| 55 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RECLIN.M
CHANGED
|
@@ -1,3 +1,57 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% RECLIN.M (RECombination extended LINe)
|
| 2 |
+
%
|
| 3 |
+
% This function performs extended line recombination between
|
| 4 |
+
% pairs of individuals and returns the new individuals after mating.
|
| 5 |
+
%
|
| 6 |
+
% Syntax: NewChrom = reclin(OldChrom, XOVR)
|
| 7 |
+
%
|
| 8 |
+
% Input parameters:
|
| 9 |
+
% OldChrom - Matrix containing the chromosomes of the old
|
| 10 |
+
% population. Each line corresponds to one
|
| 11 |
+
% individual
|
| 12 |
+
% XOVR - Probability of crossover occurring between pairs
|
| 13 |
+
% of individuals. (not used, only for compatibility)
|
| 14 |
+
%
|
| 15 |
+
% Output parameter:
|
| 16 |
+
% NewChrom - Matrix containing the chromosomes of the population
|
| 17 |
+
% after mating, ready to be mutated and/or evaluated,
|
| 18 |
+
% in the same format as OldChrom.
|
| 19 |
+
|
| 20 |
+
% Author: Hartmut Pohlheim
|
| 21 |
+
% History: 26.11.93 file created
|
| 22 |
+
% 06.12.93 change of name of function
|
| 23 |
+
% 25.02.94 clean up
|
| 24 |
+
% 19.03.94 multipopulation support removed
|
| 25 |
+
|
| 26 |
+
function NewChrom = reclin(OldChrom, XOVR);
|
| 27 |
+
|
| 28 |
+
% Identify the population size (Nind) and the number of variables (Nvar)
|
| 29 |
+
[Nind,Nvar] = size(OldChrom);
|
| 30 |
+
|
| 31 |
+
% Identify the number of matings
|
| 32 |
+
Xops = floor(Nind/2);
|
| 33 |
+
|
| 34 |
+
% Performs recombination
|
| 35 |
+
odd = 1:2:Nind-1;
|
| 36 |
+
even= 2:2:Nind;
|
| 37 |
+
|
| 38 |
+
% position of value of offspring compared to parents
|
| 39 |
+
Alpha = -0.25 + 1.5 * rand(Xops,1);
|
| 40 |
+
Alpha = Alpha(1:Xops,ones(Nvar,1));
|
| 41 |
+
|
| 42 |
+
% recombination
|
| 43 |
+
NewChrom(odd,:) = OldChrom(odd,:) + Alpha .* (OldChrom(even,:) - OldChrom(odd,:));
|
| 44 |
+
|
| 45 |
+
% the same ones more for second half of offspring
|
| 46 |
+
Alpha = -0.25 + 1.5 * rand(Xops,1);
|
| 47 |
+
Alpha = Alpha(1:Xops,ones(Nvar,1));
|
| 48 |
+
NewChrom(even,:) = OldChrom(odd,:) + Alpha .* (OldChrom(even,:) - OldChrom(odd,:));
|
| 49 |
+
|
| 50 |
+
% If the number of individuals is odd, the last individual cannot be mated
|
| 51 |
+
% but must be included in the new population
|
| 52 |
+
if rem(Nind,2), NewChrom(Nind,:)=OldChrom(Nind,:); end
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
% End of function
|
| 56 |
+
|
| 57 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RECMUT.M
CHANGED
|
@@ -1,3 +1,118 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% RECLIN.M (line RECombination with MUTation features)
|
| 2 |
+
%
|
| 3 |
+
% This function performs line recombination with mutation features between
|
| 4 |
+
% pairs of individuals and returns the new individuals after mating.
|
| 5 |
+
%
|
| 6 |
+
% Syntax: NewChrom = recmut(OldChrom, FieldDR, MutOpt)
|
| 7 |
+
%
|
| 8 |
+
% Input parameters:
|
| 9 |
+
% OldChrom - Matrix containing the chromosomes of the old
|
| 10 |
+
% population. Each line corresponds to one individual
|
| 11 |
+
% FieldDR - Matrix describing the boundaries of each variable.
|
| 12 |
+
% MutOpt - (optional) Vector containing recombination rate and shrink value
|
| 13 |
+
% MutOpt(1): MutR - number containing the recombination rate -
|
| 14 |
+
% probability for recombine a pair of parents
|
| 15 |
+
% if omitted or NaN, MutOpt(1) = 1 is assumed
|
| 16 |
+
% MutOpt(2): MutShrink - (optional) number for shrinking the
|
| 17 |
+
% recombination range in the range [0 1], possibility to
|
| 18 |
+
% shrink the range of the recombination depending on,
|
| 19 |
+
% for instance actual generation.
|
| 20 |
+
% if omitted or NaN, MutOpt(2) = 1 is assumed
|
| 21 |
+
%
|
| 22 |
+
% Output parameter:
|
| 23 |
+
% NewChrom - Matrix containing the chromosomes of the population
|
| 24 |
+
% after mating, ready to be mutated and/or evaluated,
|
| 25 |
+
% in the same format as OldChrom.
|
| 26 |
+
|
| 27 |
+
% Author: Hartmut Pohlheim
|
| 28 |
+
% History: 27.03.94 file created
|
| 29 |
+
|
| 30 |
+
function NewChrom = recmut(OldChrom, FieldDR, MutOpt);
|
| 31 |
+
|
| 32 |
+
% Check parameter consistency
|
| 33 |
+
if nargin < 2, error('Not enough input parameter'); end
|
| 34 |
+
|
| 35 |
+
% Identify the population size (Nind) and the number of variables (Nvar)
|
| 36 |
+
[Nind,Nvar] = size(OldChrom);
|
| 37 |
+
|
| 38 |
+
[mF, nF] = size(FieldDR);
|
| 39 |
+
if mF ~= 2, error('FieldDR must be a matrix with 2 rows'); end
|
| 40 |
+
if Nvar ~= nF, error('FieldDR and OldChrom disagree'); end
|
| 41 |
+
|
| 42 |
+
if nargin < 3, MutR = 1; MutShrink = 1;
|
| 43 |
+
elseif isempty(MutOpt), MutR = 1; MutShrink = 1;
|
| 44 |
+
elseif isnan(MutOpt), MutR = 1; MutShrink = 1;
|
| 45 |
+
else
|
| 46 |
+
if length(MutOpt) == 1, MutR = MutOpt; MutShrink = 1;
|
| 47 |
+
elseif length(MutOpt) == 2, MutR = MutOpt(1); MutShrink = MutOpt(2);
|
| 48 |
+
else, error(' Too many parameter in MutOpt'); end
|
| 49 |
+
end
|
| 50 |
+
|
| 51 |
+
if isempty(MutR), MutR = 1;
|
| 52 |
+
elseif isnan(MutR), MutR = 1;
|
| 53 |
+
elseif length(MutR) ~= 1, error('Parameter for recombination rate must be a scalar');
|
| 54 |
+
elseif (MutR < 0 | MutR > 1), error('Parameter for recombination rate must be a scalar in [0, 1]'); end
|
| 55 |
+
|
| 56 |
+
if isempty(MutShrink), MutShrink = 1;
|
| 57 |
+
elseif isnan(MutShrink), MutShrink = 1;
|
| 58 |
+
elseif length(MutShrink) ~= 1, error('Parameter for shrinking recombination range must be a scalar');
|
| 59 |
+
elseif (MutShrink < 0 | MutShrink > 1),
|
| 60 |
+
error('Parameter for shrinking recombination range must be a scalar in [0, 1]');
|
| 61 |
+
end
|
| 62 |
+
|
| 63 |
+
% Identify the number of matings
|
| 64 |
+
Xops = floor(Nind/2);
|
| 65 |
+
|
| 66 |
+
% NewChrom = OldChrom (+ or -) * Range * MutShrink * Delta * ChromDiff
|
| 67 |
+
% - with probability 0.9, + with probability 0.1
|
| 68 |
+
% Range = 0.5 * (upperbound - lowerbound), given by FieldDR
|
| 69 |
+
% Delta = Sum(Alpha_i * 2^-i) from 0 to ACCUR; Alpha_i = rand(ACCUR,1) < 1/ACCUR
|
| 70 |
+
% ChromDiff = (individual1 - individual2) / Distance between individuals
|
| 71 |
+
|
| 72 |
+
% Matrix with range values for every variable
|
| 73 |
+
Range = rep(0.5 * MutShrink *(FieldDR(2,:)-FieldDR(1,:)),[Xops 1]);
|
| 74 |
+
|
| 75 |
+
% zeros and ones for recombine or not this variable, together with Range
|
| 76 |
+
if MutR < 1, Range = Range .* rep((rand(Xops,1) < MutR), [1 Nvar]); end
|
| 77 |
+
|
| 78 |
+
% compute, if + or - sign
|
| 79 |
+
Range = Range .* (1 - 2 * (rand(Xops,Nvar) < 0.9));
|
| 80 |
+
|
| 81 |
+
% compute distance between mating pairs
|
| 82 |
+
NormO = zeros(Xops,1);
|
| 83 |
+
for irun = 1:Xops,
|
| 84 |
+
NormO(irun) = max(realmin,abs(norm(OldChrom(2*irun,:)) - norm(OldChrom(2*irun-1,:))));
|
| 85 |
+
end
|
| 86 |
+
|
| 87 |
+
% compute difference between variables divided by distance
|
| 88 |
+
ChromDiff = zeros(Xops,Nvar);
|
| 89 |
+
for irun = 1:Xops
|
| 90 |
+
ChromDiff(irun,:) = diff([OldChrom(2*irun-1,:); OldChrom(2*irun,:)]) / NormO(irun);
|
| 91 |
+
end
|
| 92 |
+
|
| 93 |
+
% compute delta value for all individuals
|
| 94 |
+
ACCUR = 20;
|
| 95 |
+
Vect = 2 .^ (-(0:(ACCUR-1))');
|
| 96 |
+
Delta = (rand(Xops,ACCUR) < 1/ACCUR) * Vect;
|
| 97 |
+
Delta = rep(Delta, [1 Nvar]);
|
| 98 |
+
|
| 99 |
+
% Performs recombination
|
| 100 |
+
odd = 1:2:Nind-1;
|
| 101 |
+
even= 2:2:Nind;
|
| 102 |
+
|
| 103 |
+
% recombination
|
| 104 |
+
NewChrom(odd,:) = OldChrom(odd,:) + Range .* Delta .* (ChromDiff);
|
| 105 |
+
NewChrom(even,:) = OldChrom(even,:) + Range .* Delta .* (-ChromDiff);
|
| 106 |
+
|
| 107 |
+
% If the number of individuals is odd, the last individual cannot be mated
|
| 108 |
+
% but must be included in the new population
|
| 109 |
+
if rem(Nind,2), NewChrom(Nind,:)=OldChrom(Nind,:); end
|
| 110 |
+
|
| 111 |
+
% Ensure variables boundaries, compare with lower and upper boundaries
|
| 112 |
+
NewChrom = max(rep(FieldDR(1,:),[Nind 1]), NewChrom);
|
| 113 |
+
NewChrom = min(rep(FieldDR(2,:),[Nind 1]), NewChrom);
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
% End of function
|
| 117 |
+
|
| 118 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RECOMBIN.M
CHANGED
|
@@ -1,3 +1,69 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% RECOMBIN.M (RECOMBINation high-level function)
|
| 2 |
+
%
|
| 3 |
+
% This function performs recombination between pairs of individuals
|
| 4 |
+
% and returns the new individuals after mating. The function handles
|
| 5 |
+
% multiple populations and calls the low-level recombination function
|
| 6 |
+
% for the actual recombination process.
|
| 7 |
+
%
|
| 8 |
+
% Syntax: NewChrom = recombin(REC_F, OldChrom, RecOpt, SUBPOP)
|
| 9 |
+
%
|
| 10 |
+
% Input parameters:
|
| 11 |
+
% REC_F - String containing the name of the recombination or
|
| 12 |
+
% crossover function
|
| 13 |
+
% Chrom - Matrix containing the chromosomes of the old
|
| 14 |
+
% population. Each line corresponds to one individual
|
| 15 |
+
% RecOpt - (optional) Scalar containing the probability of
|
| 16 |
+
% recombination/crossover occurring between pairs
|
| 17 |
+
% of individuals.
|
| 18 |
+
% if omitted or NaN, 1 is assumed
|
| 19 |
+
% SUBPOP - (optional) Number of subpopulations
|
| 20 |
+
% if omitted or NaN, 1 subpopulation is assumed
|
| 21 |
+
%
|
| 22 |
+
% Output parameter:
|
| 23 |
+
% NewChrom - Matrix containing the chromosomes of the population
|
| 24 |
+
% after recombination in the same format as OldChrom.
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 18.03.94 file created
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
function NewChrom = recombin(REC_F, Chrom, RecOpt, SUBPOP);
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
% Check parameter consistency
|
| 34 |
+
if nargin < 2, error('Not enough input parameter'); end
|
| 35 |
+
|
| 36 |
+
% Identify the population size (Nind)
|
| 37 |
+
[Nind,Nvar] = size(Chrom);
|
| 38 |
+
|
| 39 |
+
if nargin < 4, SUBPOP = 1; end
|
| 40 |
+
if nargin > 3,
|
| 41 |
+
if isempty(SUBPOP), SUBPOP = 1;
|
| 42 |
+
elseif isnan(SUBPOP), SUBPOP = 1;
|
| 43 |
+
elseif length(SUBPOP) ~= 1, error('SUBPOP must be a scalar'); end
|
| 44 |
+
end
|
| 45 |
+
|
| 46 |
+
if (Nind/SUBPOP) ~= fix(Nind/SUBPOP), error('Chrom and SUBPOP disagree'); end
|
| 47 |
+
Nind = Nind/SUBPOP; % Compute number of individuals per subpopulation
|
| 48 |
+
|
| 49 |
+
if nargin < 3, RecOpt = 0.7; end
|
| 50 |
+
if nargin > 2,
|
| 51 |
+
if isempty(RecOpt), RecOpt = 0.7;
|
| 52 |
+
elseif isnan(RecOpt), RecOpt = 0.7;
|
| 53 |
+
elseif length(RecOpt) ~= 1, error('RecOpt must be a scalar');
|
| 54 |
+
elseif (RecOpt < 0 | RecOpt > 1), error('RecOpt must be a scalar in [0, 1]'); end
|
| 55 |
+
end
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
% Select individuals of one subpopulation and call low level function
|
| 59 |
+
NewChrom = [];
|
| 60 |
+
for irun = 1:SUBPOP,
|
| 61 |
+
ChromSub = Chrom((irun-1)*Nind+1:irun*Nind,:);
|
| 62 |
+
NewChromSub = feval(REC_F, ChromSub, RecOpt);
|
| 63 |
+
NewChrom=[NewChrom; NewChromSub];
|
| 64 |
+
end
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
% End of function
|
| 68 |
+
|
| 69 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/REINS.M
CHANGED
|
@@ -1,3 +1,123 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% REINS.M (RE-INSertion of offspring in population replacing parents)
|
| 2 |
+
%
|
| 3 |
+
% This function reinserts offspring in the population.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: [Chrom, ObjVCh] = reins(Chrom, SelCh, SUBPOP, InsOpt, ObjVCh, ObjVSel)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the individuals (parents) of the current
|
| 9 |
+
% population. Each row corresponds to one individual.
|
| 10 |
+
% SelCh - Matrix containing the offspring of the current
|
| 11 |
+
% population. Each row corresponds to one individual.
|
| 12 |
+
% SUBPOP - (optional) Number of subpopulations
|
| 13 |
+
% if omitted or NaN, 1 subpopulation is assumed
|
| 14 |
+
% InsOpt - (optional) Vector containing the insertion method parameters
|
| 15 |
+
% ExOpt(1): Select - number indicating kind of insertion
|
| 16 |
+
% 0 - uniform insertion
|
| 17 |
+
% 1 - fitness-based insertion
|
| 18 |
+
% if omitted or NaN, 0 is assumed
|
| 19 |
+
% ExOpt(2): INSR - Rate of offspring to be inserted per
|
| 20 |
+
% subpopulation (% of subpopulation)
|
| 21 |
+
% if omitted or NaN, 1.0 (100%) is assumed
|
| 22 |
+
% ObjVCh - (optional) Column vector containing the objective values
|
| 23 |
+
% of the individuals (parents - Chrom) in the current
|
| 24 |
+
% population, needed for fitness-based insertion
|
| 25 |
+
% saves recalculation of objective values for population
|
| 26 |
+
% ObjVSel - (optional) Column vector containing the objective values
|
| 27 |
+
% of the offspring (SelCh) in the current population, needed for
|
| 28 |
+
% partial insertion of offspring,
|
| 29 |
+
% saves recalculation of objective values for population
|
| 30 |
+
%
|
| 31 |
+
% Output parameters:
|
| 32 |
+
% Chrom - Matrix containing the individuals of the current
|
| 33 |
+
% population after reinsertion.
|
| 34 |
+
% ObjVCh - if ObjVCh and ObjVSel are input parameter, than column
|
| 35 |
+
% vector containing the objective values of the individuals
|
| 36 |
+
% of the current generation after reinsertion.
|
| 37 |
+
|
| 38 |
+
% Author: Hartmut Pohlheim
|
| 39 |
+
% History: 10.03.94 file created
|
| 40 |
+
% 19.03.94 parameter checking improved
|
| 41 |
+
|
| 42 |
+
function [Chrom, ObjVCh] = reins(Chrom, SelCh, SUBPOP, InsOpt, ObjVCh, ObjVSel);
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
% Check parameter consistency
|
| 46 |
+
if nargin < 2, error('Not enough input parameter'); end
|
| 47 |
+
if (nargout == 2 & nargin < 6), error('Input parameter missing: ObjVCh and/or ObjVSel'); end
|
| 48 |
+
|
| 49 |
+
[NindP, NvarP] = size(Chrom);
|
| 50 |
+
[NindO, NvarO] = size(SelCh);
|
| 51 |
+
|
| 52 |
+
if nargin == 2, SUBPOP = 1; end
|
| 53 |
+
if nargin > 2,
|
| 54 |
+
if isempty(SUBPOP), SUBPOP = 1;
|
| 55 |
+
elseif isnan(SUBPOP), SUBPOP = 1;
|
| 56 |
+
elseif length(SUBPOP) ~= 1, error('SUBPOP must be a scalar'); end
|
| 57 |
+
end
|
| 58 |
+
|
| 59 |
+
if (NindP/SUBPOP) ~= fix(NindP/SUBPOP), error('Chrom and SUBPOP disagree'); end
|
| 60 |
+
if (NindO/SUBPOP) ~= fix(NindO/SUBPOP), error('SelCh and SUBPOP disagree'); end
|
| 61 |
+
NIND = NindP/SUBPOP; % Compute number of individuals per subpopulation
|
| 62 |
+
NSEL = NindO/SUBPOP; % Compute number of offspring per subpopulation
|
| 63 |
+
|
| 64 |
+
IsObjVCh = 0; IsObjVSel = 0;
|
| 65 |
+
if nargin > 4,
|
| 66 |
+
[mO, nO] = size(ObjVCh);
|
| 67 |
+
if nO ~= 1, error('ObjVCh must be a column vector'); end
|
| 68 |
+
if NindP ~= mO, error('Chrom and ObjVCh disagree'); end
|
| 69 |
+
IsObjVCh = 1;
|
| 70 |
+
end
|
| 71 |
+
if nargin > 5,
|
| 72 |
+
[mO, nO] = size(ObjVSel);
|
| 73 |
+
if nO ~= 1, error('ObjVSel must be a column vector'); end
|
| 74 |
+
if NindO ~= mO, error('SelCh and ObjVSel disagree'); end
|
| 75 |
+
IsObjVSel = 1;
|
| 76 |
+
end
|
| 77 |
+
|
| 78 |
+
if nargin < 4, INSR = 1.0; Select = 0; end
|
| 79 |
+
if nargin >= 4,
|
| 80 |
+
if isempty(InsOpt), INSR = 1.0; Select = 0;
|
| 81 |
+
elseif isnan(InsOpt), INSR = 1.0; Select = 0;
|
| 82 |
+
else
|
| 83 |
+
INSR = NaN; Select = NaN;
|
| 84 |
+
if (length(InsOpt) > 2), error('Parameter InsOpt too long'); end
|
| 85 |
+
if (length(InsOpt) >= 1), Select = InsOpt(1); end
|
| 86 |
+
if (length(InsOpt) >= 2), INSR = InsOpt(2); end
|
| 87 |
+
if isnan(Select), Select = 0; end
|
| 88 |
+
if isnan(INSR), INSR =1.0; end
|
| 89 |
+
end
|
| 90 |
+
end
|
| 91 |
+
|
| 92 |
+
if (INSR < 0 | INSR > 1), error('Parameter for insertion rate must be a scalar in [0, 1]'); end
|
| 93 |
+
if (INSR < 1 & IsObjVSel ~= 1), error('For selection of offspring ObjVSel is needed'); end
|
| 94 |
+
if (Select ~= 0 & Select ~= 1), error('Parameter for selection method must be 0 or 1'); end
|
| 95 |
+
if (Select == 1 & IsObjVCh == 0), error('ObjVCh for fitness-based exchange needed'); end
|
| 96 |
+
|
| 97 |
+
if INSR == 0, return; end
|
| 98 |
+
NIns = min(max(floor(INSR*NSEL+.5),1),NIND); % Number of offspring to insert
|
| 99 |
+
|
| 100 |
+
% perform insertion for each subpopulation
|
| 101 |
+
for irun = 1:SUBPOP,
|
| 102 |
+
% Calculate positions in old subpopulation, where offspring are inserted
|
| 103 |
+
if Select == 1, % fitness-based reinsertion
|
| 104 |
+
[Dummy, ChIx] = sort(-ObjVCh((irun-1)*NIND+1:irun*NIND));
|
| 105 |
+
else % uniform reinsertion
|
| 106 |
+
[Dummy, ChIx] = sort(rand(NIND,1));
|
| 107 |
+
end
|
| 108 |
+
PopIx = ChIx((1:NIns)')+ (irun-1)*NIND;
|
| 109 |
+
% Calculate position of Nins-% best offspring
|
| 110 |
+
if (NIns < NSEL), % select best offspring
|
| 111 |
+
[Dummy,OffIx] = sort(ObjVSel((irun-1)*NSEL+1:irun*NSEL));
|
| 112 |
+
else
|
| 113 |
+
OffIx = (1:NIns)';
|
| 114 |
+
end
|
| 115 |
+
SelIx = OffIx((1:NIns)')+(irun-1)*NSEL;
|
| 116 |
+
% Insert offspring in subpopulation -> new subpopulation
|
| 117 |
+
Chrom(PopIx,:) = SelCh(SelIx,:);
|
| 118 |
+
if (IsObjVCh == 1 & IsObjVSel == 1), ObjVCh(PopIx) = ObjVSel(SelIx); end
|
| 119 |
+
end
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
% End of function
|
| 123 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/REP.M
CHANGED
|
@@ -1,3 +1,46 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% REP.m Replicate a matrix
|
| 2 |
+
%
|
| 3 |
+
% This function replicates a matrix in both dimensions.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: MatOut = rep(MatIn,REPN);
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% MatIn - Input Matrix (before replicating)
|
| 9 |
+
%
|
| 10 |
+
% REPN - Vector of 2 numbers, how many replications in each dimension
|
| 11 |
+
% REPN(1): replicate vertically
|
| 12 |
+
% REPN(2): replicate horizontally
|
| 13 |
+
%
|
| 14 |
+
% Example:
|
| 15 |
+
%
|
| 16 |
+
% MatIn = [1 2 3]
|
| 17 |
+
% REPN = [1 2]: MatOut = [1 2 3 1 2 3]
|
| 18 |
+
% REPN = [2 1]: MatOut = [1 2 3;
|
| 19 |
+
% 1 2 3]
|
| 20 |
+
% REPN = [3 2]: MatOut = [1 2 3 1 2 3;
|
| 21 |
+
% 1 2 3 1 2 3;
|
| 22 |
+
% 1 2 3 1 2 3]
|
| 23 |
+
%
|
| 24 |
+
% Output parameter:
|
| 25 |
+
% MatOut - Output Matrix (after replicating)
|
| 26 |
+
%
|
| 27 |
+
|
| 28 |
+
% Author: Carlos Fonseca & Hartmut Pohlheim
|
| 29 |
+
% History: 14.02.94 file created
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
function MatOut = rep(MatIn,REPN)
|
| 33 |
+
|
| 34 |
+
% Get size of input matrix
|
| 35 |
+
[N_D,N_L] = size(MatIn);
|
| 36 |
+
|
| 37 |
+
% Calculate
|
| 38 |
+
Ind_D = rem(0:REPN(1)*N_D-1,N_D) + 1;
|
| 39 |
+
Ind_L = rem(0:REPN(2)*N_L-1,N_L) + 1;
|
| 40 |
+
|
| 41 |
+
% Create output matrix
|
| 42 |
+
MatOut = MatIn(Ind_D,Ind_L);
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
% End of function
|
| 46 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RESPLOT.M
CHANGED
|
@@ -1,3 +1,56 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% RESPLOT.M (RESult PLOTing)
|
| 2 |
+
%
|
| 3 |
+
% This function plots some results during computation.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: resplot(Chrom,IndAll,ObjV,Best,gen)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each line corresponds to one individual.
|
| 10 |
+
% IndAll - Matrix containing the best individual (variables) of each
|
| 11 |
+
% generation. Each line corresponds to one individual.
|
| 12 |
+
% ObjV - Vector containing objective values of the current
|
| 13 |
+
% generation
|
| 14 |
+
% Best - Matrix containing the best and average Objective values of
|
| 15 |
+
% each generation, [best value per generation,average value
|
| 16 |
+
% per generation]
|
| 17 |
+
% gen - Scalar containing the number of the current generation
|
| 18 |
+
%
|
| 19 |
+
% Output parameter:
|
| 20 |
+
% no output parameter
|
| 21 |
+
|
| 22 |
+
% Author: Hartmut Pohlheim
|
| 23 |
+
% History: 27.11.93 file created
|
| 24 |
+
% 29.11.93 decision, if plot or not deleted
|
| 25 |
+
% yscale not log
|
| 26 |
+
% 15.12.93 MutMatrix as parameter and plot added
|
| 27 |
+
% 16.03.94 function cleaned, MutMatrix removed, IndAll added
|
| 28 |
+
|
| 29 |
+
function resplot(Chrom,IndAll,ObjV,Best,gen);
|
| 30 |
+
|
| 31 |
+
% plot of best and mean value per generation
|
| 32 |
+
subplot(2,2,1), plot(Best);
|
| 33 |
+
title('Best and mean objective value');
|
| 34 |
+
xlabel('generation'), ylabel('objective value');
|
| 35 |
+
|
| 36 |
+
% plot of best individuals in all generations
|
| 37 |
+
subplot(2,2,2), plot(IndAll);
|
| 38 |
+
title(['Best individuals']);
|
| 39 |
+
xlabel('generation'), ylabel('value of variable');
|
| 40 |
+
|
| 41 |
+
% plot of variables of all individuals in current generation
|
| 42 |
+
subplot(2,2,3), plot(Chrom');
|
| 43 |
+
title(['All individuals in gen ',num2str(gen)]);
|
| 44 |
+
xlabel('number of variable'), ylabel('value of variable');
|
| 45 |
+
|
| 46 |
+
% plot of all objective values in current generation
|
| 47 |
+
subplot(2,2,4), plot(ObjV,'y.');
|
| 48 |
+
title(['All objective values']);
|
| 49 |
+
xlabel('number of individual'), ylabel('objective value');
|
| 50 |
+
|
| 51 |
+
drawnow;
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
% End of function
|
| 55 |
+
|
| 56 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/RWS.M
CHANGED
|
@@ -1,3 +1,31 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% RWS.m - Roulette Wheel Selection
|
| 2 |
+
%
|
| 3 |
+
% Syntax:
|
| 4 |
+
% NewChrIx = rws(FitnV, Nsel)
|
| 5 |
+
%
|
| 6 |
+
% This function selects a given number of individuals Nsel from a
|
| 7 |
+
% population. FitnV is a column vector containing the fitness
|
| 8 |
+
% values of the individuals in the population.
|
| 9 |
+
%
|
| 10 |
+
% The function returns another column vector containing the
|
| 11 |
+
% indexes of the new generation of chromosomes relative to the
|
| 12 |
+
% original population matrix, shuffled. The new population, ready
|
| 13 |
+
% for mating, can be obtained by calculating
|
| 14 |
+
% OldChrom(NewChrIx, :).
|
| 15 |
+
|
| 16 |
+
% Author: Carlos Fonseca, Updated: Andrew Chipperfield
|
| 17 |
+
% Date: 04/10/93, Date: 27-Jan-94
|
| 18 |
+
|
| 19 |
+
function NewChrIx = rws(FitnV,Nsel);
|
| 20 |
+
|
| 21 |
+
% Identify the population size (Nind)
|
| 22 |
+
[Nind,ans] = size(FitnV);
|
| 23 |
+
|
| 24 |
+
% Perform Stochastic Sampling with Replacement
|
| 25 |
+
cumfit = cumsum(FitnV);
|
| 26 |
+
trials = cumfit(Nind) .* rand(Nsel, 1);
|
| 27 |
+
Mf = cumfit(:, ones(1, Nsel));
|
| 28 |
+
Mt = trials(:, ones(1, Nind))';
|
| 29 |
+
[NewChrIx, ans] = find(Mt < Mf & ...
|
| 30 |
+
[ zeros(1, Nsel); Mf(1:Nind-1, :) ] <= Mt);
|
| 31 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/SCALING.M
CHANGED
|
@@ -1,3 +1,52 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% SCALING.m - linear fitness scaling
|
| 2 |
+
%
|
| 3 |
+
% This function implements a linear fitness scaling algorithm as described
|
| 4 |
+
% by Goldberg in "Genetic Algorithms in Search, Optimization and Machine
|
| 5 |
+
% Learning", Addison Wesley, 1989. It use is not recommended when fitness
|
| 6 |
+
% functions produce negative results as the scaling will become unreliable.
|
| 7 |
+
% It is included in this version of the GA Toolbox only for the sake of
|
| 8 |
+
% completeness.
|
| 9 |
+
%
|
| 10 |
+
% Syntax: FitnV = scaling(ObjV, Smul)
|
| 11 |
+
%
|
| 12 |
+
% Input parameters:
|
| 13 |
+
%
|
| 14 |
+
% Objv - A vector containing the values of individuals
|
| 15 |
+
% fitness.
|
| 16 |
+
%
|
| 17 |
+
% Smul - Optional scaling parameter (default 2).
|
| 18 |
+
%
|
| 19 |
+
% Output parameters:
|
| 20 |
+
%
|
| 21 |
+
% FitnV - A vector containing the individual fitnesses
|
| 22 |
+
% for the current population.
|
| 23 |
+
%
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Andrew Chipperfield
|
| 27 |
+
% Date: 24-Feb-94
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
function FitnV = scaling( ObjV, Smul )
|
| 31 |
+
|
| 32 |
+
if nargin == 1
|
| 33 |
+
Smul = 2 ;
|
| 34 |
+
end
|
| 35 |
+
|
| 36 |
+
[Nind, Nobj] = size( ObjV ) ;
|
| 37 |
+
Oave = sum( ObjV ) / Nind ;
|
| 38 |
+
Omin = min( ObjV ) ;
|
| 39 |
+
Omax = max( ObjV ) ;
|
| 40 |
+
|
| 41 |
+
if (Omin > ( Smul * Oave - Omax ) / ( Smul - 1.0 ))
|
| 42 |
+
delta = Omax - Oave
|
| 43 |
+
a = ( Smul - 1.0 ) * Oave / delta
|
| 44 |
+
b = Oave * ( Omax - Smul * Oave ) / delta
|
| 45 |
+
else
|
| 46 |
+
delta = Oave - Omin ;
|
| 47 |
+
a = Oave / delta ;
|
| 48 |
+
b = -Omin * Oave / delta ;
|
| 49 |
+
end
|
| 50 |
+
|
| 51 |
+
FitnV = ObjV.*a + b ;
|
| 52 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/SELECT.M
CHANGED
|
@@ -1,3 +1,69 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% SELECT.M (universal SELECTion)
|
| 2 |
+
%
|
| 3 |
+
% This function performs universal selection. The function handles
|
| 4 |
+
% multiple populations and calls the low level selection function
|
| 5 |
+
% for the actual selection process.
|
| 6 |
+
|
| 7 |
+
%
|
| 8 |
+
% Syntax: SelCh = select(SEL_F, Chrom, FitnV, GGAP, SUBPOP)
|
| 9 |
+
%
|
| 10 |
+
% Input parameters:
|
| 11 |
+
% SEL_F - Name of the selection function
|
| 12 |
+
% Chrom - Matrix containing the individuals (parents) of the current
|
| 13 |
+
% population. Each row corresponds to one individual.
|
| 14 |
+
% FitnV - Column vector containing the fitness values of the
|
| 15 |
+
% individuals in the population.
|
| 16 |
+
% GGAP - (optional) Rate of individuals to be selected
|
| 17 |
+
% if omitted 1.0 is assumed
|
| 18 |
+
% SUBPOP - (optional) Number of subpopulations
|
| 19 |
+
% if omitted 1 subpopulation is assumed
|
| 20 |
+
%
|
| 21 |
+
% Output parameters:
|
| 22 |
+
% SelCh - Matrix containing the selected individuals.
|
| 23 |
+
|
| 24 |
+
% Author: Hartmut Pohlheim
|
| 25 |
+
% History: 10.03.94 file created
|
| 26 |
+
|
| 27 |
+
function SelCh = select(SEL_F, Chrom, FitnV, GGAP, SUBPOP);
|
| 28 |
+
|
| 29 |
+
% Check parameter consistency
|
| 30 |
+
if nargin < 3, error('Not enough input parameter'); end
|
| 31 |
+
|
| 32 |
+
% Identify the population size (Nind)
|
| 33 |
+
[NindCh,Nvar] = size(Chrom);
|
| 34 |
+
[NindF,VarF] = size(FitnV);
|
| 35 |
+
if NindCh ~= NindF, error('Chrom and FitnV disagree'); end
|
| 36 |
+
if VarF ~= 1, error('FitnV must be a column vector'); end
|
| 37 |
+
|
| 38 |
+
if nargin < 5, SUBPOP = 1; end
|
| 39 |
+
if nargin > 4,
|
| 40 |
+
if isempty(SUBPOP), SUBPOP = 1;
|
| 41 |
+
elseif isnan(SUBPOP), SUBPOP = 1;
|
| 42 |
+
elseif length(SUBPOP) ~= 1, error('SUBPOP must be a scalar'); end
|
| 43 |
+
end
|
| 44 |
+
|
| 45 |
+
if (NindCh/SUBPOP) ~= fix(NindCh/SUBPOP), error('Chrom and SUBPOP disagree'); end
|
| 46 |
+
Nind = NindCh/SUBPOP; % Compute number of individuals per subpopulation
|
| 47 |
+
|
| 48 |
+
if nargin < 4, GGAP = 1; end
|
| 49 |
+
if nargin > 3,
|
| 50 |
+
if isempty(GGAP), GGAP = 1;
|
| 51 |
+
elseif isnan(GGAP), GGAP = 1;
|
| 52 |
+
elseif length(GGAP) ~= 1, error('GGAP must be a scalar');
|
| 53 |
+
elseif (GGAP < 0), error('GGAP must be a scalar bigger than 0'); end
|
| 54 |
+
end
|
| 55 |
+
|
| 56 |
+
% Compute number of new individuals (to select)
|
| 57 |
+
NSel=max(floor(Nind*GGAP+.5),2);
|
| 58 |
+
|
| 59 |
+
% Select individuals from population
|
| 60 |
+
SelCh = [];
|
| 61 |
+
for irun = 1:SUBPOP,
|
| 62 |
+
FitnVSub = FitnV((irun-1)*Nind+1:irun*Nind);
|
| 63 |
+
ChrIx=feval(SEL_F, FitnVSub, NSel)+(irun-1)*Nind;
|
| 64 |
+
SelCh=[SelCh; Chrom(ChrIx,:)];
|
| 65 |
+
end
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
% End of function
|
| 69 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/SGA.M
CHANGED
|
@@ -1,3 +1,69 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% sga
|
| 2 |
+
%
|
| 3 |
+
% This script implements the Simple Genetic Algorithm described
|
| 4 |
+
% in the examples section of the GA Toolbox manual.
|
| 5 |
+
%
|
| 6 |
+
|
| 7 |
+
% Author: Andrew Chipperfield
|
| 8 |
+
% History: 23-Mar-94 file created
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
NIND = 40; % Number of individuals per subpopulations
|
| 12 |
+
MAXGEN = 300; % maximum Number of generations
|
| 13 |
+
GGAP = .9; % Generation gap, how many new individuals are created
|
| 14 |
+
NVAR = 20; % Generation gap, how many new individuals are created
|
| 15 |
+
PRECI = 20; % Precision of binary representation
|
| 16 |
+
|
| 17 |
+
% Build field descriptor
|
| 18 |
+
FieldD = [rep([PRECI],[1, NVAR]); rep([-512;512],[1, NVAR]);...
|
| 19 |
+
rep([1; 0; 1 ;1], [1, NVAR])];
|
| 20 |
+
|
| 21 |
+
% Initialise population
|
| 22 |
+
Chrom = crtbp(NIND, NVAR*PRECI);
|
| 23 |
+
|
| 24 |
+
% Reset counters
|
| 25 |
+
Best = NaN*ones(MAXGEN,1); % best in current population
|
| 26 |
+
gen = 0; % generational counter
|
| 27 |
+
|
| 28 |
+
% Evaluate initial population
|
| 29 |
+
ObjV = objfun1(bs2rv(Chrom,FieldD));
|
| 30 |
+
|
| 31 |
+
% Track best individual and display convergence
|
| 32 |
+
Best(gen+1) = min(ObjV);
|
| 33 |
+
plot(log10(Best),'ro');xlabel('generation'); ylabel('log10(f(x))');
|
| 34 |
+
text(0.5,0.95,['Best = ', num2str(Best(gen+1))],'Units','normalized');
|
| 35 |
+
drawnow;
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
% Generational loop
|
| 39 |
+
while gen < MAXGEN,
|
| 40 |
+
|
| 41 |
+
% Assign fitness-value to entire population
|
| 42 |
+
FitnV = ranking(ObjV);
|
| 43 |
+
|
| 44 |
+
% Select individuals for breeding
|
| 45 |
+
SelCh = select('sus', Chrom, FitnV, GGAP);
|
| 46 |
+
|
| 47 |
+
% Recombine selected individuals (crossover)
|
| 48 |
+
SelCh = recombin('xovsp',SelCh,0.7);
|
| 49 |
+
|
| 50 |
+
% Perform mutation on offspring
|
| 51 |
+
SelCh = mut(SelCh);
|
| 52 |
+
|
| 53 |
+
% Evaluate offspring, call objective function
|
| 54 |
+
ObjVSel = objfun1(bs2rv(SelCh,FieldD));
|
| 55 |
+
|
| 56 |
+
% Reinsert offspring into current population
|
| 57 |
+
[Chrom ObjV]=reins(Chrom,SelCh,1,1,ObjV,ObjVSel);
|
| 58 |
+
|
| 59 |
+
% Increment generational counter
|
| 60 |
+
gen = gen+1;
|
| 61 |
+
|
| 62 |
+
% Update display and record current best individual
|
| 63 |
+
Best(gen+1) = min(ObjV);
|
| 64 |
+
plot(log10(Best),'ro'); xlabel('generation'); ylabel('log10(f(x))');
|
| 65 |
+
text(0.5,0.95,['Best = ', num2str(Best(gen+1))],'Units','normalized');
|
| 66 |
+
drawnow;
|
| 67 |
+
end
|
| 68 |
+
% End of GA
|
| 69 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/SUS.M
CHANGED
|
@@ -1,3 +1,41 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% SUS.M (Stochastic Universal Sampling)
|
| 2 |
+
%
|
| 3 |
+
% This function performs selection with STOCHASTIC UNIVERSAL SAMPLING.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: NewChrIx = sus(FitnV, Nsel)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% FitnV - Column vector containing the fitness values of the
|
| 9 |
+
% individuals in the population.
|
| 10 |
+
% Nsel - number of individuals to be selected
|
| 11 |
+
%
|
| 12 |
+
% Output parameters:
|
| 13 |
+
% NewChrIx - column vector containing the indexes of the selected
|
| 14 |
+
% individuals relative to the original population, shuffled.
|
| 15 |
+
% The new population, ready for mating, can be obtained
|
| 16 |
+
% by calculating OldChrom(NewChrIx,:).
|
| 17 |
+
|
| 18 |
+
% Author: Hartmut Pohlheim (Carlos Fonseca)
|
| 19 |
+
% History: 12.12.93 file created
|
| 20 |
+
% 22.02.94 clean up, comments
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
function NewChrIx = sus(FitnV,Nsel);
|
| 24 |
+
|
| 25 |
+
% Identify the population size (Nind)
|
| 26 |
+
[Nind,ans] = size(FitnV);
|
| 27 |
+
|
| 28 |
+
% Perform stochastic universal sampling
|
| 29 |
+
cumfit = cumsum(FitnV);
|
| 30 |
+
trials = cumfit(Nind) / Nsel * (rand + (0:Nsel-1)');
|
| 31 |
+
Mf = cumfit(:, ones(1, Nsel));
|
| 32 |
+
Mt = trials(:, ones(1, Nind))';
|
| 33 |
+
[NewChrIx, ans] = find(Mt < Mf & [ zeros(1, Nsel); Mf(1:Nind-1, :) ] <= Mt);
|
| 34 |
+
|
| 35 |
+
% Shuffle new population
|
| 36 |
+
[ans, shuf] = sort(rand(Nsel, 1));
|
| 37 |
+
NewChrIx = NewChrIx(shuf);
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
% End of function
|
| 41 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/DEMOGA1.M
CHANGED
|
@@ -1,3 +1,118 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% DEMOGA1.M (DEMO of Genetic Algorithms 1)
|
| 2 |
+
%
|
| 3 |
+
% This function displays a number of figures. Select a number of these
|
| 4 |
+
% figures with the mouse by click in the area of the shape. These
|
| 5 |
+
% figure are the parents for the next generation. The offspring are
|
| 6 |
+
% created by recombination and mutation. The user is the selector.
|
| 7 |
+
%
|
| 8 |
+
% The shape of the figures is defined by Points X- and Y-values each.
|
| 9 |
+
% These points are ploted by patch(), each figure in a rectangle.
|
| 10 |
+
% The X- and Y-values are the variables of a individual.
|
| 11 |
+
%
|
| 12 |
+
% Aim of this demo is, to "construct" a special figure, e.g. a square
|
| 13 |
+
% or a star or ..., imagine, what you want and select appropriate.
|
| 14 |
+
%
|
| 15 |
+
% Parameters inside function for changing:
|
| 16 |
+
% Num - Number of figures (4, 9, 16, 25, ...)
|
| 17 |
+
% Points - Number of Points per figure (3, 4, 5...), 5 recommended
|
| 18 |
+
% MAXGEN - Number of generations (more than 30 recommended)
|
| 19 |
+
%
|
| 20 |
+
% Syntax: demoga1();
|
| 21 |
+
%
|
| 22 |
+
% Input parameters:
|
| 23 |
+
% no input parameter
|
| 24 |
+
% Output parameter:
|
| 25 |
+
% no output parameter
|
| 26 |
+
|
| 27 |
+
% Author: Hartmut Pohlheim
|
| 28 |
+
% History: 24.03.94 file created
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
function demoga1();
|
| 32 |
+
|
| 33 |
+
Num = 16; % Number of figures
|
| 34 |
+
Points = 6; % Number of points per figure
|
| 35 |
+
MAXGEN = 30; % Number of generations
|
| 36 |
+
FieldDR = rep([0; 1], [1 Points]); % Fielddescription for mutation
|
| 37 |
+
|
| 38 |
+
% Function needs as many rows as columns, every place has to be filled
|
| 39 |
+
if sqrt(Num) ~= ceil(sqrt(Num)),
|
| 40 |
+
error('sqrt(Num) must be an integer');
|
| 41 |
+
end
|
| 42 |
+
|
| 43 |
+
ColRowNum = ceil(sqrt(Num)); % Number of columns and rows
|
| 44 |
+
Shrink=Num/ColRowNum; % Value for shrinking of area
|
| 45 |
+
SelectNumber = ColRowNum; % Number of parents by selection
|
| 46 |
+
|
| 47 |
+
Cols = 1:1:ColRowNum; % Index of individuals in first columns
|
| 48 |
+
Rows = 1:ColRowNum:Num; % Index of individuals in first row
|
| 49 |
+
|
| 50 |
+
h = figure; % Open a new figure for output
|
| 51 |
+
axes('Position',[0 0 1 1]); % Set axes to whole figure
|
| 52 |
+
set(gca, 'xcolor',[0 0 0]); % Make X-Axis invisible
|
| 53 |
+
set(gca, 'ycolor',[0 0 0]); % Make Y-Axis invisible
|
| 54 |
+
axis('ij'); % Position start in left-upper corner
|
| 55 |
+
axis(axis); % Freeze axes
|
| 56 |
+
|
| 57 |
+
XStart = (Cols(1:ColRowNum-1)/Shrink); % Calculate X-start- and Y-endvalues of lines
|
| 58 |
+
XLine1 = [XStart; XStart]; % between figures
|
| 59 |
+
YLine1 = [zeros(1,ColRowNum-1); ones(1,ColRowNum-1)]; % X-end- and Y-startvalues
|
| 60 |
+
XLine = [XLine1 YLine1]; YLine = [YLine1 XLine1]; % Assemble line vectors
|
| 61 |
+
|
| 62 |
+
MatX=rand(Points,Num); % Create X-values of figures at random
|
| 63 |
+
MatY=rand(Points,Num); % Create Y-values of figures at random
|
| 64 |
+
|
| 65 |
+
for igen = 1:MAXGEN, % Loop over all generations
|
| 66 |
+
|
| 67 |
+
% Recombine individuals
|
| 68 |
+
MatXYOff = recombin('recint', [MatX MatY]',NaN, 2);
|
| 69 |
+
|
| 70 |
+
% Mutate individuals
|
| 71 |
+
MatXYOff = mutbga(MatXYOff, FieldDR, 1/Points);
|
| 72 |
+
|
| 73 |
+
MatXYOff = MatXYOff'; % Invert matrix of individuals
|
| 74 |
+
MatX = MatXYOff(:,1:Num); % Select X- and Y-values
|
| 75 |
+
MatY = MatXYOff(:,size(MatXYOff,2)/2+1:size(MatXYOff,2)/2+Num);
|
| 76 |
+
|
| 77 |
+
PolyMatX = MatX / Shrink; % Shrink X-values for fitting in small area
|
| 78 |
+
PolyMatY = MatY / Shrink; % Shrink Y-values for fitting in small area
|
| 79 |
+
|
| 80 |
+
% Add a value to the X-value for placing individual in the appropriate column
|
| 81 |
+
for irun = 1:ColRowNum-1,
|
| 82 |
+
PolyMatX(:,Rows+irun)=PolyMatX(:,Rows+irun)+(irun)/Shrink;
|
| 83 |
+
end
|
| 84 |
+
|
| 85 |
+
% Add a value to the Y-value for placing individual in the appropriate row
|
| 86 |
+
for irun = 1:ColRowNum-1,
|
| 87 |
+
PolyMatY(:,Cols+(irun*ColRowNum))= ...
|
| 88 |
+
PolyMatY(:,Cols+(irun*ColRowNum))+(irun)/Shrink;
|
| 89 |
+
end
|
| 90 |
+
|
| 91 |
+
cla; % Clear axes, removes all earlier figures
|
| 92 |
+
patch(PolyMatX,PolyMatY,'b'); % Plot shape of figures
|
| 93 |
+
lh = line(XLine, YLine); % Plot lines between figures
|
| 94 |
+
set(lh,'Color',[.6 .6 .6]); % Set linecolor to grey
|
| 95 |
+
|
| 96 |
+
xclick = []; yclick = []; % Reset vectors for storing click points
|
| 97 |
+
for isel = 1:SelectNumber, % Loop for as many points as individuals to select
|
| 98 |
+
set(gcf,'Name',[ ' Select ' int2str(isel) '. figure (of ' ...
|
| 99 |
+
int2str(SelectNumber) ') with mouseclick (Generation ' ...
|
| 100 |
+
int2str(igen) ' of ' int2str(MAXGEN) ')']);
|
| 101 |
+
[xclick1 yclick1] = ginput(1); % get position of mouse click
|
| 102 |
+
xclick = [xclick; xclick1]; yclick = [yclick; yclick1]; % add position to vectors
|
| 103 |
+
end
|
| 104 |
+
|
| 105 |
+
xpos = ceil(xclick * Shrink); % Calculate column of mouse click
|
| 106 |
+
ypos = ceil(yclick * Shrink); % Calculate row of mouse click
|
| 107 |
+
|
| 108 |
+
SelNumber = xpos + ColRowNum * (ypos-1); % Calculate numbers of selected figures
|
| 109 |
+
|
| 110 |
+
% select X- and Y-values of individuals and repeat them
|
| 111 |
+
MatX = rep(MatX(:,SelNumber),[1 ceil(Num/SelectNumber)]);
|
| 112 |
+
MatY = rep(MatY(:,SelNumber),[1 ceil(Num/SelectNumber)]);
|
| 113 |
+
|
| 114 |
+
end
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
% End of function
|
| 118 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/MPGA.M
CHANGED
|
@@ -1,3 +1,127 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% MPGA.M (Multi Population Genetic Algorithm)
|
| 2 |
+
%
|
| 3 |
+
% This script implements the Multi Population Genetic Algorithm.
|
| 4 |
+
% Real valued representation for the individuals is used.
|
| 5 |
+
%
|
| 6 |
+
% Author: Hartmut Pohlheim
|
| 7 |
+
% History: 23.03.94 file created
|
| 8 |
+
|
| 9 |
+
GGAP = .8; % Generation gap, how many new individuals are created
|
| 10 |
+
INSR = .9; % Insertion rate, how many of the offspring are inserted
|
| 11 |
+
XOVR = 1; % Crossover rate
|
| 12 |
+
SP = 2; % Selective Pressure
|
| 13 |
+
MUTR = 1; % Mutation rate; only a factor;
|
| 14 |
+
MIGR = 0.2; % Migration rate between subpopulations
|
| 15 |
+
MIGGEN = 20; % Number of generations between migration (isolation time)
|
| 16 |
+
|
| 17 |
+
TERMEXACT = 1e-4; % Value for termination if minimum reached
|
| 18 |
+
|
| 19 |
+
SEL_F = 'sus'; % Name of selection function
|
| 20 |
+
XOV_F = 'recdis'; % Name of recombination function for individuals
|
| 21 |
+
MUT_F = 'mutbga'; % Name of mutation function
|
| 22 |
+
|
| 23 |
+
OBJ_F = 'objharv'; % Name of function for objective values
|
| 24 |
+
|
| 25 |
+
% Get boundaries of objective function
|
| 26 |
+
FieldDR = feval(OBJ_F,[],1);
|
| 27 |
+
|
| 28 |
+
% compute SUBPOP, NIND depending on number of variables (defined in objective function)
|
| 29 |
+
NVAR = size(FieldDR,2); % Get number of variables from objective function
|
| 30 |
+
SUBPOP = 2 * floor(sqrt(NVAR)); % Number of subpopulations
|
| 31 |
+
NIND = 20 + 5 * floor(NVAR/50); % Number of individuals per subpopulations
|
| 32 |
+
MAXGEN = 300 * floor(sqrt(NVAR)); % Maximal number of generations
|
| 33 |
+
MUTR = MUTR / NVAR; % Mutation rate depending on NVAR
|
| 34 |
+
|
| 35 |
+
% Get value of minimum, defined in objective function
|
| 36 |
+
GlobalMin = feval(OBJ_F,[],3);
|
| 37 |
+
|
| 38 |
+
% Get title of objective function, defined in objective function
|
| 39 |
+
FigTitle = [feval(OBJ_F,[],2) ' (' int2str(SUBPOP) ':' int2str(MAXGEN) ') '];
|
| 40 |
+
|
| 41 |
+
% Clear Best and storing matrix
|
| 42 |
+
% Initialise Matrix for storing best results
|
| 43 |
+
Best = NaN * ones(MAXGEN,3);
|
| 44 |
+
Best(:,3) = zeros(size(Best,1),1);
|
| 45 |
+
% Matrix for storing best individuals
|
| 46 |
+
IndAll = [];
|
| 47 |
+
|
| 48 |
+
% Create real population
|
| 49 |
+
Chrom = crtrp(SUBPOP*NIND,FieldDR);
|
| 50 |
+
|
| 51 |
+
% reset count variables
|
| 52 |
+
gen = 0;
|
| 53 |
+
termopt = 0;
|
| 54 |
+
|
| 55 |
+
% Calculate objective function for population
|
| 56 |
+
ObjV = feval(OBJ_F,Chrom);
|
| 57 |
+
% count number of objective function evaluations
|
| 58 |
+
Best(gen+1,3) = Best(gen+1,3) + NIND;
|
| 59 |
+
|
| 60 |
+
% Iterate subpopulation till termination or MAXGEN
|
| 61 |
+
while ((gen < MAXGEN) & (termopt == 0)),
|
| 62 |
+
|
| 63 |
+
% Save the best and average objective values and the best individual
|
| 64 |
+
[Best(gen+1,1),ix] = min(ObjV);
|
| 65 |
+
Best(gen+1,2) = mean(ObjV);
|
| 66 |
+
IndAll = [IndAll; Chrom(ix,:)];
|
| 67 |
+
|
| 68 |
+
% Fitness assignement to whole population
|
| 69 |
+
FitnV = ranking(ObjV,[2 0],SUBPOP);
|
| 70 |
+
|
| 71 |
+
% Select individuals from population
|
| 72 |
+
SelCh = select(SEL_F, Chrom, FitnV, GGAP, SUBPOP);
|
| 73 |
+
|
| 74 |
+
% Recombine selected individuals
|
| 75 |
+
SelCh=recombin(XOV_F, SelCh, XOVR, SUBPOP);
|
| 76 |
+
|
| 77 |
+
% Mutate offspring
|
| 78 |
+
SelCh=mutate(MUT_F, SelCh, FieldDR, [MUTR], SUBPOP);
|
| 79 |
+
|
| 80 |
+
% Calculate objective function for offsprings
|
| 81 |
+
ObjVOff = feval(OBJ_F,SelCh);
|
| 82 |
+
Best(gen+1,3) = Best(gen+1,3) + size(SelCh,1);
|
| 83 |
+
|
| 84 |
+
% Insert best offspring in population replacing worst parents
|
| 85 |
+
[Chrom, ObjV] = reins(Chrom, SelCh, SUBPOP, [1 INSR], ObjV, ObjVOff);
|
| 86 |
+
|
| 87 |
+
gen=gen+1;
|
| 88 |
+
|
| 89 |
+
% Plot some results, rename title of figure for graphic output
|
| 90 |
+
if ((rem(gen,20) == 1) | (rem(gen,MAXGEN) == 0) | (termopt == 1)),
|
| 91 |
+
set(gcf,'Name',[FigTitle ' in ' int2str(gen)]);
|
| 92 |
+
resplot(Chrom(1:2:size(Chrom,1),:),...
|
| 93 |
+
IndAll(max(1,gen-39):size(IndAll,1),:),...
|
| 94 |
+
[ObjV; GlobalMin], Best(max(1,gen-19):gen,[1 2]), gen);
|
| 95 |
+
end
|
| 96 |
+
|
| 97 |
+
% Check, if best objective value near GlobalMin -> termination criterion
|
| 98 |
+
% compute differenz between GlobalMin and best objective value
|
| 99 |
+
ActualMin = abs(min(ObjV) - GlobalMin);
|
| 100 |
+
% if ActualMin smaller than TERMEXACT --> termination
|
| 101 |
+
if ((ActualMin < (TERMEXACT * abs(GlobalMin))) | (ActualMin < TERMEXACT))
|
| 102 |
+
termopt = 1;
|
| 103 |
+
end
|
| 104 |
+
|
| 105 |
+
% migrate individuals between subpopulations
|
| 106 |
+
if ((termopt ~= 1) & (rem(gen,MIGGEN) == 0))
|
| 107 |
+
[Chrom, ObjV] = migrate(Chrom, SUBPOP, [MIGR, 1, 0], ObjV);
|
| 108 |
+
end
|
| 109 |
+
|
| 110 |
+
end
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
% Results
|
| 114 |
+
% add number of objective function evaluations
|
| 115 |
+
Results = cumsum(Best(1:gen,3));
|
| 116 |
+
% number of function evaluation, mean and best results
|
| 117 |
+
Results = [Results Best(1:gen,2) Best(1:gen,1)];
|
| 118 |
+
|
| 119 |
+
% Plot Results and show best individuals => optimum
|
| 120 |
+
figure('Name',['Results of ' FigTitle]);
|
| 121 |
+
subplot(2,1,1), plot(Results(:,1),Results(:,2),'-',Results(:,1),Results(:,3),':');
|
| 122 |
+
subplot(2,1,2), plot(IndAll(gen-4:gen,:)');
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
% End of script
|
| 126 |
+
|
| 127 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJBRAN.M
CHANGED
|
@@ -1,3 +1,69 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJBRAN.M (OBJective function for BRANin RCOS function)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the BRANIN RCOS function.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objbran(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then speziell values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 25.11.93 file created
|
| 28 |
+
% 27.11.93 text of title and switch added
|
| 29 |
+
% 16.12.93 switch == 3, return value of global minimum
|
| 30 |
+
% 01.03.94 name changed in obj*
|
| 31 |
+
|
| 32 |
+
function ObjVal = objbran(Chrom,switch);
|
| 33 |
+
|
| 34 |
+
% Compute population parameters
|
| 35 |
+
[Nind,Nvar] = size(Chrom);
|
| 36 |
+
|
| 37 |
+
% Check size of Chrom and do the appropriate thing
|
| 38 |
+
% if Chrom is []
|
| 39 |
+
if Nind == 0
|
| 40 |
+
% return text of title for graphic output
|
| 41 |
+
if switch == 2
|
| 42 |
+
ObjVal = 'BRANINs RCOS function';
|
| 43 |
+
% return value of global minimum
|
| 44 |
+
elseif switch == 3
|
| 45 |
+
ObjVal = 0.397887;
|
| 46 |
+
% define size of boundary-matrix and values
|
| 47 |
+
else
|
| 48 |
+
% x1 x2
|
| 49 |
+
ObjVal = [-5 0; % lower bounds
|
| 50 |
+
10 15]; % upper bounds
|
| 51 |
+
end
|
| 52 |
+
% if two variables, compute values of function
|
| 53 |
+
elseif Nvar == 2
|
| 54 |
+
% BRANIN's RCOS function
|
| 55 |
+
% -5 <= x1 <= 10 ; 0 <= x2 <= 15
|
| 56 |
+
% global minimum at (x1,x2)=(-pi,12.275), (pi,2.275), and
|
| 57 |
+
% (9.42478,2.475) ; fmin=0.397887
|
| 58 |
+
x1 = Chrom(:,1);
|
| 59 |
+
x2 = Chrom(:,2);
|
| 60 |
+
ObjVal = 1*(x2-(5.1/(4*pi^2))*x1.^2+(5/pi)*x1-6).^2+10*(1-(1/(8*pi))).*cos(x1)+10;
|
| 61 |
+
% otherwise error, wrong format of Chrom
|
| 62 |
+
else
|
| 63 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 64 |
+
end
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
% End of function
|
| 68 |
+
|
| 69 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJDOPI.M
CHANGED
|
@@ -1,3 +1,107 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJDOPI.M (OBJective function for DOuble Integrator)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the Double Integrator.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objdopi(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then special values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 17.12.93 file created (copy of valfun7.m)
|
| 28 |
+
% 19.12.93 Dim reintroduced
|
| 29 |
+
% Dim and STEPSIMU independend from each other, rk23
|
| 30 |
+
% can compute control between times
|
| 31 |
+
% 01.03.94 name changed in obj*
|
| 32 |
+
% 05.04.94 trapz used
|
| 33 |
+
|
| 34 |
+
function [ObjVal,t,x] = objdopi(Chrom,switch);
|
| 35 |
+
|
| 36 |
+
% Define used method
|
| 37 |
+
method = 1; % 1 - sim: simulink model
|
| 38 |
+
% 2 - ode: ordinary differential equations
|
| 39 |
+
% 3 - con: transfer function to state space
|
| 40 |
+
|
| 41 |
+
% Dimension of objective function
|
| 42 |
+
Dim = 20;
|
| 43 |
+
TSTART = 0;
|
| 44 |
+
TEND = 1;
|
| 45 |
+
STEPSIMU = min(0.1,abs((TEND-TSTART)/(Dim-1)));
|
| 46 |
+
TIMEVEC = linspace(TSTART,TEND,Dim)';
|
| 47 |
+
|
| 48 |
+
% initial conditions
|
| 49 |
+
XINIT = [ 0; -1];
|
| 50 |
+
|
| 51 |
+
% end conditions
|
| 52 |
+
XEND = [ 0; 0];
|
| 53 |
+
|
| 54 |
+
% weights for control and end
|
| 55 |
+
XENDWEIGHT = 12 * [1; 1]; % XEND(1); XEND(2)
|
| 56 |
+
UWEIGHT = [0.5]; % Control vector
|
| 57 |
+
|
| 58 |
+
% Compute population parameters
|
| 59 |
+
[Nind,Nvar] = size(Chrom);
|
| 60 |
+
|
| 61 |
+
% Check size of Chrom and do the appropriate thing
|
| 62 |
+
% if Chrom is [], then
|
| 63 |
+
if Nind == 0
|
| 64 |
+
% return text of title for graphic output
|
| 65 |
+
if switch == 2
|
| 66 |
+
if method == 2, ObjVal = ['Double Integrator (ode)-' int2str(Dim)];
|
| 67 |
+
elseif method == 3, ObjVal = ['Double Integrator (con)-' int2str(Dim)];
|
| 68 |
+
else ObjVal = ['Double Integrator (sim)-' int2str(Dim)];
|
| 69 |
+
end
|
| 70 |
+
% return value of global minimum
|
| 71 |
+
elseif switch == 3
|
| 72 |
+
ObjVal = 2; % UWEIGHT * 3 * (TEND - TSTART);
|
| 73 |
+
% define size of boundary-matrix and values
|
| 74 |
+
else
|
| 75 |
+
% lower and upper bound, identical for all n variables
|
| 76 |
+
ObjVal1 = [-15; 15];
|
| 77 |
+
ObjVal = rep(ObjVal1,[1 Dim]);
|
| 78 |
+
end
|
| 79 |
+
% if Dim variables, compute values of function
|
| 80 |
+
elseif Nvar == Dim
|
| 81 |
+
if method == 3, % Convert transfer function to state space system
|
| 82 |
+
[Ai2 Bi2 Ci2 Di2] = tf2ss(1, [1 0 0]);
|
| 83 |
+
t = TIMEVEC;
|
| 84 |
+
end
|
| 85 |
+
ObjVal = zeros(Nind,1);
|
| 86 |
+
for indrun = 1:Nind
|
| 87 |
+
steuerung = [TIMEVEC [Chrom(indrun,:)]'];
|
| 88 |
+
if method == 2,
|
| 89 |
+
[t x] = rk23('simdopi2',[TSTART TEND],XINIT,[1e-3;STEPSIMU;STEPSIMU],steuerung);
|
| 90 |
+
elseif method == 3,
|
| 91 |
+
[y x] = lsim(Ai2, Bi2, Ci2, Di2, Chrom(indrun,:),TIMEVEC, XINIT);
|
| 92 |
+
else
|
| 93 |
+
[t x] = rk23('simdopi1',[TSTART TEND],[],[1e-3;STEPSIMU;STEPSIMU],steuerung);
|
| 94 |
+
end
|
| 95 |
+
% Calculate objective function, endvalues, trapez-integration for control vector
|
| 96 |
+
ObjVal(indrun) = sum(XENDWEIGHT .* abs( x(size(x,1),:)' - XEND )) + ...
|
| 97 |
+
(UWEIGHT / (Dim-1) * trapz(Chrom(indrun,:).^2));
|
| 98 |
+
end
|
| 99 |
+
% otherwise error, wrong format of Chrom
|
| 100 |
+
else
|
| 101 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 102 |
+
end
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
% End of function
|
| 106 |
+
|
| 107 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJEASO.M
CHANGED
|
@@ -1,3 +1,69 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJEASO.M (OBJective function for EASom function)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the EASOM function.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objeaso(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then speziell values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 25.11.93 file created
|
| 28 |
+
% 27.11.93 text of title and switch added
|
| 29 |
+
% 16.12.93 switch == 3, return value of global minimum
|
| 30 |
+
% 01.03.94 name changed in obj*
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
function ObjVal = objeaso(Chrom,switch);
|
| 34 |
+
|
| 35 |
+
% Compute population parameters
|
| 36 |
+
[Nind,Nvar] = size(Chrom);
|
| 37 |
+
|
| 38 |
+
% Check size of Chrom and do the appropriate thing
|
| 39 |
+
% if Chrom is []
|
| 40 |
+
if Nind == 0
|
| 41 |
+
% return text of title for graphic output
|
| 42 |
+
if switch == 2
|
| 43 |
+
ObjVal = 'EASOMs function';
|
| 44 |
+
% return value of global minimum
|
| 45 |
+
elseif switch == 3
|
| 46 |
+
ObjVal = -1;
|
| 47 |
+
% define size of boundary-matrix and values
|
| 48 |
+
else
|
| 49 |
+
% x1 x2
|
| 50 |
+
ObjVal = [-100 -100; % lower bounds
|
| 51 |
+
100 100]; % upper bounds
|
| 52 |
+
end
|
| 53 |
+
% if two variables, compute values of function
|
| 54 |
+
elseif Nvar == 2
|
| 55 |
+
% EASOM's function
|
| 56 |
+
% -100(-5) <= x1 <= 100(5) ; -100(-5) <= x2 <= 100(5)
|
| 57 |
+
% global minimum at (x1,x2)=(pi,pi) ; fmin=-1
|
| 58 |
+
x1 = Chrom(:,1);
|
| 59 |
+
x2 = Chrom(:,2);
|
| 60 |
+
ObjVal = -cos(x1).*cos(x2).*exp(-((x1-pi).^2+(x2-pi).^2));
|
| 61 |
+
% otherwise error, wrong format of Chrom
|
| 62 |
+
else
|
| 63 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 64 |
+
end
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
% End of function
|
| 68 |
+
|
| 69 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN1.M
CHANGED
|
@@ -1,3 +1,71 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJFUN1.M (OBJective function for de jong's FUNction 1)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the DE JONG function 1.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objfun1(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then special values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 26.11.93 file created
|
| 28 |
+
% 27.11.93 text of title and switch added
|
| 29 |
+
% 30.11.93 show Dim in figure titel
|
| 30 |
+
% 16.12.93 switch == 3, return value of global minimum
|
| 31 |
+
% 01.03.94 name changed in obj*
|
| 32 |
+
|
| 33 |
+
function ObjVal = objfun1(Chrom,switch);
|
| 34 |
+
|
| 35 |
+
% Dimension of objective function
|
| 36 |
+
Dim = 20;
|
| 37 |
+
|
| 38 |
+
% Compute population parameters
|
| 39 |
+
[Nind,Nvar] = size(Chrom);
|
| 40 |
+
|
| 41 |
+
% Check size of Chrom and do the appropriate thing
|
| 42 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 43 |
+
if Nind == 0
|
| 44 |
+
% return text of title for graphic output
|
| 45 |
+
if switch == 2
|
| 46 |
+
ObjVal = ['DE JONG function 1-' int2str(Dim)];
|
| 47 |
+
% return value of global minimum
|
| 48 |
+
elseif switch == 3
|
| 49 |
+
ObjVal = 0;
|
| 50 |
+
% define size of boundary-matrix and values
|
| 51 |
+
else
|
| 52 |
+
% lower and upper bound, identical for all n variables
|
| 53 |
+
ObjVal = 100*[-5.12; 5.12];
|
| 54 |
+
ObjVal = ObjVal(1:2,ones(Dim,1));
|
| 55 |
+
end
|
| 56 |
+
% if Dim variables, compute values of function
|
| 57 |
+
elseif Nvar == Dim
|
| 58 |
+
% function 1, sum of xi^2 for i = 1:Dim (Dim=30)
|
| 59 |
+
% n = Dim, -5.12 <= xi <= 5.12
|
| 60 |
+
% global minimum at (xi)=(0) ; fmin=0
|
| 61 |
+
ObjVal = sum((Chrom .* Chrom)')';
|
| 62 |
+
% ObjVal = diag(Chrom * Chrom'); % both lines produce the same
|
| 63 |
+
% otherwise error, wrong format of Chrom
|
| 64 |
+
else
|
| 65 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 66 |
+
end
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
% End of function
|
| 70 |
+
|
| 71 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN1A.M
CHANGED
|
@@ -1,3 +1,68 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJFUN1A.M (OBJective function for axis parallel hyper-ellipsoid)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the axis parallel hyper-ellipsoid.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objfun1a(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then special values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 07.04.94 file created
|
| 28 |
+
|
| 29 |
+
function ObjVal = objfun1a(Chrom,switch);
|
| 30 |
+
|
| 31 |
+
% Dimension of objective function
|
| 32 |
+
Dim = 10;
|
| 33 |
+
|
| 34 |
+
% Compute population parameters
|
| 35 |
+
[Nind,Nvar] = size(Chrom);
|
| 36 |
+
|
| 37 |
+
% Check size of Chrom and do the appropriate thing
|
| 38 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 39 |
+
if Nind == 0
|
| 40 |
+
% return text of title for graphic output
|
| 41 |
+
if switch == 2
|
| 42 |
+
ObjVal = ['Axis Parallel Hyper-Ellipsoid 1a-' int2str(Dim)];
|
| 43 |
+
% return value of global minimum
|
| 44 |
+
elseif switch == 3
|
| 45 |
+
ObjVal = 0;
|
| 46 |
+
% define size of boundary-matrix and values
|
| 47 |
+
else
|
| 48 |
+
% lower and upper bound, identical for all n variables
|
| 49 |
+
ObjVal = 100*[-5.12; 5.12];
|
| 50 |
+
ObjVal = ObjVal(1:2,ones(Dim,1));
|
| 51 |
+
end
|
| 52 |
+
% if Dim variables, compute values of function
|
| 53 |
+
elseif Nvar == Dim
|
| 54 |
+
% function 1a, sum of i * xi^2 for i = 1:Dim (Dim=30)
|
| 55 |
+
% n = Dim, -5.12 <= xi <= 5.12
|
| 56 |
+
% global minimum at (xi)=(0) ; fmin=0
|
| 57 |
+
nummer = rep(1:Dim,[Nind 1]);
|
| 58 |
+
ObjVal = sum((nummer .* (Chrom .* Chrom))')';
|
| 59 |
+
% ObjVal = diag((nummer .* (Chrom * Chrom))'); % both lines produce the same
|
| 60 |
+
% otherwise error, wrong format of Chrom
|
| 61 |
+
else
|
| 62 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 63 |
+
end
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
% End of function
|
| 67 |
+
|
| 68 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN1B.M
CHANGED
|
@@ -1,3 +1,66 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJFUN1B.M (OBJective function for rotated hyper-ellipsoid)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the rotated hyper-ellipsoid.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objfun1b(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then special values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 07.04.94 file created
|
| 28 |
+
|
| 29 |
+
function ObjVal = objfun1b(Chrom,switch);
|
| 30 |
+
|
| 31 |
+
% Dimension of objective function
|
| 32 |
+
Dim = 10;
|
| 33 |
+
|
| 34 |
+
% Compute population parameters
|
| 35 |
+
[Nind,Nvar] = size(Chrom);
|
| 36 |
+
|
| 37 |
+
% Check size of Chrom and do the appropriate thing
|
| 38 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 39 |
+
if Nind == 0
|
| 40 |
+
% return text of title for graphic output
|
| 41 |
+
if switch == 2
|
| 42 |
+
ObjVal = ['Rotated Hyper-Ellipsoid 1b-' int2str(Dim)];
|
| 43 |
+
% return value of global minimum
|
| 44 |
+
elseif switch == 3
|
| 45 |
+
ObjVal = 0;
|
| 46 |
+
% define size of boundary-matrix and values
|
| 47 |
+
else
|
| 48 |
+
% lower and upper bound, identical for all n variables
|
| 49 |
+
ObjVal = [-65; 65];
|
| 50 |
+
ObjVal = ObjVal(1:2,ones(Dim,1));
|
| 51 |
+
end
|
| 52 |
+
% if Dim variables, compute values of function
|
| 53 |
+
elseif Nvar == Dim
|
| 54 |
+
% function 1b, sum over i of ( sum of xj )^2 for i = 1:Dim, j = 1:i (Dim=30)
|
| 55 |
+
% n = Dim, -65 <= xj <= 65
|
| 56 |
+
% global minimum at (xi)=(0) ; fmin=0
|
| 57 |
+
ObjVal = sum(cumsum(Chrom').^2)';
|
| 58 |
+
% otherwise error, wrong format of Chrom
|
| 59 |
+
else
|
| 60 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 61 |
+
end
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
% End of function
|
| 65 |
+
|
| 66 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN2.M
CHANGED
|
@@ -1,3 +1,72 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJFUN2.M (OBJective function for rosenbrock's FUNction)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the ROSENBROCK valley (DE JONG's Function 2).
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objfun2(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one
|
| 10 |
+
% individual's string representation.
|
| 11 |
+
% if called with Chrom == [], then boundaries of
|
| 12 |
+
% the function or title for figure will be returned
|
| 13 |
+
% switch - if Chrom == [] and switch == 1 (or []) then return
|
| 14 |
+
% boundaries, if switch == 2 return title
|
| 15 |
+
%
|
| 16 |
+
% Output parameters:
|
| 17 |
+
% ObjVal - Column vector containing the objective values of the
|
| 18 |
+
% individuals in the current population.
|
| 19 |
+
% if called with Chrom == [], then ObjVal contains
|
| 20 |
+
% the matrix with the boundaries of the function or
|
| 21 |
+
% the Text for the title of the graphic output
|
| 22 |
+
%
|
| 23 |
+
|
| 24 |
+
% Author: Hartmut Pohlheim
|
| 25 |
+
% History: 26.01.94 file created
|
| 26 |
+
% 01.03.94 name changed in obj*
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
function ObjVal = objfun2(Chrom,switch);
|
| 30 |
+
|
| 31 |
+
% Dimension of objective function
|
| 32 |
+
Dim = 2;
|
| 33 |
+
|
| 34 |
+
% Compute population parameters
|
| 35 |
+
[Nind,Nvar] = size(Chrom);
|
| 36 |
+
|
| 37 |
+
% Check size of Chrom and do the appropriate thing
|
| 38 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 39 |
+
if Nind == 0
|
| 40 |
+
% return text of title for graphic output
|
| 41 |
+
if switch == 2
|
| 42 |
+
ObjVal = ['ROSENBROCKs function 2-' int2str(Dim)];
|
| 43 |
+
% return value of global minimum
|
| 44 |
+
elseif switch == 3
|
| 45 |
+
ObjVal = 0;
|
| 46 |
+
% define size of boundary-matrix and values
|
| 47 |
+
else
|
| 48 |
+
% lower and upper bound, identical for all n variables
|
| 49 |
+
ObjVal = [-2; 2];
|
| 50 |
+
ObjVal = ObjVal(1:2,ones(Dim,1));
|
| 51 |
+
end
|
| 52 |
+
% if Dim variables, compute values of function
|
| 53 |
+
elseif Nvar == Dim
|
| 54 |
+
% function 11, sum of 100* (x(i+1) -xi^2)^2+(1-xi)^2 for i = 1:Dim (Dim=10)
|
| 55 |
+
% n = Dim, -10 <= xi <= 10
|
| 56 |
+
% global minimum at (xi)=(1) ; fmin=0
|
| 57 |
+
Mat1 = Chrom(:,1:Nvar-1);
|
| 58 |
+
Mat2 = Chrom(:,2:Nvar);
|
| 59 |
+
if Dim == 2
|
| 60 |
+
ObjVal = 100*(Mat2-Mat1.^2).^2+(1-Mat1).^2;
|
| 61 |
+
else
|
| 62 |
+
ObjVal = sum((100*(Mat2-Mat1.^2).^2+(1-Mat1).^2)')';
|
| 63 |
+
end
|
| 64 |
+
% otherwise error, wrong format of Chrom
|
| 65 |
+
else
|
| 66 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 67 |
+
end
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
% End of function
|
| 71 |
+
|
| 72 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN6.M
CHANGED
|
@@ -1,3 +1,73 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJFUN6.M (OBJective function for rastrigins FUNction 6)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the RASTRIGIN function 6.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objfun6(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then speziell values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 26.11.93 file created
|
| 28 |
+
% 27.11.93 text of title and switch added
|
| 29 |
+
% 30.11.93 show Dim in figure titel
|
| 30 |
+
% 16.12.93 switch == 3, return value of global minimum
|
| 31 |
+
% 01.03.94 name changed in obj*
|
| 32 |
+
|
| 33 |
+
function ObjVal = objfun6(Chrom,switch);
|
| 34 |
+
|
| 35 |
+
% Dimension of objective function
|
| 36 |
+
Dim = 20;
|
| 37 |
+
|
| 38 |
+
% Compute population parameters
|
| 39 |
+
[Nind,Nvar] = size(Chrom);
|
| 40 |
+
|
| 41 |
+
% Check size of Chrom and do the appropriate thing
|
| 42 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 43 |
+
if Nind == 0
|
| 44 |
+
% return text of title for graphic output
|
| 45 |
+
if switch == 2
|
| 46 |
+
ObjVal = ['RASTRIGINs function 6-' int2str(Dim)];
|
| 47 |
+
% return value of global minimum
|
| 48 |
+
elseif switch == 3
|
| 49 |
+
ObjVal = 0;
|
| 50 |
+
% define size of boundary-matrix and values
|
| 51 |
+
else
|
| 52 |
+
% lower and upper bound, identical for all n variables
|
| 53 |
+
ObjVal = [-5.12; 5.12];
|
| 54 |
+
ObjVal = ObjVal(1:2,ones(Dim,1));
|
| 55 |
+
end
|
| 56 |
+
% if Dim variables, compute values of function
|
| 57 |
+
elseif Nvar == Dim
|
| 58 |
+
% function 6, Dim*A + sum of (xi^2 - A*cos(Omega*xi)) for i = 1:Dim (Dim=20)
|
| 59 |
+
% n = Dim, -5.12 <= xi <= 5.12
|
| 60 |
+
% global minimum at (xi)=(0) ; fmin=0
|
| 61 |
+
A = 10;
|
| 62 |
+
Omega = 2 * pi;
|
| 63 |
+
ObjVal = Dim * A + sum(((Chrom .* Chrom) - A * cos(Omega * Chrom))')';
|
| 64 |
+
% ObjVal = diag(Chrom * Chrom'); % both lines produce the same
|
| 65 |
+
% otherwise error, wrong format of Chrom
|
| 66 |
+
else
|
| 67 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 68 |
+
end
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
% End of function
|
| 72 |
+
|
| 73 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN7.M
CHANGED
|
@@ -1,3 +1,68 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJFUN7.M (OBJective function for schwefel's FUNction)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the SCHWEFEL function 7.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objfun7(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one
|
| 10 |
+
% individual's string representation.
|
| 11 |
+
% if called with Chrom == [], then boundaries of
|
| 12 |
+
% the function or title for figure will be returned
|
| 13 |
+
% switch - if Chrom == [] and switch == 1 (or []) then return
|
| 14 |
+
% boundaries, if switch == 2 return title
|
| 15 |
+
%
|
| 16 |
+
% Output parameters:
|
| 17 |
+
% ObjVal - Column vector containing the objective values of the
|
| 18 |
+
% individuals in the current population.
|
| 19 |
+
% if called with Chrom == [], then ObjVal contains
|
| 20 |
+
% the matrix with the boundaries of the function or
|
| 21 |
+
% the Text for the title of the graphic output
|
| 22 |
+
%
|
| 23 |
+
|
| 24 |
+
% Author: Hartmut Pohlheim
|
| 25 |
+
% History: 27.11.93 file created
|
| 26 |
+
% 30.11.93 show Dim in figure titel
|
| 27 |
+
% 01.03.94 name changed in obj*
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
function ObjVal = objfun7(Chrom,switch);
|
| 31 |
+
|
| 32 |
+
% Dimension of objective function
|
| 33 |
+
Dim = 20;
|
| 34 |
+
|
| 35 |
+
% Compute population parameters
|
| 36 |
+
[Nind,Nvar] = size(Chrom);
|
| 37 |
+
|
| 38 |
+
% Check size of Chrom and do the appropriate thing
|
| 39 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 40 |
+
if Nind == 0
|
| 41 |
+
% return text of title for graphic output
|
| 42 |
+
if switch == 2
|
| 43 |
+
ObjVal = ['SCHWEFELs function 7-' int2str(Dim)];
|
| 44 |
+
% return value of global minimum
|
| 45 |
+
elseif switch == 3
|
| 46 |
+
xmin = 420.9687;
|
| 47 |
+
ObjVal = Dim * (-xmin * sin(sqrt(abs(xmin))));
|
| 48 |
+
% define size of boundary-matrix and values
|
| 49 |
+
else
|
| 50 |
+
% lower and upper bound, identical for all n variables
|
| 51 |
+
ObjVal = [-500; 500];
|
| 52 |
+
ObjVal = ObjVal(1:2,ones(Dim,1));
|
| 53 |
+
end
|
| 54 |
+
% if Dim variables, compute values of function
|
| 55 |
+
elseif Nvar == Dim
|
| 56 |
+
% function 7, sum of -xi*sin(sqrt(abs(xi))) for i = 1:Dim (Dim=10)
|
| 57 |
+
% n = Dim, -500 <= xi <= 500
|
| 58 |
+
% global minimum at (xi)=(420.9687) ; fmin=?
|
| 59 |
+
ObjVal = sum((-Chrom .* sin(sqrt(abs(Chrom))))')';
|
| 60 |
+
% otherwise error, wrong format of Chrom
|
| 61 |
+
else
|
| 62 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 63 |
+
end
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
% End of function
|
| 67 |
+
|
| 68 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN8.M
CHANGED
|
@@ -1,3 +1,72 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJFUN8.M (OBJective function for griewangk's FUNction)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the GRIEWANGK function 8.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objfun8(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then speziell values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 12.12.93 file created (copy of valfun7.m)
|
| 28 |
+
% 16.12.93 switch == 3, return value of global minimum
|
| 29 |
+
% 27.01.94 20* in formula, correction ??
|
| 30 |
+
% 01.03.94 name changed in obj*
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
function ObjVal = objfun8(Chrom,switch);
|
| 34 |
+
|
| 35 |
+
% Dimension of objective function
|
| 36 |
+
Dim = 10;
|
| 37 |
+
|
| 38 |
+
% Compute population parameters
|
| 39 |
+
[Nind,Nvar] = size(Chrom);
|
| 40 |
+
|
| 41 |
+
% Check size of Chrom and do the appropriate thing
|
| 42 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 43 |
+
if Nind == 0
|
| 44 |
+
% return text of title for graphic output
|
| 45 |
+
if switch == 2
|
| 46 |
+
ObjVal = ['GRIEWANGKs function 8-' int2str(Dim)];
|
| 47 |
+
% return value of global minimum
|
| 48 |
+
elseif switch == 3
|
| 49 |
+
ObjVal = 0;
|
| 50 |
+
% define size of boundary-matrix and values
|
| 51 |
+
else
|
| 52 |
+
% lower and upper bound, identical for all n variables
|
| 53 |
+
ObjVal = [-600; 600];
|
| 54 |
+
ObjVal = ObjVal(1:2,ones(Dim,1));
|
| 55 |
+
end
|
| 56 |
+
% if Dim variables, compute values of function
|
| 57 |
+
elseif Nvar == Dim
|
| 58 |
+
% function 8, sum(xi^2/4000) - 20*prod(cos(xi/sqrt(i))) + 1 for i = 1:Dim (Dim=10)
|
| 59 |
+
% n = Dim, -600 <= xi <= 600
|
| 60 |
+
% global minimum at (xi)=(0) ; fmin=0
|
| 61 |
+
% nummer = 1:Dim;
|
| 62 |
+
nummer = rep(1:Dim,[Nind 1]);
|
| 63 |
+
ObjVal = sum(((Chrom.^2) / 4000)')' - prod(cos(Chrom ./ sqrt(nummer))')' + 1;
|
| 64 |
+
% otherwise error, wrong format of Chrom
|
| 65 |
+
else
|
| 66 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 67 |
+
end
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
% End of function
|
| 71 |
+
|
| 72 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJFUN9.M
CHANGED
|
@@ -1,3 +1,67 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJFUN9.M (OBJective function for sum of different power FUNction 9)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the sum of different power.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objfun9(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then special values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 07.04.94 file created
|
| 28 |
+
|
| 29 |
+
function ObjVal = objfun9(Chrom,switch);
|
| 30 |
+
|
| 31 |
+
% Dimension of objective function
|
| 32 |
+
Dim = 10;
|
| 33 |
+
|
| 34 |
+
% Compute population parameters
|
| 35 |
+
[Nind,Nvar] = size(Chrom);
|
| 36 |
+
|
| 37 |
+
% Check size of Chrom and do the appropriate thing
|
| 38 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 39 |
+
if Nind == 0
|
| 40 |
+
% return text of title for graphic output
|
| 41 |
+
if switch == 2
|
| 42 |
+
ObjVal = ['Sum of different Power 9-' int2str(Dim)];
|
| 43 |
+
% return value of global minimum
|
| 44 |
+
elseif switch == 3
|
| 45 |
+
ObjVal = 0;
|
| 46 |
+
% define size of boundary-matrix and values
|
| 47 |
+
else
|
| 48 |
+
% lower and upper bound, identical for all n variables
|
| 49 |
+
ObjVal = [-1; 1];
|
| 50 |
+
ObjVal = ObjVal(1:2,ones(Dim,1));
|
| 51 |
+
end
|
| 52 |
+
% if Dim variables, compute values of function
|
| 53 |
+
elseif Nvar == Dim
|
| 54 |
+
% function 9, sum of abs(xi)^(i+1) for i = 1:Dim (Dim=30)
|
| 55 |
+
% n = Dim, -1 <= xi <= 1
|
| 56 |
+
% global minimum at (xi)=(0) ; fmin=0
|
| 57 |
+
nummer = rep(1:Dim,[Nind 1]);
|
| 58 |
+
ObjVal = sum((abs(Chrom).^(nummer+1))')';
|
| 59 |
+
% otherwise error, wrong format of Chrom
|
| 60 |
+
else
|
| 61 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 62 |
+
end
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
% End of function
|
| 66 |
+
|
| 67 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJGOLD.M
CHANGED
|
@@ -1,3 +1,71 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJGOLD.M (OBJective function for GOLDstein-price function)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the GOLDSTEIN-PRICE function.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objgold(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then speziell values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 25.11.93 file created
|
| 28 |
+
% 27.11.93 text of title and switch added
|
| 29 |
+
% 16.12.93 switch == 3, return value of global minimum
|
| 30 |
+
% 01.03.94 name changed in obj*
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
function ObjVal = objgold(Chrom,switch);
|
| 34 |
+
|
| 35 |
+
% Compute population parameters
|
| 36 |
+
[Nind,Nvar] = size(Chrom);
|
| 37 |
+
|
| 38 |
+
% Check size of Chrom and do the appropriate thing
|
| 39 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 40 |
+
if Nind == 0
|
| 41 |
+
% return text of title for graphic output
|
| 42 |
+
if switch == 2
|
| 43 |
+
ObjVal = 'GOLDSTEIN-PRICE function';
|
| 44 |
+
% return value of global minimum
|
| 45 |
+
elseif switch == 3
|
| 46 |
+
ObjVal = 3;
|
| 47 |
+
% define size of boundary-matrix and values
|
| 48 |
+
else
|
| 49 |
+
brd = 3;
|
| 50 |
+
% x1 x2
|
| 51 |
+
ObjVal = [-brd -brd; % lower bounds
|
| 52 |
+
brd brd]; % upper bounds
|
| 53 |
+
end
|
| 54 |
+
% if two variables, compute values of function
|
| 55 |
+
elseif Nvar == 2
|
| 56 |
+
% GOLDSTEIN-PRICE function
|
| 57 |
+
% -2 <= x1 <= 2 ; -2 <= x2 <= 2 (or -10 <= xi <= 10)
|
| 58 |
+
% global minimum at (x1,x2)=(0,-1) ; fmin=3
|
| 59 |
+
x1 = Chrom(:,1);
|
| 60 |
+
x2 = Chrom(:,2);
|
| 61 |
+
ObjVal = ((1+(x1+x2+1).^2.*(19-14*x1+3*x1.^2-14*x2+6*x1.*x2+3*x2.^2))...
|
| 62 |
+
.*(30+(2*x1-3*x2).^2.*(18-32*x1+12*x1.^2+48*x2-36*x1.*x2+27*x2.^2)));
|
| 63 |
+
% otherwise error, wrong format of Chrom
|
| 64 |
+
else
|
| 65 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 66 |
+
end
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
% End of function
|
| 70 |
+
|
| 71 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJHARV.M
CHANGED
|
@@ -1,3 +1,78 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJHARV.M (OBJective function for HARVest problem)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the HARVEST PROBLEM.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objharv(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then speziell values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 18.02.94 file created (copy of vallinq.m)
|
| 28 |
+
% 01.03.94 name changed in obj*
|
| 29 |
+
|
| 30 |
+
function ObjVal = objharv(Chrom,switch);
|
| 31 |
+
|
| 32 |
+
% global gen;
|
| 33 |
+
|
| 34 |
+
% Dimension of objective function
|
| 35 |
+
Dim = 20;
|
| 36 |
+
|
| 37 |
+
% values from MICHALEWICZ
|
| 38 |
+
a = 1.1;
|
| 39 |
+
x0 = 100;
|
| 40 |
+
xend = x0;
|
| 41 |
+
XENDWEIGHT = 0.4/(Dim^0.6);
|
| 42 |
+
|
| 43 |
+
% Compute population parameters
|
| 44 |
+
[Nind,Nvar] = size(Chrom);
|
| 45 |
+
|
| 46 |
+
% Check size of Chrom and do the appropriate thing
|
| 47 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 48 |
+
if Nind == 0
|
| 49 |
+
% return text of title for graphic output
|
| 50 |
+
if switch == 2
|
| 51 |
+
ObjVal = ['HARVEST PROBLEM-' int2str(Dim)];
|
| 52 |
+
% return value of global minimum
|
| 53 |
+
elseif switch == 3
|
| 54 |
+
ObjVal = -sqrt(x0*(a^Dim-1)^2/(a^(Dim-1)*(a-1)));
|
| 55 |
+
% define size of boundary-matrix and values
|
| 56 |
+
else
|
| 57 |
+
% lower and upper bound, identical for all n variables
|
| 58 |
+
ObjVal1 = [0; 10*Dim];
|
| 59 |
+
ObjVal = rep(ObjVal1,[1 Dim]);
|
| 60 |
+
end
|
| 61 |
+
% if Dim variables, compute values of function
|
| 62 |
+
elseif Nvar == Dim
|
| 63 |
+
ObjVal = zeros(Nind,1);
|
| 64 |
+
X = rep(x0,[Nind 1]);
|
| 65 |
+
for irun = 1:Nvar,
|
| 66 |
+
X = a*X - Chrom(:,irun);
|
| 67 |
+
end
|
| 68 |
+
X;
|
| 69 |
+
ObjVal = -(sum(sqrt(Chrom)')' - XENDWEIGHT * abs(X-x0));
|
| 70 |
+
% otherwise error, wrong format of Chrom
|
| 71 |
+
else
|
| 72 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 73 |
+
end
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
% End of function
|
| 77 |
+
|
| 78 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJLINQ.M
CHANGED
|
@@ -1,3 +1,86 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJLINQ.M (OBJective function for LINear Quadratic problem)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the discret LINEAR-QUADRATIC PROBLEM.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objlinq(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then special values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 18.02.94 file created (copy of valfun7.m)
|
| 28 |
+
% 01.03.94 name changed in obj*
|
| 29 |
+
|
| 30 |
+
function ObjVal = objlinq(Chrom,switch);
|
| 31 |
+
|
| 32 |
+
% Dimension of objective function
|
| 33 |
+
Dim = 45;
|
| 34 |
+
|
| 35 |
+
% values from MICHALEWICZ
|
| 36 |
+
x0 = 100; % start of X
|
| 37 |
+
var = 1; % 1 - 10 possible
|
| 38 |
+
Para = [ 1 1 1 1 1 16180.3399;
|
| 39 |
+
10 1 1 1 1 109160.7978;
|
| 40 |
+
1000 1 1 1 1 10009990.0200;
|
| 41 |
+
1 10 1 1 1 37015.6212;
|
| 42 |
+
1 1000 1 1 1 287569.3725;
|
| 43 |
+
1 1 0 1 1 16180.3399;
|
| 44 |
+
1 1 1000 1 1 16180.3399;
|
| 45 |
+
1 1 1 0.01 1 10000.5000;
|
| 46 |
+
1 1 1 1 0.01 431004.0987;
|
| 47 |
+
1 1 1 1 100 10000.9999];
|
| 48 |
+
s = Para(var,1); r = Para(var,2); q = Para(var,3);
|
| 49 |
+
a = Para(var,4); b = Para(var,5); GlobalMinimum = Para(var,6);
|
| 50 |
+
|
| 51 |
+
% Compute population parameters
|
| 52 |
+
[Nind,Nvar] = size(Chrom);
|
| 53 |
+
|
| 54 |
+
% Check size of Chrom and do the appropriate thing
|
| 55 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 56 |
+
if Nind == 0
|
| 57 |
+
% return text of title for graphic output
|
| 58 |
+
if switch == 2
|
| 59 |
+
ObjVal = ['Linear-quadratic problem (dis)-' int2str(Dim)];
|
| 60 |
+
% return value of global minimum
|
| 61 |
+
elseif switch == 3
|
| 62 |
+
ObjVal = GlobalMinimum;
|
| 63 |
+
% define size of boundary-matrix and values
|
| 64 |
+
else
|
| 65 |
+
% lower and upper bound, identical for all n variables
|
| 66 |
+
ObjVal1 = [-100 -70 -50; 20 20 20];
|
| 67 |
+
ObjVal = [ObjVal1 rep([-30;20],[1 Dim-3])];
|
| 68 |
+
end
|
| 69 |
+
% if Dim variables, compute values of function
|
| 70 |
+
elseif Nvar == Dim
|
| 71 |
+
ObjVal = zeros(Nind,1);
|
| 72 |
+
X = zeros(Nind,Nvar+1);
|
| 73 |
+
X(:,1) = rep(x0,[Nind 1]);
|
| 74 |
+
for irun = 1:Nvar,
|
| 75 |
+
X(:,irun+1) = a*X(:,irun) + b*Chrom(:,irun);
|
| 76 |
+
end
|
| 77 |
+
ObjVal = q * X(:,Nvar+1).^2 + sum((s * X(:,1:Nvar).^2 + r * Chrom.^2)')';
|
| 78 |
+
% otherwise error, wrong format of Chrom
|
| 79 |
+
else
|
| 80 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 81 |
+
end
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
% End of function
|
| 85 |
+
|
| 86 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJLINQ2.M
CHANGED
|
@@ -1,3 +1,105 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJLINQ2.M (OBJective function for LINear Quadratic problem)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the continuous LINear Quadratic problem.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objlinq2(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then special values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 03.03.94 file created
|
| 28 |
+
% 06.04.94 all linq (sim, ode, con) in 1 file
|
| 29 |
+
|
| 30 |
+
function [ObjVal,t,x] = objlinq2(Chrom,switch);
|
| 31 |
+
|
| 32 |
+
% Define used method
|
| 33 |
+
method = 1; % 1 - sim: simulink model
|
| 34 |
+
% 2 - ode: ordinary differential equations
|
| 35 |
+
% 3 - con: transfer function to state space
|
| 36 |
+
|
| 37 |
+
% Dimension of objective function
|
| 38 |
+
Dim = 50;
|
| 39 |
+
TSTART = 0;
|
| 40 |
+
TEND = 1;
|
| 41 |
+
STEPSIMU = min(0.1,abs((TEND-TSTART)/(Dim-1)));
|
| 42 |
+
TIMEVEC = linspace(TSTART,TEND,Dim)';
|
| 43 |
+
|
| 44 |
+
% initial conditions
|
| 45 |
+
XINIT = [100];
|
| 46 |
+
|
| 47 |
+
% end conditions
|
| 48 |
+
XEND = [0];
|
| 49 |
+
|
| 50 |
+
% weights for control and end
|
| 51 |
+
XENDWEIGHT = [20]; % XEND
|
| 52 |
+
XWEIGHT = [2]; % State vector
|
| 53 |
+
UWEIGHT = [1]; % Control vector
|
| 54 |
+
|
| 55 |
+
% Compute population parameters
|
| 56 |
+
[Nind,Nvar] = size(Chrom);
|
| 57 |
+
|
| 58 |
+
% Check size of Chrom and do the appropriate thing
|
| 59 |
+
% if Chrom is [], then
|
| 60 |
+
if Nind == 0
|
| 61 |
+
% return text of title for graphic output
|
| 62 |
+
if switch == 2
|
| 63 |
+
if method == 2, ObjVal = ['Linear-quadratic problem (ode)-' int2str(Dim)];
|
| 64 |
+
elseif method == 3, ObjVal = ['Linear-quadratic problem (con)-' int2str(Dim)];
|
| 65 |
+
else ObjVal = ['Linear-quadratic problem (sim)-' int2str(Dim)];
|
| 66 |
+
end
|
| 67 |
+
% return value of global minimum
|
| 68 |
+
elseif switch == 3
|
| 69 |
+
ObjVal = 16180.3399;
|
| 70 |
+
% define size of boundary-matrix and values
|
| 71 |
+
else
|
| 72 |
+
% lower and upper bound, identical for all n variables
|
| 73 |
+
ObjVal = rep([-600; 0],[1 Dim]);
|
| 74 |
+
end
|
| 75 |
+
% if Dim variables, compute values of function
|
| 76 |
+
elseif Nvar == Dim
|
| 77 |
+
if method == 3, % Convert transfer function to state space system
|
| 78 |
+
[NC DC]=cloop(1, [1 0], +1);
|
| 79 |
+
[Ai2 Bi2 Ci2 Di2] = tf2ss(NC, DC);
|
| 80 |
+
t = TIMEVEC;
|
| 81 |
+
end
|
| 82 |
+
ObjVal = zeros(Nind,1);
|
| 83 |
+
for indrun = 1:Nind
|
| 84 |
+
steuerung = [TIMEVEC Chrom(indrun,:)'];
|
| 85 |
+
if method == 2,
|
| 86 |
+
[t x] = linsim('simlinq2',[TSTART TEND],[],[1e-3;STEPSIMU;STEPSIMU],steuerung);
|
| 87 |
+
elseif method == 3,
|
| 88 |
+
[y x] = lsim(Ai2, Bi2, Ci2, Di2, Chrom(indrun,:),TIMEVEC, XINIT);
|
| 89 |
+
else
|
| 90 |
+
[t x] = linsim('simlinq1',[TSTART TEND],[],[1e-3;STEPSIMU;STEPSIMU],steuerung);
|
| 91 |
+
end
|
| 92 |
+
% Calculate objective function, endvalues, trapez-integration for control vector
|
| 93 |
+
ObjVal(indrun) = (XENDWEIGHT * ( x(size(x,1),:)^2 )) + ...
|
| 94 |
+
(UWEIGHT / (Dim-1) * trapz(Chrom(indrun,:).^2)) + ...
|
| 95 |
+
(XWEIGHT / size(x,1) * sum(x.^2));
|
| 96 |
+
end
|
| 97 |
+
% otherwise error, wrong format of Chrom
|
| 98 |
+
else
|
| 99 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 100 |
+
end
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
% End of function
|
| 104 |
+
|
| 105 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJPUSH.M
CHANGED
|
@@ -1,3 +1,75 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJPUSH.M (OBJective function for PUSH-cart problem)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the PUSH-CART PROBLEM.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objpush(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then speziell values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 19.02.94 file created (copy of valharv.m)
|
| 28 |
+
% 01.03.94 name changed in obj*
|
| 29 |
+
|
| 30 |
+
function ObjVal = objpush(Chrom,switch);
|
| 31 |
+
|
| 32 |
+
% Dimension of objective function
|
| 33 |
+
Dim = 20;
|
| 34 |
+
|
| 35 |
+
% values from MICHALEWICZ
|
| 36 |
+
x0 = [0 0];
|
| 37 |
+
|
| 38 |
+
% Compute population parameters
|
| 39 |
+
[Nind,Nvar] = size(Chrom);
|
| 40 |
+
|
| 41 |
+
% Check size of Chrom and do the appropriate thing
|
| 42 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 43 |
+
if Nind == 0
|
| 44 |
+
% return text of title for graphic output
|
| 45 |
+
if switch == 2
|
| 46 |
+
ObjVal = ['PUSH-CART PROBLEM-' int2str(Dim)];
|
| 47 |
+
% return value of global minimum
|
| 48 |
+
elseif switch == 3
|
| 49 |
+
ObjVal = -(1/3 - ((3*Dim-1)/(6*Dim^2)) - (1/(2*Dim^3))*sum((1:Dim-1).^2));
|
| 50 |
+
% define size of boundary-matrix and values
|
| 51 |
+
else
|
| 52 |
+
% lower and upper bound, identical for all n variables
|
| 53 |
+
ObjVal = [0; 5];
|
| 54 |
+
ObjVal = rep(ObjVal,[1 Dim]);
|
| 55 |
+
end
|
| 56 |
+
% if Dim variables, compute values of function
|
| 57 |
+
elseif Nvar == Dim
|
| 58 |
+
ObjVal = zeros(Nind,1);
|
| 59 |
+
X = rep(x0,[Nind 1]);
|
| 60 |
+
for irun = 1:Nvar,
|
| 61 |
+
Xsave = X;
|
| 62 |
+
X(:,1) = Xsave(:,2);
|
| 63 |
+
X(:,2) = 2 * X(:,2) - Xsave(:,1) + (1/Dim^2) * Chrom(:,irun);
|
| 64 |
+
end
|
| 65 |
+
X;
|
| 66 |
+
ObjVal = -(X(:,1) - (1/(2*Dim)) * sum((Chrom.^2)')');
|
| 67 |
+
% otherwise error, wrong format of Chrom
|
| 68 |
+
else
|
| 69 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 70 |
+
end
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
% End of function
|
| 74 |
+
|
| 75 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/OBJSIXH.M
CHANGED
|
@@ -1,3 +1,68 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% OBJSIXH.M (OBJective function for SIX Hump camelback function)
|
| 2 |
+
%
|
| 3 |
+
% This function implements the six hump camelback function.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: ObjVal = objsixh(Chrom,switch)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each row corresponds to one individual's
|
| 10 |
+
% string representation.
|
| 11 |
+
% if Chrom == [], then speziell values will be returned
|
| 12 |
+
% switch - if Chrom == [] and
|
| 13 |
+
% switch == 1 (or []) return boundaries
|
| 14 |
+
% switch == 2 return title
|
| 15 |
+
% switch == 3 return value of global minimum
|
| 16 |
+
%
|
| 17 |
+
% Output parameters:
|
| 18 |
+
% ObjVal - Column vector containing the objective values of the
|
| 19 |
+
% individuals in the current population.
|
| 20 |
+
% if called with Chrom == [], then ObjVal contains
|
| 21 |
+
% switch == 1, matrix with the boundaries of the function
|
| 22 |
+
% switch == 2, text for the title of the graphic output
|
| 23 |
+
% switch == 3, value of global minimum
|
| 24 |
+
%
|
| 25 |
+
|
| 26 |
+
% Author: Hartmut Pohlheim
|
| 27 |
+
% History: 25.11.93 file created
|
| 28 |
+
% 27.11.93 text of title and switch added
|
| 29 |
+
% 16.12.93 switch == 3, return value of global minimum
|
| 30 |
+
% 01.03.94 name changed in obj*
|
| 31 |
+
|
| 32 |
+
function ObjVal = objsixh(Chrom,switch);
|
| 33 |
+
|
| 34 |
+
% Compute population parameters
|
| 35 |
+
[Nind,Nvar] = size(Chrom);
|
| 36 |
+
|
| 37 |
+
% Check size of Chrom and do the appropriate thing
|
| 38 |
+
% if Chrom is [], then define size of boundary-matrix and values
|
| 39 |
+
if Nind == 0
|
| 40 |
+
% return text of title for graphic output
|
| 41 |
+
if switch == 2
|
| 42 |
+
ObjVal = 'six-hump camelback function';
|
| 43 |
+
% return value of global minimum
|
| 44 |
+
elseif switch == 3
|
| 45 |
+
ObjVal = -1.0316;
|
| 46 |
+
% define size of boundary-matrix and values
|
| 47 |
+
else
|
| 48 |
+
% x1 x2
|
| 49 |
+
ObjVal = [-3 -2; % lower bounds
|
| 50 |
+
3 2]; % upper bounds
|
| 51 |
+
end
|
| 52 |
+
% if two variables, compute values of function
|
| 53 |
+
elseif Nvar == 2
|
| 54 |
+
% six-hump camelback function
|
| 55 |
+
% -3 <= x1 <= 3 ; -2 <= x2 <= 2
|
| 56 |
+
% global minimum at (x1,x2)=(-0.0898,0.7126),(0.0898,-0.7126) ; fmin=-1.0316
|
| 57 |
+
x1 = Chrom(:,1);
|
| 58 |
+
x2 = Chrom(:,2);
|
| 59 |
+
ObjVal = (4-2.1*x1.^2+1/3*x1.^4).*x1.^2+x1.*x2+(-4+4*x2.^2).*x2.^2;
|
| 60 |
+
% otherwise error, wrong format of Chrom
|
| 61 |
+
else
|
| 62 |
+
error('size of matrix Chrom is not correct for function evaluation');
|
| 63 |
+
end
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
% End of function
|
| 67 |
+
|
| 68 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/RESPLOT.M
CHANGED
|
@@ -1,3 +1,55 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% RESPLOT.M (RESult PLOTing)
|
| 2 |
+
%
|
| 3 |
+
% This function plots some of the results during computation.
|
| 4 |
+
%
|
| 5 |
+
% Syntax: resplot(Chrom,IndAll,ObjV,Best,gen)
|
| 6 |
+
%
|
| 7 |
+
% Input parameters:
|
| 8 |
+
% Chrom - Matrix containing the chromosomes of the current
|
| 9 |
+
% population. Each line corresponds to one individual.
|
| 10 |
+
% IndAll - Matrix containing the best individual (variables) of each
|
| 11 |
+
% generation. Each line corresponds to one individual.
|
| 12 |
+
% ObjV - Vector containing objective values of the current
|
| 13 |
+
% generation
|
| 14 |
+
% Best - Matrix containing the best and average Objective values of each
|
| 15 |
+
% generation, [best value per generation,average value per generation]
|
| 16 |
+
% gen - Scalar containing the number of the current generation
|
| 17 |
+
%
|
| 18 |
+
% Output parameter:
|
| 19 |
+
% no output parameter
|
| 20 |
+
|
| 21 |
+
% Author: Hartmut Pohlheim
|
| 22 |
+
% History: 27.11.93 file created
|
| 23 |
+
% 29.11.93 decision, if plot or not deleted
|
| 24 |
+
% yscale not log
|
| 25 |
+
% 15.12.93 MutMatrix as parameter and plot added
|
| 26 |
+
% 16.03.94 function cleaned, MutMatrix removed, IndAll added
|
| 27 |
+
|
| 28 |
+
function resplot(Chrom,IndAll,ObjV,Best,gen);
|
| 29 |
+
|
| 30 |
+
% plot of best and mean value per generation
|
| 31 |
+
subplot(2,2,1), plot(Best);
|
| 32 |
+
title('Best and mean objective value');
|
| 33 |
+
xlabel('generation'), ylabel('objective value');
|
| 34 |
+
|
| 35 |
+
% plot of best individuals in all generations
|
| 36 |
+
subplot(2,2,2), plot(IndAll);
|
| 37 |
+
title(['Best individuals']);
|
| 38 |
+
xlabel('generation'), ylabel('value of variable');
|
| 39 |
+
|
| 40 |
+
% plot of variables of all individuals in current generation
|
| 41 |
+
subplot(2,2,3), plot(Chrom');
|
| 42 |
+
title(['All individuals in gen ',num2str(gen)]);
|
| 43 |
+
xlabel('number of variable'), ylabel('value of variable');
|
| 44 |
+
|
| 45 |
+
% plot of all objective values in current generation
|
| 46 |
+
subplot(2,2,4), plot(ObjV,'y.');
|
| 47 |
+
title(['All objective values']);
|
| 48 |
+
xlabel('number of individual'), ylabel('objective value');
|
| 49 |
+
|
| 50 |
+
drawnow;
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
% End of function
|
| 54 |
+
|
| 55 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/SGA.M
CHANGED
|
@@ -1,3 +1,67 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% SGA.M (Simple Genetic Algorithm)
|
| 2 |
+
%
|
| 3 |
+
% This script implements the Simple Genetic Algorithm.
|
| 4 |
+
% Binary representation for the individuals is used.
|
| 5 |
+
%
|
| 6 |
+
% Author: Hartmut Pohlheim
|
| 7 |
+
% History: 23.03.94 file created
|
| 8 |
+
|
| 9 |
+
NIND = 20; % Number of individuals per subpopulations
|
| 10 |
+
MAXGEN = 300; % maximal Number of generations
|
| 11 |
+
GGAP = .8; % Generation gap, how many new individuals are created
|
| 12 |
+
|
| 13 |
+
SEL_F = 'sus'; % Name of selection function
|
| 14 |
+
XOV_F = 'xovsp'; % Name of recombination function for individuals
|
| 15 |
+
MUT_F = 'mut'; % Name of mutation function for individuals
|
| 16 |
+
OBJ_F = 'objfun1'; % Name of function for objective values
|
| 17 |
+
|
| 18 |
+
% Get boundaries of objective function
|
| 19 |
+
FieldDR = feval(OBJ_F,[],1);
|
| 20 |
+
|
| 21 |
+
% Number of variables of objective function, in OBJ_F defined
|
| 22 |
+
NVAR = size(FieldDR,2);
|
| 23 |
+
|
| 24 |
+
% Build fielddescription matrix
|
| 25 |
+
PRECI = 20; % Precisicion of binary representation
|
| 26 |
+
FieldDD = [rep([PRECI],[1, NVAR]);...
|
| 27 |
+
FieldDR;...
|
| 28 |
+
rep([1; 0; 1 ;1], [1, NVAR])];
|
| 29 |
+
|
| 30 |
+
% Create population
|
| 31 |
+
Chrom = crtbp(NIND, NVAR*PRECI);
|
| 32 |
+
|
| 33 |
+
% reset count variables
|
| 34 |
+
gen = 0;
|
| 35 |
+
Best = NaN*ones(MAXGEN,1);
|
| 36 |
+
|
| 37 |
+
% Iterate population
|
| 38 |
+
while gen < MAXGEN,
|
| 39 |
+
|
| 40 |
+
% Calculate objective function for population
|
| 41 |
+
ObjV = feval(OBJ_F,bs2rv(Chrom, FieldDD));
|
| 42 |
+
Best(gen+1) = min(ObjV);
|
| 43 |
+
plot(log10(Best),'ro');
|
| 44 |
+
drawnow;
|
| 45 |
+
|
| 46 |
+
% Fitness assignement to whole population
|
| 47 |
+
FitnV = ranking(ObjV);
|
| 48 |
+
|
| 49 |
+
% Select individuals from population
|
| 50 |
+
SelCh = select(SEL_F, Chrom, FitnV, GGAP);
|
| 51 |
+
|
| 52 |
+
% Recombine selected individuals (crossover)
|
| 53 |
+
SelCh=recombin(XOV_F, SelCh);
|
| 54 |
+
|
| 55 |
+
% Mutate offspring
|
| 56 |
+
SelCh=mutate(MUT_F, SelCh);
|
| 57 |
+
|
| 58 |
+
% Insert offspring in population replacing parents
|
| 59 |
+
Chrom = reins(Chrom, SelCh);
|
| 60 |
+
|
| 61 |
+
gen=gen+1;
|
| 62 |
+
|
| 63 |
+
end
|
| 64 |
+
|
| 65 |
+
% End of script
|
| 66 |
+
|
| 67 |
+
|
matlab数学建模算法/遗传算法@遗传退火算法(算法简介+编程技巧+工具箱+应用大全)(含源代码)/《Matlab遗传算法工具箱及应用》源码/gatbx/gatbx-origin/SRC/TEST_FNS/SIMDOPI1.M
CHANGED
|
@@ -1,3 +1,80 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function [ret,x0,str]=simdopi1(t,x,u,flag);
|
| 2 |
+
%SIMDOPI1 is the M-file description of the SIMULINK system named SIMDOPI1.
|
| 3 |
+
% The block-diagram can be displayed by typing: SIMDOPI1.
|
| 4 |
+
%
|
| 5 |
+
% SYS=SIMDOPI1(T,X,U,FLAG) returns depending on FLAG certain
|
| 6 |
+
% system values given time point, T, current state vector, X,
|
| 7 |
+
% and input vector, U.
|
| 8 |
+
% FLAG is used to indicate the type of output to be returned in SYS.
|
| 9 |
+
%
|
| 10 |
+
% Setting FLAG=1 causes SIMDOPI1 to return state derivatives, FLAG=2
|
| 11 |
+
% discrete states, FLAG=3 system outputs and FLAG=4 next sample
|
| 12 |
+
% time. For more information and other options see SFUNC.
|
| 13 |
+
%
|
| 14 |
+
% Calling SIMDOPI1 with a FLAG of zero:
|
| 15 |
+
% [SIZES]=SIMDOPI1([],[],[],0), returns a vector, SIZES, which
|
| 16 |
+
% contains the sizes of the state vector and other parameters.
|
| 17 |
+
% SIZES(1) number of states
|
| 18 |
+
% SIZES(2) number of discrete states
|
| 19 |
+
% SIZES(3) number of outputs
|
| 20 |
+
% SIZES(4) number of inputs.
|
| 21 |
+
% For the definition of other parameters in SIZES, see SFUNC.
|
| 22 |
+
% See also, TRIM, LINMOD, LINSIM, EULER, RK23, RK45, ADAMS, GEAR.
|
| 23 |
+
|
| 24 |
+
% Note: This M-file is only used for saving graphical information;
|
| 25 |
+
% after the model is loaded into memory an internal model
|
| 26 |
+
% representation is used.
|
| 27 |
+
|
| 28 |
+
% the system will take on the name of this mfile:
|
| 29 |
+
sys = mfilename;
|
| 30 |
+
new_system(sys)
|
| 31 |
+
simver(1.2)
|
| 32 |
+
if(0 == (nargin + nargout))
|
| 33 |
+
set_param(sys,'Location',[100,100,600,400])
|
| 34 |
+
open_system(sys)
|
| 35 |
+
end;
|
| 36 |
+
set_param(sys,'algorithm', 'RK-45')
|
| 37 |
+
set_param(sys,'Start time', '0.0')
|
| 38 |
+
set_param(sys,'Stop time', '1')
|
| 39 |
+
set_param(sys,'Min step size', '0.001')
|
| 40 |
+
set_param(sys,'Max step size', '0.01')
|
| 41 |
+
set_param(sys,'Relative error','1e-3')
|
| 42 |
+
set_param(sys,'Return vars', '')
|
| 43 |
+
|
| 44 |
+
add_block('built-in/Inport',[sys,'/','Inport'])
|
| 45 |
+
set_param([sys,'/','Inport'],...
|
| 46 |
+
'position',[65,95,85,115])
|
| 47 |
+
|
| 48 |
+
add_block('built-in/Note',[sys,'/','Doppelintegrator'])
|
| 49 |
+
set_param([sys,'/','Doppelintegrator'],...
|
| 50 |
+
'position',[225,10,230,15])
|
| 51 |
+
|
| 52 |
+
add_block('built-in/Note',[sys,'/','Steuerung'])
|
| 53 |
+
set_param([sys,'/','Steuerung'],...
|
| 54 |
+
'position',[75,65,80,70])
|
| 55 |
+
|
| 56 |
+
add_block('built-in/Integrator',[sys,'/','Integrator1'])
|
| 57 |
+
set_param([sys,'/','Integrator1'],...
|
| 58 |
+
'position',[175,95,195,115])
|
| 59 |
+
|
| 60 |
+
add_block('built-in/Integrator',[sys,'/','Integrator2'])
|
| 61 |
+
set_param([sys,'/','Integrator2'],...
|
| 62 |
+
'Initial','-1',...
|
| 63 |
+
'position',[280,95,300,115])
|
| 64 |
+
add_line(sys,[90,105;165,105])
|
| 65 |
+
add_line(sys,[200,105;270,105])
|
| 66 |
+
|
| 67 |
+
% Return any arguments.
|
| 68 |
+
if (nargin | nargout)
|
| 69 |
+
% Must use feval here to access system in memory
|
| 70 |
+
if (nargin > 3)
|
| 71 |
+
if (flag == 0)
|
| 72 |
+
eval(['[ret,x0,str]=',sys,'(t,x,u,flag);'])
|
| 73 |
+
else
|
| 74 |
+
eval(['ret =', sys,'(t,x,u,flag);'])
|
| 75 |
+
end
|
| 76 |
+
else
|
| 77 |
+
[ret,x0,str] = feval(sys);
|
| 78 |
+
end
|
| 79 |
+
end
|
| 80 |
+
|