21 package org.matsim.visum;
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;
29 import org.apache.logging.log4j.LogManager;
30 import org.apache.logging.log4j.Logger;
57 private final String[]
GENERAL_DCODE = {
"DIRECTIONCODE",
"RICHTUNGCODE"};
67 private final String[]
TABLE_STOP = {
"$STOP:",
"$HALTESTELLE:"};
68 private final String[]
TABLE_STOPAREA = {
"$STOPAREA:",
"$HALTESTELLENBEREICH:"};
70 private final String[]
TABLE_LINE = {
"$LINE:",
"$LINIE:"};
158 public void read(
final String filename)
throws UncheckedIOException {
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?");
167 line = reader.readLine();
168 while (line != null) {
169 if (line.startsWith(
"$VERSION:")) {
171 }
else if (line.startsWith(
this.TABLE_STOP[
this.language])) {
173 }
else if (line.startsWith(
this.TABLE_LINKTYPE[
this.language])) {
175 }
else if (line.startsWith(
this.TABLE_STOPAREA[
this.language])) {
177 }
else if (line.startsWith(
this.TABLE_STOPPOINT[
this.language])) {
179 }
else if (line.startsWith(
this.TABLE_LINE[
this.language])) {
181 }
else if (line.startsWith(
this.TABLE_LINEROUTE[
this.language])) {
183 }
else if (line.startsWith(
this.TABLE_LINEROUTEITEM[
this.language])) {
185 }
else if (line.startsWith(
this.TABLE_TIMEPROFILE[
this.language])) {
187 }
else if (line.startsWith(
this.TABLE_TIMEPROFILEITEM[
this.language])) {
189 }
else if (line.startsWith(
this.TABLE_VEHJOURNEY[
this.language])) {
191 }
else if (line.startsWith(
this.TABLE_VEHJOURNEYSECTION[
this.language])) {
193 }
else if (line.startsWith(
this.TABLE_VEHUNIT[
this.language])) {
195 }
else if (line.startsWith(
this.TABLE_VEHCOMB[
this.language])) {
197 }
else if (line.startsWith(
this.TABLE_VEHUNITTOVEHCOMB[
this.language])) {
199 }
else if (line.startsWith(
"$")) {
201 }
else if (!line.startsWith(
"* ")) {
202 throw new IOException(
"cannot interpret line: " + line);
205 line = reader.readLine();
208 }
catch (IOException e) {
209 this.log.warn(
"there was an exception while reading the file.", e);
212 }
catch (IOException e2) {
213 this.log.warn(
"could not close reader.", e2);
215 throw new UncheckedIOException(e);
220 }
catch (IOException e) {
221 this.log.warn(
"could not close reader.", e);
227 private void readVersion(
final String tableAttributes,
final BufferedReader reader)
throws IOException {
228 final String[] attributes =
StringUtils.
explode(tableAttributes.substring(
"$VERSION:".length()),
';');
231 String line = reader.readLine();
236 if (parts[idxLanguage].equals(
"ENG")) {
238 }
else if (parts[idxLanguage].equals(
"DEU")) {
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);
254 String line = reader.readLine();
255 while (line != null && line.length() > 0) {
260 line = reader.readLine();
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);
271 String line = reader.readLine();
272 while (line != null && line.length() > 0) {
275 new Coord(Double.parseDouble(parts[idxXcoord].replace(
',',
'.')), Double.parseDouble(parts[idxYcoord].replace(
',',
'.'))));
278 line = reader.readLine();
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);
287 String line = reader.readLine();
288 while (line != null && line.length() > 0) {
293 line = reader.readLine();
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) {
312 line = reader.readLine();
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);
322 String line = reader.readLine();
323 while (line != null && line.length() > 0) {
330 lr1.
takt = parts[idxTakt];
334 line = reader.readLine();
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);
343 String line = reader.readLine();
344 while (line != null && line.length() > 0) {
348 parts[idxTCode], parts[idxVehCombNo]);
351 line = reader.readLine();
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);
364 String line = reader.readLine();
365 while (line != null && line.length() > 0) {
368 String stopPointNoString = parts[idxStopPointNo];
370 if (stopPointNoString.length() == 0) {
378 line = reader.readLine();
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);
389 String line = reader.readLine();
390 while (line != null && line.length() > 0) {
396 parts[idxVehCombNo]);
399 line = reader.readLine();
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);
413 String line = reader.readLine();
414 while (line != null && line.length() > 0) {
418 parts[idxTPName], parts[idxDCode], parts[idxIndex], parts[idxArr], parts[idxDep],
422 line = reader.readLine();
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);
435 String line = reader.readLine();
436 while (line != null && line.length() > 0) {
442 line = reader.readLine();
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);
451 String line = reader.readLine();
452 while (line != null && line.length() > 0) {
455 String vehJourneyNo = parts[idxVehicleJourneyNo];
456 String vehCombNo = parts[idxVehCombinationNo];
458 d.vehCombinationNo = vehCombNo;
460 line = reader.readLine();
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);
471 String line = reader.readLine();
472 while (line != null && line.length() > 0) {
476 Integer.parseInt(parts[idxSeatCap]), Integer.parseInt(parts[idxTotalCap]));
479 line = reader.readLine();
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);
488 String line = reader.readLine();
489 while (line != null && line.length() > 0) {
495 line = reader.readLine();
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);
505 String line = reader.readLine();
506 while (line != null && line.length() > 0) {
510 vehicleComb.vehUnitId = parts[idxVehicleUnit];
511 vehicleComb.numOfVehicles = Integer.parseInt(parts[idxVehicleNumber]);
513 line = reader.readLine();
518 String line = reader.readLine();
519 while (line != null && line.length() > 0) {
521 line = reader.readLine();
526 for (
int i = 0; i < attributes.length; i++) {
527 if (attributes[i].equals(attribute)) {
void readTimeProfile(final String tableAttributes, final BufferedReader reader)
final String [] ATTRIBUTE_TPI_DCODE
final String [] ATTRIBUTE_VEHUNIT_CODE
final String [] TABLE_VEHJOURNEY
void addLineRoute(final TransitLineRoute lr1)
void readDepartureSections(final String tableAttributes, final BufferedReader reader)
final String [] ATTRIBUTE_STOPPT_STOPAREANO
final String [] GENERAL_NO
final String [] TABLE_VEHUNIT
void readDepartures(final String tableAttributes, final BufferedReader reader)
void addStop(final Stop stop)
final String [] ATTRIBUTE_VEHUNITTOVEHCOMB_VEHCOMBNO
final String [] TABLE_VEHUNITTOVEHCOMB
void addStopArea(final StopArea stopAr)
final String [] TABLE_LINEROUTE
void addEdgeType(final EdgeType edgeType)
final String [] ATTRIBUTE_STOPAREA_NO
final VisumNetwork network
final String [] ATTRIBUTE_LRI_SPNO
void readStops(final String tableAttributes, final BufferedReader reader)
void addline(final TransitLine l1)
final String [] TABLE_TIMEPROFILE
final String [] ATTRIBUTE_TPI_LNAME
final String [] ATTRIBUTE_STOPPT_NAME
final String [] ATTRIBUTE_LR_TAKT
final String [] ATTRIBUTE_TPI_ID
final String [] ATTRIBUTE_VJS_VEHCOMBNO
final String [] GENERAL_NAME
static BufferedReader getBufferedReader(URL url, Charset charset)
final String [] GENERAL_DCODE
static URL getFileUrl(String filename)
static String [] explode(final String str, final char delimiter, final int limit)
final String [] ATTRIBUTE_VEHUNIT_TOTALCAP
final String [] ATTRIBUTE_LINKTYPE_KAPIV
final String [] GENERAL_INDEX
final String [] ATTRIBUTE_TP_LNAME
final String [] ATTRIBUTE_STOPPT_RLNO
void readStopPoints(final String tableAttributes, final BufferedReader reader)
final String [] ATTRIBUTE_L_NAME
final String [] ATTRIBUTE_STOP_YCOORD
final String [] ATTRIBUTE_TPI_ARR
static< T > Id< T > create(final long key, final Class< T > type)
final String [] ATTRIBUTE_VEHUNITTOVEHCOMB_NUMVEHUNITS
final String [] ATTRIBUTE_LINKTYPE_NO
final String [] ATTRIBUTE_VEHUNIT_ID
void addStopPoint(final StopPoint stopPt)
void readEdgeTypes(String tableAttributes, BufferedReader reader)
void addVehicleCombination(final VehicleCombination vehComb)
void addTimeProfile(final TimeProfile tp1)
final String [] ATTRIBUTE_LINKTYPE_V0IV
final String [] ATTRIBUTE_LR_NAME
int getAttributeIndex(final String attribute, final String[] attributes)
final Map< String, Departure > departuresByNo
void readLineRouteItems(final String tableAttributes, final BufferedReader reader)
final String [] ATTRIBUTE_STOPPT_NODE
final String [] ATTRIBUTE_L_VEHCOMBNO
void readVehicleUnits(final String tableAttributes, final BufferedReader reader)
final String [] ATTRIBUTE_LRI_ID
final String [] ATTRIBUTE_LINKTYPE_NOLANES
final String [] ATTRIBUTE_LR_LINENAME
final String [] TABLE_TIMEPROFILEITEM
final String [] TABLE_STOPPOINT
final String [] ATTRIBUTE_VEHUNIT_SEATCAP
final String [] TABLE_VEHCOMB
final String [] ATTRIBUTE_VEHCOMB_NO
final String [] ATTRIBUTE_STOP_XCOORD
final String [] ATTRIBUTE_D_LNAME
final String [] ATTRIBUTE_D_DCODE
static final String ATTRIBUTE_UNKNOWN
final String [] ATTRIBUTE_LRI_DCODE
void readLines(final String tableAttributes, final BufferedReader reader)
final String [] ATTRIBUTE_D_DEP
final String [] ATTRIBUTE_TP_LRNAME
final Map< String, VehicleCombination > vehicleCombinations
final String [] ATTRIBUTE_TPI_TPNAME
void readStopAreas(final String tableAttributes, final BufferedReader reader)
final String [] ATTRIBUTE_D_ID
final String [] ATTRIBUTE_TP_DCODE
void readLineRoutes(final String tableAttributes, final BufferedReader reader)
final String [] ATTRIBUTE_VJS_VEHJOURNEYNO
final String [] GENERAL_LINENAME
final String [] TABLE_STOPAREA
void readVehicleUnitToVehicleCombination(final String tableAttributes, final BufferedReader reader)
final String [] TABLE_LINE
void addLineRouteItem(final LineRouteItem lri1)
void addTimeProfileItem(final TimeProfileItem tpi1)
final String [] TABLE_LINEROUTEITEM
final String [] ATTRIBUTE_TPI_LRIINDEX
final String [] ATTRIBUTE_L_TCODE
final String [] ATTRIBUTE_D_LRNAME
final String [] ATTRIBUTE_TP_VEHCOMBNO
final String [] ATTRIBUTE_STOPPT_NO
final String [] ATTRIBUTE_TP_ID
final String [] ATTRIBUTE_VEHCOMB_NAME
void read(final String filename)
final String [] ATTRIBUTE_LR_DCODE
final String [] TABLE_VEHJOURNEYSECTION
final String [] ATTRIBUTE_D_TPNAME
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)
final String [] ATTRIBUTE_TPI_DEP
VisumNetworkReader(final VisumNetwork network)
final String [] ATTRIBUTE_LRI_NODEID
final String [] TABLE_STOP
final String [] ATTRIBUTE_VEHUNITTOVEHCOMB_VEHUNITNO
final String [] TABLE_LINKTYPE
void readUnknownTable(final BufferedReader reader)
final String [] ATTRIBUTE_TPI_LRNAME
final String [] ATTRIBUTE_LRI_LNAME
final String [] ATTRIBUTE_STOP_NAME
void readVehicleCombinations(final String tableAttributes, final BufferedReader reader)
final String [] ATTRIBUTE_LRI_LRNAME
final String [] ATTRIBUTE_STOP_NO
final String [] ATTRIBUTE_STOPAREA_STOPNO
final String [] GENERAL_LINEROUTENAME