Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13042 was 8670, checked in by svonolfe, 12 years ago

Added first version of the dynamic vehicle routing addon (#1955)

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