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:
1 added
5 edited
5 copied

Legend:

Unmodified
Added
Removed
  • branches/PTSP/HeuristicLab.Problems.Instances.TSPLIB/3.3/HeuristicLab.Problems.Instances.TSPLIB-3.3.csproj

    r11650 r13412  
    1919    <DebugType>full</DebugType>
    2020    <Optimize>false</Optimize>
    21     <OutputPath>..\..\bin\</OutputPath>
     21    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    2222    <DefineConstants>DEBUG;TRACE</DefineConstants>
    2323    <ErrorReport>prompt</ErrorReport>
     
    2828    <DebugType>pdbonly</DebugType>
    2929    <Optimize>true</Optimize>
    30     <OutputPath>..\..\bin\</OutputPath>
     30    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    3131    <DefineConstants>TRACE</DefineConstants>
    3232    <ErrorReport>prompt</ErrorReport>
     
    4242  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    4343    <DebugSymbols>true</DebugSymbols>
    44     <OutputPath>..\..\bin\</OutputPath>
     44    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    4545    <DefineConstants>DEBUG;TRACE</DefineConstants>
    4646    <DebugType>full</DebugType>
     
    5858  </PropertyGroup>
    5959  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
    60     <OutputPath>..\..\bin\</OutputPath>
     60    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    6161    <DefineConstants>TRACE</DefineConstants>
    6262    <Optimize>true</Optimize>
     
    7676  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    7777    <DebugSymbols>true</DebugSymbols>
    78     <OutputPath>..\..\bin\</OutputPath>
     78    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    7979    <DefineConstants>DEBUG;TRACE</DefineConstants>
    8080    <DebugType>full</DebugType>
     
    9292  </PropertyGroup>
    9393  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
    94     <OutputPath>..\..\bin\</OutputPath>
     94    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    9595    <DefineConstants>TRACE</DefineConstants>
    9696    <Optimize>true</Optimize>
     
    109109  </PropertyGroup>
    110110  <ItemGroup>
     111    <Reference Include="HeuristicLab.Common-3.3">
     112      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
     113      <Private>False</Private>
     114    </Reference>
     115    <Reference Include="HeuristicLab.PluginInfrastructure-3.3">
     116      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     117      <Private>False</Private>
     118    </Reference>
    111119    <Reference Include="System" />
    112120    <Reference Include="System.Core" />
     
    115123  </ItemGroup>
    116124  <ItemGroup>
     125    <Compile Include="MarsagliaRandom.cs" />
     126    <Compile Include="TSPLIBHeterogeneousPTSPDataDescriptor.cs" />
     127    <Compile Include="TSPLIBHomogeneousPTSPDataDescriptor.cs" />
     128    <Compile Include="TSPLIBHeterogeneousPTSPInstanceProvider.cs" />
    117129    <Compile Include="TSPLIBInstanceProvider.cs" />
    118130    <Compile Include="TSPLIBATSPInstanceProvider.cs" />
    119131    <Compile Include="TSPLIBCVRPInstanceProvider.cs" />
    120132    <Compile Include="TSPLIBDataDescriptor.cs" />
     133    <Compile Include="TSPLIBHomogeneousPTSPInstanceProvider.cs" />
    121134    <Compile Include="TSPLIBTSPInstanceProvider.cs" />
    122135    <Compile Include="TSPLIBParser.cs" />
     
    134147  </ItemGroup>
    135148  <ItemGroup>
    136     <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
    137       <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
    138       <Name>HeuristicLab.Common-3.3</Name>
    139       <Private>False</Private>
    140     </ProjectReference>
    141     <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
    142       <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
    143       <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
    144       <Private>False</Private>
    145     </ProjectReference>
    146149    <ProjectReference Include="..\..\HeuristicLab.Problems.Instances\3.3\HeuristicLab.Problems.Instances-3.3.csproj">
    147       <Project>{3540E29E-4793-49E7-8EE2-FEA7F61C3994}</Project>
     150      <Project>{3540e29e-4793-49e7-8ee2-fea7f61c3994}</Project>
    148151      <Name>HeuristicLab.Problems.Instances-3.3</Name>
    149152      <Private>False</Private>
    150153    </ProjectReference>
    151154  </ItemGroup>
    152   <ItemGroup />
    153155  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    154156  <PropertyGroup>
  • branches/PTSP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBATSPInstanceProvider.cs

    r12012 r13412  
    3636    protected override string FileExtension { get { return "atsp"; } }
    3737
    38     protected override ATSPData LoadInstance(TSPLIBParser parser) {
     38    protected override ATSPData LoadInstance(TSPLIBParser parser, IDataDescriptor descriptor = null) {
    3939      var instance = new ATSPData();
    4040
  • branches/PTSP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBCVRPInstanceProvider.cs

    r12012 r13412  
    3636    protected override string FileExtension { get { return "vrp"; } }
    3737
    38     protected override CVRPData LoadInstance(TSPLIBParser parser) {
     38    protected override CVRPData LoadInstance(TSPLIBParser parser, IDataDescriptor descriptor = null) {
    3939      parser.Parse();
    4040      var instance = new CVRPData();
  • branches/PTSP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBHeterogeneousPTSPDataDescriptor.cs

    r13408 r13412  
    2020#endregion
    2121
     22
    2223namespace HeuristicLab.Problems.Instances.TSPLIB {
    23   internal class TSPLIBDataDescriptor : IDataDescriptor {
    24     public string Name { get; internal set; }
    25     public string Description { get; internal set; }
     24  internal class TSPLIBHeterogeneousPTSPDataDescriptor : TSPLIBDataDescriptor {
     25    public int Seed { get; internal set; }
    2626
    27     internal string InstanceIdentifier { get; set; }
    28     internal string SolutionIdentifier { get; set; }
    29 
    30     internal TSPLIBDataDescriptor(string name, string description, string instanceIdentifier, string solutionIdentifier) {
     27    internal TSPLIBHeterogeneousPTSPDataDescriptor(string name, string description, string instanceIdentifier, string solutionIdentifier, int seed)
     28      : base(name, description, instanceIdentifier, solutionIdentifier) {
    3129      this.Name = name;
    3230      this.Description = description;
    3331      this.InstanceIdentifier = instanceIdentifier;
    3432      this.SolutionIdentifier = solutionIdentifier;
     33      this.Seed = seed;
    3534    }
    3635  }
  • 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)) {
  • branches/PTSP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBHomogeneousPTSPDataDescriptor.cs

    r13408 r13412  
    2121
    2222namespace HeuristicLab.Problems.Instances.TSPLIB {
    23   internal class TSPLIBDataDescriptor : IDataDescriptor {
    24     public string Name { get; internal set; }
    25     public string Description { get; internal set; }
     23  internal class TSPLIBHomogeneousPTSPDataDescriptor : TSPLIBDataDescriptor {
     24    public double Probability { get; internal set; }
    2625
    27     internal string InstanceIdentifier { get; set; }
    28     internal string SolutionIdentifier { get; set; }
    29 
    30     internal TSPLIBDataDescriptor(string name, string description, string instanceIdentifier, string solutionIdentifier) {
     26    internal TSPLIBHomogeneousPTSPDataDescriptor(string name, string description, string instanceIdentifier, string solutionIdentifier, double probability)
     27      : base(name, description, instanceIdentifier, solutionIdentifier) {
    3128      this.Name = name;
    3229      this.Description = description;
    3330      this.InstanceIdentifier = instanceIdentifier;
    3431      this.SolutionIdentifier = solutionIdentifier;
     32      this.Probability = probability;
    3533    }
    3634  }
  • branches/PTSP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBHomogeneousPTSPInstanceProvider.cs

    r13408 r13412  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Globalization;
    2325using System.IO;
    2426using System.Linq;
    2527
    2628namespace HeuristicLab.Problems.Instances.TSPLIB {
    27   public class TSPLIBTSPInstanceProvider : TSPLIBInstanceProvider<TSPData> {
     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 };
    2831
    2932    public override string Name {
    30       get { return "TSPLIB (symmetric TSP)"; }
     33      get { return "TSPLIB (homogeneous symmetric PTSP)"; }
    3134    }
    3235
     
    3740    protected override string FileExtension { get { return "tsp"; } }
    3841
    39     protected override TSPData LoadInstance(TSPLIBParser parser) {
     42    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
     43      var tspDescriptors = base.GetDataDescriptors().OfType<TSPLIBDataDescriptor>();
     44      foreach (var desc in tspDescriptors) {
     45        foreach (var p in probabilities) {
     46          yield return new TSPLIBHomogeneousPTSPDataDescriptor(
     47            desc.Name + "-" + p.ToString(CultureInfo.InvariantCulture.NumberFormat),
     48            desc.Description,
     49            desc.InstanceIdentifier,
     50            p == 1.0 ? desc.SolutionIdentifier : null,
     51            p);
     52        }
     53      }
     54    }
     55
     56    protected override PTSPData LoadInstance(TSPLIBParser parser, IDataDescriptor descriptor = null) {
    4057      parser.Parse();
    4158      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();
     59      var instance = new PTSPData();
    4360      instance.Dimension = parser.Dimension;
    4461      instance.Coordinates = parser.Vertices != null ? parser.Vertices : parser.DisplayVertices;
     
    7390        + Environment.NewLine + Environment.NewLine
    7491        + GetInstanceDescription();
     92      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
    7596      return instance;
    7697    }
    7798
    78     protected override void LoadSolution(TSPLIBParser parser, TSPData instance) {
     99    protected override void LoadSolution(TSPLIBParser parser, PTSPData instance) {
    79100      parser.Parse();
    80101      instance.BestKnownTour = parser.Tour.FirstOrDefault();
    81102    }
    82103
    83     public TSPData LoadData(string tspFile, string tourFile, double? bestQuality) {
     104    public PTSPData LoadData(string tspFile, string tourFile, double? bestQuality) {
    84105      var data = LoadInstance(new TSPLIBParser(tspFile));
    85106      if (!String.IsNullOrEmpty(tourFile)) {
  • branches/PTSP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBInstanceProvider.cs

    r12012 r13412  
    4545    protected abstract string FileExtension { get; }
    4646
    47     protected abstract T LoadInstance(TSPLIBParser parser);
     47    protected abstract T LoadInstance(TSPLIBParser parser, IDataDescriptor descriptor = null);
    4848    protected abstract void LoadSolution(TSPLIBParser parser, T instance);
    4949
     
    7474        var stream = entry.Open();
    7575        var parser = new TSPLIBParser(stream);
    76         var instance = LoadInstance(parser);
     76        var instance = LoadInstance(parser, id);
    7777
    7878        if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) {
  • branches/PTSP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBTSPInstanceProvider.cs

    r12012 r13412  
    3737    protected override string FileExtension { get { return "tsp"; } }
    3838
    39     protected override TSPData LoadInstance(TSPLIBParser parser) {
     39    protected override TSPData LoadInstance(TSPLIBParser parser, IDataDescriptor descriptor = null) {
    4040      parser.Parse();
    4141      if (parser.FixedEdges != null) throw new InvalidDataException("TSP instance " + parser.Name + " contains fixed edges which are not supported by HeuristicLab.");
Note: See TracChangeset for help on using the changeset viewer.