Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/13/17 10:21:43 (7 years ago)
Author:
abeham
Message:

#2797: Updated sample to change from Schwefel to Rastrigin (in the hope that it's numerically more stable)

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/PsoRastriginSampleTest.cs

    r15222 r15223  
    2424using System.Linq;
    2525using HeuristicLab.Algorithms.ParticleSwarmOptimization;
    26 using HeuristicLab.Data;
    2726using HeuristicLab.Encodings.RealVectorEncoding;
    2827using HeuristicLab.Persistence.Default.Xml;
     
    3332  [TestClass]
    3433  public class PsoSchwefelSampleTest {
    35     private const string SampleFileName = "PSO_Schwefel";
     34    private const string SampleFileName = "PSO_Rastrigin";
    3635
    3736    [TestMethod]
    3837    [TestCategory("Samples.Create")]
    3938    [TestProperty("Time", "medium")]
    40     public void CreatePsoSchwefelSampleTest() {
    41       var pso = CreatePsoSchwefelSample();
     39    public void CreatePsoRastriginSampleTest() {
     40      var pso = CreatePsoRastriginSample();
    4241      string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
    4342      XmlGenerator.Serialize(pso, path);
     
    4645    [TestCategory("Samples.Execute")]
    4746    [TestProperty("Time", "medium")]
    48     public void RunPsoSchwefelSampleTest() {
    49       var pso = CreatePsoSchwefelSample();
     47    public void RunPsoRastriginSampleTest() {
     48      var pso = CreatePsoRastriginSample();
    5049      pso.SetSeedRandomly.Value = false;
    5150      SamplesUtils.RunAlgorithm(pso);
    5251      if (Environment.Is64BitProcess) {
    53         Assert.AreEqual(-1.4779288903810084E-12, SamplesUtils.GetDoubleResult(pso, "BestQuality"));
    54         Assert.AreEqual(189.28837949705971, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality"));
    55         Assert.AreEqual(1195.4166822158872, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality"));
     52        Assert.AreEqual(0, SamplesUtils.GetDoubleResult(pso, "BestQuality"));
     53        Assert.AreEqual(3.9649516110677525, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality"));
     54        Assert.AreEqual(25.566430359483757, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality"));
    5655        Assert.AreEqual(200, SamplesUtils.GetIntResult(pso, "Iterations"));
    5756      } else {
    58         Assert.AreEqual(-1.4779288903810084E-12, SamplesUtils.GetDoubleResult(pso, "BestQuality"));
    59         Assert.AreEqual(189.28837949705971, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality"));
    60         Assert.AreEqual(1195.4166822158873, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality"));
     57        Assert.AreEqual(0, SamplesUtils.GetDoubleResult(pso, "BestQuality"));
     58        Assert.AreEqual(3.3957460831564048, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality"));
     59        Assert.AreEqual(34.412788077766145, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality"));
    6160        Assert.AreEqual(200, SamplesUtils.GetIntResult(pso, "Iterations"));
    6261      }
    6362    }
    6463
    65     private ParticleSwarmOptimization CreatePsoSchwefelSample() {
     64    private ParticleSwarmOptimization CreatePsoRastriginSample() {
    6665      ParticleSwarmOptimization pso = new ParticleSwarmOptimization();
    6766      #region Problem Configuration
    6867      var problem = new SingleObjectiveTestFunctionProblem();
    69       problem.BestKnownQuality.Value = 0.0;
    70       problem.BestKnownSolutionParameter.Value = new RealVector(new double[] { 420.968746, 420.968746 });
    71       problem.Bounds = new DoubleMatrix(new double[,] { { -500, 500 } });
    72       problem.EvaluatorParameter.Value = new SchwefelEvaluator();
    73       problem.Maximization.Value = false;
    74       problem.ProblemSize.Value = 2;
     68      var provider = new SOTFInstanceProvider();
     69      problem.Load(provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name == "Rastrigin Function")));
    7570      problem.SolutionCreatorParameter.Value = new UniformRandomRealVectorCreator();
    7671      #endregion
    7772      #region Algorithm Configuration
    78       pso.Name = "Particle Swarm Optimization - Schwefel";
    79       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)";
     73      pso.Name = "Particle Swarm Optimization - Rastrigin";
     74      pso.Description = "A particle swarm optimization algorithm which solves the 2-dimensional Rastrigin test function.";
    8075      pso.Problem = problem;
    8176      pso.Inertia.Value = 0.721;
Note: See TracChangeset for help on using the changeset viewer.