Changeset 6544
 Timestamp:
 07/07/11 23:23:58 (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/sources/HeuristicLab/3.3/Tests/SamplesTest.cs
r6505 r6544 1 using System; 2 using System.Text; 3 using System.Collections.Generic; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 20022011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 4 23 using System.Linq; 5 using Microsoft.VisualStudio.TestTools.UnitTesting; 24 using System.Threading; 25 using HeuristicLab.Algorithms.EvolutionStrategy; 6 26 using HeuristicLab.Algorithms.GeneticAlgorithm; 7 using HeuristicLab.Problems.ArtificialAnt;8 using HeuristicLab.Selection;9 using HeuristicLab.Data;10 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;11 using HeuristicLab.Persistence.Default.Xml;12 using HeuristicLab.Optimization;13 using System.Threading;14 using HeuristicLab.ParallelEngine;15 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;16 using HeuristicLab.Problems.DataAnalysis;17 using HeuristicLab.Problems.DataAnalysis.Symbolic;18 using System.IO;19 using HeuristicLab.Problems.DataAnalysis.Symbolic.Classification;20 using HeuristicLab.Problems.TravelingSalesman;21 using HeuristicLab.Encodings.PermutationEncoding;22 using HeuristicLab.Problems.VehicleRouting;23 using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin;24 using HeuristicLab.Problems.VehicleRouting.Encodings;25 using HeuristicLab.Problems.VehicleRouting.Encodings.General;26 using HeuristicLab.Algorithms.EvolutionStrategy;27 using HeuristicLab.Encodings.RealVectorEncoding;28 using HeuristicLab.Problems.TestFunctions;29 using HeuristicLab.Optimization.Operators;30 27 using HeuristicLab.Algorithms.LocalSearch; 31 using HeuristicLab.Problems.Knapsack;32 using HeuristicLab.Encodings.BinaryVectorEncoding;33 28 using HeuristicLab.Algorithms.ParticleSwarmOptimization; 34 29 using HeuristicLab.Algorithms.SimulatedAnnealing; 35 30 using HeuristicLab.Algorithms.TabuSearch; 36 31 using HeuristicLab.Algorithms.VariableNeighborhoodSearch; 32 using HeuristicLab.Data; 33 using HeuristicLab.Encodings.BinaryVectorEncoding; 34 using HeuristicLab.Encodings.PermutationEncoding; 35 using HeuristicLab.Encodings.RealVectorEncoding; 36 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 37 using HeuristicLab.Optimization; 38 using HeuristicLab.Optimization.Operators; 39 using HeuristicLab.ParallelEngine; 40 using HeuristicLab.Persistence.Default.Xml; 41 using HeuristicLab.Problems.ArtificialAnt; 42 using HeuristicLab.Problems.DataAnalysis; 43 using HeuristicLab.Problems.DataAnalysis.Symbolic; 44 using HeuristicLab.Problems.DataAnalysis.Symbolic.Classification; 45 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 46 using HeuristicLab.Problems.Knapsack; 47 using HeuristicLab.Problems.TestFunctions; 48 using HeuristicLab.Problems.TravelingSalesman; 49 using HeuristicLab.Problems.VehicleRouting; 50 using HeuristicLab.Problems.VehicleRouting.Encodings.General; 51 using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin; 52 using HeuristicLab.Selection; 53 using Microsoft.VisualStudio.TestTools.UnitTesting; 37 54 38 55 namespace HeuristicLab_33.Tests { … … 65 82 private GeneticAlgorithm CreateGaTspSample() { 66 83 GeneticAlgorithm ga = new GeneticAlgorithm(); 67 #region problem configuration84 #region Problem Configuration 68 85 TravelingSalesmanProblem tspProblem = new TravelingSalesmanProblem(); 69 86 tspProblem.ImportFromTSPLIB("ch130.tsp", "ch130.opt.tour", 6110); … … 74 91 tspProblem.Description = "130 city problem (Churritz)"; 75 92 #endregion 76 #region algorithm configuration93 #region Algorithm Configuration 77 94 ga.Name = "Genetic Algorithm  TSP"; 78 95 ga.Description = "A genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)"; … … 90 107 return ga; 91 108 } 92 93 109 #endregion 94 110 #region VRP … … 112 128 private GeneticAlgorithm CreateGaVrpSample() { 113 129 GeneticAlgorithm ga = new GeneticAlgorithm(); 114 #region problem configuration130 #region Problem Configuration 115 131 VehicleRoutingProblem vrpProblem = new VehicleRoutingProblem(); 116 132 … … 130 146 vrpProblem.Vehicles.Value = 25; 131 147 #endregion 132 #region algorithm configuration148 #region Algorithm Configuration 133 149 ga.Name = "Genetic Algorithm  VRP"; 134 150 ga.Description = "A genetic algorithm which solves the \"C101\" vehicle routing problem (imported from Solomon)"; … … 161 177 return ga; 162 178 } 163 164 179 #endregion 165 180 #region ArtificialAnt 166 167 181 [TestMethod] 168 182 public void CreateGpArtificialAntSampleTest() { … … 191 205 public GeneticAlgorithm CreateGpArtificialAntSample() { 192 206 GeneticAlgorithm ga = new GeneticAlgorithm(); 193 #region problem configuration207 #region Problem Configuration 194 208 ArtificialAntProblem antProblem = new ArtificialAntProblem(); 195 209 antProblem.BestKnownQuality.Value = 89; … … 200 214 antProblem.MaxTimeSteps.Value = 600; 201 215 #endregion 202 #region algorithm configuration216 #region Algorithm Configuration 203 217 ga.Name = "Genetic Programming  Artificial Ant"; 204 218 ga.Description = "A standard genetic programming algorithm to solve the artificial ant problem (SantaFe trail)"; … … 222 236 return ga; 223 237 } 224 225 #endregion 226 #region symbolic regression 238 #endregion 239 #region Symbolic Regression 227 240 [TestMethod] 228 241 public void CreateGpSymbolicRegressionSampleTest() { … … 250 263 private GeneticAlgorithm CreateGpSymbolicRegressionSample() { 251 264 GeneticAlgorithm ga = new GeneticAlgorithm(); 252 #region problem configuration265 #region Problem Configuration 253 266 SymbolicRegressionSingleObjectiveProblem symbRegProblem = new SymbolicRegressionSingleObjectiveProblem(); 254 267 symbRegProblem.Name = "Tower Symbolic Regression Problem"; … … 323 336 symbRegProblem.EvaluatorParameter.Value = new SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(); 324 337 #endregion 325 #region algorithm configuration338 #region Algorithm Configuration 326 339 ga.Problem = symbRegProblem; 327 340 ga.Name = "Genetic Programming  Symbolic Regression"; … … 345 358 } 346 359 #endregion 347 #region symbolic classification 348 360 #region Symbolic Classification 349 361 [TestMethod] 350 362 public void CreateGpSymbolicClassificationSampleTest() { … … 373 385 private GeneticAlgorithm CreateGpSymbolicClassificationSample() { 374 386 GeneticAlgorithm ga = new GeneticAlgorithm(); 375 #region problem configuration387 #region Problem Configuration 376 388 SymbolicClassificationSingleObjectiveProblem symbClassProblem = new SymbolicClassificationSingleObjectiveProblem(); 377 389 symbClassProblem.Name = "Mammography Classification Problem"; … … 439 451 symbClassProblem.EvaluatorParameter.Value = new SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator(); 440 452 #endregion 441 #region algorithm configuration453 #region Algorithm Configuration 442 454 ga.Problem = symbClassProblem; 443 455 ga.Name = "Genetic Programming  Symbolic Classification"; … … 485 497 private EvolutionStrategy CreateEsGriewankSample() { 486 498 EvolutionStrategy es = new EvolutionStrategy(); 487 #region problem configuration499 #region Problem Configuration 488 500 SingleObjectiveTestFunctionProblem problem = new SingleObjectiveTestFunctionProblem(); 489 501 … … 498 510 problem.Description = "Test function with real valued inputs and a single objective."; 499 511 #endregion 500 #region algorithm configuration512 #region Algorithm Configuration 501 513 es.Name = "Evolution Strategy  Griewank"; 502 514 es.Description = "An evolution strategy which solves the 10dimensional Griewank test function"; … … 516 528 return es; 517 529 } 518 519 530 #endregion 520 531 #endregion … … 540 551 private IslandGeneticAlgorithm CreateIslandGaTspSample() { 541 552 IslandGeneticAlgorithm ga = new IslandGeneticAlgorithm(); 542 #region problem configuration553 #region Problem Configuration 543 554 TravelingSalesmanProblem tspProblem = new TravelingSalesmanProblem(); 544 555 tspProblem.ImportFromTSPLIB("ch130.tsp", "ch130.opt.tour", 6110); … … 549 560 tspProblem.Description = "130 city problem (Churritz)"; 550 561 #endregion 551 #region algorithm configuration562 #region Algorithm Configuration 552 563 ga.Name = "Island Genetic Algorithm  TSP"; 553 564 ga.Description = "An island genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)"; … … 566 577 return ga; 567 578 } 568 569 579 #endregion 570 580 #endregion … … 590 600 private LocalSearch CreateLocalSearchKnapsackSample() { 591 601 LocalSearch ls = new LocalSearch(); 592 #region problem configuration602 #region Problem Configuration 593 603 KnapsackProblem problem = new KnapsackProblem(); 594 604 problem.BestKnownQuality = new DoubleValue(362); … … 607 617 problem.Description = "Represents a Knapsack problem."; 608 618 #endregion 609 #region algorithm configuration619 #region Algorithm Configuration 610 620 ls.Name = "Local Search  Knapsack"; 611 621 ls.Description = "A local search algorithm that solves a randomly generated Knapsack problem"; … … 624 634 ls.Seed.Value = 0; 625 635 ls.SetSeedRandomly.Value = true; 626 627 636 #endregion 628 637 ls.Engine = new ParallelEngine(); 629 638 return ls; 630 639 } 631 632 640 #endregion 633 641 #endregion … … 659 667 private ParticleSwarmOptimization CreatePsoSchwefelSample() { 660 668 ParticleSwarmOptimization pso = new ParticleSwarmOptimization(); 661 #region problem configuration669 #region Problem Configuration 662 670 var problem = new SingleObjectiveTestFunctionProblem(); 663 671 problem.BestKnownQuality.Value = 0.0; … … 669 677 problem.SolutionCreator = new UniformRandomRealVectorCreator(); 670 678 #endregion 671 #region algorithm configuration679 #region Algorithm Configuration 672 680 pso.Name = "Particle Swarm Optimization  Schwefel"; 673 681 pso.Description = "A particle swarm optimization algorithm which solves the 2dimensional Schwefel test function (based on the description in Pedersen, M.E.H. (2010). PhD thesis. University of Southampton)"; … … 705 713 pso.Seed.Value = 0; 706 714 pso.SetSeedRandomly.Value = true; 707 708 715 #endregion 709 716 pso.Engine = new ParallelEngine(); … … 730 737 private SimulatedAnnealing CreateSimulatedAnnealingRastriginSample() { 731 738 SimulatedAnnealing sa = new SimulatedAnnealing(); 732 #region problem configuration739 #region Problem Configuration 733 740 var problem = new SingleObjectiveTestFunctionProblem(); 734 741 problem.BestKnownQuality.Value = 0.0; … … 740 747 problem.SolutionCreator = new UniformRandomRealVectorCreator(); 741 748 #endregion 742 #region algorithm configuration749 #region Algorithm Configuration 743 750 sa.Name = "Simulated Annealing  Rastrigin"; 744 751 sa.Description = "A simulated annealing algorithm that solves the 2dimensional Rastrigin test function"; … … 799 806 private TabuSearch CreateTabuSearchTspSample() { 800 807 TabuSearch ts = new TabuSearch(); 801 #region problem configuration808 #region Problem Configuration 802 809 var tspProblem = new TravelingSalesmanProblem(); 803 810 tspProblem.ImportFromTSPLIB("ch130.tsp", "ch130.opt.tour", 6110); … … 808 815 tspProblem.Description = "130 city problem (Churritz)"; 809 816 #endregion 810 #region algorithm configuration817 #region Algorithm Configuration 811 818 ts.Name = "Tabu Search  TSP"; 812 819 ts.Description = "A tabu search algorithm that solves the \"ch130\" TSP (imported from TSPLIB)"; … … 853 860 return ts; 854 861 } 855 856 862 #endregion 857 863 #endregion … … 877 883 private VariableNeighborhoodSearch CreateVnsTspSample() { 878 884 VariableNeighborhoodSearch vns = new VariableNeighborhoodSearch(); 879 #region problem configuration885 #region Problem Configuration 880 886 TravelingSalesmanProblem tspProblem = new TravelingSalesmanProblem(); 881 887 tspProblem.BestKnownSolution = new Permutation(PermutationTypes.Absolute, new int[] { … … 893 899 tspProblem.Description = "Represents a symmetric Traveling Salesman Problem."; 894 900 #endregion 895 #region algorithm configuration901 #region Algorithm Configuration 896 902 vns.Name = "Variable Neighborhood Search  TSP"; 897 903 vns.Description = "A variable neighborhood search algorithm which solves a funny TSP instance"; … … 938 944 return vns; 939 945 } 940 941 #endregion 942 #endregion 943 #region helper946 #endregion 947 #endregion 948 949 #region Helpers 944 950 private void ConfigureEvolutionStrategyParameters<R, M, SC, SR, SM>(EvolutionStrategy es, int popSize, int children, int parentsPerChild, int maxGens, bool plusSelection) 945 951 where R : ICrossover
Note: See TracChangeset
for help on using the changeset viewer.