public void Run() { GA Ga; Ga = new GA(); Ga.EncodingType = EncodingType.Integer; Ga.MinIntValue = -5000; Ga.MaxIntValue = 5000; Ga.ChromosomeLength = Coefficients.Length; Ga.PopulationSize = Coefficients.Length * 10; Ga.Objective = new ObjectiveDelegate(this.LinearDiophantineObjective); Ga.ObjectiveType = ObjectiveType.MinimizeObjective; Ga.Terminate += new TerminateEventHandler(new ObjectiveThresholdTerminator(0).Terminate); Ga.Terminate += new TerminateEventHandler(new EvolutionTimeTerminator(new TimeSpan(0, 0, 20)).Terminate); Ga.NewPopulation += new NewPopulationEventHandler(OnNewPopulation_ShowSummary); Ga.FitnessScaling = FitnessScaling.LinearRanked; Ga.Run(); Console.WriteLine("Best Individual: (obj={0})", Ga.BestObjective); PopulationSummary ps = new PopulationSummary(Ga, Ga.Population); Console.WriteLine(ps.BestChromosome); Console.WriteLine("Finished. Hit return."); Console.ReadLine(); }
static void Main() { // // Create the genetic algorithm component, and set the required // properties. // GA ga = new GA(); ga.EncodingType = EncodingType.Binary; ga.ChromosomeLength = 10; ga.PopulationSize = 50; ga.MaxGenerations = 10; // // Set the objective function for the run, which provides feedback // to the algorithm as to the relative merit of candidate solutions. // ga.Objective = new ObjectiveDelegate(BinaryAlternateObjective); // // Set a "NewPopulation" event handler so that we get a callback on // each new generation. During the callback, we print out the // generation's statistics and the best chromosome found so far. // ga.NewPopulation += new NewPopulationEventHandler(OnNewPopulation_ShowSummary); // // Run the algorithm. It will stop after ga.MaxGenerations have elapsed. // ga.Run(); // // Output the best individual that was found during the run. // Console.WriteLine("Best Individual:"); PopulationSummary ps = new PopulationSummary(ga, ga.Population); Console.WriteLine(ps.BestChromosome); Console.WriteLine("Finished. Hit return."); Console.ReadLine(); }
static void Main() { // // Describe the coding of our problem as an array of 10 integers // in the range [-10,10]. // GA ga = new GA(); ga.ChromosomeLength = 10; ga.PopulationSize = 100; ga.MaxGenerations = 100; ga.EncodingType = EncodingType.Integer; ga.MinIntValue = -10; ga.MaxIntValue = 10; ga.Objective = new ObjectiveDelegate(IntegerMaximizationObjective); ga.MutationOperator = MutationOperator.GeneSpecific; // // Set a "NewPopulation" event handler so that we get a callback on // each new generation. During the callback, we print out the // generation's statistics and the best chromosome found so far. // ga.NewPopulation += new NewPopulationEventHandler(OnNewPopulation_ShowSummary); // // Let it run until default termination criteria are met, or // MaxGenerations has elapsed. // ga.Run(); // // Output the best individual that was found during the run. // Console.WriteLine("Best Individual:"); PopulationSummary ps = new PopulationSummary(ga, ga.Population); Console.WriteLine(ps.BestChromosome); Console.WriteLine("Finished. Hit return."); Console.ReadLine(); }
static void Main(string[] args) { GA ga; ga = new GA(); ga.Homogeneous = true; ga.ChromosomeLength = 5; ga.EncodingType = EncodingType.Real; ga.MinDoubleValue = -30; ga.MaxDoubleValue = 30; ga.Objective = new ObjectiveDelegate(AckleyMinimizationObjective); ga.ObjectiveType = ObjectiveType.MinimizeObjective; ga.Run(); PopulationSummary ps = new PopulationSummary(ga, ga.Population); Console.WriteLine("Best Individual:"); Console.WriteLine(ps.BestChromosome); Console.WriteLine("Finished. Hit return."); Console.ReadLine(); }
static void Main() { // // Create the genetic algorithm, and set the required properties. // GA ga = new GA(); ga.EncodingType = EncodingType.Binary; ga.ChromosomeLength = 25; //ga.Objective = new ObjectiveDelegate( BinaryMaximizationObjective ); ga.Objective = new ObjectiveDelegate(BinaryAlternateObjective); ga.PopulationSize = 25; //ga.Mutated += new MutatedEventHandler( OnMutated ); //ga.NewPopulation += new NewPopulationEventHandler( OnNewPopulation ); //ga.NewPopulation += new NewPopulationEventHandler( OnNewPopulation_ShowParents ); ga.NewPopulation += new NewPopulationEventHandler(OnNewPopulation_ShowSummary); //ga.NewPopulation += new NewPopulationEventHandler( new BinaryPersist().NewPopulationHandler ); //ga.NewPopulation += new NewPopulationEventHandler( new BinaryPersist().NewPopulationHandlerSoap ); optimalObjective = 25; //ga.Terminate += new TerminateEventHandler( OnTerminate_CheckForOptimal ); ga.Terminate += new TerminateEventHandler(new ObjectiveThresholdTerminator(optimalObjective).Terminate); ga.FitnessScaling = FitnessScaling.LinearRanked; ga.GeneMutationProbability = 0.05; ga.Run(50); // // Output the best individual that was found during the run. // Console.WriteLine("Best Individual:"); PopulationSummary ps = new PopulationSummary(ga, ga.Population); Console.WriteLine(ps.BestChromosome); Console.WriteLine("Finished. Hit return."); Console.ReadLine(); }