- Timestamp:
- 08/06/10 16:08:46 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.