Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Tests/HeuristicLab-3.3/Samples/TabuSearch3dBinPackingSampleTest.cs @ 14170

Last change on this file since 14170 was 14170, checked in by gkronber, 8 years ago

#2641: merged r14162,r14163,r14167,r14168,r14169 from trunk to stable

File size: 3.9 KB
RevLine 
[14167]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.Encodings.PermutationEncoding;
26using HeuristicLab.Persistence.Default.Xml;
27using HeuristicLab.Problems.BinPacking3D;
28using Microsoft.VisualStudio.TestTools.UnitTesting;
29
30namespace HeuristicLab.Tests {
31  [TestClass]
32  public class TabuSearch3dBinPackingSampleTest {
33    private const string SampleFileName = "TS_BPP";
34
35    [TestMethod]
36    [TestCategory("Samples.Create")]
37    [TestProperty("Time", "medium")]
38    public void CreateTabuSearchBppSampleTest() {
39      var ts = CreateTabuSearchBppSample();
40      string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
41      XmlGenerator.Serialize(ts, path);
42    }
43    [TestMethod]
44    [TestCategory("Samples.Execute")]
45    [TestProperty("Time", "long")]
46    public void RunTabuSearchBppSampleTest() {
47      var ts = CreateTabuSearchBppSample();
48      ts.SetSeedRandomly.Value = false;
49      SamplesUtils.RunAlgorithm(ts);
50      // Assert.AreEqual(6294, SamplesUtils.GetDoubleResult(ts, "BestQuality"));
51      // Assert.AreEqual(7380.0386666666664, SamplesUtils.GetDoubleResult(ts, "CurrentAverageQuality"));
52      // Assert.AreEqual(8328, SamplesUtils.GetDoubleResult(ts, "CurrentWorstQuality"));
53      // Assert.AreEqual(750000, SamplesUtils.GetIntResult(ts, "EvaluatedMoves"));
54    }
55
56    private TabuSearch CreateTabuSearchBppSample() {
57      TabuSearch ts = new TabuSearch();
58      #region Problem Configuration
59      PermutationProblem bppProblem = new PermutationProblem();
60      #endregion
61      #region Algorithm Configuration
62      ts.Name = "Tabu Search - 3D Bin Packing Problem";
63      ts.Description = "A tabu search algorithm that solves a 3D bin packing problem instance";
64      ts.Problem = bppProblem;
65
66      ts.MaximumIterations.Value = 1000;
67      // move generator has to be set first
68      var moveGenerator = ts.MoveGeneratorParameter.ValidValues
69        .OfType<Encodings.PermutationEncoding.StochasticTranslocationMultiMoveGenerator>()
70        .Single();
71      ts.MoveGenerator = moveGenerator;
72      var moveEvaluator = ts.MoveEvaluatorParameter.ValidValues
73        .OfType<Problems.BinPacking3D.TranslocationMoveEvaluator>()
74        .Single();
75      ts.MoveEvaluator = moveEvaluator;
76      var moveMaker = ts.MoveMakerParameter.ValidValues
77        .OfType<TranslocationMoveMaker>()
78        .Single();
79      ts.MoveMaker = moveMaker;
80      ts.SampleSize.Value = 100;
81      ts.Seed.Value = 0;
82      ts.SetSeedRandomly.Value = true;
83
84      var tabuChecker = ts.TabuCheckerParameter.ValidValues
85        .OfType<TranslocationMoveSoftTabuCriterion>()
86        .Single();
87      tabuChecker.UseAspirationCriterion.Value = true;
88      ts.TabuChecker = tabuChecker;
89
90      var tabuMaker = ts.TabuMakerParameter.ValidValues
91        .OfType<TranslocationMoveTabuMaker>()
92        .Single();
93      ts.TabuMaker = tabuMaker;
94      ts.TabuTenure.Value = 60;
95
96      #endregion
97      ts.Engine = new ParallelEngine.ParallelEngine();
98      return ts;
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.