Eclipse SUMO - Simulation of Urban MObility
NIImporter_Vissim.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // -------------------
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 
29 #include <string>
30 #include <fstream>
35 #include <netbuild/NBNetBuilder.h>
36 #include "NIImporter_Vissim.h"
92 
93 
94 #include "tempstructs/NIVissimTL.h"
107 
109 #include <utils/xml/XMLSubSys.h>
114 
115 #include <netbuild/NBEdgeCont.h> // !!! only for debugging purposes
116 
117 
118 // ===========================================================================
119 // static variables
120 // ===========================================================================
129  { "linkPolyPoint", NIImporter_Vissim::VISSIM_TAG_LINKPOLYPOINT },
131  { "fromLinkEndPt", NIImporter_Vissim::VISSIM_TAG_FROM },
132  { "toLinkEndPt", NIImporter_Vissim::VISSIM_TAG_TO },
136  { "intObjectRef", NIImporter_Vissim::VISSIM_TAG_INTOBJECTREF },
137  { "desSpeedDecision", NIImporter_Vissim::VISSIM_TAG_SPEED_DECISION },
138  {
139  "desSpeedDistribution",
141  },
142  {
143  "speedDistributionDataPoint",
145  },
146  {
147  "vehicleRoutingDecisionStatic",
149  },
150  {
151  "vehicleRouteStatic",
153  },
154  { "conflictArea", NIImporter_Vissim::VISSIM_TAG_CA },
156 };
157 
158 
160  { "no", NIImporter_Vissim::VISSIM_ATTR_NO }, //id
172  { "intLink", NIImporter_Vissim::VISSIM_ATTR_INTLINK }, //edgeID
184 };
185 
186 
187 // ===========================================================================
188 // method definitions
189 // ===========================================================================
190 // ---------------------------------------------------------------------------
191 // static methods (interface in this case)
192 // ---------------------------------------------------------------------------
193 void
195  if (!oc.isSet("vissim-file")) {
196  return;
197  }
198  NIImporter_Vissim(nb).load(oc);
199 }
200 
201 
202 // ---------------------------------------------------------------------------
203 // definitions of NIVissimXMLHandler_Streckendefinition-methods
204 // ---------------------------------------------------------------------------
206  //std::map<int, VissimXMLEdge>& toFill)
207  nodeMap& elemData)
210  "vissim - file"),
211  myElemData(elemData),
212  myHierarchyLevel(0),
213  isConnector(false) {
214  myElemData.clear();
215 }
216 
218 
219 void
222 
223  // finding an actual LINK
224  if (element == VISSIM_TAG_LINK) {
225  //parse all links
226  bool ok = true;
227  int id = attrs.get<int>(VISSIM_ATTR_NO, nullptr, ok);
228  myLastNodeID = id;
229 
230  // !!! assuming empty myElemData
231  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, nullptr, ok));
232  // error ignored if name is empty
233  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, nullptr, ok, false));
234  myElemData["type"].push_back(attrs.get<std::string>(VISSIM_ATTR_LINKBEHAVETYPE, nullptr, ok));
235  myElemData["zuschlag1"].push_back(attrs.get<std::string>(VISSIM_ATTR_ZUSCHLAG1, nullptr, ok));
236  myElemData["zuschlag2"].push_back(attrs.get<std::string>(VISSIM_ATTR_ZUSCHLAG2, nullptr, ok));
237  }
238 
239  if (element == VISSIM_TAG_LANE) {
240  bool ok = true;
241  // appends empty element if no width found
242  // error ignored if name is empty
243  myElemData["width"].push_back(attrs.get<std::string>(VISSIM_ATTR_WIDTH, nullptr, ok, false));
244  }
245 
246  if (element == VISSIM_TAG_FROM) {
247  if (isConnector != true) {
248  isConnector = true;
249  }
250  bool ok = true;
251  std::vector<std::string> from(StringTokenizer(attrs.get<std::string>(
252  VISSIM_ATTR_LANE, nullptr, ok), " ").getVector());
253  myElemData["from_pos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, nullptr, ok));
254  myElemData["from_id"].push_back(from[0]);
255  myElemData["from_lane"].push_back(from[1]);
256  }
257 
258  if (element == VISSIM_TAG_TO) {
259  bool ok = true;
260  std::vector<std::string> to(StringTokenizer(attrs.get<std::string>(
261  VISSIM_ATTR_LANE, nullptr, ok), " ").getVector());
262  myElemData["to_pos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, nullptr, ok));
263  myElemData["to_id"].push_back(to[0]);
264  myElemData["to_lane"].push_back(to[1]);
265  }
266 
267  if (element == VISSIM_TAG_POINT3D || element == VISSIM_TAG_LINKPOLYPOINT) {
268  bool ok = true;
269  // create a <sep> separated string of coordinate data
270  std::string sep(" ");
271 
272  std::string posS(attrs.get<std::string>(VISSIM_ATTR_X, nullptr, ok));
273  posS += sep;
274  posS.append(attrs.get<std::string>(VISSIM_ATTR_Y, nullptr, ok));
275  // allow for no Z
276  std::string z(attrs.get<std::string>(VISSIM_ATTR_ZOFFSET, nullptr, ok, false));
277  if (z.length() > 0) {
278  posS += sep;
279  posS.append(z);
280  }
281  myElemData["pos"].push_back(posS);
282  }
283 
284 
285 }
286 
287 void
289  if (element == VISSIM_TAG_LINK && myHierarchyLevel == 3) {
290  //std::cout << "elemData len:" << myElemData.size() << std::endl;
291 
292  NIVissimClosedLanesVector clv; //FIXME -> clv einlesen
293  std::vector<int> assignedVehicles; //FIXME -> assignedVehicles einlesen
294  int id(StringUtils::toInt(myElemData["id"].front()));
295 
296  PositionVector geom;
297  // convert all position coordinate strings to PositionVectors
298  while (!myElemData["pos"].empty()) {
299  std::vector<std::string> sPos_v(StringTokenizer(
300  myElemData["pos"].front(), " ").getVector());
301  myElemData["pos"].pop_front();
302  std::vector<double> pos_v(3);
303 
304  // doing a transform with explicit hint on function signature
305  std::transform(sPos_v.begin(), sPos_v.end(), pos_v.begin(),
307  geom.push_back_noDoublePos(Position(pos_v[0], pos_v[1], pos_v[2]));
308  }
309  // FIXME: a length = 0 PosVec seems fatal -> segfault
310  double length(geom.length());
311 
312  if (isConnector == false) {
313  // Add Edge
314  std::vector<double> laneWidths;
315  for (std::string& w : myElemData["width"]) {
316  laneWidths.push_back(StringUtils::toDouble(w));
317  }
318  NIVissimEdge* edge = new NIVissimEdge(id,
319  myElemData["name"].front(),
320  myElemData["type"].front(),
321  laneWidths,
322  StringUtils::toDouble(myElemData["zuschlag1"].front()),
323  StringUtils::toDouble(myElemData["zuschlag2"].front()),
324  length, geom, clv);
325  NIVissimEdge::dictionary(id, edge);
326  } else {
327  int numLanes = (int)myElemData["width"].size();
328  std::vector<int> laneVec(numLanes);
329  // Add Connector
330 
331  //NOTE: there should be only 1 lane number in XML
332  // subtraction of 1 as in readExtEdgePointDef()
333  laneVec[0] = StringUtils::toInt(myElemData["from_lane"].front()) - 1;
334  // then count up, building lane number vector
335  for (std::vector<int>::iterator each = ++laneVec.begin(); each != laneVec.end(); ++each) {
336  *each = *(each - 1) + 1;
337  }
338 
339  NIVissimExtendedEdgePoint from_def(
340  StringUtils::toInt(myElemData["from_id"].front()),
341  laneVec,
342  StringUtils::toDouble(myElemData["from_pos"].front()),
343  assignedVehicles);
344 
345  //NOTE: there should be only 1 lane number in XML
346  // subtraction of 1 as in readExtEdgePointDef()
347  laneVec[0] = StringUtils::toInt(myElemData["to_lane"].front()) - 1;
348  // then count up, building lane number vector
349  for (std::vector<int>::iterator each = ++laneVec.begin(); each != laneVec.end(); ++each) {
350  *each = *(each - 1) + 1;
351  }
352 
354  StringUtils::toInt(myElemData["to_id"].front()),
355  laneVec,
356  StringUtils::toDouble(myElemData["to_pos"].front()),
357  assignedVehicles);
358 
359  NIVissimConnection* connector = new
361  myElemData["name"].front(),
362  from_def, to_def,
363  geom, assignedVehicles, clv);
364 
365  NIVissimConnection::dictionary(id, connector);
366  }
367  // clear the element data
368  myElemData.clear();
369  isConnector = false;
370  //std::cout << "elemData len (clear):" << myElemData.size() << std::endl;
371  //std::cout.flush();
372 
373  }
375 }
376 
377 
378 // ---------------------------------------------------------------------------
379 // definitions of NIVissimXMLHandler_Zuflussdefinition-methods
380 // ---------------------------------------------------------------------------
384  "vissim - file") {
385 }
386 
388 
389 void
391  // finding an actual flow
392  if (element == VISSIM_TAG_VEHICLE_INPUT) {
393  //parse all flows
394  bool ok = true;
395  std::string id = attrs.get<std::string>(VISSIM_ATTR_NO, nullptr, ok);
396  std::string edgeid = attrs.get<std::string>(VISSIM_ATTR_LINK, nullptr, ok);
397  std::string name = attrs.get<std::string>(VISSIM_ATTR_NAME, nullptr, ok, false);
398 
400  name,
401  edgeid);
402  }
403 }
404 
405 // ---------------------------------------------------------------------------
406 // definitions of NIVissimXMLHandler_Parkplatzdefinition-methods
407 // ---------------------------------------------------------------------------
411  "vissim - file") {
412 }
413 
415 
416 void
418  // finding an actual parkinglot
419  if (element == VISSIM_TAG_PARKINGLOT) {
420  //parse all parkinglots
421  bool ok = true;
422  int id = attrs.get<int>(VISSIM_ATTR_NO, nullptr, ok);
423  int edgeid = attrs.get<int>(VISSIM_ATTR_INTLINK, nullptr, ok);
424  std::string name = attrs.get<std::string>(VISSIM_ATTR_NAME, nullptr, ok, false);
425  double position = attrs.get<double>(VISSIM_ATTR_POS, nullptr, ok);
426  std::vector<std::pair<int, int> > assignedVehicles; // (vclass, vwunsch)
427  //FIXME: vWunsch + Fahzeugklassen einlesen
428  // There can be s
429  std::vector<int> districts;
430  //FIXME: Parkplatzdefinition für mehrere Zonen implementieren
431  std::vector<double> percentages;
432  districts.push_back(attrs.get<int>(VISSIM_ATTR_DISTRICT, nullptr, ok));
433  percentages.push_back(attrs.get<double>(VISSIM_ATTR_PERCENTAGE, nullptr, ok));
434 
436  name,
437  districts,
438  percentages,
439  edgeid,
440  position,
441  assignedVehicles);
442  }
443 }
444 
445 
446 // ---------------------------------------------------------------------------
447 // definitions of NIVissimXMLHandler_Fahrzeugklassendefinition-methods
448 // ---------------------------------------------------------------------------
452  "vissim - file"),
453  myElemData(elemData),
454  myHierarchyLevel(0) {
455  myElemData.clear();
456 }
457 
459 
460 void
463 
464  if (element == VISSIM_TAG_VEHICLE_CLASS) {
465  bool ok = true;
466  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, nullptr, ok));
467  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, nullptr, ok, false));
468  std::string colorStr(attrs.get<std::string>(VISSIM_ATTR_COLOR, nullptr, ok));
469  for (int pos = (int)colorStr.size() - 2; pos > 0; pos -= 2) {
470  colorStr.insert(pos, " ");
471  }
472  myElemData["color"].push_back(colorStr);
473  }
474  if (element == VISSIM_TAG_INTOBJECTREF) {
475  bool ok = true;
476  myElemData["types"].push_back(attrs.get<std::string>(VISSIM_ATTR_KEY, nullptr, ok));
477 
478 
479  }
480 }
481 
482 void
484  if (element == VISSIM_TAG_VEHICLE_CLASS && myHierarchyLevel == 3) {
485  RGBColor color;
486  std::istringstream iss(myElemData["color"].front());
487  std::vector<std::string> sCol_v(StringTokenizer(
488  myElemData["color"].front(), " ").getVector());
489  std::vector<int> myColorVector(sCol_v.size());
490  std::transform(sCol_v.begin(), sCol_v.end(), myColorVector.begin(), StringUtils::hexToInt);
491 
492  color = RGBColor((unsigned char)myColorVector[0],
493  (unsigned char)myColorVector[1],
494  (unsigned char)myColorVector[2],
495  (unsigned char)myColorVector[3]);
496  std::vector<int> types;
497  while (!myElemData["types"].empty()) {
498  types.push_back(StringUtils::toInt(myElemData["types"].front()));
499  myElemData["types"].pop_front();
500  }
501 
503  myElemData["name"].front(),
504  color,
505  types);
506  myElemData.clear();
507  }
509 }
510 
511 // ---------------------------------------------------------------------------
512 // definitions of NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition-methods
513 // ---------------------------------------------------------------------------
517  "vissim - file"),
518  myElemData(elemData),
519  myHierarchyLevel(0) {
520  myElemData.clear();
521 }
522 
524 
525 void
528  if (element == VISSIM_TAG_SPEED_DIST) {
529  bool ok = true;
530  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, nullptr, ok));
531  }
532 
533  if (element == VISSIM_TAG_DATAPOINT) {
534  bool ok = true;
535  std::string sep(" ");
536  std::string posS(attrs.get<std::string>(VISSIM_ATTR_X, nullptr, ok));
537  posS += sep;
538  posS.append(attrs.get<std::string>(VISSIM_ATTR_FX, nullptr, ok));
539  myElemData["points"].push_back(posS);
540 
541  }
542 
543 }
544 
545 void
547  if (element == VISSIM_TAG_SPEED_DIST && myHierarchyLevel == 3) {
548  Distribution_Points* points = new Distribution_Points(myElemData["id"].front());
549  while (!myElemData["points"].empty()) {
550  std::vector<std::string> sPos_v(StringTokenizer(
551  myElemData["points"].front(), " ").getVector());
552  myElemData["points"].pop_front();
553  points->add(StringUtils::toDouble(sPos_v[0]), StringUtils::toDouble(sPos_v[1]));
554  }
555  DistributionCont::dictionary("speed", myElemData["id"].front(), points);
556  myElemData.clear();
557  }
559 }
560 
561 // ---------------------------------------------------------------------------
562 // definitions of NIVissimXMLHandler_VWunschentscheidungsdefinition-methods
563 // ---------------------------------------------------------------------------
567  "vissim - file"),
568  myElemData(elemData),
569  myHierarchyLevel(0) {
570  myElemData.clear();
571 }
572 
574 
575 void
578  if (element == VISSIM_TAG_SPEED_DECISION) {
579  bool ok = true;
580  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, nullptr, ok, false));
581  //FIXME: 2 vWunsch in the xml file, but only 1 of them is set???
582  }
583 
584 }
585 
586 void
589 }
590 
591 
592 // ---------------------------------------------------------------------------
593 // definitions of NIVissimXMLHandler_Routenentscheidungsdefinition-methods
594 // ---------------------------------------------------------------------------
598  "vissim - file"),
599  myElemData(elemData),
600  myHierarchyLevel(0) {
601  myElemData.clear();
602 }
603 
605 
606 void
609  if (element == VISSIM_TAG_DECISION_STATIC) {
610  bool ok = true;
611  myElemData["startLink"].push_back(attrs.get<std::string>(VISSIM_ATTR_LINK, nullptr, ok));
612  myElemData["startPos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, nullptr, ok));
613  }
614  if (element == VISSIM_TAG_ROUTE_STATIC) {
615  bool ok = true;
616  myElemData["destLink"].push_back(attrs.get<std::string>(VISSIM_ATTR_DESTLINK, nullptr, ok));
617  myElemData["destPos"].push_back(attrs.get<std::string>(VISSIM_ATTR_DESTPOS, nullptr, ok));
618  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, nullptr, ok));
619  }
620  if (element == VISSIM_TAG_INTOBJECTREF) {
621  // bool ok = true;
622  }
623 
624 }
625 
626 void
629 }
630 
631 // ---------------------------------------------------------------------------
632 // definitions of NIVissimXMLHandler_ConflictArea-methods
633 // ---------------------------------------------------------------------------
637  "vissim - file") {}
638 
640 
641 void
643  // finding an actual flow
644  if (element == VISSIM_TAG_CA) {
645  //parse all flows
646  bool ok = true;
647  std::string status = attrs.get<std::string>(VISSIM_ATTR_STATUS, nullptr, ok);
648  //get only the conflict areas which were set in VISSIM
649  if (status != "PASSIVE") {
650  NIVissimConflictArea::dictionary(attrs.get<int>(VISSIM_ATTR_NO, nullptr, ok),
651  attrs.get<std::string>(VISSIM_ATTR_LINK1, nullptr, ok),
652  attrs.get<std::string>(VISSIM_ATTR_LINK2, nullptr, ok),
653  status);
654  }
655 
656  }
657 }
658 
659 
660 /* -------------------------------------------------------------------------
661  * NIImporter_Vissim::VissimSingleTypeParser-methods
662  * ----------------------------------------------------------------------- */
664  : myVissimParent(parent) {}
665 
666 
668 
669 
670 std::string
672  std::string tmp;
673  from >> tmp;
674  return StringUtils::to_lower_case(tmp);
675 }
676 
677 
678 
679 std::string
681  const std::string& excl) {
682  std::string myExcl = StringUtils::to_lower_case(excl);
683  std::string tmp = myRead(from);
684  if (tmp == "") {
685  return "DATAEND";
686  }
687  if (tmp != myExcl
688  &&
689  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
690  ) {
691  return "DATAEND";
692  }
693  return StringUtils::to_lower_case(tmp);
694 }
695 
696 
697 std::string
699  const std::vector<std::string>& excl) {
700  std::vector<std::string> myExcl;
701  std::vector<std::string>::const_iterator i;
702  for (i = excl.begin(); i != excl.end(); i++) {
703  std::string mes = StringUtils::to_lower_case(*i);
704  myExcl.push_back(mes);
705  }
706  std::string tmp = myRead(from);
707  if (tmp == "") {
708  return "DATAEND";
709  }
710 
711  bool equals = false;
712  for (i = myExcl.begin(); i != myExcl.end() && !equals; i++) {
713  if ((*i) == tmp) {
714  equals = true;
715  }
716  }
717  if (!equals
718  &&
719  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
720  ) {
721  return "DATAEND";
722  }
723  return StringUtils::to_lower_case(tmp);
724 }
725 
726 
727 std::string
729  const std::string& tag) {
730  std::string tmp;
731  if (tag == "") {
732  tmp = myRead(from);
733  } else {
734  tmp = tag;
735  }
736  if (tmp == "beschriftung") {
737  tmp = myRead(from);
738  if (tmp == "keine") {
739  from >> tmp;
740  }
741  tmp = myRead(from);
742  tmp = myRead(from);
743  }
744  return tmp;
745 }
746 
747 
748 Position
750  double x, y;
751  from >> x; // type-checking is missing!
752  from >> y; // type-checking is missing!
753  return Position(x, y);
754 }
755 
756 
757 std::vector<int>
759  std::istream& from, const std::string& next) {
760  std::string tmp = readEndSecure(from);
761  std::vector<int> ret;
762  if (tmp == "alle") {
763  ret.push_back(-1);
764  return ret;
765  }
766  while (tmp != "DATAEND" && tmp != next) {
767  ret.push_back(StringUtils::toInt(tmp));
768  tmp = readEndSecure(from);
769  }
770  return ret;
771 }
772 
773 
776  std::istream& from) {
777  std::string tag;
778  from >> tag; // "Strecke"
779  int edgeid;
780  from >> edgeid; // type-checking is missing!
781  from >> tag; // "Spuren"
782  std::vector<int> lanes;
783  while (tag != "bei") {
784  tag = readEndSecure(from);
785  if (tag != "bei") {
786  int lane = StringUtils::toInt(tag);
787  lanes.push_back(lane - 1);
788  }
789  }
790  double position;
791  from >> position;
792  std::vector<int> dummy;
793  return NIVissimExtendedEdgePoint(edgeid, lanes, position, dummy);
794 }
795 
796 
797 std::string
799  std::string name;
800  from >> name;
801  if (name[0] == '"') {
802  while (name[name.length() - 1] != '"') {
803  std::string tmp;
804  from >> tmp;
805  name = name + " " + tmp;
806  }
807  name = name.substr(1, name.length() - 2);
808  }
809  return StringUtils::convertUmlaute(name);
810 }
811 
812 
813 void
815  const std::string& name) {
816  std::string tag;
817  while (tag != name) {
818  tag = myRead(from);
819  }
820 }
821 
822 bool
824  const std::string& name) {
825  std::string tag;
826  while (tag != name) {
827  tag = myRead(from);
828  }
829  while (tag != "DATAEND") {
830  tag = readEndSecure(from);
831  }
832  return true;
833 }
834 
835 
836 
837 /* -------------------------------------------------------------------------
838  * NIImporter_Vissim-methods
839  * ----------------------------------------------------------------------- */
842  buildParsers();
843  myColorMap["blau"] = RGBColor(77, 77, 255, 255);
844  myColorMap["gelb"] = RGBColor::YELLOW;
845  myColorMap["grau"] = RGBColor::GREY;
846  myColorMap["lila"] = RGBColor::MAGENTA;
847  myColorMap["gruen"] = RGBColor::GREEN;
848  myColorMap["rot"] = RGBColor::RED;
849  myColorMap["schwarz"] = RGBColor::BLACK;
850  myColorMap["tuerkis"] = RGBColor::CYAN;
851  myColorMap["weiss"] = RGBColor::WHITE;
852  myColorMap["keine"] = RGBColor::WHITE;
853 }
854 
855 
856 
857 
877  for (ToParserMap::iterator i = myParsers.begin(); i != myParsers.end(); i++) {
878  delete (*i).second;
879  }
880 }
881 
882 
883 void
885  const std::string file = options.getString("vissim-file");
886  // try to open the file
887  std::ifstream strm(file.c_str());
888  if (!strm.good()) {
889  WRITE_ERROR("Could not open vissim-file '" + file + "'.");
890  return;
891  }
892  std::string token;
893  strm >> token;
894  if (StringUtils::endsWith(file, ".inpx") || StringUtils::endsWith(token, "<?xml") || StringUtils::endsWith(token, "<network")) {
895  // Create NIVissimXMLHandlers
896  NIVissimXMLHandler_Streckendefinition XMLHandler_Streckendefinition(elementData);
897  NIVissimXMLHandler_Zuflussdefinition XMLHandler_Zuflussdefinition;
898  //NIVissimXMLHandler_Parkplatzdefinition XMLHandler_Parkplatzdefinition;
899  NIVissimXMLHandler_Fahrzeugklassendefinition XMLHandler_Fahrzeugklassendefinition(elementData);
900  NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition XMLHandler_Geschwindigkeitsverteilung(elementData);
901  NIVissimXMLHandler_ConflictArea XMLHandler_ConflictAreas;
902 
903  // Strecken + Verbinder
904  XMLHandler_Streckendefinition.setFileName(file);
905  PROGRESS_BEGIN_MESSAGE("Parsing strecken+verbinder from vissim-file '" + file + "'");
906  if (!XMLSubSys::runParser(XMLHandler_Streckendefinition, file)) {
907  return;
908  }
910 
911  // Zuflüsse
912  XMLHandler_Zuflussdefinition.setFileName(file);
913  PROGRESS_BEGIN_MESSAGE("Parsing zuflüsse from vissim-file '" + file + "'");
914  if (!XMLSubSys::runParser(XMLHandler_Zuflussdefinition, file)) {
915  return;
916  }
918 
919  //Geschwindigkeitsverteilungen
920  XMLHandler_Geschwindigkeitsverteilung.setFileName(file);
921  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
922  if (!XMLSubSys::runParser(XMLHandler_Geschwindigkeitsverteilung, file)) {
923  return;
924  }
926 
927 
928  //Fahrzeugklassen
929  XMLHandler_Fahrzeugklassendefinition.setFileName(file);
930  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
931  if (!XMLSubSys::runParser(XMLHandler_Fahrzeugklassendefinition, file)) {
932  return;
933  }
935 
936  //Parkplätze
937  /*XMLHandler_Parkplatzdefinition.setFileName(file);
938  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
939  if (!XMLSubSys::runParser(XMLHandler_Parkplatzdefinition, file)) {
940  return;
941  }
942  PROGRESS_DONE_MESSAGE();*/
943 
944 
945  //Konfliktflächen
946  XMLHandler_ConflictAreas.setFileName(file);
947  PROGRESS_BEGIN_MESSAGE("Parsing conflict areas from vissim-file '" + file + "'");
948  if (!XMLSubSys::runParser(XMLHandler_ConflictAreas, file)) {
949  return;
950  }
952  } else {
953  strm.seekg(strm.beg);
954  if (!readContents(strm)) {
955  return;
956  }
957  }
958  postLoadBuild(options.getFloat("vissim.join-distance"));
959 }
960 
961 
962 bool
963 NIImporter_Vissim::admitContinue(const std::string& tag) {
964  ToElemIDMap::const_iterator i = myKnownElements.find(tag);
965  if (i == myKnownElements.end()) {
966  return true;
967  }
968  myLastSecure = tag;
969  return false;
970 }
971 
972 
973 bool
974 NIImporter_Vissim::readContents(std::istream& strm) {
975  // read contents
976  bool ok = true;
977  while (strm.good() && ok) {
978  std::string tag;
979  if (myLastSecure != "") {
980  tag = myLastSecure;
981  } else {
982  strm >> tag;
983  }
984  myLastSecure = "";
985  bool parsed = false;
986  while (!parsed && strm.good() && ok) {
987  ToElemIDMap::iterator i = myKnownElements.find(StringUtils::to_lower_case(tag));
988  if (i != myKnownElements.end()) {
989  ToParserMap::iterator j = myParsers.find((*i).second);
990  if (j != myParsers.end()) {
991  VissimSingleTypeParser* parser = (*j).second;
992  ok = parser->parse(strm);
993  parsed = true;
994  }
995  }
996  if (!parsed) {
997  std::string line;
998  std::streamoff pos;
999  do {
1000  pos = strm.tellg();
1001  getline(strm, line);
1002  } while (strm.good() && (line == "" || line[0] == ' ' || line[0] == '-'));
1003  if (!strm.good()) {
1004  return true;
1005  }
1006  strm.seekg(pos);
1007  strm >> tag;
1008  }
1009  }
1010  }
1011  return ok;
1012 }
1013 
1014 
1015 void
1017  // close the loading process
1021  // build district->connections map
1023  // build clusters around nodes
1024 // NIVissimNodeDef::buildNodeClusters();
1025  // build node clusters around traffic lights
1026 // NIVissimTL::buildNodeClusters();
1027 
1028  // when connections or disturbances are left, build nodes around them
1029 
1030  // try to assign connection clusters to nodes
1031  // only left connections will be processed in
1032  // buildConnectionClusters & join
1033 //30.4. brauchen wir noch! NIVissimNodeDef::dict_assignConnectionsToNodes();
1034 
1035  // build clusters of connections with the same direction and a similar position along the streets
1037  // check whether further nodes (connection clusters by now) must be added
1039 
1040  // join clusters when overlapping (different streets are possible)
1043 // NIVissimConnectionCluster::joinByDisturbances(offset);
1044 
1045 // NIVissimConnectionCluster::addTLs(offset);
1046 
1047  // build nodes from clusters
1050 
1051 // NIVissimNodeCluster::dict_recheckEdgeChanges();
1057  if (OptionsCont::getOptions().getBool("vissim.report-unset-speeds")) {
1059  }
1065 }
1066 
1067 
1068 void
1070  myKnownElements["kennung"] = VE_Kennungszeile;
1071  myKnownElements["zufallszahl"] = VE_Startzufallszahl;
1072  myKnownElements["simulationsdauer"] = VE_Simdauer;
1073  myKnownElements["startuhrzeit"] = VE_Startuhrzeit;
1074  myKnownElements["simulationsrate"] = VE_SimRate;
1075  myKnownElements["zeitschritt"] = VE_Zeitschrittfaktor;
1076  myKnownElements["linksverkehr"] = VE_Linksverkehr;
1077  myKnownElements["dynuml"] = VE_DynUml;
1079  myKnownElements["gelbverhalten"] = VE_Gelbverhaltendefinition;
1081  myKnownElements["verbindung"] = VE_Verbindungsdefinition;
1082  myKnownElements["richtungsentscheidung"] = VE_Richtungsentscheidungsdefinition;
1083  myKnownElements["routenentscheidung"] = VE_Routenentscheidungsdefinition;
1084  myKnownElements["vwunschentscheidung"] = VE_VWunschentscheidungsdefinition;
1085  myKnownElements["langsamfahrbereich"] = VE_Langsamfahrbereichdefinition;
1087  myKnownElements["fahrzeugtyp"] = VE_Fahrzeugtypdefinition;
1088  myKnownElements["fahrzeugklasse"] = VE_Fahrzeugklassendefinition;
1098  myKnownElements["wunschbeschleunigung"] = VE_Wunschbeschleunigungskurvedefinition;
1101  myKnownElements["querverkehrsstoerung"] = VE_Querverkehrsstoerungsdefinition;
1103  myKnownElements["signalgruppe"] = VE_Signalgruppendefinition;
1104  myKnownElements["signalgeber"] = VE_Signalgeberdefinition;
1105  myKnownElements["lsakopplung"] = VE_LSAKopplungdefinition;
1107  myKnownElements["haltestelle"] = VE_Haltestellendefinition;
1109  myKnownElements["stopschild"] = VE_Stopschilddefinition;
1113  myKnownElements["querschnittsmessung"] = VE_Querschnittsmessungsdefinition;
1114  myKnownElements["stauzaehler"] = VE_Stauzaehlerdefinition;
1115  myKnownElements["auswertung"] = VE_Auswertungsdefinition;
1118  myKnownElements["parkplatz"] = VE_Parkplatzdefinition;
1121  myKnownElements["netzobjekt"] = VE_Netzobjektdefinition;
1122  myKnownElements["richtungspfeil"] = VE_Richtungspfeildefinition;
1124  myKnownElements["fahrverhalten"] = VE_Fahrverhaltendefinition;
1125  myKnownElements["fahrtverlaufdateien"] = VE_Fahrtverlaufdateien;
1126  myKnownElements["emission"] = VE_Emission;
1128  myKnownElements["streckentyp"] = VE_Streckentypdefinition;
1129  myKnownElements["kantensperrung"] = VE_Kantensperrung;
1131 
1132 
1133  myKnownElements["advance"] = VE_DUMMY;
1134  myKnownElements["temperatur"] = VE_DUMMY;
1135 
1136 }
1137 
1138 
1139 
1140 void
1146  myParsers[VE_DynUml] =
1220 
1263 
1264 }
1265 
1266 
1267 
1268 /****************************************************************************/
1269 
static void clearDict()
static void joinBySameEdges(double offset)
Tries to joind clusters participating within a node This is done by joining clusters which overlap...
void readUntil(std::istream &from, const std::string &name)
Reads from the stream until the keywor occurs.
static void dict_BuildDistricts(NBDistrictCont &dc, NBEdgeCont &ec, NBNodeCont &nc)
Builds the districts.
static bool dictionary(int id, const std::string &name, const RGBColor &color, std::vector< int > &types)
static void dict_buildNBEdgeConnections(NBEdgeCont &ec)
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
NIVissimXMLHandler_Streckendefinition(nodeMap &elemData)
Constructor.
static const RGBColor WHITE
Definition: RGBColor.h:197
static bool dictionary(int id, const std::string &link1, const std::string &link2, const std::string &status)
Adds the described item to the dictionary Builds the conflict area first.
std::string myRead(std::istream &from)
reads from the stream and returns the lower case version of the read value
static void dict_checkEdges2Join()
static void reportUnsetSpeeds()
Writes edges with unset speeds to the warnings message log instance.
std::string readEndSecure(std::istream &from, const std::string &excl="")
as myRead, but returns "DATAEND" when the current field has ended
std::vector< NIVissimClosedLaneDef * > NIVissimClosedLanesVector
~NIImporter_Vissim()
destructor
static StringBijection< int >::Entry vissimAttrs[]
The names of VISSIM-XML attributes (for passing to GenericSAXHandler)
static void clearDict()
Importer for networks stored in Vissim format.
VissimSingleTypeParser(NIImporter_Vissim &parent)
Constructor.
static void dict_buildNBEdges(NBDistrictCont &dc, NBNodeCont &nc, NBEdgeCont &ec, double offset)
Builds NBEdges from the VissimEdges within the dictionary.
virtual bool parse(std::istream &from)=0
Parses a single data type. Returns whether no error occurred.
bool readContents(std::istream &strm)
static bool dictionary(const std::string &type, const std::string &id, Distribution *d)
Adds a distribution of the given type and name to the container.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static const RGBColor BLACK
Definition: RGBColor.h:198
static bool dictionary(int id, NIVissimConnection *o)
int myLastNodeID
ID of the currently parsed node, for reporting mainly.
static void clearDict()
static int getMaxID()
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything&#39;s ok.
Definition: XMLSubSys.cpp:113
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
static void setPriorityRegulation(NBEdgeCont &ec)
Sets the priority regulation according to the VISSIM conflict area data.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
A temporary storage for edges imported from Vissim.
Definition: NIVissimEdge.h:53
ToParserMap myParsers
Parsers by element id.
static void dict_assignToEdges()
void insertKnownElements()
adds name-to-id - relationships of known elements into myKnownElements
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
ToElemIDMap myKnownElements
Map from element names to their numerical representation.
A handler which converts occuring elements and attributes into enums.
static void setCurrentVirtID(int id)
static const RGBColor GREEN
Definition: RGBColor.h:191
static const RGBColor GREY
Definition: RGBColor.h:199
void setFileName(const std::string &name)
Sets the current file name.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
NIVissimExtendedEdgePoint readExtEdgePointDef(std::istream &from)
static void dict_addDisturbances(NBDistrictCont &dc, NBNodeCont &nc, NBEdgeCont &ec)
Encapsulated SAX-Attributes.
static void dict_propagateSpeeds()
void load(const OptionsCont &options)
loads the vissim file
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
static void clearDict()
Clears the dictionary.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:151
static StringBijection< int >::Entry vissimTags[]
The names of VISSIM-XML elements (for passing to GenericSAXHandler)
A list of positions.
ColorMap myColorMap
a map from color names to color definitions
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static bool dict_SetSignals(NBTrafficLightLogicCont &tlc, NBEdgeCont &ec)
Definition: NIVissimTL.cpp:366
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
static const RGBColor MAGENTA
Definition: RGBColor.h:195
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:241
Position getPosition(std::istream &from)
returns the 2d-position saved as next within the stream
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
static bool dictionary(int id, const std::string &name, const std::string &type, int noLanes, double zuschlag1, double zuschlag2, double length, const PositionVector &geom, const NIVissimClosedLanesVector &clv)
Adds the described item to the dictionary Builds the edge first.
std::string readName(std::istream &from)
Reads the structures name We cannot use the "<<" operator, as names may contain more than one word wh...
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
static std::string convertUmlaute(std::string str)
Converts german "Umlaute" to their latin-version.
Definition: StringUtils.cpp:86
NIImporter_Vissim(NBNetBuilder &nb)
constructor
std::vector< std::string > getVector()
return vector of strings
void buildParsers()
adds id-to-parser - relationships of elements to parse into myParsers
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:245
static void clearDict()
Clears the dictionary.
static void buildConnectionClusters()
Clusters connections of each edge.
static std::string to_lower_case(std::string str)
Transfers the content to lower case.
Definition: StringUtils.cpp:58
static const RGBColor YELLOW
Definition: RGBColor.h:193
static const RGBColor RED
named colors
Definition: RGBColor.h:190
double length() const
Returns the length.
static const RGBColor CYAN
Definition: RGBColor.h:194
std::map< std::string, std::list< std::string > > nodeMap
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:156
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Instance responsible for building networks.
Definition: NBNetBuilder.h:110
A storage for options typed value containers)
Definition: OptionsCont.h:90
bool skipOverreading(std::istream &from, const std::string &name="")
Overreads the named parameter (if) given and skips the rest until "DATAEND".
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads network definition from the assigned option and stores it in the given network builder...
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:166
static void buildNBNodes(NBNodeCont &nc)
static void clearDict()
Definition: NIVissimTL.cpp:354
void postLoadBuild(double offset)
static void dict_SetDisturbances()
void push_back_noDoublePos(const Position &p)
insert in back a non double position
NBNetBuilder & myNetBuilder
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:242
std::string myLastSecure
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
Definition: NBNetBuilder.h:171
static int hexToInt(const std::string &sData)
converts a string with a hex value into the integer value described by it by calling the char-type co...
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
bool admitContinue(const std::string &tag)
std::string overrideOptionalLabel(std::istream &from, const std::string &tag="")
overrides the optional label definition; returns the next tag as done by readEndSecure ...
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
std::vector< int > parseAssignedVehicleTypes(std::istream &from, const std::string &next)
parses a listof vehicle types assigned to the current data field One should remeber, that -1 means "all" vehicle types
static bool dictionary(const std::string &id, const std::string &name, const std::string &edgeid)
static void dict_BuildDistrictNodes(NBDistrictCont &dc, NBNodeCont &nc)
Builds the nodes that belong to a district.
static bool dictionary(int id, const std::string &name, const std::vector< int > &districts, const std::vector< double > &percentages, int edgeid, double position, const std::vector< std::pair< int, int > > &assignedVehicles)
Inserts the connection into the dictionary after building it.