Changeset 6838
- Timestamp:
- 09/27/11 13:29:56 (13 years ago)
- Location:
- branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4
- Files:
-
- 1 added
- 1 deleted
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators/IterativeInsertionCreator.cs
r6788 r6838 101 101 102 102 Tour currentTour = new Tour(); 103 result.Tours.Add(currentTour); 103 104 104 105 int j = random.Next(customers.Count); … … 114 115 } 115 116 116 CVRPEvaluation evaluation = instance.Evaluate (currentTour) as CVRPEvaluation;117 CVRPEvaluation evaluation = instance.EvaluateTour(currentTour, result) as CVRPEvaluation; 117 118 if (result.Tours.Count < instance.Vehicles.Value && 118 119 ((adhereTimeWindows && !instance.Feasible(evaluation)) || ((!adhereTimeWindows) && evaluation.Overload > double.Epsilon))) { … … 132 133 } 133 134 134 if (currentTour.Stops.Count >0)135 result.Tours. Add(currentTour);135 if (currentTour.Stops.Count == 0) 136 result.Tours.Remove(currentTour); 136 137 137 138 return result; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinInsertionBasedCrossover.cs
r6752 r6838 149 149 150 150 private bool FindRouteInsertionPlace( 151 PotvinEncoding individual, 151 152 Tour tour, 152 153 int city, bool allowInfeasible, out int place) { … … 162 163 163 164 double minDetour = 0; 164 VRPEvaluation eval = ProblemInstance.Evaluate (tour);165 VRPEvaluation eval = ProblemInstance.EvaluateTour(tour, individual); 165 166 bool originalFeasible = ProblemInstance.Feasible(eval); 166 167 … … 220 221 221 222 Tour childTour = new Tour(); 223 child.Tours.Add(childTour); 222 224 childTour.Stops.AddRange(r1.Stops); 223 225 … … 233 235 234 236 while (count < maxCount && R2.Count != 0) { 235 PotvinEncoding newChild = child.Clone() as PotvinEncoding;236 newChild.Tours.Add(childTour);237 238 237 int index = random.Next(R2.Count); 239 238 int city = R2[index]; … … 241 240 242 241 int place = -1; 243 bool found = FindRouteInsertionPlace(child Tour, city, allowInfeasible, out place);242 bool found = FindRouteInsertionPlace(child, childTour, city, allowInfeasible, out place); 244 243 if (found) { 245 244 childTour.Stops.Insert(place, city); … … 253 252 } 254 253 255 child.Tours.Add(childTour);256 254 Repair(random, child, childTour, ProblemInstance, allowInfeasible); 257 255 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinLocalSearchManipulator.cs
r4752 r6838 69 69 distance = individual.GetTourLength(individual.Tours[currentTour]); 70 70 individual.Tours[currentTour].Stops.InsertRange(currentCity, toBeDeleted); 71 if (ProblemInstance. Feasible(individual.Tours[currentTour])) {71 if (ProblemInstance.TourFeasible(individual.Tours[currentTour], individual)) { 72 72 double lengthIncrease = 73 73 individual.GetTourLength(individual.Tours[currentTour]) - distance; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Manipulators/PotvinTwoLevelExchangeManipulator.cs
r6796 r6838 66 66 route1.Stops.RemoveAt(customer1Position); 67 67 68 if (ProblemInstance. Feasible(tour)) {68 if (ProblemInstance.TourFeasible(tour, individual)) { 69 69 int routeIdx, place; 70 70 if (FindInsertionPlace(individual, -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDRearrange/PotvinPDRearrangeMoveMaker.cs
r6806 r6838 61 61 public static void InsertPair(PotvinEncoding solution, Tour tour, int source, int target, IVRPProblemInstance problemInstance, int positionToAvoid = -1, int positionToAvoid2 = -1) { 62 62 int stops = tour.Stops.Count; 63 VRPEvaluation eval = problemInstance.Evaluate (tour);63 VRPEvaluation eval = problemInstance.EvaluateTour(tour, solution); 64 64 double minCosts = double.MaxValue; 65 65 int sourceLocation = -1; … … 68 68 for (int i = 0; i <= stops; i++) { 69 69 tour.Stops.Insert(i, source); 70 VRPEvaluation tourEval = problemInstance.Evaluate (tour);70 VRPEvaluation tourEval = problemInstance.EvaluateTour(tour, solution); 71 71 double sourceCosts = tourEval.Quality - eval.Quality; 72 72 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs
r6771 r6838 82 82 double minQuality = -1; 83 83 84 VRPEvaluation eval = ProblemInstance.Evaluate (tour);84 VRPEvaluation eval = ProblemInstance.EvaluateTour(tour, this); 85 85 86 86 for (int i = 0; i <= tour.Stops.Count; i++) { -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/PrinsEncoding.cs
r6758 r6838 61 61 62 62 VRPEvaluation eval = 63 ProblemInstance.Evaluate (tour);63 ProblemInstance.EvaluateTour(tour, this); 64 64 65 65 double cost = eval.Quality; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Zhu/ZhuEncoding.cs
r4752 r6838 43 43 int city = this[i] + 1; 44 44 newTour.Stops.Add(city); 45 if (!ProblemInstance. Feasible(newTour)) {45 if (!ProblemInstance.TourFeasible(newTour, this)) { 46 46 newTour.Stops.Remove(city); 47 47 if (newTour.Stops.Count > 0) -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/HeuristicLab.Problems.VehicleRouting-3.4.csproj
r6773 r6838 129 129 <Compile Include="Encodings\Alba\AlbaEncoding.cs" /> 130 130 <Compile Include="Encodings\Alba\Creators\DefaultRepresentationCreator.cs" /> 131 <Compile Include="Encodings\Alba\Creators\PushForwardInsertionCreator.cs" />132 131 <Compile Include="Encodings\Alba\Creators\RandomCreator.cs" /> 133 132 <Compile Include="Encodings\Alba\Creators\AlbaCreator.cs" /> … … 203 202 <Compile Include="Encodings\GVR\Manipulators\GVRManipulator.cs" /> 204 203 <Compile Include="Encodings\GVR\Manipulators\GVRSwapManipulator.cs" /> 204 <Compile Include="Encodings\Potvin\Creators\PushForwardInsertionCreator.cs" /> 205 205 <Compile Include="Encodings\Potvin\Creators\PotvinCreator.cs" /> 206 206 <Compile Include="Encodings\Potvin\Creators\IterativeInsertionCreator.cs" /> -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPEvaluator.cs
r6752 r6838 33 33 34 34 VRPEvaluation Evaluate(IVRPProblemInstance instance, IVRPEncoding solution); 35 VRPEvaluation Evaluate (IVRPProblemInstance instance, Tour tour);35 VRPEvaluation EvaluateTour(IVRPProblemInstance instance, Tour tour, IVRPEncoding solution); 36 36 bool Feasible(VRPEvaluation evaluation); 37 37 double GetInsertionCosts(IVRPProblemInstance instance, VRPEvaluation eval, int customer, int tour, int index, out bool feasible); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPProblemInstance.cs
r6752 r6838 50 50 double GetDistance(int start, int end); 51 51 bool Feasible(IVRPEncoding solution); 52 bool Feasible(Tour tour);52 bool TourFeasible(Tour tour, IVRPEncoding solution); 53 53 VRPEvaluation Evaluate(IVRPEncoding solution); 54 VRPEvaluation Evaluate (Tour tour);54 VRPEvaluation EvaluateTour(Tour tour, IVRPEncoding solution); 55 55 bool Feasible(VRPEvaluation eval); 56 56 double GetInsertionCosts(VRPEvaluation eval, int customer, int tour, int index, out bool feasible); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluator.cs
r6752 r6838 47 47 } 48 48 49 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour ) {49 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) { 50 50 TourInsertionInfo tourInfo = new TourInsertionInfo(); 51 51 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluator.cs
r6752 r6838 47 47 } 48 48 49 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour ) {49 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) { 50 50 TourInsertionInfo tourInfo = new TourInsertionInfo(); 51 51 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluator.cs
r6752 r6838 51 51 } 52 52 53 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour ) {53 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) { 54 54 TourInsertionInfo tourInfo = new TourInsertionInfo(); 55 55 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/SingleDepotVRPEvaluator.cs
r6752 r6838 40 40 [StorableClass] 41 41 public class SingleDepotVRPEvaluator: VRPEvaluator { 42 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour ) {42 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) { 43 43 TourInsertionInfo tourInfo = new TourInsertionInfo(); 44 44 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPEvaluator.cs
r6752 r6838 81 81 } 82 82 83 protected abstract void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour );83 protected abstract void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution); 84 84 85 85 protected virtual void InitResultParameters() { … … 95 95 DistanceParameter.ActualValue.Value = tourEvaluation.Distance; 96 96 PenaltyParameter.ActualValue.Value = tourEvaluation.Penalty; 97 }98 99 private VRPEvaluation EvaluateTour(IVRPProblemInstance instance, Tour tour) {100 VRPEvaluation evaluation = CreateTourEvaluation();101 EvaluateTour(evaluation, instance, tour);102 return evaluation;103 97 } 104 98 … … 123 117 } 124 118 119 public VRPEvaluation EvaluateTour(IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) { 120 VRPEvaluation evaluation = CreateTourEvaluation(); 121 EvaluateTour(evaluation, instance, tour, solution); 122 return evaluation; 123 } 124 125 125 public VRPEvaluation Evaluate(IVRPProblemInstance instance, IVRPEncoding solution) { 126 126 VRPEvaluation evaluation = CreateTourEvaluation(); 127 127 128 128 foreach (Tour tour in solution.GetTours()) { 129 EvaluateTour(evaluation, instance, tour );129 EvaluateTour(evaluation, instance, tour, solution); 130 130 } 131 131 132 132 return evaluation; 133 }134 135 public VRPEvaluation Evaluate(IVRPProblemInstance instance, Tour tour) {136 return EvaluateTour(instance, tour);137 133 } 138 134 … … 141 137 142 138 VRPEvaluation evaluation = CreateTourEvaluation(); 143 foreach (Tour tour in VRPToursParameter.ActualValue.GetTours()) { 144 EvaluateTour(evaluation, ProblemInstance, tour); 139 IVRPEncoding solution = VRPToursParameter.ActualValue; 140 foreach (Tour tour in solution.GetTours()) { 141 EvaluateTour(evaluation, ProblemInstance, tour, solution); 145 142 } 146 143 SetResultParameters(evaluation); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs
r6752 r6838 212 212 } 213 213 214 public bool Feasible(Tour tour) {214 public bool TourFeasible(Tour tour, IVRPEncoding solution) { 215 215 return evaluator.Feasible( 216 evaluator.Evaluate (217 this, tour ));216 evaluator.EvaluateTour( 217 this, tour, solution)); 218 218 } 219 219 … … 222 222 } 223 223 224 public VRPEvaluation Evaluate (Tour tour) {225 return evaluator.Evaluate (this, tour);224 public VRPEvaluation EvaluateTour(Tour tour, IVRPEncoding solution) { 225 return evaluator.EvaluateTour(this, tour, solution); 226 226 } 227 227
Note: See TracChangeset
for help on using the changeset viewer.