Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NIImporter_VISUM.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// A VISUM network importer
22/****************************************************************************/
23#include <config.h>
24
25#include <string>
32#include <netbuild/NBDistrict.h>
34#include <netbuild/NBPTStop.h>
35#include "NILoader.h"
36#include "NIImporter_VISUM.h"
37
38
40 { "VSYS", VISUM_SYS },
41 { "STRECKENTYP", VISUM_LINKTYPE },
42 { "KNOTEN", VISUM_NODE },
43 { "BEZIRK", VISUM_DISTRICT },
44 { "PUNKT", VISUM_POINT },
45 { "STRECKE", VISUM_LINK },
46 { "V0IV", VISUM_V0 },
47 { "VSYSSET", VISUM_TYPES },
48 { "RANG", VISUM_RANK },
49 { "KAPIV", VISUM_CAPACITY },
50 { "XKOORD", VISUM_XCOORD },
51 { "YKOORD", VISUM_YCOORD },
52 { "ID", VISUM_ID },
53 { "CODE", VISUM_CODE },
54 { "VONKNOTNR", VISUM_FROMNODE },
55 { "NACHKNOTNR", VISUM_TONODE },
56 { "TYPNR", VISUM_TYPE },
57 { "TYP", VISUM_TYP },
58 { "ANBINDUNG", VISUM_DISTRICT_CONNECTION },
59 { "BEZNR", VISUM_SOURCE_DISTRICT },
60 { "KNOTNR", VISUM_FROMNODENO },
61 { "RICHTUNG", VISUM_DIRECTION },
62 { "FLAECHEID", VISUM_SURFACEID },
63 { "TFLAECHEID", VISUM_FACEID },
64 { "VONPUNKTID", VISUM_FROMPOINTID },
65 { "NACHPUNKTID", VISUM_TOPOINTID },
66 { "KANTE", VISUM_EDGE },
67 { "ABBIEGER", VISUM_TURN },
68 { "UEBERKNOTNR", VISUM_VIANODENO },
69 { "ANZFAHRSTREIFEN", VISUM_NUMLANES },
70 { "INDEX", VISUM_INDEX },
71 { "STRECKENPOLY", VISUM_LINKPOLY },
72 { "FLAECHENELEMENT", VISUM_SURFACEITEM },
73 { "TEILFLAECHENELEMENT", VISUM_FACEITEM },
74 { "KANTEID", VISUM_EDGEID },
75 { "Q", VISUM_ORIGIN },
76 { "Z", VISUM_DESTINATION },
77 { "HALTEPUNKT", VISUM_STOPPOINT },
78 { "NAME", VISUM_NAME },
79 { "STRNR", VISUM_LINKNO },
80 { "RELPOS", VISUM_RELPOS },
81 { "KATNR", VISUM_CATID },
82 { "ZWISCHENPUNKT", VISUM_EDGEITEM },
83 { "POIKATEGORIE", VISUM_POICATEGORY },
84 { "NR", VISUM_NO } // must be the last one
85};
86
87
88
90
91// ===========================================================================
92// method definitions
93// ===========================================================================
94// ---------------------------------------------------------------------------
95// static methods (interface in this case)
96// ---------------------------------------------------------------------------
97void
99 // check whether the option is set (properly)
100 if (!oc.isSet("visum-file")) {
101 return;
102 }
103 // build the handler
104 NIImporter_VISUM loader(nb, oc.getString("visum-file"),
105 NBCapacity2Lanes(oc.getFloat("lanes-from-capacity.norm")),
106 oc.getBool("visum.use-type-priority"),
107 oc.getString("visum.language-file"));
108 loader.load();
109}
110
111
112
113// ---------------------------------------------------------------------------
114// loader methods
115// ---------------------------------------------------------------------------
117 const std::string& file,
118 NBCapacity2Lanes capacity2Lanes,
119 bool useVisumPrio,
120 const std::string& languageFile) :
121 myNetBuilder(nb), myFileName(file),
122 myCapacity2Lanes(capacity2Lanes), myUseVisumPrio(useVisumPrio) {
123 if (languageFile != "") {
124 loadLanguage(languageFile);
125 }
126
127 // the order of process is important!
128 // set1
134
135 // set2
136 // two types of "strecke"
139
140 // set3
141 if (OptionsCont::getOptions().getBool("visum.no-connectors")) {
143 } else {
145 }
146 // two types of "abbieger"
147 addParser("ABBIEGEBEZIEHUNG", &NIImporter_VISUM::parse_Turns);
149
153
154
155 // set4
156 // two types of lsa
159 // two types of knotenzulsa
163 // two types of signalgruppe
166 // three types of ABBZULSASIGNALGRUPPE
168 addParser("SIGNALGRUPPEZUABBIEGER", &NIImporter_VISUM::parse_TurnsToSignalGroups);
169 addParser("SIGNALGRUPPEZUFSABBIEGER", &NIImporter_VISUM::parse_TurnsToSignalGroups);
170
172
173 // two types of LSAPHASE
176
177 addParser("LSASIGNALGRUPPEZULSAPHASE", &NIImporter_VISUM::parse_SignalGroupsToPhases);
178 addParser("FAHRSTREIFENABBIEGER", &NIImporter_VISUM::parse_LanesConnections);
179
181}
182
183
185 for (NIVisumTL_Map::iterator j = myTLS.begin(); j != myTLS.end(); j++) {
186 delete j->second;
187 }
188}
189
190
191void
192NIImporter_VISUM::addParser(const std::string& name, ParsingFunction function) {
193 TypeParser p;
194 p.name = name;
195 p.function = function;
196 p.position = -1;
197 mySingleDataParsers.push_back(p);
198}
199
200
201void
203 // open the file
205 throw ProcessError(TLF("Can not open visum-file '%'.", myFileName));
206 }
207 // scan the file for data positions
208 while (myLineReader.hasMore()) {
209 std::string line = myLineReader.readLine();
210 if (line.length() > 0 && line[0] == '$') {
211 ParserVector::iterator i;
212 for (i = mySingleDataParsers.begin(); i != mySingleDataParsers.end(); i++) {
213 std::string dataName = "$" + (*i).name + ":";
214 if (line.substr(0, dataName.length()) == dataName) {
215 (*i).position = myLineReader.getPosition();
216 (*i).pattern = line.substr(dataName.length());
217 WRITE_MESSAGE("Found: " + dataName + " at line " + toString<int>(myLineReader.getLineNumber()));
218 }
219 }
220 }
221 }
222 // go through the parsers and process all entries
223 for (ParserVector::iterator i = mySingleDataParsers.begin(); i != mySingleDataParsers.end(); i++) {
224 if ((*i).position < 0) {
225 // do not process using parsers for which no information was found
226 continue;
227 }
228 // ok, the according information is stored in the file
229 PROGRESS_BEGIN_MESSAGE("Parsing " + (*i).name);
230 // reset the line reader and let it point to the begin of the according data field
232 myLineReader.setPos((*i).position);
233 // prepare the line parser
234 myLineParser.reinit((*i).pattern);
235 // read
236 bool singleDataEndFound = false;
237 while (myLineReader.hasMore() && !singleDataEndFound) {
238 std::string line = myLineReader.readLine();
239 if (line.length() == 0 || line[0] == '*' || line[0] == '$') {
240 singleDataEndFound = true;
241 } else {
243 try {
244 myCurrentID = "<unknown>";
245 (this->*(*i).function)();
246 } catch (OutOfBoundsException&) {
247 WRITE_ERRORF(TL("Too short value line in % occurred."), (*i).name);
248 } catch (NumberFormatException&) {
249 WRITE_ERRORF(TL("A value in % should be numeric but is not (id='%')."), (*i).name, myCurrentID);
250 } catch (UnknownElement& e) {
251 WRITE_ERRORF(TL("One of the needed values ('%') is missing in %."), std::string(e.what()), (*i).name);
252 }
253 }
254 }
255 // close single reader processing
257 }
259
260 // build traffic lights
261 for (NIVisumTL_Map::iterator j = myTLS.begin(); j != myTLS.end(); j++) {
263 }
264 // build district shapes
265 for (std::map<NBDistrict*, PositionVector>::const_iterator k = myDistrictShapes.begin(); k != myDistrictShapes.end(); ++k) {
266 (*k).first->addShape((*k).second);
267 }
268}
269
270
271
272
273
274void
276 std::string name = myLineParser.know("VSysCode") ? myLineParser.get("VSysCode").c_str() : myLineParser.get(KEYS.getString(VISUM_CODE)).c_str();
277 std::string type = myLineParser.know("VSysMode") ? myLineParser.get("VSysMode").c_str() : myLineParser.get(KEYS.getString(VISUM_TYP)).c_str();
278 myVSysTypes[name] = type;
279}
280
281
282void
284 // get the id
286 // get the maximum speed
287 double speed = getWeightedFloat2("v0-IV", KEYS.getString(VISUM_V0), "km/h");
288 if (speed == 0) {
289 // unlimited speed
290 speed = 3600;
291 } else if (speed < 0) {
292 WRITE_ERROR("Type '" + myCurrentID + "' has speed " + toString(speed));
293 }
294 // get the permissions
296 // get the priority
297 const int priority = 1000 - StringUtils::toInt(myLineParser.get(KEYS.getString(VISUM_RANK)));
298 // try to retrieve the number of lanes
299 const int numLanes = myCapacity2Lanes.get(getNamedFloat("Kap-IV", KEYS.getString(VISUM_CAPACITY)));
300 // insert the type
301 myNetBuilder.getTypeCont().insertEdgeType(myCurrentID, numLanes, speed / (double) 3.6, priority, permissions, LaneSpreadFunction::RIGHT,
309}
310
311
312void
314 // get the id
316 // get the position
319 Position pos(x, y);
321 WRITE_ERRORF(TL("Unable to project coordinates for node %."), myCurrentID);
322 return;
323 }
324 // add to the list
326 WRITE_ERRORF(TL("Duplicate node occurred ('%')."), myCurrentID);
327 }
328}
329
330
331void
333 // get the id
335 // get the information whether the source and the destination
336 // connections are weighted
337 //bool sourcesWeighted = getWeightedBool("Proz_Q");
338 //bool destWeighted = getWeightedBool("Proz_Z");
339 // get the node information
342 Position pos(x, y);
343 if (!NBNetBuilder::transformCoordinate(pos, false)) {
344 WRITE_ERRORF(TL("Unable to project coordinates for district %."), myCurrentID);
345 return;
346 }
347 // build the district
348 NBDistrict* district = new NBDistrict(myCurrentID, pos);
349 if (!myNetBuilder.getDistrictCont().insert(district)) {
350 WRITE_ERRORF(TL("Duplicate district occurred ('%')."), myCurrentID);
351 delete district;
352 return;
353 }
355 long long int flaecheID;
356 try {
358 } catch (EmptyData&) {
360 }
361 myShapeDistrictMap[flaecheID] = district;
362 }
363}
364
365
366void
371 Position pos(x, y);
372 if (!NBNetBuilder::transformCoordinate(pos, false)) {
373 WRITE_ERRORF(TL("Unable to project coordinates for point %."), toString(id));
374 return;
375 }
376 myPoints[id] = pos;
377}
378
379
380void
383 // no vehicle allowed; don't add
384 return;
385 }
386 // get the id
388 // get the from- & to-node and validate them
389 NBNode* from = getNamedNode("VonKnot", KEYS.getString(VISUM_FROMNODE));
390 NBNode* to = getNamedNode("NachKnot", KEYS.getString(VISUM_TONODE));
391 if (!checkNodes(from, to)) {
392 return;
393 }
394 // get the type
396 // get the speed
397 double speed = myNetBuilder.getTypeCont().getEdgeTypeSpeed(type);
398 if (!OptionsCont::getOptions().getBool("visum.use-type-speed")) {
399 try {
400 std::string speedS = myLineParser.know("v0-IV") ? myLineParser.get("v0-IV") : myLineParser.get(KEYS.getString(VISUM_V0));
401 if (speedS.find("km/h") != std::string::npos) {
402 speedS = speedS.substr(0, speedS.find("km/h"));
403 }
404 speed = StringUtils::toDouble(speedS) / 3.6;
405 } catch (OutOfBoundsException&) {}
406 }
407 if (speed <= 0) {
409 }
410
411 // get the information whether the edge is a one-way
412 bool oneway = myLineParser.know("Einbahn")
414 : true;
415 // get the number of lanes
416 int nolanes = myNetBuilder.getTypeCont().getEdgeTypeNumLanes(type);
417 if (!OptionsCont::getOptions().getBool("visum.recompute-lane-number")) {
418 if (!OptionsCont::getOptions().getBool("visum.use-type-laneno")) {
419 if (myLineParser.know("Fahrstreifen")) {
420 nolanes = StringUtils::toInt(myLineParser.get("Fahrstreifen"));
423 }
424 }
425 } else {
428 } else if (myLineParser.know("KAP-IV")) {
430 }
431 }
432 // check whether the id is already used
433 // (should be the opposite direction)
434 bool oneway_checked = oneway;
436 if (previous != nullptr) {
437 myCurrentID = '-' + myCurrentID;
439 oneway_checked = false;
440 }
441 if (find(myTouchedEdges.begin(), myTouchedEdges.end(), myCurrentID) != myTouchedEdges.end()) {
442 oneway_checked = false;
443 }
444 std::string tmpid = '-' + myCurrentID;
445 if (find(myTouchedEdges.begin(), myTouchedEdges.end(), tmpid) != myTouchedEdges.end()) {
446 previous = myNetBuilder.getEdgeCont().retrieve(tmpid);
447 if (previous != nullptr) {
449 }
450 oneway_checked = false;
451 }
453 // add the edge
456 if (nolanes != 0 && speed != 0) {
458 NBEdge* e = new NBEdge(myCurrentID, from, to, type, speed, NBEdge::UNSPECIFIED_FRICTION, nolanes, prio,
460 e->setPermissions(permissions);
461 if (!myNetBuilder.getEdgeCont().insert(e)) {
462 delete e;
463 WRITE_ERRORF(TL("Duplicate edge occurred ('%')."), myCurrentID);
464 }
465 }
466 myTouchedEdges.push_back(myCurrentID);
467 // nothing more to do, when the edge is a one-way street
468 if (oneway) {
469 return;
470 }
471 // add the opposite edge
472 myCurrentID = '-' + myCurrentID;
473 if (nolanes != 0 && speed != 0) {
475 NBEdge* e = new NBEdge(myCurrentID, from, to, type, speed, NBEdge::UNSPECIFIED_FRICTION, nolanes, prio,
477 e->setPermissions(permissions);
478 if (!myNetBuilder.getEdgeCont().insert(e)) {
479 delete e;
480 WRITE_ERRORF(TL("Duplicate edge occurred ('%')."), myCurrentID);
481 }
482 }
483 myTouchedEdges.push_back(myCurrentID);
484}
485
486
487void
492 myEdges[id] = std::make_pair(from, to);
493}
494
495
496void
499 long long int flaechePartID = StringUtils::toLong(myLineParser.get(KEYS.getString(VISUM_FACEID)));
500 if (mySubPartsAreas.find(flaechePartID) == mySubPartsAreas.end()) {
501 mySubPartsAreas[flaechePartID] = std::vector<long long int>();
502 }
503 mySubPartsAreas[flaechePartID].push_back(flaecheID);
504}
505
506
507void
509 // get the source district
511 // get the destination node
513 if (dest == nullptr) {
514 return;
515 }
516 // get the weight of the connection
517 double proz = 1;
518 if (myLineParser.know("Proz") || myLineParser.know("Proz(IV)")) {
519 proz = getNamedFloat("Proz", "Proz(IV)") / 100;
520 }
521 // get the information whether this is a sink or a source
522 std::string dir = myLineParser.get(KEYS.getString(VISUM_DIRECTION));
523 if (dir.length() == 0) {
525 }
526 // build the source when needed
527 if (dir.find(KEYS.getString(VISUM_ORIGIN)) != std::string::npos) {
528 for (NBEdge* edge : dest->getOutgoingEdges()) {
529 myNetBuilder.getDistrictCont().addSource(bez, edge, proz);
530 }
531 }
532 // build the sink when needed
533 if (dir.find(KEYS.getString(VISUM_DESTINATION)) != std::string::npos) {
534 for (NBEdge* edge : dest->getIncomingEdges()) {
535 myNetBuilder.getDistrictCont().addSink(bez, edge, proz);
536 }
537 }
538}
539
540
541
542void
544 // get the source district
546 // get the destination node
548 if (dest == nullptr) {
549 return;
550 }
551 // get the weight of the connection
552 double proz = 1;
553 if (myLineParser.know("Proz") || myLineParser.know("Proz(IV)")) {
554 proz = getNamedFloat("Proz", "Proz(IV)") / 100;
555 }
556 // get the duration to wait (unused)
557// double retard = -1;
558// if (myLineParser.know("t0-IV")) {
559// retard = getNamedFloat("t0-IV", -1);
560// }
561 // get the type;
562 // use a standard type with a large speed when a type is not given
563
564 std::string type = myLineParser.know(KEYS.getString(VISUM_TYP))
566 : "";
567 // add the connectors as an edge
568 std::string id = bez + "-" + dest->getID();
569 // get the information whether this is a sink or a source
570 std::string dir = myLineParser.get(KEYS.getString(VISUM_DIRECTION));
571 if (dir.length() == 0) {
573 }
574 // build the source when needed
575 if (dir.find(KEYS.getString(VISUM_ORIGIN)) != std::string::npos) {
576 const EdgeVector& edges = dest->getOutgoingEdges();
577 bool hasContinuation = false;
578 for (EdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
579 if (!(*i)->isMacroscopicConnector()) {
580 hasContinuation = true;
581 }
582 }
583 if (!hasContinuation) {
584 // obviously, there is no continuation on the net
585 WRITE_WARNINGF(TL("Incoming connector '%' will not be build - would be not connected to network."), id);
586 } else {
587 NBNode* src = buildDistrictNode(bez, dest, true);
588 if (src == nullptr) {
589 WRITE_ERRORF(TL("The district '%' could not be built."), bez);
590 return;
591 }
592 NBEdge* edge = new NBEdge(id, src, dest, "VisumConnector",
593 OptionsCont::getOptions().getFloat("visum.connector-speeds"), NBEdge::UNSPECIFIED_FRICTION,
594 OptionsCont::getOptions().getInt("visum.connectors-lane-number"),
598 if (!myNetBuilder.getEdgeCont().insert(edge)) {
599 WRITE_ERRORF(TL("A duplicate edge id occurred (ID='%')."), id);
600 return;
601 }
602 edge = myNetBuilder.getEdgeCont().retrieve(id);
603 if (edge != nullptr) {
604 myNetBuilder.getDistrictCont().addSource(bez, edge, proz);
605 }
606 }
607 }
608 // build the sink when needed
609 if (dir.find(KEYS.getString(VISUM_DESTINATION)) != std::string::npos) {
610 const EdgeVector& edges = dest->getIncomingEdges();
611 bool hasPredeccessor = false;
612 for (EdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
613 if (!(*i)->isMacroscopicConnector()) {
614 hasPredeccessor = true;
615 }
616 }
617 if (!hasPredeccessor) {
618 // obviously, the network is not connected to this node
619 WRITE_WARNINGF(TL("Outgoing connector '%' will not be build - would be not connected to network."), id);
620 } else {
621 NBNode* src = buildDistrictNode(bez, dest, false);
622 if (src == nullptr) {
623 WRITE_ERRORF(TL("The district '%' could not be built."), bez);
624 return;
625 }
626 id = "-" + id;
627 NBEdge* edge = new NBEdge(id, dest, src, "VisumConnector",
628 OptionsCont::getOptions().getFloat("visum.connector-speeds"), NBEdge::UNSPECIFIED_FRICTION,
629 OptionsCont::getOptions().getInt("visum.connectors-lane-number"),
633 if (!myNetBuilder.getEdgeCont().insert(edge)) {
634 WRITE_ERRORF(TL("A duplicate edge id occurred (ID='%')."), id);
635 return;
636 }
637 edge = myNetBuilder.getEdgeCont().retrieve(id);
638 if (edge != nullptr) {
639 myNetBuilder.getDistrictCont().addSink(bez, edge, proz);
640 }
641 }
642 }
643}
644
645
646void
649 // no vehicle allowed; don't add
650 return;
651 }
652 // retrieve the nodes
653 NBNode* from = getNamedNode("VonKnot", KEYS.getString(VISUM_FROMNODE));
654 NBNode* via = getNamedNode("UeberKnot", KEYS.getString(VISUM_VIANODENO));
655 NBNode* to = getNamedNode("NachKnot", KEYS.getString(VISUM_TONODE));
656 if (from == nullptr || via == nullptr || to == nullptr) {
657 return;
658 }
659 // all nodes are known
660 std::string type = myLineParser.know("VSysCode")
661 ? myLineParser.get("VSysCode")
663 if (myVSysTypes.find(type) != myVSysTypes.end() && myVSysTypes.find(type)->second == "IV") {
664 // try to set the turning definition
665 NBEdge* src = from->getConnectionTo(via);
666 NBEdge* dest = via->getConnectionTo(to);
667 // check both
668 if (src == nullptr) {
669 if (OptionsCont::getOptions().getBool("visum.verbose-warnings")) {
670 WRITE_WARNINGF(TL("There is no edge from node '%' to node '%'."), from->getID(), via->getID());
671 }
672 return;
673 }
674 if (dest == nullptr) {
675 if (OptionsCont::getOptions().getBool("visum.verbose-warnings")) {
676 WRITE_WARNINGF(TL("There is no edge from node '%' to node '%'."), via->getID(), to->getID());
677 }
678 return;
679 }
680 // both edges found
681 // set them into the edge
682 src->addEdge2EdgeConnection(dest);
683 }
684}
685
686
687void
689 // get the from- & to-node and validate them
690 NBNode* from = getNamedNode("VonKnot", KEYS.getString(VISUM_FROMNODE));
691 NBNode* to = getNamedNode("NachKnot", KEYS.getString(VISUM_TONODE));
692 if (!checkNodes(from, to)) {
693 return;
694 }
695 bool failed = false;
696 int index;
697 double x, y;
698 try {
702 } catch (NumberFormatException&) {
703 WRITE_ERRORF(TL("Error in geometry description from node '%' to node '%'."), from->getID(), to->getID());
704 return;
705 }
706 Position pos(x, y);
708 WRITE_ERRORF(TL("Unable to project coordinates for node '%'."), from->getID());
709 return;
710 }
711 NBEdge* e = from->getConnectionTo(to);
712 if (e != nullptr) {
713 e->addGeometryPoint(index, pos);
714 } else {
715 failed = true;
716 }
717 e = to->getConnectionTo(from);
718 if (e != nullptr) {
719 e->addGeometryPoint(-index, pos);
720 failed = false;
721 }
722 // check whether the operation has failed
723 if (failed) {
724 if (OptionsCont::getOptions().getBool("visum.verbose-warnings")) {
725 WRITE_WARNINGF(TL("There is no edge from node '%' to node '%'."), from->getID(), to->getID());
726 }
727 }
728}
729
730
731void
733 // The base number of lanes for the edge was already defined in STRECKE
734 // this refines lane specific attribute (width) and optionally introduces splits for additional lanes
735 // It is permitted for KNOTNR to be 0
736 //
737 // get the edge
739 if (baseEdge == nullptr) {
740 return;
741 }
742 NBEdge* edge = baseEdge;
743 // get the node
744 NBNode* node = getNamedNodeSecure("KNOTNR");
745 if (node == nullptr) {
746 node = edge->getToNode();
747 } else {
749 }
750 // check
751 if (edge == nullptr) {
752 return;
753 }
754 // get the lane
755 std::string laneS = myLineParser.know("FSNR")
758 int lane = -1;
759 try {
760 lane = StringUtils::toInt(laneS);
761 } catch (NumberFormatException&) {
762 WRITE_ERRORF(TL("A lane number for edge '%' is not numeric (%)."), edge->getID(), laneS);
763 return;
764 }
765 lane -= 1;
766 if (lane < 0) {
767 WRITE_ERRORF(TL("A lane number for edge '%' is not positive (%)."), edge->getID(), laneS);
768 return;
769 }
770 // get the direction
771 std::string dirS = NBHelpers::normalIDRepresentation(myLineParser.get("RICHTTYP"));
772 int prevLaneNo = baseEdge->getNumLanes();
773 if ((dirS == "1" && !(node->hasIncoming(edge))) || (dirS == "0" && !(node->hasOutgoing(edge)))) {
774 // get the last part of the turnaround direction
775 NBEdge* cand = getReversedContinuating(edge, node);
776 if (cand) {
777 edge = cand;
778 }
779 }
780 // get the length
781 std::string lengthS = NBHelpers::normalIDRepresentation(myLineParser.get("LAENGE"));
782 double length = -1;
783 try {
784 length = StringUtils::toDouble(lengthS);
785 } catch (NumberFormatException&) {
786 WRITE_ERRORF(TL("A lane length for edge '%' is not numeric (%)."), edge->getID(), lengthS);
787 return;
788 }
789 if (length < 0) {
790 WRITE_ERRORF(TL("A lane length for edge '%' is not positive (%)."), edge->getID(), lengthS);
791 return;
792 }
793 //
794 if (dirS == "1") {
795 lane -= prevLaneNo;
796 }
797 //
798 if (length == 0) {
799 if ((int) edge->getNumLanes() > lane) {
800 // ok, we know this already...
801 return;
802 }
803 // increment by one
804 edge->incLaneNo(1);
805 } else {
806 // check whether this edge already has been created
807 if (isSplitEdge(edge, node)) {
808 if (edge->getID().substr(edge->getID().find('_')) == "_" + toString(length) + "_" + node->getID()) {
809 if ((int) edge->getNumLanes() > lane) {
810 // ok, we know this already...
811 return;
812 }
813 // increment by one
814 edge->incLaneNo(1);
815 return;
816 }
817 }
818 // nope, we have to split the edge...
819 // maybe it is not the proper edge to split - VISUM seems not to sort the splits...
820 bool mustRecheck = true;
821 double seenLength = 0;
822 while (mustRecheck) {
823 if (isSplitEdge(edge, node)) {
824 // ok, we have a previously created edge here
825 std::string sub = edge->getID();
826 sub = sub.substr(sub.rfind('_', sub.rfind('_') - 1));
827 sub = sub.substr(1, sub.find('_', 1) - 1);
828 double dist = StringUtils::toDouble(sub);
829 if (dist < length) {
830 seenLength += edge->getLength();
831 if (dirS == "1") {
832 // incoming -> move back
833 edge = edge->getFromNode()->getIncomingEdges()[0];
834 } else {
835 // outgoing -> move forward
836 edge = edge->getToNode()->getOutgoingEdges()[0];
837 }
838 } else {
839 mustRecheck = false;
840 }
841 } else {
842 // we have the center edge - do not continue...
843 mustRecheck = false;
844 }
845 }
846 // compute position
847 Position p;
848 double useLength = length - seenLength;
849 useLength = edge->getLength() - useLength;
850 if (useLength < 0 || useLength > edge->getLength()) {
851 WRITE_WARNINGF(TL("Could not find split position for edge '%'."), edge->getID());
852 return;
853 }
854 std::string edgeID = edge->getID();
855 p = edge->getGeometry().positionAtOffset(useLength);
856 if (isSplitEdge(edge, node)) {
857 edgeID = edgeID.substr(0, edgeID.find('_'));
858 }
859 NBNode* rn = new NBNode(edgeID + "_" + toString((int) length) + "_" + node->getID(), p);
860 if (!myNetBuilder.getNodeCont().insert(rn)) {
861 throw ProcessError(TL("Ups - could not insert node!"));
862 }
863 std::string nid = edgeID + "_" + toString((int) length) + "_" + node->getID();
865 edge->getID(), nid, edge->getNumLanes() + 0, edge->getNumLanes() + 1);
866 // old edge is deleted and a new edge with the same name created
867 edge = myNetBuilder.getEdgeCont().retrieve(edgeID);
868 NBEdge* nedge = myNetBuilder.getEdgeCont().retrieve(nid);
869 nedge = nedge->getToNode()->getOutgoingEdges()[0];
870 while (isSplitEdge(edge, node)) {
871 assert(nedge->getToNode()->getOutgoingEdges().size() > 0);
872 nedge->incLaneNo(1);
873 nedge = nedge->getToNode()->getOutgoingEdges()[0];
874 }
875 }
876}
877
878
879void
882 const SUMOTime cycleTime = TIME2STEPS(getWeightedFloat2("Umlaufzeit", "UMLZEIT", "s"));
883 const SUMOTime intermediateTime = TIME2STEPS(getWeightedFloat2("StdZwischenzeit", "STDZWZEIT", "s"));
884 bool phaseBased = myLineParser.know("PhasenBasiert")
885 ? StringUtils::toBool(myLineParser.get("PhasenBasiert"))
886 : false;
887 const SUMOTime offset = myLineParser.know("ZEITVERSATZ") ? TIME2STEPS(getWeightedFloat("ZEITVERSATZ", "s")) : 0;
888 // add to the list
889 myTLS[myCurrentID] = new NIVisumTL(myCurrentID, cycleTime, offset, intermediateTime, phaseBased);
890}
891
892
893void
895 std::string node = myLineParser.get("KnotNr").c_str();
896 if (node == "0") {
897 // this is a dummy value which cannot be assigned to
898 return;
899 }
900 std::string trafficLight = myLineParser.get("LsaNr").c_str();
901 // add to the list
903 auto tlIt = myTLS.find(trafficLight);
904 if (n != nullptr && tlIt != myTLS.end()) {
905 tlIt->second->addNode(n);
906 } else {
907 WRITE_ERROR("Could not assign" + std::string(n == nullptr ? " missing" : "") + " node '" + node
908 + "' to" + std::string(tlIt == myTLS.end() ? " missing" : "") + " traffic light '" + trafficLight + "'");
909 }
910}
911
912
913void
916 std::string LSAid = NBHelpers::normalIDRepresentation(myLineParser.get("LsaNr"));
917 const SUMOTime startTime = TIME2STEPS(getNamedFloat("GzStart", "GRUENANF"));
918 const SUMOTime endTime = TIME2STEPS(getNamedFloat("GzEnd", "GRUENENDE"));
919 const SUMOTime yellowTime = myLineParser.know("GELB") ? TIME2STEPS(getNamedFloat("GELB")) : -1;
920 // add to the list
921 if (myTLS.find(LSAid) == myTLS.end()) {
922 WRITE_ERRORF(TL("Could not find TLS '%' for setting the signal group."), LSAid);
923 return;
924 }
925 myTLS.find(LSAid)->second->addSignalGroup(myCurrentID, startTime, endTime, yellowTime);
926}
927
928
929void
931 // get the id
932 std::string SGid = getNamedString("SGNR", "SIGNALGRUPPENNR");
933 if (!myLineParser.know("LsaNr")) {
935 WRITE_WARNING(TL("Ignoring SIGNALGRUPPEZUFSABBIEGER because LsaNr is not known"));
936 return;
937 }
938 std::string LSAid = getNamedString("LsaNr");
939 // nodes
940 NBNode* from = myLineParser.know("VonKnot") ? getNamedNode("VonKnot") : nullptr;
941 NBNode* via = myLineParser.know("KNOTNR")
942 ? getNamedNode("KNOTNR")
943 : getNamedNode("UeberKnot", "UeberKnotNr");
944 NBNode* to = myLineParser.know("NachKnot") ? getNamedNode("NachKnot") : nullptr;
945 // edges
946 NBEdge* edg1 = nullptr;
947 NBEdge* edg2 = nullptr;
948 if (from == nullptr && to == nullptr) {
949 edg1 = getNamedEdgeContinuating("VONSTRNR", via);
950 edg2 = getNamedEdgeContinuating("NACHSTRNR", via);
951 } else {
952 edg1 = getEdge(from, via);
953 edg2 = getEdge(via, to);
954 }
955 // add to the list
956 NIVisumTL::SignalGroup& SG = myTLS.find(LSAid)->second->getSignalGroup(SGid);
957 if (edg1 != nullptr && edg2 != nullptr) {
958 if (!via->hasIncoming(edg1)) {
959 std::string sid;
960 if (edg1->getID()[0] == '-') {
961 sid = edg1->getID().substr(1);
962 } else {
963 sid = "-" + edg1->getID();
964 }
965 if (sid.find('_') != std::string::npos) {
966 sid = sid.substr(0, sid.find('_'));
967 }
969 }
970 if (!via->hasOutgoing(edg2)) {
971 std::string sid;
972 if (edg2->getID()[0] == '-') {
973 sid = edg2->getID().substr(1);
974 } else {
975 sid = "-" + edg2->getID();
976 }
977 if (sid.find('_') != std::string::npos) {
978 sid = sid.substr(0, sid.find('_'));
979 }
981 }
982 SG.connections().push_back(NBConnection(edg1, edg2));
983 }
984}
985
986
987void
991 if (myEdges.find(edgeid) == myEdges.end()) {
992 WRITE_ERROR(TL("Unknown edge in TEILFLAECHENELEMENT"));
993 return;
994 }
995 std::string dir = myLineParser.get(KEYS.getString(VISUM_DIRECTION));
996// get index (unused)
997// std::string indexS = NBHelpers::normalIDRepresentation(myLineParser.get("INDEX"));
998// int index = -1;
999// try {
1000// index = StringUtils::toInt(indexS) - 1;
1001// } catch (NumberFormatException&) {
1002// WRITE_ERRORF(TL("An index for a TEILFLAECHENELEMENT is not numeric (id='%')."), toString(id));
1003// return;
1004// }
1005 PositionVector shape;
1006 shape.push_back(myPoints[myEdges[edgeid].first]);
1007 shape.push_back(myPoints[myEdges[edgeid].second]);
1008 if (dir.length() > 0 && dir[0] == '1') {
1009 shape = shape.reverse();
1010 }
1011 if (mySubPartsAreas.find(id) == mySubPartsAreas.end()) {
1012 WRITE_ERRORF(TL("Unknown are for area part '%'."), myCurrentID);
1013 return;
1014 }
1015
1016 const std::vector<long long int>& areas = mySubPartsAreas.find(id)->second;
1017 for (std::vector<long long int>::const_iterator i = areas.begin(); i != areas.end(); ++i) {
1019 if (d == nullptr) {
1020 continue;
1021 }
1022 if (myDistrictShapes.find(d) == myDistrictShapes.end()) {
1024 }
1025 if (dir.length() > 0 && dir[0] == '1') {
1026 myDistrictShapes[d].push_back(myPoints[myEdges[edgeid].second]);
1027 myDistrictShapes[d].push_back(myPoints[myEdges[edgeid].first]);
1028 } else {
1029 myDistrictShapes[d].push_back(myPoints[myEdges[edgeid].first]);
1030 myDistrictShapes[d].push_back(myPoints[myEdges[edgeid].second]);
1031 }
1032 }
1033}
1034
1035
1036void
1038 // get the id
1040 const std::string LSAid = NBHelpers::normalIDRepresentation(myLineParser.get("LsaNr"));
1041 const SUMOTime startTime = TIME2STEPS(getNamedFloat("GzStart", "GRUENANF"));
1042 const SUMOTime endTime = TIME2STEPS(getNamedFloat("GzEnd", "GRUENENDE"));
1043 const SUMOTime yellowTime = myLineParser.know("GELB") ? TIME2STEPS(getNamedFloat("GELB")) : -1;
1044 myTLS.find(LSAid)->second->addPhase(phaseid, startTime, endTime, yellowTime);
1045}
1046
1047
1049 // get the id
1050 std::string Phaseid = NBHelpers::normalIDRepresentation(myLineParser.get("PsNr"));
1051 std::string LSAid = NBHelpers::normalIDRepresentation(myLineParser.get("LsaNr"));
1052 std::string SGid = NBHelpers::normalIDRepresentation(myLineParser.get("SGNR"));
1053 // insert
1054 NIVisumTL* LSA = myTLS.find(LSAid)->second;
1055 NIVisumTL::SignalGroup& SG = LSA->getSignalGroup(SGid);
1056 NIVisumTL::Phase* PH = LSA->getPhases().find(Phaseid)->second;
1057 SG.phases()[Phaseid] = PH;
1058}
1059
1060
1062 NBNode* node = nullptr;
1063 NBEdge* fromEdge = nullptr;
1064 NBEdge* toEdge = nullptr;
1065 // get the node and edges depending on network format
1066 const std::string nodeID = getNamedString("KNOTNR", "KNOT");
1067 if (nodeID == "0") {
1068 fromEdge = getNamedEdge("VONSTRNR", "VONSTR");
1069 toEdge = getNamedEdge("NACHSTRNR", "NACHSTR");
1070 if (fromEdge == nullptr) {
1071 return;
1072 }
1073 node = fromEdge->getToNode();
1074 WRITE_WARNING(TL("Ignoring lane-to-lane connection (not yet implemented for this format version)"));
1075 return;
1076 } else {
1077 node = getNamedNode("KNOTNR", "KNOT");
1078 if (node == nullptr) {
1079 return;
1080 }
1081 fromEdge = getNamedEdgeContinuating("VONSTRNR", "VONSTR", node);
1082 toEdge = getNamedEdgeContinuating("NACHSTRNR", "NACHSTR", node);
1083 }
1084 if (fromEdge == nullptr || toEdge == nullptr) {
1085 return;
1086 }
1087
1088 int fromLaneOffset = 0;
1089 if (!node->hasIncoming(fromEdge)) {
1090 fromLaneOffset = fromEdge->getNumLanes();
1091 fromEdge = getReversedContinuating(fromEdge, node);
1092 } else {
1093 fromEdge = getReversedContinuating(fromEdge, node);
1094 NBEdge* tmp = myNetBuilder.getEdgeCont().retrieve(fromEdge->getID().substr(0, fromEdge->getID().find('_')));
1095 fromLaneOffset = tmp->getNumLanes();
1096 }
1097
1098 int toLaneOffset = 0;
1099 if (!node->hasOutgoing(toEdge)) {
1100 toLaneOffset = toEdge->getNumLanes();
1101 toEdge = getReversedContinuating(toEdge, node);
1102 } else {
1103 NBEdge* tmp = myNetBuilder.getEdgeCont().retrieve(toEdge->getID().substr(0, toEdge->getID().find('_')));
1104 toLaneOffset = tmp->getNumLanes();
1105 }
1106 // get the from-lane
1107 std::string fromLaneS = NBHelpers::normalIDRepresentation(myLineParser.get("VONFSNR"));
1108 int fromLane = -1;
1109 try {
1110 fromLane = StringUtils::toInt(fromLaneS);
1111 } catch (NumberFormatException&) {
1112 WRITE_ERRORF(TL("A from-lane number for edge '%' is not numeric (%)."), fromEdge->getID(), fromLaneS);
1113 return;
1114 }
1115 fromLane -= 1;
1116 if (fromLane < 0) {
1117 WRITE_ERRORF(TL("A from-lane number for edge '%' is not positive (%)."), fromEdge->getID(), fromLaneS);
1118 return;
1119 }
1120 // get the from-lane
1121 std::string toLaneS = NBHelpers::normalIDRepresentation(myLineParser.get("NACHFSNR"));
1122 int toLane = -1;
1123 try {
1124 toLane = StringUtils::toInt(toLaneS);
1125 } catch (NumberFormatException&) {
1126 WRITE_ERRORF(TL("A to-lane number for edge '%' is not numeric (%)."), toEdge->getID(), toLaneS);
1127 return;
1128 }
1129 toLane -= 1;
1130 if (toLane < 0) {
1131 WRITE_ERRORF(TL("A to-lane number for edge '%' is not positive (%)."), toEdge->getID(), toLaneS);
1132 return;
1133 }
1134 // !!! the next is probably a hack
1135 if (fromLane - fromLaneOffset < 0) {
1136 //fromLaneOffset = 0;
1137 } else {
1138 fromLane = (int)fromEdge->getNumLanes() - (fromLane - fromLaneOffset) - 1;
1139 }
1140 if (toLane - toLaneOffset < 0) {
1141 //toLaneOffset = 0;
1142 } else {
1143 toLane = (int)toEdge->getNumLanes() - (toLane - toLaneOffset) - 1;
1144 }
1145 //
1146 if ((int) fromEdge->getNumLanes() <= fromLane) {
1147 WRITE_ERRORF(TL("A from-lane number for edge '%' is larger than the edge's lane number (%)."), fromEdge->getID(), fromLaneS);
1148 return;
1149 }
1150 if ((int) toEdge->getNumLanes() <= toLane) {
1151 WRITE_ERRORF(TL("A to-lane number for edge '%' is larger than the edge's lane number (%)."), toEdge->getID(), toLaneS);
1152 return;
1153 }
1154 //
1155 fromEdge->addLane2LaneConnection(fromLane, toEdge, toLane, NBEdge::Lane2LaneInfoType::VALIDATED);
1156}
1157
1158
1165 const std::string edgeID = myLineParser.get(KEYS.getString(VISUM_LINKNO));
1166 if (edgeID == "") {
1167 WRITE_WARNINGF(TL("Ignoring stopping place '%' without edge id"), id);
1168 } else if (from == nullptr && to == nullptr) {
1169 WRITE_WARNINGF(TL("Ignoring stopping place '%' without node information"), id);
1170 } else {
1172 if (edge == nullptr) {
1173 WRITE_WARNINGF(TL("Ignoring stopping place '%' with invalid edge reference '%'"), id, edgeID);
1174 return;
1175 } else if (from != nullptr) {
1176 if (edge->getToNode() == from) {
1177 NBEdge* edge2 = myNetBuilder.getEdgeCont().retrieve("-" + edge->getID());
1178 if (edge2 == nullptr) {
1179 WRITE_WARNINGF(TL("Could not find edge with from-node '%' and base id '%' for stopping place '%'"), from->getID(), edge->getID(), id);
1180 } else {
1181 edge = edge2;
1182 }
1183 } else if (edge->getFromNode() != from) {
1184 WRITE_WARNINGF(TL("Unexpected from-node '%' for edge '%' of stopping place '%'"), from->getID(), edge->getID(), id);
1185 }
1186 } else {
1187 if (edge->getFromNode() == to) {
1188 NBEdge* edge2 = myNetBuilder.getEdgeCont().retrieve("-" + edge->getID());
1189 if (edge2 == nullptr) {
1190 WRITE_WARNINGF(TL("Could not find edge with to-node '%' and base id '%' for stopping place '%'"), to->getID(), edge->getID(), id);
1191 } else {
1192 edge = edge2;
1193 }
1194 } else if (edge->getToNode() != to) {
1195 WRITE_WARNINGF(TL("Unexpected to-node '%' for edge '%' of stopping place '%'"), to->getID(), edge->getID(), id);
1196 }
1197 }
1200 Position pos = edge->getGeometry().positionAtOffset(edge->getLength() * relPos);
1201
1202 const double length = OptionsCont::getOptions().getFloat("osm.stop-output.length");
1203 std::shared_ptr<NBPTStop> ptStop = std::make_shared<NBPTStop>(id, pos, edge->getID(), edge->getID(), length, name, permissions);
1205 }
1206}
1207
1208
1209double
1210NIImporter_VISUM::getWeightedFloat(const std::string& name, const std::string& suffix) {
1211 try {
1212 std::string val = myLineParser.get(name);
1213 if (val.find(suffix) != std::string::npos) {
1214 val = val.substr(0, val.find(suffix));
1215 }
1216 return StringUtils::toDouble(val);
1217 } catch (...) {}
1218 return -1;
1219}
1220
1221
1222double
1223NIImporter_VISUM::getWeightedFloat2(const std::string& name, const std::string& name2, const std::string& suffix) {
1224 double result = getWeightedFloat(name, suffix);
1225 if (result != -1) {
1226 return result;
1227 } else {
1228 return getWeightedFloat(name2, suffix);
1229 }
1230}
1231
1232bool
1233NIImporter_VISUM::getWeightedBool(const std::string& name) {
1234 try {
1235 return StringUtils::toBool(myLineParser.get(name));
1236 } catch (...) {}
1237 try {
1238 return StringUtils::toBool(myLineParser.get((name + "(IV)")));
1239 } catch (...) {}
1240 return false;
1241}
1242
1244NIImporter_VISUM::getPermissions(const std::string& name, bool warn, SVCPermissions unknown) {
1245 SVCPermissions result = 0;
1246 for (std::string v : StringTokenizer(myLineParser.get(name), ",").getVector()) {
1247 // common values in english and german
1248 // || v == "funiculaire-telecabine" ---> no matching
1250 if (v == "bus" || v == "tcsp" || v == "acces tc" || v == "Accès tc" || v == "accès tc") {
1251 result |= SVC_BUS;
1252 } else if (v == "walk" || v == "w" || v == "f" || v == "ped" || v == "map") {
1253 result |= SVC_PEDESTRIAN;
1254 } else if (v == "l" || v == "lkw" || v == "h" || v == "hgv" || v == "lw" || v == "truck" || v == "tru" || v == "pl") {
1255 result |= SVC_TRUCK;
1256 } else if (v == "b" || v == "bike" || v == "velo") {
1257 result |= SVC_BICYCLE;
1258 } else if (v == "train" || v == "rail") {
1259 result |= SVC_RAIL;
1260 } else if (v == "tram") {
1261 result |= SVC_TRAM;
1262 } else if (v == "p" || v == "pkw" || v == "car" || v == "c" || v == "vp" || v == "2rm") {
1263 result |= SVC_PASSENGER;
1264 } else {
1265 if (warn) {
1266 WRITE_WARNINGF("Encountered unknown vehicle category '" + v + "' in type '%'", myLineParser.get(KEYS.getString(VISUM_NO)));
1267 }
1268 result |= unknown;
1269 }
1270 }
1271 return result;
1272}
1273
1274NBNode*
1275NIImporter_VISUM::getNamedNode(const std::string& fieldName) {
1276 std::string nodeS = NBHelpers::normalIDRepresentation(myLineParser.get(fieldName));
1277 NBNode* node = myNetBuilder.getNodeCont().retrieve(nodeS);
1278 if (node == nullptr) {
1279 WRITE_ERRORF(TL("The node '%' is not known."), nodeS);
1280 }
1281 return node;
1282}
1283
1284NBNode*
1285NIImporter_VISUM::getNamedNodeSecure(const std::string& fieldName, NBNode* fallback) {
1286 std::string nodeS = NBHelpers::normalIDRepresentation(myLineParser.get(fieldName));
1287 NBNode* node = myNetBuilder.getNodeCont().retrieve(nodeS);
1288 if (node == nullptr) {
1289 return fallback;
1290 }
1291 return node;
1292}
1293
1294
1295NBNode*
1296NIImporter_VISUM::getNamedNode(const std::string& fieldName1, const std::string& fieldName2) {
1297 if (myLineParser.know(fieldName1)) {
1298 return getNamedNode(fieldName1);
1299 } else {
1300 return getNamedNode(fieldName2);
1301 }
1302}
1303
1304
1305NBEdge*
1306NIImporter_VISUM::getNamedEdge(const std::string& fieldName) {
1307 std::string edgeS = NBHelpers::normalIDRepresentation(myLineParser.get(fieldName));
1308 NBEdge* edge = myNetBuilder.getEdgeCont().retrieve(edgeS);
1309 if (edge == nullptr) {
1310 WRITE_ERRORF(TL("The edge '%' is not known."), edgeS);
1311 }
1312 return edge;
1313}
1314
1315
1316NBEdge*
1317NIImporter_VISUM::getNamedEdge(const std::string& fieldName1, const std::string& fieldName2) {
1318 if (myLineParser.know(fieldName1)) {
1319 return getNamedEdge(fieldName1);
1320 } else {
1321 return getNamedEdge(fieldName2);
1322 }
1323}
1324
1325
1326
1327NBEdge*
1329 std::string sid;
1330 if (edge->getID()[0] == '-') {
1331 sid = edge->getID().substr(1);
1332 } else {
1333 sid = "-" + edge->getID();
1334 }
1335 if (sid.find('_') != std::string::npos) {
1336 sid = sid.substr(0, sid.find('_'));
1337 }
1339}
1340
1341
1342NBEdge*
1344 if (begin == nullptr) {
1345 return nullptr;
1346 }
1347 NBEdge* ret = begin;
1348 std::string edgeID = ret->getID();
1349 // hangle forward
1350 while (ret != nullptr) {
1351 // ok, this is the edge we are looking for
1352 if (ret->getToNode() == node) {
1353 return ret;
1354 }
1355 const EdgeVector& nedges = ret->getToNode()->getOutgoingEdges();
1356 if (nedges.size() != 1) {
1357 // too many edges follow
1358 ret = nullptr;
1359 continue;
1360 }
1361 NBEdge* next = nedges[0];
1362 if (ret->getID().substr(0, edgeID.length()) != next->getID().substr(0, edgeID.length())) {
1363 // ok, another edge is next...
1364 ret = nullptr;
1365 continue;
1366 }
1367 if (next->getID().substr(next->getID().length() - node->getID().length()) != node->getID()) {
1368 ret = nullptr;
1369 continue;
1370 }
1371 ret = next;
1372 }
1373
1374 ret = begin;
1375 // hangle backward
1376 while (ret != nullptr) {
1377 // ok, this is the edge we are looking for
1378 if (ret->getFromNode() == node) {
1379 return ret;
1380 }
1381 const EdgeVector& nedges = ret->getFromNode()->getIncomingEdges();
1382 if (nedges.size() != 1) {
1383 // too many edges follow
1384 ret = nullptr;
1385 continue;
1386 }
1387 NBEdge* next = nedges[0];
1388 if (ret->getID().substr(0, edgeID.length()) != next->getID().substr(0, edgeID.length())) {
1389 // ok, another edge is next...
1390 ret = nullptr;
1391 continue;
1392 }
1393 if (next->getID().substr(next->getID().length() - node->getID().length()) != node->getID()) {
1394 ret = nullptr;
1395 continue;
1396 }
1397 ret = next;
1398 }
1399 return nullptr;
1400}
1401
1402
1403NBEdge*
1404NIImporter_VISUM::getNamedEdgeContinuating(const std::string& fieldName, NBNode* node) {
1405 std::string edgeS = NBHelpers::normalIDRepresentation(myLineParser.get(fieldName));
1406 NBEdge* edge = myNetBuilder.getEdgeCont().retrieve(edgeS);
1407 if (edge == nullptr) {
1408 WRITE_ERRORF(TL("The edge '%' is not known."), edgeS);
1409 }
1410 return getNamedEdgeContinuating(edge, node);
1411}
1412
1413
1414NBEdge*
1415NIImporter_VISUM::getNamedEdgeContinuating(const std::string& fieldName1, const std::string& fieldName2,
1416 NBNode* node) {
1417 if (myLineParser.know(fieldName1)) {
1418 return getNamedEdgeContinuating(fieldName1, node);
1419 } else {
1420 return getNamedEdgeContinuating(fieldName2, node);
1421 }
1422}
1423
1424
1425NBEdge*
1427 EdgeVector::const_iterator i;
1428 for (i = FromNode->getOutgoingEdges().begin(); i != FromNode->getOutgoingEdges().end(); i++) {
1429 if (ToNode == (*i)->getToNode()) {
1430 return (*i);
1431 }
1432 }
1434 return nullptr;
1435}
1436
1437
1438double
1439NIImporter_VISUM::getNamedFloat(const std::string& fieldName) {
1440 std::string value = myLineParser.get(fieldName);
1441 if (StringUtils::endsWith(myLineParser.get(fieldName), "km/h")) {
1442 value = value.substr(0, value.length() - 4);
1443 }
1444 return StringUtils::toDouble(value);
1445}
1446
1447
1448double
1449NIImporter_VISUM::getNamedFloat(const std::string& fieldName, double defaultValue) {
1450 try {
1451 return StringUtils::toDouble(myLineParser.get(fieldName));
1452 } catch (...) {
1453 return defaultValue;
1454 }
1455}
1456
1457
1458double
1459NIImporter_VISUM::getNamedFloat(const std::string& fieldName1, const std::string& fieldName2) {
1460 if (myLineParser.know(fieldName1)) {
1461 return getNamedFloat(fieldName1);
1462 } else {
1463 return getNamedFloat(fieldName2);
1464 }
1465}
1466
1467
1468double
1469NIImporter_VISUM::getNamedFloat(const std::string& fieldName1, const std::string& fieldName2,
1470 double defaultValue) {
1471 if (myLineParser.know(fieldName1)) {
1472 return getNamedFloat(fieldName1, defaultValue);
1473 } else {
1474 return getNamedFloat(fieldName2, defaultValue);
1475 }
1476}
1477
1478
1479std::string
1480NIImporter_VISUM::getNamedString(const std::string& fieldName) {
1482}
1483
1484
1485std::string
1486NIImporter_VISUM::getNamedString(const std::string& fieldName1,
1487 const std::string& fieldName2) {
1488 if (myLineParser.know(fieldName1)) {
1489 return getNamedString(fieldName1);
1490 } else {
1491 return getNamedString(fieldName2);
1492 }
1493}
1494
1495
1496
1497
1498
1499
1500NBNode*
1501NIImporter_VISUM::buildDistrictNode(const std::string& id, NBNode* dest,
1502 bool isSource) {
1503 // get the district
1505 if (dist == nullptr) {
1506 return nullptr;
1507 }
1508 // build the id
1509 std::string nid;
1510 nid = id + "-" + dest->getID();
1511 if (!isSource) {
1512 nid = "-" + nid;
1513 }
1514 // insert the node
1515 if (!myNetBuilder.getNodeCont().insert(nid, dist->getPosition())) {
1516 WRITE_ERRORF(TL("Could not build connector node '%'."), nid);
1517 }
1518 // return the node
1519 return myNetBuilder.getNodeCont().retrieve(nid);
1520}
1521
1522
1523bool
1525 if (from == nullptr) {
1526 WRITE_ERROR(TL(" The from-node was not found within the net"));
1527 }
1528 if (to == nullptr) {
1529 WRITE_ERROR(TL(" The to-node was not found within the net"));
1530 }
1531 if (from == to) {
1532 WRITE_ERROR(TL(" Both nodes are the same"));
1533 }
1534 return from != nullptr && to != nullptr && from != to;
1535}
1536
1537bool
1539 return (edge->getID().length() > node->getID().length() + 1
1540 && (edge->getID().substr(edge->getID().length() - node->getID().length() - 1) == "_" + node->getID()));
1541}
1542
1543void
1544NIImporter_VISUM::loadLanguage(const std::string& file) {
1545 std::ifstream strm(file.c_str());
1546 if (!strm.good()) {
1547 throw ProcessError(TLF("Could not load VISUM language map from '%'.", file));
1548 }
1549 while (strm.good()) {
1550 std::string keyDE;
1551 std::string keyNew;
1552 strm >> keyDE;
1553 strm >> keyNew;
1554 if (KEYS.hasString(keyDE)) {
1555 VISUM_KEY key = KEYS.get(keyDE);
1556 KEYS.remove(keyDE, key);
1557 KEYS.insert(keyNew, key);
1558 } else if (keyDE != "") {
1559 WRITE_WARNINGF(TL("Unknown entry '%' in VISUM language map"), keyDE);
1560 }
1561 }
1562
1563}
1564
1565
1566/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define WRITE_ERRORF(...)
Definition MsgHandler.h:296
#define WRITE_MESSAGE(msg)
Definition MsgHandler.h:288
#define WRITE_ERROR(msg)
Definition MsgHandler.h:295
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TL(string)
Definition MsgHandler.h:304
#define PROGRESS_DONE_MESSAGE()
Definition MsgHandler.h:291
#define TLF(string,...)
Definition MsgHandler.h:306
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition MsgHandler.h:290
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition NBCont.h:42
#define TIME2STEPS(x)
Definition SUMOTime.h:57
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SVC_TRUCK
vehicle is a large transport vehicle
@ SVC_RAIL
vehicle is a not electrified rail
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_TRAM
vehicle is a light rail
@ SVC_BUS
vehicle is a bus
@ SVC_PEDESTRIAN
pedestrian
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_ONEWAY
@ SUMO_ATTR_PRIORITY
@ SUMO_ATTR_NUMLANES
@ SUMO_ATTR_SPREADTYPE
The information about how to spread the lanes from the given position.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
void setPos(unsigned long pos)
Sets the current position within the file to the given value.
unsigned long getPosition()
Returns the current position within the file.
bool readLine(LineHandler &lh)
Reads a single (the next) line from the file and reports it to the given LineHandler.
bool setFile(const std::string &file)
Reinitialises the reader for reading from the given file.
int getLineNumber()
Definition LineReader.h:143
void reinit()
Reinitialises the reading (of the previous file)
bool hasMore() const
Returns whether another line may be read (the file was not read completely)
A helper class which computes the lane number from given capacity.
int get(double capacity) const
Returns the number of lanes computed from the given capacity.
NBDistrict * retrieve(const std::string &id) const
Returns the districts with the given id.
bool addSink(const std::string &dist, NBEdge *const destination, double weight)
Adds a sink to the named district.
bool insert(NBDistrict *const district)
Adds a district to the dictionary.
bool addSource(const std::string &dist, NBEdge *const source, double weight)
Adds a source to the named district.
A class representing a single district.
Definition NBDistrict.h:62
const Position & getPosition() const
Returns the position of this district's center.
Definition NBDistrict.h:120
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
void reduceGeometries(const double minDist)
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
bool splitAt(NBDistrictCont &dc, NBEdge *edge, NBNode *node)
Splits the edge at the position nearest to the given node.
The representation of a single edge during network building.
Definition NBEdge.h:92
void addGeometryPoint(int index, const Position &p)
Adds a further geometry point.
Definition NBEdge.cpp:1027
double getLength() const
Returns the computed length of the edge.
Definition NBEdge.h:599
void setPermissions(SVCPermissions permissions, int lane=-1)
set allowed/disallowed classes for the given lane or for all lanes if -1 is given
Definition NBEdge.cpp:4503
NBNode * getToNode() const
Returns the destination node of the edge.
Definition NBEdge.h:552
static const double UNSPECIFIED_FRICTION
unspecified lane friction
Definition NBEdge.h:355
void incLaneNo(int by)
increment lane
Definition NBEdge.cpp:4236
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition NBEdge.h:789
bool addEdge2EdgeConnection(NBEdge *dest, bool overrideRemoval=false, SVCPermissions permission=SVC_UNSPECIFIED)
Adds a connection to another edge.
Definition NBEdge.cpp:1120
bool addLane2LaneConnection(int fromLane, NBEdge *dest, int toLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false, KeepClear keepClear=KEEPCLEAR_UNSPECIFIED, double contPos=UNSPECIFIED_CONTPOS, double visibility=UNSPECIFIED_VISIBILITY_DISTANCE, double speed=UNSPECIFIED_SPEED, double friction=UNSPECIFIED_FRICTION, double length=myDefaultConnectionLength, const PositionVector &customShape=PositionVector::EMPTY, const bool uncontrolled=UNSPECIFIED_CONNECTION_UNCONTROLLED, SVCPermissions permissions=SVC_UNSPECIFIED, const bool indirectLeft=false, const std::string &edgeType="", SVCPermissions changeLeft=SVC_UNSPECIFIED, SVCPermissions changeRight=SVC_UNSPECIFIED, bool postProcess=false)
Adds a connection between the specified this edge's lane and an approached one.
Definition NBEdge.cpp:1156
const std::string & getID() const
Definition NBEdge.h:1551
void setLaneSpreadFunction(LaneSpreadFunction spread)
(Re)sets how the lanes lateral offset shall be computed
Definition NBEdge.cpp:1015
int getNumLanes() const
Returns the number of lanes.
Definition NBEdge.h:526
@ VALIDATED
The connection was computed and validated.
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition NBEdge.h:545
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition NBEdge.h:346
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition NBEdge.h:349
void setAsMacroscopicConnector()
Definition NBEdge.h:1135
static std::string normalIDRepresentation(const std::string &id)
converts the numerical id to its "normal" string representation
Definition NBHelpers.cpp:69
Instance responsible for building networks.
NBPTStopCont & getPTStopCont()
Returns a reference to the pt stop container.
NBNodeCont & getNodeCont()
Returns a reference to the node container.
NBEdgeCont & getEdgeCont()
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
NBTypeCont & getTypeCont()
Returns a reference to the type container.
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=nullptr)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Represents a single node (junction) during network building.
Definition NBNode.h:66
bool hasIncoming(const NBEdge *const e) const
Returns whether the given edge ends at this node.
Definition NBNode.cpp:1994
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges (The edges which yield in this node)
Definition NBNode.h:268
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges (The edges which start at this node)
Definition NBNode.h:273
bool hasOutgoing(const NBEdge *const e) const
Returns whether the given edge starts at this node.
Definition NBNode.cpp:2000
NBEdge * getConnectionTo(NBNode *n) const
get connection to certain node
Definition NBNode.cpp:2801
bool insert(std::shared_ptr< NBPTStop > ptStop, bool floating=false)
Inserts a node into the map.
bool markEdgeTypeAsSet(const std::string &id, const SumoXMLAttr attr)
Marks an attribute of a edgeType as set.
void insertEdgeType(const std::string &id, int numLanes, double maxSpeed, int prio, SVCPermissions permissions, LaneSpreadFunction spreadType, double width, bool oneWayIsDefault, double sidewalkWidth, double bikeLaneWidth, double widthResolution, double maxWidth, double minWidth)
Adds a edgeType into the list.
double getEdgeTypeSpeed(const std::string &edgeType) const
Returns the maximal velocity for the given edgeType [m/s].
int getEdgeTypePriority(const std::string &edgeType) const
Returns the priority for the given edgeType.
int getEdgeTypeNumLanes(const std::string &edgeType) const
Returns the number of lanes for the given edgeType.
SVCPermissions getEdgeTypePermissions(const std::string &edgeType) const
Returns allowed vehicle classes for the given edgeType.
A VISUM network importer.
void load()
Parses the VISUM-network file storing the parsed structures within myNetBuilder.
void parse_Phases()
Parses LSAPHASE/PHASE.
NBCapacity2Lanes myCapacity2Lanes
The converter to compute the lane number of edges from their capacity.
static StringBijection< VISUM_KEY > KEYS
link directions
NBNetBuilder & myNetBuilder
The network builder to fill with loaded values.
void parse_Edges()
Parses STRECKE/STRECKEN.
double getWeightedFloat2(const std::string &name, const std::string &name2, const std::string &suffix)
as above but with two alternative names
~NIImporter_VISUM()
destructor
std::vector< std::string > myTouchedEdges
Already read edges.
NBEdge * getNamedEdge(const std::string &fieldName)
Tries to get the edge which name is stored in the given field.
double getWeightedFloat(const std::string &name, const std::string &suffix)
tries to get a double which is possibly assigned to a certain modality
void parse_VSysTypes()
Parses VSYS.
SVCPermissions getPermissions(const std::string &name, bool warn=false, SVCPermissions unknown=SVCAll)
parse permissions
void parse_NodesToTrafficLights()
Parses KNOTENZULSA/SIGNALANLAGEZUKNOTEN.
void parse_PartOfArea()
Parses FLAECHENELEMENT.
void parse_TrafficLights()
Parses LSA/SIGNALANLAGE.
NBNode * getNamedNodeSecure(const std::string &fieldName, NBNode *fallback=0)
void parse_Point()
Parses PUNKT.
void parse_Districts()
Parses BEZIRK.
VSysTypeNames myVSysTypes
The used vsystypes.
std::string myCurrentID
The name of the currently parsed item used for error reporting.
bool getWeightedBool(const std::string &name)
tries to get a bool which is possibly assigned to a certain modality
void parse_stopPoints()
Parses HALTEPUNKT (public transport stop locations)
std::map< NBDistrict *, PositionVector > myDistrictShapes
A temporary storage for district shapes as they are filled incrementally.
std::string myFileName
The name of the parsed file, for error reporting.
std::map< long long int, Position > myPoints
A map of point ids to positions.
void addParser(const std::string &name, ParsingFunction function)
Adds a parser into the sorted list of parsers to use.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads network definition from the assigned option and stores it in the given network builder.
NIImporter_VISUM(NBNetBuilder &nb, const std::string &file, NBCapacity2Lanes capacity2Lanes, bool useVisumPrio, const std::string &languageFile)
constructor
static StringBijection< VISUM_KEY >::Entry KEYS_DE[]
Strings for the keywords.
std::map< long long int, std::pair< long long int, long long int > > myEdges
A map of edge (not road, but "edge" in this case) ids to from/to-points.
void parse_EdgePolys()
Parses STRECKENPOLY.
LineReader myLineReader
The line reader to use to read from the file.
bool myUseVisumPrio
Information whether VISUM priority information shall be used.
void loadLanguage(const std::string &file)
bool checkNodes(NBNode *from, NBNode *to)
Returns whether both nodes are a valid combination of from/to-nodes.
NBEdge * getReversedContinuating(NBEdge *edge, NBNode *node)
Returns the opposite direction of the given edge.
ParserVector mySingleDataParsers
List of known parsers.
void parse_SignalGroupsToPhases()
Parses LSASIGNALGRUPPEZULSAPHASE.
NBNode * getNamedNode(const std::string &fieldName)
Tries to get the node which name is stored in the given field.
void parse_Kante()
Parses FLAECHENELEMENT.
void parse_SignalGroups()
Parses LSASIGNALGRUPPE/SIGNALGRUPPE.
NBNode * buildDistrictNode(const std::string &id, NBNode *dest, bool isSource)
Builds a node for the given district and returns it.
void parse_Lanes()
Parses FAHRSTREIFEN.
NBEdge * getEdge(NBNode *FromNode, NBNode *ToNode)
Returns the edge that connects both nodes.
NamedColumnsParser myLineParser
the parser to parse the information from the data lines
double getNamedFloat(const std::string &fieldName)
Returns the value from the named column as a float.
std::map< long long int, NBDistrict * > myShapeDistrictMap
A map from district shape definition name to the district.
void parse_Turns()
Parses ABBIEGEBEZIEHUNG/ABBIEGER.
void parse_Nodes()
Parses KNOTEN.
void parse_TurnsToSignalGroups()
Parses ABBZULSASIGNALGRUPPE/SIGNALGRUPPEZUABBIEGER.
NBEdge * getNamedEdgeContinuating(const std::string &fieldName, NBNode *node)
Tries to get the edge which name is stored in the given field continuating the search for a subedge t...
std::string getNamedString(const std::string &fieldName)
Returns the value from the named column as a normalised string.
void parse_LanesConnections()
Parses FAHRSTREIFENABBIEGER.
static bool isSplitEdge(NBEdge *edge, NBNode *node)
whether the edge id ends with _nodeID
void parse_Types()
Parses STRECKENTYP.
void parse_Connectors()
Parses ANBINDUNG.
void parse_AreaSubPartElement()
Parses ABBZULSASIGNALGRUPPE/SIGNALGRUPPEZUABBIEGER.
std::map< long long int, std::vector< long long int > > mySubPartsAreas
A map from area parts to area ids.
NIVisumTL_Map myTLS
List of visum traffic lights.
A signal group can be defined either by a time period or by phases.
Definition NIVisumTL.h:103
std::map< std::string, Phase * > & phases()
Returns the phases map.
Definition NIVisumTL.h:118
NBConnectionVector & connections()
Returns the connections vector.
Definition NIVisumTL.h:113
Intermediate class for storing visum traffic lights during their import.
Definition NIVisumTL.h:41
std::map< std::string, Phase * > & getPhases()
Returns the map of named phases.
Definition NIVisumTL.h:159
SignalGroup & getSignalGroup(const std::string &name)
Returns the named signal group.
Definition NIVisumTL.cpp:66
void reinit(const std::string &def, const std::string &defDelim=";", const std::string &lineDelim=";", bool chomp=false, bool ignoreCase=true)
Reinitialises the parser.
bool know(const std::string &name) const
Returns the information whether the named column is known.
void parseLine(const std::string &line)
Parses the contents of the line.
std::string get(const std::string &name, bool prune=false) const
Returns the named information.
const std::string & getID() const
Returns the id.
Definition Named.h:74
A storage for options typed value containers)
Definition OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
PositionVector reverse() const
reverse position vector
const std::string & getString(const T key) const
get string
void remove(const std::string str, const T key)
remove string
bool hasString(const std::string &str) const
check if the given string exist
T get(const std::string &str) const
get key
void insert(const std::string str, const T key, bool checkDuplicates=true)
insert string and their associated key
std::vector< std::string > getVector()
return vector of strings
static long long int toLong(const std::string &sData)
converts a string into the long value described by it by calling the char-type converter,...
static std::string to_lower_case(const std::string &str)
Transfers the content to lower case.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static std::string latin1_to_utf8(std::string str)
Transfers from Latin 1 (ISO-8859-1) to UTF-8.
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
A complete call description for parsing a single db.
ParsingFunction function
Pointer to the function used for parsing.
std::string name
The name of the db.
long position
Position of the according db within the file.
bijection entry