- Timestamp:
- 09/29/11 15:51:56 (13 years ago)
- Location:
- branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/AlbaEncoding.cs
r6710 r6851 33 33 [Item("AlbaEncoding", "Represents an Alba encoding of VRP solutions. It is implemented as described in Alba, E. and Dorronsoro, B. (2004). Solving the Vehicle Routing Problem by Using Cellular Genetic Algorithms.")] 34 34 [StorableClass] 35 public class AlbaEncoding : PermutationEncoding , IHeterogenousCapacitatedEncoding{35 public class AlbaEncoding : PermutationEncoding { 36 36 #region IVRPEncoding Members 37 37 public override List<Tour> GetTours() { 38 Repair(); 38 39 List<Tour> result = new List<Tour>(); 39 40 … … 55 56 if (tour.Stops.Count > 0) { 56 57 result.Add(tour); 57 } 58 } 58 59 59 60 return result; 60 61 } 61 #endregion62 62 63 #region IHeterogenousCapacitatedEncoding Members 64 65 public int GetVehicleAssignment(int tour) { 63 public override int GetVehicleAssignment(int tour) { 66 64 int vehicleAssignment = -1; 67 65 Tour currentTour = GetTours()[tour]; … … 72 70 int lastStopIndex = this.IndexOf(lastStop); 73 71 74 if (lastStopIndex == this.Length - 1) 75 vehicleAssignment = this.ProblemInstance.Vehicles.Value - 1; 72 if (lastStopIndex == this.Length - 1) { 73 int i = this.Length - 1; 74 75 while (vehicleAssignment == -1) { 76 if (this.array[i] >= ProblemInstance.Cities.Value) { 77 vehicleAssignment = this.array[i] - ProblemInstance.Cities.Value; 78 } 79 80 i--; 81 } 82 } 76 83 else 77 84 vehicleAssignment = this[lastStopIndex + 1] - this.ProblemInstance.Cities.Value; … … 80 87 } 81 88 #endregion 89 90 public void Repair() { 91 int cities = ProblemInstance.Cities.Value; 92 93 if (this[this.Length - 1] < cities) { 94 int index = this.Length - 2; 95 while (this[index] < cities) { 96 index--; 97 } 98 99 int vehicle = this[index]; 100 for (int i = index; i < this.Length - 1; i++) 101 this[i] = this[i + 1]; 102 this[Length - 1] = vehicle; 103 } 104 } 82 105 83 106 public AlbaEncoding(Permutation permutation, IVRPProblemInstance instance) … … 100 123 public static AlbaEncoding ConvertFrom(List<int> routeParam, IVRPProblemInstance instance) { 101 124 List<int> route = new List<int>(routeParam); 102 route.RemoveAt(routeParam.Count - 1);103 125 104 126 int cities = instance.Cities.Value; … … 129 151 int emptyVehicles = instance.Vehicles.Value - tours.Count; 130 152 131 int[] array = new int[cities + tours.Count + emptyVehicles - 1];153 int[] array = new int[cities + tours.Count + emptyVehicles]; 132 154 int delimiter = 0; 133 155 int arrayIndex = 0; … … 140 162 141 163 if (arrayIndex != array.Length) { 142 if (encoding is IHeterogenousCapacitatedEncoding) { 143 array[arrayIndex] = cities + (encoding as IHeterogenousCapacitatedEncoding).GetVehicleAssignment(delimiter); 144 } else { 145 array[arrayIndex] = cities + delimiter; 146 } 164 array[arrayIndex] = cities + encoding.GetVehicleAssignment(delimiter); 147 165 148 166 delimiter++; … … 151 169 } 152 170 153 for (int i = 0; i < emptyVehicles - 1; i++) { 154 if (encoding is IHeterogenousCapacitatedEncoding) { 155 array[arrayIndex] = cities + (encoding as IHeterogenousCapacitatedEncoding).GetVehicleAssignment(delimiter); 156 } else { 157 array[arrayIndex] = cities + delimiter; 158 } 171 for (int i = 0; i < emptyVehicles; i++) { 172 array[arrayIndex] = cities + encoding.GetVehicleAssignment(delimiter); 159 173 160 174 delimiter++; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Creators/AlbaCreator.cs
r4752 r6851 47 47 : base(original, cloner) { 48 48 } 49 50 public override IOperation Apply() { 51 (VRPToursParameter.ActualValue as AlbaEncoding).Repair(); 52 53 return base.Apply(); 54 } 49 55 } 50 56 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Crossovers/AlbaCrossover.cs
r4752 r6851 67 67 68 68 ChildParameter.ActualValue = 69 Crossover(RandomParameter.ActualValue, parents[0] as AlbaEncoding, parents[1] as AlbaEncoding); 69 Crossover(RandomParameter.ActualValue, parents[0] as AlbaEncoding, parents[1] as AlbaEncoding); 70 (ChildParameter.ActualValue as AlbaEncoding).Repair(); 70 71 71 72 return base.Apply(); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/IAlbaOperator.cs
r4369 r6851 32 32 33 33 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba { 34 public interface IAlbaOperator: 35 ISingleDepotOperator, IHeterogenousCapacitatedOperator, I TimeWindowedOperator {34 public interface IAlbaOperator: 35 ISingleDepotOperator, IHeterogenousCapacitatedOperator, IMultiDepotOperator, ITimeWindowedOperator { 36 36 } 37 37 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Manipulators/AlbaManipulator.cs
r4752 r6851 71 71 72 72 Manipulate(RandomParameter.ActualValue, VRPToursParameter.ActualValue as AlbaEncoding); 73 (VRPToursParameter.ActualValue as AlbaEncoding).Repair(); 73 74 74 75 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.