additional parameters for GA custom crossover/mutation function

Hi all,
I am using GA optimization on bitstrings with a custom mutation and crossover function. As GA optimization on bitstrings does not respect contraints I have a want to run a function within the two functions that applies my constraints to the new children. For this I need to pass an addtional parameter to the mutation and crossover function.
I am pretty sure on the GA options setup with this additional parameter. It looks like this:
options = gaoptimset('Display','iter','PopulationType','bitstring',...
'PopulationSize',nPopulationSize,...
'InitialPopulation',bPopulation,...
'CrossoverFcn', @PopulationCrossover(bConstraint),...
'MutationFcn', @PopulationMutation(bConstraint),...
'PlotFcns', @GAPlotRule,...
'Vectorized','on',...
'UseParallel',true);
and the GA call looks like this:
[bBitStringBest,rResult] = ga(obj,size(bPopulation,2),[],[],[],[],[],[],[],options);
BUT now the question is how the custom crossover/mutation function needs to look like?
This is basically the the structure described here with some renamings for better understanding: https://de.mathworks.com/help/gads/genetic-algorithm-options.html#f6633
function bCrossoverKids = PopulationCrossover(bParenetChosen,options,nPopulationWidth,FitnessFcn,unused,bParentPopulation)
end
I am struggling on how to pass the additional parameter to the crossover function. Does this have to be in the input arguments and just added behind 'bParentPopulation'?
Thank you for your help.
Christian

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 27 日
編集済み: Ameer Hamza 2020 年 4 月 27 日

0 投票

You can pass additional parameters to PopulationCrossover() function using the cell array syntax. If you look at the example sat the link you shared, they also mention this syntax; however, they didn't explicitly mention it in reference to passing additional arguments.
1. Add the additional parameters at the end of the list of input arguments
function bCrossoverKids = PopulationCrossover(bParenetChosen,options,nPopulationWidth,FitnessFcn,unused,bParentPopulation, opt_parameter1, opt_parameter2)
% your cide
end
and then pass it like this
options = gaoptimset('Display','iter','PopulationType','bitstring',...
'PopulationSize',nPopulationSize,...
'InitialPopulation',bPopulation,...
'CrossoverFcn', {@PopulationCrossover, opt_parameter1_value, opt_parameter2_value},...
'MutationFcn', {@PopulationMutation, opt_parameter1_value},...
'PlotFcns', @GAPlotRule,...
'Vectorized','on',...
'UseParallel',true);

2 件のコメント

Christian
Christian 2020 年 4 月 27 日
Hi Ameer,
thank you for your fast answer on my maybe unnecessary question. It works fine.
Cheers
Christian
Ameer Hamza
Ameer Hamza 2020 年 4 月 28 日
I am glad to be of help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2020 年 4 月 26 日

コメント済み:

2020 年 4 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by