void Replace(Chromosome[] children) { Population nextPopulation = new Population(this, population.PopulationSize); for (int i = 0; i < populationSize; i++) { // // Since the recombination record for a chromosome may contain a // pointer to chromosome's in the previous population, it has to be // cleared out. This prevents us from getting an unbroken reference // chain between the current population's chromosomes all the way back // to the first population (which would prevent the garbage collector // from reclaiming any chromosome memory). // (There is probably some way we can configure how deep we want // to remember recombination records. But that might be overkill // if we get everything serializing nicely.) // population.Chromosomes[i].Parents = null; nextPopulation.Chromosomes[i] = children[i]; nextPopulation.Chromosomes[i].ID = nextChromosomeID++; } NewPopulationEventArgs e = new NewPopulationEventArgs(); e.OldPopulation = population; e.NewPopulation = nextPopulation; e.Generation = generation; OnNewPopulation(e); population = nextPopulation; // BUGBUG: should move this before the call out }
static void OnNewPopulation_ShowParents(object o, NewPopulationEventArgs e) { // // 00101110 // + 10100010 // ----^--- // = 00100010 // foreach(Chromosome c in e.NewPopulation.Chromosomes) { Console.WriteLine( " {0}", c.Parents[0]); Console.WriteLine( "+ {0}", c.Parents[1]); Console.Write( " "); for(int i=0;i<c.CrossoverPoint;i++) { Console.Write("--"); } Console.Write("^-"); for(int i=c.CrossoverPoint+1;i<c.Genes.Length;i++) { Console.Write("--"); } Console.WriteLine(); Console.WriteLine( "= {0}", c); Console.WriteLine(); } }
/// <summary> /// Raises the NewPopulation event. /// </summary> /// <param name="e"></param> protected virtual void OnNewPopulation(NewPopulationEventArgs e) { if (NewPopulation != null) { NewPopulation(this, e); } }
void NewPopulationHandler(object sender, NewPopulationEventArgs e) { IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); Stream stream = new FileStream(filenameBase + count + filenameExt, FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, e.NewPopulation); stream.Close(); count++; }
// // Handler for the "NewPopulation" event that is raised by the GA // component each time a new population has been evaluated. We take // the opportunity to print out information about the best chromosome // in the just-evaluated generation. // static void OnNewPopulation_ShowSummary(object o, NewPopulationEventArgs e) { Chromosome bestChromosome = e.OldPopulation.Summary.BestChromosome; Console.WriteLine( "{0}: {1} ({2})", e.Generation, bestChromosome, bestChromosome.RawObjective ); }
static void OnNewPopulation(object o, NewPopulationEventArgs e) { Console.WriteLine(); for(int i=0;i<e.NewPopulation.PopulationSize;i++) { Console.WriteLine( "{0,2}) {1} {2,2}) {3}", e.OldPopulation.Chromosomes[i].ID, e.OldPopulation.Chromosomes[i], e.NewPopulation.Chromosomes[i].ID, e.NewPopulation.Chromosomes[i] ); } }
static void OnNewPopulation(object o, NewPopulationEventArgs e) { //Console.WriteLine("Gen {0}: {1}", gen++, e.OldPopulation.Summary.BestChromosome); Console.WriteLine(e.OldPopulation.Summary); }
// // Handler for the "NewPopulation" event that is raised by the GA // component each time a new population has been evaluated. We take // the opportunity to print out some of the summary data for the // just-evaluated generation. // static void OnNewPopulation_ShowSummary(object o, NewPopulationEventArgs e) { Population oldPopulation = e.OldPopulation; // the just-evaluated population Console.WriteLine( "Generation: {0}", e.Generation ); Console.WriteLine( " Highest Objective: {0}", oldPopulation.Summary.HighestObjective ); Console.WriteLine( " Lowest Objective : {0}", oldPopulation.Summary.LowestObjective ); Console.WriteLine( " Best Individual : {0}", oldPopulation.Summary.BestChromosome ); }
void OnNewPopulation(object o, NewPopulationEventArgs e) { //System.Threading.Monitor.Enter(this); currentPopulationSummary = e.OldPopulation.Summary; //System.Threading.Monitor.Exit(this); axMSChart1.RowCount++; axMSChart1.DataGrid.SetData( ++generation, 1, currentPopulationSummary.BestChromosome.RawObjective, 0 ); graphPanel.Invalidate(); }
static void OnNewPopulation_ShowSummary(object o, NewPopulationEventArgs e) { Console.WriteLine( e.OldPopulation.Summary.ToString() ); }
void Replace(Chromosome[] children) { Population nextPopulation = new Population( this, population.PopulationSize ); for(int i=0;i<populationSize;i++) { // // Since the recombination record for a chromosome may contain a // pointer to chromosome's in the previous population, it has to be // cleared out. This prevents us from getting an unbroken reference // chain between the current population's chromosomes all the way back // to the first population (which would prevent the garbage collector // from reclaiming any chromosome memory). // (There is probably some way we can configure how deep we want // to remember recombination records. But that might be overkill // if we get everything serializing nicely.) // population.Chromosomes[i].Parents = null; nextPopulation.Chromosomes[i] = children[i]; nextPopulation.Chromosomes[i].ID = nextChromosomeID++; } NewPopulationEventArgs e = new NewPopulationEventArgs(); e.OldPopulation = population; e.NewPopulation = nextPopulation; e.Generation = generation; OnNewPopulation( e ); population = nextPopulation; // BUGBUG: should move this before the call out }
/// <summary> /// Raises the NewPopulation event. /// </summary> /// <param name="e"></param> protected virtual void OnNewPopulation(NewPopulationEventArgs e) { if ( NewPopulation != null ) { NewPopulation(this, e); } }
static void OnNewPopulation(object o, NewPopulationEventArgs e) { Chromosome c = e.OldPopulation.Summary.BestChromosome; Console.WriteLine("Best of Generation: {0}", e.OldPopulation.Summary.BestChromosome); Console.WriteLine(" cost = {0}", Objective.GetCost(c)); Console.WriteLine(" value = {0}", Objective.GetValue(c)); Console.WriteLine(" objective = {0}", c.RawObjective ); }