Changeset 6607 for branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs
- Timestamp:
- 07/28/11 14:16:21 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs
r5202 r6607 80 80 81 81 public double GetTourLength(Tour tour) { 82 double length = 0; 83 84 if (tour.Stops.Count > 0) { 85 List<int> cities = new List<int>(); 86 cities.Add(0); 87 foreach (int city in tour.Stops) { 88 cities.Add(city); 89 } 90 cities.Add(0); 91 92 for (int i = 1; i < cities.Count; i++) { 93 length += ProblemInstance.GetDistance(cities[i - 1], cities[i]); 94 } 95 } 96 97 return length; 82 return tour.GetTourLength(ProblemInstance); 98 83 } 99 84 … … 105 90 tour.Stops.Insert(i, city); 106 91 107 VRPEvaluation eval = ProblemInstance.Evaluat orParameter.Value.Evaluate(ProblemInstance,tour);92 VRPEvaluation eval = ProblemInstance.Evaluate(tour); 108 93 double quality = eval.Quality + eval.Penalty * (PenaltyFactor - 1.0); 109 94 … … 122 107 } 123 108 124 public bool FindInsertionPlace(int city, int routeToAvoid, out int route, out int place) {109 public bool FindInsertionPlace(int city, int routeToAvoid, bool allowInfeasible, out int route, out int place) { 125 110 route = -1; 126 111 place = -1; 127 double minDetour = 0; 112 bool bestFeasible = false; 113 double minDetour = double.MaxValue; 128 114 129 115 for (int tour = 0; tour < Tours.Count; tour++) { 130 116 if (tour != routeToAvoid) { 131 double length = GetTourLength(Tours[tour]); 117 for (int i = 0; i <= Tours[tour].Stops.Count; i++) { 118 double length = GetTourLength(Tours[tour]); 132 119 133 for (int i = 0; i <= Tours[tour].Stops.Count; i++) {134 120 Tours[tour].Stops.Insert(i, city); 135 121 136 VRPEvaluation eval = ProblemInstance.EvaluatorParameter.Value.Evaluate( 137 ProblemInstance, Tours[tour]); 138 if (ProblemInstance.EvaluatorParameter.Value.Feasible(eval)) { 139 double newLength = eval.Distance; 122 bool feasible = ProblemInstance.Feasible(Tours[tour]); 140 123 124 if (feasible || allowInfeasible && !bestFeasible) { 125 double newLength = GetTourLength(Tours[tour]); 141 126 double detour = newLength - length; 142 127 143 if (route < = 0 || detour < minDetour) {128 if (route < 0 || detour < minDetour || feasible && !bestFeasible) { 144 129 route = tour; 145 130 place = i; 146 131 minDetour = detour; 132 133 if (feasible) 134 bestFeasible = true; 147 135 } 148 136 }
Note: See TracChangeset
for help on using the changeset viewer.