Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Parsers/LiLimParser.cs @ 6774

Last change on this file since 6774 was 6710, checked in by svonolfe, 13 years ago

Added support for pickups and deliveries (#1177)

File size: 4.2 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.Problems.VehicleRouting.Parsers {
28  class LiLimParser {
29    private string file;
30    private string problemName;
31    private int cities;
32    private int vehicles;
33    private double capacity;
34    private List<double> xCoord;
35    private List<double> yCoord;
36    private List<double> demand;
37    private List<double> readyTime;
38    private List<double> dueTime;
39    private List<double> serviceTime;
40    private List<int> pickipDeliveryLocation;
41
42    public int Cities {
43      get {
44        return cities;
45      }
46    }
47
48    public int Vehicles {
49      get {
50        return vehicles;
51      }
52    }
53
54    public double Capacity {
55      get {
56        return capacity;
57      }
58    }
59
60    public double[,] Coordinates {
61      get {
62        double[] x = xCoord.ToArray();
63        double[] y = yCoord.ToArray();
64        double[,] coord = new double[x.Length, 2];
65        for (int i = 0; i < x.Length; i++) {
66          coord[i, 0] = x[i];
67          coord[i, 1] = y[i];
68        }
69        return coord;
70      }
71    }
72
73    public double[] Demands {
74      get {
75        return demand.ToArray();
76      }
77    }
78
79    public double[] Readytimes {
80      get {
81        return readyTime.ToArray();
82      }
83    }
84
85    public double[] Duetimes {
86      get {
87        return dueTime.ToArray();
88      }
89    }
90
91    public double[] Servicetimes {
92      get {
93        return serviceTime.ToArray();
94      }
95    }
96
97    public int[] PickupDeliveryLocations {
98      get {
99        return pickipDeliveryLocation.ToArray();
100      }
101    }
102
103    public String ProblemName {
104      get {
105        return problemName;
106      }
107    }
108
109    public LiLimParser(string file) {
110      this.file = file;
111      xCoord = new List<double>();
112      yCoord = new List<double>();
113      demand = new List<double>();
114      readyTime = new List<double>();
115      dueTime = new List<double>();
116      serviceTime = new List<double>();
117      pickipDeliveryLocation = new List<int>();
118    }
119
120    public void Parse() {
121      string line;
122      Regex reg = new Regex(@"-?\d+");
123      MatchCollection m;
124
125      StreamReader reader = new StreamReader(file);
126
127      problemName = Path.GetFileNameWithoutExtension(file);
128      line = reader.ReadLine();
129
130      m = reg.Matches(line);
131      if (m.Count != 3)
132        throw new InvalidDataException("File has wrong format!");
133
134      vehicles = int.Parse(m[0].Value);
135      capacity = double.Parse(m[1].Value);
136
137      line = reader.ReadLine();
138      while ((line != null) && (line.Length > 5)) {
139        m = reg.Matches(line);
140        if (m.Count != 9) { continue; }
141        xCoord.Add((double)int.Parse(m[1].Value));
142        yCoord.Add((double)int.Parse(m[2].Value));
143        demand.Add((double)int.Parse(m[3].Value));
144        readyTime.Add((double)int.Parse(m[4].Value));
145        double st = (double)int.Parse(m[6].Value);
146        dueTime.Add((double)int.Parse(m[5].Value));
147        serviceTime.Add(st);
148
149        int location = int.Parse(m[7].Value);
150        if (location == 0)
151          location = int.Parse(m[8].Value);
152        pickipDeliveryLocation.Add(location);
153       
154        line = reader.ReadLine();
155      }
156      cities = serviceTime.Count;
157    }
158
159    internal string OnReset() {
160      throw new NotImplementedException();
161    }
162  }
163}
Note: See TracBrowser for help on using the repository browser.