Changeset 17711
- Timestamp:
- 08/03/20 18:06:16 (4 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4
- Files:
-
- 1 added
- 9 deleted
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/AlbaEncoding.cs
r17704 r17711 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Optimization;29 28 using HeuristicLab.PluginInfrastructure; 30 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; … … 33 32 [Item("AlbaEncoding", "Represents the encoding for Alba encoded solutions.")] 34 33 [StorableType("9ff9f959-31d2-44e5-8a5e-b122220535c2")] 35 public class AlbaEncoding : Encoding, IVRPEncoding {34 public sealed class AlbaEncoding : VRPEncoding { 36 35 37 36 [StorableConstructor] … … 60 59 }; 61 60 } 62 pr ivate void DiscoverOperators() {61 protected override void DiscoverOperators() { 63 62 var assembly = typeof(IAlbaOperator).Assembly; 64 63 var discoveredTypes = ApplicationManager.Manager.GetTypes(encodingSpecificOperatorTypes, assembly, true, false, false); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/GVR/GVREncoding.cs
r17706 r17711 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Optimization;29 28 using HeuristicLab.PluginInfrastructure; 30 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; … … 33 32 [Item("GVR Encoding", "Represents the genetic vehicle representation encoding for GVR encoded solutions.")] 34 33 [StorableType("9ff9f959-31d2-44e5-8a5e-b122220535c2")] 35 public class GVREncoding : Encoding, IVRPEncoding {34 public class GVREncoding : VRPEncoding { 36 35 37 36 [StorableConstructor] … … 60 59 }; 61 60 } 62 pr ivate void DiscoverOperators() {61 protected override void DiscoverOperators() { 63 62 var assembly = typeof(IGVROperator).Assembly; 64 63 var discoveredTypes = ApplicationManager.Manager.GetTypes(encodingSpecificOperatorTypes, assembly, true, false, false); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/MultiVRPEncoding.cs
r17706 r17711 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Optimization;29 28 using HeuristicLab.PluginInfrastructure; 30 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; … … 33 32 [Item("MultiVRPEncoding", "Represents the combination of all encodings from the VRP.")] 34 33 [StorableType("9ff9f959-31d2-44e5-8a5e-b122220535c2")] 35 public class MultiVRPEncoding : Encoding, IVRPEncoding {34 public class MultiVRPEncoding : VRPEncoding { 36 35 37 36 [StorableConstructor] … … 58 57 }; 59 58 } 60 pr ivate void DiscoverOperators() {59 protected override void DiscoverOperators() { 61 60 var assembly = typeof(IAlbaOperator).Assembly; 62 61 var discoveredTypes = ApplicationManager.Manager.GetTypes(encodingSpecificOperatorTypes, assembly, true, false, false); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs
r17706 r17711 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Optimization;29 28 using HeuristicLab.PluginInfrastructure; 30 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; … … 33 32 [Item("Potvin Encoding", "Represents the Potvin encoding for Potvin encoded solutions.")] 34 33 [StorableType("9ff9f959-31d2-44e5-8a5e-b122220535c2")] 35 public class PotvinEncoding : Encoding, IVRPEncoding {34 public class PotvinEncoding : VRPEncoding { 36 35 37 36 [StorableConstructor] … … 60 59 }; 61 60 } 62 pr ivate void DiscoverOperators() {61 protected override void DiscoverOperators() { 63 62 var assembly = typeof(IPotvinOperator).Assembly; 64 63 var discoveredTypes = ApplicationManager.Manager.GetTypes(encodingSpecificOperatorTypes, assembly, true, false, false); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/PrinsEncoding.cs
r17706 r17711 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Optimization;29 28 using HeuristicLab.PluginInfrastructure; 30 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; … … 33 32 [Item("Prins Encoding", "Represents the Prins encoding for Prins encoded solutions.")] 34 33 [StorableType("9ff9f959-31d2-44e5-8a5e-b122220535c2")] 35 public class PrinsEncoding : Encoding, IVRPEncoding {34 public class PrinsEncoding : VRPEncoding { 36 35 37 36 [StorableConstructor] … … 60 59 }; 61 60 } 62 pr ivate void DiscoverOperators() {61 protected override void DiscoverOperators() { 63 62 var assembly = typeof(IPrinsOperator).Assembly; 64 63 var discoveredTypes = ApplicationManager.Manager.GetTypes(encodingSpecificOperatorTypes, assembly, true, false, false); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Zhu/ZhuEncoding.cs
r17706 r17711 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Optimization;29 28 using HeuristicLab.PluginInfrastructure; 30 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; … … 33 32 [Item("Zhu Encoding", "Represents the Zhu encoding for Zhu encoded solutions.")] 34 33 [StorableType("9ff9f959-31d2-44e5-8a5e-b122220535c2")] 35 public class ZhuEncoding : Encoding, IVRPEncoding {34 public class ZhuEncoding : VRPEncoding { 36 35 37 36 [StorableConstructor] … … 60 59 }; 61 60 } 62 pr ivate void DiscoverOperators() {61 protected override void DiscoverOperators() { 63 62 var assembly = typeof(IZhuOperator).Assembly; 64 63 var discoveredTypes = ApplicationManager.Manager.GetTypes(encodingSpecificOperatorTypes, assembly, true, false, false); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/HeuristicLab.Problems.VehicleRouting-3.4.csproj
r17709 r17711 148 148 <Compile Include="Encodings\Potvin\Moves\TwoOptStar\PotvinTwoOptStarSingleMoveGenerator.cs" /> 149 149 <Compile Include="Encodings\Prins\PrinsEncoding.cs" /> 150 <Compile Include="Encodings\VRPEncoding.cs" /> 150 151 <Compile Include="Encodings\Zhu\ZhuEncoding.cs" /> 151 152 <Compile Include="Improver\VRPImprovementOperator.cs" /> … … 340 341 <Compile Include="Interfaces\IVRPProblemInstance.cs" /> 341 342 <Compile Include="Plugin.cs" /> 342 <Compile Include="ProblemInstances\MultiDepotVRP\MDCVRP\MDCVRPEvaluator.cs" />343 343 <Compile Include="ProblemInstances\MultiDepotVRP\MDCVRP\MDCVRPProblemInstance.cs" /> 344 <Compile Include="ProblemInstances\MultiDepotVRP\MDCVRP\MDCVRPTW\MDCVRPPDTW\MDCVRPPDTWEvaluator.cs" />345 344 <Compile Include="ProblemInstances\MultiDepotVRP\MDCVRP\MDCVRPTW\MDCVRPPDTW\MDCVRPPDTWProblemInstance.cs" /> 346 <Compile Include="ProblemInstances\MultiDepotVRP\MDCVRP\MDCVRPTW\MDCVRPTWEvaluator.cs" />347 345 <Compile Include="ProblemInstances\MultiDepotVRP\MDCVRP\MDCVRPTW\MDCVRPTWProblemInstance.cs" /> 348 346 <Compile Include="ProblemInstances\MultiDepotVRP\MultiDepotVRPProblemInstance.cs" /> 349 <Compile Include="ProblemInstances\MultiDepotVRP\MultiDepotVRPEvaluator.cs" />350 347 <Compile Include="ProblemInstances\SingleDepotVRP\CVRP\CVRPTW\CVRPPDTW\CVRPPDTWProblemInstance.cs" /> 351 348 <Compile Include="ProblemInstances\SingleDepotVRP\CVRP\CVRPTW\CVRPPDTW\CVRPPDTWEvaluation.cs" /> 352 <Compile Include="ProblemInstances\SingleDepotVRP\CVRP\CVRPTW\CVRPPDTW\CVRPPDTWEvaluator.cs" />353 <Compile Include="ProblemInstances\SingleDepotVRP\SingleDepotVRPEvaluator.cs" />354 349 <Compile Include="SimilarityCalculators\VRPSimilarityCalculator.cs" /> 355 350 <Compile Include="SolutionParser.cs" /> … … 373 368 <Compile Include="ProblemInstances\SingleDepotVRP\CVRP\CVRPTW\CVRPTWEvaluation.cs" /> 374 369 <Compile Include="ProblemInstances\SingleDepotVRP\CVRP\CVRPEvaluation.cs" /> 375 <Compile Include="ProblemInstances\SingleDepotVRP\CVRP\CVRPTW\CVRPTWEvaluator.cs" />376 <Compile Include="ProblemInstances\SingleDepotVRP\CVRP\CVRPEvaluator.cs" />377 <Compile Include="ProblemInstances\VRPEvaluator.cs" />378 370 <Compile Include="ProblemInstances\VRPEvaluation.cs" /> 379 371 <Compile Include="ProblemInstances\SingleDepotVRP\SingleDepotVRPProblemInstance.cs" /> -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPEncoding.cs
r17699 r17711 22 22 using HEAL.Attic; 23 23 using HeuristicLab.Optimization; 24 using HeuristicLab.Problems.VehicleRouting.Interfaces; 24 25 25 26 namespace HeuristicLab.Problems.VehicleRouting { 26 27 27 28 [StorableType("b6674651-cc95-48d8-a2c3-83ee9325def3")] 28 public interface IVRPEncoding : IEncoding { } 29 public interface IVRPEncoding : IEncoding { 30 void FilterOperators(IVRPProblemInstance instance); 31 } 29 32 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPProblemInstance.cs
r17698 r17711 22 22 using System; 23 23 using System.Collections.Generic; 24 using HEAL.Attic; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 27 using HEAL.Attic;28 28 29 29 namespace HeuristicLab.Problems.VehicleRouting.Interfaces { 30 30 [StorableType("B8E231D0-6BA9-4DCF-9585-95E46B280B47")] 31 31 public interface IVRPProblemInstance : IParameterizedNamedItem { 32 IVRPEvaluator SolutionEvaluator { get; set; } 33 IVRPEvaluator MoveEvaluator { get; } 34 IEnumerable<IOperator> Operators { get; } 32 IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators); 35 33 36 34 event EventHandler EvaluationChanged; … … 50 48 double GetDistance(int start, int end, IVRPEncodedSolution solution); 51 49 double GetInsertionDistance(int start, int customer, int end, IVRPEncodedSolution solution, out double startDistance, out double endDistance); 52 bool Feasible(IVRPEncodedSolution solution);53 bool TourFeasible(Tour tour, IVRPEncodedSolution solution);54 50 VRPEvaluation Evaluate(IVRPEncodedSolution solution); 55 51 VRPEvaluation EvaluateTour(Tour tour, IVRPEncodedSolution solution); 56 bool Feasible(VRPEvaluation eval);57 52 double GetInsertionCosts(VRPEvaluation eval, IVRPEncodedSolution solution, int customer, int tour, int index, out bool feasible); 58 53 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPProblemInstance.cs
r17226 r17711 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 28 using HeuristicLab.Optimization;29 29 using HeuristicLab.Parameters; 30 using HEAL.Attic;31 using HeuristicLab.PluginInfrastructure;32 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; 33 31 using HeuristicLab.Problems.VehicleRouting.Variants; … … 67 65 } 68 66 69 protected override IEnumerable<IOperator> GetOperators() { 70 return base.GetOperators() 71 .Where(o => o is IHeterogenousCapacitatedOperator).Cast<IOperator>(); 72 } 73 74 protected override IEnumerable<IOperator> GetAnalyzers() { 75 return ApplicationManager.Manager.GetInstances<ICapacitatedOperator>() 76 .Where(o => o is IAnalyzer) 77 .Cast<IOperator>().Union(base.GetAnalyzers()); 78 } 79 80 protected override IVRPEvaluator Evaluator { 81 get { 82 return new MDCVRPEvaluator(); 83 } 67 public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) { 68 return base.FilterOperators(operators).Where(x => x is IHeterogenousCapacitatedOperator); 69 } 70 71 protected override VRPEvaluation CreateTourEvaluation() { 72 return new CVRPEvaluation(); 73 } 74 75 protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) { 76 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour))); 77 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 78 double originalQuality = eval.Quality; 79 80 double delivered = 0.0; 81 double overweight = 0.0; 82 double distance = 0.0; 83 84 int tourIndex = solution.GetTourIndex(tour); 85 int vehicle = solution.GetVehicleAssignment(tourIndex); 86 87 double capacity = Capacity[vehicle]; 88 for (int i = 0; i < tour.Stops.Count; i++) { 89 delivered += GetDemand(tour.Stops[i]); 90 } 91 92 double spareCapacity = capacity - delivered; 93 94 //simulate a tour, start and end at depot 95 for (int i = 0; i <= tour.Stops.Count; i++) { 96 int start = 0; 97 if (i > 0) 98 start = tour.Stops[i - 1]; 99 int end = 0; 100 if (i < tour.Stops.Count) 101 end = tour.Stops[i]; 102 103 //drive there 104 double currentDistace = GetDistance(start, end, solution); 105 distance += currentDistace; 106 107 CVRPInsertionInfo stopInfo = new CVRPInsertionInfo(start, end, spareCapacity); 108 tourInfo.AddStopInsertionInfo(stopInfo); 109 } 110 111 eval.Quality += FleetUsageFactor.Value; 112 eval.Quality += DistanceFactor.Value * distance; 113 114 eval.Distance += distance; 115 eval.VehicleUtilization += 1; 116 117 if (delivered > capacity) { 118 overweight = delivered - capacity; 119 } 120 121 (eval as CVRPEvaluation).Overload += overweight; 122 double penalty = overweight * OverloadPenalty.Value; 123 eval.Penalty += penalty; 124 eval.Quality += penalty; 125 tourInfo.Penalty = penalty; 126 tourInfo.Quality = eval.Quality - originalQuality; 127 } 128 129 protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 130 out bool feasible) { 131 CVRPInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPInsertionInfo; 132 133 double costs = 0; 134 feasible = tourInsertionInfo.Penalty < double.Epsilon; 135 136 double overloadPenalty = OverloadPenalty.Value; 137 138 double startDistance, endDistance; 139 costs += GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance); 140 141 double demand = GetDemand(customer); 142 if (demand > insertionInfo.SpareCapacity) { 143 feasible = false; 144 145 if (insertionInfo.SpareCapacity >= 0) 146 costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty; 147 else 148 costs += demand * overloadPenalty; 149 } 150 151 return costs; 84 152 } 85 153 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPPDTW/MDCVRPPDTWProblemInstance.cs
r17226 r17711 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 28 using HeuristicLab.Optimization;29 29 using HeuristicLab.Parameters; 30 using HEAL.Attic;31 using HeuristicLab.PluginInfrastructure;32 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; 33 31 using HeuristicLab.Problems.VehicleRouting.Variants; … … 67 65 } 68 66 69 protected override IEnumerable<IOperator> GetOperators() {70 return71 ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()72 .Where(o => !(o is IAnalyzer))73 .Cast<IOperator>().Union(base.GetOperators());74 }75 76 protected override IEnumerable<IOperator> GetAnalyzers() {77 return ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()78 .Where(o => o is IAnalyzer)79 .Cast<IOperator>().Union(base.GetAnalyzers());80 }81 82 protected override IVRPEvaluator Evaluator {83 get {84 return new MDCVRPPDTWEvaluator();85 }86 }87 88 67 public int GetPickupDeliveryLocation(int city) { 89 68 return PickupDeliveryLocation[city - 1]; 69 } 70 71 public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) { 72 return base.FilterOperators(operators).Where(x => x is IPickupAndDeliveryOperator); 73 } 74 75 protected override VRPEvaluation CreateTourEvaluation() { 76 return new CVRPPDTWEvaluation(); 77 } 78 79 protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) { 80 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour))); 81 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 82 double originalQuality = eval.Quality; 83 84 int depots = Depots.Value; 85 86 double time = 0.0; 87 double waitingTime = 0.0; 88 double serviceTime = 0.0; 89 double tardiness = 0.0; 90 double overweight = 0.0; 91 double distance = 0.0; 92 93 int tourIndex = solution.GetTourIndex(tour); 94 int vehicle = solution.GetVehicleAssignment(tourIndex); 95 int depot = VehicleDepotAssignment[vehicle]; 96 97 double capacity = Capacity[vehicle]; 98 99 double currentLoad = 0.0; 100 Dictionary<int, bool> stops = new Dictionary<int, bool>(); 101 int pickupViolations = 0; 102 103 double tourStartTime = ReadyTime[0]; 104 time = tourStartTime; 105 106 //simulate a tour, start and end at depot 107 for (int i = 0; i <= tour.Stops.Count; i++) { 108 int start = 0; 109 if (i > 0) 110 start = tour.Stops[i - 1]; 111 int end = 0; 112 if (i < tour.Stops.Count) 113 end = tour.Stops[i]; 114 115 //drive there 116 double currentDistace = GetDistance(start, end, solution); 117 time += currentDistace; 118 distance += currentDistace; 119 120 double arrivalTime = time; 121 122 int endIndex; 123 if (end == 0) 124 endIndex = depot; 125 else 126 endIndex = end + depots - 1; 127 128 //check if it was serviced on time 129 if (time > DueTime[endIndex]) 130 tardiness += time - DueTime[endIndex]; 131 132 //wait 133 double currentWaitingTime = 0.0; 134 if (time < ReadyTime[endIndex]) 135 currentWaitingTime = ReadyTime[endIndex] - time; 136 137 double waitTime = ReadyTime[endIndex] - time; 138 139 waitingTime += currentWaitingTime; 140 time += currentWaitingTime; 141 142 double spareTime = DueTime[endIndex] - time; 143 double arrivalSpareCapacity = capacity - currentLoad; 144 145 if (end > 0) { 146 //service 147 double currentServiceTime = ServiceTime[end - 1]; 148 serviceTime += currentServiceTime; 149 time += currentServiceTime; 150 151 //Pickup / deliver 152 bool validPickupDelivery = 153 validPickupDelivery = 154 ((Demand[end - 1] >= 0) || 155 (stops.ContainsKey(PickupDeliveryLocation[end - 1]))); 156 157 if (validPickupDelivery) { 158 currentLoad += Demand[end - 1]; 159 } else { 160 pickupViolations++; 161 } 162 163 if (currentLoad > capacity) 164 overweight += currentLoad - capacity; 165 } 166 167 double spareCapacity = capacity - currentLoad; 168 CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, tourStartTime, 169 arrivalTime, time, spareTime, waitTime, new List<int>(stops.Keys), arrivalSpareCapacity); 170 tourInfo.AddStopInsertionInfo(stopInfo); 171 172 stops.Add(end, true); 173 } 174 175 eval.Quality += FleetUsageFactor.Value; 176 eval.Quality += DistanceFactor.Value * distance; 177 eval.Distance += distance; 178 eval.VehicleUtilization += 1; 179 180 (eval as CVRPEvaluation).Overload += overweight; 181 double tourPenalty = 0; 182 double penalty = overweight * OverloadPenalty.Value; 183 eval.Penalty += penalty; 184 eval.Quality += penalty; 185 tourPenalty += penalty; 186 187 (eval as CVRPTWEvaluation).Tardiness += tardiness; 188 (eval as CVRPTWEvaluation).TravelTime += time; 189 190 penalty = tardiness * TardinessPenalty.Value; 191 eval.Penalty += penalty; 192 eval.Quality += penalty; 193 tourPenalty += penalty; 194 195 (eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations; 196 penalty = pickupViolations * PickupViolationPenalty.Value; 197 eval.Penalty += penalty; 198 tourPenalty += penalty; 199 200 eval.Quality += penalty; 201 eval.Quality += time * TimeFactor.Value; 202 tourInfo.Penalty = tourPenalty; 203 tourInfo.Quality = eval.Quality - originalQuality; 204 205 eval.IsFeasible = overweight == 0 && tardiness == 0 && pickupViolations == 0; 206 } 207 208 protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 209 out bool feasible) { 210 CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo; 211 212 double costs = 0; 213 feasible = tourInsertionInfo.Penalty < double.Epsilon; 214 bool tourFeasible = true; 215 216 double overloadPenalty = OverloadPenalty.Value; 217 double tardinessPenalty = TardinessPenalty.Value; 218 219 int depots = Depots.Value; 220 221 double pickupPenalty = PickupViolationPenalty.Value; 222 223 double startDistance, endDistance; 224 costs += GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance); 225 226 double demand = GetDemand(customer); 227 if (demand > insertionInfo.ArrivalSpareCapacity) { 228 tourFeasible = feasible = false; 229 if (insertionInfo.ArrivalSpareCapacity >= 0) 230 costs += (demand - insertionInfo.ArrivalSpareCapacity) * overloadPenalty; 231 else 232 costs += demand * overloadPenalty; 233 } 234 int destination = PickupDeliveryLocation[customer - 1]; 235 236 bool validPickup = true; 237 if (demand < 0 && !insertionInfo.Visited.Contains(destination)) { 238 tourFeasible = feasible = false; 239 validPickup = false; 240 costs += pickupPenalty; 241 } 242 243 double time = 0; 244 double tardiness = 0; 245 246 if (index > 0) 247 time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime; 248 else 249 time = insertionInfo.TourStartTime; 250 251 time += startDistance; 252 253 int customerIndex = customer + depots - 1; 254 255 if (time > DueTime[customerIndex]) { 256 tardiness += time - DueTime[customerIndex]; 257 } 258 if (time < ReadyTime[customerIndex]) 259 time += ReadyTime[customerIndex] - time; 260 time += ServiceTime[customer - 1]; 261 time += endDistance; 262 263 double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime; 264 for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) { 265 CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo; 266 267 if (demand >= 0) { 268 if (nextStop.End == destination) { 269 demand = 0; 270 costs -= pickupPenalty; 271 if (tourInsertionInfo.Penalty == pickupPenalty && tourFeasible) 272 feasible = true; 273 } else if (nextStop.SpareCapacity < 0) { 274 costs += demand * overloadPenalty; 275 } else if (nextStop.SpareCapacity < demand) { 276 tourFeasible = feasible = false; 277 costs += (demand - nextStop.SpareCapacity) * overloadPenalty; 278 } 279 } else if (validPickup) { 280 if (nextStop.SpareCapacity < 0) { 281 costs += Math.Max(demand, nextStop.SpareCapacity) * overloadPenalty; 282 } 283 } 284 285 if (additionalTime < 0) { 286 //arrive earlier than before 287 //wait probably 288 if (nextStop.WaitingTime < 0) { 289 double wait = nextStop.WaitingTime - additionalTime; 290 if (wait > 0) 291 additionalTime += wait; 292 } else { 293 additionalTime = 0; 294 } 295 296 //check due date, decrease tardiness 297 if (nextStop.SpareTime < 0) { 298 costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty; 299 } 300 } else { 301 //arrive later than before, probably don't have to wait 302 if (nextStop.WaitingTime > 0) { 303 additionalTime -= Math.Min(additionalTime, nextStop.WaitingTime); 304 } 305 306 //check due date 307 if (nextStop.SpareTime > 0) { 308 double spare = nextStop.SpareTime - additionalTime; 309 if (spare < 0) 310 tardiness += -spare; 311 } else { 312 tardiness += additionalTime; 313 } 314 } 315 } 316 317 costs += additionalTime * TimeFactor.Value; 318 319 if (tardiness > 0) { 320 tourFeasible = feasible = false; 321 } 322 323 costs += tardiness * tardinessPenalty; 324 325 return costs; 90 326 } 91 327 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPTWProblemInstance.cs
r17226 r17711 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 28 using HeuristicLab.Optimization;29 29 using HeuristicLab.Parameters; 30 using HEAL.Attic;31 using HeuristicLab.PluginInfrastructure;32 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; 33 31 using HeuristicLab.Problems.VehicleRouting.Variants; … … 89 87 } 90 88 91 protected override IEnumerable<IOperator> GetOperators() { 92 return base.GetOperators() 93 .Where(o => o is ITimeWindowedOperator).Cast<IOperator>(); 94 } 95 96 protected override IEnumerable<IOperator> GetAnalyzers() { 97 return ApplicationManager.Manager.GetInstances<ITimeWindowedOperator>() 98 .Where(o => o is IAnalyzer) 99 .Cast<IOperator>().Union(base.GetAnalyzers()); 100 } 101 102 protected override IVRPEvaluator Evaluator { 103 get { 104 return new MDCVRPTWEvaluator(); 105 } 89 public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) { 90 return base.FilterOperators(operators).Where(x => x is ITimeWindowedOperator); 91 } 92 93 protected override VRPEvaluation CreateTourEvaluation() { 94 return new CVRPTWEvaluation(); 95 } 96 97 protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) { 98 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour))); 99 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 100 double originalQuality = eval.Quality; 101 102 int depots = Depots.Value; 103 104 double time = 0.0; 105 double waitingTime = 0.0; 106 double serviceTime = 0.0; 107 double tardiness = 0.0; 108 double delivered = 0.0; 109 double overweight = 0.0; 110 double distance = 0.0; 111 112 int tourIndex = solution.GetTourIndex(tour); 113 int vehicle = solution.GetVehicleAssignment(tourIndex); 114 int depot = VehicleDepotAssignment[vehicle]; 115 116 double capacity = Capacity[vehicle]; 117 for (int i = 0; i < tour.Stops.Count; i++) { 118 delivered += GetDemand(tour.Stops[i]); 119 } 120 121 double spareCapacity = capacity - delivered; 122 123 double tourStartTime = ReadyTime[depot]; 124 time = tourStartTime; 125 126 //simulate a tour, start and end at depot 127 for (int i = 0; i <= tour.Stops.Count; i++) { 128 int start = 0; 129 if (i > 0) 130 start = tour.Stops[i - 1]; 131 int end = 0; 132 if (i < tour.Stops.Count) 133 end = tour.Stops[i]; 134 135 //drive there 136 double currentDistace = GetDistance(start, end, solution); 137 time += currentDistace; 138 distance += currentDistace; 139 140 double arrivalTime = time; 141 142 int endIndex; 143 if (end == 0) 144 endIndex = depot; 145 else 146 endIndex = end + depots - 1; 147 148 //check if it was serviced on time 149 if (time > DueTime[endIndex]) 150 tardiness += time - DueTime[endIndex]; 151 152 //wait 153 double currentWaitingTime = 0.0; 154 if (time < ReadyTime[endIndex]) 155 currentWaitingTime = ReadyTime[endIndex] - time; 156 157 double waitTime = ReadyTime[endIndex] - time; 158 159 waitingTime += currentWaitingTime; 160 time += currentWaitingTime; 161 162 double spareTime = DueTime[endIndex] - time; 163 164 //service 165 double currentServiceTime = 0; 166 if (end > 0) 167 currentServiceTime = ServiceTime[end - 1]; 168 serviceTime += currentServiceTime; 169 time += currentServiceTime; 170 171 CVRPTWInsertionInfo stopInfo = new CVRPTWInsertionInfo(start, end, spareCapacity, tourStartTime, arrivalTime, time, spareTime, waitTime); 172 tourInfo.AddStopInsertionInfo(stopInfo); 173 } 174 175 eval.Quality += FleetUsageFactor.Value; 176 eval.Quality += DistanceFactor.Value * distance; 177 eval.Distance += distance; 178 eval.VehicleUtilization += 1; 179 180 if (delivered > capacity) { 181 overweight = delivered - capacity; 182 } 183 184 (eval as CVRPEvaluation).Overload += overweight; 185 double tourPenalty = 0; 186 double penalty = overweight * OverloadPenalty.Value; 187 eval.Penalty += penalty; 188 eval.Quality += penalty; 189 tourPenalty += penalty; 190 191 (eval as CVRPTWEvaluation).Tardiness += tardiness; 192 (eval as CVRPTWEvaluation).TravelTime += time; 193 194 penalty = tardiness * TardinessPenalty.Value; 195 eval.Penalty += penalty; 196 eval.Quality += penalty; 197 tourPenalty += penalty; 198 eval.Quality += time * TimeFactor.Value; 199 tourInfo.Penalty = tourPenalty; 200 tourInfo.Quality = eval.Quality - originalQuality; 201 202 eval.IsFeasible = overweight == 0 && tardiness == 0; 203 } 204 205 protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 206 out bool feasible) { 207 CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo; 208 209 double costs = 0; 210 feasible = tourInsertionInfo.Penalty < double.Epsilon; 211 212 double overloadPenalty = OverloadPenalty.Value; 213 double tardinessPenalty = TardinessPenalty.Value; 214 int depots = Depots.Value; 215 216 double startDistance, endDistance; 217 costs += GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance); 218 219 double demand = GetDemand(customer); 220 if (demand > insertionInfo.SpareCapacity) { 221 feasible = false; 222 223 if (insertionInfo.SpareCapacity >= 0) 224 costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty; 225 else 226 costs += demand * overloadPenalty; 227 } 228 229 double time = 0; 230 double tardiness = 0; 231 232 if (index > 0) 233 time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime; 234 else 235 time = insertionInfo.TourStartTime; 236 237 time += startDistance; 238 239 int customerIndex = customer + depots - 1; 240 241 if (time > DueTime[customerIndex]) { 242 tardiness += time - DueTime[customerIndex]; 243 } 244 if (time < ReadyTime[customerIndex]) 245 time += ReadyTime[customerIndex] - time; 246 time += ServiceTime[customer - 1]; 247 time += endDistance; 248 249 double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime; 250 for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) { 251 CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo; 252 253 if (additionalTime < 0) { 254 //arrive earlier than before 255 //wait probably 256 if (nextStop.WaitingTime < 0) { 257 double wait = nextStop.WaitingTime - additionalTime; 258 if (wait > 0) 259 additionalTime += wait; 260 } else { 261 additionalTime = 0; 262 } 263 264 //check due date, decrease tardiness 265 if (nextStop.SpareTime < 0) { 266 costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty; 267 } 268 } else { 269 //arrive later than before, probably don't have to wait 270 if (nextStop.WaitingTime > 0) { 271 additionalTime -= Math.Min(additionalTime, nextStop.WaitingTime); 272 } 273 274 //check due date 275 if (nextStop.SpareTime > 0) { 276 double spare = nextStop.SpareTime - additionalTime; 277 if (spare < 0) 278 tardiness += -spare; 279 } else { 280 tardiness += additionalTime; 281 } 282 } 283 } 284 285 costs += additionalTime * TimeFactor.Value; 286 287 if (tardiness > 0) { 288 feasible = false; 289 } 290 291 costs += tardiness * tardinessPenalty; 292 293 return costs; 106 294 } 107 295 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MultiDepotVRPProblemInstance.cs
r17698 r17711 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 28 using HeuristicLab.Optimization;29 29 using HeuristicLab.Parameters; 30 using HEAL.Attic;31 using HeuristicLab.PluginInfrastructure;32 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; 33 31 using HeuristicLab.Problems.VehicleRouting.Variants; … … 60 58 } 61 59 62 protected override IEnumerable<IOperator> GetOperators() { 63 return ApplicationManager.Manager.GetInstances<IMultiDepotOperator>().Cast<IOperator>(); 64 } 65 66 protected override IEnumerable<IOperator> GetAnalyzers() { 67 return ApplicationManager.Manager.GetInstances<IMultiDepotOperator>() 68 .Where(o => o is IAnalyzer) 69 .Cast<IOperator>(); 70 } 71 72 public override IntValue Cities { 73 get { 74 return new IntValue(Demand.Length); 75 } 76 } 77 78 protected override IVRPEvaluator Evaluator { 79 get { 80 return new MultiDepotVRPEvaluator(); 81 } 82 } 83 84 protected override IVRPCreator Creator { 85 get { 86 return new HeuristicLab.Problems.VehicleRouting.Encodings.Alba.RandomCreator(); 87 } 88 } 60 public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) { 61 return base.FilterOperators(operators).Where(x => x is IMultiDepotOperator); 62 } 63 64 public override IntValue Cities => new IntValue(Demand.Length); 65 89 66 90 67 public override double GetDemand(int city) { … … 172 149 return newDistance - distance; 173 150 } 151 protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) { 152 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour))); 153 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 154 155 double distance = 0.0; 156 double quality = 0.0; 157 158 //simulate a tour, start and end at depot 159 for (int i = 0; i <= tour.Stops.Count; i++) { 160 int start = 0; 161 if (i > 0) 162 start = tour.Stops[i - 1]; 163 int end = 0; 164 if (i < tour.Stops.Count) 165 end = tour.Stops[i]; 166 167 //drive there 168 double currentDistace = GetDistance(start, end, solution); 169 distance += currentDistace; 170 171 StopInsertionInfo stopInfo = new StopInsertionInfo(start, end); 172 tourInfo.AddStopInsertionInfo(stopInfo); 173 } 174 175 //Fleet usage 176 quality += FleetUsageFactor.Value; 177 //Distance 178 quality += DistanceFactor.Value * distance; 179 180 eval.Distance += distance; 181 eval.VehicleUtilization += 1; 182 183 eval.Quality += quality; 184 tourInfo.Quality = quality; 185 } 186 187 protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 188 out bool feasible) { 189 StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index); 190 191 double costs = 0; 192 feasible = true; 193 double startDistance, endDistance; 194 195 costs += GetInsertionDistance(insertionInfo.Start, customer, insertionInfo.End, solution, out startDistance, out endDistance); 196 197 return costs; 198 } 174 199 175 200 [StorableConstructor] -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPProblemInstance.cs
r17226 r17711 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 28 using HeuristicLab.Optimization;29 29 using HeuristicLab.Parameters; 30 using HEAL.Attic;31 using HeuristicLab.PluginInfrastructure;32 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; 33 31 using HeuristicLab.Problems.VehicleRouting.Variants; … … 67 65 } 68 66 69 protected override IEnumerable<IOperator> GetOperators() { 70 return base.GetOperators() 71 .Where(o => o is IHomogenousCapacitatedOperator).Cast<IOperator>(); 72 } 73 74 protected override IEnumerable<IOperator> GetAnalyzers() { 75 return ApplicationManager.Manager.GetInstances<ICapacitatedOperator>() 76 .Where(o => o is IAnalyzer) 77 .Cast<IOperator>().Union(base.GetAnalyzers()); 78 } 79 80 protected override IVRPEvaluator Evaluator { 81 get { 82 return new CVRPEvaluator(); 83 } 67 public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) { 68 return base.FilterOperators(operators).Where(x => x is IHomogenousCapacitatedOperator); 69 } 70 protected override VRPEvaluation CreateTourEvaluation() { 71 return new CVRPEvaluation(); 72 } 73 74 protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) { 75 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour))); ; 76 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 77 double originalQuality = eval.Quality; 78 79 double delivered = 0.0; 80 double overweight = 0.0; 81 double distance = 0.0; 82 83 double capacity = Capacity.Value; 84 for (int i = 0; i <= tour.Stops.Count; i++) { 85 int end = 0; 86 if (i < tour.Stops.Count) 87 end = tour.Stops[i]; 88 89 delivered += Demand[end]; 90 } 91 92 double spareCapacity = capacity - delivered; 93 94 //simulate a tour, start and end at depot 95 for (int i = 0; i <= tour.Stops.Count; i++) { 96 int start = 0; 97 if (i > 0) 98 start = tour.Stops[i - 1]; 99 int end = 0; 100 if (i < tour.Stops.Count) 101 end = tour.Stops[i]; 102 103 //drive there 104 double currentDistace = GetDistance(start, end, solution); 105 distance += currentDistace; 106 107 CVRPInsertionInfo stopInfo = new CVRPInsertionInfo(start, end, spareCapacity); 108 tourInfo.AddStopInsertionInfo(stopInfo); 109 } 110 111 eval.Quality += FleetUsageFactor.Value; 112 eval.Quality += DistanceFactor.Value * distance; 113 114 eval.Distance += distance; 115 eval.VehicleUtilization += 1; 116 117 if (delivered > capacity) { 118 overweight = delivered - capacity; 119 } 120 121 (eval as CVRPEvaluation).Overload += overweight; 122 double penalty = overweight * OverloadPenalty.Value; 123 eval.Penalty += penalty; 124 eval.Quality += penalty; 125 tourInfo.Penalty = penalty; 126 tourInfo.Quality = eval.Quality - originalQuality; 127 128 eval.IsFeasible = overweight == 0; 129 } 130 131 protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 132 out bool feasible) { 133 CVRPInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPInsertionInfo; 134 135 double costs = 0; 136 feasible = tourInsertionInfo.Penalty < double.Epsilon; 137 138 double overloadPenalty = OverloadPenalty.Value; 139 140 double distance = GetDistance(insertionInfo.Start, insertionInfo.End, solution); 141 double newDistance = 142 GetDistance(insertionInfo.Start, customer, solution) + 143 GetDistance(customer, insertionInfo.End, solution); 144 costs += DistanceFactor.Value * (newDistance - distance); 145 146 double demand = Demand[customer]; 147 if (demand > insertionInfo.SpareCapacity) { 148 feasible = false; 149 150 if (insertionInfo.SpareCapacity >= 0) 151 costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty; 152 else 153 costs += demand * overloadPenalty; 154 } 155 156 return costs; 84 157 } 85 158 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWProblemInstance.cs
r17226 r17711 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 28 using HeuristicLab.Optimization;29 29 using HeuristicLab.Parameters; 30 using HEAL.Attic;31 using HeuristicLab.PluginInfrastructure;32 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; 33 31 using HeuristicLab.Problems.VehicleRouting.Variants; … … 67 65 } 68 66 69 protected override IEnumerable<IOperator> GetOperators() {70 return71 ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()72 .Where(o => !(o is IAnalyzer))73 .Cast<IOperator>().Union(base.GetOperators());74 }75 76 protected override IEnumerable<IOperator> GetAnalyzers() {77 return ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()78 .Where(o => o is IAnalyzer)79 .Cast<IOperator>().Union(base.GetAnalyzers());80 }81 82 protected override IVRPEvaluator Evaluator {83 get {84 return new CVRPPDTWEvaluator();85 }86 }87 88 67 public int GetPickupDeliveryLocation(int city) { 89 68 return PickupDeliveryLocation[city]; 69 } 70 71 public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) { 72 return base.FilterOperators(operators).Where(x => x is IPickupAndDeliveryOperator); 73 } 74 75 protected override VRPEvaluation CreateTourEvaluation() { 76 return new CVRPPDTWEvaluation(); 77 } 78 79 protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) { 80 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour))); 81 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 82 double originalQuality = eval.Quality; 83 84 double capacity = Capacity.Value; 85 86 double time = 0.0; 87 double waitingTime = 0.0; 88 double serviceTime = 0.0; 89 double tardiness = 0.0; 90 double overweight = 0.0; 91 double distance = 0.0; 92 93 double currentLoad = 0.0; 94 Dictionary<int, bool> stops = new Dictionary<int, bool>(); 95 int pickupViolations = 0; 96 97 double tourStartTime = ReadyTime[0]; 98 time = tourStartTime; 99 100 //simulate a tour, start and end at depot 101 for (int i = 0; i <= tour.Stops.Count; i++) { 102 int start = 0; 103 if (i > 0) 104 start = tour.Stops[i - 1]; 105 int end = 0; 106 if (i < tour.Stops.Count) 107 end = tour.Stops[i]; 108 109 //drive there 110 double currentDistace = GetDistance(start, end, solution); 111 time += currentDistace; 112 distance += currentDistace; 113 114 double arrivalTime = time; 115 116 //check if it was serviced on time 117 if (time > DueTime[end]) 118 tardiness += time - DueTime[end]; 119 120 //wait 121 double currentWaitingTime = 0.0; 122 if (time < ReadyTime[end]) 123 currentWaitingTime = ReadyTime[end] - time; 124 125 double waitTime = ReadyTime[end] - time; 126 127 waitingTime += currentWaitingTime; 128 time += currentWaitingTime; 129 130 double spareTime = DueTime[end] - time; 131 132 //service 133 double currentServiceTime = ServiceTime[end]; 134 serviceTime += currentServiceTime; 135 time += currentServiceTime; 136 137 //Pickup / deliver 138 double arrivalSpareCapacity = capacity - currentLoad; 139 140 bool validPickupDelivery = 141 validPickupDelivery = 142 ((Demand[end] >= 0) || 143 (stops.ContainsKey(PickupDeliveryLocation[end]))); 144 145 if (validPickupDelivery) { 146 currentLoad += Demand[end]; 147 } else { 148 pickupViolations++; 149 } 150 151 if (currentLoad > capacity) 152 overweight += currentLoad - capacity; 153 154 double spareCapacity = capacity - currentLoad; 155 CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, tourStartTime, 156 arrivalTime, time, spareTime, waitTime, new List<int>(stops.Keys), arrivalSpareCapacity); 157 tourInfo.AddStopInsertionInfo(stopInfo); 158 159 stops.Add(end, true); 160 } 161 162 eval.Quality += FleetUsageFactor.Value; 163 eval.Quality += DistanceFactor.Value * distance; 164 eval.Distance += distance; 165 eval.VehicleUtilization += 1; 166 167 (eval as CVRPEvaluation).Overload += overweight; 168 double tourPenalty = 0; 169 double penalty = overweight * OverloadPenalty.Value; 170 eval.Penalty += penalty; 171 eval.Quality += penalty; 172 tourPenalty += penalty; 173 174 (eval as CVRPTWEvaluation).Tardiness += tardiness; 175 (eval as CVRPTWEvaluation).TravelTime += time; 176 177 penalty = tardiness * TardinessPenalty.Value; 178 eval.Penalty += penalty; 179 eval.Quality += penalty; 180 tourPenalty += penalty; 181 182 (eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations; 183 penalty = pickupViolations * PickupViolationPenalty.Value; 184 eval.Penalty += penalty; 185 tourPenalty += penalty; 186 187 eval.Quality += penalty; 188 eval.Quality += time * TimeFactor.Value; 189 tourInfo.Penalty = tourPenalty; 190 tourInfo.Quality = eval.Quality - originalQuality; 191 192 eval.IsFeasible = overweight == 0 && tardiness == 0 && pickupViolations == 0; 193 } 194 195 protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 196 out bool feasible) { 197 CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo; 198 199 double costs = 0; 200 feasible = tourInsertionInfo.Penalty < double.Epsilon; 201 bool tourFeasible = true; 202 203 double overloadPenalty = OverloadPenalty.Value; 204 double tardinessPenalty = TardinessPenalty.Value; 205 double pickupPenalty = PickupViolationPenalty.Value; 206 207 double distance = GetDistance(insertionInfo.Start, insertionInfo.End, solution); 208 double newDistance = 209 GetDistance(insertionInfo.Start, customer, solution) + 210 GetDistance(customer, insertionInfo.End, solution); 211 costs += DistanceFactor.Value * (newDistance - distance); 212 213 double demand = Demand[customer]; 214 if (demand > insertionInfo.ArrivalSpareCapacity) { 215 tourFeasible = feasible = false; 216 if (insertionInfo.ArrivalSpareCapacity >= 0) 217 costs += (demand - insertionInfo.ArrivalSpareCapacity) * overloadPenalty; 218 else 219 costs += demand * overloadPenalty; 220 } 221 int destination = PickupDeliveryLocation[customer]; 222 223 bool validPickup = true; 224 if (demand < 0 && !insertionInfo.Visited.Contains(destination)) { 225 tourFeasible = feasible = false; 226 validPickup = false; 227 costs += pickupPenalty; 228 } 229 230 double time = 0; 231 double tardiness = 0; 232 233 if (index > 0) 234 time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime; 235 else 236 time = insertionInfo.TourStartTime; 237 238 time += GetDistance(insertionInfo.Start, customer, solution); 239 if (time > DueTime[customer]) { 240 tardiness += time - DueTime[customer]; 241 } 242 if (time < ReadyTime[customer]) 243 time += ReadyTime[customer] - time; 244 time += ServiceTime[customer]; 245 time += GetDistance(customer, insertionInfo.End, solution); 246 247 double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime; 248 for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) { 249 CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo; 250 251 if (demand >= 0) { 252 if (nextStop.End == destination) { 253 demand = 0; 254 costs -= pickupPenalty; 255 if (tourInsertionInfo.Penalty == pickupPenalty && tourFeasible) 256 feasible = true; 257 } else if (nextStop.SpareCapacity < 0) { 258 costs += demand * overloadPenalty; 259 } else if (nextStop.SpareCapacity < demand) { 260 tourFeasible = feasible = false; 261 costs += (demand - nextStop.SpareCapacity) * overloadPenalty; 262 } 263 } else if (validPickup) { 264 if (nextStop.SpareCapacity < 0) { 265 costs += Math.Max(demand, nextStop.SpareCapacity) * overloadPenalty; 266 } 267 } 268 269 if (additionalTime < 0) { 270 //arrive earlier than before 271 //wait probably 272 if (nextStop.WaitingTime < 0) { 273 double wait = nextStop.WaitingTime - additionalTime; 274 if (wait > 0) 275 additionalTime += wait; 276 } else { 277 additionalTime = 0; 278 } 279 280 //check due date, decrease tardiness 281 if (nextStop.SpareTime < 0) { 282 costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty; 283 } 284 } else { 285 //arrive later than before, probably don't have to wait 286 if (nextStop.WaitingTime > 0) { 287 additionalTime -= Math.Min(additionalTime, nextStop.WaitingTime); 288 } 289 290 //check due date 291 if (nextStop.SpareTime > 0) { 292 double spare = nextStop.SpareTime - additionalTime; 293 if (spare < 0) 294 tardiness += -spare; 295 } else { 296 tardiness += additionalTime; 297 } 298 } 299 } 300 301 costs += additionalTime * TimeFactor.Value; 302 303 if (tardiness > 0) { 304 tourFeasible = feasible = false; 305 } 306 307 costs += tardiness * tardinessPenalty; 308 309 return costs; 90 310 } 91 311 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWProblemInstance.cs
r17226 r17711 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 28 using HeuristicLab.Optimization;29 29 using HeuristicLab.Parameters; 30 using HEAL.Attic;31 using HeuristicLab.PluginInfrastructure;32 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; 33 31 using HeuristicLab.Problems.VehicleRouting.Variants; … … 89 87 } 90 88 91 protected override IEnumerable<IOperator> GetOperators() { 92 return base.GetOperators() 93 .Where(o => o is ITimeWindowedOperator).Cast<IOperator>(); 94 } 95 96 protected override IEnumerable<IOperator> GetAnalyzers() { 97 return ApplicationManager.Manager.GetInstances<ITimeWindowedOperator>() 98 .Where(o => o is IAnalyzer) 99 .Cast<IOperator>().Union(base.GetAnalyzers()); 100 } 101 102 protected override IVRPEvaluator Evaluator { 103 get { 104 return new CVRPTWEvaluator(); 105 } 89 public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) { 90 return base.FilterOperators(operators).Where(x => x is ITimeWindowedOperator); 91 } 92 93 protected override VRPEvaluation CreateTourEvaluation() { 94 return new CVRPTWEvaluation(); 95 } 96 97 protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) { 98 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour))); 99 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 100 double originalQuality = eval.Quality; 101 102 double time = 0.0; 103 double waitingTime = 0.0; 104 double serviceTime = 0.0; 105 double tardiness = 0.0; 106 double delivered = 0.0; 107 double overweight = 0.0; 108 double distance = 0.0; 109 110 double capacity = Capacity.Value; 111 for (int i = 0; i <= tour.Stops.Count; i++) { 112 int end = 0; 113 if (i < tour.Stops.Count) 114 end = tour.Stops[i]; 115 116 delivered += Demand[end]; 117 } 118 119 double spareCapacity = capacity - delivered; 120 121 double tourStartTime = ReadyTime[0]; 122 time = tourStartTime; 123 124 //simulate a tour, start and end at depot 125 for (int i = 0; i <= tour.Stops.Count; i++) { 126 int start = 0; 127 if (i > 0) 128 start = tour.Stops[i - 1]; 129 int end = 0; 130 if (i < tour.Stops.Count) 131 end = tour.Stops[i]; 132 133 //drive there 134 double currentDistace = GetDistance(start, end, solution); 135 time += currentDistace; 136 distance += currentDistace; 137 138 double arrivalTime = time; 139 140 //check if it was serviced on time 141 if (time > DueTime[end]) { 142 tardiness += time - DueTime[end]; 143 } 144 145 //wait 146 double currentWaitingTime = 0.0; 147 if (time < ReadyTime[end]) 148 currentWaitingTime = ReadyTime[end] - time; 149 150 double waitTime = ReadyTime[end] - time; 151 152 waitingTime += currentWaitingTime; 153 time += currentWaitingTime; 154 155 double spareTime = DueTime[end] - time; 156 157 //service 158 double currentServiceTime = ServiceTime[end]; 159 serviceTime += currentServiceTime; 160 time += currentServiceTime; 161 162 CVRPTWInsertionInfo stopInfo = new CVRPTWInsertionInfo(start, end, spareCapacity, tourStartTime, arrivalTime, time, spareTime, waitTime); 163 tourInfo.AddStopInsertionInfo(stopInfo); 164 } 165 166 eval.Quality += FleetUsageFactor.Value; 167 eval.Quality += DistanceFactor.Value * distance; 168 eval.Distance += distance; 169 eval.VehicleUtilization += 1; 170 171 if (delivered > capacity) { 172 overweight = delivered - capacity; 173 } 174 175 (eval as CVRPEvaluation).Overload += overweight; 176 double tourPenalty = 0; 177 double penalty = overweight * OverloadPenalty.Value; 178 eval.Penalty += penalty; 179 eval.Quality += penalty; 180 tourPenalty += penalty; 181 182 (eval as CVRPTWEvaluation).Tardiness += tardiness; 183 (eval as CVRPTWEvaluation).TravelTime += time; 184 185 penalty = tardiness * TardinessPenalty.Value; 186 eval.Penalty += penalty; 187 eval.Quality += penalty; 188 tourPenalty += penalty; 189 eval.Quality += time * TimeFactor.Value; 190 tourInfo.Penalty = tourPenalty; 191 tourInfo.Quality = eval.Quality - originalQuality; 192 193 eval.IsFeasible = overweight == 0 && tardiness == 0; 194 } 195 196 protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 197 out bool feasible) { 198 CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo; 199 200 double costs = 0; 201 feasible = tourInsertionInfo.Penalty < double.Epsilon; 202 203 double overloadPenalty = OverloadPenalty.Value; 204 double tardinessPenalty = TardinessPenalty.Value; 205 206 double distance = GetDistance(insertionInfo.Start, insertionInfo.End, solution); 207 double newDistance = 208 GetDistance(insertionInfo.Start, customer, solution) + 209 GetDistance(customer, insertionInfo.End, solution); 210 costs += DistanceFactor.Value * (newDistance - distance); 211 212 double demand = Demand[customer]; 213 if (demand > insertionInfo.SpareCapacity) { 214 feasible = false; 215 if (insertionInfo.SpareCapacity >= 0) 216 costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty; 217 else 218 costs += demand * overloadPenalty; 219 } 220 221 double time = 0; 222 double tardiness = 0; 223 224 if (index > 0) 225 time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime; 226 else 227 time = insertionInfo.TourStartTime; 228 229 time += GetDistance(insertionInfo.Start, customer, solution); 230 if (time > DueTime[customer]) { 231 tardiness += time - DueTime[customer]; 232 } 233 if (time < ReadyTime[customer]) 234 time += ReadyTime[customer] - time; 235 time += ServiceTime[customer]; 236 time += GetDistance(customer, insertionInfo.End, solution); 237 238 double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime; 239 for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) { 240 CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo; 241 242 if (additionalTime < 0) { 243 //arrive earlier than before 244 //wait probably 245 if (nextStop.WaitingTime < 0) { 246 double wait = nextStop.WaitingTime - additionalTime; 247 if (wait > 0) 248 additionalTime += wait; 249 } else { 250 additionalTime = 0; 251 } 252 253 //check due date, decrease tardiness 254 if (nextStop.SpareTime < 0) { 255 costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty; 256 } 257 } else { 258 //arrive later than before, probably don't have to wait 259 if (nextStop.WaitingTime > 0) { 260 additionalTime -= Math.Min(additionalTime, nextStop.WaitingTime); 261 } 262 263 //check due date 264 if (nextStop.SpareTime > 0) { 265 double spare = nextStop.SpareTime - additionalTime; 266 if (spare < 0) 267 tardiness += -spare; 268 } else { 269 tardiness += additionalTime; 270 } 271 } 272 } 273 274 costs += additionalTime * TimeFactor.Value; 275 276 if (tardiness > 0) { 277 feasible = false; 278 } 279 280 costs += tardiness * tardinessPenalty; 281 282 return costs; 106 283 } 107 284 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/SingleDepotVRPProblemInstance.cs
r17698 r17711 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Optimization;29 using HeuristicLab.PluginInfrastructure;30 28 using HeuristicLab.Problems.VehicleRouting.Interfaces; 31 29 using HeuristicLab.Problems.VehicleRouting.Variants; … … 35 33 [StorableType("A45435DD-F615-45C6-8456-5A49EE5D3C8E")] 36 34 public class SingleDepotVRPProblemInstance : VRPProblemInstance, ISingleDepotProblemInstance { 37 protected override IEnumerable<IOperator> GetOperators() {38 return ApplicationManager.Manager.GetInstances<ISingleDepotOperator>().Cast<IOperator>();39 }40 35 41 protected override IEnumerable<IOperator> GetAnalyzers() { 42 return ApplicationManager.Manager.GetInstances<ISingleDepotOperator>() 43 .Where(o => o is IAnalyzer) 44 .Cast<IOperator>(); 36 public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) { 37 return base.FilterOperators(operators).Where(x => x is ISingleDepotOperator); 45 38 } 46 39 … … 50 43 } 51 44 } 45 protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) { 46 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour))); 47 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 52 48 53 protected override IVRPEvaluator Evaluator { 54 get { 55 return new SingleDepotVRPEvaluator(); 49 double distance = 0.0; 50 double quality = 0.0; 51 52 //simulate a tour, start and end at depot 53 for (int i = 0; i <= tour.Stops.Count; i++) { 54 int start = 0; 55 if (i > 0) 56 start = tour.Stops[i - 1]; 57 int end = 0; 58 if (i < tour.Stops.Count) 59 end = tour.Stops[i]; 60 61 //drive there 62 double currentDistace = GetDistance(start, end, solution); 63 distance += currentDistace; 64 65 StopInsertionInfo stopInfo = new StopInsertionInfo(start, end); 66 tourInfo.AddStopInsertionInfo(stopInfo); 56 67 } 68 69 //Fleet usage 70 quality += FleetUsageFactor.Value; 71 //Distance 72 quality += DistanceFactor.Value * distance; 73 74 eval.Distance += distance; 75 eval.VehicleUtilization += 1; 76 77 tourInfo.Quality = quality; 78 eval.Quality += quality; 57 79 } 58 80 59 protected override IVRPCreator Creator { 60 get { 61 return new HeuristicLab.Problems.VehicleRouting.Encodings.Alba.RandomCreator(); 62 } 81 protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 82 out bool feasible) { 83 StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index); 84 85 double costs = 0; 86 feasible = true; 87 88 double distance = GetDistance(insertionInfo.Start, insertionInfo.End, solution); 89 double newDistance = 90 GetDistance(insertionInfo.Start, customer, solution) + 91 GetDistance(customer, insertionInfo.End, solution); 92 93 costs += DistanceFactor.Value * (newDistance - distance); 94 95 return costs; 63 96 } 97 64 98 65 99 [StorableConstructor] -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs
r17698 r17711 28 28 using HeuristicLab.Data; 29 29 using HeuristicLab.Parameters; 30 using HeuristicLab.Problems.VehicleRouting.Encodings.General;31 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; 32 31 … … 35 34 [StorableType("9A6CCE89-A4B6-4FA3-A150-181FC315B713")] 36 35 public abstract class VRPProblemInstance : ParameterizedNamedItem, IVRPProblemInstance, IStatefulItem { 37 IVRPEvaluator moveEvaluator;38 39 private object locker = new object();40 41 public IVRPEvaluator MoveEvaluator {42 get {43 lock (locker) {44 if (evaluator == null)45 return null;46 else {47 if (moveEvaluator == null) {48 moveEvaluator = evaluator.Clone() as IVRPEvaluator;49 50 foreach (IParameter parameter in moveEvaluator.Parameters) {51 if (parameter is ILookupParameter52 && parameter != moveEvaluator.ProblemInstanceParameter53 && parameter != moveEvaluator.VRPToursParameter) {54 (parameter as ILookupParameter).ActualName =55 VRPMoveEvaluator.MovePrefix +56 (parameter as ILookupParameter).ActualName;57 }58 }59 }60 61 return moveEvaluator;62 }63 }64 }65 }66 67 protected abstract IEnumerable<IOperator> GetOperators();68 protected abstract IEnumerable<IOperator> GetAnalyzers();69 70 public IEnumerable<IOperator> Operators {71 get {72 return GetOperators().Union(GetAnalyzers());73 }74 }75 36 76 37 protected ValueParameter<DoubleMatrix> CoordinatesParameter { … … 131 92 } 132 93 94 public virtual IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) { 95 return operators.Where(x => x is IVRPOperator); 96 } 97 133 98 protected virtual double CalculateDistance(int start, int end) { 134 double distance = 0.0; 135 136 distance = 99 var distance = 137 100 Math.Sqrt( 138 101 Math.Pow(Coordinates[start, 0] - Coordinates[end, 0], 2) + … … 172 135 //cache for performance improvement 173 136 private DoubleMatrix distanceMatrix = null; 174 private IVRPEvaluator evaluator = null; 175 176 public IVRPEvaluator SolutionEvaluator { 177 get { 178 return evaluator; 179 } 180 set { 181 lock (locker) { 182 moveEvaluator = null; 183 evaluator = value; 184 EvalBestKnownSolution(); 185 } 186 } 187 } 137 188 138 189 139 public virtual double GetDistance(int start, int end, IVRPEncodedSolution solution) { … … 208 158 } 209 159 210 public bool Feasible(IVRPEncodedSolution solution) { 211 return evaluator.Feasible( 212 evaluator.Evaluate( 213 this, solution)); 214 } 215 216 public bool TourFeasible(Tour tour, IVRPEncodedSolution solution) { 217 return evaluator.Feasible( 218 evaluator.EvaluateTour( 219 this, tour, solution)); 160 protected virtual VRPEvaluation CreateTourEvaluation() { 161 return new VRPEvaluation(); 220 162 } 221 163 222 164 public VRPEvaluation Evaluate(IVRPEncodedSolution solution) { 223 return evaluator.Evaluate(this, solution); 165 VRPEvaluation evaluation = CreateTourEvaluation(); 166 evaluation.IsFeasible = true; 167 foreach (Tour tour in solution.GetTours()) { 168 EvaluateTour(evaluation, tour, solution); 169 } 170 return evaluation; 224 171 } 225 172 226 173 public VRPEvaluation EvaluateTour(Tour tour, IVRPEncodedSolution solution) { 227 return evaluator.EvaluateTour(this, tour, solution); 228 } 229 230 public bool Feasible(VRPEvaluation eval) { 231 return evaluator.Feasible(eval); 174 VRPEvaluation evaluation = CreateTourEvaluation(); 175 evaluation.IsFeasible = true; 176 EvaluateTour(evaluation, tour, solution); 177 return evaluation; 232 178 } 233 179 234 180 public double GetInsertionCosts(VRPEvaluation eval, IVRPEncodedSolution solution, int customer, int tour, int index, out bool feasible) { 235 return evaluator.GetInsertionCosts(this, solution, eval, customer, tour, index, out feasible); 236 } 181 bool tourFeasible; 182 double costs = GetTourInsertionCosts( 183 solution, 184 eval.InsertionInfo.GetTourInsertionInfo(tour), 185 index, 186 customer, out tourFeasible); 187 188 feasible = tourFeasible; 189 190 return costs; 191 } 192 protected abstract double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer, out bool feasible); 193 194 protected abstract void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution); 237 195 238 196 … … 241 199 protected void EvalBestKnownSolution() { 242 200 EventHandler tmp = EvaluationChanged; 243 if (tmp != null) 244 tmp(this, null); 245 } 246 247 protected abstract IVRPEvaluator Evaluator { get; } 248 protected abstract IVRPCreator Creator { get; } 201 if (tmp != null) tmp(this, null); 202 } 249 203 250 204 [StorableConstructor] … … 262 216 Parameters.Add(new ValueParameter<DoubleValue>("EvalDistanceFactor", "The distance factor considered in the evaluation.", new DoubleValue(1))); 263 217 264 evaluator = Evaluator;265 218 AttachEventHandlers(); 266 219 } … … 268 221 protected VRPProblemInstance(VRPProblemInstance original, Cloner cloner) 269 222 : base(original, cloner) { 270 evaluator = Evaluator;271 223 AttachEventHandlers(); 272 224 } … … 274 226 [StorableHook(HookType.AfterDeserialization)] 275 227 private void AfterDeserialization() { 276 evaluator = Evaluator;277 228 AttachEventHandlers(); 278 229 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs
r17710 r17711 75 75 public VehicleRoutingProblem() 76 76 : base(new PotvinEncoding()) { 77 EncodingParameter.Hidden = false; 78 77 79 Parameters.Add(new ValueParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance")); 78 80 Parameters.Add(new OptionalValueParameter<VRPSolution>("BestKnownSolution", "The best known solution of this VRP instance.")); … … 211 213 212 214 private void InitializeOperators() { 215 Encoding.FilterOperators(ProblemInstance); 216 213 217 Operators.Add(new VRPSimilarityCalculator()); 214 218 Operators.Add(new QualitySimilarityCalculator());
Note: See TracChangeset
for help on using the changeset viewer.