Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/01/12 15:15:22 (12 years ago)
Author:
abeham
Message:

#1614

  • Fixed plugin dependencies
  • Updated GQAP view
  • Changed instances infrastructure
    • Changed interface types into classes
    • Removed the library specific instance classes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBTSPInstanceProvider.cs

    r7482 r7538  
    2828
    2929namespace HeuristicLab.Problems.Instances.TSPLIB {
    30   public class TSPLIBTSPInstanceProvider : ProblemInstanceProvider<ITSPInstance> {
     30  public class TSPLIBTSPInstanceProvider : ProblemInstanceProvider<TSPInstance> {
    3131
    3232    public override string Name {
     
    6565    }
    6666
    67     public override ITSPInstance GetInstance(IInstanceDescriptor id) {
     67    public override TSPInstance LoadInstance(IInstanceDescriptor id) {
    6868      var descriptor = (TSPLIBInstanceDescriptor)id;
    69       var instance = new TSPLIBTSPInstance();
    7069      using (var stream = Assembly.GetExecutingAssembly()
    7170        .GetManifestResourceStream(descriptor.InstanceIdentifier)) {
    7271        var parser = new TSPLIBParser(stream);
    73         parser.Parse();
    74         if (parser.FixedEdges != null) throw new InvalidDataException("TSP instance " + parser.Name + " contains fixed edges which are not supported by HeuristicLab.");
    75 
    76         instance.Dimension = parser.Dimension;
    77         instance.Coordinates = parser.Vertices != null ? parser.Vertices : parser.DisplayVertices;
    78         instance.Distances = parser.Distances;
    79         switch (parser.EdgeWeightType) {
    80           case TSPLIBEdgeWeightTypes.ATT:
    81             instance.DistanceMeasure = TSPDistanceMeasure.Att; break;
    82           case TSPLIBEdgeWeightTypes.CEIL_2D:
    83             instance.DistanceMeasure = TSPDistanceMeasure.UpperEuclidean; break;
    84           case TSPLIBEdgeWeightTypes.EUC_2D:
    85             instance.DistanceMeasure = TSPDistanceMeasure.RoundedEuclidean; break;
    86           case TSPLIBEdgeWeightTypes.EUC_3D:
    87             throw new InvalidDataException("3D coordinates are not supported.");
    88           case TSPLIBEdgeWeightTypes.EXPLICIT:
    89             instance.DistanceMeasure = TSPDistanceMeasure.Direct; break;
    90           case TSPLIBEdgeWeightTypes.GEO:
    91             instance.DistanceMeasure = TSPDistanceMeasure.Geo; break;
    92           case TSPLIBEdgeWeightTypes.MAN_2D:
    93             instance.DistanceMeasure = TSPDistanceMeasure.Manhattan; break;
    94           case TSPLIBEdgeWeightTypes.MAN_3D:
    95             throw new InvalidDataException("3D coordinates are not supported.");
    96           case TSPLIBEdgeWeightTypes.MAX_2D:
    97             instance.DistanceMeasure = TSPDistanceMeasure.Maximum; break;
    98           case TSPLIBEdgeWeightTypes.MAX_3D:
    99             throw new InvalidDataException("3D coordinates are not supported.");
    100           default:
    101             throw new InvalidDataException("The given edge weight is not supported by HeuristicLab.");
    102         }
    103 
    104         instance.Name = parser.Name;
    105         instance.Description = parser.Comment
    106           + Environment.NewLine + Environment.NewLine
    107           + GetDescription();
     72        var instance = Load(parser);
    10873
    10974        if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) {
     
    11580          }
    11681        }
     82        return instance;
    11783      }
     84    }
     85
     86    public override TSPInstance LoadInstance(string path) {
     87      return Load(new TSPLIBParser(path));
     88    }
     89
     90    public override void SaveInstance(TSPInstance instance, string path) {
     91      throw new NotSupportedException();
     92    }
     93
     94    private TSPInstance Load(TSPLIBParser parser) {
     95      parser.Parse();
     96      if (parser.FixedEdges != null) throw new InvalidDataException("TSP instance " + parser.Name + " contains fixed edges which are not supported by HeuristicLab.");
     97      var instance = new TSPInstance();
     98      instance.Dimension = parser.Dimension;
     99      instance.Coordinates = parser.Vertices != null ? parser.Vertices : parser.DisplayVertices;
     100      instance.Distances = parser.Distances;
     101      switch (parser.EdgeWeightType) {
     102        case TSPLIBEdgeWeightTypes.ATT:
     103          instance.DistanceMeasure = TSPDistanceMeasure.Att; break;
     104        case TSPLIBEdgeWeightTypes.CEIL_2D:
     105          instance.DistanceMeasure = TSPDistanceMeasure.UpperEuclidean; break;
     106        case TSPLIBEdgeWeightTypes.EUC_2D:
     107          instance.DistanceMeasure = TSPDistanceMeasure.RoundedEuclidean; break;
     108        case TSPLIBEdgeWeightTypes.EUC_3D:
     109          throw new InvalidDataException("3D coordinates are not supported.");
     110        case TSPLIBEdgeWeightTypes.EXPLICIT:
     111          instance.DistanceMeasure = TSPDistanceMeasure.Direct; break;
     112        case TSPLIBEdgeWeightTypes.GEO:
     113          instance.DistanceMeasure = TSPDistanceMeasure.Geo; break;
     114        case TSPLIBEdgeWeightTypes.MAN_2D:
     115          instance.DistanceMeasure = TSPDistanceMeasure.Manhattan; break;
     116        case TSPLIBEdgeWeightTypes.MAN_3D:
     117          throw new InvalidDataException("3D coordinates are not supported.");
     118        case TSPLIBEdgeWeightTypes.MAX_2D:
     119          instance.DistanceMeasure = TSPDistanceMeasure.Maximum; break;
     120        case TSPLIBEdgeWeightTypes.MAX_3D:
     121          throw new InvalidDataException("3D coordinates are not supported.");
     122        default:
     123          throw new InvalidDataException("The given edge weight is not supported by HeuristicLab.");
     124      }
     125
     126      instance.Name = parser.Name;
     127      instance.Description = parser.Comment
     128        + Environment.NewLine + Environment.NewLine
     129        + GetDescription();
    118130      return instance;
    119131    }
Note: See TracChangeset for help on using the changeset viewer.