Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Tests/HeuristicLab-3.3/Samples/RAPGASchedulingSampleTest.cs @ 17035

Last change on this file since 17035 was 17035, checked in by gkronber, 5 years ago

#2925: merged r17007:17033 from trunk to branch

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2019 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.RAPGA;
26using HeuristicLab.Encodings.ScheduleEncoding.JobSequenceMatrix;
27using HeuristicLab.Problems.Scheduling;
28using Microsoft.VisualStudio.TestTools.UnitTesting;
29
30namespace HeuristicLab.Tests {
31  [TestClass]
32  public class RAPGASchedulingSampleTest {
33    private const string SampleFileName = "RAPGA_JSSP";
34    private static readonly ProtoBufSerializer serializer = new ProtoBufSerializer();
35
36    [TestMethod]
37    [TestCategory("Samples.Create")]
38    [TestProperty("Time", "medium")]
39    public void CreateRAPGASchedulingSampleTest() {
40      var ss = CreateRAPGASchedulingSample();
41      string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
42      serializer.Serialize(ss, path);
43    }
44
45    [TestMethod]
46    [TestCategory("Samples.Execute")]
47    [TestProperty("Time", "long")]
48    public void RunRAPGASchedulingSampleTest() {
49      var rapga = CreateRAPGASchedulingSample();
50      rapga.SetSeedRandomly.Value = false;
51      SamplesUtils.RunAlgorithm(rapga);
52      Assert.AreEqual(988.00, SamplesUtils.GetDoubleResult(rapga, "BestQuality"));
53      Assert.AreEqual(988.00, SamplesUtils.GetDoubleResult(rapga, "CurrentAverageQuality"));
54      Assert.AreEqual(988.00, SamplesUtils.GetDoubleResult(rapga, "CurrentWorstQuality"));
55      Assert.AreEqual(27100, SamplesUtils.GetIntResult(rapga, "EvaluatedSolutions"));
56    }
57
58    private RAPGA CreateRAPGASchedulingSample() {
59      #region Problem Configuration
60      JobShopSchedulingProblem problem = new JobShopSchedulingProblem();
61      #endregion
62
63      #region Algorithm Configuration
64      RAPGA rapga = new RAPGA();
65      rapga.Engine = new SequentialEngine.SequentialEngine();
66      rapga.Name = "RAPGA - Job Shop Scheduling";
67      rapga.Description = "A relevant alleles preserving genetic algorithm which solves a job shop scheduling problem";
68      rapga.Problem = problem;
69      rapga.Mutator = rapga.MutatorParameter.ValidValues.OfType<JSMSwapManipulator>().First();
70      rapga.Seed.Value = 0;
71      return rapga;
72      #endregion
73    }
74  }
75}
Note: See TracBrowser for help on using the repository browser.