public static void evalNet(Object input)
        {
            evalPack e = (evalPack)input;

            if (e.g == null) //|| e.g.EvaluationCount != 0)
            {
                sem.Release();
                return;
            }
            sem2.WaitOne();
            INetwork network = e.g.Decode(e.Activation);

            sem2.Release();
            if (network == null)
            {   // Future genomes may not decode - handle the possibility.
                e.g.Fitness = EvolutionAlgorithm.MIN_GENOME_FITNESS;
            }
            else
            {
                e.g.Fitness = Math.Max(e.NetworkEvaluator.threadSafeEvaluateNetwork(network, sem2), EvolutionAlgorithm.MIN_GENOME_FITNESS);
            }

            // Reset these genome level statistics.
            e.g.TotalFitness    += e.g.Fitness;
            e.g.EvaluationCount += 1;
            sem.Release();
        }
        public static void evalNet(Object input)
        {
            evalPack e = (evalPack)input;

            if (e.g == null || (!HyperNEATParameters.reevaluateEveryGeneration && e.g.EvaluationCount != 0))
            {
                sem.Release();
                return;
            }
            sem2.WaitOne();
            INetwork network = e.g.Decode(e.Activation);

            sem2.Release();
            if (network == null)
            {   // Future genomes may not decode - handle the possibility.
                e.g.Fitness     = EvolutionAlgorithm.MIN_GENOME_FITNESS;
                e.g.RealFitness = e.g.Fitness;
            }
            else
            {
                BehaviorType behavior;
                e.g.Fitness     = Math.Max(e.NetworkEvaluator.threadSafeEvaluateNetwork(network, sem2, out behavior, e.ThreadNumber), EvolutionAlgorithm.MIN_GENOME_FITNESS);
                e.g.Behavior    = behavior;
                e.g.RealFitness = e.g.Fitness;
            }

            // Reset these genome level statistics.
            e.g.TotalFitness    += e.g.Fitness;
            e.g.EvaluationCount += 1;
            sem.Release();
        }
        public void EvaluatePopulation(Population pop, EvolutionAlgorithm ea)
        {
            int count = pop.GenomeList.Count;

            evalPack e;
            IGenome  g;
            int      i;

            for (i = 0; i < count; i++)
            {
                sem.WaitOne();
                g = pop.GenomeList[i];
                e = new evalPack(networkEvaluator, activationFn, g);

                ThreadPool.QueueUserWorkItem(new WaitCallback(evalNet), e);
                // Update master evaluation counter.
                evaluationCount++;
            }

            for (int j = 0; j < HyperNEATParameters.numThreads; j++)
            {
                sem.WaitOne();
            }
            for (int j = 0; j < HyperNEATParameters.numThreads; j++)
            {
                sem.Release();
            }
        }
        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();
                }
            }

        }
Esempio n. 5
0
        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 static void evalNet(Object input)
        {
            evalPack e = (evalPack)input;

            if (e.g == null || (!HyperNEATParameters.reevaluateEveryGeneration && e.g.EvaluationCount != 0))
            {
                sem.Release();
                return;
            }
            sem2.WaitOne();

            // Schrum: Debugging

            /*
             * XmlDocument doc = new XmlDocument();
             * XmlGenomeWriterStatic.Write(doc, (SharpNeatLib.NeatGenome.NeatGenome)e.g);
             * FileInfo oFileInfo = new FileInfo("MostRecentlySaved.xml");
             * doc.Save(oFileInfo.FullName);
             */
            INetwork network = e.g.Decode(e.Activation);

            sem2.Release();
            if (network == null)
            {   // Future genomes may not decode - handle the possibility.
                e.g.Fitness     = EvolutionAlgorithm.MIN_GENOME_FITNESS;
                e.g.RealFitness = e.g.Fitness;
            }
            else
            {
                BehaviorType behavior;
                e.g.Fitness     = Math.Max(e.NetworkEvaluator.threadSafeEvaluateNetwork(network, sem2, out behavior, e.ThreadNumber), EvolutionAlgorithm.MIN_GENOME_FITNESS);
                e.g.Behavior    = behavior;
                e.g.RealFitness = e.g.Fitness;
            }

            // Reset these genome level statistics.
            e.g.TotalFitness    += e.g.Fitness;
            e.g.EvaluationCount += 1;
            sem.Release();
        }
        public void EvaluatePopulation(Population pop, EvolutionAlgorithm ea)
        {
            int count = pop.GenomeList.Count;

            evalPack e;
            IGenome g;
            int i;

            for (i = 0; i < count; i++)
            {

                sem.WaitOne();
                g = pop.GenomeList[i];
                e = new evalPack(networkEvaluator, activationFn, g);

                ThreadPool.QueueUserWorkItem(new WaitCallback(evalNet), e);
                // Update master evaluation counter.
                evaluationCount++;

            }

            for (int j = 0; j < HyperNEATParameters.numThreads; j++)
            {
                sem.WaitOne();
            }
            for (int j = 0; j < HyperNEATParameters.numThreads; j++)
            {
                sem.Release();
            }
        }