- Timestamp:
- 09/30/11 15:23:48 (13 years ago)
- Location:
- branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin
- Files:
-
- 13 added
- 10 edited
- 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; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinRouteBasedCrossover.cs
r6851 r6857 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Common; 28 using HeuristicLab.Problems.VehicleRouting.Encodings.ExtendedPotvin;29 28 30 29 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { … … 60 59 child.Tours.Insert(tourParent2, replacing); 61 60 62 if (parent1 is ExtendedPotvinEncoding && child is ExtendedPotvinEncoding) { 63 Permutation vehicleAssignment = (child as ExtendedPotvinEncoding).VehicleAssignment; 61 Permutation vehicleAssignment = child.VehicleAssignment; 64 62 65 63 int vehicle = vehicleAssignment[tourParent2]; 66 int vehicle2 = (parent1 as ExtendedPotvinEncoding).VehicleAssignment[tourParent1];64 int vehicle2 = parent1.VehicleAssignment[tourParent1]; 67 65 vehicleAssignment[tourParent2] = vehicle2; 68 66 … … 73 71 } 74 72 } 75 }76 73 77 74 foreach (int city in replaced.Stops) -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/IPotvinOperator.cs
r4376 r6857 32 32 33 33 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { 34 public interface IPotvinOperator : 35 ISingleDepotOperator, IHomogenousCapacitatedOperator, ITimeWindowedOperator { 34 public interface IPotvinOperator : 35 ISingleDepotOperator, IHomogenousCapacitatedOperator, ITimeWindowedOperator, 36 IMultiDepotOperator, IHeterogenousCapacitatedOperator { 36 37 } 37 38 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/CustomerRelocation/PotvinCustomerRelocationMoveMaker.cs
r6751 r6857 89 89 PotvinEncoding newSolution = move.Individual.Clone() as PotvinEncoding; 90 90 Apply(newSolution, move, ProblemInstance); 91 newSolution.Repair(); 91 92 VRPToursParameter.ActualValue = newSolution; 92 93 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDExchange/PotvinPDExchangeMoveMaker.cs
r6856 r6857 98 98 PotvinEncoding newSolution = move.Individual.Clone() as PotvinEncoding; 99 99 Apply(newSolution, move, ProblemInstance); 100 newSolution.Repair(); 100 101 VRPToursParameter.ActualValue = newSolution; 101 102 //reset move quality103 VRPEvaluation eval = ProblemInstance.Evaluate(newSolution);104 MoveQualityParameter.ActualValue.Value = eval.Quality;105 102 } 106 103 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDExchange/PotvinPDExchangeMoveTabuCriterion.cs
r6797 r6857 116 116 PotvinPDRelocateMoveAttribute attribute = tabuMove as PotvinPDRelocateMoveAttribute; 117 117 118 double distance = 0; 119 if (MoveDistanceParameter.ActualValue != null) 120 distance = MoveDistanceParameter.ActualValue.Value; 118 if (attribute != null) { 119 double distance = 0; 120 if (MoveDistanceParameter.ActualValue != null) 121 distance = MoveDistanceParameter.ActualValue.Value; 121 122 122 double overload = 0;123 if (MoveOverloadParameter.ActualValue != null)124 overload = MoveOverloadParameter.ActualValue.Value;123 double overload = 0; 124 if (MoveOverloadParameter.ActualValue != null) 125 overload = MoveOverloadParameter.ActualValue.Value; 125 126 126 double tardiness = 0;127 if (MoveTardinessParameter.ActualValue != null)128 tardiness = MoveTardinessParameter.ActualValue.Value;127 double tardiness = 0; 128 if (MoveTardinessParameter.ActualValue != null) 129 tardiness = MoveTardinessParameter.ActualValue.Value; 129 130 130 IVRPProblemInstance instance = ProblemInstanceParameter.ActualValue;131 double quality = attribute.Distance * instance.DistanceFactor.Value;131 IVRPProblemInstance instance = ProblemInstanceParameter.ActualValue; 132 double quality = attribute.Distance * instance.DistanceFactor.Value; 132 133 133 IHomogenousCapacitatedProblemInstance cvrp = instance as IHomogenousCapacitatedProblemInstance;134 if (cvrp != null)135 quality += attribute.Overload * cvrp.OverloadPenalty.Value;134 IHomogenousCapacitatedProblemInstance cvrp = instance as IHomogenousCapacitatedProblemInstance; 135 if (cvrp != null) 136 quality += attribute.Overload * cvrp.OverloadPenalty.Value; 136 137 137 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;138 if (vrptw != null)139 quality += attribute.Tardiness * vrptw.TardinessPenalty.Value;138 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance; 139 if (vrptw != null) 140 quality += attribute.Tardiness * vrptw.TardinessPenalty.Value; 140 141 141 if (!useAspiration || moveQuality >= quality) {142 if ((attribute.City == move.City && attribute.Tour == move.Tour) ||143 (attribute.City == move.Replaced && attribute.Tour == move.OldTour)) {144 isTabu = true;145 break;146 }142 if (!useAspiration || moveQuality >= quality) { 143 if ((attribute.City == move.City && attribute.Tour == move.Tour) || 144 (attribute.City == move.Replaced && attribute.Tour == move.OldTour)) { 145 isTabu = true; 146 break; 147 } 147 148 148 if (attribute.Distance == distance && attribute.Overload == overload && attribute.Tardiness == tardiness) { 149 isTabu = true; 150 break; 149 if (attribute.Distance == distance && attribute.Overload == overload && attribute.Tardiness == tardiness) { 150 isTabu = true; 151 break; 152 } 151 153 } 152 154 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDRearrange/PotvinPDRearrangeMoveMaker.cs
r6856 r6857 117 117 PotvinEncoding newSolution = move.Individual.Clone() as PotvinEncoding; 118 118 Apply(newSolution, move, ProblemInstance); 119 newSolution.Repair(); 119 120 VRPToursParameter.ActualValue = newSolution; 120 121 //reset move quality122 VRPEvaluation eval = ProblemInstance.Evaluate(newSolution);123 MoveQualityParameter.ActualValue.Value = eval.Quality;124 121 } 125 122 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDRearrange/PotvinPDRearrangeMoveTabuCriterion.cs
r6797 r6857 116 116 PotvinPDRelocateMoveAttribute attribute = tabuMove as PotvinPDRelocateMoveAttribute; 117 117 118 double distance = 0; 119 if (MoveDistanceParameter.ActualValue != null) 120 distance = MoveDistanceParameter.ActualValue.Value; 118 if (attribute != null) { 119 double distance = 0; 120 if (MoveDistanceParameter.ActualValue != null) 121 distance = MoveDistanceParameter.ActualValue.Value; 121 122 122 double overload = 0;123 if (MoveOverloadParameter.ActualValue != null)124 overload = MoveOverloadParameter.ActualValue.Value;123 double overload = 0; 124 if (MoveOverloadParameter.ActualValue != null) 125 overload = MoveOverloadParameter.ActualValue.Value; 125 126 126 double tardiness = 0;127 if (MoveTardinessParameter.ActualValue != null)128 tardiness = MoveTardinessParameter.ActualValue.Value;127 double tardiness = 0; 128 if (MoveTardinessParameter.ActualValue != null) 129 tardiness = MoveTardinessParameter.ActualValue.Value; 129 130 130 IVRPProblemInstance instance = ProblemInstanceParameter.ActualValue;131 double quality = attribute.Distance * instance.DistanceFactor.Value;131 IVRPProblemInstance instance = ProblemInstanceParameter.ActualValue; 132 double quality = attribute.Distance * instance.DistanceFactor.Value; 132 133 133 IHomogenousCapacitatedProblemInstance cvrp = instance as IHomogenousCapacitatedProblemInstance;134 if (cvrp != null)135 quality += attribute.Overload * cvrp.OverloadPenalty.Value;134 IHomogenousCapacitatedProblemInstance cvrp = instance as IHomogenousCapacitatedProblemInstance; 135 if (cvrp != null) 136 quality += attribute.Overload * cvrp.OverloadPenalty.Value; 136 137 137 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;138 if (vrptw != null)139 quality += attribute.Tardiness * vrptw.TardinessPenalty.Value;138 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance; 139 if (vrptw != null) 140 quality += attribute.Tardiness * vrptw.TardinessPenalty.Value; 140 141 141 if (!useAspiration || moveQuality >= quality) {142 if (attribute.City == move.City && attribute.Tour == move.Tour) {143 isTabu = true;144 break;145 }142 if (!useAspiration || moveQuality >= quality) { 143 if (attribute.City == move.City && attribute.Tour == move.Tour) { 144 isTabu = true; 145 break; 146 } 146 147 147 if (attribute.Distance == distance && attribute.Overload == overload && attribute.Tardiness == tardiness) { 148 isTabu = true; 149 break; 148 if (attribute.Distance == distance && attribute.Overload == overload && attribute.Tardiness == tardiness) { 149 isTabu = true; 150 break; 151 } 150 152 } 151 153 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDShift/PotvinPDShiftMoveMaker.cs
r6856 r6857 86 86 PotvinEncoding newSolution = move.Individual.Clone() as PotvinEncoding; 87 87 Apply(newSolution, move, ProblemInstance); 88 newSolution.Repair(); 88 89 VRPToursParameter.ActualValue = newSolution; 89 90 //reset move quality91 VRPEvaluation eval = ProblemInstance.Evaluate(newSolution);92 MoveQualityParameter.ActualValue.Value = eval.Quality;93 90 } 94 91 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Moves/PickupDelivery/PDShift/PotvinPDShiftMoveTabuCriterion.cs
r6797 r6857 116 116 PotvinPDRelocateMoveAttribute attribute = tabuMove as PotvinPDRelocateMoveAttribute; 117 117 118 double distance = 0; 119 if (MoveDistanceParameter.ActualValue != null) 120 distance = MoveDistanceParameter.ActualValue.Value; 118 if (attribute != null) { 119 double distance = 0; 120 if (MoveDistanceParameter.ActualValue != null) 121 distance = MoveDistanceParameter.ActualValue.Value; 121 122 122 double overload = 0;123 if (MoveOverloadParameter.ActualValue != null)124 overload = MoveOverloadParameter.ActualValue.Value;123 double overload = 0; 124 if (MoveOverloadParameter.ActualValue != null) 125 overload = MoveOverloadParameter.ActualValue.Value; 125 126 126 double tardiness = 0;127 if (MoveTardinessParameter.ActualValue != null)128 tardiness = MoveTardinessParameter.ActualValue.Value;127 double tardiness = 0; 128 if (MoveTardinessParameter.ActualValue != null) 129 tardiness = MoveTardinessParameter.ActualValue.Value; 129 130 130 IVRPProblemInstance instance = ProblemInstanceParameter.ActualValue;131 double quality = attribute.Distance * instance.DistanceFactor.Value;131 IVRPProblemInstance instance = ProblemInstanceParameter.ActualValue; 132 double quality = attribute.Distance * instance.DistanceFactor.Value; 132 133 133 IHomogenousCapacitatedProblemInstance cvrp = instance as IHomogenousCapacitatedProblemInstance;134 if (cvrp != null)135 quality += attribute.Overload * cvrp.OverloadPenalty.Value;134 IHomogenousCapacitatedProblemInstance cvrp = instance as IHomogenousCapacitatedProblemInstance; 135 if (cvrp != null) 136 quality += attribute.Overload * cvrp.OverloadPenalty.Value; 136 137 137 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;138 if (vrptw != null)139 quality += attribute.Tardiness * vrptw.TardinessPenalty.Value;138 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance; 139 if (vrptw != null) 140 quality += attribute.Tardiness * vrptw.TardinessPenalty.Value; 140 141 141 if (!useAspiration || moveQuality >= quality) {142 if (attribute.City == move.City && attribute.Tour == move.Tour) {143 isTabu = true;144 break;145 }142 if (!useAspiration || moveQuality >= quality) { 143 if (attribute.City == move.City && attribute.Tour == move.Tour) { 144 isTabu = true; 145 break; 146 } 146 147 147 if (attribute.Distance == distance && attribute.Overload == overload && attribute.Tardiness == tardiness) { 148 isTabu = true; 149 break; 148 if (attribute.Distance == distance && attribute.Overload == overload && attribute.Tardiness == tardiness) { 149 isTabu = true; 150 break; 151 } 150 152 } 151 153 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs
r6851 r6857 39 39 public List<int> Unrouted { get; set; } 40 40 41 [Storable] 42 public Permutation VehicleAssignment { get; private set; } 43 41 44 public PotvinEncoding(IVRPProblemInstance instance) 42 45 : base(instance) { 43 46 Unrouted = new List<int>(); 47 VehicleAssignment = new Permutation(PermutationTypes.Absolute, instance.Vehicles.Value); 44 48 } 45 49 … … 56 60 : base(original, cloner) { 57 61 this.Unrouted = new List<int>(original.Unrouted); 62 this.VehicleAssignment = cloner.Clone<Permutation>(original.VehicleAssignment); 63 } 64 65 public override int GetVehicleAssignment(int tour) { 66 return VehicleAssignment[tour]; 58 67 } 59 68 … … 62 71 63 72 TourEncoding.ConvertFrom(encoding, solution, instance); 73 74 List<int> vehicles = new List<int>(); 75 for (int i = 0; i < instance.Vehicles.Value; i++) 76 vehicles.Add(i); 77 78 int[] assignment = new int[instance.Vehicles.Value]; 79 for (int i = 0; i < assignment.Length; i++) 80 assignment[i] = -1; 81 82 for (int i = 0; i < solution.Tours.Count; i++) { 83 int vehicle = encoding.GetVehicleAssignment(i); 84 assignment[i] = vehicle; 85 vehicles.Remove(vehicle); 86 } 87 88 for (int i = 0; i < instance.Vehicles.Value; i++) { 89 if (assignment[i] == -1) { 90 int vehicle = vehicles[0]; 91 assignment[i] = vehicle; 92 vehicles.RemoveAt(0); 93 } 94 } 95 96 solution.VehicleAssignment = new Permutation(PermutationTypes.Absolute, assignment); 64 97 65 98 return solution; … … 79 112 80 113 public int FindBestInsertionPlace(Tour tour, int city, int positionToAvoid = -1) { 114 if (tour.Stops.Count == 0) 115 return 0; 116 81 117 int place = -1; 82 118 double minQuality = -1;
Note: See TracChangeset
for help on using the changeset viewer.