Hi, I do really like your work,
but is there any way to apply two (parent) selectors?
e.g., I would like to apply a truncation selector to keep the best phenotype, and then a Tournament to choose the others.
Is this possible?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Franz,
There is a thing that i cannot seem to understand:
I've put a synchronized list in this selector to track down the fitness throught the generations, but at the end, the list has twice the elements than generations.
e.g., if I build the engine with engine.stream().limit(200) I expect a list of 200 elements, but I get a 400 elements one instead.
Is this a problem with my implementation or is a legit behaviour?
Btw: I suppose that in the code you kindly provided me the append method should return p1, if it works like the Collection javadoc suggests.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My bad, I'm not talking about bugs, but just to undarstand why the selector are called twice.
But you are right, without source code it's pretty difficult.
Here is my version of your code
publicclassCombinedSelector<GextendsGene<?,G>,CextendsComparable<?superC>>implementsSelector<G,C>{privatefinalTruncationSelector<G,C>_s1;privatefinalTournamentSelector<G,C>_s2;privateArrayList<C>fitnesses;publicCombinedSelector(inttournamentSize){_s1=newTruncationSelector<>();_s2=newTournamentSelector<>(tournamentSize);fitnesses=newArrayList<>();}@OverridepublicPopulation<G,C>select(finalPopulation<G,C>population,finalintcount,finalOptimizeopt){finalPopulation<G,C>elite=_s1.select(population,1,opt);Phenotype<G,C>best=elite.get(0);appendFitness(best.getFitness());returnpopulation.isEmpty()||count<=0?newPopulation<>(0):append(elite,_s2.select(population,max(0,count-1),opt));}privatePopulation<G,C>append(finalPopulation<G,C>p1,finalPopulation<G,C>p2){p1.addAll(p2);returnp1;}privatesynchronizedvoidappendFitness(Cfitness){System.out.println(Thread.currentThread().getName()+"-"+fitnesses.size()+") Best Fitness: "+fitness+" "+newTimestamp(System.currentTimeMillis()));fitnesses.add(fitness);}
Notice the println in the apppendFitness method, that's what is called twice.
The value of 400 makes totally sense. You are using the same selector for offspring and survivors. You have to choose a different selector for the offsprings.
Hi, I do really like your work,
but is there any way to apply two (parent) selectors?
e.g., I would like to apply a truncation selector to keep the best phenotype, and then a Tournament to choose the others.
Is this possible?
Hi, there is no Selector implementation in the library with this functionality. But it is not hard to implement a Selector which does what you want:
How lazy of me to not think that I could implement it myself.
Thank you for your time.
Hi Franz,
There is a thing that i cannot seem to understand:
I've put a synchronized list in this selector to track down the fitness throught the generations, but at the end, the list has twice the elements than generations.
e.g., if I build the engine with engine.stream().limit(200) I expect a list of 200 elements, but I get a 400 elements one instead.
Is this a problem with my implementation or is a legit behaviour?
Btw: I suppose that in the code you kindly provided me the append method should return p1, if it works like the Collection javadoc suggests.
Without the source code, it is hard to say what you want to achieve and whether its a bug in the library.
I have a unit test (in
EngineTest
class), which checks the generation count:And yes, the method sould return p1.
Last edit: Franz Wilhelmstötter 2016-02-10
My bad, I'm not talking about bugs, but just to undarstand why the selector are called twice.
But you are right, without source code it's pretty difficult.
Here is my version of your code
Notice the println in the apppendFitness method, that's what is called twice.
And here is the code about the settings
The value of 400 makes totally sense. You are using the same selector for offspring and survivors. You have to choose a different selector for the offsprings.
Thats the gear I was missing.
Thank you again.