#region License Information /* HeuristicLab * Copyright (C) 2002-2012 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.Linq; using HeuristicLab.Data; using HeuristicLab.Encodings.IntegerVectorEncoding; using HeuristicLab.Problems.GeneralizedQuadraticAssignment; using HeuristicLab.Problems.Instances.CordeauGQAP; using HeuristicLab.Random; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace UnitTests { [TestClass] public class CordeauCrossoverTest { [TestMethod] public void CordeauCrossoverFunctionalityTest() { var provider = new CordeauGQAPInstanceProvider(); var instance = provider.LoadData(provider.GetDataDescriptors().First()); var gqap = new GeneralizedQuadraticAssignmentProblem(); gqap.Load(instance); var random = new MersenneTwister(); for (int i = 0; i < 100; i++) { var parent1 = new IntegerVector(gqap.Demands.Length, random, 0, gqap.Capacities.Length); var parent2 = new IntegerVector(gqap.Demands.Length, random, 0, gqap.Capacities.Length); try { CordeauCrossover.Apply(random, gqap.Maximization, parent1, new DoubleValue(GQAPEvaluator.Evaluate(parent1, gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.OverbookedCapacityPenalty)), parent2, new DoubleValue(GQAPEvaluator.Evaluate(parent2, gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.OverbookedCapacityPenalty)), gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.OverbookedCapacityPenalty); } catch { Assert.Fail("Error during crossover"); } } } } }