- Timestamp:
- 08/06/10 16:08:46 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings
- Files:
-
- 5 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/AlbaEncoding.cs
r4150 r4174 42 42 for (int i = 0; i < this.array.Length; i++) { 43 43 if (this.array[i] >= cities) { 44 if (tour.C ount > 0) {44 if (tour.Cities.Count > 0) { 45 45 result.Add(tour); 46 46 … … 48 48 } 49 49 } else { 50 tour. Add(new IntValue(this.array[i] + 1));50 tour.Cities.Add(this.array[i] + 1); 51 51 } 52 52 } 53 53 54 if (tour.C ount > 0) {54 if (tour.Cities.Count > 0) { 55 55 result.Add(tour); 56 56 } … … 97 97 int cities = 0; 98 98 foreach (Tour tour in tours) { 99 cities += tour.C ount;99 cities += tour.Cities.Count; 100 100 } 101 101 … … 107 107 108 108 foreach (Tour tour in tours) { 109 foreach ( IntValue city in tour) {110 array[arrayIndex] = city .Value- 1;109 foreach (int city in tour.Cities) { 110 array[arrayIndex] = city - 1; 111 111 arrayIndex++; 112 112 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/PotvinEncoding.cs
r4150 r4174 31 31 [Item("PotvinEncoding", "Represents a potvin encoding of VRP solutions.")] 32 32 [StorableClass] 33 class PotvinEncoding : Item, IVRPEncoding {33 public class PotvinEncoding : Item, IVRPEncoding { 34 34 public override Image ItemImage { 35 35 get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Class; } … … 46 46 47 47 foreach (Tour tour in Tours) { 48 cities += tour.C ount;48 cities += tour.Cities.Count; 49 49 } 50 50 … … 55 55 56 56 [Storable] 57 public ItemList<IntValue> Unrouted { get; set; }57 public List<int> Unrouted { get; set; } 58 58 59 59 public override IDeepCloneable Clone(HeuristicLab.Common.Cloner cloner) { … … 61 61 cloner.RegisterClonedObject(this, clone); 62 62 clone.Tours = (ItemList<Tour>)cloner.Clone(this.Tours); 63 clone.Unrouted = (ItemList<IntValue>)cloner.Clone(this.Unrouted);63 clone.Unrouted = new List<int>(Unrouted); 64 64 return clone; 65 65 } … … 67 67 public PotvinEncoding() { 68 68 Tours = new ItemList<Tour>(); 69 Unrouted = new ItemList<IntValue>();69 Unrouted = new List<int>(); 70 70 } 71 71 … … 85 85 for (int i = 0; i < route.Count; i++) { 86 86 if (route[i] == 0) { 87 if (tour.C ount > 0) {87 if (tour.Cities.Count > 0) { 88 88 solution.Tours.Add(tour); 89 89 tour = new Tour(); 90 90 } 91 91 } else { 92 tour. Add(new IntValue(route[i]));92 tour.Cities.Add(route[i]); 93 93 } 94 94 } … … 96 96 return solution; 97 97 } 98 99 public bool FindInsertionPlace( 100 DoubleArray dueTimeArray, 101 DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity, 102 DoubleMatrix coordinates, ILookupParameter<DoubleMatrix> distanceMatrix, BoolValue useDistanceMatrix, 103 int city, int routeToAvoid, out int route, out int place) { 104 route = -1; 105 place = -1; 106 double minDetour = 0; 107 108 for (int tour = 0; tour < Tours.Count; tour++) { 109 if (tour != routeToAvoid) { 110 for (int i = 0; i <= Tours[tour].Cities.Count; i++) { 111 double length = Tours[tour].GetLength(coordinates, distanceMatrix, useDistanceMatrix); 112 113 Tours[tour].Cities.Insert(i, city); 114 115 if (Tours[tour].Feasible(dueTimeArray, serviceTimeArray, readyTimeArray, demandArray, 116 capacity, coordinates, distanceMatrix, useDistanceMatrix)) { 117 double newLength = Tours[tour].GetLength(coordinates, distanceMatrix, useDistanceMatrix); 118 119 double detour = newLength - length; 120 121 if (route <= 0 || detour < minDetour) { 122 route = tour; 123 place = i; 124 minDetour = detour; 125 } 126 } 127 128 Tours[tour].Cities.RemoveAt(i); 129 } 130 } 131 } 132 133 return route >= 0 && place >= 0; 134 } 98 135 } 99 136 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Tour.cs
r4068 r4174 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Data; 24 using System.Collections.Generic; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Common; 24 27 25 28 namespace HeuristicLab.Problems.VehicleRouting.Encodings { 26 public class Tour : ItemList<IntValue> { 29 [StorableClass] 30 public class Tour : Item { 31 [Storable] 32 public List<int> Cities { get; private set; } 33 34 public Tour() { 35 Cities = new List<int>(); 36 } 37 38 public override IDeepCloneable Clone(Cloner cloner) { 39 Tour clone = base.Clone(cloner) as Tour; 40 clone.Cities = new List<int>(Cities); 41 42 return clone; 43 } 44 45 public bool Feasible(DoubleArray dueTimeArray, 46 DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity, 47 DoubleMatrix coordinates, ILookupParameter<DoubleMatrix> distanceMatrix, BoolValue useDistanceMatrix) { 48 TourEvaluation eval = VRPEvaluator.EvaluateTour(this, 49 dueTimeArray, 50 serviceTimeArray, 51 readyTimeArray, 52 demandArray, 53 capacity, 54 new DoubleValue(0), 55 new DoubleValue(0), 56 new DoubleValue(0), 57 new DoubleValue(1), 58 new DoubleValue(1), 59 coordinates, 60 distanceMatrix, 61 useDistanceMatrix); 62 63 return eval.Overload < double.Epsilon && eval.Tardiness < double.Epsilon; 64 } 65 66 public double GetLength(DoubleMatrix coordinates, 67 ILookupParameter<DoubleMatrix> distanceMatrix, 68 BoolValue useDistanceMatrix) { 69 double length = 0; 70 71 if (Cities.Count > 0) { 72 List<int> cities = new List<int>(); 73 cities.Add(0); 74 foreach (int city in Cities) { 75 cities.Add(city); 76 } 77 cities.Add(0); 78 79 for (int i = 1; i < cities.Count; i++) { 80 length += VRPUtilities.GetDistance( 81 cities[i - 1], cities[i], coordinates, distanceMatrix, useDistanceMatrix); 82 } 83 } 84 85 return length; 86 } 27 87 } 28 88 }
Note: See TracChangeset
for help on using the changeset viewer.