Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/28/15 23:38:51 (9 years ago)
Author:
abeham
Message:

#2221:

  • Completely refactored PTSP branch
    • Added two sets of problem instances based on TSPLIB: homogeneous and heterogeneous
    • Implemented missing EvaluateByCoordinates for 1-shift moves
    • Made it clear that move evaluators are for estimated PTSP only
    • Changed parameter realization from a rather strange list of list of ints to a list of bool arrays
    • Reusing code of the 2-opt and 1-shift move evaluators in 2.5 move evaluator
    • Introducing distance calculators to properly handle the case when no distance matrix is given (previous code only worked with distance matrix and without only with euclidean distance in some settings)
    • Fixed several smaller code issues: protected, static, method parameters, copy & paste, interfaces, naming, parameters, serialization hooks, license headers, doc comments, data types
Location:
branches/PTSP/HeuristicLab.Problems.Instances.TSPLIB
Files:
2 copied

Legend:

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

    r13408 r13412  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.IO;
    2425using System.Linq;
    2526
    2627namespace HeuristicLab.Problems.Instances.TSPLIB {
    27   public class TSPLIBTSPInstanceProvider : TSPLIBInstanceProvider<TSPData> {
     28  public class TSPLIBHeterogeneousPTSPInstanceProvider : TSPLIBInstanceProvider<PTSPData> {
    2829
    2930    public override string Name {
    30       get { return "TSPLIB (symmetric TSP)"; }
     31      get { return "TSPLIB (heterogeneous symmetric PTSP)"; }
    3132    }
    3233
     
    3738    protected override string FileExtension { get { return "tsp"; } }
    3839
    39     protected override TSPData LoadInstance(TSPLIBParser parser) {
     40    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
     41      foreach (var desc in base.GetDataDescriptors().OfType<TSPLIBDataDescriptor>()) {
     42        desc.Name += " [0.1;0.9]";
     43        desc.SolutionIdentifier = null;
     44        yield return desc;
     45      }
     46    }
     47
     48    protected override PTSPData LoadInstance(TSPLIBParser parser, IDataDescriptor descriptor = null) {
    4049      parser.Parse();
    4150      if (parser.FixedEdges != null) throw new InvalidDataException("TSP instance " + parser.Name + " contains fixed edges which are not supported by HeuristicLab.");
    42       var instance = new TSPData();
     51      var instance = new PTSPData();
    4352      instance.Dimension = parser.Dimension;
    4453      instance.Coordinates = parser.Vertices != null ? parser.Vertices : parser.DisplayVertices;
     
    7382        + Environment.NewLine + Environment.NewLine
    7483        + GetInstanceDescription();
     84
     85      var random = new MarsagliaRandom((uint)(descriptor != null ? descriptor.Name : instance.Name).GetHashCode());
     86      instance.Probabilities = Enumerable.Range(0, instance.Dimension).Select(_ => 0.1 + 0.9 * random.NextDouble()).ToArray();
     87
    7588      return instance;
    7689    }
    7790
    78     protected override void LoadSolution(TSPLIBParser parser, TSPData instance) {
     91    protected override void LoadSolution(TSPLIBParser parser, PTSPData instance) {
    7992      parser.Parse();
    8093      instance.BestKnownTour = parser.Tour.FirstOrDefault();
    8194    }
    8295
    83     public TSPData LoadData(string tspFile, string tourFile, double? bestQuality) {
     96    public PTSPData LoadData(string tspFile, string tourFile, double? bestQuality) {
    8497      var data = LoadInstance(new TSPLIBParser(tspFile));
    8598      if (!String.IsNullOrEmpty(tourFile)) {
Note: See TracChangeset for help on using the changeset viewer.