Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/16/12 16:28:49 (12 years ago)
Author:
gkronber
Message:

merged r7609:7840 from trunk into time series branch

Location:
branches/HeuristicLab.TimeSeries
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries

  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBCVRPInstanceProvider.cs

    r7548 r7842  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.IO;
    25 using System.Linq;
    26 using System.Reflection;
    27 using System.Text.RegularExpressions;
    2824
    2925namespace HeuristicLab.Problems.Instances.TSPLIB {
    30   public class TSPLIBCVRPInstanceProvider : ProblemInstanceProvider<CVRPData> {
     26  public class TSPLIBCVRPInstanceProvider : TSPLIBInstanceProvider<CVRPData> {
    3127
    3228    public override string Name {
     
    3834    }
    3935
    40     public override Uri WebLink {
    41       get { return new Uri("http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/"); }
    42     }
     36    protected override string FileExtension { get { return "vrp"; } }
    4337
    44     public override string ReferencePublication {
    45       get {
    46         return @"G. Reinelt. 1991.
    47 TSPLIB - A Traveling Salesman Problem Library.
    48 ORSA Journal on Computing, 3, pp. 376-384.";
    49       }
    50     }
    51 
    52     public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    53       var solutions = Assembly.GetExecutingAssembly()
    54         .GetManifestResourceNames()
    55         .Where(x => Regex.Match(x, @".*\.Data\.CVRP\..*").Success)
    56         .Where(x => x.EndsWith(".opt.tour"))
    57         .ToDictionary(x => x.Substring(0, x.Length - ".opt.tour".Length) + ".vrp", x => x);
    58 
    59       return Assembly.GetExecutingAssembly()
    60           .GetManifestResourceNames()
    61           .Where(x => Regex.Match(x, @".*\.Data\.CVRP\..*").Success)
    62           .OrderBy(x => x)
    63           .Select(x => new TSPLIBDataDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty));
    64     }
    65 
    66     public override CVRPData LoadData(IDataDescriptor id) {
    67       var descriptor = (TSPLIBDataDescriptor)id;
    68       using (var stream = Assembly.GetExecutingAssembly()
    69         .GetManifestResourceStream(descriptor.InstanceIdentifier)) {
    70         var instance = Load(new TSPLIBParser(stream));
    71 
    72         if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) {
    73           using (Stream solStream = Assembly.GetExecutingAssembly()
    74             .GetManifestResourceStream(descriptor.SolutionIdentifier)) {
    75             var slnParser = new TSPLIBParser(solStream);
    76             slnParser.Parse();
    77             instance.BestKnownTour = slnParser.Tour;
    78           }
    79         }
    80         return instance;
    81       }
    82     }
    83 
    84     public override CVRPData LoadData(string path) {
    85       return Load(new TSPLIBParser(path));
    86     }
    87 
    88     public override void SaveData(CVRPData instance, string path) {
    89       throw new NotSupportedException();
    90     }
    91 
    92     private CVRPData Load(TSPLIBParser parser) {
     38    protected override CVRPData LoadInstance(TSPLIBParser parser) {
    9339      parser.Parse();
    9440      var instance = new CVRPData();
     
    12369      instance.Description = parser.Comment
    12470        + Environment.NewLine + Environment.NewLine
    125         + GetDescription();
     71        + GetInstanceDescription();
    12672
    12773      return instance;
    12874    }
    12975
    130     private string GetPrettyName(string instanceIdentifier) {
    131       return Regex.Match(instanceIdentifier, GetType().Namespace + @"\.Data\.CVRP\.(.*)\.vrp").Groups[1].Captures[0].Value;
    132     }
    133 
    134     private string GetDescription() {
    135       return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
     76    protected override void LoadSolution(TSPLIBParser parser, CVRPData instance) {
     77      parser.Parse();
     78      instance.BestKnownTour = parser.Tour;
    13679    }
    13780  }
Note: See TracChangeset for help on using the changeset viewer.