/// <summary> /// Determine the species of each genome in genomeList and build the 'species' Hashtable. /// </summary> public void BuildSpeciesTable(EvolutionAlgorithm ea) { //----- Build the table. speciesTable = new Hashtable(); // First pass. Genomes that already have an assigned species. //foreach(IGenome genome in genomeList) int genomeIdx; int genomeBound = genomeList.Count; for (genomeIdx = 0; genomeIdx < genomeBound; genomeIdx++) { IGenome genome = genomeList[genomeIdx]; if (genome.SpeciesId != -1) { AddGenomeToSpeciesTable(ea, genome); } } // Second pass. New genomes. Performing two passes ensures we preserve the species IDs. for (genomeIdx = 0; genomeIdx < genomeBound; genomeIdx++) { IGenome genome = genomeList[genomeIdx]; if (genome.SpeciesId == -1) { AddGenomeToSpeciesTable(ea, genome); } } }
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 initializeEvolution(int populationSize) { logOutput = new StreamWriter(outputFolder + "logfile.txt"); IdGenerator idgen = new IdGenerator(); ea = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(experiment.DefaultNeatParameters, idgen, experiment.InputNeuronCount, experiment.OutputNeuronCount, experiment.OutputsPerPolicy, experiment.DefaultNeatParameters.pInitialPopulationInterconnections, populationSize)), experiment.PopulationEvaluator, experiment.DefaultNeatParameters); }
public EvolutionAlgorithm initializeEvolutionAlgorithm(IPopulationEvaluator popEval, int popSize, AssessGenotypeFunction assess, List <long> parentGenomeIDs = null) { //have to add our seed to the parents! if (officialSeedGenome != null) { //if we aren't given any parents, make a new list, and add the seed if (parentGenomeIDs == null) { parentGenomeIDs = new List <long>(); } parentGenomeIDs.Add(officialSeedGenome.GenomeId); } //create our initial population, using seeds or not, making sure it is at least "popsize" long GenomeList gl = createGenomeList(popSize, assess, parentGenomeIDs); //now we have a genomelist full of our parents, if they didn't die in a car crash when we were young, yay! //also, these parents, their connections, and neurons are safely catalogued by WIN (eventually...) Population pop = new Population(idgen, gl); //create our algorithm evoAlgorithm = new EvolutionAlgorithm(pop, popEval, neatParams, assess); createExperimentDirectory(); //send it away! return(evoAlgorithm); }
/// <summary> /// This version of AddGenomeToSpeciesTable is used by RedetermineSpeciation(). It allows us to /// pass in the genome's original species object, which we can then re-use if the genome does not /// match any of our existing species and needs to be placed into a new species of it's own. /// The old species object can be used directly because it should already have already had all of /// its genome sremoved by RedetermineSpeciation() before being passed in here. /// </summary> /// <param name="ea"></param> /// <param name="genome"></param> /// <param name="originalSpecies"></param> private void AddGenomeToSpeciesTable(EvolutionAlgorithm ea, IGenome genome, Species originalSpecies) { Species species = DetermineSpecies(ea, genome); if (species == null) { // The genome is not in one of the existing (new) species. Is this genome's old // species already in the new table? species = (Species)speciesTable[genome.SpeciesId]; if (species != null) { // The genomes old species is already in the table but the genome no longer fits into that // species. Therefore we need to create an entirely new species. species = new Species(); species.SpeciesId = nextSpeciesId++; } else { // We can re-use the oldSpecies object. species = originalSpecies; } speciesTable.Add(species.SpeciesId, species); } //----- The genome is a member of an existing species. genome.SpeciesId = species.SpeciesId; species.Members.Add(genome); }
public void EvaluatePopulation(Population pop, EvolutionAlgorithm ea) { int count = pop.GenomeList.Count; for (var i = 0; i < count; i++) { Sem.WaitOne(); var g = pop.GenomeList[i]; var e = new EvalPack(_networkEvaluator, _activationFn, g); ThreadPool.QueueUserWorkItem(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(); } _networkEvaluator.endOfGeneration(); // GWM - Update novelty stuff }
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 { g.Fitness = Math.Max(networkEvaluator.EvaluateNetwork(network), EvolutionAlgorithm.MIN_GENOME_FITNESS); } // Reset these genome level statistics. g.TotalFitness = g.Fitness; g.EvaluationCount = 1; // Update master evaluation counter. evaluationCount++; } }
public void AddGenomeToPopulation(EvolutionAlgorithm ea, IGenome genome) { //----- Add genome to the master list of genomes. genomeList.Add(genome); //----- Determine it's species and insert into the speciestable. AddGenomeToSpeciesTable(ea, genome); }
private void EvolutionaryThread() { m_exp = CreateExperiment(); var idgen = new IdGenerator(); m_evoAlg = new EvolutionAlgorithm( new Population(idgen, GenomeFactory.CreateGenomeList(m_exp.DefaultNeatParameters, idgen, m_exp.InputNeuronCount, m_exp.OutputNeuronCount, m_exp.DefaultNeatParameters.pInitialPopulationInterconnections, NeatExpParams.PopulationSize)), m_exp.PopulationEvaluator, m_exp.DefaultNeatParameters); while (!m_shouldQuit) { Console.WriteLine("::::: Performing one generation"); Console.WriteLine(); m_evoAlg.PerformOneGeneration(); if (NeatExpParams.SaveFitnessGrowth) { m_eaLogger.WriteLine(String.Format("{0,-10} {1,-20} {2,-20} {3,-20}", m_evoAlg.Generation, m_evoAlg.BestGenome.Fitness, m_evoAlg.Population.MeanFitness, m_evoAlg.Population.AvgComplexity)); } m_curBestGenome = m_evoAlg.BestGenome as NeatGenome; if (m_evoAlg.BestGenome.Fitness > m_overalBestFitness) { m_overalBestFitness = m_evoAlg.BestGenome.Fitness; m_overalBestGenome = m_curBestGenome; if (NeatExpParams.SaveEachGenerationChampionCPPN) { try { var doc = new XmlDocument(); XmlGenomeWriterStatic.Write(doc, (NeatGenome)m_evoAlg.BestGenome); var oFileInfo = new FileInfo(Path.Combine( NeatExpParams.EALogDir, String.Format("BestIndividual-{0}-{1}.xml", MyUnum, m_evoAlg.Generation.ToString()))); doc.Save(oFileInfo.FullName); } catch { } } } if (EAUpdate != null) { EAUpdate.Invoke(this, EventArgs.Empty); } } }
public void initalizeEvolution(Population pop) { if (logOutput != null) { logOutput.Close(); } logOutput = new StreamWriter(outputFolder + "logfile.txt"); //IdGenerator idgen = new IdGeneratorFactory().CreateIdGenerator(pop.GenomeList); ea = new EvolutionAlgorithm(pop, populationEval, neatParams); }
public void initializeEvolution(int populationSize) { if (logOutput != null) { logOutput.Close(); } logOutput = new StreamWriter(outputFolder + "logfile.txt"); IdGenerator idgen = new IdGenerator(); ea = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(neatParams, idgen, cppnInputs, cppnOutputs, neatParams.pInitialPopulationInterconnections, populationSize)), populationEval, neatParams); }
public void EvaluatePopulation(Population pop, EvolutionAlgorithm ea) { resetGenomes(pop); if (AnalyzeHands) { Console.WriteLine("Caching {0} for this generation", CachedHandsPerGeneration); cachedHands = new List <CachedHand>(); for (var i = 0; i < CachedHandsPerGeneration; i++) { if (i % 10 == 0) { Console.WriteLine("{0} hands cached", i); } cachedHands.Add(new CachedHand(MaxPlayersPerGame, random)); } } var count = pop.GenomeList.Count; //TODO: Parallelize/Distribute this loop //Ideally we should have a distributed method which returns an array of //doubles to add to the genome fitnesses of each individual. for (var i = 0; i < count; i++) { Console.WriteLine("Individual #{0}", i + 1); var g = pop.GenomeList[i]; var network = g.Decode(ActivationFunction); if (network == null) { // Future genomes may not decode - handle the possibility. g.Fitness = EvolutionAlgorithm.MIN_GENOME_FITNESS; g.TotalFitness = g.Fitness; g.EvaluationCount = 1; continue; } for (int round = 0; round < TourneysPerNetwork; round++) { //int playersThisHand = random.Next(MinPlayersPerGame, MaxPlayersPerGame + 1); var field = getPlayers(pop, i, MaxPlayersPerGame); var stacks = getStacks(MaxPlayersPerGame); //List<double> roi = playRound(field, stacks); var roi = playSemiTourney(field, stacks); addScores(field, roi); } } //normalize the win rates to [0...max+min] assignFitness(pop); }
public void initializeEvolution(int populationSize, NeatGenome seedGenome) { if (seedGenome == null) { initializeEvolution(populationSize); return; } logOutput = new StreamWriter(outputFolder + "logfile.txt"); IdGenerator idgen = new IdGeneratorFactory().CreateIdGenerator(seedGenome); ea = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(seedGenome, populationSize, experiment.DefaultNeatParameters, idgen)), experiment.PopulationEvaluator, experiment.DefaultNeatParameters); }
private bool IsGenomeInSpecies(IGenome genome, Species compareWithSpecies, EvolutionAlgorithm ea) { // // Pick a member of the species at random. // IGenome compareWithGenome = compareWithSpecies.Members[(int)Math.Floor(compareWithSpecies.Members.Count * Utilities.NextDouble())]; // return (genome.CalculateCompatibility(compareWithGenome, ea.NeatParameters) < ea.NeatParameters.compatibilityThreshold); // Compare against the species champ. The species champ is the exemplar that represents the species. IGenome compareWithGenome = compareWithSpecies.Members[0]; //IGenome compareWithGenome = compareWithSpecies.Members[(int)Math.Floor(compareWithSpecies.Members.Count * Utilities.NextDouble())]; return(genome.IsCompatibleWithGenome(compareWithGenome, ea.NeatParameters)); }
public NoveltyThread(JSPopulationEvaluator jsPop, AssessGenotypeFunction assess, int popSize) { //save our objects for executing later! popEval = jsPop; populationSize = popSize; autoEvent = new AutoResetEvent(false); waitNextTime = true; novelThread = new Thread(delegate() { autoEvent.WaitOne(); //we'll start by testing with 0 parents, and popsize of 15 yay! noveltyRun = EvolutionManager.SharedEvolutionManager.initializeEvolutionAlgorithm(popEval, populationSize, assess); //let our algoirhtm know we want to do novelty gosh darnit if (noveltyRun.multiobjective != null) { noveltyRun.multiobjective.doNovelty = true; } //we make sure we don't wait in this loop, since we just got started! waitNextTime = false; while (true) { //this will cause us to pause! if (waitNextTime) { waitNextTime = false; autoEvent.WaitOne(); } // Start the stopwatch we'll use to measure eval performance Stopwatch sw = Stopwatch.StartNew(); //run the generation noveltyRun.PerformOneGeneration(); // Stop the stopwatch sw.Stop(); // Report the results Console.WriteLine("Time used per gen (float): {0} ms", sw.Elapsed.TotalMilliseconds); Console.WriteLine("Time used per gen (rounded): {0} ms", sw.ElapsedMilliseconds); } }); novelThread.Start(); }
public override 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++) { // Grab the next individual out of the population IGenome g = pop.GenomeList[i]; if (g.EvaluationCount != 0) { continue; } // The current genome is a CPPN genome, not a network genome // So, decode the CPPN genome into a CPPN, use the CPPN to generate an ANN, // then run the networkEvaluator on the ANN INetwork cppn = g.Decode(activationFn); if (cppn == null) { // Future genomes may not decode - handle the possibility. g.Fitness = EvolutionAlgorithm.MIN_GENOME_FITNESS; } else { //BehaviorType behavior; //INetwork network = Chromaria.Simulator.controllerSubstrate.generateGenome(cppn).Decode(activationFn); g.Fitness = Math.Max(0.0f, EvolutionAlgorithm.MIN_GENOME_FITNESS); //if (Chromaria.Simulator.plantingWasValid) //Chromaria.Simulator.successfulPlanterGenome = g; g.RealFitness = g.Fitness; } // Reset these genome level statistics. g.TotalFitness = g.Fitness; g.EvaluationCount = 1; // Update master evaluation counter. evaluationCount++; // Close the XML tag for this individual //Chromaria.Simulator.xmlWriter.WriteEndElement(); } if (ea.NeatParameters.noveltySearch) { if (ea.NeatParameters.noveltySearch && ea.noveltyInitialized) { ea.CalculateNovelty(); } } }
/// <summary> /// Determine the given genome's species and return that species. If the genome does not /// match one of the existing species then we return null to indicate a new species. /// </summary> /// <param name="genome"></param> /// <returns></returns> private Species DetermineSpecies(EvolutionAlgorithm ea, IGenome genome) { //----- Performance optimization. Check against parent species IDs first. Species parentSpecies1 = null; Species parentSpecies2 = null; // Parent1. Not set in initial population. if (genome.ParentSpeciesId1 != -1) { parentSpecies1 = (Species)speciesTable[genome.ParentSpeciesId1]; if (parentSpecies1 != null) { if (IsGenomeInSpecies(genome, parentSpecies1, ea)) { return(parentSpecies1); } } } // Parent2. Not set if result of asexual reproduction. if (genome.ParentSpeciesId2 != -1) { parentSpecies2 = (Species)speciesTable[genome.ParentSpeciesId2]; if (parentSpecies2 != null) { if (IsGenomeInSpecies(genome, parentSpecies2, ea)) { return(parentSpecies2); } } } //----- Not in parent species. Systematically compare against all species. foreach (Species compareWithSpecies in speciesTable.Values) { // Don't compare against the parent species again. if (compareWithSpecies == parentSpecies1 || compareWithSpecies == parentSpecies2) { continue; } if (IsGenomeInSpecies(genome, compareWithSpecies, ea)) { // We have found matching species. return(compareWithSpecies); } } //----- The genome is not a member of any existing species. return(null); }
public override void EvaluatePopulation(Population pop, EvolutionAlgorithm ea) { // Evaluate in single-file each genome within the population. // Only evaluate new genomes (those with EvaluationCount==0). FoodGatherParams.fillLookups(); FoodGatherParams.fillFood(); 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 { g.Fitness = Math.Max(networkEvaluator.EvaluateNetwork(network), EvolutionAlgorithm.MIN_GENOME_FITNESS); g.ObjectiveFitness = g.Fitness; } // Reset these genome level statistics. g.TotalFitness = g.Fitness; g.EvaluationCount = 1; // Update master evaluation counter. evaluationCount++; } if (requestResolutionUp == true) { requestResolutionUp = false; requestResolutionDown = false; FoodGatherParams.resolution *= 2; } else if (requestResolutionDown == true) { requestResolutionUp = false; requestResolutionDown = false; if (FoodGatherParams.resolution > 4) { FoodGatherParams.resolution /= 2; } } }
public void initializeEvolution(int populationSize, NeatGenome seedGenome) { if (seedGenome == null) { initializeEvolution(populationSize); return; } if (logOutput != null) { logOutput.Close(); } logOutput = new StreamWriter(outputFolder + "logfile.txt"); IdGenerator idgen = new IdGeneratorFactory().CreateIdGenerator(seedGenome); ea = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(seedGenome, populationSize, neatParams, idgen)), populationEval, neatParams); }
private void AddGenomeToSpeciesTable(EvolutionAlgorithm ea, IGenome genome) { Species species = DetermineSpecies(ea, genome); if (species == null) { species = new Species(); // Completely new species. Generate a speciesID. species.SpeciesId = nextSpeciesId++; speciesTable.Add(species.SpeciesId, species); } //----- The genome is a member of an existing species. genome.SpeciesId = species.SpeciesId; species.Members.Add(genome); }
/// <summary> /// Initializes the EA using an initial population that has already been read into object format. /// </summary> /// <param name="pop"></param> public void initalizeEvolution(Population pop) { LogOutput = Logging ? new StreamWriter(Path.Combine(OutputFolder, "log.txt")) : null; FinalPositionOutput = FinalPositionLogging ? new StreamWriter(Path.Combine(OutputFolder, "final-position.txt")) : null; ArchiveModificationOutput = FinalPositionLogging ? new StreamWriter(Path.Combine(OutputFolder, "archive-mods.txt")) : null; ComplexityOutput = new StreamWriter(Path.Combine(OutputFolder, "complexity.txt")); ComplexityOutput.WriteLine("avg,stdev,min,max"); if (FinalPositionLogging) { FinalPositionOutput.WriteLine("ID,x,y"); ArchiveModificationOutput.WriteLine("ID,action,time,x,y"); } EA = new EvolutionAlgorithm(pop, experiment.PopulationEvaluator, experiment.DefaultNeatParameters); EA.outputFolder = OutputFolder; EA.neatBrain = NEATBrain; }
//private static Random random; public static void Main(string[] args) { Util.Initialize(args[0]); var idgen = new IdGenerator(); IExperiment experiment = new LimitExperiment(); XmlSerializer ser = new XmlSerializer(typeof(Settings)); //Settings settings = new Settings() //{ // SmallBlind = 1, // BigBlind = 2, // GamesPerIndividual = 100, // LogFile = "mutlithreaded_log.txt", // MaxHandsPerTourney = 200, // PlayersPerGame = 6, // StackSize = 124, // Threads = 4 //}; //ser.Serialize(new StreamWriter("settings.xml"), settings); Settings settings = (Settings)ser.Deserialize(new StreamReader("settings.xml")); var eval = new PokerPopulationEvaluator <SimpleLimitNeuralNetPlayer2, RingGamePlayerEvaluator>(settings); var ea = new EvolutionAlgorithm( new Population(idgen, GenomeFactory.CreateGenomeList(experiment.DefaultNeatParameters, idgen, experiment.InputNeuronCount, experiment.OutputNeuronCount, experiment.DefaultNeatParameters.pInitialPopulationInterconnections, experiment.DefaultNeatParameters.populationSize)), eval, experiment.DefaultNeatParameters); Console.WriteLine("Starting real evolution"); for (int i = 0; true; i++) { Console.WriteLine("Generation {0}", i + 1); ea.PerformOneGeneration(); Console.WriteLine("Champion Fitness={0}", ea.BestGenome.Fitness); var doc = new XmlDocument(); XmlGenomeWriterStatic.Write(doc, (NeatGenome)ea.BestGenome); FileInfo oFileInfo = new FileInfo("genomes_simple\\" + "bestGenome" + i.ToString() + ".xml"); doc.Save(oFileInfo.FullName); } }
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(); } } }
/// <summary> /// Initializes the EA with a random intial population. /// </summary> public void initializeEvolution(int populationSize) { LogOutput = Logging ? new StreamWriter(Path.Combine(OutputFolder, "log.txt")) : null; FinalPositionOutput = FinalPositionLogging ? new StreamWriter(Path.Combine(OutputFolder, "final-position.txt")) : null; ArchiveModificationOutput = FinalPositionLogging ? new StreamWriter(Path.Combine(OutputFolder, "archive-mods.txt")) : null; ComplexityOutput = new StreamWriter(Path.Combine(OutputFolder, "complexity.txt")); ComplexityOutput.WriteLine("avg,stdev,min,max"); if (FinalPositionLogging) { FinalPositionOutput.WriteLine("ID,x,y"); ArchiveModificationOutput.WriteLine("ID,action,time,x,y"); } IdGenerator idgen = new IdGenerator(); EA = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(experiment.DefaultNeatParameters, idgen, experiment.InputNeuronCount, experiment.OutputNeuronCount, experiment.DefaultNeatParameters.pInitialPopulationInterconnections, populationSize, SimExperiment.neatBrain)), experiment.PopulationEvaluator, experiment.DefaultNeatParameters); EA.outputFolder = OutputFolder; EA.neatBrain = NEATBrain; }
public void RedetermineSpeciation(EvolutionAlgorithm ea) { // Keep a reference to the old species table. Hashtable oldSpeciesTable = speciesTable; // Remove the gnomes from the old species objects. Note that the genome's can still be // accessed via 'genomeList' and that they still contain the old speciesId. foreach (Species species in oldSpeciesTable.Values) { species.Members.Clear(); } // Create a new species table. speciesTable = new Hashtable(); // Loop through all of the genomes and place them into the new species table. // Use the overload for AddGenomeToSpeciesTable() that re-uses the old species // objects instead of creating new species. int genomeBound = genomeList.Count; for (int genomeIdx = 0; genomeIdx < genomeBound; genomeIdx++) { IGenome genome = genomeList[genomeIdx]; Species oldSpecies = (Species)oldSpeciesTable[genome.SpeciesId]; AddGenomeToSpeciesTable(ea, genome, oldSpecies); } // speciesTable.Clear(); // // int genomeBound = genomeList.Count; // for(int genomeIdx=0; genomeIdx<genomeBound; genomeIdx++) // { // IGenome genome = genomeList[genomeIdx]; // // genome.SpeciesId = -1; // genome.ParentSpeciesId1=-1; // genome.ParentSpeciesId2=-1; // AddGenomeToSpeciesTable(ea, genome); // } }
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 void ResetPopulation(GenomeList l, EvolutionAlgorithm ea) { speciesToRemove.Clear(); foreach (Species species in speciesTable.Values) { speciesToRemove.Add(species.SpeciesId); } int speciesBound = speciesToRemove.Count; for (int speciesIdx = 0; speciesIdx < speciesBound; speciesIdx++) { speciesTable.Remove(speciesToRemove[speciesIdx]); } for (int i = 0; i < l.Count; i++) { this.AddGenomeToPopulation(ea, l[i]); } this.RebuildGenomeList(); }
public void EvaluatePopulation(Population pop, EvolutionAlgorithm ea) { List <IPlayer> allPlayers = CreatePlayers(pop); threads = new List <ThreadInfo>(); //for (var i = 0; i < allPlayers.Count; i++) //{ // Console.WriteLine("Individual #{0}", i + 1); // for (var games = 0; games < settings.GamesPerIndividual; games++) // { // if (threads.Count >= settings.Threads) // WaitOne(); //List<IPlayer> table = allPlayers.RandomSubset(settings.PlayersPerGame - 1, random); //table.Add(allPlayers[i]); threadsToUse = Settings.IsPeakHours() ? settings.PeakHoursThreads : settings.Threads; Console.WriteLine("Using {0} evaluation threads", threadsToUse); for (int i = 0; i < threadsToUse; i++) { EvaluatorType eval = new EvaluatorType(); Thread t = new Thread(delegate() { eval.Evaluate(allPlayers, settings, false, settings.GamesPerIndividual / threadsToUse); }); threads.Add(new ThreadInfo() { EvalThread = t, Evaluator = eval, Table = allPlayers }); t.Start(); } WaitAll(); AssignFitness(pop); PlayChampions(allPlayers); EvaluationCount++; }
/// <summary> /// Initializes the EA with an initial population generated from a single seed genome. /// </summary> public void initializeEvolution(int populationSize, NeatGenome seedGenome) { if (seedGenome == null) { initializeEvolution(populationSize); return; } LogOutput = Logging ? new StreamWriter(Path.Combine(OutputFolder, "log.txt")) : null; FinalPositionOutput = FinalPositionLogging ? new StreamWriter(Path.Combine(OutputFolder, "final-position.txt")) : null; ArchiveModificationOutput = FinalPositionLogging ? new StreamWriter(Path.Combine(OutputFolder, "archive-mods.txt")) : null; ComplexityOutput = new StreamWriter(Path.Combine(OutputFolder, "complexity.txt")); ComplexityOutput.WriteLine("avg,stdev,min,max"); if (FinalPositionLogging) { FinalPositionOutput.WriteLine("x,y"); ArchiveModificationOutput.WriteLine("ID,action,time,x,y"); } IdGenerator idgen = new IdGeneratorFactory().CreateIdGenerator(seedGenome); EA = new EvolutionAlgorithm(new Population(idgen, GenomeFactory.CreateGenomeList(seedGenome, populationSize, experiment.DefaultNeatParameters, idgen)), experiment.PopulationEvaluator, experiment.DefaultNeatParameters); EA.outputFolder = OutputFolder; EA.neatBrain = NEATBrain; }
/// <summary> /// Sexual reproduction. No mutation performed. /// </summary> /// <param name="parent"></param> /// <returns></returns> abstract public IGenome CreateOffspring_Sexual(EvolutionAlgorithm ea, IGenome parent);