see InitialPopulation
and PopInitRange
in options of gaoptimset
.
you can initialize a sequence of integers in the range 2 to 20 as your initial population.
then you might use IntCon.
OR
as a first statement in your myFitnessfcn
model=round(model);
if model > 20 || model < 2
fitness=1e20;
else
% evaluate the original fitness function
end
this way model parameters fed to your fitness function are always integers. and since any model with values less than 2 or more than 20 will be assigned really bad value of fitness (1e20 for example), this is essentially what Simon said, such models will be automatically removed from the population after 2-3 generations.