private IslandGeneticAlgorithm CreateIslandGaTspSample()
        {
            IslandGeneticAlgorithm ga = new IslandGeneticAlgorithm();

            #region Problem Configuration
            var provider = new TSPLIBTSPInstanceProvider();
            var instance = provider.GetDataDescriptors().Where(x => x.Name == "ch130").Single();
            TravelingSalesmanProblem tspProblem = new TravelingSalesmanProblem();
            tspProblem.Load(provider.LoadData(instance));
            tspProblem.UseDistanceMatrix.Value = true;
            #endregion
            #region Algorithm Configuration
            ga.Name        = "Island Genetic Algorithm - TSP";
            ga.Description = "An island genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)";
            ga.Problem     = tspProblem;
            SamplesUtils.ConfigureIslandGeneticAlgorithmParameters <ProportionalSelector, OrderCrossover2, InversionManipulator,
                                                                    UnidirectionalRingMigrator, BestSelector, WorstReplacer>(
                ga, 100, 1, 1000, 0.05, 5, 50, 0.25);
            #endregion
            return(ga);
        }
예제 #2
0
        public static void ConfigureIslandGeneticAlgorithmParameters <S, C, M, Mi, MiS, MiR>(IslandGeneticAlgorithm ga, int popSize, int elites, int maxGens, double mutationRate, int numberOfIslands, int migrationInterval, double migrationRate)
            where S : ISelector
            where C : ICrossover
            where M : IManipulator
            where Mi : IMigrator
            where MiS : ISelector
            where MiR : IReplacer
        {
            ga.Elites.Value              = elites;
            ga.MaximumGenerations.Value  = maxGens;
            ga.MutationProbability.Value = mutationRate;
            ga.PopulationSize.Value      = popSize;
            ga.NumberOfIslands.Value     = numberOfIslands;
            ga.MigrationInterval.Value   = migrationInterval;
            ga.MigrationRate.Value       = migrationRate;
            ga.Seed.Value            = 0;
            ga.SetSeedRandomly.Value = true;
            ga.Selector = ga.SelectorParameter.ValidValues
                          .OfType <S>()
                          .Single();

            ga.Crossover = ga.CrossoverParameter.ValidValues
                           .OfType <C>()
                           .Single();

            ga.Mutator = ga.MutatorParameter.ValidValues
                         .OfType <M>()
                         .Single();
            ga.Migrator = ga.MigratorParameter.ValidValues
                          .OfType <Mi>()
                          .Single();
            ga.EmigrantsSelector = ga.EmigrantsSelectorParameter.ValidValues
                                   .OfType <MiS>()
                                   .Single();
            ga.ImmigrationReplacer = ga.ImmigrationReplacerParameter.ValidValues
                                     .OfType <MiR>()
                                     .Single();
            ga.Engine = new ParallelEngine.ParallelEngine();
        }