Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 8675 was 8675, checked in by abeham, 12 years ago

#1955:

  • Added disposing of StreamReader to prevent file locking after parsing
  • Fixed regular expression pattern to match double values (hacky)
File size: 2.8 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);
50          v.yCoord = double.Parse(m[1].Value);
51          v.capacity = double.Parse(m[2].Value);
52          v.readyTime = double.Parse(m[3].Value);
53          v.dueTime = double.Parse(m[4].Value);
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);
67          o.pickupXCoord = double.Parse(m[1].Value);
68          o.pickupYCoord = double.Parse(m[2].Value);
69          o.deliveryXCoord = double.Parse(m[3].Value);
70          o.deliveryYCoord = double.Parse(m[4].Value);
71          o.demand = double.Parse(m[5].Value);
72          o.pickupServiceTime = double.Parse(m[6].Value);
73          o.pickupReadyTime = double.Parse(m[7].Value);
74          o.pickupDueTime = double.Parse(m[8].Value);
75          o.deliveryServiceTime = double.Parse(m[9].Value);
76          o.deliveryReadyTime = double.Parse(m[10].Value);
77          o.deliveryDueTime = double.Parse(m[11].Value);
78
79          orders.Add(o);
80        }
81      }
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.