Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBCVRPInstanceProvider.cs @ 15557

Last change on this file since 15557 was 14697, checked in by swagner, 8 years ago

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

File size: 3.3 KB
RevLine 
[7466]1#region License Information
2/* HeuristicLab
[14185]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[7466]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.IO;
24
25namespace HeuristicLab.Problems.Instances.TSPLIB {
[7618]26  public class TSPLIBCVRPInstanceProvider : TSPLIBInstanceProvider<CVRPData> {
[7482]27
[7466]28    public override string Name {
29      get { return "TSPLIB (CVRP)"; }
30    }
31
32    public override string Description {
33      get { return "Traveling Salesman Problem Library"; }
34    }
35
[7618]36    protected override string FileExtension { get { return "vrp"; } }
[7466]37
[13484]38    protected override CVRPData LoadInstance(TSPLIBParser parser, IDataDescriptor descriptor = null) {
[7538]39      parser.Parse();
[7548]40      var instance = new CVRPData();
[7538]41      instance.Dimension = parser.Dimension;
42      instance.Coordinates = parser.Vertices != null ? parser.Vertices : parser.DisplayVertices;
43      instance.Distances = parser.Distances;
44      instance.Capacity = parser.Capacity.Value;
45      instance.Demands = parser.Demands;
46      switch (parser.EdgeWeightType) {
47        case TSPLIBEdgeWeightTypes.ATT:
[7872]48          instance.DistanceMeasure = DistanceMeasure.Att; break;
[7538]49        case TSPLIBEdgeWeightTypes.CEIL_2D:
[7872]50          instance.DistanceMeasure = DistanceMeasure.UpperEuclidean; break;
[7538]51        case TSPLIBEdgeWeightTypes.EUC_2D:
52        case TSPLIBEdgeWeightTypes.EUC_3D:
[7872]53          instance.DistanceMeasure = DistanceMeasure.RoundedEuclidean; break;
[7538]54        case TSPLIBEdgeWeightTypes.EXPLICIT:
[7872]55          instance.DistanceMeasure = DistanceMeasure.Direct; break;
[7538]56        case TSPLIBEdgeWeightTypes.GEO:
[7872]57          instance.DistanceMeasure = DistanceMeasure.Geo; break;
[7538]58        case TSPLIBEdgeWeightTypes.MAN_2D:
59        case TSPLIBEdgeWeightTypes.MAN_3D:
[7872]60          instance.DistanceMeasure = DistanceMeasure.Manhattan; break;
[7538]61        case TSPLIBEdgeWeightTypes.MAX_2D:
62        case TSPLIBEdgeWeightTypes.MAX_3D:
[7872]63          instance.DistanceMeasure = DistanceMeasure.Maximum; break;
[7538]64        default:
65          throw new InvalidDataException("The given edge weight is not supported by HeuristicLab.");
66      }
67
68      instance.Name = parser.Name;
69      instance.Description = parser.Comment
70        + Environment.NewLine + Environment.NewLine
[7618]71        + GetInstanceDescription();
[7538]72
[7466]73      return instance;
74    }
75
[7618]76    protected override void LoadSolution(TSPLIBParser parser, CVRPData instance) {
77      parser.Parse();
78      instance.BestKnownTour = parser.Tour;
[7466]79    }
[14697]80
81    protected override void LoadQuality(double? bestQuality, CVRPData instance) {
82      instance.BestKnownQuality = bestQuality;
83    }
[7466]84  }
85}
Note: See TracBrowser for help on using the repository browser.