Exemplo n.º 1
0
Arquivo: ga.cs Projeto: mykwillis/genX
        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
        }
Exemplo n.º 2
0
 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();
     }
 }
Exemplo n.º 3
0
Arquivo: ga.cs Projeto: mykwillis/genX
 /// <summary>
 /// Raises the NewPopulation event.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnNewPopulation(NewPopulationEventArgs e)
 {
     if (NewPopulation != null)
     {
         NewPopulation(this, e);
     }
 }
Exemplo n.º 4
0
 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++;
 }
Exemplo n.º 5
0
        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++;
        }
Exemplo n.º 6
0
        //
        // 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
                );
        }
Exemplo n.º 7
0
 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]
             );
     }            
 }
Exemplo n.º 8
0
 static void OnNewPopulation(object o, NewPopulationEventArgs e)
 {
     //Console.WriteLine("Gen {0}: {1}", gen++, e.OldPopulation.Summary.BestChromosome);
     Console.WriteLine(e.OldPopulation.Summary);
 }
Exemplo n.º 9
0
        //
        // 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 );
        }
Exemplo n.º 10
0
        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();            
        }
Exemplo n.º 11
0
 static void OnNewPopulation_ShowSummary(object o, NewPopulationEventArgs e)
 {
     Console.WriteLine( e.OldPopulation.Summary.ToString() );
 }
Exemplo n.º 12
0
Arquivo: ga.cs Projeto: mykwillis/genX
        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
        }
Exemplo n.º 13
0
Arquivo: ga.cs Projeto: mykwillis/genX
 /// <summary>
 /// Raises the NewPopulation event.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnNewPopulation(NewPopulationEventArgs e)
 {
     if ( NewPopulation != null )
     {
         NewPopulation(this, e);
     }
 }
Exemplo n.º 14
0
        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 );
        }