Changeset 11051 for trunk/sources
- Timestamp:
- 06/27/14 10:02:58 (11 years ago)
- Location:
- trunk/sources/HeuristicLab.Tests
- Files:
-
- 4 added
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/SamplesTest.cs
r11050 r11051 37 37 using HeuristicLab.Data; 38 38 using HeuristicLab.Encodings.BinaryVectorEncoding; 39 using HeuristicLab.Encodings.IntegerVectorEncoding;40 39 using HeuristicLab.Encodings.PermutationEncoding; 41 40 using HeuristicLab.Encodings.RealVectorEncoding; … … 72 71 [TestClass] 73 72 public class SamplesTest { 74 private const string samplesDirectory = @"Samples\";73 private const string samplesDirectory = SamplesUtils.Directory; 75 74 76 75 [ClassInitialize] … … 95 94 var ga = CreateGaTspSample(); 96 95 ga.SetSeedRandomly.Value = false; 97 RunAlgorithm(ga);98 Assert.AreEqual(12332, GetDoubleResult(ga, "BestQuality"));99 Assert.AreEqual(13123.2, GetDoubleResult(ga, "CurrentAverageQuality"));100 Assert.AreEqual(14538, GetDoubleResult(ga, "CurrentWorstQuality"));101 Assert.AreEqual(99100, GetIntResult(ga, "EvaluatedSolutions"));96 SamplesUtils.RunAlgorithm(ga); 97 Assert.AreEqual(12332, SamplesUtils.GetDoubleResult(ga, "BestQuality")); 98 Assert.AreEqual(13123.2, SamplesUtils.GetDoubleResult(ga, "CurrentAverageQuality")); 99 Assert.AreEqual(14538, SamplesUtils.GetDoubleResult(ga, "CurrentWorstQuality")); 100 Assert.AreEqual(99100, SamplesUtils.GetIntResult(ga, "EvaluatedSolutions")); 102 101 } 103 102 … … 115 114 ga.Description = "A genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)"; 116 115 ga.Problem = tspProblem; 117 ConfigureGeneticAlgorithmParameters<ProportionalSelector, OrderCrossover2, InversionManipulator>(116 SamplesUtils.ConfigureGeneticAlgorithmParameters<ProportionalSelector, OrderCrossover2, InversionManipulator>( 118 117 ga, 100, 1, 1000, 0.05); 119 118 #endregion … … 136 135 var ga = CreateGaVrpSample(); 137 136 ga.SetSeedRandomly.Value = false; 138 RunAlgorithm(ga);139 Assert.AreEqual(1828.9368669428338, GetDoubleResult(ga, "BestQuality"));140 Assert.AreEqual(1830.1444308908331, GetDoubleResult(ga, "CurrentAverageQuality"));141 Assert.AreEqual(1871.7128510304112, GetDoubleResult(ga, "CurrentWorstQuality"));142 Assert.AreEqual(99100, GetIntResult(ga, "EvaluatedSolutions"));137 SamplesUtils.RunAlgorithm(ga); 138 Assert.AreEqual(1828.9368669428338, SamplesUtils.GetDoubleResult(ga, "BestQuality")); 139 Assert.AreEqual(1830.1444308908331, SamplesUtils.GetDoubleResult(ga, "CurrentAverageQuality")); 140 Assert.AreEqual(1871.7128510304112, SamplesUtils.GetDoubleResult(ga, "CurrentWorstQuality")); 141 Assert.AreEqual(99100, SamplesUtils.GetIntResult(ga, "EvaluatedSolutions")); 143 142 } 144 143 … … 167 166 ga.Description = "A genetic algorithm which solves the \"C101\" vehicle routing problem (imported from Solomon)"; 168 167 ga.Problem = vrpProblem; 169 ConfigureGeneticAlgorithmParameters<TournamentSelector, MultiVRPSolutionCrossover, MultiVRPSolutionManipulator>(168 SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, MultiVRPSolutionCrossover, MultiVRPSolutionManipulator>( 170 169 ga, 100, 1, 1000, 0.05, 3); 171 170 … … 210 209 var ga = CreateGpArtificialAntSample(); 211 210 ga.SetSeedRandomly.Value = false; 212 RunAlgorithm(ga);213 Assert.AreEqual(81, GetDoubleResult(ga, "BestQuality"));214 Assert.AreEqual(48.19, GetDoubleResult(ga, "CurrentAverageQuality"));215 Assert.AreEqual(0, GetDoubleResult(ga, "CurrentWorstQuality"));216 Assert.AreEqual(50950, GetIntResult(ga, "EvaluatedSolutions"));211 SamplesUtils.RunAlgorithm(ga); 212 Assert.AreEqual(81, SamplesUtils.GetDoubleResult(ga, "BestQuality")); 213 Assert.AreEqual(48.19, SamplesUtils.GetDoubleResult(ga, "CurrentAverageQuality")); 214 Assert.AreEqual(0, SamplesUtils.GetDoubleResult(ga, "CurrentWorstQuality")); 215 Assert.AreEqual(50950, SamplesUtils.GetIntResult(ga, "EvaluatedSolutions")); 217 216 } 218 217 … … 232 231 ga.Description = "A standard genetic programming algorithm to solve the artificial ant problem (Santa-Fe trail)"; 233 232 ga.Problem = antProblem; 234 ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeArchitectureManipulator>(233 SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeArchitectureManipulator>( 235 234 ga, 1000, 1, 50, 0.15, 5); 236 235 var mutator = (MultiSymbolicExpressionTreeArchitectureManipulator)ga.Mutator; … … 265 264 var ga = CreateGpSymbolicRegressionSample(); 266 265 ga.SetSeedRandomly.Value = false; 267 RunAlgorithm(ga);268 Assert.AreEqual(0.858344291534625, GetDoubleResult(ga, "BestQuality"), 1E-8);269 Assert.AreEqual(0.56758466520692641, GetDoubleResult(ga, "CurrentAverageQuality"), 1E-8);270 Assert.AreEqual(0, GetDoubleResult(ga, "CurrentWorstQuality"), 1E-8);271 Assert.AreEqual(50950, GetIntResult(ga, "EvaluatedSolutions"));266 SamplesUtils.RunAlgorithm(ga); 267 Assert.AreEqual(0.858344291534625, SamplesUtils.GetDoubleResult(ga, "BestQuality"), 1E-8); 268 Assert.AreEqual(0.56758466520692641, SamplesUtils.GetDoubleResult(ga, "CurrentAverageQuality"), 1E-8); 269 Assert.AreEqual(0, SamplesUtils.GetDoubleResult(ga, "CurrentWorstQuality"), 1E-8); 270 Assert.AreEqual(50950, SamplesUtils.GetIntResult(ga, "EvaluatedSolutions")); 272 271 var bestTrainingSolution = (IRegressionSolution)ga.Results["Best training solution"].Value; 273 272 Assert.AreEqual(0.85504801557844745, bestTrainingSolution.TrainingRSquared, 1E-8); … … 347 346 ga.Name = "Genetic Programming - Symbolic Regression"; 348 347 ga.Description = "A standard genetic programming algorithm to solve a symbolic regression problem (tower dataset)"; 349 ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>(348 SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>( 350 349 ga, 1000, 1, 50, 0.15, 5); 351 350 var mutator = (MultiSymbolicExpressionTreeManipulator)ga.Mutator; … … 380 379 var ga = CreateGpSymbolicClassificationSample(); 381 380 ga.SetSeedRandomly.Value = false; 382 RunAlgorithm(ga);383 Assert.AreEqual(0.141880203907627, GetDoubleResult(ga, "BestQuality"), 1E-8);384 Assert.AreEqual(4.3246992327753295, GetDoubleResult(ga, "CurrentAverageQuality"), 1E-8);385 Assert.AreEqual(100.62175156249987, GetDoubleResult(ga, "CurrentWorstQuality"), 1E-8);386 Assert.AreEqual(100900, GetIntResult(ga, "EvaluatedSolutions"));381 SamplesUtils.RunAlgorithm(ga); 382 Assert.AreEqual(0.141880203907627, SamplesUtils.GetDoubleResult(ga, "BestQuality"), 1E-8); 383 Assert.AreEqual(4.3246992327753295, SamplesUtils.GetDoubleResult(ga, "CurrentAverageQuality"), 1E-8); 384 Assert.AreEqual(100.62175156249987, SamplesUtils.GetDoubleResult(ga, "CurrentWorstQuality"), 1E-8); 385 Assert.AreEqual(100900, SamplesUtils.GetIntResult(ga, "EvaluatedSolutions")); 387 386 var bestTrainingSolution = (IClassificationSolution)ga.Results["Best training solution"].Value; 388 387 Assert.AreEqual(0.80875, bestTrainingSolution.TrainingAccuracy, 1E-8); … … 459 458 ga.Name = "Genetic Programming - Symbolic Classification"; 460 459 ga.Description = "A standard genetic programming algorithm to solve a classification problem (Mammographic+Mass dataset)"; 461 ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>(460 SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>( 462 461 ga, 1000, 1, 100, 0.15, 5 463 462 ); … … 486 485 var ga = CreateGpLawnMowerSample(); 487 486 ga.SetSeedRandomly.Value = false; 488 RunAlgorithm(ga);487 SamplesUtils.RunAlgorithm(ga); 489 488 } 490 489 … … 498 497 ga.Description = "A standard genetic programming algorithm to solve the lawn mower problem"; 499 498 ga.Problem = problem; 500 ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeArchitectureManipulator>(499 SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeArchitectureManipulator>( 501 500 ga, 1000, 1, 50, 0.25, 5); 502 501 var mutator = (MultiSymbolicExpressionTreeArchitectureManipulator)ga.Mutator; … … 525 524 var es = CreateEsGriewankSample(); 526 525 es.SetSeedRandomly.Value = false; 527 RunAlgorithm(es);528 Assert.AreEqual(0, GetDoubleResult(es, "BestQuality"));529 Assert.AreEqual(0, GetDoubleResult(es, "CurrentAverageQuality"));530 Assert.AreEqual(0, GetDoubleResult(es, "CurrentWorstQuality"));531 Assert.AreEqual(100020, GetIntResult(es, "EvaluatedSolutions"));526 SamplesUtils.RunAlgorithm(es); 527 Assert.AreEqual(0, SamplesUtils.GetDoubleResult(es, "BestQuality")); 528 Assert.AreEqual(0, SamplesUtils.GetDoubleResult(es, "CurrentAverageQuality")); 529 Assert.AreEqual(0, SamplesUtils.GetDoubleResult(es, "CurrentWorstQuality")); 530 Assert.AreEqual(100020, SamplesUtils.GetIntResult(es, "EvaluatedSolutions")); 532 531 } 533 532 … … 551 550 es.Description = "An evolution strategy which solves the 10-dimensional Griewank test function"; 552 551 es.Problem = problem; 553 ConfigureEvolutionStrategyParameters<AverageCrossover, NormalAllPositionsManipulator,552 SamplesUtils.ConfigureEvolutionStrategyParameters<AverageCrossover, NormalAllPositionsManipulator, 554 553 StdDevStrategyVectorCreator, StdDevStrategyVectorCrossover, StdDevStrategyVectorManipulator>( 555 554 es, 20, 500, 2, 200, false); … … 583 582 var ga = CreateIslandGaTspSample(); 584 583 ga.SetSeedRandomly.Value = false; 585 RunAlgorithm(ga);586 Assert.AreEqual(9918, GetDoubleResult(ga, "BestQuality"));587 Assert.AreEqual(10324.64, GetDoubleResult(ga, "CurrentAverageQuality"));588 Assert.AreEqual(11823, GetDoubleResult(ga, "CurrentWorstQuality"));589 Assert.AreEqual(495500, GetIntResult(ga, "EvaluatedSolutions"));584 SamplesUtils.RunAlgorithm(ga); 585 Assert.AreEqual(9918, SamplesUtils.GetDoubleResult(ga, "BestQuality")); 586 Assert.AreEqual(10324.64, SamplesUtils.GetDoubleResult(ga, "CurrentAverageQuality")); 587 Assert.AreEqual(11823, SamplesUtils.GetDoubleResult(ga, "CurrentWorstQuality")); 588 Assert.AreEqual(495500, SamplesUtils.GetIntResult(ga, "EvaluatedSolutions")); 590 589 } 591 590 … … 603 602 ga.Description = "An island genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)"; 604 603 ga.Problem = tspProblem; 605 ConfigureIslandGeneticAlgorithmParameters<ProportionalSelector, OrderCrossover2, InversionManipulator,604 SamplesUtils.ConfigureIslandGeneticAlgorithmParameters<ProportionalSelector, OrderCrossover2, InversionManipulator, 606 605 UnidirectionalRingMigrator, BestSelector, WorstReplacer>( 607 606 ga, 100, 1, 1000, 0.05, 5, 50, 0.25); … … 627 626 var ls = CreateLocalSearchKnapsackSample(); 628 627 ls.SetSeedRandomly.Value = false; 629 RunAlgorithm(ls);630 Assert.AreEqual(345, GetDoubleResult(ls, "BestQuality"));631 Assert.AreEqual(340.70731707317071, GetDoubleResult(ls, "CurrentAverageQuality"));632 Assert.AreEqual(337, GetDoubleResult(ls, "CurrentWorstQuality"));633 Assert.AreEqual(82000, GetIntResult(ls, "EvaluatedMoves"));628 SamplesUtils.RunAlgorithm(ls); 629 Assert.AreEqual(345, SamplesUtils.GetDoubleResult(ls, "BestQuality")); 630 Assert.AreEqual(340.70731707317071, SamplesUtils.GetDoubleResult(ls, "CurrentAverageQuality")); 631 Assert.AreEqual(337, SamplesUtils.GetDoubleResult(ls, "CurrentWorstQuality")); 632 Assert.AreEqual(82000, SamplesUtils.GetIntResult(ls, "EvaluatedMoves")); 634 633 } 635 634 … … 692 691 var pso = CreatePsoSchwefelSample(); 693 692 pso.SetSeedRandomly.Value = false; 694 RunAlgorithm(pso);693 SamplesUtils.RunAlgorithm(pso); 695 694 if (!Environment.Is64BitProcess) { 696 Assert.AreEqual(118.44027985932837, GetDoubleResult(pso, "BestQuality"));697 Assert.AreEqual(140.71570105946438, GetDoubleResult(pso, "CurrentAverageQuality"));698 Assert.AreEqual(220.956806502853, GetDoubleResult(pso, "CurrentWorstQuality"));699 Assert.AreEqual(1000, GetIntResult(pso, "Iterations"));695 Assert.AreEqual(118.44027985932837, SamplesUtils.GetDoubleResult(pso, "BestQuality")); 696 Assert.AreEqual(140.71570105946438, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality")); 697 Assert.AreEqual(220.956806502853, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality")); 698 Assert.AreEqual(1000, SamplesUtils.GetIntResult(pso, "Iterations")); 700 699 } else { 701 Assert.AreEqual(118.43958282879345, GetDoubleResult(pso, "BestQuality"));702 Assert.AreEqual(139.43946864779372, GetDoubleResult(pso, "CurrentAverageQuality"));703 Assert.AreEqual(217.14654589055152, GetDoubleResult(pso, "CurrentWorstQuality"));704 Assert.AreEqual(1000, GetIntResult(pso, "Iterations"));700 Assert.AreEqual(118.43958282879345, SamplesUtils.GetDoubleResult(pso, "BestQuality")); 701 Assert.AreEqual(139.43946864779372, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality")); 702 Assert.AreEqual(217.14654589055152, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality")); 703 Assert.AreEqual(1000, SamplesUtils.GetIntResult(pso, "Iterations")); 705 704 } 706 705 } … … 775 774 var sa = CreateSimulatedAnnealingRastriginSample(); 776 775 sa.SetSeedRandomly.Value = false; 777 RunAlgorithm(sa);778 Assert.AreEqual(0.00014039606034543795, GetDoubleResult(sa, "BestQuality"));779 Assert.AreEqual(5000, GetIntResult(sa, "EvaluatedMoves"));776 SamplesUtils.RunAlgorithm(sa); 777 Assert.AreEqual(0.00014039606034543795, SamplesUtils.GetDoubleResult(sa, "BestQuality")); 778 Assert.AreEqual(5000, SamplesUtils.GetIntResult(sa, "EvaluatedMoves")); 780 779 } 781 780 private SimulatedAnnealing CreateSimulatedAnnealingRastriginSample() { … … 845 844 var ts = CreateTabuSearchTspSample(); 846 845 ts.SetSeedRandomly.Value = false; 847 RunAlgorithm(ts);848 Assert.AreEqual(6294, GetDoubleResult(ts, "BestQuality"));849 Assert.AreEqual(7380.0386666666664, GetDoubleResult(ts, "CurrentAverageQuality"));850 Assert.AreEqual(8328, GetDoubleResult(ts, "CurrentWorstQuality"));851 Assert.AreEqual(750000, GetIntResult(ts, "EvaluatedMoves"));846 SamplesUtils.RunAlgorithm(ts); 847 Assert.AreEqual(6294, SamplesUtils.GetDoubleResult(ts, "BestQuality")); 848 Assert.AreEqual(7380.0386666666664, SamplesUtils.GetDoubleResult(ts, "CurrentAverageQuality")); 849 Assert.AreEqual(8328, SamplesUtils.GetDoubleResult(ts, "CurrentWorstQuality")); 850 Assert.AreEqual(750000, SamplesUtils.GetIntResult(ts, "EvaluatedMoves")); 852 851 } 853 852 … … 916 915 var vrp = CreateTabuSearchVrpSample(); 917 916 vrp.SetSeedRandomly.Value = false; 918 RunAlgorithm(vrp);919 Assert.AreEqual(1473, GetDoubleResult(vrp, "BestQuality"));920 Assert.AreEqual(2102.1192622950812, GetDoubleResult(vrp, "CurrentAverageQuality"));921 Assert.AreEqual(4006, GetDoubleResult(vrp, "CurrentWorstQuality"));922 Assert.AreEqual(119072, GetIntResult(vrp, "EvaluatedMoves"));917 SamplesUtils.RunAlgorithm(vrp); 918 Assert.AreEqual(1473, SamplesUtils.GetDoubleResult(vrp, "BestQuality")); 919 Assert.AreEqual(2102.1192622950812, SamplesUtils.GetDoubleResult(vrp, "CurrentAverageQuality")); 920 Assert.AreEqual(4006, SamplesUtils.GetDoubleResult(vrp, "CurrentWorstQuality")); 921 Assert.AreEqual(119072, SamplesUtils.GetIntResult(vrp, "EvaluatedMoves")); 923 922 } 924 923 … … 988 987 var vns = CreateVnsTspSample(); 989 988 vns.SetSeedRandomly = false; 990 RunAlgorithm(vns);991 Assert.AreEqual(867, GetDoubleResult(vns, "BestQuality"));992 Assert.AreEqual(867, GetDoubleResult(vns, "CurrentAverageQuality"));993 Assert.AreEqual(867, GetDoubleResult(vns, "CurrentWorstQuality"));994 Assert.AreEqual(12975173, GetIntResult(vns, "EvaluatedSolutions"));989 SamplesUtils.RunAlgorithm(vns); 990 Assert.AreEqual(867, SamplesUtils.GetDoubleResult(vns, "BestQuality")); 991 Assert.AreEqual(867, SamplesUtils.GetDoubleResult(vns, "CurrentAverageQuality")); 992 Assert.AreEqual(867, SamplesUtils.GetDoubleResult(vns, "CurrentWorstQuality")); 993 Assert.AreEqual(12975173, SamplesUtils.GetIntResult(vns, "EvaluatedSolutions")); 995 994 } 996 995 … … 1070 1069 gpr.SetSeedRandomly = false; 1071 1070 gpr.Seed = 1618551877; 1072 RunAlgorithm(gpr);1073 Assert.AreEqual(-940.48768748097029, GetDoubleResult(gpr, "NegativeLogLikelihood"));1074 Assert.AreEqual(0.99561947047986976, GetDoubleResult(gpr, "Training R²"));1071 SamplesUtils.RunAlgorithm(gpr); 1072 Assert.AreEqual(-940.48768748097029, SamplesUtils.GetDoubleResult(gpr, "NegativeLogLikelihood")); 1073 Assert.AreEqual(0.99561947047986976, SamplesUtils.GetDoubleResult(gpr, "Training R²")); 1075 1074 } 1076 1075 … … 1113 1112 var ss = CreateScatterSearchVRPSample(); 1114 1113 ss.SetSeedRandomly.Value = false; 1115 RunAlgorithm(ss);1116 Assert.AreEqual(828.93686694283383, GetDoubleResult(ss, "BestQuality"));1117 Assert.AreEqual(868.63623986983077, GetDoubleResult(ss, "CurrentAverageQuality"));1118 Assert.AreEqual(1048.8333559209832, GetDoubleResult(ss, "CurrentWorstQuality"));1119 Assert.AreEqual(262622, GetIntResult(ss, "EvaluatedSolutions"));1114 SamplesUtils.RunAlgorithm(ss); 1115 Assert.AreEqual(828.93686694283383, SamplesUtils.GetDoubleResult(ss, "BestQuality")); 1116 Assert.AreEqual(868.63623986983077, SamplesUtils.GetDoubleResult(ss, "CurrentAverageQuality")); 1117 Assert.AreEqual(1048.8333559209832, SamplesUtils.GetDoubleResult(ss, "CurrentWorstQuality")); 1118 Assert.AreEqual(262622, SamplesUtils.GetIntResult(ss, "EvaluatedSolutions")); 1120 1119 } 1121 1120 … … 1173 1172 var rapga = CreateRAPGASchedulingSample(); 1174 1173 rapga.SetSeedRandomly.Value = false; 1175 RunAlgorithm(rapga);1176 Assert.AreEqual(988.00, GetDoubleResult(rapga, "BestQuality"));1177 Assert.AreEqual(988.00, GetDoubleResult(rapga, "CurrentAverageQuality"));1178 Assert.AreEqual(988.00, GetDoubleResult(rapga, "CurrentWorstQuality"));1179 Assert.AreEqual(27100, GetIntResult(rapga, "EvaluatedSolutions"));1174 SamplesUtils.RunAlgorithm(rapga); 1175 Assert.AreEqual(988.00, SamplesUtils.GetDoubleResult(rapga, "BestQuality")); 1176 Assert.AreEqual(988.00, SamplesUtils.GetDoubleResult(rapga, "CurrentAverageQuality")); 1177 Assert.AreEqual(988.00, SamplesUtils.GetDoubleResult(rapga, "CurrentWorstQuality")); 1178 Assert.AreEqual(27100, SamplesUtils.GetIntResult(rapga, "EvaluatedSolutions")); 1180 1179 } 1181 1180 … … 1215 1214 var ga = CreateGeArtificialAntSample(); 1216 1215 ga.SetSeedRandomly.Value = false; 1217 RunAlgorithm(ga);1216 SamplesUtils.RunAlgorithm(ga); 1218 1217 } 1219 1218 … … 1227 1226 ga.Description = "Grammatical evolution algorithm for solving a artificial ant problem"; 1228 1227 ga.Problem = problem; 1229 ConfigureOsGeneticAlgorithmParameters<GenderSpecificSelector, Encodings.IntegerVectorEncoding.SinglePointCrossover, Encodings.IntegerVectorEncoding.UniformOnePositionManipulator>(1228 SamplesUtils.ConfigureOsGeneticAlgorithmParameters<GenderSpecificSelector, Encodings.IntegerVectorEncoding.SinglePointCrossover, Encodings.IntegerVectorEncoding.UniformOnePositionManipulator>( 1230 1229 ga, 200, 1, 50, 0.05, 200); 1231 1230 #endregion … … 1250 1249 var ga = CreateGeSymbolicRegressionSample(); 1251 1250 ga.SetSeedRandomly.Value = false; 1252 RunAlgorithm(ga);1251 SamplesUtils.RunAlgorithm(ga); 1253 1252 } 1254 1253 … … 1271 1270 } 1272 1271 1273 ConfigureOsGeneticAlgorithmParameters<GenderSpecificSelector, Encodings.IntegerVectorEncoding.SinglePointCrossover, Encodings.IntegerVectorEncoding.UniformOnePositionManipulator>(1272 SamplesUtils.ConfigureOsGeneticAlgorithmParameters<GenderSpecificSelector, Encodings.IntegerVectorEncoding.SinglePointCrossover, Encodings.IntegerVectorEncoding.UniformOnePositionManipulator>( 1274 1273 ga, 1000, 1, 50, 0.05, 200); 1275 1274 #endregion … … 1279 1278 1280 1279 #region Helpers 1281 private void ConfigureEvolutionStrategyParameters<R, M, SC, SR, SM>(EvolutionStrategy es, int popSize, int children, int parentsPerChild, int maxGens, bool plusSelection) 1282 where R : ICrossover 1283 where M : IManipulator 1284 where SC : IStrategyParameterCreator 1285 where SR : IStrategyParameterCrossover 1286 where SM : IStrategyParameterManipulator { 1287 es.PopulationSize.Value = popSize; 1288 es.Children.Value = children; 1289 es.ParentsPerChild.Value = parentsPerChild; 1290 es.MaximumGenerations.Value = maxGens; 1291 es.PlusSelection.Value = false; 1292 1293 es.Seed.Value = 0; 1294 es.SetSeedRandomly.Value = true; 1295 1296 es.Recombinator = es.RecombinatorParameter.ValidValues 1297 .OfType<R>() 1298 .Single(); 1299 1300 es.Mutator = es.MutatorParameter.ValidValues 1301 .OfType<M>() 1302 .Single(); 1303 1304 es.StrategyParameterCreator = es.StrategyParameterCreatorParameter.ValidValues 1305 .OfType<SC>() 1306 .Single(); 1307 es.StrategyParameterCrossover = es.StrategyParameterCrossoverParameter.ValidValues 1308 .OfType<SR>() 1309 .Single(); 1310 es.StrategyParameterManipulator = es.StrategyParameterManipulatorParameter.ValidValues 1311 .OfType<SM>() 1312 .Single(); 1313 es.Engine = new ParallelEngine.ParallelEngine(); 1314 } 1315 1316 private void ConfigureGeneticAlgorithmParameters<S, C, M>(GeneticAlgorithm ga, int popSize, int elites, int maxGens, double mutationRate, int tournGroupSize = 0) 1317 where S : ISelector 1318 where C : ICrossover 1319 where M : IManipulator { 1320 ga.Elites.Value = elites; 1321 ga.MaximumGenerations.Value = maxGens; 1322 ga.MutationProbability.Value = mutationRate; 1323 ga.PopulationSize.Value = popSize; 1324 ga.Seed.Value = 0; 1325 ga.SetSeedRandomly.Value = true; 1326 ga.Selector = ga.SelectorParameter.ValidValues 1327 .OfType<S>() 1328 .First(); 1329 1330 ga.Crossover = ga.CrossoverParameter.ValidValues 1331 .OfType<C>() 1332 .First(); 1333 1334 ga.Mutator = ga.MutatorParameter.ValidValues 1335 .OfType<M>() 1336 .First(); 1337 1338 var tSelector = ga.Selector as TournamentSelector; 1339 if (tSelector != null) { 1340 tSelector.GroupSizeParameter.Value.Value = tournGroupSize; 1341 } 1342 ga.Engine = new ParallelEngine.ParallelEngine(); 1343 } 1344 1345 private void ConfigureOsGeneticAlgorithmParameters<S, C, M>(OffspringSelectionGeneticAlgorithm ga, int popSize, int elites, int maxGens, double mutationRate=0.05, double maxSelPres=100, int tournGroupSize = 0) 1346 where S : ISelector 1347 where C : ICrossover 1348 where M : IManipulator { 1349 ga.Elites.Value = elites; 1350 ga.MaximumGenerations.Value = maxGens; 1351 ga.MutationProbability.Value = mutationRate; 1352 ga.PopulationSize.Value = popSize; 1353 ga.MaximumSelectionPressure.Value = maxSelPres; 1354 ga.Seed.Value = 0; 1355 ga.SetSeedRandomly.Value = true; 1356 ga.ComparisonFactorLowerBound.Value = 1; 1357 ga.ComparisonFactorUpperBound.Value = 1; 1358 1359 ga.Selector = ga.SelectorParameter.ValidValues 1360 .OfType<S>() 1361 .First(); 1362 1363 ga.Crossover = ga.CrossoverParameter.ValidValues 1364 .OfType<C>() 1365 .First(); 1366 1367 ga.Mutator = ga.MutatorParameter.ValidValues 1368 .OfType<M>() 1369 .First(); 1370 1371 var tSelector = ga.Selector as TournamentSelector; 1372 if (tSelector != null) { 1373 tSelector.GroupSizeParameter.Value.Value = tournGroupSize; 1374 } 1375 ga.Engine = new ParallelEngine.ParallelEngine(); 1376 } 1377 1378 private void ConfigureIslandGeneticAlgorithmParameters<S, C, M, Mi, MiS, MiR>(IslandGeneticAlgorithm ga, int popSize, int elites, int maxGens, double mutationRate, int numberOfIslands, int migrationInterval, double migrationRate) 1379 where S : ISelector 1380 where C : ICrossover 1381 where M : IManipulator 1382 where Mi : IMigrator 1383 where MiS : ISelector 1384 where MiR : IReplacer { 1385 ga.Elites.Value = elites; 1386 ga.MaximumGenerations.Value = maxGens; 1387 ga.MutationProbability.Value = mutationRate; 1388 ga.PopulationSize.Value = popSize; 1389 ga.NumberOfIslands.Value = numberOfIslands; 1390 ga.MigrationInterval.Value = migrationInterval; 1391 ga.MigrationRate.Value = migrationRate; 1392 ga.Seed.Value = 0; 1393 ga.SetSeedRandomly.Value = true; 1394 ga.Selector = ga.SelectorParameter.ValidValues 1395 .OfType<S>() 1396 .Single(); 1397 1398 ga.Crossover = ga.CrossoverParameter.ValidValues 1399 .OfType<C>() 1400 .Single(); 1401 1402 ga.Mutator = ga.MutatorParameter.ValidValues 1403 .OfType<M>() 1404 .Single(); 1405 ga.Migrator = ga.MigratorParameter.ValidValues 1406 .OfType<Mi>() 1407 .Single(); 1408 ga.EmigrantsSelector = ga.EmigrantsSelectorParameter.ValidValues 1409 .OfType<MiS>() 1410 .Single(); 1411 ga.ImmigrationReplacer = ga.ImmigrationReplacerParameter.ValidValues 1412 .OfType<MiR>() 1413 .Single(); 1414 ga.Engine = new ParallelEngine.ParallelEngine(); 1415 } 1416 1417 1418 private void RunAlgorithm(IAlgorithm a) { 1419 var trigger = new EventWaitHandle(false, EventResetMode.ManualReset); 1420 Exception ex = null; 1421 a.Stopped += (src, e) => { trigger.Set(); }; 1422 a.ExceptionOccurred += (src, e) => { ex = e.Value; trigger.Set(); }; 1423 a.Prepare(); 1424 a.Start(); 1425 trigger.WaitOne(); 1426 1427 Assert.AreEqual(ex, null); 1428 } 1429 1430 private double GetDoubleResult(IAlgorithm a, string resultName) { 1431 return ((DoubleValue)a.Results[resultName].Value).Value; 1432 } 1433 private int GetIntResult(IAlgorithm a, string resultName) { 1434 return ((IntValue)a.Results[resultName].Value).Value; 1435 } 1280 1436 1281 #endregion 1437 1282 } -
trunk/sources/HeuristicLab.Tests/HeuristicLab.Tests.csproj
r10983 r11051 357 357 <Compile Include="HeuristicLab-3.3\PluginDependenciesTest.cs" /> 358 358 <Compile Include="HeuristicLab-3.3\PluginLoader.cs" /> 359 <Compile Include="HeuristicLab-3.3\SamplesTest.cs" /> 359 <Compile Include="HeuristicLab-3.3\Samples\GPMultiplexerSampleTest.cs" /> 360 <Compile Include="HeuristicLab-3.3\Samples\SamplesTest.cs" /> 361 <Compile Include="HeuristicLab-3.3\Samples\SamplesUtils.cs" /> 360 362 <Compile Include="HeuristicLab-3.3\StorableConstructorTest.cs" /> 361 363 <Compile Include="HeuristicLab-3.3\ThreadSafeLogTest.cs" /> … … 489 491 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 490 492 </None> 493 <None Include="Test Resources\Multiplexer11.csv"> 494 <CopyToOutputDirectory>Always</CopyToOutputDirectory> 495 </None> 491 496 <None Include="Test Resources\SamplesExperimentFinished.hl"> 492 497 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Note: See TracChangeset
for help on using the changeset viewer.