Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/15/15 16:38:08 (9 years ago)
Author:
abeham
Message:

#2221:

  • implemented review comments
    • hid rng as private class, implemented djb2 hash function (hash function implementation may also change)
    • added missing probabilities
    • base class for instance providers
    • prebuild event events
    • build platforms
    • unit test will be removed on trunk integration
    • corrected assembly file version
    • distance calculator parameter was not hidden, can be changed by user, updates distance matrix
    • fixed performance problems (ouch!) also for estimated ptsp (inlined GetDistance method)
  • added moves (full evaluation) for analytical tsp
  • added local improvement operators for analytical ptsp
  • added recalculation of distance matrix when parameters change
  • still lots of other changes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PTSP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBHomogeneousPTSPInstanceProvider.cs

    r13412 r13470  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Globalization;
    25 using System.IO;
    2624using System.Linq;
    2725
    2826namespace HeuristicLab.Problems.Instances.TSPLIB {
    29   public class TSPLIBHomogeneousPTSPInstanceProvider : TSPLIBInstanceProvider<PTSPData> {
    30     private static readonly double[] probabilities = new[] { 0.1, 0.2, 0.4, 0.5, 0.6, 0.8, 0.9, 1.0 };
     27  public class TSPLIBHomogeneousPTSPInstanceProvider : TSPLIBPTSPInstanceProvider {
     28    private static readonly double[] Probabilities = new[] { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 };
    3129
    3230    public override string Name {
     
    3432    }
    3533
    36     public override string Description {
    37       get { return "Traveling Salesman Problem Library"; }
    38     }
    39 
    40     protected override string FileExtension { get { return "tsp"; } }
    41 
    4234    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    4335      var tspDescriptors = base.GetDataDescriptors().OfType<TSPLIBDataDescriptor>();
    4436      foreach (var desc in tspDescriptors) {
    45         foreach (var p in probabilities) {
     37        foreach (var p in Probabilities) {
    4638          yield return new TSPLIBHomogeneousPTSPDataDescriptor(
    4739            desc.Name + "-" + p.ToString(CultureInfo.InvariantCulture.NumberFormat),
     
    5446    }
    5547
    56     protected override PTSPData LoadInstance(TSPLIBParser parser, IDataDescriptor descriptor = null) {
    57       parser.Parse();
    58       if (parser.FixedEdges != null) throw new InvalidDataException("TSP instance " + parser.Name + " contains fixed edges which are not supported by HeuristicLab.");
    59       var instance = new PTSPData();
    60       instance.Dimension = parser.Dimension;
    61       instance.Coordinates = parser.Vertices != null ? parser.Vertices : parser.DisplayVertices;
    62       instance.Distances = parser.Distances;
    63       switch (parser.EdgeWeightType) {
    64         case TSPLIBEdgeWeightTypes.ATT:
    65           instance.DistanceMeasure = DistanceMeasure.Att; break;
    66         case TSPLIBEdgeWeightTypes.CEIL_2D:
    67           instance.DistanceMeasure = DistanceMeasure.UpperEuclidean; break;
    68         case TSPLIBEdgeWeightTypes.EUC_2D:
    69           instance.DistanceMeasure = DistanceMeasure.RoundedEuclidean; break;
    70         case TSPLIBEdgeWeightTypes.EUC_3D:
    71           throw new InvalidDataException("3D coordinates are not supported.");
    72         case TSPLIBEdgeWeightTypes.EXPLICIT:
    73           instance.DistanceMeasure = DistanceMeasure.Direct; break;
    74         case TSPLIBEdgeWeightTypes.GEO:
    75           instance.DistanceMeasure = DistanceMeasure.Geo; break;
    76         case TSPLIBEdgeWeightTypes.MAN_2D:
    77           instance.DistanceMeasure = DistanceMeasure.Manhattan; break;
    78         case TSPLIBEdgeWeightTypes.MAN_3D:
    79           throw new InvalidDataException("3D coordinates are not supported.");
    80         case TSPLIBEdgeWeightTypes.MAX_2D:
    81           instance.DistanceMeasure = DistanceMeasure.Maximum; break;
    82         case TSPLIBEdgeWeightTypes.MAX_3D:
    83           throw new InvalidDataException("3D coordinates are not supported.");
    84         default:
    85           throw new InvalidDataException("The given edge weight is not supported by HeuristicLab.");
    86       }
    87 
    88       instance.Name = parser.Name;
    89       instance.Description = parser.Comment
    90         + Environment.NewLine + Environment.NewLine
    91         + GetInstanceDescription();
     48    protected override double[] GetProbabilities(IDataDescriptor descriptor, PTSPData instance) {
    9249      var ptspDesc = descriptor as TSPLIBHomogeneousPTSPDataDescriptor;
    93       instance.Probabilities = ptspDesc != null ? Enumerable.Range(0, instance.Dimension).Select(_ => ptspDesc.Probability).ToArray()
    94                                                 : Enumerable.Range(0, instance.Dimension).Select(_ => 0.5).ToArray();
    95 
    96       return instance;
     50      return ptspDesc != null ? Enumerable.Range(0, instance.Dimension).Select(_ => ptspDesc.Probability).ToArray()
     51                              : Enumerable.Range(0, instance.Dimension).Select(_ => 0.5).ToArray();
    9752    }
    98 
    99     protected override void LoadSolution(TSPLIBParser parser, PTSPData instance) {
    100       parser.Parse();
    101       instance.BestKnownTour = parser.Tour.FirstOrDefault();
    102     }
    103 
    104     public PTSPData LoadData(string tspFile, string tourFile, double? bestQuality) {
    105       var data = LoadInstance(new TSPLIBParser(tspFile));
    106       if (!String.IsNullOrEmpty(tourFile)) {
    107         var tourParser = new TSPLIBParser(tourFile);
    108         LoadSolution(tourParser, data);
    109       }
    110       if (bestQuality.HasValue)
    111         data.BestKnownQuality = bestQuality.Value;
    112       return data;
    113     }
    114 
    11553  }
    11654}
Note: See TracChangeset for help on using the changeset viewer.