How to apply a random Crossover (Arithmeti​c/Scattere​d/Two-poin​t) in Genetic Algorithm using auto-generated file from Optimization Toolbox ?

I have prepared a code in MATLAB with optimization toolbox which seems to be giving fair results for different optimization functions but at present, accuracy is highly dependent on the type of crossover selected.
To take advantage of different crossover and to improve efficiency, i want to apply a random crossover after every iteration i.e. any of Arithmetic, Scattered or Two-point. How can I do that ?

7 件のコメント

Do you have integer constraints? Do you have linear constraints?
If your system is eligible to provide CrossoverFcn, then that function is not required to do the same kind of cross-over each time.
Ankur Shah
Ankur Shah 2020 年 8 月 10 日
編集済み: Ankur Shah 2020 年 8 月 10 日
GA+fmincon is used and system has only lower and upper bounds.. I am trying to verify Schwefel and griewank benchmark.. both are unconstrained but am trying to verify with fmincon using lower and upper bounds.. since later i will be working on same algorithm.. keeping all parameters constant , With schwefel global minimum is obtained using scattered crossover and for griewank global minimum is obtained using Arithmetic crossover.. hence the confusion..
Then you can provide a custom CrossoverFcn that does whatever you want, possibly even calling a random one of the standard crossover functions.
Ankur Shah
Ankur Shah 2020 年 8 月 11 日
編集済み: Ankur Shah 2020 年 8 月 11 日
That is exactly what i am trying to do i.e. How to call a random crossover for each iteration ?
crossfcns = {@first, @second};
chosen = crossfcns{randi(length(crossfcns))} ;
[varargout{:}] = chosen<varargin{:}) ;
Ankur Shah
Ankur Shah 2020 年 8 月 11 日
編集済み: Ankur Shah 2020 年 8 月 11 日
Can u please explain where can it be applied ?.. At present I have prepared crossover code using optimization toolbox as follows
options = optimoptions(options,'CrossoverFcn', @crossoverscattered)
options = optimoptions(options,'CrossoverFcn', @MyCustomCrossover)
function varargout = MyCustomCrossover(varargin)
crossfcns = {@crossoverarithmetic, @crossoverheuristic, @crossoveritnermediate, @crossoverscattered, @crossoversinglepoint, @crossovertwopoint};
chosen = crossfcns{randi(length(crossfcns))} ;
[varargout{:}] = chosen(varargin{:}) ;
end

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

 採用された回答

options = optimoptions(options,'CrossoverFcn', @MyCustomCrossover)
function varargout = MyCustomCrossover(varargin)
crossfcns = {@crossoverarithmetic, @crossoverheuristic, @crossoveritnermediate, @crossoverscattered, @crossoversinglepoint, @crossovertwopoint};
chosen = crossfcns{randi(length(crossfcns))} ;
[varargout{:}] = chosen(varargin{:}) ;
end

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020 年 8 月 11 日
See the screen shot given in the attachement. You should select from the drop-down options whichever crossover function suits for your task.

3 件のコメント

Ankur Shah
Ankur Shah 2020 年 8 月 11 日
編集済み: Ankur Shah 2020 年 8 月 11 日
I am trying to use it in code and not in GA Optimisation toolbox. Also random crossover to be done after each iteration.
Ankur Shah
Ankur Shah 2021 年 1 月 25 日
編集済み: Ankur Shah 2021 年 1 月 25 日
Hi, Yes the code worked perfectly. I was trying to to tag your answer as Accepted but couldn't do. Apologies for confusion... Could you have a look at this question https://in.mathworks.com/matlabcentral/answers/725727-how-to-find-function-and-variable-value-at-each-iteration-for-genetic-algorithm-with-parallel-comput?s_tid=prof_contriblnk

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

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by