Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/Parsers/DefaultDynPDPParser.cs @ 15517

Last change on this file since 15517 was 8795, checked in by svonolfe, 12 years ago

Fixed parsing of double values (#1955)

File size: 3.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.IO;
23using System.Text.RegularExpressions;
24
25namespace HeuristicLab.PDPSimulation {
26  class DefaultDynPDPParser : DynPDPParser {
27    public DefaultDynPDPParser(string file)
28      : base(file) {
29    }
30
31    public override void Parse() {
32      string line;
33      Regex reg = new Regex(@"-?(\d+\.\d+|\d+)");
34      MatchCollection m;
35
36      using (var reader = new StreamReader(file)) {
37
38        line = reader.ReadLine();
39        problemName = line;
40
41        line = reader.ReadLine();
42        int vehicleCount = int.Parse(line);
43
44        for (int i = 0; i < vehicleCount; i++) {
45          line = reader.ReadLine();
46          m = reg.Matches(line);
47          Vehicle v = new Vehicle();
48
49          v.xCoord = double.Parse(m[0].Value, System.Globalization.CultureInfo.InvariantCulture);
50          v.yCoord = double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture);
51          v.capacity = double.Parse(m[2].Value, System.Globalization.CultureInfo.InvariantCulture);
52          v.readyTime = double.Parse(m[3].Value, System.Globalization.CultureInfo.InvariantCulture);
53          v.dueTime = double.Parse(m[4].Value, System.Globalization.CultureInfo.InvariantCulture);
54
55          vehicles.Add(v);
56        }
57
58        line = reader.ReadLine();
59        int orderCount = int.Parse(line);
60        m = reg.Matches(line);
61        for (int i = 0; i < orderCount; i++) {
62          line = reader.ReadLine();
63          m = reg.Matches(line);
64          Order o = new Order();
65
66          o.revealedTime = double.Parse(m[0].Value, System.Globalization.CultureInfo.InvariantCulture);
67          o.pickupXCoord = double.Parse(m[1].Value, System.Globalization.CultureInfo.InvariantCulture);
68          o.pickupYCoord = double.Parse(m[2].Value, System.Globalization.CultureInfo.InvariantCulture);
69          o.deliveryXCoord = double.Parse(m[3].Value, System.Globalization.CultureInfo.InvariantCulture);
70          o.deliveryYCoord = double.Parse(m[4].Value, System.Globalization.CultureInfo.InvariantCulture);
71          o.demand = double.Parse(m[5].Value, System.Globalization.CultureInfo.InvariantCulture);
72          o.pickupServiceTime = double.Parse(m[6].Value, System.Globalization.CultureInfo.InvariantCulture);
73          o.pickupReadyTime = double.Parse(m[7].Value, System.Globalization.CultureInfo.InvariantCulture);
74          o.pickupDueTime = double.Parse(m[8].Value, System.Globalization.CultureInfo.InvariantCulture);
75          o.deliveryServiceTime = double.Parse(m[9].Value, System.Globalization.CultureInfo.InvariantCulture);
76          o.deliveryReadyTime = double.Parse(m[10].Value, System.Globalization.CultureInfo.InvariantCulture);
77          o.deliveryDueTime = double.Parse(m[11].Value, System.Globalization.CultureInfo.InvariantCulture);
78
79          orders.Add(o);
80        }
81      }
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.