Restricting members to choose in population selection

1 view (last 30 days)
Hello all,
I'd like to be able to define the list of possibilities that my population can be selected from.
For example, if using the optimization tool, I can define my bounds to be [1,1] to [400,400] and in this case any value is chosen between this range on each iteration of the ga.
If I want to constraint this as follows so that I only use steps of 5 from the population. How can I do this. Here is what I mean by steps.
popsize = 20;
steps = [1;(5:5:400)';]
[X,Y] = ndgrid(steps,steps);
A = [X(:),Y(:)];
A(randperm(length(A),popsize),:)

Answers (1)

Alan Weiss
Alan Weiss on 8 Apr 2013
It sounds to me as if you want to restrict your population to be multiples of 5, from 5 to 400. You can do this by restricting your population to be integers from 1 to 400/5=80, and scaling your results afterwards.
To restrict your population to integers from 1 to 80, see the documentation of mixed integer programming in ga.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments
David
David on 8 Apr 2013
I see what you are saying. Thanks. I assume one could also do:
function [c, ceq] = simple_constraint(x)
c = [mod(x(:,1),5) mod(x(:,2),5)];
ceq = [];
Alan Weiss
Alan Weiss on 8 Apr 2013
I would not try to use a nonlinear constraint to enforce integrality. If it were that easy, we would not have made a special integer solver!
Please try the integer method before wasting time on a nonlinear constraint method.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!