Free cookie consent management tool by TermsFeed Policy Generator

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

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

Fixed parsing of double values (#1955)

File size: 3.6 KB
RevLine 
[8670]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 {
[8675]26  class DefaultDynPDPParser : DynPDPParser {
27    public DefaultDynPDPParser(string file)
28      : base(file) {
[8670]29    }
30
31    public override void Parse() {
32      string line;
[8675]33      Regex reg = new Regex(@"-?(\d+\.\d+|\d+)");
[8670]34      MatchCollection m;
35
[8675]36      using (var reader = new StreamReader(file)) {
[8670]37
[8675]38        line = reader.ReadLine();
39        problemName = line;
[8670]40
41        line = reader.ReadLine();
[8675]42        int vehicleCount = int.Parse(line);
[8670]43
[8675]44        for (int i = 0; i < vehicleCount; i++) {
45          line = reader.ReadLine();
46          m = reg.Matches(line);
47          Vehicle v = new Vehicle();
[8670]48
[8795]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);
[8670]54
[8675]55          vehicles.Add(v);
56        }
57
[8670]58        line = reader.ReadLine();
[8675]59        int orderCount = int.Parse(line);
[8670]60        m = reg.Matches(line);
[8675]61        for (int i = 0; i < orderCount; i++) {
62          line = reader.ReadLine();
63          m = reg.Matches(line);
64          Order o = new Order();
[8670]65
[8795]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);
[8670]78
[8675]79          orders.Add(o);
80        }
[8670]81      }
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.