Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6544 for trunk


Ignore:
Timestamp:
07/07/11 23:23:58 (13 years ago)
Author:
swagner
Message:

Added missing license header, formatted code, adapted region descriptions (#1553)

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) 2002-2011 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
     22using System;
    423using System.Linq;
    5 using Microsoft.VisualStudio.TestTools.UnitTesting;
     24using System.Threading;
     25using HeuristicLab.Algorithms.EvolutionStrategy;
    626using 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;
    3027using HeuristicLab.Algorithms.LocalSearch;
    31 using HeuristicLab.Problems.Knapsack;
    32 using HeuristicLab.Encodings.BinaryVectorEncoding;
    3328using HeuristicLab.Algorithms.ParticleSwarmOptimization;
    3429using HeuristicLab.Algorithms.SimulatedAnnealing;
    3530using HeuristicLab.Algorithms.TabuSearch;
    3631using HeuristicLab.Algorithms.VariableNeighborhoodSearch;
     32using HeuristicLab.Data;
     33using HeuristicLab.Encodings.BinaryVectorEncoding;
     34using HeuristicLab.Encodings.PermutationEncoding;
     35using HeuristicLab.Encodings.RealVectorEncoding;
     36using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     37using HeuristicLab.Optimization;
     38using HeuristicLab.Optimization.Operators;
     39using HeuristicLab.ParallelEngine;
     40using HeuristicLab.Persistence.Default.Xml;
     41using HeuristicLab.Problems.ArtificialAnt;
     42using HeuristicLab.Problems.DataAnalysis;
     43using HeuristicLab.Problems.DataAnalysis.Symbolic;
     44using HeuristicLab.Problems.DataAnalysis.Symbolic.Classification;
     45using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
     46using HeuristicLab.Problems.Knapsack;
     47using HeuristicLab.Problems.TestFunctions;
     48using HeuristicLab.Problems.TravelingSalesman;
     49using HeuristicLab.Problems.VehicleRouting;
     50using HeuristicLab.Problems.VehicleRouting.Encodings.General;
     51using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin;
     52using HeuristicLab.Selection;
     53using Microsoft.VisualStudio.TestTools.UnitTesting;
    3754
    3855namespace HeuristicLab_33.Tests {
     
    6582    private GeneticAlgorithm CreateGaTspSample() {
    6683      GeneticAlgorithm ga = new GeneticAlgorithm();
    67       #region problem configuration
     84      #region Problem Configuration
    6885      TravelingSalesmanProblem tspProblem = new TravelingSalesmanProblem();
    6986      tspProblem.ImportFromTSPLIB("ch130.tsp", "ch130.opt.tour", 6110);
     
    7491      tspProblem.Description = "130 city problem (Churritz)";
    7592      #endregion
    76       #region algorithm configuration
     93      #region Algorithm Configuration
    7794      ga.Name = "Genetic Algorithm - TSP";
    7895      ga.Description = "A genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)";
     
    90107      return ga;
    91108    }
    92 
    93109    #endregion
    94110    #region VRP
     
    112128    private GeneticAlgorithm CreateGaVrpSample() {
    113129      GeneticAlgorithm ga = new GeneticAlgorithm();
    114       #region problem configuration
     130      #region Problem Configuration
    115131      VehicleRoutingProblem vrpProblem = new VehicleRoutingProblem();
    116132
     
    130146      vrpProblem.Vehicles.Value = 25;
    131147      #endregion
    132       #region algorithm configuration
     148      #region Algorithm Configuration
    133149      ga.Name = "Genetic Algorithm - VRP";
    134150      ga.Description = "A genetic algorithm which solves the \"C101\" vehicle routing problem (imported from Solomon)";
     
    161177      return ga;
    162178    }
    163 
    164179    #endregion
    165180    #region ArtificialAnt
    166 
    167181    [TestMethod]
    168182    public void CreateGpArtificialAntSampleTest() {
     
    191205    public GeneticAlgorithm CreateGpArtificialAntSample() {
    192206      GeneticAlgorithm ga = new GeneticAlgorithm();
    193       #region problem configuration
     207      #region Problem Configuration
    194208      ArtificialAntProblem antProblem = new ArtificialAntProblem();
    195209      antProblem.BestKnownQuality.Value = 89;
     
    200214      antProblem.MaxTimeSteps.Value = 600;
    201215      #endregion
    202       #region algorithm configuration
     216      #region Algorithm Configuration
    203217      ga.Name = "Genetic Programming - Artificial Ant";
    204218      ga.Description = "A standard genetic programming algorithm to solve the artificial ant problem (Santa-Fe trail)";
     
    222236      return ga;
    223237    }
    224 
    225     #endregion
    226     #region symbolic regression
     238    #endregion
     239    #region Symbolic Regression
    227240    [TestMethod]
    228241    public void CreateGpSymbolicRegressionSampleTest() {
     
    250263    private GeneticAlgorithm CreateGpSymbolicRegressionSample() {
    251264      GeneticAlgorithm ga = new GeneticAlgorithm();
    252       #region problem configuration
     265      #region Problem Configuration
    253266      SymbolicRegressionSingleObjectiveProblem symbRegProblem = new SymbolicRegressionSingleObjectiveProblem();
    254267      symbRegProblem.Name = "Tower Symbolic Regression Problem";
     
    323336      symbRegProblem.EvaluatorParameter.Value = new SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator();
    324337      #endregion
    325       #region algorithm configuration
     338      #region Algorithm Configuration
    326339      ga.Problem = symbRegProblem;
    327340      ga.Name = "Genetic Programming - Symbolic Regression";
     
    345358    }
    346359    #endregion
    347     #region symbolic classification
    348 
     360    #region Symbolic Classification
    349361    [TestMethod]
    350362    public void CreateGpSymbolicClassificationSampleTest() {
     
    373385    private GeneticAlgorithm CreateGpSymbolicClassificationSample() {
    374386      GeneticAlgorithm ga = new GeneticAlgorithm();
    375       #region problem configuration
     387      #region Problem Configuration
    376388      SymbolicClassificationSingleObjectiveProblem symbClassProblem = new SymbolicClassificationSingleObjectiveProblem();
    377389      symbClassProblem.Name = "Mammography Classification Problem";
     
    439451      symbClassProblem.EvaluatorParameter.Value = new SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator();
    440452      #endregion
    441       #region algorithm configuration
     453      #region Algorithm Configuration
    442454      ga.Problem = symbClassProblem;
    443455      ga.Name = "Genetic Programming - Symbolic Classification";
     
    485497    private EvolutionStrategy CreateEsGriewankSample() {
    486498      EvolutionStrategy es = new EvolutionStrategy();
    487       #region problem configuration
     499      #region Problem Configuration
    488500      SingleObjectiveTestFunctionProblem problem = new SingleObjectiveTestFunctionProblem();
    489501
     
    498510      problem.Description = "Test function with real valued inputs and a single objective.";
    499511      #endregion
    500       #region algorithm configuration
     512      #region Algorithm Configuration
    501513      es.Name = "Evolution Strategy - Griewank";
    502514      es.Description = "An evolution strategy which solves the 10-dimensional Griewank test function";
     
    516528      return es;
    517529    }
    518 
    519530    #endregion
    520531    #endregion
     
    540551    private IslandGeneticAlgorithm CreateIslandGaTspSample() {
    541552      IslandGeneticAlgorithm ga = new IslandGeneticAlgorithm();
    542       #region problem configuration
     553      #region Problem Configuration
    543554      TravelingSalesmanProblem tspProblem = new TravelingSalesmanProblem();
    544555      tspProblem.ImportFromTSPLIB("ch130.tsp", "ch130.opt.tour", 6110);
     
    549560      tspProblem.Description = "130 city problem (Churritz)";
    550561      #endregion
    551       #region algorithm configuration
     562      #region Algorithm Configuration
    552563      ga.Name = "Island Genetic Algorithm - TSP";
    553564      ga.Description = "An island genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)";
     
    566577      return ga;
    567578    }
    568 
    569579    #endregion
    570580    #endregion
     
    590600    private LocalSearch CreateLocalSearchKnapsackSample() {
    591601      LocalSearch ls = new LocalSearch();
    592       #region problem configuration
     602      #region Problem Configuration
    593603      KnapsackProblem problem = new KnapsackProblem();
    594604      problem.BestKnownQuality = new DoubleValue(362);
     
    607617      problem.Description = "Represents a Knapsack problem.";
    608618      #endregion
    609       #region algorithm configuration
     619      #region Algorithm Configuration
    610620      ls.Name = "Local Search - Knapsack";
    611621      ls.Description = "A local search algorithm that solves a randomly generated Knapsack problem";
     
    624634      ls.Seed.Value = 0;
    625635      ls.SetSeedRandomly.Value = true;
    626 
    627636      #endregion
    628637      ls.Engine = new ParallelEngine();
    629638      return ls;
    630639    }
    631 
    632640    #endregion
    633641    #endregion
     
    659667    private ParticleSwarmOptimization CreatePsoSchwefelSample() {
    660668      ParticleSwarmOptimization pso = new ParticleSwarmOptimization();
    661       #region problem configuration
     669      #region Problem Configuration
    662670      var problem = new SingleObjectiveTestFunctionProblem();
    663671      problem.BestKnownQuality.Value = 0.0;
     
    669677      problem.SolutionCreator = new UniformRandomRealVectorCreator();
    670678      #endregion
    671       #region algorithm configuration
     679      #region Algorithm Configuration
    672680      pso.Name = "Particle Swarm Optimization - Schwefel";
    673681      pso.Description = "A particle swarm optimization algorithm which solves the 2-dimensional Schwefel test function (based on the description in Pedersen, M.E.H. (2010). PhD thesis. University of Southampton)";
     
    705713      pso.Seed.Value = 0;
    706714      pso.SetSeedRandomly.Value = true;
    707 
    708715      #endregion
    709716      pso.Engine = new ParallelEngine();
     
    730737    private SimulatedAnnealing CreateSimulatedAnnealingRastriginSample() {
    731738      SimulatedAnnealing sa = new SimulatedAnnealing();
    732       #region problem configuration
     739      #region Problem Configuration
    733740      var problem = new SingleObjectiveTestFunctionProblem();
    734741      problem.BestKnownQuality.Value = 0.0;
     
    740747      problem.SolutionCreator = new UniformRandomRealVectorCreator();
    741748      #endregion
    742       #region algorithm configuration
     749      #region Algorithm Configuration
    743750      sa.Name = "Simulated Annealing - Rastrigin";
    744751      sa.Description = "A simulated annealing algorithm that solves the 2-dimensional Rastrigin test function";
     
    799806    private TabuSearch CreateTabuSearchTspSample() {
    800807      TabuSearch ts = new TabuSearch();
    801       #region problem configuration
     808      #region Problem Configuration
    802809      var tspProblem = new TravelingSalesmanProblem();
    803810      tspProblem.ImportFromTSPLIB("ch130.tsp", "ch130.opt.tour", 6110);
     
    808815      tspProblem.Description = "130 city problem (Churritz)";
    809816      #endregion
    810       #region algorithm configuration
     817      #region Algorithm Configuration
    811818      ts.Name = "Tabu Search - TSP";
    812819      ts.Description = "A tabu search algorithm that solves the \"ch130\" TSP (imported from TSPLIB)";
     
    853860      return ts;
    854861    }
    855 
    856862    #endregion
    857863    #endregion
     
    877883    private VariableNeighborhoodSearch CreateVnsTspSample() {
    878884      VariableNeighborhoodSearch vns = new VariableNeighborhoodSearch();
    879       #region problem configuration
     885      #region Problem Configuration
    880886      TravelingSalesmanProblem tspProblem = new TravelingSalesmanProblem();
    881887      tspProblem.BestKnownSolution = new Permutation(PermutationTypes.Absolute, new int[] {
     
    893899      tspProblem.Description = "Represents a symmetric Traveling Salesman Problem.";
    894900      #endregion
    895       #region algorithm configuration
     901      #region Algorithm Configuration
    896902      vns.Name = "Variable Neighborhood Search - TSP";
    897903      vns.Description = "A variable neighborhood search algorithm which solves a funny TSP instance";
     
    938944      return vns;
    939945    }
    940 
    941     #endregion
    942     #endregion
    943     #region helper
     946    #endregion
     947    #endregion
     948
     949    #region Helpers
    944950    private void ConfigureEvolutionStrategyParameters<R, M, SC, SR, SM>(EvolutionStrategy es, int popSize, int children, int parentsPerChild, int maxGens, bool plusSelection)
    945951      where R : ICrossover
Note: See TracChangeset for help on using the changeset viewer.