Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14697


Ignore:
Timestamp:
02/23/17 14:42:04 (8 years ago)
Author:
swagner
Message:

#2737: Enhanced TSPLIBInstanceProvider to set best known quality even if no optimal solution is provided in the TSPLIB.

Location:
trunk/sources/HeuristicLab.Problems.Instances.TSPLIB/3.3
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.TSPLIB/3.3/HeuristicLab.Problems.Instances.TSPLIB-3.3.csproj

    r13484 r14697  
    130130    <EmbeddedResource Include="Data\tsp.opt.tour.zip" />
    131131    <EmbeddedResource Include="Data\vrp.zip" />
     132    <EmbeddedResource Include="Data\tsp.qual" />
     133    <EmbeddedResource Include="Data\atsp.qual" />
    132134    <None Include="Plugin.cs.frame" />
    133135    <Compile Include="Plugin.cs" />
  • trunk/sources/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBATSPInstanceProvider.cs

    r14185 r14697  
    5656      instance.BestKnownTour = parser.Tour.FirstOrDefault();
    5757    }
     58
     59    protected override void LoadQuality(double? bestQuality, ATSPData instance) {
     60      instance.BestKnownQuality = bestQuality;
     61    }
    5862  }
    5963}
  • trunk/sources/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBCVRPInstanceProvider.cs

    r14185 r14697  
    7878      instance.BestKnownTour = parser.Tour;
    7979    }
     80
     81    protected override void LoadQuality(double? bestQuality, CVRPData instance) {
     82      instance.BestKnownQuality = bestQuality;
     83    }
    8084  }
    8185}
  • trunk/sources/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBDataDescriptor.cs

    r14185 r14697  
    2727    internal string InstanceIdentifier { get; set; }
    2828    internal string SolutionIdentifier { get; set; }
     29    internal double? BestQuality { get; set; }
    2930
    30     internal TSPLIBDataDescriptor(string name, string description, string instanceIdentifier, string solutionIdentifier) {
     31    internal TSPLIBDataDescriptor(string name, string description, string instanceIdentifier, string solutionIdentifier, double? bestQuality) {
    3132      this.Name = name;
    3233      this.Description = description;
    3334      this.InstanceIdentifier = instanceIdentifier;
    3435      this.SolutionIdentifier = solutionIdentifier;
     36      this.BestQuality = bestQuality;
    3537    }
    3638  }
  • trunk/sources/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBHeterogeneousPTSPDataDescriptor.cs

    r14185 r14697  
    2626
    2727    internal TSPLIBHeterogeneousPTSPDataDescriptor(string name, string description, string instanceIdentifier, string solutionIdentifier, int seed)
    28       : base(name, description, instanceIdentifier, solutionIdentifier) {
     28      : base(name, description, instanceIdentifier, solutionIdentifier, null) {
    2929      this.Name = name;
    3030      this.Description = description;
  • trunk/sources/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBHomogeneousPTSPDataDescriptor.cs

    r14185 r14697  
    2525
    2626    internal TSPLIBHomogeneousPTSPDataDescriptor(string name, string description, string instanceIdentifier, string solutionIdentifier, double probability)
    27       : base(name, description, instanceIdentifier, solutionIdentifier) {
     27      : base(name, description, instanceIdentifier, solutionIdentifier, null) {
    2828      this.Name = name;
    2929      this.Description = description;
  • trunk/sources/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBInstanceProvider.cs

    r14185 r14697  
    4747    protected abstract T LoadInstance(TSPLIBParser parser, IDataDescriptor descriptor = null);
    4848    protected abstract void LoadSolution(TSPLIBParser parser, T instance);
     49    protected abstract void LoadQuality(double? bestQuality, T instance);
    4950
    5051    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
     
    5758        }
    5859      }
     60
     61      Dictionary<string, double> qualities = new Dictionary<string, double>();
     62      var qualitiesArchiveName = GetResourceName(FileExtension + @"\.qual");
     63      if (!String.IsNullOrEmpty(qualitiesArchiveName)) {
     64        using (var qualitiesReader = new StreamReader(GetType().Assembly.GetManifestResourceStream(qualitiesArchiveName))) {
     65          while (!qualitiesReader.EndOfStream) {
     66            var line = qualitiesReader.ReadLine().Split(';');
     67            qualities.Add(line[0] + "." + FileExtension, double.Parse(line[1]));
     68          }
     69        }
     70      }
     71
    5972      var instanceArchiveName = GetResourceName(FileExtension + @"\.zip");
    6073      if (String.IsNullOrEmpty(instanceArchiveName)) yield break;
     
    6275      using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
    6376        foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) {
    64           yield return new TSPLIBDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetInstanceDescription(), entry, solutions.ContainsKey(entry) ? solutions[entry] : String.Empty);
     77          yield return new TSPLIBDataDescriptor(Path.GetFileNameWithoutExtension(entry),
     78                                                GetInstanceDescription(),
     79                                                entry,
     80                                                solutions.ContainsKey(entry) ? solutions[entry] : String.Empty,
     81                                                qualities.ContainsKey(entry) ? (double?)qualities[entry] : null);
    6582        }
    6683      }
     
    7592        var parser = new TSPLIBParser(stream);
    7693        var instance = LoadInstance(parser, id);
     94        LoadQuality(descriptor.BestQuality, instance);
    7795
    7896        if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) {
  • trunk/sources/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBPTSPInstanceProvider.cs

    r14185 r14697  
    8181    }
    8282
     83    protected override void LoadQuality(double? bestQuality, PTSPData instance) {
     84      instance.BestKnownQuality = bestQuality;
     85    }
     86
    8387    public PTSPData LoadData(string tspFile, string tourFile, double? bestQuality) {
    8488      var data = LoadInstance(new TSPLIBParser(tspFile));
  • trunk/sources/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBTSPInstanceProvider.cs

    r14185 r14697  
    8181    }
    8282
     83    protected override void LoadQuality(double? bestQuality, TSPData instance) {
     84      instance.BestKnownQuality = bestQuality;
     85    }
     86
    8387    public TSPData LoadData(string tspFile, string tourFile, double? bestQuality) {
    8488      var data = LoadInstance(new TSPLIBParser(tspFile));
Note: See TracChangeset for help on using the changeset viewer.