MATLAB遗传算法优化返回高于边界的整数值并违反不等式约束。为什么? [英] MATLAB genetic algorithm optimization returns integer values higher than boundaries and violates inequality constraints. Why?

查看:184
本文介绍了MATLAB遗传算法优化返回高于边界的整数值并违反不等式约束。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MATLAB R2016a遗传算法优化工具箱来优化80个整数值。我有这些限制:

I'm using MATLAB R2016a genetic algorithm optimization toolbox to optimize 80 integer values. I have these constraints:

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

所有整数变量的范围在1到500之间。我在以下代码中使用了此代码MATLAB:

The range for all integer variables is between 1 and 500. I used this code in 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. 为什么要高于边界。

我认为你在谈论结果中的最后一个数字:174964160。那是因为你使用 num_of_var-1 而不是 num_of_var 计算 lb up

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.


  1. 不满足不等式约束。

您可能需要进行更多迭代。否则你可以用不同的方式建模。不使用带有 x(k)< = x(k + 1) - 3 的变量x,而是使用变量 dx(k)> = 3 表示 x(k) x(k + 1)之间的差异。

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).

这篇关于MATLAB遗传算法优化返回高于边界的整数值并违反不等式约束。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆