1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2017 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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.Linq;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Problems.GeneralizedQuadraticAssignment;
|
---|
26 | using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.GRASP;
|
---|
27 | using HeuristicLab.Problems.Instances.CordeauGQAP;
|
---|
28 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
29 |
|
---|
30 | namespace UnitTests {
|
---|
31 | [TestClass]
|
---|
32 | public class GRASPTest {
|
---|
33 | [TestMethod]
|
---|
34 | public void TestGraspSolveInstance() {
|
---|
35 | var provider = new CordeauGQAPInstanceProvider();
|
---|
36 | var instance = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name == "20-15-35"));
|
---|
37 | var gqap = new GQAP();
|
---|
38 | gqap.Load(instance);
|
---|
39 |
|
---|
40 | var bestQuality = new List<double>();
|
---|
41 | for (var i = 0; i < 5; i++) {
|
---|
42 | var grasp = new GRASP() {
|
---|
43 | Problem = gqap,
|
---|
44 | CandidateSizeFactor = 0.5,
|
---|
45 | EliteSetSize = 10,
|
---|
46 | MaximumCandidateListSize = 10,
|
---|
47 | MaximumIterations = 200,
|
---|
48 | MaximumLocalSearchIterations = 100,
|
---|
49 | MinimumDifference = 4,
|
---|
50 | MinimumEliteSetSize = 2,
|
---|
51 | OneMoveProbability = 0.5,
|
---|
52 | SetSeedRandomly = false,
|
---|
53 | Seed = i
|
---|
54 | };
|
---|
55 | grasp.Start();
|
---|
56 | Assert.IsTrue(grasp.ExecutionTime.TotalSeconds < 6);
|
---|
57 | bestQuality.Add(((DoubleValue)grasp.Results["BestQuality"].Value).Value);
|
---|
58 | }
|
---|
59 | // at least one in 10 runs should find the global optimum
|
---|
60 | Assert.IsTrue(bestQuality.Count(x => x == gqap.BestKnownQuality) > 0, string.Join("; ", bestQuality));
|
---|
61 | CollectionAssert.AreEqual(new double[] { 1471896, 1506076, 1509356, 1511402, 1471896 }, bestQuality);
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|