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