简体   繁体   English

MATLAB遗传算法优化返回的整数值高于边界,并且违反了不等式约束。 为什么?

[英]MATLAB genetic algorithm optimization returns integer values higher than boundaries and violates inequality constraints. Why?

I'm using MATLAB R2016a genetic algorithm optimization toolbox to optimize 80 integer values. 我正在使用MATLAB R2016a遗传算法优化工具箱来优化80个整数值。 I have these constraints: 我有这些限制:

x(80) > x(79) > x(78) > x(77) > x(76) ... x(5) > x(4) > x(3) > x(2) > x(1)

The range for all integer variables is between 1 and 500. I used this code in MATLAB: 所有整数变量的范围在1到500之间。我在MATLAB中使用了以下代码:

f = @(x)Cost_function(x, my_data);

num_of_var = 80;


for mx = 1:num_of_var-1
    A(mx,:) = [zeros(1,mx-1),1,-1, zeros(1,num_of_var-mx-1)];
end

b = repmat(-3, [num_of_var-1,1]);

lb = ones([num_of_var-1,1]);

up = repmat(500,[num_of_var-1,1]);

options = optimoptions('ga');
options.Display = 'iter';
options.PopulationSize = 200;
options.UseParallel = 0;

IntCon = 1:1:num_of_var;
[x, fval, exitflag] = ga(f, num_of_var, A, b, [], [], lb, up,[] ,IntCon, options);

Is this code correct? 此代码正确吗? In some cases this code returns integer higher than boundaries. 在某些情况下,此代码返回比边界高的整数。 For example this is first return of this code for cost function: 例如,这是此代码首次返回成本函数:

11  89  129 136 168 191 208 232 267 299 306 312 312 270 270 293 297 296 283 192 188 239 241 239 226 212 212 301 275 231 221 210 179 182 200 224 227 258 270 264 225 204 183 199 202 236 305 310 313 276 272 259 256 336 329 310 303 303 296 289 275 235 233 232 194 196 203 268 294 313 340 336 333 263 260 257 265 275 409 174964160

Otherwise this output structure doesn't satisfy my mentioned constraints. 否则,此输出结构不满足我提到的约束。 why? 为什么?

  1. Why higher than boundaries. 为什么高于界限。

I think you are talking about the last number in your result: 174964160. That is because you use num_of_var-1 instead of num_of_var in the calculation of lb and up . 我认为您正在谈论结果中的最后一个数字:174964160。这是因为在lbup的计算中使用num_of_var-1而不是num_of_var

  1. Does not satisfy inequality constraints. 不满足不平等约束。

You may need to do more iterations. 您可能需要执行更多迭代。 Otherwise you can model this differently. 否则,您可以对此建模。 Instead of using variables x with x(k) <= x(k+1) - 3 , use variables dx(k)>=3 indicating the difference between x(k) and x(k+1) . 代替使用x(k) <= x(k+1) - 3变量x,而是使用变量dx(k)>=3指示x(k)x(k+1)之间的差。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM