Changeset 4376
- Timestamp:
- 09/09/10 16:24:09 (14 years ago)
- Location:
- branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4
- Files:
-
- 12 added
- 14 edited
- 2 copied
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestAverageWorstTours/Capacitated/BestAverageWorstCapacitatedVRPToursAnalyzer.cs
r4374 r4376 39 39 [Item("BestAverageWorstCapaciatatedVRPToursAnalyzer", "An operator which analyzes the best, average and worst properties of the VRP tours in the scope tree.")] 40 40 [StorableClass] 41 public sealed class BestAverageWorstCapaciatatedVRPToursAnalyzer : AlgorithmOperator, IAnalyzer, I CapacitatedOperator {41 public sealed class BestAverageWorstCapaciatatedVRPToursAnalyzer : AlgorithmOperator, IAnalyzer, IHomogenousCapacitatedOperator { 42 42 #region Parameter properties 43 43 public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter { -
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 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/HeuristicLab.Problems.VehicleRouting-3.4.csproj
r4374 r4376 179 179 <Compile Include="Encodings\General\PermutationEncoding.cs" /> 180 180 <Compile Include="Encodings\General\TourEncoding.cs" /> 181 <Compile Include="Encodings\Potvin\Crossovers\PotvinCrossover.cs" /> 182 <Compile Include="Encodings\Potvin\Crossovers\PotvinRouteBasedCrossover.cs" /> 183 <Compile Include="Encodings\Potvin\Crossovers\PotvinSequenceBasedCrossover.cs" /> 184 <Compile Include="Encodings\Potvin\IPotvinOperator.cs" /> 185 <Compile Include="Encodings\Potvin\Manipulators\PotvinLocalSearchManipulator.cs" /> 186 <Compile Include="Encodings\Potvin\Manipulators\PotvinManipulator.cs" /> 187 <Compile Include="Encodings\Potvin\Manipulators\PotvinOneLevelExchangeManipulator.cs" /> 188 <Compile Include="Encodings\Potvin\Manipulators\PotvinTwoLevelExchangeManipulator.cs" /> 189 <Compile Include="Encodings\Potvin\PotvinEncoding.cs" /> 181 190 <Compile Include="Encodings\VRPOperator.cs" /> 182 191 <Compile Include="Interfaces\IMultiVRPOperator.cs" /> … … 192 201 <Compile Include="Variants\Capacitated\Heterogenous\IHeterogenousCapacitatedOperator.cs" /> 193 202 <Compile Include="Variants\Capacitated\Heterogenous\IHeterogenousCapacitatedEncoding.cs" /> 194 <Compile Include="Variants\Capacitated\Homogenous\ICapacitatedEncoding.cs" /> 195 <Compile Include="Variants\Capacitated\Homogenous\ICapacitatedOperator.cs" /> 196 <Compile Include="Variants\Capacitated\Homogenous\ICapacitatedProblemInstance.cs" /> 203 <Compile Include="Variants\Capacitated\Homogenous\IHomogenousCapacitatedEncoding.cs" /> 204 <Compile Include="Variants\Capacitated\Homogenous\IHomogenousCapacitatedOperator.cs" /> 205 <Compile Include="Variants\Capacitated\Homogenous\IHomogenousCapacitatedProblemInstance.cs" /> 206 <Compile Include="Variants\Capacitated\ICapacitatedProblemInstance.cs" /> 207 <Compile Include="Variants\Capacitated\ICapacitatedOperator.cs" /> 197 208 <Compile Include="Variants\General\IGeneralVRPOperator.cs" /> 198 209 <Compile Include="Variants\SingleDepot\ISingleDepotOperator.cs" /> -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluator.cs
r4363 r4376 49 49 base.EvaluateTour(eval, instance, tour); 50 50 51 I CapacitatedProblemInstance cvrpInstance = instance as ICapacitatedProblemInstance;51 IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance; 52 52 53 53 double delivered = 0.0; … … 55 55 56 56 for (int i = 0; i < tour.Stops.Count; i++) { 57 delivered += instance.Demand[ i];57 delivered += instance.Demand[tour.Stops[i]]; 58 58 } 59 59 60 double capacity = (instance as ICapacitatedProblemInstance).Capacity.Value;60 double capacity = cvrpInstance.Capacity.Value; 61 61 if (delivered > capacity) { 62 62 overweight = delivered - capacity; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPProblemInstance.cs
r4374 r4376 36 36 [Item("CVRPProblemInstance", "Represents a single depot CVRP instance.")] 37 37 [StorableClass] 38 public class CVRPProblemInstance: SingleDepotVRPProblemInstance, I CapacitatedProblemInstance {38 public class CVRPProblemInstance: SingleDepotVRPProblemInstance, IHomogenousCapacitatedProblemInstance { 39 39 protected IValueParameter<DoubleValue> CapacityParameter { 40 40 get { return (IValueParameter<DoubleValue>)Parameters["Capacity"]; } … … 55 55 protected override IEnumerable<IOperator> GetOperators() { 56 56 return base.GetOperators() 57 .Where(o => o is I CapacitatedOperator).Cast<IOperator>();57 .Where(o => o is IHomogenousCapacitatedOperator).Cast<IOperator>(); 58 58 } 59 59 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPEvaluator.cs
r4365 r4376 106 106 107 107 public bool Feasible(IVRPProblemInstance instance, Tour tour) { 108 return EvaluateTour(instance, tour).Penalty == 0;108 return EvaluateTour(instance, tour).Penalty < double.Epsilon; 109 109 } 110 110 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs
r4374 r4376 150 150 } else { 151 151 distance = CalculateDistance(start, end); 152 } 152 } 153 153 154 154 return distance; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Variants/Capacitated/Heterogenous/IHeterogenousCapacitatedEncoding.cs
r4363 r4376 26 26 27 27 namespace HeuristicLab.Problems.VehicleRouting.Variants { 28 public interface IHeterogenousCapacitatedEncoding : ICapacitatedEncoding {29 List<int> GetVehicleAssignment();28 public interface IHeterogenousCapacitatedEncoding : IHomogenousCapacitatedEncoding { 29 int GetVehicleAssignment(int tour); 30 30 } 31 31 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Variants/Capacitated/Heterogenous/IHeterogenousCapacitatedOperator.cs
r4363 r4376 26 26 27 27 namespace HeuristicLab.Problems.VehicleRouting.Variants { 28 public interface IHeterogenousCapacitatedOperator: I CapacitatedOperator {28 public interface IHeterogenousCapacitatedOperator: IHomogenousCapacitatedOperator { 29 29 } 30 30 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Variants/Capacitated/Heterogenous/IHeterogenousCapacitatedProblemInstance.cs
r4363 r4376 24 24 using System.Linq; 25 25 using System.Text; 26 using HeuristicLab.Data; 26 27 27 28 namespace HeuristicLab.Problems.VehicleRouting.Variants { 28 29 public interface IHeterogenousCapacitatedProblemInstance : ICapacitatedProblemInstance { 30 DoubleArray Capacity { get; } 29 31 } 30 32 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Variants/Capacitated/Homogenous/IHomogenousCapacitatedEncoding.cs
r4374 r4376 27 27 28 28 namespace HeuristicLab.Problems.VehicleRouting.Variants { 29 public interface I CapacitatedEncoding: IVRPEncoding {29 public interface IHomogenousCapacitatedEncoding : IVRPEncoding { 30 30 } 31 31 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Variants/Capacitated/Homogenous/IHomogenousCapacitatedOperator.cs
r4374 r4376 27 27 28 28 namespace HeuristicLab.Problems.VehicleRouting.Variants { 29 public interface I CapacitatedOperator: IVRPOperator {29 public interface IHomogenousCapacitatedOperator : ICapacitatedOperator { 30 30 } 31 31 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Variants/Capacitated/Homogenous/IHomogenousCapacitatedProblemInstance.cs
r4374 r4376 28 28 29 29 namespace HeuristicLab.Problems.VehicleRouting.Variants { 30 public interface I CapacitatedProblemInstance: IVRPProblemInstance {30 public interface IHomogenousCapacitatedProblemInstance: ICapacitatedProblemInstance { 31 31 DoubleValue Capacity { get; } 32 DoubleValue OverloadPenalty { get; }33 32 } 34 33 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Variants/Capacitated/ICapacitatedOperator.cs
r4374 r4376 27 27 28 28 namespace HeuristicLab.Problems.VehicleRouting.Variants { 29 public interface ICapacitatedOperator : IVRPOperator {29 public interface ICapacitatedOperator : IVRPOperator { 30 30 } 31 31 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Variants/Capacitated/ICapacitatedProblemInstance.cs
r4374 r4376 29 29 namespace HeuristicLab.Problems.VehicleRouting.Variants { 30 30 public interface ICapacitatedProblemInstance: IVRPProblemInstance { 31 DoubleValue Capacity { get; }32 31 DoubleValue OverloadPenalty { get; } 33 32 }
Note: See TracChangeset
for help on using the changeset viewer.