K. Rmth
K. Rmth

Reputation: 217

restricting the genes in the Genetic Algorithm chromosome to integral multiples

If i am using the GA from matlab, is there a way to restrict the genes in the chromosome to integral multiples of say 10000?

I have a chromosome like this {Pdg1 Pdg2 ... Pdg33}, I need 0<=Pdgn<=400000 where n=1,2..,33 and mod(Pdgn ,10000)=0. Does the GA,(the multiobjective optimization one) in matlab allow that? If yes, how?

Upvotes: 1

Views: 852

Answers (1)

Dmitry Galchinsky
Dmitry Galchinsky

Reputation: 2201

gamultiobj does not support integer constraints. I usually perform a scalarization and use plain ga.

function res = scalarizedFitness(x)
    [obj1, obj2, obj3] = yourFitnessFunction(x);
    %choose w1, w2, w3
    res = w1 * obj1 + w2 * obj2 + w3 * obj3;
end

The way to avoid scalarization is to write your own mutation functions for gamultiobj. I never did so. Here are some notes about it.

Integer constraints are supported by ga since some version. My 2011b supports it. Type help ga and find if it contains the line X = ga(FITNESSFCN,NVARS,A,b,[],[],lb,ub,NONLCON,INTCON). Note that INTCON parameter which is used to say what parameters are to be integer.

0<=Pdgn<=400000 : You can set lower and upper bound by using lb and ub parameters.

mod(Pdgn ,10000)=0 There are different ways to put complicated constraints. I guess the most optimal for you is to change your fitness function:

From f(Pdgn) where 0<=Pdgn<40000 to f(X) where 0<X<40 and Pdgn = X * 10000

The resulting code may look like

function result = fitnessfun(X)
    Pgds = X * 10000;
    result = scalarizedFitness(Pgds);
end

NVARS = 33;
%lower bounds
lb = 0 * ones(1, NVARS);
%upper bounds
ub = 40 * ones(1, NVARS);
%which variables are integers (all of them)
intcon = 1:NVARS;
result = ga(@fintessfun, NVARS, [], [], [], [], lb, ub, [], intcon);

Upvotes: 1

Related Questions