コード例 #1
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();
        }
コード例 #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();
        }