[11450] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2014 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.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 | /// <summary>
|
---|
| 32 | /// Summary description for ScatterSearchVRPSampleTest
|
---|
| 33 | /// </summary>
|
---|
| 34 | [TestClass]
|
---|
| 35 | public class ScatterSearchVRPSampleTest {
|
---|
| 36 | private const string samplesDirectory = SamplesUtils.Directory;
|
---|
| 37 | [ClassInitialize]
|
---|
| 38 | public static void MyClassInitialize(TestContext testContext) {
|
---|
| 39 | if (!Directory.Exists(samplesDirectory))
|
---|
| 40 | Directory.CreateDirectory(samplesDirectory);
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | [TestMethod]
|
---|
| 44 | [TestCategory("Samples.Create")]
|
---|
| 45 | [TestProperty("Time", "medium")]
|
---|
| 46 | public void CreateScatterSearchVRPSampleTest() {
|
---|
| 47 | var ss = CreateScatterSearchVRPSample();
|
---|
| 48 | XmlGenerator.Serialize(ss, @"Samples\SS_VRP.hl");
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | [TestMethod]
|
---|
| 52 | [TestCategory("Samples.Execute")]
|
---|
| 53 | [TestProperty("Time", "long")]
|
---|
| 54 | public void RunScatterSearchVRPSampleTest() {
|
---|
| 55 | var ss = CreateScatterSearchVRPSample();
|
---|
| 56 | ss.SetSeedRandomly.Value = false;
|
---|
| 57 | SamplesUtils.RunAlgorithm(ss);
|
---|
| 58 | Assert.AreEqual(828.93686694283383, SamplesUtils.GetDoubleResult(ss, "BestQuality"));
|
---|
| 59 | Assert.AreEqual(868.63623986983077, SamplesUtils.GetDoubleResult(ss, "CurrentAverageQuality"));
|
---|
| 60 | Assert.AreEqual(1048.8333559209832, SamplesUtils.GetDoubleResult(ss, "CurrentWorstQuality"));
|
---|
| 61 | Assert.AreEqual(262622, SamplesUtils.GetIntResult(ss, "EvaluatedSolutions"));
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | private ScatterSearch CreateScatterSearchVRPSample() {
|
---|
| 65 | #region Problem Configuration
|
---|
| 66 | var provider = new SolomonInstanceProvider();
|
---|
| 67 | var instance = provider.GetDataDescriptors().Single(x => x.Name == "C101");
|
---|
| 68 | VehicleRoutingProblem vrpProblem = new VehicleRoutingProblem();
|
---|
| 69 | vrpProblem.Load(provider.LoadData(instance));
|
---|
| 70 | #endregion
|
---|
| 71 |
|
---|
| 72 | #region Algorithm Configuration
|
---|
| 73 | ScatterSearch ss = new ScatterSearch();
|
---|
| 74 | ss.Engine = new SequentialEngine.SequentialEngine();
|
---|
| 75 | ss.Name = "Scatter Search - VRP";
|
---|
| 76 | ss.Description = "A scatter search algorithm which solves the \"C101\" vehicle routing problem (imported from Solomon)";
|
---|
| 77 | ss.Problem = vrpProblem;
|
---|
| 78 |
|
---|
| 79 | var improver = ss.Problem.Operators.OfType<VRPIntraRouteImprovementOperator>().First();
|
---|
| 80 | improver.ImprovementAttemptsParameter.Value.Value = 15;
|
---|
| 81 | improver.SampleSizeParameter.Value.Value = 10;
|
---|
| 82 | ss.Improver = improver;
|
---|
| 83 |
|
---|
| 84 | var pathRelinker = ss.Problem.Operators.OfType<VRPPathRelinker>().First();
|
---|
| 85 | pathRelinker.IterationsParameter.Value.Value = 25;
|
---|
| 86 | ss.PathRelinker = pathRelinker;
|
---|
| 87 |
|
---|
| 88 | var similarityCalculator = ss.SimilarityCalculatorParameter.ValidValues.OfType<VRPSimilarityCalculator>().First();
|
---|
| 89 | ss.SimilarityCalculator = similarityCalculator;
|
---|
| 90 |
|
---|
| 91 | ss.MaximumIterations.Value = 2;
|
---|
| 92 | ss.PopulationSize.Value = 20;
|
---|
| 93 | ss.ReferenceSetSize.Value = 10;
|
---|
| 94 | ss.Seed.Value = 0;
|
---|
| 95 | return ss;
|
---|
| 96 | #endregion
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | }
|
---|