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