Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/08/14 16:21:42 (10 years ago)
Author:
pfleck
Message:

#2229

  • The IVRPData now specifies an optional BestKnownTourVehicleAssignment property. This can be used for solutions where a specific assignment for tours to vehicles is necessary.
  • The VRPInterpreter interpret the new BestKnownTourVehicleAssignment directly as VehicleAssignment in the created PotvinEncoding.
  • Minor refactoring in (I)VRPInstanceProvider.
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  
    2020#endregion
    2121
     22
    2223namespace HeuristicLab.Problems.Instances.VehicleRouting {
    23   public interface IVRPInstanceProvider<T> {
     24  public interface IVRPInstanceProvider<TData> {
    2425    bool CanImportData { get; }
    25     T Import(string vrpFile, string tourFile);
     26    TData Import(string instancePath, string solutionPath);
    2627
    2728    bool CanExportData { get; }
    28     void Export(T instance, string path);
     29    void Export(TData instance, string path);
    2930  }
    3031}
  • trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/VRPInstanceProvider.cs

    r11420 r11428  
    2929
    3030namespace 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 {
    3232    protected abstract string FileName { get; }
    3333
    3434    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    35       Dictionary<string, string> solutions = new Dictionary<string, string>();
     35      var solutions = new Dictionary<string, string>();
    3636      var solutionsArchiveName = GetResourceName(FileName + @"\.opt\.zip");
    3737      if (!String.IsNullOrEmpty(solutionsArchiveName)) {
    3838        using (var solutionsZipFile = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) {
    3939          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);
    4141        }
    4242      }
     
    4646      using (var instanceStream = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(instanceArchiveName))) {
    4747        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;
    4949          yield return new VRPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetInstanceDescription(), entry, solutions.ContainsKey(solutionEntry) ? solutions[solutionEntry] : String.Empty);
    5050        }
     
    5252    }
    5353
    54     public override T LoadData(IDataDescriptor id) {
     54    public override TData LoadData(IDataDescriptor id) {
    5555      var descriptor = (VRPDataDescriptor)id;
    5656      var instanceArchiveName = GetResourceName(FileName + @"\.zip");
     
    7676    }
    7777
    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) {
    7993      List<List<int>> routes = new List<List<int>>();
    8094
     
    106120    }
    107121
    108     public static void LoadSolution(string path, T instance) {
     122    public void LoadSolution(string path, TData instance) {
    109123      using (FileStream stream = new FileStream(path, FileMode.Open)) {
    110124        LoadSolution(stream, instance);
     
    112126    }
    113127
    114     protected abstract T LoadData(Stream stream);
     128    protected abstract TData LoadData(Stream stream);
    115129
    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
    128131    protected virtual string GetResourceName(string fileName) {
    129132      return Assembly.GetExecutingAssembly().GetManifestResourceNames()
     
    141144      }
    142145    }
     146    #endregion
    143147  }
    144148}
Note: See TracChangeset for help on using the changeset viewer.