Changeset 6752 for branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs
- Timestamp:
- 09/13/11 16:00:19 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs
r6710 r6752 39 39 public List<int> Unrouted { get; set; } 40 40 41 [Storable]42 public double PenaltyFactor { get; set; }43 44 41 public PotvinEncoding(IVRPProblemInstance instance) 45 42 : base(instance) { 46 43 Unrouted = new List<int>(); 47 PenaltyFactor = 1;48 44 } 49 45 … … 60 56 : base(original, cloner) { 61 57 this.Unrouted = new List<int>(original.Unrouted); 62 this.PenaltyFactor = original.PenaltyFactor;63 58 } 64 59 … … 87 82 double minQuality = -1; 88 83 84 VRPEvaluation eval = ProblemInstance.Evaluate(tour); 85 89 86 for (int i = 0; i <= tour.Stops.Count; i++) { 90 tour.Stops.Insert(i, city); 91 92 VRPEvaluation eval = ProblemInstance.Evaluate(tour); 93 double quality = eval.Quality + eval.Penalty * (PenaltyFactor - 1.0); 94 87 bool feasible; 88 double quality = ProblemInstance.GetInsertionCosts(eval, city, 0, i, out feasible); 95 89 if (place < 0 || quality < minQuality) { 96 90 place = i; 97 91 minQuality = quality; 98 92 } 99 100 tour.Stops.RemoveAt(i);101 93 } 102 94 … … 110 102 route = -1; 111 103 place = -1; 112 bool bestFeasible = false;113 104 double minDetour = double.MaxValue; 105 106 VRPEvaluation eval = ProblemInstance.Evaluate(this); 107 bool originalFeasible = ProblemInstance.Feasible(eval); 114 108 115 109 for (int tour = 0; tour < Tours.Count; tour++) { 116 110 if (tour != routeToAvoid) { 117 VRPEvaluation eval = ProblemInstance.Evaluate(Tours[tour]);118 111 double length = eval.Quality; 119 112 120 113 for (int i = 0; i <= Tours[tour].Stops.Count; i++) { 121 Tours[tour].Stops.Insert(i, city); 122 123 eval = ProblemInstance.Evaluate(Tours[tour]); 124 bool feasible = ProblemInstance.Feasible(eval); 125 126 if (feasible || allowInfeasible && !bestFeasible) { 127 double newLength = eval.Quality; 128 double detour = newLength - length; 129 130 if (route < 0 || detour < minDetour || feasible && !bestFeasible) { 114 bool feasible; 115 double detour = ProblemInstance.GetInsertionCosts(eval, city, tour, i, out feasible); 116 117 if (feasible || allowInfeasible) { 118 if (route < 0 || detour < minDetour) { 131 119 route = tour; 132 120 place = i; 133 121 minDetour = detour; 134 135 if (feasible)136 bestFeasible = true;137 122 } 138 123 } 139 140 Tours[tour].Stops.RemoveAt(i);141 124 } 142 125 }
Note: See TracChangeset
for help on using the changeset viewer.