Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/RAPGASchedulingSampleTest.cs @ 11507

Last change on this file since 11507 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: 3.1 KB
RevLine 
[11450]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.RAPGA;
25using HeuristicLab.Encodings.ScheduleEncoding.JobSequenceMatrix;
26using HeuristicLab.Persistence.Default.Xml;
27using HeuristicLab.Problems.Scheduling;
28using Microsoft.VisualStudio.TestTools.UnitTesting;
29
30namespace HeuristicLab.Tests {
31  /// <summary>
32  /// Summary description for RAPGASchedulingSampleTest
33  /// </summary>
34  [TestClass]
35  public class RAPGASchedulingSampleTest {
36    private const string samplesDirectory = SamplesUtils.Directory;
37    [ClassInitialize]
38    public static void MyClassInitialize(TestContext testContext) {
39      if (!Directory.Exists(samplesDirectory))
40        Directory.CreateDirectory(samplesDirectory);
41    }
42
43    [TestMethod]
44    [TestCategory("Samples.Create")]
45    [TestProperty("Time", "medium")]
46    public void CreateRAPGASchedulingSampleTest() {
47      var ss = CreateRAPGASchedulingSample();
48      XmlGenerator.Serialize(ss, @"Samples\RAPGA_JSSP.hl");
49    }
50
51    [TestMethod]
52    [TestCategory("Samples.Execute")]
53    [TestProperty("Time", "long")]
54    public void RunRAPGASchedulingSampleTest() {
55      var rapga = CreateRAPGASchedulingSample();
56      rapga.SetSeedRandomly.Value = false;
57      SamplesUtils.RunAlgorithm(rapga);
58      Assert.AreEqual(988.00, SamplesUtils.GetDoubleResult(rapga, "BestQuality"));
59      Assert.AreEqual(988.00, SamplesUtils.GetDoubleResult(rapga, "CurrentAverageQuality"));
60      Assert.AreEqual(988.00, SamplesUtils.GetDoubleResult(rapga, "CurrentWorstQuality"));
61      Assert.AreEqual(27100, SamplesUtils.GetIntResult(rapga, "EvaluatedSolutions"));
62    }
63
64    private RAPGA CreateRAPGASchedulingSample() {
65      #region Problem Configuration
66      JobShopSchedulingProblem problem = new JobShopSchedulingProblem();
67      #endregion
68
69      #region Algorithm Configuration
70      RAPGA rapga = new RAPGA();
71      rapga.Engine = new SequentialEngine.SequentialEngine();
72      rapga.Name = "RAPGA - Job Shop Scheduling";
73      rapga.Description = "A relevant alleles preserving genetic algorithm which solves a job shop scheduling problem";
74      rapga.Problem = problem;
75      rapga.Mutator = rapga.MutatorParameter.ValidValues.OfType<JSMSwapManipulator>().First();
76      rapga.Seed.Value = 0;
77      return rapga;
78      #endregion
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.