Changeset 15504 for branches/GeneralizedQAP/UnitTests
- Timestamp:
- 12/10/17 22:11:10 (7 years ago)
- Location:
- branches/GeneralizedQAP/UnitTests
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/UnitTests/CordeauCrossoverTest.cs
r15490 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 var provider = new CordeauGQAPInstanceProvider(); 36 36 var instance = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name == "20-15-75")); 37 var gqap = new G eneralizedQuadraticAssignmentProblem();37 var gqap = new GQAP(); 38 38 gqap.Load(instance); 39 39 var evaluator = gqap.Evaluator; … … 41 41 for (int i = 0; i < 100; i++) { 42 42 var random = new MersenneTwister((uint)i); 43 var parent1 = GreedyRandomizedSolutionCreator.CreateSolution(random, gqap. Demands, gqap.Capacities, gqap.Evaluator, 100, true, CancellationToken.None);44 var parent2 = GreedyRandomizedSolutionCreator.CreateSolution(random, gqap. Demands, gqap.Capacities, gqap.Evaluator, 100, true, CancellationToken.None);43 var parent1 = GreedyRandomizedSolutionCreator.CreateSolution(random, gqap.ProblemInstance, 100, true, CancellationToken.None); 44 var parent2 = GreedyRandomizedSolutionCreator.CreateSolution(random, gqap.ProblemInstance, 100, true, CancellationToken.None); 45 45 46 46 try { 47 47 CordeauCrossover.Apply(random, gqap.Maximization, 48 48 parent1, 49 new DoubleValue(gqap.Evaluat or.Evaluate(parent1, gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.ExpectedRandomQuality)),49 new DoubleValue(gqap.Evaluate(parent1)), 50 50 parent2, 51 new DoubleValue(gqap.Evaluat or.Evaluate(parent2, gqap.Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.ExpectedRandomQuality)),52 gqap. Weights, gqap.Distances, gqap.InstallationCosts, gqap.Demands, gqap.Capacities, gqap.TransportationCosts, gqap.ExpectedRandomQuality, gqap.Evaluator,51 new DoubleValue(gqap.Evaluate(parent2)), 52 gqap.ProblemInstance, 53 53 new IntValue(0)); 54 54 } catch { -
branches/GeneralizedQAP/UnitTests/GQAPNMoveEvaluatorTest.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 public class GQAPNMoveEvaluatorTest { 36 36 private const int Equipments = 10, Locations = 5; 37 private static DoubleMatrix symmetricWeights, asymmetricWeights, nonZeroDiagonalWeights; 38 private static DoubleMatrix symmetricDistances, asymmetricDistances, nonZeroDiagonalDistances; 39 private static DoubleMatrix installationCosts; 40 private static DoubleArray demands, capacities; 41 private static double transportationCosts, overbookedCapacityPenalty; 37 private static GQAPInstance symmetricInstance, asymmetricInstance, nonZeroDiagonalInstance; 42 38 private static IntegerVector assignment; 43 39 private static MersenneTwister random; … … 58 54 public static void MyClassInitialize(TestContext testContext) { 59 55 random = new MersenneTwister(); 60 symmetricDistances = new DoubleMatrix(Locations, Locations);61 symmetricWeights = new DoubleMatrix(Equipments, Equipments);62 asymmetricDistances = new DoubleMatrix(Locations, Locations);63 asymmetricWeights = new DoubleMatrix(Equipments, Equipments);64 nonZeroDiagonalDistances = new DoubleMatrix(Locations, Locations);65 nonZeroDiagonalWeights = new DoubleMatrix(Equipments, Equipments);56 var symmetricDistances = new DoubleMatrix(Locations, Locations); 57 var symmetricWeights = new DoubleMatrix(Equipments, Equipments); 58 var asymmetricDistances = new DoubleMatrix(Locations, Locations); 59 var asymmetricWeights = new DoubleMatrix(Equipments, Equipments); 60 var nonZeroDiagonalDistances = new DoubleMatrix(Locations, Locations); 61 var nonZeroDiagonalWeights = new DoubleMatrix(Equipments, Equipments); 66 62 for (int i = 0; i < Equipments - 1; i++) { 67 63 for (int j = i + 1; j < Equipments; j++) { … … 86 82 nonZeroDiagonalDistances[i, i] = random.Next(Locations * 100); 87 83 } 88 installationCosts = new DoubleMatrix(Equipments, Locations);84 var installationCosts = new DoubleMatrix(Equipments, Locations); 89 85 for (int i = 0; i < Equipments; i++) { 90 86 for (int j = 0; j < Locations; j++) { … … 92 88 } 93 89 } 94 demands = new DoubleArray(Equipments);90 var demands = new DoubleArray(Equipments); 95 91 for (int i = 0; i < Equipments; i++) { 96 92 demands[i] = random.Next(1, 10); 97 93 } 98 capacities = new DoubleArray(Locations);94 var capacities = new DoubleArray(Locations); 99 95 for (int j = 0; j < Locations; j++) { 100 96 capacities[j] = random.Next(1, 10) * ((double)Equipments / (double)Locations) * 1.5; … … 107 103 nonZeroDiagonalWeights[index, index] = random.Next(1, Equipments * 100); 108 104 109 transportationCosts = random.NextDouble() * 10;110 overbookedCapacityPenalty = 1000 * random.NextDouble() + 100;105 var transportationCosts = random.NextDouble() * 10; 106 var overbookedCapacityPenalty = 1000 * random.NextDouble() + 100; 111 107 assignment = new IntegerVector(Equipments, random, 0, Locations); 108 109 symmetricInstance = new GQAPInstance() { 110 Capacities = capacities, 111 Demands = demands, 112 InstallationCosts = installationCosts, 113 PenaltyLevel = overbookedCapacityPenalty, 114 TransportationCosts = transportationCosts, 115 Weights = symmetricWeights, 116 Distances = symmetricDistances 117 }; 118 asymmetricInstance = new GQAPInstance() { 119 Capacities = capacities, 120 Demands = demands, 121 InstallationCosts = installationCosts, 122 PenaltyLevel = overbookedCapacityPenalty, 123 TransportationCosts = transportationCosts, 124 Weights = asymmetricWeights, 125 Distances = asymmetricDistances 126 }; 127 nonZeroDiagonalInstance = new GQAPInstance() { 128 Capacities = capacities, 129 Demands = demands, 130 InstallationCosts = installationCosts, 131 PenaltyLevel = overbookedCapacityPenalty, 132 TransportationCosts = transportationCosts, 133 Weights = nonZeroDiagonalWeights, 134 Distances = nonZeroDiagonalDistances 135 }; 112 136 } 113 137 #endregion … … 119 143 [TestMethod()] 120 144 public void EvaluateTest() { 121 var evaluator = new GQAPAdditivePenaltyEvaluator();122 145 for (int i = 0; i < 500; i++) { 123 NMove currentMove = StochasticNMoveSingleMoveGenerator.GenerateUpToN(random, assignment, 3, capacities);146 NMove currentMove = StochasticNMoveSingleMoveGenerator.GenerateUpToN(random, assignment, 3, symmetricInstance.Capacities); 124 147 IntegerVector prevAssignment = (IntegerVector)assignment.Clone(); 125 148 NMoveMaker.Apply(assignment, currentMove); 126 double before = evaluator.Evaluate(prevAssignment, symmetricWeights, symmetricDistances, installationCosts, demands, capacities, transportationCosts, 0); 127 double after = evaluator.Evaluate(assignment, symmetricWeights, symmetricDistances, installationCosts, demands, capacities, transportationCosts, 0); 128 double moveDiff = GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, symmetricWeights, symmetricDistances, installationCosts, demands, capacities, transportationCosts, 0, evaluator); 149 var beforeEval = symmetricInstance.Evaluate(prevAssignment); 150 double before = symmetricInstance.ToSingleObjective(beforeEval); 151 double after = Evaluate(symmetricInstance, assignment); 152 double moveDiff = symmetricInstance.ToSingleObjective( 153 GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, beforeEval, symmetricInstance) 154 ) - symmetricInstance.ToSingleObjective(beforeEval); 129 155 Assert.IsTrue(Math.Abs(moveDiff - (after - before)) < 1e-07, "Failed on symmetric matrices: " + Environment.NewLine 130 156 + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveDiff + "."); 131 157 132 before = evaluator.Evaluate(prevAssignment, asymmetricWeights, asymmetricDistances, installationCosts, demands, capacities, transportationCosts, 0); 133 after = evaluator.Evaluate(assignment, asymmetricWeights, asymmetricDistances, installationCosts, demands, capacities, transportationCosts, 0); 134 moveDiff = GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, asymmetricWeights, asymmetricDistances, installationCosts, demands, capacities, transportationCosts, 0, evaluator); 158 beforeEval = asymmetricInstance.Evaluate(prevAssignment); 159 before = asymmetricInstance.ToSingleObjective(beforeEval); 160 after = Evaluate(asymmetricInstance, assignment); 161 moveDiff = asymmetricInstance.ToSingleObjective( 162 GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, beforeEval, asymmetricInstance) 163 ) - asymmetricInstance.ToSingleObjective(beforeEval); 135 164 Assert.IsTrue(Math.Abs(moveDiff - (after - before)) < 1e-07, "Failed on asymmetric matrices: " + Environment.NewLine 136 165 + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveDiff + "."); 137 166 138 before = evaluator.Evaluate(prevAssignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances, installationCosts, demands, capacities, transportationCosts, 0); 139 after = evaluator.Evaluate(assignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances, installationCosts, demands, capacities, transportationCosts, 0); 140 moveDiff = GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances, installationCosts, demands, capacities, transportationCosts, 0, evaluator); 167 beforeEval = nonZeroDiagonalInstance.Evaluate(prevAssignment); 168 before = nonZeroDiagonalInstance.ToSingleObjective(beforeEval); 169 after = Evaluate(nonZeroDiagonalInstance, assignment); 170 moveDiff = nonZeroDiagonalInstance.ToSingleObjective( 171 GQAPNMoveEvaluator.Evaluate(currentMove, prevAssignment, beforeEval, nonZeroDiagonalInstance) 172 ) - nonZeroDiagonalInstance.ToSingleObjective(beforeEval); 141 173 Assert.IsTrue(Math.Abs(moveDiff - (after - before)) < 1e-07, "Failed on non-zero diagonal matrices: " + Environment.NewLine 142 174 + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveDiff + "."); 143 175 } 144 176 } 177 178 private double Evaluate(GQAPInstance instance, IntegerVector assignment) { 179 return instance.ToSingleObjective(instance.Evaluate(assignment)); 180 } 145 181 } 146 182 } -
branches/GeneralizedQAP/UnitTests/Properties/AssemblyInfo.cs
r7412 r15504 1 1 using System.Reflection; 2 using System.Runtime.CompilerServices;3 2 using System.Runtime.InteropServices; 4 3 … … 9 8 [assembly: AssemblyDescription("")] 10 9 [assembly: AssemblyConfiguration("")] 11 [assembly: AssemblyCompany(" Microsoft")]10 [assembly: AssemblyCompany("HEAL")] 12 11 [assembly: AssemblyProduct("UnitTests")] 13 [assembly: AssemblyCopyright(" Copyright © Microsoft 2012")]12 [assembly: AssemblyCopyright("(c) 2002-2017 HEAL")] 14 13 [assembly: AssemblyTrademark("")] 15 14 [assembly: AssemblyCulture("")]
Note: See TracChangeset
for help on using the changeset viewer.