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

天大地大妈咪最大 提交于 2020-01-14 06:13:27

问题


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)

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:


  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.

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



来源:https://stackoverflow.com/questions/37364741/matlab-genetic-algorithm-optimization-returns-integer-values-higher-than-boundar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!