Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Tests/HeuristicLab-3.3/Samples/TabuSearchVRPSampleTest.cs @ 12136

Last change on this file since 12136 was 12009, checked in by ascheibe, 10 years ago

#2212 updated copyright year

File size: 4.2 KB
Line 
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
22using System.IO;
23using System.Linq;
24using HeuristicLab.Algorithms.TabuSearch;
25using HeuristicLab.Persistence.Default.Xml;
26using HeuristicLab.Problems.Instances.VehicleRouting;
27using HeuristicLab.Problems.VehicleRouting;
28using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin;
29using Microsoft.VisualStudio.TestTools.UnitTesting;
30
31namespace 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}
Note: See TracBrowser for help on using the repository browser.