Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/TabuSearchVRPSampleTest.cs @ 11450

Last change on this file since 11450 was 11450, checked in by bburlacu, 10 years ago

#2211: Separated samples class into separate test classes. Added scripts unit tests (grid search classification/regression).

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