- Timestamp:
- 09/30/11 15:23:48 (13 years ago)
- Location:
- branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators
- Files:
-
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators/IterativeInsertionCreator.cs
r6753 r6857 31 31 using HeuristicLab.Problems.VehicleRouting.Interfaces; 32 32 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 33 using HeuristicLab.Problems.VehicleRouting.Variants; 33 34 34 35 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { … … 64 65 65 66 private static double CalculateAngleToDepot(IVRPProblemInstance instance, int city) { 66 double dx = instance. Coordinates[0,0];67 double dy = instance. Coordinates[0,1];67 double dx = instance.GetCoordinates(0)[0]; 68 double dy = instance.GetCoordinates(0)[1]; 68 69 69 double cx = instance. Coordinates[city,0];70 double cy = instance. Coordinates[city,1];70 double cx = instance.GetCoordinates(city)[0]; 71 double cy = instance.GetCoordinates(city)[1]; 71 72 72 73 double alpha = Math.Atan((cx - dx) / (dy - cy)) * (180.0 / Math.PI); … … 84 85 PotvinEncoding result = new PotvinEncoding(instance); 85 86 87 IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance; 88 86 89 List<int> customers = new List<int>(); 87 for (int i = 0; i < instance.Cities.Value; i++) 88 customers.Add(i + 1); 90 for (int i = 1; i <= instance.Cities.Value; i++) 91 if(pdp == null || pdp.GetDemand(i) >= 0) 92 customers.Add(i); 93 89 94 customers.Sort(delegate(int city1, int city2) 90 95 { … … 96 101 97 102 Tour currentTour = new Tour(); 103 result.Tours.Add(currentTour); 98 104 99 105 int j = random.Next(customers.Count); … … 101 107 int index = (i + j) % customers.Count; 102 108 103 int stopIdx = result.FindBestInsertionPlace(currentTour, customers[index]); 109 int stopIdx = 0; 110 if(currentTour.Stops.Count > 0) 111 result.FindBestInsertionPlace(currentTour, customers[index]); 104 112 currentTour.Stops.Insert(stopIdx, customers[index]); 105 113 106 CVRPEvaluation evaluation = instance.Evaluate(currentTour) as CVRPEvaluation; 114 if (pdp != null) { 115 stopIdx = result.FindBestInsertionPlace(currentTour, pdp.GetPickupDeliveryLocation(customers[index])); 116 currentTour.Stops.Insert(stopIdx, pdp.GetPickupDeliveryLocation(customers[index])); 117 } 118 119 CVRPEvaluation evaluation = instance.EvaluateTour(currentTour, result) as CVRPEvaluation; 107 120 if (result.Tours.Count < instance.Vehicles.Value && 108 121 ((adhereTimeWindows && !instance.Feasible(evaluation)) || ((!adhereTimeWindows) && evaluation.Overload > double.Epsilon))) { 109 currentTour.Stops.RemoveAt(stopIdx); 122 currentTour.Stops.Remove(customers[index]); 123 if (pdp != null) 124 currentTour.Stops.Remove(pdp.GetPickupDeliveryLocation(customers[index])); 110 125 111 if (currentTour.Stops.Count >0)112 result.Tours. Add(currentTour);126 if (currentTour.Stops.Count == 0) 127 result.Tours.Remove(currentTour); 113 128 currentTour = new Tour(); 129 result.Tours.Add(currentTour); 114 130 115 131 currentTour.Stops.Add(customers[index]); 132 if (pdp != null) { 133 currentTour.Stops.Add(pdp.GetPickupDeliveryLocation(customers[index])); 134 } 116 135 } 117 136 } 118 137 119 if (currentTour.Stops.Count >0)120 result.Tours. Add(currentTour);138 if (currentTour.Stops.Count == 0) 139 result.Tours.Remove(currentTour); 121 140 122 141 return result; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators/PushForwardInsertionCreator.cs
r6856 r6857 33 33 using HeuristicLab.Problems.VehicleRouting.Variants; 34 34 35 namespace HeuristicLab.Problems.VehicleRouting.Encodings. ExtendedPotvin {35 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { 36 36 [Item("PushForwardInsertionCreator", "Creates a randomly initialized VRP solution.")] 37 37 [StorableClass] 38 public sealed class PushForwardInsertionCreator : ExtendedPotvinCreator, IStochasticOperator {38 public sealed class PushForwardInsertionCreator : PotvinCreator, IStochasticOperator { 39 39 #region IStochasticOperator Members 40 40 public ILookupParameter<IRandom> RandomParameter { … … 116 116 } 117 117 118 private static ExtendedPotvinEncoding CreateSolution(IVRPProblemInstance problemInstance, IRandom random,118 private static PotvinEncoding CreateSolution(IVRPProblemInstance problemInstance, IRandom random, 119 119 double alphaValue = 0.7, double betaValue = 0.1, double gammaValue = 0.2, 120 120 double alphaVariance = 0.5, double betaVariance = 0.07, double gammaVariance = 0.14) { 121 ExtendedPotvinEncoding result = new ExtendedPotvinEncoding(problemInstance);121 PotvinEncoding result = new PotvinEncoding(problemInstance); 122 122 123 123 double alpha, beta, gamma;
Note: See TracChangeset
for help on using the changeset viewer.