[11450] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17209] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[11450] | 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.IO;
|
---|
| 23 | using System.Linq;
|
---|
[17120] | 24 | using HEAL.Attic;
|
---|
[11450] | 25 | using HeuristicLab.Algorithms.VariableNeighborhoodSearch;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
[12721] | 27 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
| 28 | using HeuristicLab.Problems.Orienteering;
|
---|
[11450] | 29 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Tests {
|
---|
| 32 | [TestClass]
|
---|
[12721] | 33 | public class VnsOpSampleTest {
|
---|
| 34 | private const string SampleFileName = "VNS_OP";
|
---|
[17120] | 35 | private static readonly ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
[11450] | 36 |
|
---|
| 37 | [TestMethod]
|
---|
| 38 | [TestCategory("Samples.Create")]
|
---|
| 39 | [TestProperty("Time", "medium")]
|
---|
[12836] | 40 | public void CreateVnsOpSampleTest() {
|
---|
| 41 | var vns = CreateVnsOpSample();
|
---|
[11514] | 42 | string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
|
---|
[17120] | 43 | serializer.Serialize(vns, path);
|
---|
[11450] | 44 | }
|
---|
| 45 | [TestMethod]
|
---|
| 46 | [TestCategory("Samples.Execute")]
|
---|
| 47 | [TestProperty("Time", "long")]
|
---|
[12836] | 48 | public void RunVnsOpSampleTest() {
|
---|
| 49 | var vns = CreateVnsOpSample();
|
---|
[11450] | 50 | vns.SetSeedRandomly = false;
|
---|
| 51 | SamplesUtils.RunAlgorithm(vns);
|
---|
[12721] | 52 | Assert.AreEqual(1182, SamplesUtils.GetDoubleResult(vns, "BestQuality"));
|
---|
| 53 | Assert.AreEqual(1182, SamplesUtils.GetDoubleResult(vns, "CurrentAverageQuality"));
|
---|
| 54 | Assert.AreEqual(1182, SamplesUtils.GetDoubleResult(vns, "CurrentWorstQuality"));
|
---|
| 55 | Assert.AreEqual(42651753, SamplesUtils.GetIntResult(vns, "EvaluatedSolutions"));
|
---|
[11450] | 56 | }
|
---|
| 57 |
|
---|
[12836] | 58 | private VariableNeighborhoodSearch CreateVnsOpSample() {
|
---|
[11450] | 59 | VariableNeighborhoodSearch vns = new VariableNeighborhoodSearch();
|
---|
| 60 | #region Problem Configuration
|
---|
[12721] | 61 | OrienteeringProblem opProblem = new OrienteeringProblem();
|
---|
| 62 | opProblem.BestKnownQuality = new DoubleValue(1188);
|
---|
| 63 | opProblem.BestKnownSolution = new IntegerVector(new[] {
|
---|
| 64 | 0, 1, 3, 6, 11, 17, 24, 18, 13, 19, 14, 20, 26, 34, 27, 35, 42, 48, 53, 57, 52, 47, 41, 33, 25, 32, 40, 46, 39, 31, 38, 50, 44, 37, 30, 23, 16, 10, 15, 22, 29, 21, 28, 36, 43, 49, 54, 58, 61, 63
|
---|
[11450] | 65 | });
|
---|
[12721] | 66 | opProblem.Coordinates = new DoubleMatrix(new double[,] {
|
---|
| 67 | { 7, 0 },{ 6, 1 },{ 8, 1 },{ 5, 2 },{ 7, 2 },{ 9, 2 },{ 4, 3 },{ 6, 3 },{ 8, 3 },{ 10, 3 },{ 3, 4 },{ 5, 4 },{ 7, 4 },{ 9, 4 },{ 11, 4 },{ 2, 5 },{ 4, 5 },{ 6, 5 },{ 8, 5 },{ 10, 5 },{ 12, 5 },{ 1, 6 },{ 3, 6 },{ 5, 6 },{ 7, 6 },{ 9, 6 },{ 11, 6 },{ 13, 6 },{ 0, 7 },{ 2, 7 },{ 4, 7 },{ 6, 7 },{ 8, 7 },{ 10, 7 },{ 12, 7 },{ 14, 7 },{ 1, 8 },{ 3, 8 },{ 5, 8 },{ 7, 8 },{ 9, 8 },{ 11, 8 },{ 13, 8 },{ 2, 9 },{ 4, 9 },{ 6, 9 },{ 8, 9 },{ 10, 9 },{ 12, 9 },{ 3, 10 },{ 5, 10 },{ 7, 10 },{ 9, 10 },{ 11, 10 },{ 4, 11 },{ 6, 11 },{ 8, 11 },{ 10, 11 },{ 5, 12 },{ 7, 12 },{ 9, 12 },{ 6, 13 },{ 8, 13 },{ 7, 14 }
|
---|
[11450] | 68 | });
|
---|
[12721] | 69 | opProblem.MaximumDistance = 70;
|
---|
| 70 | opProblem.PointVisitingCosts = 0;
|
---|
| 71 | opProblem.Scores = new DoubleArray(new double[] {
|
---|
| 72 | 0, 6, 6, 12, 6, 12, 18, 12, 12, 18, 24, 18, 12, 18, 24, 30, 24, 18, 18, 24, 30, 36, 30, 24, 18, 24, 30, 36, 42, 36, 30, 24, 24, 30, 36, 42, 36, 30, 24, 18, 24, 30, 36, 30, 24, 18, 18, 24, 30, 24, 18, 12, 18, 24, 18, 12, 12, 18, 12, 6, 12, 6, 6, 0
|
---|
| 73 | });
|
---|
| 74 | opProblem.StartingPoint = 0;
|
---|
| 75 | opProblem.TerminalPoint = 63;
|
---|
[11450] | 76 |
|
---|
[12721] | 77 | opProblem.Name = "1_p64_t070";
|
---|
[12812] | 78 | opProblem.Description = "Represents an instance of an orienteering problem.";
|
---|
[11450] | 79 | #endregion
|
---|
| 80 | #region Algorithm Configuration
|
---|
[12812] | 81 | vns.Name = "Variable Neighborhood Search - OP";
|
---|
| 82 | vns.Description = "A variable neighborhood search algorithm which solves an orienteering problem instance";
|
---|
[12721] | 83 | vns.Problem = opProblem;
|
---|
[11450] | 84 |
|
---|
[12721] | 85 | vns.LocalImprovement = vns.LocalImprovementParameter.ValidValues.OfType<OrienteeringLocalImprovementOperator>().Single();
|
---|
| 86 | vns.LocalImprovementMaximumIterations = 200;
|
---|
[11450] | 87 | vns.MaximumIterations = 25;
|
---|
| 88 | vns.Seed = 0;
|
---|
| 89 | vns.SetSeedRandomly = true;
|
---|
[12721] | 90 | vns.ShakingOperator = vns.ShakingOperatorParameter.ValidValues.OfType<OrienteeringShakingOperator>().Single();
|
---|
[11450] | 91 | #endregion
|
---|
| 92 | vns.Engine = new ParallelEngine.ParallelEngine();
|
---|
| 93 | return vns;
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 | }
|
---|