Changeset 8894 for trunk/sources
- Timestamp:
- 11/12/12 13:32:46 (12 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/HeuristicLab.Problems.VehicleRouting-3.4.csproj
r8649 r8894 141 141 <Compile Include="Encodings\Potvin\Moves\TwoOptStar\PotvinTwoOptStarSingleMoveGenerator.cs" /> 142 142 <Compile Include="Improver\VRPImprovementOperator.cs" /> 143 <Compile Include="Improver\VRPIntraRouteImprovementOperator.cs" /> 143 144 <Compile Include="Interfaces\IVRPLocalSearchManipulator.cs" /> 144 145 <Compile Include="Interpreters\MDCVRPInterpreter.cs" /> … … 474 475 --> 475 476 <PropertyGroup> 476 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)477 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir) 477 478 set ProjectDir=$(ProjectDir) 478 479 set SolutionDir=$(SolutionDir) … … 480 481 481 482 call PreBuildEvent.cmd</PreBuildEvent> 482 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">483 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' "> 483 484 export ProjectDir=$(ProjectDir) 484 485 export SolutionDir=$(SolutionDir) -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Improver/VRPImprovementOperator.cs
r8346 r8894 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 29 using HeuristicLab.Problems.VehicleRouting.Encodings; 30 using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;31 30 using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin; 32 31 using HeuristicLab.Problems.VehicleRouting.Interfaces; … … 35 34 namespace HeuristicLab.Problems.VehicleRouting { 36 35 /// <summary> 37 /// A n operator that improves vehicle routingsolutions.36 /// A base class for operators which improve VRP solutions. 38 37 /// </summary> 39 [Item("VRPImprovementOperator", "A n operator that improves vehicle routingsolutions.")]38 [Item("VRPImprovementOperator", "A base class for operators which improve VRP solutions.")] 40 39 [StorableClass] 41 public sealedclass VRPImprovementOperator : VRPOperator, IGeneralVRPOperator, ISingleObjectiveImprovementOperator {40 public abstract class VRPImprovementOperator : VRPOperator, IGeneralVRPOperator, ISingleObjectiveImprovementOperator { 42 41 #region Parameter properties 43 42 public ScopeParameter CurrentScopeParameter { … … 47 46 get { return (IValueParameter<IntValue>)Parameters["ImprovementAttempts"]; } 48 47 } 49 public IValue Parameter<IntValue> LambdaParameter{50 get { return (IValue Parameter<IntValue>)Parameters["Lambda"]; }48 public IValueLookupParameter<IntValue> LocalEvaluatedSolutions { 49 get { return (IValueLookupParameter<IntValue>)Parameters["LocalEvaluatedSolutions"]; } 51 50 } 52 51 public ILookupParameter<IRandom> RandomParameter { … … 62 61 63 62 [StorableConstructor] 64 pr ivateVRPImprovementOperator(bool deserializing) : base(deserializing) { }65 pr ivateVRPImprovementOperator(VRPImprovementOperator original, Cloner cloner) : base(original, cloner) { }66 p ublicVRPImprovementOperator()63 protected VRPImprovementOperator(bool deserializing) : base(deserializing) { } 64 protected VRPImprovementOperator(VRPImprovementOperator original, Cloner cloner) : base(original, cloner) { } 65 protected VRPImprovementOperator() 67 66 : base() { 68 67 #region Create parameters 69 68 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the solution to be improved.")); 70 69 Parameters.Add(new ValueParameter<IntValue>("ImprovementAttempts", "The number of improvement attempts the operator should perform.", new IntValue(100))); 71 Parameters.Add(new Value Parameter<IntValue>("Lambda", "The number of neighbors that should be exchanged.", new IntValue(1)));70 Parameters.Add(new ValueLookupParameter<IntValue>("LocalEvaluatedSolutions", "The number of evaluated solutions.")); 72 71 Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator.")); 73 Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The number of moves that should be executed.", new IntValue( 100)));72 Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The number of moves that should be executed.", new IntValue(25))); 74 73 Parameters.Add(new ValueLookupParameter<IItem>("Solution", "The solution to be improved. This parameter is used for name translation only.")); 75 74 #endregion 76 75 } 77 76 78 public override IDeepCloneable Clone(Cloner cloner) {79 return new VRPImprovementOperator(this, cloner);80 }81 82 77 public override IOperation Apply() { 83 AlbaEncoding solution = SolutionParameter.ActualValue is AlbaEncoding 84 ? SolutionParameter.ActualValue as AlbaEncoding 85 : AlbaEncoding.ConvertFrom(SolutionParameter.ActualValue as IVRPEncoding, ProblemInstance); 78 var solution = SolutionParameter.ActualValue as IVRPEncoding; 79 var potvinSolution = solution is PotvinEncoding ? solution as PotvinEncoding : PotvinEncoding.ConvertFrom(solution, ProblemInstance); 86 80 87 81 if (solution == null) 88 82 throw new ArgumentException("Cannot improve solution because it has the wrong type."); 89 83 90 double quality = -1; 91 int evaluatedSolutions; 84 int evaluatedSolutions = Improve(potvinSolution); 92 85 93 AlbaLambdaInterchangeLocalImprovementOperator.Apply(solution, ImprovementAttemptsParameter.Value.Value, 94 LambdaParameter.Value.Value, SampleSizeParameter.Value.Value, 95 RandomParameter.ActualValue, ProblemInstance, ref quality, 96 out evaluatedSolutions); 97 98 SolutionParameter.ActualValue = PotvinEncoding.ConvertFrom(solution, ProblemInstance); 99 CurrentScopeParameter.ActualValue.Variables.Add(new Variable("LocalEvaluatedSolutions", new IntValue(evaluatedSolutions))); 86 SolutionParameter.ActualValue = solution; 87 LocalEvaluatedSolutions.ActualValue = new IntValue(evaluatedSolutions); 100 88 101 89 return base.Apply(); 102 90 } 91 92 protected abstract int Improve(PotvinEncoding solution); 103 93 } 104 94 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/PathRelinkers/VRPPathRelinker.cs
r8346 r8894 37 37 namespace HeuristicLab.Problems.VehicleRouting { 38 38 /// <summary> 39 /// An operator that relinks paths between vehicle routingsolutions.39 /// An operator which relinks paths between VRP solutions. 40 40 /// </summary> 41 [Item("VRPPathRelinker", "An operator that relinks paths between vehicle routingsolutions.")]41 [Item("VRPPathRelinker", "An operator which relinks paths between VRP solutions.")] 42 42 [StorableClass] 43 43 public sealed class VRPPathRelinker : SingleObjectivePathRelinker, IGeneralVRPOperator, IStochasticOperator { 44 44 #region Parameter properties 45 public IValueParameter<IntValue> IterationsParameter { 46 get { return (IValueParameter<IntValue>)Parameters["Iterations"]; } 47 } 48 public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter { 49 get { return (ILookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; } 50 } 45 51 public ILookupParameter<IRandom> RandomParameter { 46 52 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 47 53 } 48 public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {49 get { return (ILookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }50 }51 54 public IValueParameter<IntValue> SampleSizeParameter { 52 55 get { return (IValueParameter<IntValue>)Parameters["SampleSize"]; } 53 }54 public IValueParameter<IntValue> IterationsParameter {55 get { return (IValueParameter<IntValue>)Parameters["Iterations"]; }56 56 } 57 57 #endregion … … 62 62 public VRPPathRelinker() 63 63 : base() { 64 Parameters.Add(new ValueParameter<IntValue>("Iterations", "The number of iterations the operator should perform.", new IntValue(50))); 65 Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance")); 64 66 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 65 Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance"));66 67 Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The number of moves that should be executed.", new IntValue(10))); 67 Parameters.Add(new ValueParameter<IntValue>("Iterations", "The number of iterations the operator should perform.", new IntValue(50)));68 68 } 69 69 … … 72 72 } 73 73 74 public static ItemArray<IItem> Apply(PotvinEncoding initiator, PotvinEncoding guide, PercentValue n, int sampleSize, int iterations, IRandom rand, IVRPProblemInstance problemInstance) { 75 if (initiator == null || guide == null) 76 throw new ArgumentException("Cannot relink path because one of the provided solutions or both are null."); 77 78 double sigma = 1.5; 79 double minPenalty = 0.001; 80 double maxPenalty = 1000000000; 81 82 var originalOverloadPenalty = new DoubleValue(); 83 if (problemInstance is IHomogenousCapacitatedProblemInstance) 84 originalOverloadPenalty.Value = (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value; 85 var originalTardinessPenalty = new DoubleValue(); 86 if (problemInstance is ITimeWindowedProblemInstance) 87 originalTardinessPenalty.Value = (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value; 88 89 PotvinEncoding current = MatchTours(initiator, guide, problemInstance); 90 double currentSimilarity = VRPSimilarityCalculator.CalculateSimilarity(current, guide); 91 92 IList<PotvinEncoding> solutions = new List<PotvinEncoding>(); 93 int i = 0; 94 while (i < iterations && !currentSimilarity.IsAlmost(1.0)) { 95 var currentEval = problemInstance.Evaluate(current); 96 currentSimilarity = VRPSimilarityCalculator.CalculateSimilarity(current, guide); 97 98 if (currentSimilarity < 1.0) { 99 for (int sample = 0; sample < sampleSize; sample++) { 100 var next = current.Clone() as PotvinEncoding; 101 102 int neighborhood = rand.Next(3); 103 switch (neighborhood) { 104 case 0: next = RouteBasedXOver(next, guide, rand, 105 problemInstance); 106 break; 107 case 1: next = SequenceBasedXOver(next, guide, rand, 108 problemInstance); 109 break; 110 case 2: GuidedRelocateMove(next, guide, rand); 111 break; 112 } 113 114 next = MatchTours(next, guide, problemInstance); 115 116 var nextEval = problemInstance.Evaluate(next); 117 if ((nextEval.Quality < currentEval.Quality)) { 118 current = next; 119 solutions.Add(current); 120 break; 121 } 122 } 123 124 if (problemInstance is IHomogenousCapacitatedProblemInstance) { 125 if (((CVRPEvaluation)currentEval).Overload > 0) { 126 (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value = 127 Math.Min(maxPenalty, 128 (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value * sigma); 129 } else { 130 (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value = 131 Math.Max(minPenalty, 132 (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value * sigma); 133 } 134 } 135 136 137 if (problemInstance is ITimeWindowedProblemInstance) { 138 if (((CVRPTWEvaluation)currentEval).Tardiness > 0) { 139 (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value = 140 Math.Min(maxPenalty, 141 (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value * sigma); 142 } else { 143 (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value = 144 Math.Max(minPenalty, 145 (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value / sigma); 146 } 147 } 148 149 i++; 150 } 151 } 152 153 if (problemInstance is IHomogenousCapacitatedProblemInstance) 154 (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value = originalOverloadPenalty.Value; 155 if (problemInstance is ITimeWindowedProblemInstance) 156 (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value = originalTardinessPenalty.Value; 157 158 return new ItemArray<IItem>(ChooseSelection(solutions, n)); 159 } 160 161 private static IList<IItem> ChooseSelection(IList<PotvinEncoding> solutions, PercentValue n) { 162 IList<IItem> selection = new List<IItem>(); 163 if (solutions.Count > 0) { 164 int noSol = (int)(solutions.Count * n.Value); 165 if (noSol <= 0) noSol++; 166 double stepSize = (double)solutions.Count / (double)noSol; 167 for (int i = 0; i < noSol; i++) 168 selection.Add(solutions.ElementAt((int)((i + 1) * stepSize - stepSize * 0.5))); 169 } 170 171 return selection; 172 } 173 174 protected override ItemArray<IItem> Relink(ItemArray<IItem> parents, PercentValue n) { 175 if (parents.Length != 2) 176 throw new ArgumentException("The number of parents is not equal to 2."); 177 178 if (!(parents[0] is PotvinEncoding)) 179 parents[0] = PotvinEncoding.ConvertFrom(parents[0] as IVRPEncoding, ProblemInstanceParameter.ActualValue); 180 if (!(parents[1] is PotvinEncoding)) 181 parents[1] = PotvinEncoding.ConvertFrom(parents[1] as IVRPEncoding, ProblemInstanceParameter.ActualValue); 182 183 return Apply(parents[0] as PotvinEncoding, parents[1] as PotvinEncoding, n, 184 SampleSizeParameter.Value.Value, IterationsParameter.Value.Value, RandomParameter.ActualValue, ProblemInstanceParameter.ActualValue); 185 } 186 74 187 private static int MatchingCities(Tour tour1, Tour tour2) { 75 188 return tour1.Stops.Intersect(tour2.Stops).Count(); … … 77 190 78 191 private static PotvinEncoding MatchTours(PotvinEncoding initiator, PotvinEncoding guide, IVRPProblemInstance problemInstance) { 79 PotvinEncodingresult = new PotvinEncoding(problemInstance);80 81 List<bool>used = new List<bool>();192 var result = new PotvinEncoding(problemInstance); 193 194 var used = new List<bool>(); 82 195 for (int i = 0; i < initiator.Tours.Count; i++) { 83 196 used.Add(false); … … 120 233 return PotvinSequenceBasedCrossover.Apply(random, initiator, guide, problemInstance, false); 121 234 } 122 123 235 124 236 public static void GuidedRelocateMove(PotvinEncoding initiator, PotvinEncoding guide, IRandom random) { … … 208 320 individual.Tours.RemoveAll(t => t.Stops.Count == 0); 209 321 } 210 211 public static void ExchangeMove(PotvinEncoding individual, IRandom random) {212 if (individual.Tours.Count > 1) {213 int tour1Idx = random.Next(individual.Tours.Count);214 int tour2Idx = random.Next(individual.Tours.Count - 1);215 if (tour2Idx >= tour1Idx)216 tour2Idx++;217 218 Tour tour1 = individual.Tours[tour1Idx];219 Tour tour2 = individual.Tours[tour2Idx];220 221 int index1 = random.Next(tour1.Stops.Count);222 int city1 = tour1.Stops[index1];223 224 int index2 = random.Next(tour2.Stops.Count);225 int city2 = tour2.Stops[index2];226 227 tour1.Stops.RemoveAt(index1);228 tour1.Stops.Insert(index1, city2);229 230 tour2.Stops.RemoveAt(index2);231 tour2.Stops.Insert(index2, city1);232 }233 }234 235 public static void TwoOptMove(PotvinEncoding individual, IRandom random) {236 List<Tour> tours = individual.Tours.FindAll(t => t.Stops.Count >= 4);237 238 if (tours.Count > 0) {239 int tourIdx = random.Next(tours.Count);240 Tour tour = tours[tourIdx];241 242 int a;243 if (tour.Stops.Count == 4) {244 a = 0;245 } else if (tour.Stops.Count == 5) {246 int idx = random.Next(4);247 if (idx >= 2)248 idx++;249 a = idx;250 } else {251 a = random.Next(tour.Stops.Count);252 }253 254 int b;255 List<int> indices = new List<int>();256 for (int i = 0; i < tour.Stops.Count; i++) {257 if (Math.Abs(i - a) > 2) {258 indices.Add(i);259 }260 }261 b = indices[random.Next(indices.Count)];262 263 if (b < a) {264 int tmp = a;265 a = b;266 b = tmp;267 }268 269 int index = a + 1;270 int count = b - a - 1;271 List<int> segment = tour.Stops.GetRange(index, count);272 tour.Stops.RemoveRange(index, count);273 segment.Reverse();274 tour.Stops.InsertRange(index, segment);275 }276 }277 278 public static void TwoOptStarMove(PotvinEncoding individual, IRandom random) {279 //consider creating new tour280 individual.Tours.Add(new Tour());281 282 int route1Idx = random.Next(individual.Tours.Count);283 int route2Idx = random.Next(individual.Tours.Count - 1);284 if (route2Idx >= route1Idx)285 route2Idx++;286 287 Tour route1 = individual.Tours[route1Idx];288 Tour route2 = individual.Tours[route2Idx];289 290 int x1 = random.Next(route1.Stops.Count + 1);291 int x2 = random.Next(route2.Stops.Count + 1);292 293 int count = route1.Stops.Count - x1;294 List<int> segmentX1 = new List<int>();295 if (count > 0) {296 segmentX1 = route1.Stops.GetRange(x1, count);297 route1.Stops.RemoveRange(x1, count);298 }299 300 count = route2.Stops.Count - x2;301 List<int> segmentX2 = new List<int>();302 if (count > 0) {303 segmentX2 = route2.Stops.GetRange(x2, count);304 route2.Stops.RemoveRange(x2, count);305 }306 307 route1.Stops.AddRange(segmentX2);308 route2.Stops.AddRange(segmentX1);309 310 individual.Tours.RemoveAll(t => t.Stops.Count == 0);311 }312 313 public static void OrOptMove(PotvinEncoding individual, IRandom random) {314 List<Tour> tours = individual.Tours.FindAll(t => t.Stops.Count >= 2);315 316 if (tours.Count > 0) {317 int tourIdx = random.Next(tours.Count);318 Tour tour = tours[tourIdx];319 320 int segmentStart = random.Next(tour.Stops.Count);321 int segmentLength;322 if (segmentStart == 0) {323 segmentLength = 1 + random.Next(tour.Stops.Count - 1);324 } else {325 segmentLength = 1 + random.Next(tour.Stops.Count - segmentStart);326 }327 328 List<int> segment = tour.Stops.GetRange(segmentStart, segmentLength);329 tour.Stops.RemoveRange(segmentStart, segmentLength);330 int newPos;331 if (tour.Stops.Count == 1)332 newPos = 0;333 else334 newPos = random.Next(tour.Stops.Count - 1);335 336 if (newPos >= segmentStart)337 newPos++;338 tour.Stops.InsertRange(newPos, segment);339 }340 }341 322 #endregion 342 343 private static IList<IItem> ChooseSelection(IList<PotvinEncoding> solutions, PercentValue n) {344 IList<IItem> selection = new List<IItem>();345 if (solutions.Count > 0) {346 int noSol = (int)(solutions.Count * n.Value);347 if (noSol <= 0) noSol++;348 double stepSize = (double)solutions.Count / (double)noSol;349 for (int i = 0; i < noSol; i++)350 selection.Add(solutions.ElementAt((int)((i + 1) * stepSize - stepSize * 0.5)));351 }352 353 return selection;354 }355 356 public static ItemArray<IItem> Apply(PotvinEncoding initiator, PotvinEncoding guide, PercentValue n, int sampleSize, int iterations, IRandom rand, IVRPProblemInstance problemInstance) {357 358 if (initiator == null || guide == null)359 throw new ArgumentException("Cannot relink path because one of the provided solutions or both are null.");360 361 double sigma = 1.5;362 363 DoubleValue originalOverloadPenalty = new DoubleValue();364 if (problemInstance is IHomogenousCapacitatedProblemInstance)365 originalOverloadPenalty.Value = (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value;366 DoubleValue originalTardinessPenalty = new DoubleValue();367 if (problemInstance is ITimeWindowedProblemInstance)368 originalTardinessPenalty.Value = (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value;369 370 PotvinEncoding current = MatchTours(initiator, guide, problemInstance);371 double currentSimilarity = VRPSimilarityCalculator.CalculateSimilarity(current, guide);372 373 IList<PotvinEncoding> solutions = new List<PotvinEncoding>();374 int i = 0;375 while (i < iterations && currentSimilarity != 1.0) {376 VRPEvaluation currentEval = problemInstance.Evaluate(current);377 currentSimilarity = VRPSimilarityCalculator.CalculateSimilarity(current, guide);378 379 if (currentSimilarity < 1.0) {380 for (int sample = 0; sample < sampleSize; sample++) {381 PotvinEncoding next = current.Clone() as PotvinEncoding;382 383 int neighborhood = rand.Next(4);384 switch (neighborhood) {385 case 0: next = RouteBasedXOver(next, guide, rand,386 problemInstance);387 break;388 case 1: next = SequenceBasedXOver(next, guide, rand,389 problemInstance);390 break;391 case 2: TwoOptMove(next, rand);392 break;393 case 3: GuidedRelocateMove(next, guide, rand);394 break;395 }396 397 next = MatchTours(next, guide, problemInstance);398 399 VRPEvaluation nextEval = problemInstance.Evaluate(next);400 double nextSimilarity = VRPSimilarityCalculator.CalculateSimilarity(next, guide);401 402 if (nextSimilarity > currentSimilarity && nextEval.Quality <= currentEval.Quality) {403 current = next;404 solutions.Add(current);405 break;406 }407 }408 409 if (problemInstance is IHomogenousCapacitatedProblemInstance) {410 if (((CVRPEvaluation)currentEval).Overload > 0)411 (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value *= sigma;412 else413 (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value /= sigma;414 }415 416 417 if (problemInstance is ITimeWindowedProblemInstance) {418 if (((CVRPTWEvaluation)currentEval).Tardiness > 0)419 (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value *= sigma;420 else421 (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value /= sigma;422 }423 424 i++;425 }426 }427 428 if (problemInstance is IHomogenousCapacitatedProblemInstance)429 (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value = originalOverloadPenalty.Value;430 if (problemInstance is ITimeWindowedProblemInstance)431 (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value = originalTardinessPenalty.Value;432 433 return new ItemArray<IItem>(ChooseSelection(solutions, n));434 }435 436 protected override ItemArray<IItem> Relink(ItemArray<IItem> parents, PercentValue n) {437 if (parents.Length != 2)438 throw new ArgumentException("The number of parents is not equal to 2.");439 440 if (!(parents[0] is PotvinEncoding))441 parents[0] = PotvinEncoding.ConvertFrom(parents[0] as IVRPEncoding, ProblemInstanceParameter.ActualValue);442 if (!(parents[1] is PotvinEncoding))443 parents[1] = PotvinEncoding.ConvertFrom(parents[1] as IVRPEncoding, ProblemInstanceParameter.ActualValue);444 445 return Apply(parents[0] as PotvinEncoding, parents[1] as PotvinEncoding, n,446 SampleSizeParameter.Value.Value, IterationsParameter.Value.Value, RandomParameter.ActualValue, ProblemInstanceParameter.ActualValue);447 }448 323 } 449 324 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/SimilarityCalculators/VRPSimilarityCalculator.cs
r8720 r8894 32 32 namespace HeuristicLab.Problems.VehicleRouting { 33 33 /// <summary> 34 /// An operator that performs similarity calculation between two vehicle routingsolutions.34 /// An operator which performs similarity calculation between two VRP solutions. 35 35 /// </summary> 36 36 /// <remarks> 37 37 /// The operator calculates the similarity based on the number of edges the two solutions have in common. 38 38 /// </remarks> 39 [Item("VRPSimilarityCalculator", "An operator that performs similarity calculation between two vehicle routingsolutions.")]39 [Item("VRPSimilarityCalculator", "An operator which performs similarity calculation between two VRP solutions.")] 40 40 [StorableClass] 41 41 public sealed class VRPSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { -
trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/SamplesTest.cs
r8891 r8894 968 968 ss.SetSeedRandomly.Value = false; 969 969 RunAlgorithm(ss); 970 Assert.AreEqual( 749, GetDoubleResult(ss, "BestQuality"));971 Assert.AreEqual( 766.95, GetDoubleResult(ss, "CurrentAverageQuality"));972 Assert.AreEqual( 789, GetDoubleResult(ss, "CurrentWorstQuality"));973 Assert.AreEqual(2 7400, GetIntResult(ss, "EvaluatedSolutions"));970 Assert.AreEqual(828.93686694283383, GetDoubleResult(ss, "BestQuality")); 971 Assert.AreEqual(868.63623986983077, GetDoubleResult(ss, "CurrentAverageQuality")); 972 Assert.AreEqual(1048.8333559209832, GetDoubleResult(ss, "CurrentWorstQuality")); 973 Assert.AreEqual(262622, GetIntResult(ss, "EvaluatedSolutions")); 974 974 } 975 975 976 976 private ScatterSearch CreateScatterSearchVRPSample() { 977 977 #region Problem Configuration 978 var provider = new AugeratInstanceProvider();979 var instance = provider.GetDataDescriptors(). Where(x => x.Name == "A-n38-k5").Single();978 var provider = new SolomonInstanceProvider(); 979 var instance = provider.GetDataDescriptors().Single(x => x.Name == "C101"); 980 980 VehicleRoutingProblem vrpProblem = new VehicleRoutingProblem(); 981 981 vrpProblem.Load(provider.LoadData(instance)); … … 986 986 ss.Engine = new SequentialEngine(); 987 987 ss.Name = "Scatter Search - VRP"; 988 ss.Description = "A Scatter Search algorithm which solves the \"A-n38-k5\" vehicle routing problem (imported from Augerat)";988 ss.Description = "A scatter search algorithm which solves the \"C101\" vehicle routing problem (imported from Solomon)"; 989 989 ss.Problem = vrpProblem; 990 990 991 var improver = ss.Problem.Operators.OfType<VRPI mprovementOperator>().First();992 improver.ImprovementAttemptsParameter.Value.Value = 5;993 improver.SampleSizeParameter.Value.Value = 5;991 var improver = ss.Problem.Operators.OfType<VRPIntraRouteImprovementOperator>().First(); 992 improver.ImprovementAttemptsParameter.Value.Value = 15; 993 improver.SampleSizeParameter.Value.Value = 10; 994 994 ss.Improver = improver; 995 995 996 996 var pathRelinker = ss.Problem.Operators.OfType<VRPPathRelinker>().First(); 997 pathRelinker.IterationsParameter.Value.Value = 15;997 pathRelinker.IterationsParameter.Value.Value = 25; 998 998 ss.PathRelinker = pathRelinker; 999 999 1000 var qualitySimCalc = ss.SimilarityCalculatorParameter.ValidValues.OfType<QualitySimilarityCalculator>().First(); 1001 ss.SimilarityCalculator = qualitySimCalc; 1002 1003 ss.MaximumIterations.Value = 5; 1000 var similarityCalculator = ss.SimilarityCalculatorParameter.ValidValues.OfType<VRPSimilarityCalculator>().First(); 1001 ss.SimilarityCalculator = similarityCalculator; 1002 1003 ss.MaximumIterations.Value = 2; 1004 ss.PopulationSize.Value = 20; 1005 ss.ReferenceSetSize.Value = 10; 1004 1006 ss.Seed.Value = 0; 1005 1007 return ss;
Note: See TracChangeset
for help on using the changeset viewer.