Changeset 11428
- Timestamp:
- 10/08/14 16:21:42 (10 years ago)
- Location:
- trunk/sources
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/IVRPInstanceProvider.cs
r11420 r11428 20 20 #endregion 21 21 22 22 23 namespace HeuristicLab.Problems.Instances.VehicleRouting { 23 public interface IVRPInstanceProvider<T > {24 public interface IVRPInstanceProvider<TData> { 24 25 bool CanImportData { get; } 25 T Import(string vrpFile, string tourFile);26 TData Import(string instancePath, string solutionPath); 26 27 27 28 bool CanExportData { get; } 28 void Export(T instance, string path);29 void Export(TData instance, string path); 29 30 } 30 31 } -
trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/VRPInstanceProvider.cs
r11420 r11428 29 29 30 30 namespace HeuristicLab.Problems.Instances.VehicleRouting { 31 public abstract class VRPInstanceProvider<T > : ProblemInstanceProvider<T>, IVRPInstanceProvider<T> where T: IVRPData {31 public abstract class VRPInstanceProvider<TData> : ProblemInstanceProvider<TData>, IVRPInstanceProvider<TData> where TData : IVRPData { 32 32 protected abstract string FileName { get; } 33 33 34 34 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 35 Dictionary<string, string>solutions = new Dictionary<string, string>();35 var solutions = new Dictionary<string, string>(); 36 36 var solutionsArchiveName = GetResourceName(FileName + @"\.opt\.zip"); 37 37 if (!String.IsNullOrEmpty(solutionsArchiveName)) { 38 38 using (var solutionsZipFile = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) { 39 39 foreach (var entry in GetZipContents(solutionsZipFile)) 40 solutions.Add( entry.Substring(0, entry.Length - ".opt".Length) + "." + FileName, entry);40 solutions.Add(Path.GetFileNameWithoutExtension(entry) + "." + FileName, entry); 41 41 } 42 42 } … … 46 46 using (var instanceStream = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(instanceArchiveName))) { 47 47 foreach (var entry in GetZipContents(instanceStream).OrderBy(x => x)) { 48 string solutionEntry = entry.Substring(0, entry.Length - ".opt".Length) + "." + FileName;48 string solutionEntry = Path.GetFileNameWithoutExtension(entry) + "." + FileName; 49 49 yield return new VRPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetInstanceDescription(), entry, solutions.ContainsKey(solutionEntry) ? solutions[solutionEntry] : String.Empty); 50 50 } … … 52 52 } 53 53 54 public override T LoadData(IDataDescriptor id) {54 public override TData LoadData(IDataDescriptor id) { 55 55 var descriptor = (VRPDataDescriptor)id; 56 56 var instanceArchiveName = GetResourceName(FileName + @"\.zip"); … … 76 76 } 77 77 78 private static void LoadSolution(Stream stream, T instance) { 78 #region IVRPInstanceProvider 79 public TData Import(string vrpFile, string tourFile) { 80 var data = ImportData(vrpFile); 81 if (!String.IsNullOrEmpty(tourFile)) { 82 LoadSolution(tourFile, data); 83 } 84 return data; 85 } 86 87 public void Export(TData instance, string path) { 88 ExportData(instance, path); 89 } 90 #endregion 91 92 protected virtual void LoadSolution(Stream stream, TData instance) { 79 93 List<List<int>> routes = new List<List<int>>(); 80 94 … … 106 120 } 107 121 108 public static void LoadSolution(string path, Tinstance) {122 public void LoadSolution(string path, TData instance) { 109 123 using (FileStream stream = new FileStream(path, FileMode.Open)) { 110 124 LoadSolution(stream, instance); … … 112 126 } 113 127 114 protected abstract T LoadData(Stream stream);128 protected abstract TData LoadData(Stream stream); 115 129 116 public T Import(string vrpFile, string tourFile) { 117 var data = ImportData(vrpFile); 118 if (!String.IsNullOrEmpty(tourFile)) { 119 LoadSolution(tourFile, data); 120 } 121 return data; 122 } 123 124 public void Export(T instance, string path) { 125 ExportData(instance, path); 126 } 127 130 #region Helpers 128 131 protected virtual string GetResourceName(string fileName) { 129 132 return Assembly.GetExecutingAssembly().GetManifestResourceNames() … … 141 144 } 142 145 } 146 #endregion 143 147 } 144 148 } -
trunk/sources/HeuristicLab.Problems.Instances/3.3/Types/VRP/IVRPData.cs
r11171 r11428 31 31 double? BestKnownQuality { get; set; } 32 32 int[][] BestKnownTour { get; set; } 33 int[] BestKnownTourVehicleAssignment { get; set; } 33 34 } 34 35 } -
trunk/sources/HeuristicLab.Problems.Instances/3.3/Types/VRP/VRPData.cs
r11285 r11428 78 78 public int[][] BestKnownTour { get; set; } 79 79 /// <summary> 80 /// Optional! Specifies the used vehicle for a given tour. 81 /// </summary> 82 public int[] BestKnownTourVehicleAssignment { get; set; } 83 /// <summary> 80 84 /// Optional! The quality of the best-known solution. 81 85 /// </summary> -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs
r11171 r11428 36 36 public List<int> Unrouted { get; set; } 37 37 38 // VehicleAssignment[tour] retreives the assigned vehicle for the given tour 38 39 [Storable] 39 40 public Permutation VehicleAssignment { get; private set; } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Interpreters/VRPInterpreter.cs
r11171 r11428 20 20 #endregion 21 21 22 using System.IO; 22 23 using HeuristicLab.Data; 23 24 using HeuristicLab.Problems.Instances; … … 44 45 } 45 46 47 if (data.BestKnownTourVehicleAssignment != null) { 48 if (data.BestKnownTourVehicleAssignment.Length != solution.VehicleAssignment.Length) 49 throw new InvalidDataException("Number of vehicles of the best known tour does not match the number vehicles of the instance."); 50 for (int i = 0; i < data.BestKnownTourVehicleAssignment.Length; i++) 51 solution.VehicleAssignment[i] = data.BestKnownTourVehicleAssignment[i]; 52 } 53 46 54 return solution; 47 55 } else { … … 51 59 52 60 protected abstract IVRPProblemInstance CreateProblemInstance(); 53 61 54 62 public VRPInstanceDescription Interpret(IVRPData data) { 55 63 VRPInstanceDescription result = new VRPInstanceDescription();
Note: See TracChangeset
for help on using the changeset viewer.