public void EvaluatePopulation(Population pop, EvolutionAlgorithm ea) { int count = pop.GenomeList.Count; evalPack e; IGenome g; int i; for (i = 0; i < count; i++) { //Console.WriteLine(i); sem.WaitOne(); g = pop.GenomeList[i]; e = new evalPack(networkEvaluator, activationFn, g, i % HyperNEATParameters.numThreads,(int)ea.Generation); ThreadPool.QueueUserWorkItem(new WaitCallback(evalNet), e); // Update master evaluation counter. evaluationCount++; /*if(printFinalPositions) file.WriteLine(g.Behavior.behaviorList[0].ToString() + ", " + g.Behavior.behaviorList[1].ToString());//*/ } //Console.WriteLine("waiting for last threads.."); for (int j = 0; j < HyperNEATParameters.numThreads; j++) { sem.WaitOne(); // Console.WriteLine("waiting"); } for (int j = 0; j < HyperNEATParameters.numThreads; j++) { //Console.WriteLine("releasing"); sem.Release(); } //Console.WriteLine("generation done..."); //calulate novelty scores... if(ea.NeatParameters.noveltySearch) { if(ea.NeatParameters.noveltySearch) { ea.CalculateNovelty(); } } }
public virtual void EvaluatePopulation(Population pop, EvolutionAlgorithm ea) { // Evaluate in single-file each genome within the population. // Only evaluate new genomes (those with EvaluationCount==0). int count = pop.GenomeList.Count; for(int i=0; i<count; i++) { IGenome g = pop.GenomeList[i]; if(g.EvaluationCount!=0) continue; INetwork network = g.Decode(activationFn); if(network==null) { // Future genomes may not decode - handle the possibility. g.Fitness = EvolutionAlgorithm.MIN_GENOME_FITNESS; } else { BehaviorType behavior; g.Fitness = Math.Max(networkEvaluator.EvaluateNetwork(network,out behavior), EvolutionAlgorithm.MIN_GENOME_FITNESS); g.RealFitness = g.Fitness; g.Behavior = behavior; } // Reset these genome level statistics. g.TotalFitness = g.Fitness; g.EvaluationCount = 1; // Update master evaluation counter. evaluationCount++; } if(ea.NeatParameters.noveltySearch) { if(ea.NeatParameters.noveltySearch && ea.noveltyInitialized) { ea.CalculateNovelty(); } } }