Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Tests/HeuristicLab-3.3/Samples/ScatterSearchVRPSampleTest.cs @ 17021

Last change on this file since 17021 was 17021, checked in by mkommend, 5 years ago

#2520: Adapted all unit tests to use attic instead of the xml persistence. This affects all sample unit tests, the test resources, script unit tests and some general unit tests.

File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2019 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.IO;
23using System.Linq;
24using HEAL.Attic;
25using HeuristicLab.Algorithms.ScatterSearch;
26using HeuristicLab.Problems.Instances.VehicleRouting;
27using HeuristicLab.Problems.VehicleRouting;
28using Microsoft.VisualStudio.TestTools.UnitTesting;
29
30namespace HeuristicLab.Tests {
31  [TestClass]
32  public class ScatterSearchVRPSampleTest {
33    private const string SampleFileName = "SS_VRP";
34    private static readonly ProtoBufSerializer serializer = new ProtoBufSerializer();
35
36    [TestMethod]
37    [TestCategory("Samples.Create")]
38    [TestProperty("Time", "medium")]
39    public void CreateScatterSearchVRPSampleTest() {
40      var ss = CreateScatterSearchVRPSample();
41      string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
42      serializer.Serialize(ss, path);
43    }
44
45    [TestMethod]
46    [TestCategory("Samples.Execute")]
47    [TestProperty("Time", "long")]
48    public void RunScatterSearchVRPSampleTest() {
49      var ss = CreateScatterSearchVRPSample();
50      ss.SetSeedRandomly.Value = false;
51      SamplesUtils.RunAlgorithm(ss);
52      Assert.AreEqual(828.93686694283383, SamplesUtils.GetDoubleResult(ss, "BestQuality"));
53      Assert.AreEqual(868.63623986983077, SamplesUtils.GetDoubleResult(ss, "CurrentAverageQuality"));
54      Assert.AreEqual(1048.8333559209832, SamplesUtils.GetDoubleResult(ss, "CurrentWorstQuality"));
55      Assert.AreEqual(262622, SamplesUtils.GetIntResult(ss, "EvaluatedSolutions"));
56    }
57
58    private ScatterSearch CreateScatterSearchVRPSample() {
59      #region Problem Configuration
60      var provider = new SolomonInstanceProvider();
61      var instance = provider.GetDataDescriptors().Single(x => x.Name == "C101");
62      VehicleRoutingProblem vrpProblem = new VehicleRoutingProblem();
63      vrpProblem.Load(provider.LoadData(instance));
64      #endregion
65
66      #region Algorithm Configuration
67      ScatterSearch ss = new ScatterSearch();
68      ss.Engine = new SequentialEngine.SequentialEngine();
69      ss.Name = "Scatter Search - VRP";
70      ss.Description = "A scatter search algorithm which solves the \"C101\" vehicle routing problem (imported from Solomon)";
71      ss.Problem = vrpProblem;
72
73      var improver = ss.Problem.Operators.OfType<VRPIntraRouteImprovementOperator>().First();
74      improver.ImprovementAttemptsParameter.Value.Value = 15;
75      improver.SampleSizeParameter.Value.Value = 10;
76      ss.Improver = improver;
77
78      var pathRelinker = ss.Problem.Operators.OfType<VRPPathRelinker>().First();
79      pathRelinker.IterationsParameter.Value.Value = 25;
80      ss.PathRelinker = pathRelinker;
81
82      var similarityCalculator = ss.SimilarityCalculatorParameter.ValidValues.OfType<VRPSimilarityCalculator>().First();
83      ss.SimilarityCalculator = similarityCalculator;
84
85      ss.MaximumIterations.Value = 2;
86      ss.PopulationSize.Value = 20;
87      ss.ReferenceSetSize.Value = 10;
88      ss.Seed.Value = 0;
89      return ss;
90      #endregion
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.