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