1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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.TabuSearch;
|
---|
25 | using HeuristicLab.Persistence.Default.Xml;
|
---|
26 | using HeuristicLab.Problems.Instances.VehicleRouting;
|
---|
27 | using HeuristicLab.Problems.VehicleRouting;
|
---|
28 | using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin;
|
---|
29 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Tests {
|
---|
32 | [TestClass]
|
---|
33 | public class TabuSearchVRPSampleTest {
|
---|
34 | private const string SampleFileName = "TS_VRP";
|
---|
35 |
|
---|
36 | [TestMethod]
|
---|
37 | [TestCategory("Samples.Create")]
|
---|
38 | [TestProperty("Time", "medium")]
|
---|
39 | public void CreateTabuSearchVRPSampleTest() {
|
---|
40 | var vrp = CreateTabuSearchVrpSample();
|
---|
41 | string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
|
---|
42 | XmlGenerator.Serialize(vrp, path);
|
---|
43 | }
|
---|
44 | [TestMethod]
|
---|
45 | [TestCategory("Samples.Execute")]
|
---|
46 | [TestProperty("Time", "long")]
|
---|
47 | public void RunTabuSearchVRPSampleTest() {
|
---|
48 | var vrp = CreateTabuSearchVrpSample();
|
---|
49 | vrp.SetSeedRandomly.Value = false;
|
---|
50 | SamplesUtils.RunAlgorithm(vrp);
|
---|
51 | Assert.AreEqual(1473, SamplesUtils.GetDoubleResult(vrp, "BestQuality"));
|
---|
52 | Assert.AreEqual(2102.1192622950812, SamplesUtils.GetDoubleResult(vrp, "CurrentAverageQuality"));
|
---|
53 | Assert.AreEqual(4006, SamplesUtils.GetDoubleResult(vrp, "CurrentWorstQuality"));
|
---|
54 | Assert.AreEqual(119072, SamplesUtils.GetIntResult(vrp, "EvaluatedMoves"));
|
---|
55 | }
|
---|
56 |
|
---|
57 | private TabuSearch CreateTabuSearchVrpSample() {
|
---|
58 | TabuSearch ts = new TabuSearch();
|
---|
59 | #region Problem Configuration
|
---|
60 | var provider = new AugeratInstanceProvider();
|
---|
61 | var instance = provider.GetDataDescriptors().Where(x => x.Name == "A-n62-k8").Single();
|
---|
62 | VehicleRoutingProblem vrpProblem = new VehicleRoutingProblem();
|
---|
63 | vrpProblem.Load(provider.LoadData(instance));
|
---|
64 | #endregion
|
---|
65 | #region Algorithm Configuration
|
---|
66 | ts.Name = "Tabu Search - VRP";
|
---|
67 | ts.Description = "A tabu search algorithm that solves the \"A-n62-k8\" VRP (imported from Augerat)";
|
---|
68 | ts.Problem = vrpProblem;
|
---|
69 |
|
---|
70 | ts.MaximumIterations.Value = 200;
|
---|
71 | // move generator has to be set first
|
---|
72 | var moveGenerator = ts.MoveGeneratorParameter.ValidValues
|
---|
73 | .OfType<PotvinCustomerRelocationExhaustiveMoveGenerator>()
|
---|
74 | .Single();
|
---|
75 | ts.MoveGenerator = moveGenerator;
|
---|
76 | var moveEvaluator = ts.MoveEvaluatorParameter.ValidValues
|
---|
77 | .OfType<PotvinCustomerRelocationMoveEvaluator>()
|
---|
78 | .Single();
|
---|
79 | ts.MoveEvaluator = moveEvaluator;
|
---|
80 | var moveMaker = ts.MoveMakerParameter.ValidValues
|
---|
81 | .OfType<PotvinCustomerRelocationMoveMaker>()
|
---|
82 | .Single();
|
---|
83 | ts.MoveMaker = moveMaker;
|
---|
84 | ts.SampleSize.Value = 1000;
|
---|
85 | ts.Seed.Value = 0;
|
---|
86 | ts.SetSeedRandomly.Value = true;
|
---|
87 |
|
---|
88 | var tabuChecker = ts.TabuCheckerParameter.ValidValues
|
---|
89 | .OfType<PotvinCustomerRelocationMoveTabuCriterion>()
|
---|
90 | .Single();
|
---|
91 | tabuChecker.UseAspirationCriterion.Value = false;
|
---|
92 | ts.TabuChecker = tabuChecker;
|
---|
93 |
|
---|
94 | var tabuMaker = ts.TabuMakerParameter.ValidValues
|
---|
95 | .OfType<PotvinCustomerRelocationMoveTabuMaker>()
|
---|
96 | .Single();
|
---|
97 | ts.TabuMaker = tabuMaker;
|
---|
98 | ts.TabuTenure.Value = 6;
|
---|
99 |
|
---|
100 | #endregion
|
---|
101 | ts.Engine = new ParallelEngine.ParallelEngine();
|
---|
102 | return ts;
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|