MATSIM
VisumNetworkReader.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * VisumNetReader.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2008 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.visum;
22 
23 import java.io.BufferedReader;
24 import java.io.IOException;
25 import java.io.UncheckedIOException;
26 import java.nio.charset.Charset;
27 import java.nio.charset.StandardCharsets;
28 
29 import org.apache.logging.log4j.LogManager;
30 import org.apache.logging.log4j.Logger;
31 import org.matsim.api.core.v01.Coord;
32 import org.matsim.api.core.v01.Id;
35 import org.matsim.core.utils.io.IOUtils;
40 
41 
42 public class VisumNetworkReader {
43 
44  private static final String ATTRIBUTE_UNKNOWN = "%%%KEINE_AHNUNG%%%";
45 
46  private final VisumNetwork network;
47 
48  private final Logger log = LogManager.getLogger(VisumNetworkReader.class);
49 
51  private int language = 0;
52 
53  /* collection of localized strings: [0] english, [1] german */
54 
55  // reusable strings
56 
57  private final String[] GENERAL_DCODE = {"DIRECTIONCODE", "RICHTUNGCODE"};
58  private final String[] GENERAL_INDEX = {"INDEX", "INDEX"};
59  private final String[] GENERAL_NAME = {"NAME", "NAME"};
60  private final String[] GENERAL_NO = {"NO", "NR"};
61  private final String[] GENERAL_LINENAME = {"LINENAME", "LINNAME"};
62  private final String[] GENERAL_LINEROUTENAME = {"LINEROUTENAME", "LINROUTENAME"};
63 
64  // specific strings
65 
66  private final String[] TABLE_LINKTYPE = {"$LINKTYPE:", "$STRECKENTYP:"};
67  private final String[] TABLE_STOP = {"$STOP:", "$HALTESTELLE:"};
68  private final String[] TABLE_STOPAREA = {"$STOPAREA:", "$HALTESTELLENBEREICH:"};
69  private final String[] TABLE_STOPPOINT = {"$STOPPOINT:", "$HALTEPUNKT:"};
70  private final String[] TABLE_LINE = {"$LINE:", "$LINIE:"};
71  private final String[] TABLE_LINEROUTE = {"$LINEROUTE:", "$LINIENROUTE:"};
72  private final String[] TABLE_LINEROUTEITEM = {"$LINEROUTEITEM:", "$LINIENROUTENELEMENT:"};
73  private final String[] TABLE_TIMEPROFILE = {"$TIMEPROFILE:", "$FAHRZEITPROFIL:"};
74  private final String[] TABLE_TIMEPROFILEITEM = {"$TIMEPROFILEITEM:", "$FAHRZEITPROFILELEMENT:"};
75  private final String[] TABLE_VEHJOURNEY = {"$VEHJOURNEY:", "$FZGFAHRT:"};
76 // private final String[] TABLE_VEHJOURNEYITEM = {"$VEHJOURNEYITEM:", "$FZGFAHRTELEMENT:"};
77  private final String[] TABLE_VEHJOURNEYSECTION = {"$VEHJOURNEYSECTION:", "$FZGFAHRTABSCHNITT:"};
78  private final String[] TABLE_VEHUNIT = {"$VEHUNIT:", "$FZGEINHEIT:"};
79  private final String[] TABLE_VEHCOMB = {"$VEHCOMB:", "$FZGKOMB:"};
80  private final String[] TABLE_VEHUNITTOVEHCOMB = {"$VEHUNITTOVEHCOMB:", "$FZGEINHEITZUFZGKOMB:"};
81 
82  private final String[] ATTRIBUTE_LINKTYPE_NO = GENERAL_NO;
83  private final String[] ATTRIBUTE_LINKTYPE_KAPIV = {"CAPPRT", "KAPIV"};
84  private final String[] ATTRIBUTE_LINKTYPE_V0IV = {"V0PRT", "V0IV"};
85  private final String[] ATTRIBUTE_LINKTYPE_NOLANES = {"NUMLANES", "ANZFAHRSTREIFEN"};
86 
87  private final String[] ATTRIBUTE_STOP_NO = GENERAL_NO;
88  private final String[] ATTRIBUTE_STOP_NAME = GENERAL_NAME;
89  private final String[] ATTRIBUTE_STOP_XCOORD = {"XCOORD", "XKOORD"};
90  private final String[] ATTRIBUTE_STOP_YCOORD = {"YCOORD", "YKOORD"};
91 
92  private final String[] ATTRIBUTE_STOPAREA_NO = GENERAL_NO;
93  private final String[] ATTRIBUTE_STOPAREA_STOPNO = {"STOPNO", "HSTNR"};
94 
95  private final String[] ATTRIBUTE_STOPPT_NO = GENERAL_NO;
96  private final String[] ATTRIBUTE_STOPPT_STOPAREANO = {"STOPAREANO", "HSTBERNR"};
97  private final String[] ATTRIBUTE_STOPPT_NAME = GENERAL_NAME;
98  private final String[] ATTRIBUTE_STOPPT_RLNO = {"LINKNO", "STRNR"};
99  private final String[] ATTRIBUTE_STOPPT_NODE = {"NODENO", "KNOTNR"};
100 
101  private final String[] ATTRIBUTE_LR_NAME = GENERAL_NAME;
102  private final String[] ATTRIBUTE_LR_LINENAME = GENERAL_LINENAME;
103  private final String[] ATTRIBUTE_LR_DCODE = GENERAL_DCODE;
104  private final String[] ATTRIBUTE_LR_TAKT = {ATTRIBUTE_UNKNOWN, "TAKT_TAG_HVZ"};
105 
106  private final String[] ATTRIBUTE_L_NAME = GENERAL_NAME;
107  private final String[] ATTRIBUTE_L_TCODE = {"TSYSCODE", "VSYSCODE"};
108  private final String[] ATTRIBUTE_L_VEHCOMBNO = {"VEHCOMBNO", "FZGKOMBNR"};
109 
110  private final String[] ATTRIBUTE_LRI_LRNAME = GENERAL_LINEROUTENAME;
111  private final String[] ATTRIBUTE_LRI_LNAME = GENERAL_LINENAME;
112  private final String[] ATTRIBUTE_LRI_ID = GENERAL_INDEX;
113  private final String[] ATTRIBUTE_LRI_DCODE = GENERAL_DCODE;
114  private final String[] ATTRIBUTE_LRI_NODEID = {"NODENO", "KNOTNR"};
115  private final String[] ATTRIBUTE_LRI_SPNO = {"STOPPOINTNO", "HPUNKTNR"};
116 
117  private final String[] ATTRIBUTE_TP_LNAME = GENERAL_LINENAME;
118  private final String[] ATTRIBUTE_TP_LRNAME = GENERAL_LINEROUTENAME;
119  private final String[] ATTRIBUTE_TP_ID = GENERAL_NAME;
120  private final String[] ATTRIBUTE_TP_DCODE = GENERAL_DCODE;
121  private final String[] ATTRIBUTE_TP_VEHCOMBNO = {"VEHCOMBNO", "FZGKOMBNR"};
122 
123  private final String[] ATTRIBUTE_TPI_LNAME = GENERAL_LINENAME;
124  private final String[] ATTRIBUTE_TPI_LRNAME = GENERAL_LINEROUTENAME;
125  private final String[] ATTRIBUTE_TPI_ID = GENERAL_INDEX;
126  private final String[] ATTRIBUTE_TPI_TPNAME = {"TIMEPROFILENAME", "FZPROFILNAME"};
127  private final String[] ATTRIBUTE_TPI_DCODE = GENERAL_DCODE;
128  private final String[] ATTRIBUTE_TPI_ARR = {"ARR", "ANKUNFT"};
129  private final String[] ATTRIBUTE_TPI_DEP = {"DEP", "ABFAHRT"};
130  private final String[] ATTRIBUTE_TPI_LRIINDEX = {"LRITEMINDEX", "LRELEMINDEX"};
131 
132  private final String[] ATTRIBUTE_D_LNAME = GENERAL_LINENAME;
133  private final String[] ATTRIBUTE_D_LRNAME = GENERAL_LINEROUTENAME;
134  private final String[] ATTRIBUTE_D_ID = GENERAL_NO;
135  private final String[] ATTRIBUTE_D_TPNAME = {"TIMEPROFILENAME", "FZPROFILNAME"};
136  private final String[] ATTRIBUTE_D_DEP = {"DEP", "ABFAHRT"};
137  private final String[] ATTRIBUTE_D_DCODE = GENERAL_DCODE;
138 
139  private final String[] ATTRIBUTE_VJS_VEHJOURNEYNO = {"VEHJOURNEYNO", "FZGFAHRTNR"}; // vehicle journey section
140  private final String[] ATTRIBUTE_VJS_VEHCOMBNO = {"VEHCOMBNO", "FZGKOMBNR"};
141 
142  private final String[] ATTRIBUTE_VEHUNIT_ID = GENERAL_NO;
143  private final String[] ATTRIBUTE_VEHUNIT_CODE = {"CODE", "CODE"};
144  private final String[] ATTRIBUTE_VEHUNIT_SEATCAP = {"SEATCAP", "SITZPL"};
145  private final String[] ATTRIBUTE_VEHUNIT_TOTALCAP = {"TOTALCAP", "GESAMTPL"};
146 
147  private final String[] ATTRIBUTE_VEHCOMB_NO = GENERAL_NO;
148  private final String[] ATTRIBUTE_VEHCOMB_NAME = GENERAL_NAME;
149 
150  private final String[] ATTRIBUTE_VEHUNITTOVEHCOMB_VEHCOMBNO = {"VEHCOMBNO", "FZGKOMBNR"};
151  private final String[] ATTRIBUTE_VEHUNITTOVEHCOMB_VEHUNITNO = {"VEHUNITNO", "FZGEINHEITNR"};
152  private final String[] ATTRIBUTE_VEHUNITTOVEHCOMB_NUMVEHUNITS = {"NUMVEHUNITS", "ANZFZGEINH"};
153 
154  public VisumNetworkReader(final VisumNetwork network) {
155  this.network = network;
156  }
157 
158  public void read(final String filename) throws UncheckedIOException {
159  BufferedReader reader = IOUtils.getBufferedReader(IOUtils.getFileUrl(filename), StandardCharsets.ISO_8859_1);
160 
161  try {
162  String line = reader.readLine();
163  if (!"$VISION".equals(line)) {
164  throw new IOException("File does not start with '$VISION'. Are you sure it is a VISUM network file?");
165  }
166  // next line after header:
167  line = reader.readLine();
168  while (line != null) {
169  if (line.startsWith("$VERSION:")) {
170  readVersion(line, reader);
171  } else if (line.startsWith(this.TABLE_STOP[this.language])) {
172  readStops(line, reader);
173  } else if (line.startsWith(this.TABLE_LINKTYPE[this.language])) {
174  readEdgeTypes(line, reader);
175  } else if (line.startsWith(this.TABLE_STOPAREA[this.language])) {
176  readStopAreas(line, reader);
177  } else if (line.startsWith(this.TABLE_STOPPOINT[this.language])) {
178  readStopPoints(line, reader);
179  } else if (line.startsWith(this.TABLE_LINE[this.language])) {
180  readLines(line, reader);
181  } else if (line.startsWith(this.TABLE_LINEROUTE[this.language])) {
182  readLineRoutes(line, reader);
183  } else if (line.startsWith(this.TABLE_LINEROUTEITEM[this.language])) {
184  readLineRouteItems(line, reader);
185  } else if (line.startsWith(this.TABLE_TIMEPROFILE[this.language])) {
186  readTimeProfile(line, reader);
187  } else if (line.startsWith(this.TABLE_TIMEPROFILEITEM[this.language])) {
188  readTimeProfileItems(line, reader);
189  } else if (line.startsWith(this.TABLE_VEHJOURNEY[this.language])) {
190  readDepartures(line, reader);
191  } else if (line.startsWith(this.TABLE_VEHJOURNEYSECTION[this.language])) {
192  readDepartureSections(line, reader);
193  } else if (line.startsWith(this.TABLE_VEHUNIT[this.language])) {
194  readVehicleUnits(line, reader);
195  } else if (line.startsWith(this.TABLE_VEHCOMB[this.language])) {
196  readVehicleCombinations(line, reader);
197  } else if (line.startsWith(this.TABLE_VEHUNITTOVEHCOMB[this.language])) {
199  } else if (line.startsWith("$")) {
200  readUnknownTable(reader);
201  } else if (!line.startsWith("* ")) {
202  throw new IOException("cannot interpret line: " + line);
203  }
204  // next line:
205  line = reader.readLine();
206  }
207 
208  } catch (IOException e) {
209  this.log.warn("there was an exception while reading the file.", e);
210  try {
211  reader.close();
212  } catch (IOException e2) {
213  this.log.warn("could not close reader.", e2);
214  }
215  throw new UncheckedIOException(e);
216  }
217 
218  try {
219  reader.close();
220  } catch (IOException e) {
221  this.log.warn("could not close reader.", e);
222  }
223 
224  }
225 
226 
227  private void readVersion(final String tableAttributes, final BufferedReader reader) throws IOException {
228  final String[] attributes = StringUtils.explode(tableAttributes.substring("$VERSION:".length()), ';');
229  final int idxLanguage = getAttributeIndex("LANGUAGE", attributes);
230 
231  String line = reader.readLine();
232  if (line == null) {
233  throw new RuntimeException("Language definition cannot be found.");
234  }
235  final String[] parts = StringUtils.explode(line, ';');
236  if (parts[idxLanguage].equals("ENG")) {
237  this.language = 0;
238  } else if (parts[idxLanguage].equals("DEU")) {
239  this.language = 1;
240  } else {
241  throw new RuntimeException("Unknown language: " + parts[idxLanguage]);
242  }
243  // proceed to next line, assumed to be empty
244  reader.readLine();
245  }
246 
247  private void readEdgeTypes(String tableAttributes, BufferedReader reader) throws IOException {
248  final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_LINKTYPE[this.language].length()), ';');
249  final int idxNo = getAttributeIndex(this.ATTRIBUTE_LINKTYPE_NO[this.language], attributes);
250  final int idxKapIV = getAttributeIndex(this.ATTRIBUTE_LINKTYPE_KAPIV[this.language], attributes);
251  final int idxV0IV = getAttributeIndex(this.ATTRIBUTE_LINKTYPE_V0IV[this.language], attributes);
252  final int idxNoOfLanes = getAttributeIndex(this.ATTRIBUTE_LINKTYPE_NOLANES[this.language], attributes);
253 
254  String line = reader.readLine();
255  while (line != null && line.length() > 0) {
256  final String[] parts = StringUtils.explode(line, ';');
257  VisumNetwork.EdgeType edgeType = new VisumNetwork.EdgeType(Id.create(parts[idxNo], VisumNetwork.EdgeType.class), parts[idxKapIV], parts[idxV0IV], parts[idxNoOfLanes]);
258  this.network.addEdgeType(edgeType);
259  // proceed to next line
260  line = reader.readLine();
261  }
262  }
263 
264  private void readStops(final String tableAttributes, final BufferedReader reader) throws IOException {
265  final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_STOP[this.language].length()), ';');
266  final int idxNo = getAttributeIndex(this.ATTRIBUTE_STOP_NO[this.language], attributes);
267  final int idxName = getAttributeIndex(this.ATTRIBUTE_STOP_NAME[this.language], attributes);
268  final int idxXcoord = getAttributeIndex(this.ATTRIBUTE_STOP_XCOORD[this.language], attributes);
269  final int idxYcoord = getAttributeIndex(this.ATTRIBUTE_STOP_YCOORD[this.language], attributes);
270 
271  String line = reader.readLine();
272  while (line != null && line.length() > 0) {
273  final String[] parts = StringUtils.explode(line, ';');
274  VisumNetwork.Stop stop = new VisumNetwork.Stop(Id.create(parts[idxNo], VisumNetwork.Stop.class), parts[idxName],
275  new Coord(Double.parseDouble(parts[idxXcoord].replace(',', '.')), Double.parseDouble(parts[idxYcoord].replace(',', '.'))));
276  this.network.addStop(stop);
277  // proceed to next line
278  line = reader.readLine();
279  }
280  }
281 
282  private void readStopAreas(final String tableAttributes, final BufferedReader reader) throws IOException {
283  final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_STOPAREA[this.language].length()), ';');
284  final int idxNo = getAttributeIndex(this.ATTRIBUTE_STOPAREA_NO[this.language], attributes);
285  final int idxStopId = getAttributeIndex(this.ATTRIBUTE_STOPAREA_STOPNO[this.language], attributes);
286 
287  String line = reader.readLine();
288  while (line != null && line.length() > 0) {
289  final String[] parts = StringUtils.explode(line, ';');
290  VisumNetwork.StopArea stopAr = new VisumNetwork.StopArea(Id.create(parts[idxNo], VisumNetwork.StopArea.class), Id.create(parts[idxStopId], VisumNetwork.Stop.class));
291  this.network.addStopArea(stopAr);
292  // proceed to next line
293  line = reader.readLine();
294  }
295  }
296  private void readStopPoints(final String tableAttributes, final BufferedReader reader) throws IOException {
297  final String[] attributes = StringUtils.explode(tableAttributes.substring( this.TABLE_STOPPOINT[this.language].length()), ';');
298  final int idxNo = getAttributeIndex(this.ATTRIBUTE_STOPPT_NO[this.language], attributes);
299  final int idxStopAreaNo = getAttributeIndex(this.ATTRIBUTE_STOPPT_STOPAREANO[this.language], attributes);
300  final int idxName = getAttributeIndex(this.ATTRIBUTE_STOPPT_NAME[this.language], attributes);
301  final int idxRLNo = getAttributeIndex(this.ATTRIBUTE_STOPPT_RLNO[this.language], attributes);
302  final int idxNode = getAttributeIndex(this.ATTRIBUTE_STOPPT_NODE[this.language], attributes);
303  String line = reader.readLine();
304  while (line != null && line.length() > 0) {
305  final String[] parts = StringUtils.explode(line, ';');
306  VisumNetwork.StopPoint stopPt = new VisumNetwork.StopPoint(Id.create(parts[idxNo], VisumNetwork.StopPoint.class),
307  Id.create(parts[idxStopAreaNo], VisumNetwork.StopArea.class),
308  parts[idxName],
309  Id.create(parts[idxRLNo], Link.class), Id.create(parts[idxNode], Node.class));
310  this.network.addStopPoint(stopPt);
311  // proceed to next line
312  line = reader.readLine();
313  }
314  }
315  private void readLineRoutes(final String tableAttributes, final BufferedReader reader) throws IOException {
316  final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_LINEROUTE[this.language].length()), ';');
317  final int idxName = getAttributeIndex(this.ATTRIBUTE_LR_NAME[this.language], attributes);
318  final int idxLineName = getAttributeIndex(this.ATTRIBUTE_LR_LINENAME[this.language], attributes);
319  final int idxDCode = getAttributeIndex(this.ATTRIBUTE_LR_DCODE[this.language], attributes);
320  final int idxTakt = getAttributeIndex(this.ATTRIBUTE_LR_TAKT[this.language], attributes);
321 
322  String line = reader.readLine();
323  while (line != null && line.length() > 0) {
324  final String[] parts = StringUtils.explode(line, ';');
326  Id.create(parts[idxName], TransitLineRoute.class),
327  Id.create(parts[idxLineName], TransitLine.class),
328  parts[idxDCode]);
329  if (idxTakt != -1) {
330  lr1.takt = parts[idxTakt];
331  }
332  this.network.addLineRoute(lr1);
333  // proceed to next line
334  line = reader.readLine();
335  }
336  }
337  private void readLines(final String tableAttributes, final BufferedReader reader) throws IOException {
338  final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_LINE[this.language].length()), ';');
339  final int idxName = getAttributeIndex(this.ATTRIBUTE_L_NAME[this.language], attributes);
340  final int idxTCode = getAttributeIndex(this.ATTRIBUTE_L_TCODE[this.language], attributes);
341  final int idxVehCombNo = getAttributeIndex(this.ATTRIBUTE_L_VEHCOMBNO[this.language], attributes);
342 
343  String line = reader.readLine();
344  while (line != null && line.length() > 0) {
345  final String[] parts = StringUtils.explode(line, ';');
347  Id.create(parts[idxName], TransitLine.class),
348  parts[idxTCode], parts[idxVehCombNo]);
349  this.network.addline(tLine);
350  // proceed to next line
351  line = reader.readLine();
352  }
353  }
354  private void readLineRouteItems(final String tableAttributes, final BufferedReader reader) throws IOException {
355  final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_LINEROUTEITEM[this.language].length()), ';');
356  final int idxLineRouteName = getAttributeIndex(this.ATTRIBUTE_LRI_LRNAME[this.language], attributes);
357  final int idxLineName = getAttributeIndex(this.ATTRIBUTE_LRI_LNAME[this.language], attributes);
358  final int idxIndex = getAttributeIndex(this.ATTRIBUTE_LRI_ID[this.language], attributes);
359  final int idxDCode = getAttributeIndex(this.ATTRIBUTE_LRI_DCODE[this.language], attributes);
360  final int idxNodeId = getAttributeIndex(this.ATTRIBUTE_LRI_NODEID[this.language], attributes);
361  final int idxStopPointNo = getAttributeIndex(this.ATTRIBUTE_LRI_SPNO[this.language], attributes);
362 
363 
364  String line = reader.readLine();
365  while (line != null && line.length() > 0) {
366  final String[] parts = StringUtils.explode(line, ';');
367  Id<Node> nodeId = Id.create(parts[idxNodeId], Node.class);
368  String stopPointNoString = parts[idxStopPointNo];
369  Id<StopPoint> stopPointNo;
370  if (stopPointNoString.length() == 0) {
371  stopPointNo = null;
372  } else {
373  stopPointNo = Id.create(stopPointNoString, StopPoint.class);
374  }
375  VisumNetwork.LineRouteItem lri1 = new VisumNetwork.LineRouteItem(parts[idxLineName],parts[idxLineRouteName],parts[idxIndex],parts[idxDCode],nodeId,stopPointNo);
376  this.network.addLineRouteItem(lri1);
377  // proceed to next line
378  line = reader.readLine();
379  }
380  }
381  private void readTimeProfile(final String tableAttributes, final BufferedReader reader) throws IOException {
382  final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_TIMEPROFILE[this.language].length()), ';');
383  final int idxLineName = getAttributeIndex(this.ATTRIBUTE_TP_LNAME[this.language], attributes);
384  final int idxLineRouteName = getAttributeIndex(this.ATTRIBUTE_TP_LRNAME[this.language], attributes);
385  final int idxIndex = getAttributeIndex(this.ATTRIBUTE_TP_ID[this.language], attributes);
386  final int idxDCode = getAttributeIndex(this.ATTRIBUTE_TP_DCODE[this.language], attributes);
387  final int idxVehCombNo = getAttributeIndex(this.ATTRIBUTE_TP_VEHCOMBNO[this.language], attributes);
388 
389  String line = reader.readLine();
390  while (line != null && line.length() > 0) {
391  final String[] parts = StringUtils.explode(line, ';');
392 
393  VisumNetwork.TimeProfile tp1 = new VisumNetwork.TimeProfile(Id.create(parts[idxLineName], VisumNetwork.TransitLine.class),
394  Id.create(parts[idxLineRouteName], TransitLineRoute.class), Id.create(parts[idxIndex], VisumNetwork.TimeProfile.class),
395  parts[idxDCode],
396  parts[idxVehCombNo]);
397  this.network.addTimeProfile(tp1);
398  // proceed to next line
399  line = reader.readLine();
400  }
401  }
402  private void readTimeProfileItems(final String tableAttributes, final BufferedReader reader) throws IOException {
403  final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_TIMEPROFILEITEM[this.language].length()), ';');
404  final int idxLineRouteName = getAttributeIndex(this.ATTRIBUTE_TPI_LRNAME[this.language], attributes);
405  final int idxLineName = getAttributeIndex(this.ATTRIBUTE_TPI_LNAME[this.language], attributes);
406  final int idxTPName = getAttributeIndex(this.ATTRIBUTE_TPI_TPNAME[this.language], attributes);
407  final int idxDCode = getAttributeIndex(this.ATTRIBUTE_TPI_DCODE[this.language], attributes);
408  final int idxIndex = getAttributeIndex(this.ATTRIBUTE_TPI_ID[this.language], attributes);
409  final int idxArr = getAttributeIndex(this.ATTRIBUTE_TPI_ARR[this.language], attributes);
410  final int idxDep = getAttributeIndex(this.ATTRIBUTE_TPI_DEP[this.language], attributes);
411  final int idxLRIIndex = getAttributeIndex(this.ATTRIBUTE_TPI_LRIINDEX[this.language], attributes);
412 
413  String line = reader.readLine();
414  while (line != null && line.length() > 0) {
415  final String[] parts = StringUtils.explode(line, ';');
416 
417  VisumNetwork.TimeProfileItem tpi1 = new VisumNetwork.TimeProfileItem(parts[idxLineName], parts[idxLineRouteName],
418  parts[idxTPName], parts[idxDCode], parts[idxIndex], parts[idxArr], parts[idxDep],
419  Id.create(parts[idxLRIIndex], VisumNetwork.TimeProfileItem.class));
420  this.network.addTimeProfileItem(tpi1);
421  // proceed to next line
422  line = reader.readLine();
423  }
424  }
425 
426  private void readDepartures(final String tableAttributes, final BufferedReader reader) throws IOException {
427  final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_VEHJOURNEY[this.language].length()), ';');
428  final int idxLineRouteName = getAttributeIndex(this.ATTRIBUTE_D_LRNAME[this.language], attributes);
429  final int idxLineName = getAttributeIndex(this.ATTRIBUTE_D_LNAME[this.language], attributes);
430  final int idxNo = getAttributeIndex(this.ATTRIBUTE_D_ID[this.language], attributes);
431  final int idxTRI = getAttributeIndex(this.ATTRIBUTE_D_TPNAME[this.language], attributes);
432  final int idxDep = getAttributeIndex(this.ATTRIBUTE_D_DEP[this.language], attributes);
433  final int idxDCode = getAttributeIndex(this.ATTRIBUTE_D_DCODE[this.language], attributes);
434 
435  String line = reader.readLine();
436  while (line != null && line.length() > 0) {
437  final String[] parts = StringUtils.explode(line, ';');
438 
439  VisumNetwork.Departure d = new VisumNetwork.Departure(parts[idxLineName], parts[idxLineRouteName], parts[idxNo], parts[idxTRI], parts[idxDep], parts[idxDCode]);
440  this.network.addDeparture(d);
441  // proceed to next line
442  line = reader.readLine();
443  }
444  }
445 
446  private void readDepartureSections(final String tableAttributes, final BufferedReader reader) throws IOException {
447  final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_VEHJOURNEYSECTION[this.language].length()), ';');
448  final int idxVehicleJourneyNo = getAttributeIndex(this.ATTRIBUTE_VJS_VEHJOURNEYNO[this.language], attributes);
449  final int idxVehCombinationNo = getAttributeIndex(this.ATTRIBUTE_VJS_VEHCOMBNO[this.language], attributes);
450 
451  String line = reader.readLine();
452  while (line != null && line.length() > 0) {
453  final String[] parts = StringUtils.explode(line, ';');
454 
455  String vehJourneyNo = parts[idxVehicleJourneyNo];
456  String vehCombNo = parts[idxVehCombinationNo];
457  VisumNetwork.Departure d = this.network.departuresByNo.get(vehJourneyNo);
458  d.vehCombinationNo = vehCombNo;
459  // proceed to next line
460  line = reader.readLine();
461  }
462  }
463 
464  private void readVehicleUnits(final String tableAttributes, final BufferedReader reader) throws IOException {
465  final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_VEHUNIT[this.language].length()), ';');
466  final int idxId = getAttributeIndex(this.ATTRIBUTE_VEHUNIT_ID[this.language], attributes);
467  final int idxCode = getAttributeIndex(this.ATTRIBUTE_VEHUNIT_CODE[this.language], attributes);
468  final int idxSeatCap = getAttributeIndex(this.ATTRIBUTE_VEHUNIT_SEATCAP[this.language], attributes);
469  final int idxTotalCap = getAttributeIndex(this.ATTRIBUTE_VEHUNIT_TOTALCAP[this.language], attributes);
470 
471  String line = reader.readLine();
472  while (line != null && line.length() > 0) {
473  final String[] parts = StringUtils.explode(line, ';');
474 
475  VisumNetwork.VehicleUnit vehicleUnit = new VisumNetwork.VehicleUnit(parts[idxId], parts[idxCode],
476  Integer.parseInt(parts[idxSeatCap]), Integer.parseInt(parts[idxTotalCap]));
477  this.network.addVehicleUnit(vehicleUnit);
478  // proceed to next line
479  line = reader.readLine();
480  }
481  }
482 
483  private void readVehicleCombinations(final String tableAttributes, final BufferedReader reader) throws IOException {
484  final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_VEHCOMB[this.language].length()), ';');
485  final int idxId = getAttributeIndex(this.ATTRIBUTE_VEHCOMB_NO[this.language], attributes);
486  final int idxName = getAttributeIndex(this.ATTRIBUTE_VEHCOMB_NAME[this.language], attributes);
487 
488  String line = reader.readLine();
489  while (line != null && line.length() > 0) {
490  final String[] parts = StringUtils.explode(line, ';');
491 
492  VisumNetwork.VehicleCombination vehicleComb = new VisumNetwork.VehicleCombination(parts[idxId], parts[idxName]);
493  this.network.addVehicleCombination(vehicleComb);
494  // proceed to next line
495  line = reader.readLine();
496  }
497  }
498 
499  private void readVehicleUnitToVehicleCombination(final String tableAttributes, final BufferedReader reader) throws IOException {
500  final String[] attributes = StringUtils.explode(tableAttributes.substring(this.TABLE_VEHUNITTOVEHCOMB[this.language].length()), ';');
501  final int idxVehicleUnit = getAttributeIndex(this.ATTRIBUTE_VEHUNITTOVEHCOMB_VEHUNITNO[this.language], attributes);
502  final int idxVehicleComb = getAttributeIndex(this.ATTRIBUTE_VEHUNITTOVEHCOMB_VEHCOMBNO[this.language], attributes);
503  final int idxVehicleNumber = getAttributeIndex(this.ATTRIBUTE_VEHUNITTOVEHCOMB_NUMVEHUNITS[this.language], attributes);
504 
505  String line = reader.readLine();
506  while (line != null && line.length() > 0) {
507  final String[] parts = StringUtils.explode(line, ';');
508 
509  VisumNetwork.VehicleCombination vehicleComb = this.network.vehicleCombinations.get(parts[idxVehicleComb]);
510  vehicleComb.vehUnitId = parts[idxVehicleUnit];
511  vehicleComb.numOfVehicles = Integer.parseInt(parts[idxVehicleNumber]);
512  // proceed to next line
513  line = reader.readLine();
514  }
515  }
516 
517  private void readUnknownTable(final BufferedReader reader) throws IOException {
518  String line = reader.readLine();
519  while (line != null && line.length() > 0) {
520 
521  line = reader.readLine();
522  }
523  }
524 
525  private int getAttributeIndex(final String attribute, final String[] attributes) {
526  for (int i = 0; i < attributes.length; i++) {
527  if (attributes[i].equals(attribute)) {
528  return i;
529  }
530  }
531  return -1;
532  }
533 }
void readTimeProfile(final String tableAttributes, final BufferedReader reader)
void addLineRoute(final TransitLineRoute lr1)
void readDepartureSections(final String tableAttributes, final BufferedReader reader)
void readDepartures(final String tableAttributes, final BufferedReader reader)
void addStop(final Stop stop)
void addStopArea(final StopArea stopAr)
void addEdgeType(final EdgeType edgeType)
void readStops(final String tableAttributes, final BufferedReader reader)
void addline(final TransitLine l1)
static BufferedReader getBufferedReader(URL url, Charset charset)
Definition: IOUtils.java:321
static URL getFileUrl(String filename)
Definition: IOUtils.java:501
static String [] explode(final String str, final char delimiter, final int limit)
void readStopPoints(final String tableAttributes, final BufferedReader reader)
static< T > Id< T > create(final long key, final Class< T > type)
Definition: Id.java:68
void addStopPoint(final StopPoint stopPt)
void readEdgeTypes(String tableAttributes, BufferedReader reader)
void addVehicleCombination(final VehicleCombination vehComb)
void addTimeProfile(final TimeProfile tp1)
int getAttributeIndex(final String attribute, final String[] attributes)
final Map< String, Departure > departuresByNo
void readLineRouteItems(final String tableAttributes, final BufferedReader reader)
void readVehicleUnits(final String tableAttributes, final BufferedReader reader)
void readLines(final String tableAttributes, final BufferedReader reader)
final Map< String, VehicleCombination > vehicleCombinations
void readStopAreas(final String tableAttributes, final BufferedReader reader)
void readLineRoutes(final String tableAttributes, final BufferedReader reader)
void readVehicleUnitToVehicleCombination(final String tableAttributes, final BufferedReader reader)
void addLineRouteItem(final LineRouteItem lri1)
void addTimeProfileItem(final TimeProfileItem tpi1)
void readVersion(final String tableAttributes, final BufferedReader reader)
void readTimeProfileItems(final String tableAttributes, final BufferedReader reader)
void addDeparture(final Departure d)
void addVehicleUnit(final VehicleUnit vehUnit)
VisumNetworkReader(final VisumNetwork network)
void readUnknownTable(final BufferedReader reader)
void readVehicleCombinations(final String tableAttributes, final BufferedReader reader)