# MATLAB genetic algorithm integer optimization toolbox returns values higher than boundaries and doesn't satisfy inequality constraints. Why?

2 views (last 30 days)
Jack on 21 May 2016
Commented: Alan Weiss on 23 May 2016
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?
Geoff Hayes on 21 May 2016
Jack - what is your Cost_function?
Jack on 21 May 2016
Edited: Jack on 21 May 2016
I checked first array which was sent to cost_function before cost function calculations so this behavior doesn't bound to cost function (mentioned array in question is not final optimized array). But for more information it is going to fit some linear least square regression to a time series between generated time steps extracted by optimization algorithm. You can use every cost function in above code. You have same mentioned behavior.

Alan Weiss on 22 May 2016
I would give a feasible point for starting. Something like
x0 = 2:2:160;
options.InitialPopulationMatrix = x0;
It is possible that you don't have any feasible points, and the solver gets stuck in the infeasible region.
Alan Weiss
MATLAB mathematical toolbox documentation
Jack on 22 May 2016
Edited: Jack on 22 May 2016
Thank you for your answer. With your proposed codes I get this array in beginning of first call of cost function:
44 60 84 96 178 213 220 218 221 201 204 231 267 312 328 333 327 306 274 268 267 262 265 267 271 269 209 215 229 238 285 292 296 290 291 272 273 276 279 282 263 244 242 243 246 249 253 256 270 275 326 354 388 394 275 279 284 332 343 362 365 364 327 319 291 209 211 217 282 279 263 234 233 184 176 179 209 233 246 283
Unfortunately based on linear constrains this is not a feasible solution.
Alan Weiss on 23 May 2016
I am not sure that I understand you. ga is population-based, and unless you have a population of just one member, the vector you gave is not a complete population.
Your population should consist of entirely feasible members when using the @gacreationlinearfeasible creation function. Is that your creation function? If it is, then if you have an infeasible population then your linear constraints are not set up properly. Please check what you get when you take your A matrix and multiply it by a solution to see whether it satisfies A*x <= b.
Sorry, I don't have any other ideas right now.
Alan Weiss
MATLAB mathematical toolbox documentation

### Categories

Find more on Genetic Algorithm in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!