cumprod fuction in GA

73 views (last 30 days)
HSUAN
HSUAN on 6 Apr 2024 at 10:00
Commented: HSUAN on 8 Apr 2024 at 9:51
I want to calculate the following formula in GA.
syms Nb Nv K n Tb Hb t Sb F Sv Hv...
D P Cj j r q
Tb=1.2;
Hb=[2.8 2.2 1.7 1.2 0.8 0.6 0 0];
Sb=[25 28 32 36 35 38 0 0];
F=[70 50 48 55 80 65 0 0];
Sv=[0 280 200 320 360 380 420 0];
Hv=[0 2.5 1.9 1.4 1 0.7 0.5 0];
D=[180000 200000 240000 300000 350000 400000 0 0];
P=[0 200000 240000 300000 350000 400000 450000 0];
q=[1 1 1 1 1 1 0 0];
u=[0.009 0.0064 0.0054 0.0072 0.01 0.008 0 0];
t=[0.015 0.01 0.009 0.012 0.016 0.014 0 0];
w=[0.005 0.004 0.003 0.004 0.006 0.004 0 0];
Se=[29 32 38 42 37 40 0 0];
n=[1 0.9 0.75 0.6 0.51 0.45];
p=[3.2 2.6 2.1 1.6 1.2 0.9 0 0];
%
Nb=[1 1 1 1 1 1 0 0];
Nv=[0 3 2 1 1 1 1 0];
K=[0 26 14 12 8 5 5 0];
m=[0.0095 0.0078 0.0072 0.0092 0.0116 0.0104 0 0];
%
idx = 1:6;
Nvc = cumprod(Nv(idx+1));
Nvb = cumprod(Nv(idx));
s = sum(n(idx).*Tb.*Hb(idx).*D(idx).*(m(idx)-u(idx))+...
(n(idx)*Tb).^2./(Nvc.*K(idx+1)).* ...
(D(idx)/2.*(Hb(idx)+Hv(idx+1)-2*Hv(idx+1).*(1-D(idx)./P(idx+1))))+ ...
Nvc.*K(idx+1).*(Se(idx).*(t(idx)-m(idx)).^3.*(t(idx)+3*m(idx)-4*w(idx)) ...
./(t(idx)-w(idx)).^4 +(Hb(idx)+p(idx)).*D(idx).*(t(idx)-m(idx)).^5.*(2*t(idx)+3*m(idx)-5*w(idx)) ...
./(5*(t(idx)-w(idx)).^4)+F(idx))+Nvc.*Sv(idx+1)+...
(n(idx)*Tb).^2./Nvc.*(Hv(idx+1).*D(idx)/2.*(1-D(idx)./P(idx+1)))...
+ Nvb.*Nb(idx).*Sb(idx))
so I put it in the Algorithm
tic
syms Nb Nv K n Tb Hb t Sb F Sv Hv...
D P Cj j r q
options = optimoptions( ...
'ga', ...
'PopulationSize', 30, ...
'MaxGenerations', 1000, ...
'CrossoverFraction', 0.8, ...
'Display', 'iter');
% 'PlotFcn', {@gaplotbestf, @my_plot}, ...
Tb=1.2;
Hb=[2.8 2.2 1.7 1.2 0.8 0.6 0 0];
Sb=[25 28 32 36 35 38 0 0];
F=[70 50 48 55 80 65 0 0];
Sv=[0 280 200 320 360 380 420 0];
Hv=[0 2.5 1.9 1.4 1 0.7 0.5 0];
D=[180000 200000 240000 300000 350000 400000 0 0];
P=[0 200000 240000 300000 350000 400000 450000 0];
q=[1 1 1 1 1 1 0 0];
u=[0.009 0.0064 0.0054 0.0072 0.01 0.008 0 0];
t=[0.015 0.01 0.009 0.012 0.016 0.014 0 0];
w=[0.005 0.004 0.003 0.004 0.006 0.004 0 0];
Se=[29 32 38 42 37 40 0 0];
n=[1 0.9 0.75 0.6 0.51 0.45];
p=[3.2 2.6 2.1 1.6 1.2 0.9 0 0];
[x, fval] = ga(@FitnessFcn,x(1),x(2),x(3), 3, [], [], [], [], [1, 1], [40, 40], ...
[w(idx)<= m(idx)<= t(idx)], [Nv,K,m], options);
function Z = FitnessFcn(x)
Nv = x(1);
K = x(2);
m = x(3);
idx = 1:6;
Nvc = cumprod(Nv(idx+1));
Nvb = cumprod(Nv(idx));
Z = sum(n(idx).*Tb.*Hb(idx).*D(idx).*(m(idx)-u(idx))+...
(n(idx)*Tb).^2./(Nvc.*K(idx+1)).* ...
(D(idx)/2.*(Hb(idx)+Hv(idx+1)-2*Hv(idx+1).*(1-D(idx)./P(idx+1))))+ ...
Nvc.*K(idx+1).*(Se(idx).*(t(idx)-m(idx)).^3.*(t(idx)+3*m(idx)-4*w(idx)) ...
./(t(idx)-w(idx)).^4 +(Hb(idx)+p(idx)).*D(idx).*(t(idx)-m(idx)).^5.*(2*t(idx)+3*m(idx)-5*w(idx)) ...
./(5*(t(idx)-w(idx)).^4)+F(idx))+Nvc.*Sv(idx+1)+...
(n(idx)*Tb).^2./Nvc.*(Hv(idx+1).*D(idx)/2.*(1-D(idx)./P(idx+1)))...
+ Nvb.*Nb(idx).*Sb(idx))
Display Z Nv K m
toc
end
error
Unrecognized function or variable 'x'.
and it also can't seem to use cumprod in algorithm.
Nv,K,m are positive integers.
In addition, I would also like to ask if there is a three-variable drawing method based on the above problem. The information found so far only applies to two-variable equations.
Please help me fix the code so that I can get the result from algorithm, thank you for taking the time to answer.
  2 Comments
Torsten
Torsten on 6 Apr 2024 at 10:46
Moved: Torsten on 6 Apr 2024 at 20:21
Your call to ga is wrong:
x(1), x(2) and x(3) do not belong there, idx is undefined, lb and ub have 2 elements instead of 3, [Nv,K,m] don't belong there.
In the fitness function:
Nv, K and m are single numbers, but you reference Nv, K and m as 7-element vectors in your sum expression.
Further, all your arrays Tb, Hb, Sb,... are not visible in the fitness function because you defined them in the script part, but don't transfer them to the function.
HSUAN
HSUAN on 6 Apr 2024 at 14:06
Moved: Torsten on 6 Apr 2024 at 20:21
I really hope to use the algorithm to find the seven solutions of Nv, K and m. Based on this, how should I modify the code?
So I don't need to list the values ​​of Tb, Hb, Sb,...?

Sign in to comment.

Accepted Answer

Torsten
Torsten on 6 Apr 2024 at 20:17
Edited: Torsten on 7 Apr 2024 at 20:25
Note that Nb was not defined in your code - I added it to the known arrays.
rng("default")
t=[0.015 0.01 0.009 0.012 0.016 0.014 0 0];
w=[0.005 0.004 0.003 0.004 0.006 0.004 0 0];
options = optimoptions( ...
'ga', ...
'PopulationSize', 30, ...
'MaxGenerations', 1000, ...
'CrossoverFraction', 0.8, ...
'Display', 'iter');
nvars = 7 + 7 + 6;
lb = [ones(7,1);ones(7,1);w(1:6).'];
ub = [40*ones(7,1);40*ones(7,1);t(1:6).'];
intcon = 1:(7+7);
[x, fval, exitflag,output] = ga(@FitnessFcn,nvars,[],[],[],[],lb,ub,[],intcon,options)
Single objective optimization: 20 Variables 14 Integer variables Options: CreationFcn: @gacreationuniformint CrossoverFcn: @crossoverlaplace SelectionFcn: @selectiontournament MutationFcn: @mutationpower Best Mean Stall Generation Func-count Penalty Penalty Generations 1 60 1.68e+06 3.57e+10 0 2 85 1.68e+06 9.663e+09 1 3 110 1.68e+06 2.437e+10 2 4 135 1.68e+06 5.923e+09 3 5 160 1.009e+06 2.529e+09 0 6 185 6.031e+05 5.922e+09 0 7 210 5.848e+05 1.109e+10 0 8 235 2.733e+05 8.217e+08 0 9 260 2.733e+05 4.51e+08 1 10 285 2.733e+05 4.148e+10 2 11 310 2.733e+05 2.086e+09 3 12 335 2.733e+05 1.585e+09 4 13 360 2.733e+05 4.752e+08 5 14 385 2.45e+05 4.614e+08 0 15 410 2.436e+05 1.445e+08 0 16 435 2.005e+05 3.298e+09 0 17 460 1.882e+05 1.945e+06 0 18 485 1.882e+05 7.831e+09 1 19 510 1.882e+05 1.714e+10 2 20 535 1.882e+05 9.4e+08 3 21 560 1.882e+05 1.885e+09 4 22 585 1.826e+05 5.043e+09 0 23 610 1.754e+05 2.931e+09 0 24 635 1.687e+05 2.339e+05 0 25 660 1.586e+05 4.432e+09 0 26 685 1.586e+05 2.565e+09 1 27 710 1.56e+05 2.19e+09 0 28 735 1.56e+05 6.232e+08 1 29 760 1.558e+05 3.814e+09 0 Best Mean Stall Generation Func-count Penalty Penalty Generations 30 785 1.531e+05 1.965e+05 0 31 810 1.496e+05 2.147e+08 0 32 835 1.491e+05 1.315e+09 0 33 860 1.462e+05 8.205e+09 0 34 885 1.437e+05 2.051e+09 0 35 910 1.425e+05 4.477e+09 0 36 935 1.381e+05 1.559e+05 0 37 960 1.381e+05 8.978e+08 1 38 985 1.347e+05 1.471e+05 0 39 1010 1.341e+05 1.428e+05 0 40 1035 1.323e+05 1.519e+05 0 41 1060 1.323e+05 1.424e+05 1 42 1085 1.313e+05 2.168e+09 0 43 1110 1.283e+05 1.495e+05 0 44 1135 1.283e+05 2.649e+09 1 45 1160 1.268e+05 1.531e+05 0 46 1185 1.268e+05 2.209e+08 0 47 1210 1.268e+05 9.499e+08 1 48 1235 1.231e+05 6.079e+09 0 49 1260 1.231e+05 1.171e+07 1 50 1285 1.231e+05 3.111e+09 2 51 1310 1.231e+05 1.069e+08 3 52 1335 1.231e+05 2.577e+10 4 53 1360 1.231e+05 4.676e+08 5 54 1385 1.231e+05 1.346e+05 6 55 1410 1.228e+05 6.251e+09 0 56 1435 1.213e+05 1.149e+10 0 57 1460 1.205e+05 1.705e+09 0 58 1485 1.205e+05 1.354e+05 1 59 1510 1.205e+05 9.981e+08 2 Best Mean Stall Generation Func-count Penalty Penalty Generations 60 1535 1.205e+05 1.505e+05 3 61 1560 1.205e+05 1.445e+05 4 62 1585 1.205e+05 1.587e+10 5 63 1610 1.199e+05 1.52e+05 0 64 1635 1.194e+05 4.773e+08 0 65 1660 1.193e+05 1.024e+10 0 66 1685 1.193e+05 9.236e+09 0 67 1710 1.192e+05 4.878e+06 0 68 1735 1.179e+05 2.04e+10 0 69 1760 1.179e+05 1.376e+05 1 70 1785 1.179e+05 1.104e+10 2 71 1810 1.179e+05 1.383e+05 3 72 1835 1.179e+05 1.279e+05 4 73 1860 1.178e+05 3.051e+08 0 74 1885 1.178e+05 8.962e+09 1 75 1910 1.178e+05 1.25e+05 2 76 1935 1.176e+05 1.696e+10 0 77 1960 1.175e+05 6.835e+08 0 78 1985 1.175e+05 1.075e+11 1 79 2010 1.174e+05 1.365e+08 0 80 2035 1.173e+05 1.5e+09 0 81 2060 1.169e+05 4.088e+09 0 82 2085 1.166e+05 8.133e+10 0 83 2110 1.163e+05 2.419e+08 0 84 2135 1.156e+05 1.187e+05 0 85 2160 1.154e+05 1.233e+05 0 86 2185 1.153e+05 5.778e+08 0 87 2210 1.149e+05 4.911e+08 0 88 2235 1.141e+05 1.166e+05 0 89 2260 1.14e+05 1.153e+05 0 Best Mean Stall Generation Func-count Penalty Penalty Generations 90 2285 1.138e+05 1.464e+10 0 91 2310 1.135e+05 2.694e+08 0 92 2335 1.135e+05 1.157e+05 1 93 2360 1.134e+05 1.272e+05 0 94 2385 1.134e+05 1.18e+05 1 95 2410 1.133e+05 5.736e+09 0 96 2435 1.131e+05 1.299e+09 0 97 2460 1.131e+05 1.218e+05 1 98 2485 1.131e+05 1.788e+09 0 99 2510 1.131e+05 1.739e+09 1 100 2535 1.131e+05 1.148e+05 2 101 2560 1.128e+05 5.215e+09 0 102 2585 1.124e+05 1.152e+05 0 103 2610 1.123e+05 1.317e+05 0 104 2635 1.123e+05 7.884e+09 1 105 2660 1.123e+05 1.172e+05 2 106 2685 1.123e+05 8.514e+09 3 107 2710 1.123e+05 1.141e+05 4 108 2735 1.123e+05 1.229e+05 5 109 2760 1.122e+05 2.137e+09 0 110 2785 1.122e+05 4.282e+09 1 111 2810 1.122e+05 5.647e+08 2 112 2835 1.122e+05 4.16e+08 3 113 2860 1.122e+05 5.195e+08 0 114 2885 1.122e+05 1.138e+05 0 115 2910 1.122e+05 4.544e+09 1 116 2935 1.121e+05 5.387e+08 0 117 2960 1.121e+05 4.197e+09 0 118 2985 1.121e+05 8.744e+08 0 119 3010 1.121e+05 1.13e+05 0 Best Mean Stall Generation Func-count Penalty Penalty Generations 120 3035 1.121e+05 1.169e+05 1 121 3060 1.121e+05 3.956e+09 2 122 3085 1.121e+05 1.163e+05 0 123 3110 1.121e+05 5.443e+10 0 124 3135 1.121e+05 1.173e+05 1 125 3160 1.121e+05 1.159e+05 0 126 3185 1.121e+05 1.034e+08 0 127 3210 1.121e+05 1.144e+05 0 128 3235 1.121e+05 3.852e+09 0 129 3260 1.121e+05 6.047e+08 0 130 3285 1.121e+05 1.154e+05 0 131 3310 1.121e+05 1.14e+09 0 132 3335 1.121e+05 1.476e+10 0 133 3360 1.121e+05 4.08e+09 1 134 3385 1.121e+05 1.129e+05 2 135 3410 1.121e+05 8.66e+07 0 136 3435 1.121e+05 1.166e+05 0 137 3460 1.121e+05 2.594e+10 0 138 3485 1.121e+05 5.404e+08 0 139 3510 1.121e+05 2.081e+10 0 140 3535 1.121e+05 6.659e+09 1 141 3560 1.121e+05 1.138e+05 0 142 3585 1.121e+05 1.15e+05 1 143 3610 1.121e+05 5.924e+07 2 144 3635 1.121e+05 4.099e+09 0 145 3660 1.121e+05 6.75e+08 0 146 3685 1.121e+05 7.468e+09 1 147 3710 1.121e+05 1.322e+10 2 148 3735 1.121e+05 1.167e+05 0 149 3760 1.121e+05 1.133e+05 1 Best Mean Stall Generation Func-count Penalty Penalty Generations 150 3785 1.121e+05 7.044e+09 2 151 3810 1.121e+05 1.257e+08 3 152 3835 1.121e+05 1.147e+05 0 153 3860 1.12e+05 1.135e+05 0 154 3885 1.12e+05 1.134e+05 1 155 3910 1.117e+05 2.84e+08 0 156 3935 1.115e+05 7.336e+10 0 157 3960 1.115e+05 1.942e+10 1 158 3985 1.115e+05 1.241e+09 2 159 4010 1.115e+05 5.832e+06 3 160 4035 1.115e+05 1.493e+08 0 161 4060 1.115e+05 1.262e+09 1 162 4085 1.115e+05 1.12e+05 2 163 4110 1.115e+05 1.125e+05 3 164 4135 1.115e+05 4.587e+09 4 165 4160 1.115e+05 1.443e+05 5 166 4185 1.115e+05 1.128e+05 6 167 4210 1.115e+05 2.251e+09 7 168 4235 1.115e+05 1.314e+09 0 169 4260 1.115e+05 1.243e+05 0 170 4285 1.115e+05 2.869e+09 0 171 4310 1.115e+05 1.117e+05 1 172 4335 1.115e+05 1.131e+05 2 173 4360 1.115e+05 8.639e+09 0 174 4385 1.115e+05 2.267e+09 1 175 4410 1.115e+05 2.451e+10 2 176 4435 1.115e+05 5.881e+08 0 177 4460 1.115e+05 1.121e+05 0 178 4485 1.115e+05 1.16e+05 0 179 4510 1.115e+05 1.614e+09 1 Best Mean Stall Generation Func-count Penalty Penalty Generations 180 4535 1.115e+05 1.436e+09 0 181 4560 1.115e+05 1.731e+10 0 182 4585 1.114e+05 3.974e+10 0 183 4610 1.114e+05 1.129e+05 0 184 4635 1.114e+05 2.83e+09 1 185 4660 1.114e+05 2.044e+09 0 186 4685 1.114e+05 9.661e+08 0 187 4710 1.114e+05 8.422e+08 1 188 4735 1.114e+05 5.73e+10 0 189 4760 1.114e+05 2.253e+08 1 190 4785 1.114e+05 4.512e+08 2 191 4810 1.114e+05 4.174e+09 0 192 4835 1.114e+05 1.699e+10 1 193 4860 1.114e+05 1.119e+05 0 194 4885 1.114e+05 6.666e+08 0 195 4910 1.114e+05 5.871e+09 0 196 4935 1.114e+05 2.716e+10 1 197 4960 1.114e+05 6.854e+07 2 198 4985 1.114e+05 2.017e+10 0 199 5010 1.114e+05 1.149e+05 1 200 5035 1.114e+05 1.138e+05 0 201 5060 1.114e+05 4.336e+08 1 202 5085 1.114e+05 6.012e+09 0 203 5110 1.113e+05 1.142e+05 0 204 5135 1.112e+05 1.143e+05 0 205 5160 1.112e+05 1.118e+05 1 206 5185 1.112e+05 1.174e+05 0 207 5210 1.112e+05 3.051e+10 0 208 5235 1.112e+05 2.053e+09 1 209 5260 1.111e+05 4.557e+08 0 Best Mean Stall Generation Func-count Penalty Penalty Generations 210 5285 1.111e+05 7.571e+08 1 211 5310 1.111e+05 7.197e+09 2 212 5335 1.111e+05 1.145e+05 3 213 5360 1.111e+05 1.121e+05 0 214 5385 1.111e+05 1.578e+10 1 215 5410 1.111e+05 2.666e+07 0 216 5435 1.111e+05 3.178e+07 0 217 5460 1.111e+05 8.565e+09 1 218 5485 1.111e+05 2.043e+10 2 219 5510 1.111e+05 5.442e+09 0 220 5535 1.111e+05 2.814e+08 1 221 5560 1.111e+05 1.127e+05 0 222 5585 1.111e+05 7.336e+08 0 223 5610 1.111e+05 2.733e+10 1 224 5635 1.111e+05 1.273e+05 2 225 5660 1.111e+05 6.899e+09 3 226 5685 1.111e+05 7.528e+08 0 227 5710 1.111e+05 6.619e+08 1 228 5735 1.111e+05 1.061e+10 0 229 5760 1.111e+05 3.035e+09 1 230 5785 1.111e+05 1.821e+09 2 231 5810 1.111e+05 1.077e+10 0 232 5835 1.111e+05 1.133e+05 0 233 5860 1.111e+05 1.797e+08 0 234 5885 1.111e+05 8.28e+08 1 235 5910 1.111e+05 1.14e+05 0 236 5935 1.111e+05 2.482e+10 0 237 5960 1.111e+05 1.974e+09 0 238 5985 1.111e+05 1.142e+05 1 239 6010 1.111e+05 1.114e+05 0 Best Mean Stall Generation Func-count Penalty Penalty Generations 240 6035 1.111e+05 1.307e+09 1 241 6060 1.111e+05 1.154e+05 2 242 6085 1.111e+05 9.023e+09 3 243 6110 1.111e+05 1.163e+05 4 244 6135 1.111e+05 2.702e+09 5 245 6160 1.111e+05 2.276e+09 6 246 6185 1.111e+05 8.233e+09 7 247 6210 1.111e+05 1.156e+05 8 248 6235 1.111e+05 7.4e+09 9 249 6260 1.111e+05 1.133e+05 10 250 6285 1.111e+05 1.049e+10 11 251 6310 1.111e+05 1.298e+10 12 252 6335 1.111e+05 1.297e+05 13 253 6360 1.111e+05 1.121e+05 14 254 6385 1.111e+05 1.164e+05 15 255 6410 1.111e+05 3.452e+09 16 256 6435 1.111e+05 1.152e+05 17 257 6460 1.111e+05 1.028e+10 18 258 6485 1.111e+05 1.215e+05 19 259 6510 1.111e+05 7.092e+09 20 260 6535 1.11e+05 1.138e+05 0 261 6560 1.11e+05 6.835e+07 0 262 6585 1.11e+05 6.281e+09 1 263 6610 1.11e+05 1.139e+05 2 264 6635 1.11e+05 2.119e+09 3 265 6660 1.11e+05 1.128e+05 4 266 6685 1.11e+05 1.501e+10 0 267 6710 1.11e+05 6.156e+08 1 268 6735 1.11e+05 1.196e+05 2 269 6760 1.11e+05 1.317e+10 0 Best Mean Stall Generation Func-count Penalty Penalty Generations 270 6785 1.109e+05 1.459e+10 0 271 6810 1.109e+05 1.223e+05 0 272 6835 1.109e+05 1.349e+07 0 273 6860 1.109e+05 6.732e+09 0 274 6885 1.109e+05 5.224e+10 1 275 6910 1.109e+05 1.125e+05 2 276 6935 1.109e+05 1.115e+05 3 277 6960 1.109e+05 3.25e+08 4 278 6985 1.109e+05 6.786e+07 5 279 7010 1.109e+05 1.336e+10 0 280 7035 1.109e+05 1.138e+05 1 281 7060 1.109e+05 6.088e+08 2 282 7085 1.109e+05 7.31e+09 0 283 7110 1.109e+05 7.746e+08 1 284 7135 1.109e+05 1.112e+05 0 285 7160 1.109e+05 1.121e+05 1 286 7185 1.109e+05 3.355e+09 0 287 7210 1.109e+05 8.788e+08 0 288 7235 1.109e+05 1.148e+05 1 289 7260 1.109e+05 1.124e+05 0 290 7285 1.109e+05 1.199e+05 0 291 7310 1.109e+05 6.312e+09 1 292 7335 1.109e+05 1.256e+10 0 293 7360 1.109e+05 1.132e+05 0 294 7385 1.109e+05 4.399e+09 1 295 7410 1.109e+05 1.164e+05 0 296 7435 1.109e+05 1.111e+05 0 297 7460 1.109e+05 2.789e+08 1 298 7485 1.109e+05 7.352e+08 0 299 7510 1.109e+05 1.113e+05 0 Best Mean Stall Generation Func-count Penalty Penalty Generations 300 7535 1.109e+05 1.188e+05 1 301 7560 1.109e+05 1.12e+05 0 302 7585 1.109e+05 1.203e+05 1 303 7610 1.109e+05 1.28e+05 0 304 7635 1.109e+05 1.447e+05 0 305 7660 1.109e+05 1.202e+05 0 306 7685 1.109e+05 1.125e+05 0 307 7710 1.109e+05 1.364e+09 1 308 7735 1.109e+05 1.254e+05 2 309 7760 1.109e+05 2.357e+10 0 310 7785 1.109e+05 1.119e+05 1 311 7810 1.109e+05 5.921e+08 0 312 7835 1.109e+05 3.144e+10 0 313 7860 1.109e+05 7.998e+09 0 314 7885 1.109e+05 1.117e+05 0 315 7910 1.109e+05 1.839e+08 0 316 7935 1.109e+05 1.124e+05 0 317 7960 1.109e+05 5.483e+09 1 318 7985 1.109e+05 2.871e+09 0 319 8010 1.109e+05 1.163e+05 0 320 8035 1.109e+05 5.51e+07 1 321 8060 1.109e+05 5.6e+09 0 322 8085 1.109e+05 1.156e+09 0 323 8110 1.109e+05 1.382e+10 0 324 8135 1.109e+05 9.655e+08 0 325 8160 1.109e+05 1.427e+09 0 326 8185 1.109e+05 1.112e+05 1 327 8210 1.109e+05 1.203e+05 0 328 8235 1.109e+05 7.335e+09 0 329 8260 1.109e+05 1.861e+08 0 Best Mean Stall Generation Func-count Penalty Penalty Generations 330 8285 1.109e+05 1.412e+10 0 331 8310 1.109e+05 1.771e+08 0 332 8335 1.109e+05 1.294e+05 0 333 8360 1.109e+05 5.997e+10 0 334 8385 1.109e+05 6.81e+09 0 335 8410 1.109e+05 1.83e+09 0 336 8435 1.109e+05 1.433e+08 1 ga stopped because the average change in the penalty function value is less than options.FunctionTolerance and the constraint violation is less than options.ConstraintTolerance.
x = 1x20
1.0000 1.0000 7.0000 1.0000 1.0000 1.0000 1.0000 17.0000 40.0000 12.0000 10.0000 7.0000 5.0000 4.0000 0.0063 0.0078 0.0071 0.0092 0.0121 0.0103
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
fval = 1.1092e+05
exitflag = 1
output = struct with fields:
problemtype: 'integerconstraints' rngstate: [1x1 struct] generations: 336 funccount: 8436 message: 'ga stopped because the average change in the penalty function value is less than options.FunctionTolerance and ...' maxconstraint: 0 hybridflag: []
Nv = x(1:7)
Nv = 1x7
1 1 7 1 1 1 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
K = x(7+1:7+7)
K = 1x7
17 40 12 10 7 5 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
m = x(7+7+1:7+7+6)
m = 1x6
0.0063 0.0078 0.0071 0.0092 0.0121 0.0103
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
fval
fval = 1.1092e+05
FitnessFcn(x)
ans = 1.1092e+05
function Z = FitnessFcn(x)
Nv = x(1:7);
K = x(7+1:7+7);
m = x(7+7+1:7+7+6);
Tb=1.2;
Hb=[2.8 2.2 1.7 1.2 0.8 0.6 0 0];
Sb=[25 28 32 36 35 38 0 0];
F=[70 50 48 55 80 65 0 0];
Sv=[0 280 200 320 360 380 420 0];
Hv=[0 2.5 1.9 1.4 1 0.7 0.5 0];
D=[180000 200000 240000 300000 350000 400000 0 0];
P=[0 200000 240000 300000 350000 400000 450000 0];
q=[1 1 1 1 1 1 0 0];
u=[0.009 0.0064 0.0054 0.0072 0.01 0.008 0 0];
t=[0.015 0.01 0.009 0.012 0.016 0.014 0 0];
w=[0.005 0.004 0.003 0.004 0.006 0.004 0 0];
Se=[29 32 38 42 37 40 0 0];
n=[1 0.9 0.75 0.6 0.51 0.45];
p=[3.2 2.6 2.1 1.6 1.2 0.9 0 0];
Nb=[1 1 1 1 1 1 0 0];
idx = 1:6;
Nvc = cumprod(Nv(idx+1));
Nvb = cumprod(Nv(idx));
Z = sum(n(idx).*Tb.*Hb(idx).*D(idx).*(m(idx)-u(idx))+...
(n(idx)*Tb).^2./(Nvc.*K(idx+1)).* ...
(D(idx)/2.*(Hb(idx)+Hv(idx+1)-2*Hv(idx+1).*(1-D(idx)./P(idx+1))))+ ...
Nvc.*K(idx+1).*(Se(idx).*(t(idx)-m(idx)).^3.*(t(idx)+3*m(idx)-4*w(idx)) ...
./(t(idx)-w(idx)).^4 +(Hb(idx)+p(idx)).*D(idx).*(t(idx)-m(idx)).^5.*(2*t(idx)+3*m(idx)-5*w(idx)) ...
./(5*(t(idx)-w(idx)).^4)+F(idx))+Nvc.*Sv(idx+1)+...
(n(idx)*Tb).^2./Nvc.*(Hv(idx+1).*D(idx)/2.*(1-D(idx)./P(idx+1)))...
+ Nvb.*Nb(idx).*Sb(idx));
end
  7 Comments
Torsten
Torsten on 7 Apr 2024 at 20:23
Edited: Torsten on 7 Apr 2024 at 23:48
Yes. But you wrote you want to use iter=100,200,300.
Here are the default options for "ga" - maybe of interest for you to know.
optimoptions(@ga)
ans =
ga options: Set properties: No options set. Default properties: ConstraintTolerance: 1.0000e-03 CreationFcn: [] CrossoverFcn: [] CrossoverFraction: 0.8000 Display: 'final' EliteCount: '0.05*PopulationSize' FitnessLimit: -Inf FitnessScalingFcn: @fitscalingrank FunctionTolerance: 1.0000e-06 HybridFcn: [] InitialPopulationMatrix: [] InitialPopulationRange: [] InitialScoresMatrix: [] MaxGenerations: '100*numberOfVariables' MaxStallGenerations: 50 MaxStallTime: Inf MaxTime: Inf MutationFcn: [] NonlinearConstraintAlgorithm: 'auglag' OutputFcn: [] PlotFcn: [] PopulationSize: '50 when numberOfVariables <= 5, else 200' PopulationType: 'doubleVector' SelectionFcn: [] UseParallel: 0 UseVectorized: 0
And if you want to change the seed of the random generator used in "ga", you can remove or modify the line "rng("default")" which serves the purpose to make the results obtained identical every time you run the code with the same inputs.
HSUAN
HSUAN on 8 Apr 2024 at 9:51
Thank you for your patient explanation, I learned a lot.

Sign in to comment.

More Answers (0)

Categories

Find more on Linear Algebra in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!