Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Problems.VehicleRouting/3.3/ORLIBParser.cs @ 11201

Last change on this file since 11201 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 3.3 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.Globalization;
24using System.IO;
25
26namespace HeuristicLab.Problems.VehicleRouting {
27  class ORLIBParser {
28    private StreamReader source;
29    CultureInfo culture = new CultureInfo("en-US");
30   
31    private string name;
32    public string Name {
33      get {
34        return name;
35      }
36    }
37
38    private double[,] vertices;
39    public double[,] Vertices {
40      get {
41        return vertices;
42      }
43    }
44
45    private double capacity;
46    public double Capacity {
47      get {
48        return capacity;
49      }
50    }
51
52    private double maxRouteTime;
53    public double MaxRouteTime {
54      get {
55        return maxRouteTime;
56      }
57    }
58
59    private double serviceTime;
60    public double ServiceTime {
61      get {
62        return serviceTime;
63      }
64    }
65
66    private double[] demands;
67    public double[] Demands {
68      get {
69        return demands;
70      }
71    }
72
73    public ORLIBParser(String path) {
74      source = null;
75     
76      name = path;
77      vertices = null;
78      capacity = -1;
79      maxRouteTime = -1;
80      serviceTime = -1;
81      demands = null;
82    }
83
84    public void Parse() {
85      using (source = new StreamReader(name)) {
86        //Read header
87        string line = source.ReadLine();
88        string[] tokens = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
89
90        int customers = int.Parse(tokens[0]);
91        demands = new double[customers + 1];
92        demands[0] = 0;
93        vertices = new double[customers + 1, 2];
94
95        capacity = int.Parse(tokens[1]);
96        maxRouteTime = int.Parse(tokens[2]);
97        serviceTime = int.Parse(tokens[3]);
98
99        //Read depot
100        line = source.ReadLine();
101        tokens = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
102        vertices[0, 0] = double.Parse(tokens[0], culture.NumberFormat);
103        vertices[0, 1] = double.Parse(tokens[1], culture.NumberFormat);
104
105        for (int i = 0; i < customers; i++) {
106          line = source.ReadLine();
107          tokens = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
108          vertices[i + 1, 0] = double.Parse(tokens[0], culture.NumberFormat);
109          vertices[i + 1, 1] = double.Parse(tokens[1], culture.NumberFormat);
110          demands[i + 1] = double.Parse(tokens[2], culture.NumberFormat);
111        }
112      }
113
114      source = null;
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.