- Timestamp:
- 11/18/15 18:55:40 (9 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/AlpsSampleTest.cs
r13253 r13260 24 24 using HeuristicLab.Algorithms.ALPS; 25 25 using HeuristicLab.Encodings.PermutationEncoding; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 27 using HeuristicLab.Persistence.Default.Xml; 28 using HeuristicLab.Problems.DataAnalysis.Symbolic; 29 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 30 using HeuristicLab.Problems.Instances.DataAnalysis; 27 31 using HeuristicLab.Problems.Instances.TSPLIB; 28 32 using HeuristicLab.Problems.TravelingSalesman; … … 33 37 [TestClass] 34 38 public class AlpsTspSampleTest { 35 private const string SampleFileName = "ALPSGA_TSP"; 39 private const string TspSampleFileName = "ALPSGA_TSP"; 40 private const string SymRegSampleFileName = "ALPSGP_SymReg"; 36 41 37 42 [TestMethod] … … 40 45 public void CreateAlpsGaTspSampleTest() { 41 46 var alpsGa = CreateAlpsGaTspSample(); 42 string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);47 string path = Path.Combine(SamplesUtils.SamplesDirectory, TspSampleFileName + SamplesUtils.SampleFileExtension); 43 48 XmlGenerator.Serialize(alpsGa, path); 44 49 } 50 51 [TestMethod] 52 [TestCategory("Samples.Create")] 53 [TestProperty("Time", "medium")] 54 public void CreateAlpsGaSymRegSampleTest() { 55 var alpsGa = CreateAlpsGaSymRegSample(); 56 string path = Path.Combine(SamplesUtils.SamplesDirectory, SymRegSampleFileName + SamplesUtils.SampleFileExtension); 57 XmlGenerator.Serialize(alpsGa, path); 58 } 59 45 60 [TestMethod] 46 61 [TestCategory("Samples.Execute")] 47 62 [TestProperty("Time", "long")] 48 63 public void RunAlpsGaTspSampleTest() { 49 var alpsGaE = CreateAlpsGaTspSample(plusSelection: false); 50 alpsGaE.SetSeedRandomly.Value = false; 51 SamplesUtils.RunAlgorithm(alpsGaE); 52 Assert.AreEqual(23661, SamplesUtils.GetDoubleResult(alpsGaE, "BestQuality")); 53 Assert.AreEqual(35131.1625, SamplesUtils.GetDoubleResult(alpsGaE, "CurrentAverageQuality")); 54 Assert.AreEqual(49699, SamplesUtils.GetDoubleResult(alpsGaE, "CurrentWorstQuality")); 55 Assert.AreEqual(26640, SamplesUtils.GetIntResult(alpsGaE, "EvaluatedSolutions")); 56 57 var alpsGaPs = CreateAlpsGaTspSample(plusSelection: true); 58 alpsGaPs.SetSeedRandomly.Value = false; 59 SamplesUtils.RunAlgorithm(alpsGaPs); 60 Assert.AreEqual(21365, SamplesUtils.GetDoubleResult(alpsGaPs, "BestQuality")); 61 Assert.AreEqual(30774.695, SamplesUtils.GetDoubleResult(alpsGaPs, "CurrentAverageQuality")); 62 Assert.AreEqual(49699, SamplesUtils.GetDoubleResult(alpsGaPs, "CurrentWorstQuality")); 63 Assert.AreEqual(26900, SamplesUtils.GetIntResult(alpsGaPs, "EvaluatedSolutions")); 64 var alpsGa = CreateAlpsGaTspSample(); 65 alpsGa.SetSeedRandomly.Value = false; 66 SamplesUtils.RunAlgorithm(alpsGa); 67 Assert.AreEqual(7967, SamplesUtils.GetDoubleResult(alpsGa, "BestQuality")); 68 Assert.AreEqual(17565.174444444445, SamplesUtils.GetDoubleResult(alpsGa, "CurrentAverageQuality")); 69 Assert.AreEqual(50295, SamplesUtils.GetDoubleResult(alpsGa, "CurrentWorstQuality")); 70 Assert.AreEqual(621900, SamplesUtils.GetIntResult(alpsGa, "EvaluatedSolutions")); 64 71 } 65 72 66 private AlpsGeneticAlgorithm CreateAlpsGaTspSample(bool plusSelection = false) { 73 [TestMethod] 74 [TestCategory("Samples.Execute")] 75 [TestProperty("Time", "long")] 76 public void RunAlpsGaSymRegSampleTest() { 77 var alpsGa = CreateAlpsGaSymRegSample(); 78 alpsGa.SetSeedRandomly.Value = false; 79 SamplesUtils.RunAlgorithm(alpsGa); 80 Assert.AreEqual(265855, SamplesUtils.GetIntResult(alpsGa, "EvaluatedSolutions")); 81 } 82 83 private AlpsGeneticAlgorithm CreateAlpsGaTspSample() { 67 84 AlpsGeneticAlgorithm alpsGa = new AlpsGeneticAlgorithm(); 68 85 #region Problem Configuration … … 77 94 alpsGa.Description = "An age-layered population structure genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)"; 78 95 alpsGa.Problem = tspProblem; 79 SamplesUtils.ConfigureAlpsGeneticAlgorithmParameters<GeneralizedRankSelector, OrderCrossover2, InversionManipulator>(alpsGa, 80 numberOfLayers: 10, 81 popSize: 100, 82 mutationRate: 0.05, 83 elites: 1, 84 plusSelection: plusSelection, 85 agingScheme: AgingScheme.Polynomial, 86 ageGap: 20, 87 ageInheritance: 1.0, 88 maxGens: 100); 96 SamplesUtils.ConfigureAlpsGeneticAlgorithmParameters<GeneralizedRankSelector, MultiPermutationCrossover, InversionManipulator>(alpsGa, 97 numberOfLayers: 1000, 98 popSize: 100, 99 mutationRate: 0.05, 100 elites: 1, 101 plusSelection: true, 102 agingScheme: AgingScheme.Polynomial, 103 ageGap: 20, 104 ageInheritance: 1.0, 105 maxGens: 1000); 106 var checkedCrossovers = new[] { typeof(EdgeRecombinationCrossover), typeof(MaximalPreservativeCrossover), typeof(OrderCrossover2) }; 107 var multiCrossover = (MultiPermutationCrossover)alpsGa.Crossover; 108 var crossovers = multiCrossover.Operators.Where(c => checkedCrossovers.Any(cc => cc.IsInstanceOfType(c))).ToList(); 109 foreach (var c in multiCrossover.Operators) 110 multiCrossover.Operators.SetItemCheckedState(c, crossovers.Contains(c)); 111 #endregion 112 return alpsGa; 113 } 114 115 private AlpsGeneticAlgorithm CreateAlpsGaSymRegSample() { 116 AlpsGeneticAlgorithm alpsGa = new AlpsGeneticAlgorithm(); 117 #region Problem Configuration 118 var provider = new VladislavlevaInstanceProvider(); 119 var instance = provider.GetDataDescriptors().Single(x => x.Name.StartsWith("Vladislavleva-5 F5")); 120 var symbRegProblem = new SymbolicRegressionSingleObjectiveProblem(); 121 symbRegProblem.Load(provider.LoadData(instance)); 122 123 symbRegProblem.MaximumSymbolicExpressionTreeDepth.Value = 35; 124 symbRegProblem.MaximumSymbolicExpressionTreeLength.Value = 35; 125 126 var grammar = (TypeCoherentExpressionGrammar)symbRegProblem.SymbolicExpressionTreeGrammar; 127 grammar.Symbols.OfType<Exponential>().Single().Enabled = false; 128 grammar.Symbols.OfType<Logarithm>().Single().Enabled = false; 129 130 #endregion 131 #region Algorithm Configuration 132 alpsGa.Name = "ALPS Genetic Programming - Symbolic Regression"; 133 alpsGa.Description = "An ALPS-GP to solve a symbolic regression problem (Vladislavleva-5 dataset)"; 134 alpsGa.Problem = symbRegProblem; 135 SamplesUtils.ConfigureAlpsGeneticAlgorithmParameters<GeneralizedRankSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>(alpsGa, 136 numberOfLayers: 1000, 137 popSize: 100, 138 mutationRate: 0.25, 139 elites: 1, 140 plusSelection: false, 141 agingScheme: AgingScheme.Polynomial, 142 ageGap: 15, 143 ageInheritance: 1.0, 144 maxGens: 500); 89 145 #endregion 90 146 return alpsGa;
Note: See TracChangeset
for help on using the changeset viewer.