SUMO - Simulation of Urban MObility
NIImporter_Vissim.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // -------------------
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 
36 #include <string>
37 #include <fstream>
42 #include <netbuild/NBNetBuilder.h>
43 #include "NIImporter_Vissim.h"
99 
100 
101 #include "tempstructs/NIVissimTL.h"
114 
116 #include <utils/xml/XMLSubSys.h>
120 
121 #include <netbuild/NBEdgeCont.h> // !!! only for debugging purposes
122 #include <netbuild/NBDistribution.h>
123 
124 #ifdef CHECK_MEMORY_LEAKS
125 #include <foreign/nvwa/debug_new.h>
126 #endif // CHECK_MEMORY_LEAKS
127 
128 
129 // ===========================================================================
130 // static variables
131 // ===========================================================================
140  { "fromLinkEndPt", NIImporter_Vissim::VISSIM_TAG_FROM },
141  { "toLinkEndPt", NIImporter_Vissim::VISSIM_TAG_TO },
145  { "intObjectRef", NIImporter_Vissim::VISSIM_TAG_INTOBJECTREF },
146  { "desSpeedDecision", NIImporter_Vissim::VISSIM_TAG_SPEED_DECISION },
147  {
148  "desSpeedDistribution",
150  },
151  {
152  "speedDistributionDataPoint",
154  },
155  {
156  "vehicleRoutingDecisionStatic",
158  },
159  {
160  "vehicleRouteStatic",
162  },
163  { "conflictArea", NIImporter_Vissim::VISSIM_TAG_CA },
165 };
166 
167 
169  { "no", NIImporter_Vissim::VISSIM_ATTR_NO }, //id
181  { "intLink", NIImporter_Vissim::VISSIM_ATTR_INTLINK }, //edgeID
193 };
194 
195 
196 // ===========================================================================
197 // method definitions
198 // ===========================================================================
199 // ---------------------------------------------------------------------------
200 // static methods (interface in this case)
201 // ---------------------------------------------------------------------------
202 void
204  if (!oc.isSet("vissim-file")) {
205  return;
206  }
207  NIImporter_Vissim loader(nb, oc.getString("vissim-file"));
208  // check if legacy format file or newer XML file
209  // file name extension check
210  if ((oc.getString("vissim-file").find(".inpx") != std::string::npos))
211  //TODO: check if the given position of .inpx is at the end
212  {
213  // load the XML vissim network
214  loader.loadXML(oc, nb);
215  loader.myInputIsLegacyFormat = false;
216  } else {
217  // load the legacy vissim network
218  loader.load(oc);
219  loader.myInputIsLegacyFormat = true;
220  }
221 }
222 
223 
224 // ---------------------------------------------------------------------------
225 // definitions of NIVissimXMLHandler_Streckendefinition-methods
226 // ---------------------------------------------------------------------------
228  //std::map<int, VissimXMLEdge>& toFill)
229  nodeMap& elemData)
232  "vissim - file"),
233  myElemData(elemData),
234  myHierarchyLevel(0),
235  isConnector(false) {
236  myElemData.clear();
237 }
238 
240 
241 void
244 
245  // finding an actual LINK
246  if (element == VISSIM_TAG_LINK) {
247  //parse all links
248  bool ok = true;
249  int id = attrs.get<int>(VISSIM_ATTR_NO, 0, ok);
250  myLastNodeID = id;
251 
252  // !!! assuming empty myElemData
253  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
254  // error ignored if name is empty
255  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false));
256  myElemData["type"].push_back(attrs.get<std::string>(VISSIM_ATTR_LINKBEHAVETYPE, 0, ok));
257  myElemData["zuschlag1"].push_back(attrs.get<std::string>(VISSIM_ATTR_ZUSCHLAG1, 0, ok));
258  myElemData["zuschlag2"].push_back(attrs.get<std::string>(VISSIM_ATTR_ZUSCHLAG2, 0, ok));
259  }
260 
261  if (element == VISSIM_TAG_LANE) {
262  bool ok = true;
263  // appends empty element if no width found
264  // error ignored if name is empty
265  myElemData["width"].push_back(attrs.get<std::string>(VISSIM_ATTR_WIDTH, 0, ok, false));
266  }
267 
268  if (element == VISSIM_TAG_FROM) {
269  if (isConnector != true) {
270  isConnector = true;
271  }
272  bool ok = true;
273  std::vector<std::string> from(StringTokenizer(attrs.get<std::string>(
274  VISSIM_ATTR_LANE, 0, ok), " ").getVector());
275  myElemData["from_pos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, 0, ok));
276  myElemData["from_id"].push_back(from[0]);
277  myElemData["from_lane"].push_back(from[1]);
278  }
279 
280  if (element == VISSIM_TAG_TO) {
281  bool ok = true;
282  std::vector<std::string> to(StringTokenizer(attrs.get<std::string>(
283  VISSIM_ATTR_LANE, 0, ok), " ").getVector());
284  myElemData["to_pos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, 0, ok));
285  myElemData["to_id"].push_back(to[0]);
286  myElemData["to_lane"].push_back(to[1]);
287  }
288 
289  if (element == VISSIM_TAG_POINT3D) {
290  bool ok = true;
291  // create a <sep> separated string of coordinate data
292  std::string sep(" ");
293 
294  std::string posS(attrs.get<std::string>(VISSIM_ATTR_X, 0, ok));
295  posS += sep;
296  posS.append(attrs.get<std::string>(VISSIM_ATTR_Y, 0, ok));
297  // allow for no Z
298  std::string z(attrs.get<std::string>(VISSIM_ATTR_ZOFFSET, 0, ok, false));
299  if (z.length() > 0) {
300  posS += sep;
301  posS.append(z);
302  }
303  myElemData["pos"].push_back(posS);
304  }
305 
306 
307 }
308 
309 void
311  if (element == VISSIM_TAG_LINK && myHierarchyLevel == 3) {
312  //std::cout << "elemData len:" << myElemData.size() << std::endl;
313 
314  NIVissimClosedLanesVector clv; //FIXME -> clv einlesen
315  std::vector<int> assignedVehicles; //FIXME -> assignedVehicles einlesen
316  int id(TplConvert::_str2int(myElemData["id"].front()));
317 
318  PositionVector geom;
319  // convert all position coordinate strings to PositionVectors
320  while (!myElemData["pos"].empty()) {
321  std::vector<std::string> sPos_v(StringTokenizer(
322  myElemData["pos"].front(), " ").getVector());
323  myElemData["pos"].pop_front();
324  std::vector<SUMOReal> pos_v(3);
325 
326  // doing a transform with explicit hint on function signature
327  std::transform(sPos_v.begin(), sPos_v.end(), pos_v.begin(),
329  geom.push_back_noDoublePos(Position(pos_v[0], pos_v[1], pos_v[2]));
330  }
331  // FIXME: a length = 0 PosVec seems fatal -> segfault
332  SUMOReal length(geom.length());
333 
334  if (isConnector == false) {
335  // Add Edge
336  NIVissimEdge* edge = new NIVissimEdge(id,
337  myElemData["name"].front(),
338  myElemData["type"].front(),
339  (int)myElemData["width"].size(), // numLanes,
340  TplConvert::_str2SUMOReal(myElemData["zuschlag1"].front()),
341  TplConvert::_str2SUMOReal(myElemData["zuschlag2"].front()),
342  length, geom, clv);
343  NIVissimEdge::dictionary(id, edge);
344  if (id == 85 || id == 91) {
345  std::cout << id << "\n";
346  std::cout << myElemData["width"].size() << "\n";
347  std::cout << length << "\n";
348  std::cout << geom << "\n";
349  }
350  } else {
351  int numLanes = (int)myElemData["width"].size();
352  std::vector<int> laneVec(numLanes);
353  // Add Connector
354 
355  //NOTE: there should be only 1 lane number in XML
356  // subtraction of 1 as in readExtEdgePointDef()
357  laneVec[0] = TplConvert::_str2int(myElemData["from_lane"].front()) - 1;
358  // then count up, building lane number vector
359  for (std::vector<int>::iterator each = ++laneVec.begin(); each != laneVec.end(); ++each) {
360  *each = *(each - 1) + 1;
361  }
362 
363  NIVissimExtendedEdgePoint from_def(
364  TplConvert::_str2int(myElemData["from_id"].front()),
365  laneVec,
366  TplConvert::_str2SUMOReal(myElemData["from_pos"].front()),
367  assignedVehicles);
368 
369  //NOTE: there should be only 1 lane number in XML
370  // subtraction of 1 as in readExtEdgePointDef()
371  laneVec[0] = TplConvert::_str2int(myElemData["to_lane"].front()) - 1;
372  // then count up, building lane number vector
373  for (std::vector<int>::iterator each = ++laneVec.begin(); each != laneVec.end(); ++each) {
374  *each = *(each - 1) + 1;
375  }
376 
378  TplConvert::_str2int(myElemData["to_id"].front()),
379  laneVec,
380  TplConvert::_str2SUMOReal(myElemData["to_pos"].front()),
381  assignedVehicles);
382 
383  NIVissimConnection* connector = new
385  myElemData["name"].front(),
386  from_def, to_def,
387  geom, assignedVehicles, clv);
388 
389  NIVissimConnection::dictionary(id, connector);
390  }
391  // clear the element data
392  myElemData.clear();
393  //std::cout << "elemData len (clear):" << myElemData.size() << std::endl;
394  //std::cout.flush();
395  }
397 }
398 
399 
400 // ---------------------------------------------------------------------------
401 // definitions of NIVissimXMLHandler_Zuflussdefinition-methods
402 // ---------------------------------------------------------------------------
406  "vissim - file") {
407 }
408 
410 
411 void
413  // finding an actual flow
414  if (element == VISSIM_TAG_VEHICLE_INPUT) {
415  //parse all flows
416  bool ok = true;
417  std::string id = attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok);
418  std::string edgeid = attrs.get<std::string>(VISSIM_ATTR_LINK, 0, ok);
419  std::string name = attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false);
420 
422  name,
423  edgeid);
424  }
425 }
426 
427 // ---------------------------------------------------------------------------
428 // definitions of NIVissimXMLHandler_Parkplatzdefinition-methods
429 // ---------------------------------------------------------------------------
433  "vissim - file") {
434 }
435 
437 
438 void
440  // finding an actual parkinglot
441  if (element == VISSIM_TAG_PARKINGLOT) {
442  //parse all parkinglots
443  bool ok = true;
444  int id = attrs.get<int>(VISSIM_ATTR_NO, 0, ok);
445  int edgeid = attrs.get<int>(VISSIM_ATTR_INTLINK, 0, ok);
446  std::string name = attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false);
447  SUMOReal position = attrs.get<SUMOReal>(VISSIM_ATTR_POS, 0, ok);
448  std::vector<std::pair<int, int> > assignedVehicles; // (vclass, vwunsch)
449  //FIXME: vWunsch + Fahzeugklassen einlesen
450  // There can be s
451  std::vector<int> districts;
452  //FIXME: Parkplatzdefinition für mehrere Zonen implementieren
453  std::vector<SUMOReal> percentages;
454  districts.push_back(attrs.get<int>(VISSIM_ATTR_DISTRICT, 0, ok));
455  percentages.push_back(attrs.get<SUMOReal>(VISSIM_ATTR_PERCENTAGE, 0, ok));
456 
458  name,
459  districts,
460  percentages,
461  edgeid,
462  position,
463  assignedVehicles);
464  }
465 }
466 
467 
468 // ---------------------------------------------------------------------------
469 // definitions of NIVissimXMLHandler_Fahrzeugklassendefinition-methods
470 // ---------------------------------------------------------------------------
474  "vissim - file"),
475  myElemData(elemData),
476  myHierarchyLevel(0) {
477  myElemData.clear();
478 }
479 
481 
482 void
485 
486  if (element == VISSIM_TAG_VEHICLE_CLASS) {
487  bool ok = true;
488  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
489  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false));
490  std::string colorStr(attrs.get<std::string>(VISSIM_ATTR_COLOR, 0, ok));
491  for (size_t pos = colorStr.size() - 2; pos > 0; pos -= 2) {
492  colorStr.insert(pos, " ");
493  }
494  myElemData["color"].push_back(colorStr);
495  }
496  if (element == VISSIM_TAG_INTOBJECTREF) {
497  bool ok = true;
498  myElemData["types"].push_back(attrs.get<std::string>(VISSIM_ATTR_KEY, 0, ok));
499 
500 
501  }
502 }
503 
504 void
506  if (element == VISSIM_TAG_VEHICLE_CLASS && myHierarchyLevel == 3) {
507  RGBColor color;
508  std::istringstream iss(myElemData["color"].front());
509  std::vector<std::string> sCol_v(StringTokenizer(
510  myElemData["color"].front(), " ").getVector());
511  std::vector<int> myColorVector(sCol_v.size());
512  std::transform(sCol_v.begin(), sCol_v.end(), myColorVector.begin(),
514 
515  color = RGBColor((unsigned char)myColorVector[0],
516  (unsigned char)myColorVector[1],
517  (unsigned char)myColorVector[2],
518  (unsigned char)myColorVector[3]);
519  std::vector<int> types;
520  while (!myElemData["types"].empty()) {
521  types.push_back(TplConvert::_str2int(myElemData["types"].front()));
522  myElemData["types"].pop_front();
523  }
524 
526  myElemData["name"].front(),
527  color,
528  types);
529  myElemData.clear();
530  }
532 }
533 
534 // ---------------------------------------------------------------------------
535 // definitions of NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition-methods
536 // ---------------------------------------------------------------------------
540  "vissim - file"),
541  myElemData(elemData),
542  myHierarchyLevel(0) {
543  myElemData.clear();
544 }
545 
547 
548 void
551  if (element == VISSIM_TAG_SPEED_DIST) {
552  bool ok = true;
553  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
554  }
555 
556  if (element == VISSIM_TAG_DATAPOINT) {
557  bool ok = true;
558  std::string sep(" ");
559  std::string posS(attrs.get<std::string>(VISSIM_ATTR_X, 0, ok));
560  posS += sep;
561  posS.append(attrs.get<std::string>(VISSIM_ATTR_FX, 0, ok));
562  myElemData["points"].push_back(posS);
563 
564  }
565 
566 }
567 
568 void
570  if (element == VISSIM_TAG_SPEED_DIST && myHierarchyLevel == 3) {
571  PositionVector points;
572  while (!myElemData["points"].empty()) {
573  std::vector<std::string> sPos_v(StringTokenizer(
574  myElemData["points"].front(), " ").getVector());
575  myElemData["points"].pop_front();
576  std::vector<SUMOReal> pos_v(2);
577 
578  // doing a transform with explicit hint on function signature
579  std::transform(sPos_v.begin(), sPos_v.end(), pos_v.begin(),
581  points.push_back_noDoublePos(Position(pos_v[0], pos_v[1]));
582  }
584  myElemData["id"].front(),
585  new Distribution_Points(myElemData["id"].front(),
586  points));
587  myElemData.clear();
588  }
590 }
591 
592 // ---------------------------------------------------------------------------
593 // definitions of NIVissimXMLHandler_VWunschentscheidungsdefinition-methods
594 // ---------------------------------------------------------------------------
598  "vissim - file"),
599  myElemData(elemData),
600  myHierarchyLevel(0) {
601  myElemData.clear();
602 }
603 
605 
606 void
609  if (element == VISSIM_TAG_SPEED_DECISION) {
610  bool ok = true;
611  myElemData["name"].push_back(attrs.get<std::string>(VISSIM_ATTR_NAME, 0, ok, false));
612  //FIXME: 2 vWunsch in the xml file, but only 1 of them is set???
613  }
614 
615 }
616 
617 void
620 }
621 
622 
623 // ---------------------------------------------------------------------------
624 // definitions of NIVissimXMLHandler_Routenentscheidungsdefinition-methods
625 // ---------------------------------------------------------------------------
629  "vissim - file"),
630  myElemData(elemData),
631  myHierarchyLevel(0) {
632  myElemData.clear();
633 }
634 
636 
637 void
640  if (element == VISSIM_TAG_DECISION_STATIC) {
641  bool ok = true;
642  myElemData["startLink"].push_back(attrs.get<std::string>(VISSIM_ATTR_LINK, 0, ok));
643  myElemData["startPos"].push_back(attrs.get<std::string>(VISSIM_ATTR_POS, 0, ok));
644  }
645  if (element == VISSIM_TAG_ROUTE_STATIC) {
646  bool ok = true;
647  myElemData["destLink"].push_back(attrs.get<std::string>(VISSIM_ATTR_DESTLINK, 0, ok));
648  myElemData["destPos"].push_back(attrs.get<std::string>(VISSIM_ATTR_DESTPOS, 0, ok));
649  myElemData["id"].push_back(attrs.get<std::string>(VISSIM_ATTR_NO, 0, ok));
650  }
651  if (element == VISSIM_TAG_INTOBJECTREF) {
652  // bool ok = true;
653  }
654 
655 }
656 
657 void
660 }
661 
662 // ---------------------------------------------------------------------------
663 // definitions of NIVissimXMLHandler_ConflictArea-methods
664 // ---------------------------------------------------------------------------
668  "vissim - file") {}
669 
671 
672 void
674  // finding an actual flow
675  if (element == VISSIM_TAG_CA) {
676  //parse all flows
677  bool ok = true;
678  std::string status = attrs.get<std::string>(VISSIM_ATTR_STATUS, 0, ok);
679  //get only the conflict areas which were set in VISSIM
680  if (status != "PASSIVE") {
682  attrs.get<std::string>(VISSIM_ATTR_LINK1, 0, ok),
683  attrs.get<std::string>(VISSIM_ATTR_LINK2, 0, ok),
684  status);
685  }
686 
687  }
688 }
689 
690 
691 /* -------------------------------------------------------------------------
692  * NIImporter_Vissim::VissimSingleTypeParser-methods
693  * ----------------------------------------------------------------------- */
695  : myVissimParent(parent) {}
696 
697 
699 
700 
701 std::string
703  std::string tmp;
704  from >> tmp;
705  return StringUtils::to_lower_case(tmp);
706 }
707 
708 
709 
710 std::string
712  const std::string& excl) {
713  std::string myExcl = StringUtils::to_lower_case(excl);
714  std::string tmp = myRead(from);
715  if (tmp == "") {
716  return "DATAEND";
717  }
718  if (tmp != myExcl
719  &&
720  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
721  ) {
722  return "DATAEND";
723  }
724  return StringUtils::to_lower_case(tmp);
725 }
726 
727 
728 std::string
730  const std::vector<std::string>& excl) {
731  std::vector<std::string> myExcl;
732  std::vector<std::string>::const_iterator i;
733  for (i = excl.begin(); i != excl.end(); i++) {
734  std::string mes = StringUtils::to_lower_case(*i);
735  myExcl.push_back(mes);
736  }
737  std::string tmp = myRead(from);
738  if (tmp == "") {
739  return "DATAEND";
740  }
741 
742  bool equals = false;
743  for (i = myExcl.begin(); i != myExcl.end() && !equals; i++) {
744  if ((*i) == tmp) {
745  equals = true;
746  }
747  }
748  if (!equals
749  &&
750  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
751  ) {
752  return "DATAEND";
753  }
754  return StringUtils::to_lower_case(tmp);
755 }
756 
757 
758 std::string
760  const std::string& tag) {
761  std::string tmp;
762  if (tag == "") {
763  tmp = myRead(from);
764  } else {
765  tmp = tag;
766  }
767  if (tmp == "beschriftung") {
768  tmp = myRead(from);
769  if (tmp == "keine") {
770  from >> tmp;
771  }
772  tmp = myRead(from);
773  tmp = myRead(from);
774  }
775  return tmp;
776 }
777 
778 
779 Position
781  SUMOReal x, y;
782  from >> x; // type-checking is missing!
783  from >> y; // type-checking is missing!
784  return Position(x, y);
785 }
786 
787 
788 std::vector<int>
790  std::istream& from, const std::string& next) {
791  std::string tmp = readEndSecure(from);
792  std::vector<int> ret;
793  if (tmp == "alle") {
794  ret.push_back(-1);
795  return ret;
796  }
797  while (tmp != "DATAEND" && tmp != next) {
798  ret.push_back(TplConvert::_2int(tmp.c_str()));
799  tmp = readEndSecure(from);
800  }
801  return ret;
802 }
803 
804 
807  std::istream& from) {
808  std::string tag;
809  from >> tag; // "Strecke"
810  int edgeid;
811  from >> edgeid; // type-checking is missing!
812  from >> tag; // "Spuren"
813  std::vector<int> lanes;
814  while (tag != "bei") {
815  tag = readEndSecure(from);
816  if (tag != "bei") {
817  int lane = TplConvert::_2int(tag.c_str());
818  lanes.push_back(lane - 1);
819  }
820  }
821  SUMOReal position;
822  from >> position;
823  std::vector<int> dummy;
824  return NIVissimExtendedEdgePoint(edgeid, lanes, position, dummy);
825 }
826 
827 
828 std::string
830  std::string name;
831  from >> name;
832  if (name[0] == '"') {
833  while (name[name.length() - 1] != '"') {
834  std::string tmp;
835  from >> tmp;
836  name = name + " " + tmp;
837  }
838  name = name.substr(1, name.length() - 2);
839  }
840  return StringUtils::convertUmlaute(name);
841 }
842 
843 
844 void
846  const std::string& name) {
847  std::string tag;
848  while (tag != name) {
849  tag = myRead(from);
850  }
851 }
852 
853 bool
855  const std::string& name) {
856  std::string tag;
857  while (tag != name) {
858  tag = myRead(from);
859  }
860  while (tag != "DATAEND") {
861  tag = readEndSecure(from);
862  }
863  return true;
864 }
865 
866 
867 
868 /* -------------------------------------------------------------------------
869  * NIImporter_Vissim-methods
870  * ----------------------------------------------------------------------- */
872  : myNetBuilder(nb), myInputIsLegacyFormat(false) {
873  UNUSED_PARAMETER(file);
875  buildParsers();
876  myColorMap["blau"] = RGBColor(77, 77, 255, 255);
877  myColorMap["gelb"] = RGBColor::YELLOW;
878  myColorMap["grau"] = RGBColor::GREY;
879  myColorMap["lila"] = RGBColor::MAGENTA;
880  myColorMap["gruen"] = RGBColor::GREEN;
881  myColorMap["rot"] = RGBColor::RED;
882  myColorMap["schwarz"] = RGBColor::BLACK;
883  myColorMap["tuerkis"] = RGBColor::CYAN;
884  myColorMap["weiss"] = RGBColor::WHITE;
885  myColorMap["keine"] = RGBColor::WHITE;
886 }
887 
888 
889 
890 
910  for (ToParserMap::iterator i = myParsers.begin(); i != myParsers.end(); i++) {
911  delete(*i).second;
912  }
913 }
914 
915 
916 void
918  // load file contents
919  // try to open the file
920  std::ifstream strm(options.getString("vissim-file").c_str());
921  if (!strm.good()) {
922  WRITE_ERROR("The vissim-file '" + options.getString("vissim-file") + "' was not found.");
923  return;
924  }
925  if (!readContents(strm)) {
926  return;
927  }
928  postLoadBuild(options.getFloat("vissim.join-distance"));
929 }
930 
931 void
933  // Parse file
934  std::string file = options.getString("vissim-file");
935  // Create NIVissimXMLHandlers
936  NIVissimXMLHandler_Streckendefinition XMLHandler_Streckendefinition(elementData);
937  NIVissimXMLHandler_Zuflussdefinition XMLHandler_Zuflussdefinition;
938  //NIVissimXMLHandler_Parkplatzdefinition XMLHandler_Parkplatzdefinition;
939  NIVissimXMLHandler_Fahrzeugklassendefinition XMLHandler_Fahrzeugklassendefinition(elementData);
940  NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition XMLHandler_Geschwindigkeitsverteilung(elementData);
941  NIVissimXMLHandler_ConflictArea XMLHandler_ConflictAreas;
942  if (!FileHelpers::isReadable(file)) {
943  WRITE_ERROR("Could not open vissim-file '" + file + "'.");
944  return;
945  }
946 
947  // Strecken + Verbinder
948  XMLHandler_Streckendefinition.setFileName(file);
949  PROGRESS_BEGIN_MESSAGE("Parsing strecken+verbinder from vissim-file '" + file + "'");
950  if (!XMLSubSys::runParser(XMLHandler_Streckendefinition, file)) {
951  return;
952  }
954 
955  // Zuflüsse
956  XMLHandler_Zuflussdefinition.setFileName(file);
957  PROGRESS_BEGIN_MESSAGE("Parsing zuflüsse from vissim-file '" + file + "'");
958  if (!XMLSubSys::runParser(XMLHandler_Zuflussdefinition, file)) {
959  return;
960  }
962 
963  //Geschwindigkeitsverteilungen
964  XMLHandler_Geschwindigkeitsverteilung.setFileName(file);
965  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
966  if (!XMLSubSys::runParser(XMLHandler_Geschwindigkeitsverteilung, file)) {
967  return;
968  }
970 
971 
972  //Fahrzeugklassen
973  XMLHandler_Fahrzeugklassendefinition.setFileName(file);
974  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
975  if (!XMLSubSys::runParser(XMLHandler_Fahrzeugklassendefinition, file)) {
976  return;
977  }
979 
980  //Parkplätze
981  /*XMLHandler_Parkplatzdefinition.setFileName(file);
982  PROGRESS_BEGIN_MESSAGE("Parsing parkplätze from vissim-file '" + file + "'");
983  if (!XMLSubSys::runParser(XMLHandler_Parkplatzdefinition, file)) {
984  return;
985  }
986  PROGRESS_DONE_MESSAGE();*/
987 
988 
989  //Konfliktflächen
990  XMLHandler_ConflictAreas.setFileName(file);
991  PROGRESS_BEGIN_MESSAGE("Parsing conflict areas from vissim-file '" + file + "'");
992  if (!XMLSubSys::runParser(XMLHandler_ConflictAreas, file)) {
993  return;
994  }
996 
997  postLoadBuild(options.getFloat("vissim.join-distance"));
998 }
999 
1000 bool
1001 NIImporter_Vissim::admitContinue(const std::string& tag) {
1002  ToElemIDMap::const_iterator i = myKnownElements.find(tag);
1003  if (i == myKnownElements.end()) {
1004  return true;
1005  }
1006  myLastSecure = tag;
1007  return false;
1008 }
1009 
1010 
1011 bool
1012 NIImporter_Vissim::readContents(std::istream& strm) {
1013  // read contents
1014  bool ok = true;
1015  while (strm.good() && ok) {
1016  std::string tag;
1017  if (myLastSecure != "") {
1018  tag = myLastSecure;
1019  } else {
1020  strm >> tag;
1021  }
1022  myLastSecure = "";
1023  bool parsed = false;
1024  while (!parsed && strm.good() && ok) {
1025  ToElemIDMap::iterator i = myKnownElements.find(StringUtils::to_lower_case(tag));
1026  if (i != myKnownElements.end()) {
1027  ToParserMap::iterator j = myParsers.find((*i).second);
1028  if (j != myParsers.end()) {
1029  VissimSingleTypeParser* parser = (*j).second;
1030  ok = parser->parse(strm);
1031  parsed = true;
1032  }
1033  }
1034  if (!parsed) {
1035  std::string line;
1036  std::streamoff pos;
1037  do {
1038  pos = strm.tellg();
1039  getline(strm, line);
1040  } while (strm.good() && (line == "" || line[0] == ' ' || line[0] == '-'));
1041  if (!strm.good()) {
1042  return true;
1043  }
1044  strm.seekg(pos);
1045  strm >> tag;
1046  }
1047  }
1048  }
1049  return ok;
1050 }
1051 
1052 
1053 void
1055  // close the loading process
1059  // build district->connections map
1061  // build clusters around nodes
1062 // NIVissimNodeDef::buildNodeClusters();
1063  // build node clusters around traffic lights
1064 // NIVissimTL::buildNodeClusters();
1065 
1066  // when connections or disturbances are left, build nodes around them
1067 
1068  // try to assign connection clusters to nodes
1069  // only left connections will be processed in
1070  // buildConnectionClusters & join
1071 //30.4. brauchen wir noch! NIVissimNodeDef::dict_assignConnectionsToNodes();
1072 
1073  // build clusters of connections with the same direction and a similar position along the streets
1075  // check whether further nodes (connection clusters by now) must be added
1077 
1078  // join clusters when overlapping (different streets are possible)
1081 // NIVissimConnectionCluster::joinByDisturbances(offset);
1082 
1083 // NIVissimConnectionCluster::addTLs(offset);
1084 
1085  // build nodes from clusters
1088 
1089 // NIVissimNodeCluster::dict_recheckEdgeChanges();
1095  if (OptionsCont::getOptions().getBool("vissim.report-unset-speeds")) {
1097  }
1103 }
1104 
1105 
1106 void
1108  myKnownElements["kennung"] = VE_Kennungszeile;
1109  myKnownElements["zufallszahl"] = VE_Startzufallszahl;
1110  myKnownElements["simulationsdauer"] = VE_Simdauer;
1111  myKnownElements["startuhrzeit"] = VE_Startuhrzeit;
1112  myKnownElements["simulationsrate"] = VE_SimRate;
1113  myKnownElements["zeitschritt"] = VE_Zeitschrittfaktor;
1114  myKnownElements["linksverkehr"] = VE_Linksverkehr;
1115  myKnownElements["dynuml"] = VE_DynUml;
1117  myKnownElements["gelbverhalten"] = VE_Gelbverhaltendefinition;
1119  myKnownElements["verbindung"] = VE_Verbindungsdefinition;
1120  myKnownElements["richtungsentscheidung"] = VE_Richtungsentscheidungsdefinition;
1121  myKnownElements["routenentscheidung"] = VE_Routenentscheidungsdefinition;
1122  myKnownElements["vwunschentscheidung"] = VE_VWunschentscheidungsdefinition;
1123  myKnownElements["langsamfahrbereich"] = VE_Langsamfahrbereichdefinition;
1125  myKnownElements["fahrzeugtyp"] = VE_Fahrzeugtypdefinition;
1126  myKnownElements["fahrzeugklasse"] = VE_Fahrzeugklassendefinition;
1136  myKnownElements["wunschbeschleunigung"] = VE_Wunschbeschleunigungskurvedefinition;
1139  myKnownElements["querverkehrsstoerung"] = VE_Querverkehrsstoerungsdefinition;
1141  myKnownElements["signalgruppe"] = VE_Signalgruppendefinition;
1142  myKnownElements["signalgeber"] = VE_Signalgeberdefinition;
1143  myKnownElements["lsakopplung"] = VE_LSAKopplungdefinition;
1145  myKnownElements["haltestelle"] = VE_Haltestellendefinition;
1147  myKnownElements["stopschild"] = VE_Stopschilddefinition;
1151  myKnownElements["querschnittsmessung"] = VE_Querschnittsmessungsdefinition;
1152  myKnownElements["stauzaehler"] = VE_Stauzaehlerdefinition;
1153  myKnownElements["auswertung"] = VE_Auswertungsdefinition;
1156  myKnownElements["parkplatz"] = VE_Parkplatzdefinition;
1159  myKnownElements["netzobjekt"] = VE_Netzobjektdefinition;
1160  myKnownElements["richtungspfeil"] = VE_Richtungspfeildefinition;
1162  myKnownElements["fahrverhalten"] = VE_Fahrverhaltendefinition;
1163  myKnownElements["fahrtverlaufdateien"] = VE_Fahrtverlaufdateien;
1164  myKnownElements["emission"] = VE_Emission;
1166  myKnownElements["streckentyp"] = VE_Streckentypdefinition;
1167  myKnownElements["kantensperrung"] = VE_Kantensperrung;
1169 
1170 
1171  myKnownElements["advance"] = VE_DUMMY;
1172  myKnownElements["temperatur"] = VE_DUMMY;
1173 
1174 }
1175 
1176 
1177 
1178 void
1184  myParsers[VE_DynUml] =
1258 
1301 
1302 }
1303 
1304 
1305 
1306 /****************************************************************************/
1307 
static void clearDict()
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 SUMOReal _str2SUMOReal(const std::string &sData)
Definition: TplConvert.h:296
static bool dictionary(int id, const std::string &name, const RGBColor &color, std::vector< int > &types)
static void dict_buildNBEdgeConnections(NBEdgeCont &ec)
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:58
static void joinBySameEdges(SUMOReal offset)
Tries to joind clusters participating within a node This is done by joining clusters which overlap...
NIVissimXMLHandler_Streckendefinition(nodeMap &elemData)
Constructor.
static const RGBColor WHITE
Definition: RGBColor.h:196
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
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static StringBijection< int >::Entry vissimAttrs[]
The names of VISSIM-XML attributes (for passing to GenericSAXHandler)
static bool dictionary(const std::string &type, const std::string &id, Distribution *d)
static void clearDict()
Importer for networks stored in Vissim format.
VissimSingleTypeParser(NIImporter_Vissim &parent)
Constructor.
virtual bool parse(std::istream &from)=0
Parses a single data type. Returns whether no error occured.
bool readContents(std::istream &strm)
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
static const RGBColor BLACK
Definition: RGBColor.h:197
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:114
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
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:69
A temporary storage for edges imported from Vissim.
Definition: NIVissimEdge.h:61
void loadXML(const OptionsCont &options, NBNetBuilder &nb)
ToParserMap myParsers
Parsers by element id.
static void dict_assignToEdges()
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void insertKnownElements()
adds name-to-id - relationships of known elements into myKnownElements
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:190
static const RGBColor GREY
Definition: RGBColor.h:198
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
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:46
NBEdgeCont & getEdgeCont()
Returns the edge container.
Definition: NBNetBuilder.h:154
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
static int _str2int(const std::string &sData)
Definition: TplConvert.h:128
static bool dict_SetSignals(NBTrafficLightLogicCont &tlc, NBEdgeCont &ec)
Definition: NIVissimTL.cpp:377
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:194
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:202
Position getPosition(std::istream &from)
returns the 2d-position saved as next within the stream
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;.
std::string readName(std::istream &from)
Reads the structures name We cannot use the "<<" operator, as names may contain more than one word wh...
void postLoadBuild(SUMOReal offset)
static std::string convertUmlaute(std::string str)
Converts german "Umlaute" to their latin-version.
Definition: StringUtils.cpp:95
static bool dictionary(int id, const std::string &name, const std::vector< int > &districts, const std::vector< SUMOReal > &percentages, int edgeid, SUMOReal position, const std::vector< std::pair< int, int > > &assignedVehicles)
Inserts the connection into the dictionary after building it.
std::vector< std::string > getVector()
void buildParsers()
adds id-to-parser - relationships of elements to parse into myParsers
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
static void clearDict()
Clears the dictionary.
SUMOReal length() const
Returns the length.
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:67
static const RGBColor YELLOW
Definition: RGBColor.h:192
static int _2int(const E *const data)
Definition: TplConvert.h:114
static const RGBColor RED
Definition: RGBColor.h:189
static const RGBColor CYAN
Definition: RGBColor.h:193
std::map< std::string, std::list< std::string > > nodeMap
NIImporter_Vissim(NBNetBuilder &nb, const std::string &file)
constructor
NBNodeCont & getNodeCont()
Returns the node container.
Definition: NBNetBuilder.h:162
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Instance responsible for building networks.
Definition: NBNetBuilder.h:113
A storage for options typed value containers)
Definition: OptionsCont.h:108
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 the traffic light logics container.
Definition: NBNetBuilder.h:178
static void buildNBNodes(NBNodeCont &nc)
static void clearDict()
Definition: NIVissimTL.cpp:365
static bool dictionary(int id, const std::string &name, const std::string &type, int noLanes, SUMOReal zuschlag1, SUMOReal zuschlag2, SUMOReal length, const PositionVector &geom, const NIVissimClosedLanesVector &clv)
Adds the described item to the dictionary Builds the edge first.
#define SUMOReal
Definition: config.h:213
static void dict_SetDisturbances()
void push_back_noDoublePos(const Position &p)
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
NBNetBuilder & myNetBuilder
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:203
std::string myLastSecure
static int _strHex2int(const std::string &sData)
Definition: TplConvert.h:151
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
NBDistrictCont & getDistrictCont()
Returns the districts container.
Definition: NBNetBuilder.h:186
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
bool admitContinue(const std::string &tag)
static void dict_buildNBEdges(NBDistrictCont &dc, NBNodeCont &nc, NBEdgeCont &ec, SUMOReal offset)
Builds NBEdges from the VissimEdges within the dictionary.
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.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.