Changeset 4752 for branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Manipulators/AlbaLambdaInterchangeManipulator.cs
- Timestamp:
- 11/09/10 09:55:31 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Manipulators/AlbaLambdaInterchangeManipulator.cs
r4365 r4752 27 27 using System; 28 28 using System.Collections.Generic; 29 using HeuristicLab.Common; 29 30 30 31 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba { … … 43 44 Parameters.Add(new ValueParameter<IntValue>("Lambda", "The lambda value.", new IntValue(1))); 44 45 } 46 47 public override IDeepCloneable Clone(Cloner cloner) { 48 return new AlbaLambdaInterchangeManipulator(this, cloner); 49 } 50 51 private AlbaLambdaInterchangeManipulator(AlbaLambdaInterchangeManipulator original, Cloner cloner) 52 : base(original, cloner) { 53 } 45 54 46 55 public static void Apply(AlbaEncoding individual, int tour1Index, int position1, int length1, … … 100 109 protected override void Manipulate(IRandom rand, AlbaEncoding individual) { 101 110 List<Tour> tours = individual.GetTours(); 102 int lambda = LambdaParameter.Value.Value; 111 if (tours.Count > 1) { 112 int lambda = LambdaParameter.Value.Value; 103 113 104 int route1Index = rand.Next(tours.Count);105 Tour route1 = tours[route1Index];114 int route1Index = rand.Next(tours.Count); 115 Tour route1 = tours[route1Index]; 106 116 107 int route2Index = rand.Next(tours.Count - 1);108 if (route2Index >= route1Index)109 route2Index += 1;110 Tour route2 = tours[route2Index];111 117 112 int length1 = rand.Next(Math.Min(lambda + 1, route1.Stops.Count + 1)); 113 int index1 = rand.Next(route1.Stops.Count - length1 + 1); 118 int route2Index = rand.Next(tours.Count - 1); 119 if (route2Index >= route1Index) 120 route2Index += 1; 121 Tour route2 = tours[route2Index]; 114 122 115 int l2Min = 0; 116 if (length1 == 0) 117 l2Min = 1; 118 int length2 = rand.Next(l2Min, Math.Min(lambda + 1, route2.Stops.Count + 1)); 119 int index2 = rand.Next(route2.Stops.Count - length2 + 1); 123 int length1 = rand.Next(Math.Min(lambda + 1, route1.Stops.Count + 1)); 124 int index1 = rand.Next(route1.Stops.Count - length1 + 1); 120 125 121 Apply(individual, route1Index, index1, length1, 122 route2Index, index2, length2); 126 int l2Min = 0; 127 if (length1 == 0) 128 l2Min = 1; 129 int length2 = rand.Next(l2Min, Math.Min(lambda + 1, route2.Stops.Count + 1)); 130 int index2 = rand.Next(route2.Stops.Count - length2 + 1); 131 132 Apply(individual, route1Index, index1, length1, 133 route2Index, index2, length2); 134 } 123 135 } 124 136 }
Note: See TracChangeset
for help on using the changeset viewer.