- Timestamp:
- 10/08/14 16:21:42 (10 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4
- Files:
-
- 2 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 }
Note: See TracChangeset
for help on using the changeset viewer.