private AlpsGeneticAlgorithm CreateAlpsGaTspSample() { AlpsGeneticAlgorithm alpsGa = new AlpsGeneticAlgorithm(); #region Problem Configuration var provider = new TSPLIBTSPInstanceProvider(); var instance = provider.GetDataDescriptors().Single(x => x.Name == "ch130"); TravelingSalesmanProblem tspProblem = new TravelingSalesmanProblem(); tspProblem.Load(provider.LoadData(instance)); tspProblem.UseDistanceMatrix.Value = true; #endregion #region Algorithm Configuration alpsGa.Name = "ALPS Genetic Algorithm - TSP"; alpsGa.Description = "An age-layered population structure genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)"; alpsGa.Problem = tspProblem; SamplesUtils.ConfigureAlpsGeneticAlgorithmParameters <GeneralizedRankSelector, MultiPermutationCrossover, InversionManipulator>(alpsGa, numberOfLayers: 1000, popSize: 100, mutationRate: 0.05, elites: 1, plusSelection: true, agingScheme: AgingScheme.Polynomial, ageGap: 20, ageInheritance: 1.0, maxGens: 1000); var checkedCrossovers = new[] { typeof(EdgeRecombinationCrossover), typeof(MaximalPreservativeCrossover), typeof(OrderCrossover2) }; var multiCrossover = (MultiPermutationCrossover)alpsGa.Crossover; var crossovers = multiCrossover.Operators.Where(c => checkedCrossovers.Any(cc => cc.IsInstanceOfType(c))).ToList(); foreach (var c in multiCrossover.Operators) { multiCrossover.Operators.SetItemCheckedState(c, crossovers.Contains(c)); } #endregion return(alpsGa); }
private TabuSearch CreateTabuSearchTspSample() { TabuSearch ts = new TabuSearch(); #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 ts.Name = "Tabu Search - TSP"; ts.Description = "A tabu search algorithm that solves the \"ch130\" TSP (imported from TSPLIB)"; ts.Problem = tspProblem; ts.MaximumIterations.Value = 1000; // move generator has to be set first var moveGenerator = ts.MoveGeneratorParameter.ValidValues .OfType <StochasticInversionMultiMoveGenerator>() .Single(); ts.MoveGenerator = moveGenerator; var moveEvaluator = ts.MoveEvaluatorParameter.ValidValues .OfType <TSPInversionMoveRoundedEuclideanPathEvaluator>() .Single(); ts.MoveEvaluator = moveEvaluator; var moveMaker = ts.MoveMakerParameter.ValidValues .OfType <InversionMoveMaker>() .Single(); ts.MoveMaker = moveMaker; ts.SampleSize.Value = 750; ts.Seed.Value = 0; ts.SetSeedRandomly.Value = true; var tabuChecker = ts.TabuCheckerParameter.ValidValues .OfType <InversionMoveSoftTabuCriterion>() .Single(); tabuChecker.UseAspirationCriterion.Value = true; ts.TabuChecker = tabuChecker; var tabuMaker = ts.TabuMakerParameter.ValidValues .OfType <InversionMoveTabuMaker>() .Single(); ts.TabuMaker = tabuMaker; ts.TabuTenure.Value = 60; #endregion ts.Engine = new ParallelEngine.ParallelEngine(); return(ts); }
private TabuSearch CreateTabuSearchTspSample() { TabuSearch ts = new TabuSearch(); #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 ts.Name = "Tabu Search - TSP"; ts.Description = "A tabu search algorithm that solves the \"ch130\" TSP (imported from TSPLIB)"; ts.Problem = tspProblem; ts.MaximumIterations.Value = 1000; // move generator has to be set first var moveGenerator = ts.MoveGeneratorParameter.ValidValues .OfType<StochasticInversionMultiMoveGenerator>() .Single(); ts.MoveGenerator = moveGenerator; var moveEvaluator = ts.MoveEvaluatorParameter.ValidValues .OfType<TSPInversionMoveRoundedEuclideanPathEvaluator>() .Single(); ts.MoveEvaluator = moveEvaluator; var moveMaker = ts.MoveMakerParameter.ValidValues .OfType<InversionMoveMaker>() .Single(); ts.MoveMaker = moveMaker; ts.SampleSize.Value = 750; ts.Seed.Value = 0; ts.SetSeedRandomly.Value = true; var tabuChecker = ts.TabuCheckerParameter.ValidValues .OfType<InversionMoveSoftTabuCriterion>() .Single(); tabuChecker.UseAspirationCriterion.Value = true; ts.TabuChecker = tabuChecker; var tabuMaker = ts.TabuMakerParameter.ValidValues .OfType<InversionMoveTabuMaker>() .Single(); ts.TabuMaker = tabuMaker; ts.TabuTenure.Value = 60; #endregion ts.Engine = new ParallelEngine.ParallelEngine(); return ts; }
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; }
private GeneticAlgorithm CreateGaTspSample() { GeneticAlgorithm ga = new GeneticAlgorithm(); #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 = "Genetic Algorithm - TSP"; ga.Description = "A genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)"; ga.Problem = tspProblem; SamplesUtils.ConfigureGeneticAlgorithmParameters <ProportionalSelector, OrderCrossover2, InversionManipulator>( ga, 100, 1, 1000, 0.05); #endregion return(ga); }
private AlpsGeneticAlgorithm CreateAlpsGaTspSample() { AlpsGeneticAlgorithm alpsGa = new AlpsGeneticAlgorithm(); #region Problem Configuration var provider = new TSPLIBTSPInstanceProvider(); var instance = provider.GetDataDescriptors().Single(x => x.Name == "ch130"); TravelingSalesmanProblem tspProblem = new TravelingSalesmanProblem(); tspProblem.Load(provider.LoadData(instance)); tspProblem.UseDistanceMatrix.Value = true; #endregion #region Algorithm Configuration alpsGa.Name = "ALPS Genetic Algorithm - TSP"; alpsGa.Description = "An age-layered population structure genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)"; alpsGa.Problem = tspProblem; SamplesUtils.ConfigureAlpsGeneticAlgorithmParameters<GeneralizedRankSelector, MultiPermutationCrossover, InversionManipulator>(alpsGa, numberOfLayers: 1000, popSize: 100, mutationRate: 0.05, elites: 1, plusSelection: true, agingScheme: AgingScheme.Polynomial, ageGap: 20, ageInheritance: 1.0, maxGens: 1000); var checkedCrossovers = new[] { typeof(EdgeRecombinationCrossover), typeof(MaximalPreservativeCrossover), typeof(OrderCrossover2) }; var multiCrossover = (MultiPermutationCrossover)alpsGa.Crossover; var crossovers = multiCrossover.Operators.Where(c => checkedCrossovers.Any(cc => cc.IsInstanceOfType(c))).ToList(); foreach (var c in multiCrossover.Operators) multiCrossover.Operators.SetItemCheckedState(c, crossovers.Contains(c)); #endregion return alpsGa; }