Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3040_VectorBasedGP/HeuristicLab.Tests/HeuristicLab-3.3/Samples/TabuSearchVRPSampleTest.cs

Last change on this file was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

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