示例#1
0
文件: tsp.cs 项目: mykwillis/genX
        static void Main(string[] args)
        {
            GA Ga;
            TravellingSalesmanObjective Objective;

            Galib.Mutation.IntegerSwapMutator Mutator;
            IntegerChromosomeSpecifier        ChromosomeSpecifier;


            //
            // Create the objective objective.
            //
            int numberOfCities = 10;

            Objective = new TravellingSalesmanObjective(numberOfCities);

            //
            // Create the mutator
            //
            Mutator = new Galib.Mutation.IntegerSwapMutator();

            //
            // Create the chromosome specifier.
            //
            ChromosomeSpecifier                   = new IntegerChromosomeSpecifier();
            ChromosomeSpecifier.Length            = numberOfCities;
            ChromosomeSpecifier.MinValue          = 0;
            ChromosomeSpecifier.MaxValue          = numberOfCities;
            ChromosomeSpecifier.PositionDependent = true;

            //
            // Create the recombinator
            //
            Galib.Recombination.PartiallyMatchedRecombinator Recombinator;
            Recombinator = new Galib.Recombination.PartiallyMatchedRecombinator();

            Ga = new GA();

            Ga.PopulationSize      = 100;
            Ga.Mutator             = Mutator;
            Ga.ChromosomeSpecifier = ChromosomeSpecifier;
            Ga.Objective           = Objective;
            Ga.InvertedObjective   = true;
            Ga.Recombinator        = Recombinator;
            Ga.MaxGenerations      = 500;

            Ga.Run();

            Console.WriteLine("Best Individual:");
            Console.WriteLine(Ga.Population.BestChromosome);
            Console.WriteLine("Finished.  Hit return.");
            Console.ReadLine();
        }
示例#2
0
文件: tsp.cs 项目: mykwillis/genX
        static void Main(string[] args)
        {
            GA Ga;
            TravellingSalesman1dObjective Objective;
            Galib.Mutation.IntegerSwapMutator Mutator;
            IntegerChromosomeSpecifier ChromosomeSpecifier;
            
            //
            // Create the objective.
            //
            int[] cities = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
            Objective = new TravellingSalesman1dObjective(cities);
            
            //
            // Create the mutator
            //
            Mutator = new Galib.Mutation.IntegerSwapMutator();

            //
            // Create the chromosome specifier.
            //
            ChromosomeSpecifier = new IntegerChromosomeSpecifier();
            ChromosomeSpecifier.Length = numberOfCities;
            ChromosomeSpecifier.MinValue = 0;
            ChromosomeSpecifier.MaxValue = numberOfCities;
            ChromosomeSpecifier.PositionDependent = true;

            //
            // Create the recombinator
            //
            Galib.Recombination.PartiallyMatchedRecombinator Recombinator;
            Recombinator = new Galib.Recombination.PartiallyMatchedRecombinator();

            Ga = new GA();

            Ga.PopulationSize       = 100;
            Ga.Mutator              = Mutator;
            Ga.ChromosomeSpecifier  = ChromosomeSpecifier;
            Ga.Objective            = Objective;
            Ga.InvertedObjective    = true;
            Ga.Recombinator         = Recombinator;
            Ga.MaxGenerations       = 500;

            Ga.Run();

            Console.WriteLine("Best Individual:");
            Console.WriteLine( Ga.Population.BestChromosome );
            Console.WriteLine("Finished.  Hit return.");
            Console.ReadLine();
        }