一般来说,你会如何打印或绘制使用jenetics库创建的每一代的健身分数?
在我自己的代码上更具体:
private static double clashes(final Genotype<EnumGene<Integer>> gt) {
// Calculate the path distance.
final int[] intTriplets=gt.getChromosome().stream().mapToInt(EnumGene<Integer>::getAllele).toArray();
ArrayList<Triplet> triplets=new ArrayList<Triplet>();
for(int i=0;i<intTriplets.length;i++)
{
Triplet e=intToTriplet.get(intTriplets[i]);
triplets.add(e);
}
double clashes=returnScore(triplets);
return (clashes);
public static void main(String[] args) {
final Engine<EnumGene<Integer>, Double> engine = Engine
.builder(
GA::clashes,
PermutationChromosome.ofInteger(REQUIREMENTS))
.optimize(Optimize.MINIMUM)
.offspringFraction(0.75)//0.6 standaard
.survivorsSelector (new TournamentSelector <>(7) ) //standaard new TournamentSelector <>(3)
.offspringSelector (new RouletteWheelSelector <>() ) //standaard new TournamentSelector <>(3)
.maximalPhenotypeAge(40)//standaard 70
.populationSize(1000)
//.selector(new TournamentSelector<>(5))
.alterers(
new SwapMutator<>(0.02),
new PartiallyMatchedCrossover<>(0.7))
.build();我注意到可能会有过早的收敛,因为我只得到了有限的几代人,尽管我把稳定的健身极限设定在200。因此,我想找出哪一代的健身得分变化接近于0,并打印出每一代最佳元素的健身分数。
发布于 2017-12-22 10:27:23
您可以使用Stream.peek方法:java EvolutionResult<EnumGene<Integer>, Double> stream = engine.stream() .limit(100) .peek(er -> System.out.println(er.getBestPhenotype())) .collect(EvolutionResult.toBestEvolutionResult());在进化过程中打印出信息,这将为每个世代打印最佳的表型。
https://stackoverflow.com/questions/47938860
复制相似问题