Does gamultiob/ga perfom differently depending on the Matlab version?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I use gamultiobj with a personalized Creation Function, Crossover Function and Mutation Function. The random numbers that are used, are set to ensure reproducable results. This works fine in Matlab R2016a. I have to use a different computer for further evaluations. This computer has a different Matlab Version (R2015b). I changed how the options for gamultiobj are set (optimoptions to gaoptimset), but the option values stayed all the same. If I run gamulitobj with R2015b I get different results. Since I didn't find any changes mentioned in the release notes of the two versions, I was hoping somebody could help me to figure out why the results differ. Thank you for reading.
I think code for creation,crossover and muation function is not important, besides that the random numbers are set with:
global Zusatz
rng('default');
rng(Zusatz);
Function Call for Gamultiobj in R2016a:
% Set Options für gamultiobj
options = optimoptions('gamultiobj',...
'UseParallel', true,...
'UseVectorized', false,...
'CreationFcn',@popFun,...
'CrossoverFcn',@crossoverBinary,...
'MutationFcn',@mutFun,...
'PopulationSize',InitPop,...
'MaxStallGenerations',MaxStallG); %
% Starte gamultiobj
[X,fval,exitflag] = gamultiobj(objFun,n,A,B,[],[],[],[],[],options);
Function call for Gamultiobj in R2015b:
options = gaoptimset(...
'UseParallel', true,...
'Vectorized', 'off',...
'CreationFcn',@popFun,...
'CrossoverFcn',@crossoverBinary,...
'MutationFcn',@mutFun,...
'PopulationSize',InitPop,...
'StallGenLimit',MaxStallG); %
% Starte gamultiobj
[X,fval,exitflag] = gamultiobj(objFun,n,A,B,[],[],[],[],[],options);
The Creation Function:
function Population = popFun(GenomeLength,~,options)
global Zusatz
Population=zeros(options.PopulationSize,GenomeLength);
% Sicherstellen, dass die randomnumbers sich wiederholen(nur für debugging;später entfernen)
rng('default');
rng(Zusatz);
intcon=1:GenomeLength;
A=xlsread('Linearconstraints.xlsx','A2:MD86');
B=ones(85,1);
B(36,1)=-1;
lb=zeros(1,GenomeLength);
ub=ones(1,GenomeLength);
opts =optimoptions('intlinprog','IntegerTolerance',1e-06,'Display','off');
for a=1:options.PopulationSize
f= randn(GenomeLength,1);
[x,fval,exitflag]= intlinprog(f,intcon,A,B,[],[],lb,ub,opts);
Population(a,:)=x;
end
% Population = Population';
end
The Crossover Function:
function xoverKids = crossoverBinary(parents,options,GenomeLength,~,~,thisPopulation)
% Sicherstellen, dass die randomnumbers sich wiederholen(nur für debugging;später entfernen)
global Zusatz
rng('default');
rng(Zusatz);
% Extract information about linear constraints, if any
linCon = options.LinearConstr;
nKids = length(parents)/2;
index = 1;
xoverKids = nan(nKids,GenomeLength);
for k = 1:nKids
% Get the parents from the population
parent1 = thisPopulation(parents(index),:);
index = index + 1;
parent2 = thisPopulation(parents(index),:);
index = index+1;
% find locations where parents have a different genome
idx = randi(GenomeLength,1);
% Where genome is the same, keep it the same in the kids
xoverKids(k,1:idx) = parent1(1:idx);
xoverKids(k,idx+1:end) = parent2(idx+1:end);
% Ensure that kid astisfies constraints
flag = any(linCon.Aineq*(xoverKids(k,:)') > linCon.bineq,1);
while flag % Does not satisfy constraints
idx = randi(GenomeLength,1);
xoverKids(k,1:idx) = parent1(1:idx);
xoverKids(k,idx+1:end) = parent2(idx+1:end);
flag = any(linCon.Aineq*(xoverKids(k,:)') > linCon.bineq,1);
end
end
end
The Mutation Function:
function mutationChildren = mutFun(parents, options, GenomeLength, ...
~, ~, ~, thisPopulation)
% Extract information about linear constraints, if any
linCon = options.LinearConstr;
% Sicherstellen, dass die randomnumbers sich wiederholen(nur für debugging;später entfernen)
global Zusatz
rng('default');
rng(Zusatz);
% Initialize the output
mutationChildren = nan(length(parents),GenomeLength);
for k = 1:length(parents)
% Get current sample
mut = thisPopulation(parents(k),:)';
idx = rand(GenomeLength,1) < 0.01; % 1% chance of mutating
% Mutate by flipping the bits at the idx indice.
mutated = mut;
mutated(idx) = double(~mut(idx));
% Check that constraints are satisfied.
flag = any(linCon.Aineq*mutated > linCon.bineq,1);
while flag %
% Try the mutation again
idx = rand(GenomeLength,1) < 0.01; % 1% chance of mutating
% Mutate by flipping the bits at the idx indice.
mutated = mut;
mutated(idx) = double(~mut(idx));
% Check that constraints are satisfied.
flag = any(linCon.Aineq*mutated > linCon.bineq,1);
end
mutationChildren(k,:) = mutated';
end
end
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Optimization Toolbox에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!