- Timestamp:
- 09/09/10 16:24:09 (14 years ago)
- Location:
- branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings
- Files:
-
- 12 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/AlbaEncoding.cs
r4365 r4376 28 28 using HeuristicLab.Problems.VehicleRouting.Encodings.General; 29 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; 30 using HeuristicLab.Problems.VehicleRouting.Variants; 30 31 31 32 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba { 32 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.")] 33 34 [StorableClass] 34 public class AlbaEncoding : PermutationEncoding {35 public class AlbaEncoding : PermutationEncoding, ISingleDepotEncoding, ITimeWindowedEncoding, IHeterogenousCapacitatedEncoding { 35 36 #region IVRPEncoding Members 36 37 public override List<Tour> GetTours() { … … 60 61 #endregion 61 62 63 #region IHeterogenousCapacitatedEncoding Members 64 65 public int GetVehicleAssignment(int tour) { 66 int vehicleAssignment = -1; 67 Tour currentTour = GetTours()[tour]; 68 69 int lastStop = currentTour.Stops[ 70 currentTour.Stops.Count - 1] - 1; 71 72 int lastStopIndex = this.IndexOf(lastStop); 73 74 if (lastStopIndex == this.Length - 1) 75 vehicleAssignment = this.ProblemInstance.Vehicles.Value - 1; 76 else 77 vehicleAssignment = this[lastStopIndex + 1] - this.ProblemInstance.Cities.Value; 78 79 return vehicleAssignment; 80 } 81 #endregion 82 62 83 public override IDeepCloneable Clone(HeuristicLab.Common.Cloner cloner) { 63 84 AlbaEncoding clone = new AlbaEncoding( 64 new Permutation(this.PermutationType, this.array), 65 (IVRPProblemInstance)cloner.Clone(ProblemInstance)); 85 new Permutation(this.PermutationType, this.array), ProblemInstance); 66 86 cloner.RegisterClonedObject(this, clone); 67 87 clone.readOnly = readOnly; … … 103 123 instance); 104 124 } 125 126 public static AlbaEncoding ConvertFrom(IVRPEncoding encoding, IVRPProblemInstance instance) { 127 List<Tour> tours = encoding.GetTours(); 128 129 int cities = 0; 130 foreach (Tour tour in tours) { 131 cities += tour.Stops.Count; 132 } 133 134 int emptyVehicles = instance.Vehicles.Value - tours.Count; 135 136 int[] array = new int[cities + tours.Count + emptyVehicles - 1]; 137 int delimiter = 0; 138 int arrayIndex = 0; 139 140 foreach (Tour tour in tours) { 141 foreach (int city in tour.Stops) { 142 array[arrayIndex] = city - 1; 143 arrayIndex++; 144 } 145 146 if (arrayIndex != array.Length) { 147 if (encoding is IHeterogenousCapacitatedEncoding) { 148 array[arrayIndex] = cities + (encoding as IHeterogenousCapacitatedEncoding).GetVehicleAssignment(delimiter); 149 } else { 150 array[arrayIndex] = cities + delimiter; 151 } 152 153 delimiter++; 154 arrayIndex++; 155 } 156 } 157 158 for (int i = 0; i < emptyVehicles - 1; i++) { 159 if (encoding is IHeterogenousCapacitatedEncoding) { 160 array[arrayIndex] = cities + (encoding as IHeterogenousCapacitatedEncoding).GetVehicleAssignment(delimiter); 161 } else { 162 array[arrayIndex] = cities + delimiter; 163 } 164 165 delimiter++; 166 arrayIndex++; 167 } 168 169 AlbaEncoding solution = new AlbaEncoding(new Permutation(PermutationTypes.RelativeUndirected, new IntArray(array)), instance); 170 171 return solution; 172 } 105 173 } 106 174 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Crossovers/AlbaCrossover.cs
r4369 r4376 53 53 IVRPEncoding solution = ParentsParameter.ActualValue[i]; 54 54 55 /*if (!(solution is AlbaEncoding)) { 56 parents[i] = AlbaEncoding.ConvertFrom(solution, VehiclesParameter.ActualValue.Value, 57 DistanceMatrixParameter); 58 } else*/ { 55 if (!(solution is AlbaEncoding)) { 56 parents[i] = AlbaEncoding.ConvertFrom(solution, ProblemInstance); 57 } else { 59 58 parents[i] = solution; 60 59 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Manipulators/AlbaManipulator.cs
r4369 r4376 62 62 IVRPEncoding solution = VRPToursParameter.ActualValue; 63 63 if (!(solution is AlbaEncoding)) { 64 //VRPToursParameter.ActualValue = AlbaEncoding.ConvertFrom(solution, VehiclesParameter.ActualValue.Value, DistanceMatrixParameter);64 VRPToursParameter.ActualValue = AlbaEncoding.ConvertFrom(solution, ProblemInstance); 65 65 } 66 66 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Moves/AlbaMoveGenerator.cs
r4369 r4376 43 43 IVRPEncoding solution = VRPToursParameter.ActualValue; 44 44 if (!(solution is AlbaEncoding)) { 45 //VRPToursParameter.ActualValue = AlbaEncoding.ConvertFrom(solution, VehiclesParameter.ActualValue.Value, 46 // DistanceMatrixParameter); 45 VRPToursParameter.ActualValue = AlbaEncoding.ConvertFrom(solution, ProblemInstance); 47 46 } 48 47 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/TourEncoding.cs
r4365 r4376 71 71 protected IVRPProblemInstance ProblemInstance { get; set; } 72 72 73 public override IDeepCloneable Clone(Cloner cloner) {74 TourEncoding clone = (TourEncoding)base.Clone(cloner);75 76 clone.ProblemInstance = (IVRPProblemInstance)cloner.Clone(ProblemInstance);77 78 return clone;79 }80 81 73 public TourEncoding(IVRPProblemInstance problemInstance) { 82 74 Tours = new ItemList<Tour>(); … … 87 79 [StorableConstructor] 88 80 protected TourEncoding(bool serializing) 89 : base() { 81 : base(serializing) { 82 } 83 84 public static void ConvertFrom(IVRPEncoding encoding, TourEncoding solution, IVRPProblemInstance problemInstance) { 85 solution.Tours = new ItemList<Tour>(encoding.GetTours()); 86 } 87 88 public static void ConvertFrom(List<int> route, TourEncoding solution) { 89 solution.Tours = new ItemList<Tour>(); 90 91 Tour tour = new Tour(); 92 for (int i = 0; i < route.Count; i++) { 93 if (route[i] == 0) { 94 if (tour.Stops.Count > 0) { 95 solution.Tours.Add(tour); 96 tour = new Tour(); 97 } 98 } else { 99 tour.Stops.Add(route[i]); 100 } 101 } 90 102 } 91 103 }
Note: See TracChangeset
for help on using the changeset viewer.