Changeset 4377 for branches/VRP/HeuristicLab.Problems.VehicleRouting
- Timestamp:
- 09/10/10 11:26:30 (14 years ago)
- Location:
- branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluator.cs
r4376 r4377 47 47 48 48 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) { 49 base.EvaluateTour(eval, instance, tour);50 51 49 IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance; 50 DoubleArray demand = instance.Demand; 52 51 53 52 double delivered = 0.0; 54 53 double overweight = 0.0; 54 double distance = 0.0; 55 55 56 for (int i = 0; i < tour.Stops.Count; i++) { 57 delivered += instance.Demand[tour.Stops[i]]; 56 //simulate a tour, start and end at depot 57 for (int i = 0; i <= tour.Stops.Count; i++) { 58 int start = 0; 59 if (i > 0) 60 start = tour.Stops[i - 1]; 61 int end = 0; 62 if (i < tour.Stops.Count) 63 end = tour.Stops[i]; 64 65 //drive there 66 double currentDistace = instance.GetDistance(start, end); 67 distance += currentDistace; 68 69 delivered += demand[end]; 58 70 } 71 72 eval.Quality += instance.FleetUsageFactor.Value; 73 eval.Quality += instance.DistanceFactor.Value * distance; 74 75 eval.Distance = distance; 76 eval.VehicleUtilization = 1; 59 77 60 78 double capacity = cvrpInstance.Capacity.Value; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluator.cs
r4374 r4377 51 51 52 52 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) { 53 base.EvaluateTour(eval, instance, tour); 53 IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance; 54 DoubleArray demand = instance.Demand; 54 55 55 56 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance; 57 DoubleArray dueTime = vrptw.DueTime; 58 DoubleArray readyTime = vrptw.ReadyTime; 59 DoubleArray serviceTimes = vrptw.ServiceTime; 56 60 57 61 double time = 0.0; … … 59 63 double serviceTime = 0.0; 60 64 double tardiness = 0.0; 65 double delivered = 0.0; 66 double overweight = 0.0; 67 double distance = 0.0; 61 68 62 69 //simulate a tour, start and end at depot … … 72 79 double currentDistace = vrptw.GetDistance(start, end); 73 80 time += currentDistace; 81 distance += currentDistace; 74 82 75 83 //check if it was serviced on time 76 if (time > vrptw.DueTime[end])77 tardiness += time - vrptw.DueTime[end];84 if (time > dueTime[end]) 85 tardiness += time - dueTime[end]; 78 86 79 87 //wait 80 88 double currentWaitingTime = 0.0; 81 if (time < vrptw.ReadyTime[end])82 currentWaitingTime = vrptw.ReadyTime[end] - time;89 if (time < readyTime[end]) 90 currentWaitingTime = readyTime[end] - time; 83 91 waitingTime += currentWaitingTime; 84 92 time += currentWaitingTime; 85 93 86 94 //service 87 double currentServiceTime = vrptw.ServiceTime[end];95 double currentServiceTime = serviceTimes[end]; 88 96 serviceTime += currentServiceTime; 89 97 time += currentServiceTime; 98 delivered += demand[end]; 90 99 } 100 101 eval.Quality += instance.FleetUsageFactor.Value; 102 eval.Quality += instance.DistanceFactor.Value * distance; 103 eval.Distance = distance; 104 eval.VehicleUtilization = 1; 105 106 double capacity = cvrpInstance.Capacity.Value; 107 if (delivered > capacity) { 108 overweight = delivered - capacity; 109 } 110 111 (eval as CVRPEvaluation).Overload = overweight; 112 double penalty = overweight * cvrpInstance.OverloadPenalty.Value; 113 eval.Penalty += penalty; 114 eval.Quality += penalty; 91 115 92 116 (eval as CVRPTWEvaluation).Tardiness = tardiness; 93 117 (eval as CVRPTWEvaluation).TravelTime = time; 94 118 95 doublepenalty = tardiness * vrptw.TardinessPenalty.Value;119 penalty = tardiness * vrptw.TardinessPenalty.Value; 96 120 eval.Penalty += penalty; 97 121 eval.Quality += penalty; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs
r4376 r4377 56 56 get { return (ValueParameter<DoubleMatrix>)Parameters["Coordinates"]; } 57 57 } 58 protected OptionalValueParameter<DoubleMatrix> DistanceMatrixParameter {59 get { return (OptionalValueParameter<DoubleMatrix>)Parameters["DistanceMatrix"]; }60 }61 58 protected ValueParameter<BoolValue> UseDistanceMatrixParameter { 62 59 get { return (ValueParameter<BoolValue>)Parameters["UseDistanceMatrix"]; } … … 80 77 set { CoordinatesParameter.Value = value; } 81 78 } 82 public DoubleMatrix DistanceMatrix {83 get { return DistanceMatrixParameter.Value; }84 set { DistanceMatrixParameter.Value = value; }85 }79 80 [Storable] 81 public DoubleMatrix DistanceMatrix { get; set; } 82 86 83 public BoolValue UseDistanceMatrix { 87 84 get { return UseDistanceMatrixParameter.Value; } … … 138 135 double distance = 0.0; 139 136 140 if (UseDistanceMatrix.Value) { 141 if (DistanceMatrixParameter.Value != null) { 142 distance = DistanceMatrixParameter.Value[start, end]; 143 } else { 144 if (DistanceMatrixParameter.ActualValue == null) { 145 DistanceMatrixParameter.ActualValue = CreateDistanceMatrix(); 146 } 147 148 distance = DistanceMatrix[start, end]; 149 } 150 } else { 137 if (DistanceMatrix == null && UseDistanceMatrix.Value) 138 DistanceMatrix = CreateDistanceMatrix(); 139 140 if(DistanceMatrix != null) 141 distance = DistanceMatrix[start, end]; 142 else 151 143 distance = CalculateDistance(start, end); 152 }153 144 154 145 return distance; … … 180 171 : base() { 181 172 Parameters.Add(new ValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.", new DoubleMatrix())); 182 Parameters.Add(new OptionalValueParameter<DoubleMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));183 173 Parameters.Add(new ValueParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false.", new BoolValue(true))); 184 174 Parameters.Add(new ValueParameter<IntValue>("Vehicles", "The number of vehicles.", new IntValue(0)));
Note: See TracChangeset
for help on using the changeset viewer.