Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 8364 was 7872, checked in by svonolfe, 13 years ago

Moved distance measure to helper class (#1782)

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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 {
26  public class TSPLIBCVRPInstanceProvider : TSPLIBInstanceProvider<CVRPData> {
27
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
36    protected override string FileExtension { get { return "vrp"; } }
37
38    protected override CVRPData LoadInstance(TSPLIBParser parser) {
39      parser.Parse();
40      var instance = new CVRPData();
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:
48          instance.DistanceMeasure = DistanceMeasure.Att; break;
49        case TSPLIBEdgeWeightTypes.CEIL_2D:
50          instance.DistanceMeasure = DistanceMeasure.UpperEuclidean; break;
51        case TSPLIBEdgeWeightTypes.EUC_2D:
52        case TSPLIBEdgeWeightTypes.EUC_3D:
53          instance.DistanceMeasure = DistanceMeasure.RoundedEuclidean; break;
54        case TSPLIBEdgeWeightTypes.EXPLICIT:
55          instance.DistanceMeasure = DistanceMeasure.Direct; break;
56        case TSPLIBEdgeWeightTypes.GEO:
57          instance.DistanceMeasure = DistanceMeasure.Geo; break;
58        case TSPLIBEdgeWeightTypes.MAN_2D:
59        case TSPLIBEdgeWeightTypes.MAN_3D:
60          instance.DistanceMeasure = DistanceMeasure.Manhattan; break;
61        case TSPLIBEdgeWeightTypes.MAX_2D:
62        case TSPLIBEdgeWeightTypes.MAX_3D:
63          instance.DistanceMeasure = DistanceMeasure.Maximum; break;
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
71        + GetInstanceDescription();
72
73      return instance;
74    }
75
76    protected override void LoadSolution(TSPLIBParser parser, CVRPData instance) {
77      parser.Parse();
78      instance.BestKnownTour = parser.Tour;
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.