Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 12832 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 3.1 KB
RevLine 
[7466]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 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
[7618]38    protected override CVRPData LoadInstance(TSPLIBParser parser) {
[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    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.