#region License Information
/* HeuristicLab
* Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using HeuristicLab.Data;
using HeuristicLab.Problems.GeneralizedQuadraticAssignment;
using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.GRASP;
using HeuristicLab.Problems.Instances.CordeauGQAP;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTests {
[TestClass]
public class GRASPTest {
[TestMethod]
public void TestGraspSolveInstance() {
var provider = new CordeauGQAPInstanceProvider();
var instance = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name == "20-15-35"));
var gqap = new GQAP();
gqap.Load(instance);
var bestQuality = new List();
for (var i = 0; i < 5; i++) {
var grasp = new GRASP() {
Problem = gqap,
CandidateSizeFactor = 0.5,
EliteSetSize = 10,
MaximumCandidateListSize = 10,
MaximumIterations = 200,
MaximumLocalSearchIterations = 100,
MinimumDifference = 4,
MinimumEliteSetSize = 2,
OneMoveProbability = 0.5,
SetSeedRandomly = false,
Seed = i
};
grasp.Start();
Assert.IsTrue(grasp.ExecutionTime.TotalSeconds < 6);
bestQuality.Add(((DoubleValue)grasp.Results["BestQuality"].Value).Value);
}
// at least one in 10 runs should find the global optimum
Assert.IsTrue(bestQuality.Count(x => x == gqap.BestKnownQuality) > 0, string.Join("; ", bestQuality));
CollectionAssert.AreEqual(new double[] { 1471896, 1506076, 1509356, 1511402, 1471896 }, bestQuality);
}
}
}