Changeset 4230 for branches/VRP
- Timestamp:
- 08/16/10 15:20:29 (14 years ago)
- Location:
- branches/VRP
- Files:
-
- 11 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting.Views/3.3/VRPSolutionView.cs
r4185 r4230 119 119 if (Content.Solution != null) { 120 120 int currentTour = 0; 121 foreach (Tour tour in Content.Solution. Tours) {121 foreach (Tour tour in Content.Solution.GetTours()) { 122 122 double t = 0.0; 123 123 Point[] tourPoints = new Point[tour.Cities.Count + 2]; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/AlbaEncoding.cs
r4204 r4230 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 using System.Collections.Generic; 28 using HeuristicLab.Problems.VehicleRouting.Encodings.General; 28 29 29 30 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba { … … 35 36 36 37 #region IVRPEncoding Members 37 public ItemList<Tour> Tours { 38 get { 39 ItemList<Tour> result = new ItemList<Tour>(); 40 41 Tour tour = new Tour(); 42 for (int i = 0; i < this.array.Length; i++) { 43 if (this.array[i] >= cities) { 44 if (tour.Cities.Count > 0) { 45 result.Add(tour); 38 public List<Tour> GetTours() { 39 List<Tour> result = new List<Tour>(); 46 40 47 tour = new Tour(); 48 } 49 } else { 50 tour.Cities.Add(this.array[i] + 1); 41 Tour tour = new Tour(); 42 for (int i = 0; i < this.array.Length; i++) { 43 if (this.array[i] >= cities) { 44 if (tour.Cities.Count > 0) { 45 result.Add(tour); 46 47 tour = new Tour(); 51 48 } 49 } else { 50 tour.Cities.Add(this.array[i] + 1); 52 51 } 52 } 53 53 54 55 56 54 if (tour.Cities.Count > 0) { 55 result.Add(tour); 56 } 57 57 58 return result; 59 } 58 return result; 60 59 } 61 60 … … 93 92 94 93 public static AlbaEncoding ConvertFrom(IVRPEncoding encoding, int vehicles) { 95 ItemList<Tour> tours = encoding.Tours;94 List<Tour> tours = encoding.GetTours(); 96 95 97 96 int cities = 0; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Manipulators/IntraRouteInversionManipulator.cs
r4206 r4230 56 56 57 57 List<Tour> validTours = new List<Tour>(); 58 foreach (Tour tour in individual. Tours) {58 foreach (Tour tour in individual.GetTours()) { 59 59 if (tour.Cities.Count >= 4) 60 60 validTours.Add(tour); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Manipulators/LambdaInterchangeManipulator.cs
r4206 r4230 26 26 using HeuristicLab.Data; 27 27 using System; 28 using System.Collections.Generic; 28 29 29 30 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba { … … 45 46 public static void Apply(AlbaEncoding individual, int tour1Index, int position1, int length1, 46 47 int tour2Index, int position2, int length2) { 47 Tour tour1 = individual.Tours[tour1Index]; 48 List<Tour> tours = individual.GetTours(); 49 50 Tour tour1 = tours[tour1Index]; 48 51 int tour1Start = -1; 49 52 for (int i = 0; i < individual.Length; i++) { … … 54 57 } 55 58 56 Tour tour2 = individual.Tours[tour2Index];59 Tour tour2 = tours[tour2Index]; 57 60 int tour2Start = -1; 58 61 for (int i = 0; i < individual.Length; i++) { … … 96 99 97 100 protected override void Manipulate(IRandom rand, AlbaEncoding individual) { 101 List<Tour> tours = individual.GetTours(); 98 102 int lambda = LambdaParameter.Value.Value; 99 100 int route1Index = rand.Next(individual.Tours.Count);101 Tour route1 = individual.Tours[route1Index];102 103 103 int route2Index = rand.Next(individual.Tours.Count - 1); 104 int route1Index = rand.Next(tours.Count); 105 Tour route1 = tours[route1Index]; 106 107 int route2Index = rand.Next(tours.Count - 1); 104 108 if (route2Index >= route1Index) 105 109 route2Index += 1; 106 Tour route2 = individual.Tours[route2Index];110 Tour route2 = tours[route2Index]; 107 111 108 112 int length1 = rand.Next(Math.Min(lambda + 1, route1.Cities.Count + 1)); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/IntraRouteInversion/StochasticIntraRouteInversionSingleMoveGenerator.cs
r4206 r4230 59 59 60 60 List<Tour> validTours = new List<Tour>(); 61 foreach (Tour tour in individual. Tours) {61 foreach (Tour tour in individual.GetTours()) { 62 62 if (tour.Cities.Count >= 4) 63 63 validTours.Add(tour); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/ExhaustiveLambdaInterchangeMoveGenerator.cs
r4206 r4230 42 42 List<LambdaInterchangeMove> moves = new List<LambdaInterchangeMove>(); 43 43 44 for (int tour1Index = 0; tour1Index < individual.Tours.Count; tour1Index++) { 45 Tour tour1 = individual.Tours[tour1Index]; 46 for (int tour2Index = tour1Index + 1; tour2Index < individual.Tours.Count; tour2Index++) { 47 Tour tour2 = individual.Tours[tour2Index]; 44 List<Tour> tours = individual.GetTours(); 45 46 for (int tour1Index = 0; tour1Index < tours.Count; tour1Index++) { 47 Tour tour1 = tours[tour1Index]; 48 for (int tour2Index = tour1Index + 1; tour2Index < tours.Count; tour2Index++) { 49 Tour tour2 = tours[tour2Index]; 48 50 49 51 for (int length1 = 0; length1 <= Math.Min(lambda, tour1.Cities.Count); length1++) { -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/StochasticLambdaInterchangeSingleMoveGenerator.cs
r4206 r4230 55 55 56 56 public static LambdaInterchangeMove Apply(AlbaEncoding individual, int cities, int lambda, IRandom rand) { 57 int route1Index = rand.Next(individual.Tours.Count); 58 Tour route1 = individual.Tours[route1Index]; 57 List<Tour> tours = individual.GetTours(); 59 58 60 int route2Index = rand.Next(individual.Tours.Count - 1); 59 int route1Index = rand.Next(tours.Count); 60 Tour route1 = tours[route1Index]; 61 62 int route2Index = rand.Next(tours.Count - 1); 61 63 if (route2Index >= route1Index) 62 64 route2Index += 1; 63 Tour route2 = individual.Tours[route2Index];65 Tour route2 = tours[route2Index]; 64 66 65 67 int length1 = rand.Next(Math.Min(lambda + 1, route1.Cities.Count + 1)); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/PotvinEncoding.cs
r4177 r4230 27 27 using System.Drawing; 28 28 using System.Collections.Generic; 29 using HeuristicLab.Problems.VehicleRouting.Encodings.General; 29 30 30 31 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin { 31 32 [Item("PotvinEncoding", "Represents a potvin encoding of VRP solutions. It is implemented as described in Potvin, J.-Y. and Bengio, S. (1996). The Vehicle Routing Problem with Time Windows - Part II: Genetic Search. INFORMS Journal of Computing, 8:165–172.")] 32 33 [StorableClass] 33 public class PotvinEncoding : Item, IVRPEncoding { 34 public override Image ItemImage { 35 get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Class; } 36 } 37 38 #region IVRPEncoding Members 39 [Storable] 40 public ItemList<Tour> Tours { get; set; } 41 42 public int Cities { 43 get 44 { 45 int cities = 0; 46 47 foreach (Tour tour in Tours) { 48 cities += tour.Cities.Count; 49 } 50 51 return cities; 52 } 53 } 54 #endregion 55 34 public class PotvinEncoding : TourEncoding { 56 35 [Storable] 57 36 public List<int> Unrouted { get; set; } … … 65 44 } 66 45 67 public PotvinEncoding() { 68 Tours = new ItemList<Tour>(); 46 public PotvinEncoding(): base() { 69 47 Unrouted = new List<int>(); 48 } 49 50 [StorableConstructor] 51 private PotvinEncoding(bool serializing) 52 : base() { 70 53 } 71 54 … … 73 56 PotvinEncoding solution = new PotvinEncoding(); 74 57 75 solution.Tours.AddRange( 76 encoding.Tours); 58 TourEncoding.ConvertFrom(encoding, solution); 77 59 78 60 return solution; … … 82 64 PotvinEncoding solution = new PotvinEncoding(); 83 65 84 Tour tour = new Tour(); 85 for (int i = 0; i < route.Count; i++) { 86 if (route[i] == 0) { 87 if (tour.Cities.Count > 0) { 88 solution.Tours.Add(tour); 89 tour = new Tour(); 90 } 91 } else { 92 tour.Cities.Add(route[i]); 93 } 94 } 66 TourEncoding.ConvertFrom(route, solution); 95 67 96 68 return solution; … … 115 87 if (Tours[tour].Feasible(dueTimeArray, serviceTimeArray, readyTimeArray, demandArray, 116 88 capacity, coordinates, distanceMatrix, useDistanceMatrix)) { 117 double newLength = Tours[tour].GetLength(coordinates, distanceMatrix, useDistanceMatrix);89 double newLength = Tours[tour].GetLength(coordinates, distanceMatrix, useDistanceMatrix); 118 90 119 91 double detour = newLength - length; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Evaluators/VRPEvaluator.cs
r4179 r4230 101 101 IVRPEncoding vrpSolution = VRPToursParameter.ActualValue; 102 102 103 return vrpSolution. Tours.Count;103 return vrpSolution.GetTours().Count; 104 104 } 105 105 … … 190 190 sumEval.Tardiness = 0; 191 191 192 foreach (Tour tour in solution. Tours) {192 foreach (Tour tour in solution.GetTours()) { 193 193 TourEvaluation eval = EvaluateTour(tour, dueTimeArray, serviceTimeArray, readyTimeArray, demandArray, capacity, 194 194 fleetUsageFactor, timeFactor, distanceFactor, overloadPenalty, tardinessPenalty, -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/HeuristicLab.Problems.VehicleRouting-3.3.csproj
r4210 r4230 140 140 <Compile Include="Encodings\General\Moves\MultiVRPMoveOperator\MultiVRPMoveMaker.cs" /> 141 141 <Compile Include="Encodings\General\Moves\MultiVRPMoveOperator\MultiVRPMoveGenerator.cs" /> 142 <Compile Include="Encodings\General\TourEncoding.cs" /> 143 <Compile Include="Encodings\GVR\Crossovers\GVRCrossover.cs" /> 144 <Compile Include="Encodings\GVR\GVREncoding.cs" /> 145 <Compile Include="Encodings\GVR\Manipulators\GVRDisplacementManipulator.cs" /> 146 <Compile Include="Encodings\GVR\Manipulators\GVRInsertionManipulator.cs" /> 147 <Compile Include="Encodings\GVR\Manipulators\GVRInversionManipulator.cs" /> 148 <Compile Include="Encodings\GVR\Manipulators\GVRSwapManipulator.cs" /> 149 <Compile Include="Encodings\GVR\Manipulators\GVRManipulator.cs" /> 142 150 <Compile Include="Encodings\Potvin\Crossovers\RouteBasedCrossover.cs" /> 143 151 <Compile Include="Encodings\Potvin\Crossovers\SequenceBasedCrossover.cs" /> -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Interfaces/IVRPEncoding.cs
r4154 r4230 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Problems.VehicleRouting.Encodings; 24 using System.Collections.Generic; 24 25 25 26 namespace HeuristicLab.Problems.VehicleRouting { 26 27 public interface IVRPEncoding : IItem { 27 ItemList<Tour> Tours { 28 get; 29 } 28 List<Tour> GetTours(); 30 29 } 31 30 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/VRPOperator.cs
r4186 r4230 140 140 bool feasible = true; 141 141 142 foreach (Tour tour in solution. Tours) {142 foreach (Tour tour in solution.GetTours()) { 143 143 if (!Feasible(tour)) { 144 144 feasible = false;
Note: See TracChangeset
for help on using the changeset viewer.