- Timestamp:
- 01/03/11 16:18:37 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Creators/PushForwardInsertionCreator.cs
r4752 r5201 30 30 using HeuristicLab.Problems.VehicleRouting.Variants; 31 31 using HeuristicLab.Common; 32 using HeuristicLab.Problems.VehicleRouting.Interfaces; 32 33 33 34 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba { … … 83 84 84 85 // use the Box-Mueller transform in the polar form to generate a N(0,1) random variable out of two uniformly distributed random variables 85 private double Gauss(IRandom random) {86 private static double Gauss(IRandom random) { 86 87 double u = 0.0, v = 0.0, s = 0.0; 87 88 do { … … 93 94 } 94 95 95 private double N(double mu, double sigma, IRandom random) {96 private static double N(double mu, double sigma, IRandom random) { 96 97 return mu + (sigma * Gauss(random)); // transform the random variable sampled from N(0,1) to N(mu,sigma) 97 98 } 98 99 99 private double Distance(int start, int end) {100 return ProblemInstance.GetDistance(start, end);101 } 102 103 private double TravelDistance(List<int> route, int begin) {100 private static double Distance(IVRPProblemInstance problemInstance, int start, int end) { 101 return problemInstance.GetDistance(start, end); 102 } 103 104 private static double TravelDistance(IVRPProblemInstance problemInstance, List<int> route, int begin) { 104 105 double distance = 0; 105 106 for (int i = begin; i < route.Count - 1 && (i == begin || route[i] != 0); i++) { 106 distance += Distance( route[i], route[i + 1]);107 distance += Distance(problemInstance, route[i], route[i + 1]); 107 108 } 108 109 return distance; 109 110 } 110 111 111 private bool SubrouteConstraintsOK(List<int> route, int begin) {112 Tour subroute = new Tour();113 subroute.Stops.AddRange(route.GetRange(begin, 114 route.Count - begin));115 116 return ProblemInstance.Feasible(subroute); 117 }118 119 protected override List<int> CreateSolution() {112 private static bool SubrouteConstraintsOK(IVRPProblemInstance problemInstance, List<int> route, int begin) { 113 AlbaEncoding solution = AlbaEncoding.ConvertFrom(route, problemInstance); 114 115 return problemInstance.Feasible(solution); 116 } 117 118 public static List<int> CreateSolution(IVRPProblemInstance problemInstance, IRandom random, 119 double alphaValue = 0.7, double betaValue = 0.1, double gammaValue = 0.2, 120 double alphaVariance = 0.5, double betaVariance = 0.07, double gammaVariance = 0.14) { 120 121 double alpha, beta, gamma; 121 alpha = N( Alpha.Value.Value, Math.Sqrt(AlphaVariance.Value.Value), RandomParameter.ActualValue);122 beta = N( Beta.Value.Value, Math.Sqrt(BetaVariance.Value.Value), RandomParameter.ActualValue);123 gamma = N( Gamma.Value.Value, Math.Sqrt(GammaVariance.Value.Value), RandomParameter.ActualValue);124 125 double x0 = ProblemInstance.Coordinates[0, 0];126 double y0 = ProblemInstance.Coordinates[0, 1];122 alpha = N(alphaValue, Math.Sqrt(alphaVariance), random); 123 beta = N(betaValue, Math.Sqrt(betaVariance), random); 124 gamma = N(gammaValue, Math.Sqrt(gammaVariance), random); 125 126 double x0 = problemInstance.Coordinates[0, 0]; 127 double y0 = problemInstance.Coordinates[0, 1]; 127 128 double distance = 0; 128 129 double cost = 0; … … 138 139 *----------------------------------------------------------------------------- 139 140 */ 140 for (int i = 1; i <= ProblemInstance.Cities.Value; i++) {141 distance = Distance( i, 0);142 if ( ProblemInstance.Coordinates[i, 0] < x0) distance = -distance;141 for (int i = 1; i <= problemInstance.Cities.Value; i++) { 142 distance = Distance(problemInstance, i, 0); 143 if (problemInstance.Coordinates[i, 0] < x0) distance = -distance; 143 144 144 145 cost = -alpha * distance + // distance 0 <-> City[i] 145 beta * ( ProblemInstance as ITimeWindowedProblemInstance).DueTime[i] + // latest arrival time146 gamma * (Math.Asin(( ProblemInstance.Coordinates[i, 1] - y0) / distance) / 360 * distance); // polar angle146 beta * (problemInstance as ITimeWindowedProblemInstance).DueTime[i] + // latest arrival time 147 gamma * (Math.Asin((problemInstance.Coordinates[i, 1] - y0) / distance) / 360 * distance); // polar angle 147 148 148 149 index = 0; … … 161 162 int customer = -1; 162 163 int subTourCount = 1; 163 List<int> route = new List<int>( ProblemInstance.Cities.Value + ProblemInstance.Vehicles.Value - 1);164 List<int> route = new List<int>(problemInstance.Cities.Value + problemInstance.Vehicles.Value - 1); 164 165 minimumCost = double.MaxValue; 165 166 indexOfMinimumCost = -1; … … 176 177 route.Insert(i, (int)unroutedList[c]); 177 178 if (route[currentRoute] != 0) { throw new Exception("currentRoute not depot"); } 178 cost = TravelDistance( route, currentRoute);179 if (cost < minimumCost && SubrouteConstraintsOK( route, currentRoute)) {179 cost = TravelDistance(problemInstance, route, currentRoute); 180 if (cost < minimumCost && SubrouteConstraintsOK(problemInstance, route, currentRoute)) { 180 181 minimumCost = cost; 181 182 indexOfMinimumCost = i; … … 207 208 customer = -1; 208 209 } while (unroutedList.Count > 0); 209 while (route.Count < ProblemInstance.Cities.Value + ProblemInstance.Vehicles.Value)210 while (route.Count < problemInstance.Cities.Value + problemInstance.Vehicles.Value) 210 211 route.Add(0); 211 212 212 213 return route; 214 } 215 216 protected override List<int> CreateSolution() { 217 return CreateSolution(ProblemInstance, RandomParameter.ActualValue, 218 Alpha.Value.Value, Beta.Value.Value, Gamma.Value.Value, 219 AlphaVariance.Value.Value, BetaVariance.Value.Value, GammaVariance.Value.Value); 213 220 } 214 221 }
Note: See TracChangeset
for help on using the changeset viewer.