SUMO - Simulation of Urban MObility
NLHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
12 // The XML-Handler for network loading
13 /****************************************************************************/
14 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
15 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
16 /****************************************************************************/
17 //
18 // This file is part of SUMO.
19 // SUMO is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 /****************************************************************************/
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include "NLHandler.h"
36 #include "NLEdgeControlBuilder.h"
38 #include "NLDetectorBuilder.h"
39 #include "NLTriggerBuilder.h"
43 #include <utils/common/SUMOTime.h>
46 #include <utils/common/RGBColor.h>
48 #include <microsim/MSGlobals.h>
49 #include <microsim/MSLane.h>
50 #include <microsim/MSJunction.h>
57 #include <utils/shapes/Shape.h>
59 
60 #ifdef CHECK_MEMORY_LEAKS
61 #include <foreign/nvwa/debug_new.h>
62 #endif // CHECK_MEMORY_LEAKS
63 
64 
65 // ===========================================================================
66 // method definitions
67 // ===========================================================================
68 NLHandler::NLHandler(const std::string& file, MSNet& net,
69  NLDetectorBuilder& detBuilder,
70  NLTriggerBuilder& triggerBuilder,
71  NLEdgeControlBuilder& edgeBuilder,
72  NLJunctionControlBuilder& junctionBuilder) :
73  MSRouteHandler(file, true),
74  myNet(net), myActionBuilder(net),
75  myCurrentIsInternalToSkip(false),
76  myDetectorBuilder(detBuilder), myTriggerBuilder(triggerBuilder),
77  myEdgeControlBuilder(edgeBuilder), myJunctionControlBuilder(junctionBuilder),
78  myAmInTLLogicMode(false), myCurrentIsBroken(false),
79  myHaveWarnedAboutDeprecatedLanes(false),
80  myLastParameterised(0),
81  myHaveSeenInternalEdge(false),
82  myHaveSeenNeighs(false),
83  myLefthand(false),
84  myNetworkVersion(0),
85  myNetIsLoaded(false) {
86 }
87 
88 
90 
91 
92 void
94  const SUMOSAXAttributes& attrs) {
95  try {
96  switch (element) {
97  case SUMO_TAG_NET: {
98  bool ok;
99  myLefthand = attrs.getOpt<bool>(SUMO_ATTR_LEFTHAND, 0, ok, false);
100  myNetworkVersion = attrs.get<SUMOReal>(SUMO_ATTR_VERSION, 0, ok, false);
101  break;
102  }
103  case SUMO_TAG_EDGE:
104  beginEdgeParsing(attrs);
105  break;
106  case SUMO_TAG_LANE:
107  addLane(attrs);
108  break;
109  case SUMO_TAG_NEIGH:
111  myHaveSeenNeighs = true;
112  break;
113  case SUMO_TAG_JUNCTION:
114  openJunction(attrs);
115  initJunctionLogic(attrs);
116  break;
117  case SUMO_TAG_PHASE:
118  addPhase(attrs);
119  break;
120  case SUMO_TAG_CONNECTION:
121  addConnection(attrs);
122  break;
123  case SUMO_TAG_TLLOGIC:
124  initTrafficLightLogic(attrs);
125  break;
126  case SUMO_TAG_REQUEST:
127  addRequest(attrs);
128  break;
129  case SUMO_TAG_WAUT:
130  openWAUT(attrs);
131  break;
133  addWAUTSwitch(attrs);
134  break;
136  addWAUTJunction(attrs);
137  break;
138  case SUMO_TAG_E1DETECTOR:
140  addE1Detector(attrs);
141  break;
142  case SUMO_TAG_E2DETECTOR:
144  addE2Detector(attrs);
145  break;
146  case SUMO_TAG_E3DETECTOR:
148  beginE3Detector(attrs);
149  break;
150  case SUMO_TAG_DET_ENTRY:
151  addE3Entry(attrs);
152  break;
153  case SUMO_TAG_DET_EXIT:
154  addE3Exit(attrs);
155  break;
157  addInstantE1Detector(attrs);
158  break;
159  case SUMO_TAG_VSS:
161  break;
162  case SUMO_TAG_CALIBRATOR:
164  break;
165  case SUMO_TAG_REROUTER:
167  break;
168  case SUMO_TAG_BUS_STOP:
169  case SUMO_TAG_TRAIN_STOP:
172  break;
173  case SUMO_TAG_ACCESS:
175  break;
178  break;
179  case SUMO_TAG_VTYPEPROBE:
180  addVTypeProbeDetector(attrs);
181  break;
182  case SUMO_TAG_ROUTEPROBE:
183  addRouteProbeDetector(attrs);
184  break;
187  break;
190  break;
191  case SUMO_TAG_TIMEDEVENT:
193  break;
194  case SUMO_TAG_VAPORIZER:
196  break;
197  case SUMO_TAG_LOCATION:
198  setLocation(attrs);
199  break;
200  case SUMO_TAG_TAZ:
201  addDistrict(attrs);
202  break;
203  case SUMO_TAG_TAZSOURCE:
204  addDistrictEdge(attrs, true);
205  break;
206  case SUMO_TAG_TAZSINK:
207  addDistrictEdge(attrs, false);
208  break;
209  case SUMO_TAG_ROUNDABOUT:
210  addRoundabout(attrs);
211  break;
212  case SUMO_TAG_TYPE: {
213  bool ok = true;
214  myCurrentTypeID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
215  break;
216  }
217  case SUMO_TAG_RESTRICTION: {
218  bool ok = true;
219  const SUMOVehicleClass svc = getVehicleClassID(attrs.get<std::string>(SUMO_ATTR_VCLASS, myCurrentTypeID.c_str(), ok));
220  const SUMOReal speed = attrs.get<SUMOReal>(SUMO_ATTR_SPEED, myCurrentTypeID.c_str(), ok);
221  if (ok) {
222  myNet.addRestriction(myCurrentTypeID, svc, speed);
223  }
224  break;
225  }
226  default:
227  break;
228  }
229  } catch (InvalidArgument& e) {
230  WRITE_ERROR(e.what());
231  }
232  MSRouteHandler::myStartElement(element, attrs);
233  if (element == SUMO_TAG_PARAM) {
234  addParam(attrs);
235  }
236 }
237 
238 
239 void
241  switch (element) {
242  case SUMO_TAG_EDGE:
243  closeEdge();
244  break;
245  case SUMO_TAG_JUNCTION:
246  if (!myCurrentIsBroken) {
247  try {
250  } catch (InvalidArgument& e) {
251  WRITE_ERROR(e.what());
252  }
253  }
254  break;
255  case SUMO_TAG_TLLOGIC:
256  try {
258  } catch (InvalidArgument& e) {
259  WRITE_ERROR(e.what());
260  }
261  myAmInTLLogicMode = false;
262  break;
263  case SUMO_TAG_WAUT:
264  closeWAUT();
265  break;
266  case SUMO_TAG_E3DETECTOR:
268  endE3Detector();
269  break;
270  case SUMO_TAG_NET:
271  // build junction graph
272  for (JunctionGraph::iterator it = myJunctionGraph.begin(); it != myJunctionGraph.end(); ++it) {
273  MSEdge* edge = MSEdge::dictionary(it->first);
274  MSJunction* from = myJunctionControlBuilder.retrieve(it->second.first);
275  MSJunction* to = myJunctionControlBuilder.retrieve(it->second.second);
276  if (edge != 0 && from != 0 && to != 0) {
277  edge->setJunctions(from, to);
278  from->addOutgoing(edge);
279  to->addIncoming(edge);
280  }
281  }
282  myNetIsLoaded = true;
283  break;
284  default:
285  break;
286  }
288  if (element != SUMO_TAG_PARAM) {
290  }
291 }
292 
293 
294 
295 // ---- the root/edge - element
296 void
298  bool ok = true;
299  myCurrentIsBroken = false;
300  // get the id, report an error if not given or empty...
301  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
302  if (!ok) {
303  myCurrentIsBroken = true;
304  return;
305  }
306  // omit internal edges if not wished
307  if (id[0] == ':') {
308  myHaveSeenInternalEdge = true;
311  return;
312  }
313  }
314  if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
315  myJunctionGraph[id] = std::make_pair(
316  attrs.get<std::string>(SUMO_ATTR_FROM, 0, ok),
317  attrs.get<std::string>(SUMO_ATTR_TO, 0, ok));
318  } else {
319  // must be an internal edge
320  std::string junctionID = SUMOXMLDefinitions::getJunctionIDFromInternalEdge(id);
321  myJunctionGraph[id] = std::make_pair(junctionID, junctionID);
322  }
324  // parse the function
325  const SumoXMLEdgeFunc func = attrs.getEdgeFunc(ok);
326  if (!ok) {
327  WRITE_ERROR("Edge '" + id + "' has an invalid type.");
328  myCurrentIsBroken = true;
329  return;
330  }
331  // interpret the function
333  switch (func) {
334  case EDGEFUNC_NORMAL:
335  funcEnum = MSEdge::EDGEFUNCTION_NORMAL;
336  break;
337  case EDGEFUNC_CONNECTOR:
338  case EDGEFUNC_SINK:
339  case EDGEFUNC_SOURCE:
341  break;
342  case EDGEFUNC_INTERNAL:
344  break;
345  case EDGEFUNC_CROSSING:
347  break;
350  break;
351  }
352  // get the street name
353  const std::string streetName = attrs.getOpt<std::string>(SUMO_ATTR_NAME, id.c_str(), ok, "");
354  // get the edge type
355  const std::string edgeType = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, "");
356  // get the edge priority (only for visualization)
357  const int priority = attrs.getOpt<int>(SUMO_ATTR_PRIORITY, id.c_str(), ok, -1); // default taken from netbuild/NBFrame option 'default.priority'
358  if (!ok) {
359  myCurrentIsBroken = true;
360  return;
361  }
362  //
363  try {
364  myEdgeControlBuilder.beginEdgeParsing(id, funcEnum, streetName, edgeType, priority);
365  } catch (InvalidArgument& e) {
366  WRITE_ERROR(e.what());
367  myCurrentIsBroken = true;
368  }
369 
370  if (funcEnum == MSEdge::EDGEFUNCTION_CROSSING) {
371  //get the crossingEdges attribute (to implement the other side of the road pushbutton)
372  const std::string crossingEdges = attrs.getOpt<std::string>(SUMO_ATTR_CROSSING_EDGES, id.c_str(), ok, "");
373  if (!crossingEdges.empty()) {
374  std::vector<std::string> crossingEdgesVector;
375  StringTokenizer edges(crossingEdges);
376  while (edges.hasNext()) {
377  crossingEdgesVector.push_back(edges.next());
378  }
379  myEdgeControlBuilder.addCrossingEdges(crossingEdgesVector);
380  }
381  }
382 }
383 
384 
385 void
387  // omit internal edges if not wished and broken edges
389  return;
390  }
391  try {
393  MSEdge::dictionary(e->getID(), e);
394  } catch (InvalidArgument& e) {
395  WRITE_ERROR(e.what());
396  }
397 }
398 
399 
400 // ---- the root/edge/lanes/lane - element
401 void
403  // omit internal edges if not wished and broken edges
405  return;
406  }
407  bool ok = true;
408  // get the id, report an error if not given or empty...
409  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
410  if (!ok) {
411  myCurrentIsBroken = true;
412  return;
413  }
414  const SUMOReal maxSpeed = attrs.get<SUMOReal>(SUMO_ATTR_SPEED, id.c_str(), ok);
415  const SUMOReal length = attrs.get<SUMOReal>(SUMO_ATTR_LENGTH, id.c_str(), ok);
416  const std::string allow = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, id.c_str(), ok, "", false);
417  const std::string disallow = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, id.c_str(), ok, "");
418  const SUMOReal width = attrs.getOpt<SUMOReal>(SUMO_ATTR_WIDTH, id.c_str(), ok, SUMO_const_laneWidth);
419  const PositionVector shape = attrs.get<PositionVector>(SUMO_ATTR_SHAPE, id.c_str(), ok);
420  const int index = attrs.get<int>(SUMO_ATTR_INDEX, id.c_str(), ok);
421  if (shape.size() < 2) {
422  WRITE_ERROR("Shape of lane '" + id + "' is broken.\n Can not build according edge.");
423  myCurrentIsBroken = true;
424  return;
425  }
426  const SVCPermissions permissions = parseVehicleClasses(allow, disallow);
427  if (permissions != SVCAll) {
429  }
430  myCurrentIsBroken |= !ok;
431  if (!myCurrentIsBroken) {
432  try {
433  MSLane* lane = myEdgeControlBuilder.addLane(id, maxSpeed, length, shape, width, permissions, index);
434  // insert the lane into the lane-dictionary, checking
435  if (!MSLane::dictionary(id, lane)) {
436  delete lane;
437  WRITE_ERROR("Another lane with the id '" + id + "' exists.");
438  myCurrentIsBroken = true;
439  }
440  myLastParameterised = lane;
441  } catch (InvalidArgument& e) {
442  WRITE_ERROR(e.what());
443  }
444  }
445 }
446 
447 
448 // ---- the root/junction - element
449 void
451  myCurrentIsBroken = false;
452  bool ok = true;
453  // get the id, report an error if not given or empty...
454  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
455  if (!ok) {
456  myCurrentIsBroken = true;
457  return;
458  }
459  PositionVector shape;
460  if (attrs.hasAttribute(SUMO_ATTR_SHAPE)) {
461  // inner junctions have no shape
462  shape = attrs.getOpt<PositionVector>(SUMO_ATTR_SHAPE, id.c_str(), ok, PositionVector());
463  if (shape.size() > 2) {
464  shape.closePolygon();
465  }
466  }
467  SUMOReal x = attrs.get<SUMOReal>(SUMO_ATTR_X, id.c_str(), ok);
468  SUMOReal y = attrs.get<SUMOReal>(SUMO_ATTR_Y, id.c_str(), ok);
469  bool typeOK = true;
470  SumoXMLNodeType type = attrs.getNodeType(typeOK);
471  if (!typeOK) {
472  WRITE_ERROR("An unknown or invalid junction type occured in junction '" + id + "'.");
473  ok = false;
474  }
475  std::string key = attrs.getOpt<std::string>(SUMO_ATTR_KEY, id.c_str(), ok, "");
476  // incoming lanes
477  std::vector<MSLane*> incomingLanes;
478  parseLanes(id, attrs.getStringSecure(SUMO_ATTR_INCLANES, ""), incomingLanes, ok);
479  // internal lanes
480  std::vector<MSLane*> internalLanes;
481 #ifdef HAVE_INTERNAL_LANES
483  parseLanes(id, attrs.getStringSecure(SUMO_ATTR_INTLANES, ""), internalLanes, ok);
484  }
485 #endif
486  if (!ok) {
487  myCurrentIsBroken = true;
488  } else {
489  try {
490  myJunctionControlBuilder.openJunction(id, key, type, x, y, shape, incomingLanes, internalLanes);
491  } catch (InvalidArgument& e) {
492  WRITE_ERROR(e.what() + std::string("\n Can not build according junction."));
493  myCurrentIsBroken = true;
494  }
495  }
496 }
497 
498 
499 void
500 NLHandler::parseLanes(const std::string& junctionID,
501  const std::string& def, std::vector<MSLane*>& into, bool& ok) {
502  StringTokenizer st(def);
503  while (ok && st.hasNext()) {
504  std::string laneID = st.next();
505  MSLane* lane = MSLane::dictionary(laneID);
506  if (!MSGlobals::gUsingInternalLanes && laneID[0] == ':') {
507  continue;
508  }
509  if (lane == 0) {
510  WRITE_ERROR("An unknown lane ('" + laneID + "') was tried to be set as incoming to junction '" + junctionID + "'.");
511  ok = false;
512  continue;
513  }
514  into.push_back(lane);
515  }
516 }
517 // ----
518 
519 void
521  bool ok = true;
522  const std::string key = attrs.get<std::string>(SUMO_ATTR_KEY, 0, ok);
523  // circumventing empty string test
524  const std::string val = attrs.hasAttribute(SUMO_ATTR_VALUE) ? attrs.getString(SUMO_ATTR_VALUE) : "";
525  if (myLastParameterised != 0) {
527  }
528  // set
529  if (ok && myAmInTLLogicMode) {
530  assert(key != "");
531  assert(val != "");
533  }
534 }
535 
536 
537 void
539  myCurrentIsBroken = false;
540  bool ok = true;
541  // get the id, report an error if not given or empty...
542  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
543  if (!ok) {
544  myCurrentIsBroken = true;
545  return;
546  }
547  SUMOTime t = attrs.getOptSUMOTimeReporting(SUMO_ATTR_REF_TIME, id.c_str(), ok, 0);
548  std::string pro = attrs.get<std::string>(SUMO_ATTR_START_PROG, id.c_str(), ok);
549  if (!ok) {
550  myCurrentIsBroken = true;
551  }
552  if (!myCurrentIsBroken) {
553  myCurrentWAUTID = id;
554  try {
556  } catch (InvalidArgument& e) {
557  WRITE_ERROR(e.what());
558  myCurrentIsBroken = true;
559  }
560  }
561 }
562 
563 
564 void
566  bool ok = true;
568  std::string to = attrs.get<std::string>(SUMO_ATTR_TO, myCurrentWAUTID.c_str(), ok);
569  if (!ok) {
570  myCurrentIsBroken = true;
571  }
572  if (!myCurrentIsBroken) {
573  try {
575  } catch (InvalidArgument& e) {
576  WRITE_ERROR(e.what());
577  myCurrentIsBroken = true;
578  }
579  }
580 }
581 
582 
583 void
585  bool ok = true;
586  std::string wautID = attrs.get<std::string>(SUMO_ATTR_WAUT_ID, 0, ok);
587  std::string junctionID = attrs.get<std::string>(SUMO_ATTR_JUNCTION_ID, 0, ok);
588  std::string procedure = attrs.getOpt<std::string>(SUMO_ATTR_PROCEDURE, 0, ok, "");
589  bool synchron = attrs.getOpt<bool>(SUMO_ATTR_SYNCHRON, 0, ok, false);
590  if (!ok) {
591  myCurrentIsBroken = true;
592  }
593  try {
594  if (!myCurrentIsBroken) {
595  myJunctionControlBuilder.getTLLogicControlToUse().addWAUTJunction(wautID, junctionID, procedure, synchron);
596  }
597  } catch (InvalidArgument& e) {
598  WRITE_ERROR(e.what());
599  myCurrentIsBroken = true;
600  }
601 }
602 
603 
604 void
606  if (myCurrentIsBroken) {
607  return;
608  }
609  bool ok = true;
610  int request = attrs.get<int>(SUMO_ATTR_INDEX, 0, ok);
611  bool cont = false;
612 #ifdef HAVE_INTERNAL_LANES
613  cont = attrs.getOpt<bool>(SUMO_ATTR_CONT, 0, ok, false);
614 #endif
615  std::string response = attrs.get<std::string>(SUMO_ATTR_RESPONSE, 0, ok);
616  std::string foes = attrs.get<std::string>(SUMO_ATTR_FOES, 0, ok);
617  if (!ok) {
618  return;
619  }
620  // store received information
621  if (request >= 0 && response.length() > 0) {
622  try {
623  myJunctionControlBuilder.addLogicItem(request, response, foes, cont);
624  } catch (InvalidArgument& e) {
625  WRITE_ERROR(e.what());
626  }
627  }
628 }
629 
630 
631 void
633  if (myCurrentIsBroken) {
634  return;
635  }
636  bool ok = true;
637  // we either a have a junction or a legacy network with ROWLogic
638  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
639  if (ok) {
641  }
642 }
643 
644 
645 void
647  myAmInTLLogicMode = true;
648  bool ok = true;
649  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
650  std::string programID = attrs.getOpt<std::string>(SUMO_ATTR_PROGRAMID, id.c_str(), ok, "<unknown>");
652  std::string typeS;
653  if (myJunctionControlBuilder.getTLLogicControlToUse().get(id, programID) == 0) {
654  // SUMO_ATTR_TYPE is not needed when only modifying the offst of an
655  // existing program
656  typeS = attrs.get<std::string>(SUMO_ATTR_TYPE, 0, ok);
657  if (SUMOXMLDefinitions::TrafficLightTypes.hasString(typeS)) {
659  } else {
660  WRITE_ERROR("Traffic light '" + id + "' has unknown type '" + typeS + "'");
661  }
662  }
663  //
664  SUMOTime offset = attrs.getOptSUMOTimeReporting(SUMO_ATTR_OFFSET, id.c_str(), ok, 0);
665  if (!ok) {
666  return;
667  }
668  myJunctionControlBuilder.initTrafficLightLogic(id, programID, type, offset);
669 }
670 
671 
672 void
674  // try to get the phase definition
675  bool ok = true;
676  std::string state = attrs.get<std::string>(SUMO_ATTR_STATE, 0, ok);
677  if (!ok) {
678  return;
679  }
680  // try to get the phase duration
682  if (duration == 0) {
684  + " for tlLogic '" + myJunctionControlBuilder.getActiveKey()
685  + "' program '" + myJunctionControlBuilder.getActiveSubKey() + "' is zero.");
686  return;
687  }
688  // if the traffic light is an actuated traffic light, try to get
689  // the minimum and maximum durations
690  SUMOTime minDuration = attrs.getOptSUMOTimeReporting(
692  SUMOTime maxDuration = attrs.getOptSUMOTimeReporting(
694 
695 
696  //SOTL attributes
697  //If the type attribute is not present, the parsed phase is of type "undefined" (MSPhaseDefinition constructor),
698  //in this way SOTL traffic light logic can recognize the phase as unsuitable or decides other
699  //behaviors. See SOTL traffic light logic implementations.
700  if (attrs.hasAttribute(SUMO_ATTR_TYPE)) {
701  bool ok = true;
702  std::string phaseTypeString;
703  bool transient_notdecisional_bit;
704  bool commit_bit;
705  MSPhaseDefinition::LaneIdVector laneIdVector;
706  try {
707  phaseTypeString = attrs.get<std::string>(SUMO_ATTR_TYPE, "phase", ok, false);
708  } catch (EmptyData&) {
709  MsgHandler::getWarningInstance()->inform("Empty type definition. Assuming phase type as SUMOSOTL_TagAttrDefinitions::SOTL_ATTL_TYPE_TRANSIENT");
710  transient_notdecisional_bit = false;
711  }
712  if (phaseTypeString.find("decisional") != std::string::npos) {
713  transient_notdecisional_bit = false;
714  } else if (phaseTypeString.find("transient") != std::string::npos) {
715  transient_notdecisional_bit = true;
716  } else {
717  MsgHandler::getWarningInstance()->inform("SOTL_ATTL_TYPE_DECISIONAL nor SOTL_ATTL_TYPE_TRANSIENT. Assuming phase type as SUMOSOTL_TagAttrDefinitions::SOTL_ATTL_TYPE_TRANSIENT");
718  transient_notdecisional_bit = false;
719  }
720  commit_bit = (phaseTypeString.find("commit") != std::string::npos);
721 
722  if (phaseTypeString.find("target") != std::string::npos) {
723  std::string delimiter(" ,;");
724  //Phase declared as target, getting targetLanes attribute
725  try {
727  std::string targetLanesString = attrs.getStringSecure(SUMO_ATTR_TARGETLANE, "");
728  //TOKENIZING
729  MSPhaseDefinition::LaneIdVector targetLanesVector;
730  //Skip delimiters at the beginning
731  std::string::size_type firstPos = targetLanesString.find_first_not_of(delimiter, 0);
732  //Find first "non-delimiter".
733  std::string::size_type pos = targetLanesString.find_first_of(delimiter, firstPos);
734 
735  while (std::string::npos != pos || std::string::npos != firstPos) {
736  //Found a token, add it to the vector
737  targetLanesVector.push_back(targetLanesString.substr(firstPos, pos - firstPos));
738 
739  //Skip delimiters
740  firstPos = targetLanesString.find_first_not_of(delimiter, pos);
741 
742  //Find next "non-delimiter"
743  pos = targetLanesString.find_first_of(delimiter, firstPos);
744  }
745  //Adding the SOTL parsed phase to have a new MSPhaseDefinition that is SOTL compliant for target phases
746  myJunctionControlBuilder.addPhase(duration, state, minDuration, maxDuration, transient_notdecisional_bit, commit_bit, targetLanesVector);
747  } catch (EmptyData&) {
748  MsgHandler::getErrorInstance()->inform("Missing targetLane definition for the target phase.");
749  return;
750  }
751  } else {
752  //Adding the SOTL parsed phase to have a new MSPhaseDefinition that is SOTL compliant for non target phases
753  myJunctionControlBuilder.addPhase(duration, state, minDuration, maxDuration, transient_notdecisional_bit, commit_bit);
754  }
755  } else {
756  //Adding the standard parsed phase to have a new MSPhaseDefinition
757 
758  myJunctionControlBuilder.addPhase(duration, state, minDuration, maxDuration);
759  }
760 }
761 
762 
763 void
765  bool ok = true;
766  // get the id, report an error if not given or empty...
767  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
768  if (!ok) {
769  return;
770  }
771  const SUMOTime frequency = attrs.getSUMOTimeReporting(SUMO_ATTR_FREQUENCY, id.c_str(), ok);
772  const SUMOReal position = attrs.get<SUMOReal>(SUMO_ATTR_POSITION, id.c_str(), ok);
773  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, id.c_str(), ok, false);
774  const std::string vTypes = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id.c_str(), ok, "");
775  const std::string lane = attrs.get<std::string>(SUMO_ATTR_LANE, id.c_str(), ok);
776  const std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, id.c_str(), ok);
777  if (!ok) {
778  return;
779  }
780  try {
781  myDetectorBuilder.buildInductLoop(id, lane, position, frequency,
783  friendlyPos, vTypes);
784  } catch (InvalidArgument& e) {
785  WRITE_ERROR(e.what());
786  } catch (IOError& e) {
787  WRITE_ERROR(e.what());
788  }
789 }
790 
791 
792 void
794  bool ok = true;
795  // get the id, report an error if not given or empty...
796  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
797  if (!ok) {
798  return;
799  }
800  const SUMOReal position = attrs.get<SUMOReal>(SUMO_ATTR_POSITION, id.c_str(), ok);
801  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, id.c_str(), ok, false);
802  const std::string lane = attrs.get<std::string>(SUMO_ATTR_LANE, id.c_str(), ok);
803  const std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, id.c_str(), ok);
804  const std::string vTypes = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id.c_str(), ok, "");
805  if (!ok) {
806  return;
807  }
808  try {
809  myDetectorBuilder.buildInstantInductLoop(id, lane, position, FileHelpers::checkForRelativity(file, getFileName()), friendlyPos, vTypes);
810  } catch (InvalidArgument& e) {
811  WRITE_ERROR(e.what());
812  } catch (IOError& e) {
813  WRITE_ERROR(e.what());
814  }
815 }
816 
817 
818 void
820  bool ok = true;
821  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
822  SUMOTime frequency = attrs.getSUMOTimeReporting(SUMO_ATTR_FREQUENCY, id.c_str(), ok);
823  std::string type = attrs.getStringSecure(SUMO_ATTR_TYPE, "");
824  std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, id.c_str(), ok);
825  if (!ok) {
826  return;
827  }
828  try {
830  } catch (InvalidArgument& e) {
831  WRITE_ERROR(e.what());
832  } catch (IOError& e) {
833  WRITE_ERROR(e.what());
834  }
835 }
836 
837 
838 void
840  bool ok = true;
841  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
842  SUMOTime frequency = attrs.getSUMOTimeReporting(SUMO_ATTR_FREQUENCY, id.c_str(), ok);
843  SUMOTime begin = attrs.getOptSUMOTimeReporting(SUMO_ATTR_BEGIN, id.c_str(), ok, -1);
844  std::string edge = attrs.get<std::string>(SUMO_ATTR_EDGE, id.c_str(), ok);
845  std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, id.c_str(), ok);
846  const std::string vTypes = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id.c_str(), ok, "");
847  if (!ok) {
848  return;
849  }
850  try {
851  myDetectorBuilder.buildRouteProbe(id, edge, frequency, begin,
853  } catch (InvalidArgument& e) {
854  WRITE_ERROR(e.what());
855  } catch (IOError& e) {
856  WRITE_ERROR(e.what());
857  }
858 }
859 
860 
861 
862 void
864  // check whether this is a detector connected to a tls an optionally to a link
865  bool ok = true;
866  const std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
867  const std::string lsaid = attrs.getOpt<std::string>(SUMO_ATTR_TLID, id.c_str(), ok, "<invalid>");
868  const std::string toLane = attrs.getOpt<std::string>(SUMO_ATTR_TO, id.c_str(), ok, "<invalid>");
869  const SUMOTime haltingTimeThreshold = attrs.getOptSUMOTimeReporting(SUMO_ATTR_HALTING_TIME_THRESHOLD, id.c_str(), ok, TIME2STEPS(1));
870  const SUMOReal haltingSpeedThreshold = attrs.getOpt<SUMOReal>(SUMO_ATTR_HALTING_SPEED_THRESHOLD, id.c_str(), ok, 5.0f / 3.6f);
871  const SUMOReal jamDistThreshold = attrs.getOpt<SUMOReal>(SUMO_ATTR_JAM_DIST_THRESHOLD, id.c_str(), ok, 10.0f);
872  const SUMOReal position = attrs.get<SUMOReal>(SUMO_ATTR_POSITION, id.c_str(), ok);
873  const SUMOReal length = attrs.get<SUMOReal>(SUMO_ATTR_LENGTH, id.c_str(), ok);
874  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, id.c_str(), ok, false);
875  const bool cont = attrs.getOpt<bool>(SUMO_ATTR_CONT, id.c_str(), ok, false);
876  const std::string lane = attrs.get<std::string>(SUMO_ATTR_LANE, id.c_str(), ok);
877  const std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, id.c_str(), ok);
878  const std::string vTypes = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id.c_str(), ok, "");
879  if (!ok) {
880  return;
881  }
882  try {
883  if (lsaid != "<invalid>") {
884  if (toLane == "<invalid>") {
885  myDetectorBuilder.buildE2Detector(id, lane, position, length, cont,
888  haltingTimeThreshold, haltingSpeedThreshold, jamDistThreshold,
889  friendlyPos, vTypes);
890  } else {
891  myDetectorBuilder.buildE2Detector(id, lane, position, length, cont,
892  myJunctionControlBuilder.getTLLogic(lsaid), toLane,
894  haltingTimeThreshold, haltingSpeedThreshold, jamDistThreshold,
895  friendlyPos, vTypes);
896  }
897  } else {
898  bool ok = true;
899  SUMOTime frequency = attrs.getSUMOTimeReporting(SUMO_ATTR_FREQUENCY, id.c_str(), ok);
900  if (!ok) {
901  return;
902  }
903  myDetectorBuilder.buildE2Detector(id, lane, position, length, cont, frequency,
905  haltingTimeThreshold, haltingSpeedThreshold, jamDistThreshold,
906  friendlyPos, vTypes);
907  }
908  } catch (InvalidArgument& e) {
909  WRITE_ERROR(e.what());
910  } catch (IOError& e) {
911  WRITE_ERROR(e.what());
912  }
913 }
914 
915 
916 void
918  bool ok = true;
919  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
920  const SUMOTime frequency = attrs.getSUMOTimeReporting(SUMO_ATTR_FREQUENCY, id.c_str(), ok);
921  const SUMOTime haltingTimeThreshold = attrs.getOptSUMOTimeReporting(SUMO_ATTR_HALTING_TIME_THRESHOLD, id.c_str(), ok, TIME2STEPS(1));
922  const SUMOReal haltingSpeedThreshold = attrs.getOpt<SUMOReal>(SUMO_ATTR_HALTING_SPEED_THRESHOLD, id.c_str(), ok, 5.0f / 3.6f);
923  const std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, id.c_str(), ok);
924  const std::string vTypes = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id.c_str(), ok, "");
925  if (!ok) {
926  return;
927  }
928  try {
931  frequency, haltingSpeedThreshold, haltingTimeThreshold, vTypes);
932  } catch (InvalidArgument& e) {
933  WRITE_ERROR(e.what());
934  } catch (IOError& e) {
935  WRITE_ERROR(e.what());
936  }
937 }
938 
939 
940 void
942  bool ok = true;
943  const SUMOReal position = attrs.get<SUMOReal>(SUMO_ATTR_POSITION, myDetectorBuilder.getCurrentE3ID().c_str(), ok);
944  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, myDetectorBuilder.getCurrentE3ID().c_str(), ok, false);
945  const std::string lane = attrs.get<std::string>(SUMO_ATTR_LANE, myDetectorBuilder.getCurrentE3ID().c_str(), ok);
946  if (!ok) {
947  return;
948  }
949  myDetectorBuilder.addE3Entry(lane, position, friendlyPos);
950 }
951 
952 
953 void
955  bool ok = true;
956  const SUMOReal position = attrs.get<SUMOReal>(SUMO_ATTR_POSITION, myDetectorBuilder.getCurrentE3ID().c_str(), ok);
957  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, myDetectorBuilder.getCurrentE3ID().c_str(), ok, false);
958  const std::string lane = attrs.get<std::string>(SUMO_ATTR_LANE, myDetectorBuilder.getCurrentE3ID().c_str(), ok);
959  if (!ok) {
960  return;
961  }
962  myDetectorBuilder.addE3Exit(lane, position, friendlyPos);
963 }
964 
965 
966 void
967 NLHandler::addEdgeLaneMeanData(const SUMOSAXAttributes& attrs, int objecttype) {
968  bool ok = true;
969  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
970  const SUMOReal maxTravelTime = attrs.getOpt<SUMOReal>(SUMO_ATTR_MAX_TRAVELTIME, id.c_str(), ok, 100000);
971  const SUMOReal minSamples = attrs.getOpt<SUMOReal>(SUMO_ATTR_MIN_SAMPLES, id.c_str(), ok, 0);
972  const SUMOReal haltingSpeedThreshold = attrs.getOpt<SUMOReal>(SUMO_ATTR_HALTING_SPEED_THRESHOLD, id.c_str(), ok, POSITION_EPS);
973  const std::string excludeEmpty = attrs.getOpt<std::string>(SUMO_ATTR_EXCLUDE_EMPTY, id.c_str(), ok, "false");
974  const bool withInternal = attrs.getOpt<bool>(SUMO_ATTR_WITH_INTERNAL, id.c_str(), ok, false);
975  const bool trackVehicles = attrs.getOpt<bool>(SUMO_ATTR_TRACK_VEHICLES, id.c_str(), ok, false);
976  const std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, id.c_str(), ok);
977  const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, "performance");
978  std::string vtypes = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id.c_str(), ok, "");
979  const SUMOTime frequency = attrs.getOptSUMOTimeReporting(SUMO_ATTR_FREQUENCY, id.c_str(), ok, -1);
980  const SUMOTime begin = attrs.getOptSUMOTimeReporting(SUMO_ATTR_BEGIN, id.c_str(), ok, string2time(OptionsCont::getOptions().getString("begin")));
981  const SUMOTime end = attrs.getOptSUMOTimeReporting(SUMO_ATTR_END, id.c_str(), ok, string2time(OptionsCont::getOptions().getString("end")));
982  if (!ok) {
983  return;
984  }
985  try {
986  myDetectorBuilder.createEdgeLaneMeanData(id, frequency, begin, end,
987  type, objecttype == SUMO_TAG_MEANDATA_LANE,
988  // equivalent to TplConvert::_2bool used in SUMOSAXAttributes::getBool
989  excludeEmpty[0] != 't' && excludeEmpty[0] != 'T' && excludeEmpty[0] != '1' && excludeEmpty[0] != 'x',
990  excludeEmpty == "defaults", withInternal, trackVehicles,
991  maxTravelTime, minSamples, haltingSpeedThreshold, vtypes,
993  } catch (InvalidArgument& e) {
994  WRITE_ERROR(e.what());
995  } catch (IOError& e) {
996  WRITE_ERROR(e.what());
997  }
998 }
999 
1000 
1001 void
1003  bool ok = true;
1004  std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, 0, ok);
1005  if (!MSGlobals::gUsingInternalLanes && fromID[0] == ':') {
1006  return;
1007  }
1008 
1009  MSLink* link = 0;
1010  try {
1011  bool ok = true;
1012  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, 0, ok);
1013  const int fromLaneIdx = attrs.get<int>(SUMO_ATTR_FROM_LANE, 0, ok);
1014  const SUMOReal foeVisibilityDistance = attrs.getOpt<SUMOReal>(SUMO_ATTR_VISIBILITY_DISTANCE, 0, ok, 4.5);
1015  const int toLaneIdx = attrs.get<int>(SUMO_ATTR_TO_LANE, 0, ok);
1016  LinkDirection dir = parseLinkDir(attrs.get<std::string>(SUMO_ATTR_DIR, 0, ok));
1017  LinkState state = parseLinkState(attrs.get<std::string>(SUMO_ATTR_STATE, 0, ok));
1018  bool keepClear = attrs.getOpt<bool>(SUMO_ATTR_KEEP_CLEAR, 0, ok, true);
1019  std::string tlID = attrs.getOpt<std::string>(SUMO_ATTR_TLID, 0, ok, "");
1020 #ifdef HAVE_INTERNAL_LANES
1021  std::string viaID = attrs.getOpt<std::string>(SUMO_ATTR_VIA, 0, ok, "");
1022 #endif
1023 
1024  MSEdge* from = MSEdge::dictionary(fromID);
1025  if (from == 0) {
1026  WRITE_ERROR("Unknown from-edge '" + fromID + "' in connection");
1027  return;
1028  }
1029  MSEdge* to = MSEdge::dictionary(toID);
1030  if (to == 0) {
1031  WRITE_ERROR("Unknown to-edge '" + toID + "' in connection");
1032  return;
1033  }
1034  if (fromLaneIdx < 0 || fromLaneIdx >= (int)from->getLanes().size() ||
1035  toLaneIdx < 0 || toLaneIdx >= (int)to->getLanes().size()) {
1036  WRITE_ERROR("Invalid lane index in connection from '" + from->getID() + "' to '" + to->getID() + "'.");
1037  return;
1038  }
1039  MSLane* fromLane = from->getLanes()[fromLaneIdx];
1040  MSLane* toLane = to->getLanes()[toLaneIdx];
1041  assert(fromLane);
1042  assert(toLane);
1043 
1044  MSTrafficLightLogic* logic = 0;
1045  int tlLinkIdx = -1;
1046  if (tlID != "") {
1047  tlLinkIdx = attrs.get<int>(SUMO_ATTR_TLLINKINDEX, 0, ok);
1048  // make sure that the index is in range
1050  if ((tlLinkIdx < 0 || tlLinkIdx >= (int)logic->getCurrentPhaseDef().getState().size())
1051  && logic->getLogicType() != "railSignal"
1052  && logic->getLogicType() != "railCrossing") {
1053  WRITE_ERROR("Invalid " + toString(SUMO_ATTR_TLLINKINDEX) + " '" + toString(tlLinkIdx) +
1054  "' in connection controlled by '" + tlID + "'");
1055  return;
1056  }
1057  if (!ok) {
1058  return;
1059  }
1060  }
1061  SUMOReal length = fromLane->getShape()[-1].distanceTo(toLane->getShape()[0]);
1062 
1063  // build the link
1064 #ifdef HAVE_INTERNAL_LANES
1065  MSLane* via = 0;
1066  if (viaID != "" && MSGlobals::gUsingInternalLanes) {
1067  via = MSLane::dictionary(viaID);
1068  if (via == 0) {
1069  WRITE_ERROR("An unknown lane ('" + viaID +
1070  "') should be set as a via-lane for lane '" + toLane->getID() + "'.");
1071  return;
1072  }
1073  length = via->getLength();
1074  }
1075  link = new MSLink(fromLane, toLane, via, dir, state, length, foeVisibilityDistance, keepClear, logic, tlLinkIdx);
1076  if (via != 0) {
1077  via->addIncomingLane(fromLane, link);
1078  } else {
1079  toLane->addIncomingLane(fromLane, link);
1080  }
1081 #else
1082  link = new MSLink(fromLane, toLane, dir, state, length, foeVisibilityDistance, keepClear, logic, tlLinkIdx);
1083  toLane->addIncomingLane(fromLane, link);
1084 #endif
1085  toLane->addApproachingLane(fromLane, myNetworkVersion < 0.25);
1086 
1087  // if a traffic light is responsible for it, inform the traffic light
1088  // check whether this link is controlled by a traffic light
1089  // we can not reuse logic here because it might be an inactive one
1090  if (tlID != "") {
1091  myJunctionControlBuilder.getTLLogic(tlID).addLink(link, fromLane, tlLinkIdx);
1092  }
1093  // add the link
1094  fromLane->addLink(link);
1095 
1096  } catch (InvalidArgument& e) {
1097  WRITE_ERROR(e.what());
1098  }
1099 }
1100 
1101 
1103 NLHandler::parseLinkDir(const std::string& dir) {
1104  if (SUMOXMLDefinitions::LinkDirections.hasString(dir)) {
1106  } else {
1107  throw InvalidArgument("Unrecognised link direction '" + dir + "'.");
1108  }
1109 }
1110 
1111 
1112 LinkState
1113 NLHandler::parseLinkState(const std::string& state) {
1114  if (SUMOXMLDefinitions::LinkStates.hasString(state)) {
1115  return SUMOXMLDefinitions::LinkStates.get(state);
1116  } else {
1117  if (state == "t") { // legacy networks
1118  // WRITE_WARNING("Obsolete link state 't'. Use 'o' instead");
1120  } else {
1121  throw InvalidArgument("Unrecognised link state '" + state + "'.");
1122  }
1123  }
1124 }
1125 
1126 
1127 // ----------------------------------
1128 void
1130  if (myNetIsLoaded) {
1131  //WRITE_WARNING("POIs and Polygons should be loaded using option --po-files")
1132  return;
1133  }
1134  bool ok = true;
1136  Boundary convBoundary = attrs.get<Boundary>(SUMO_ATTR_CONV_BOUNDARY, 0, ok);
1137  Boundary origBoundary = attrs.get<Boundary>(SUMO_ATTR_ORIG_BOUNDARY, 0, ok);
1138  std::string proj = attrs.get<std::string>(SUMO_ATTR_ORIG_PROJ, 0, ok);
1139  if (ok) {
1140  Position networkOffset = s[0];
1141  GeoConvHelper::init(proj, networkOffset, origBoundary, convBoundary);
1142  if (OptionsCont::getOptions().getBool("fcd-output.geo") && !GeoConvHelper::getFinal().usingGeoProjection()) {
1143  WRITE_WARNING("no valid geo projection loaded from network. fcd-output.geo will not work");
1144  }
1145  }
1146 }
1147 
1148 
1149 void
1151  bool ok = true;
1152  myCurrentIsBroken = false;
1153  // get the id, report an error if not given or empty...
1154  myCurrentDistrictID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
1155  if (!ok) {
1156  myCurrentIsBroken = true;
1157  return;
1158  }
1159  try {
1161  if (!MSEdge::dictionary(myCurrentDistrictID + "-sink", sink)) {
1162  delete sink;
1163  throw InvalidArgument("Another edge with the id '" + myCurrentDistrictID + "-sink' exists.");
1164  }
1165  sink->initialize(new std::vector<MSLane*>());
1167  if (!MSEdge::dictionary(myCurrentDistrictID + "-source", source)) {
1168  delete source;
1169  throw InvalidArgument("Another edge with the id '" + myCurrentDistrictID + "-source' exists.");
1170  }
1171  source->initialize(new std::vector<MSLane*>());
1172  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
1173  std::vector<std::string> desc = attrs.getStringVector(SUMO_ATTR_EDGES);
1174  for (std::vector<std::string>::const_iterator i = desc.begin(); i != desc.end(); ++i) {
1175  MSEdge* edge = MSEdge::dictionary(*i);
1176  // check whether the edge exists
1177  if (edge == 0) {
1178  throw InvalidArgument("The edge '" + *i + "' within district '" + myCurrentDistrictID + "' is not known.");
1179  }
1180  source->addSuccessor(edge);
1181  edge->addSuccessor(sink);
1182  }
1183  }
1184  if (attrs.hasAttribute(SUMO_ATTR_SHAPE)) {
1186  if (shape.size() != 0) {
1187  if (!myNet.getShapeContainer().addPolygon(myCurrentDistrictID, "taz", RGBColor::parseColor("1.0,.33,.33"), 0, 0, "", shape, false)) {
1188  WRITE_WARNING("Skipping visualization of taz '" + myCurrentDistrictID + "', polygon already exists.");
1189  }
1190  }
1191  }
1192  } catch (InvalidArgument& e) {
1193  WRITE_ERROR(e.what());
1194  myCurrentIsBroken = true;
1195  }
1196 }
1197 
1198 
1199 void
1200 NLHandler::addDistrictEdge(const SUMOSAXAttributes& attrs, bool isSource) {
1201  if (myCurrentIsBroken) {
1202  // earlier error
1203  return;
1204  }
1205  bool ok = true;
1206  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, myCurrentDistrictID.c_str(), ok);
1207  MSEdge* succ = MSEdge::dictionary(id);
1208  if (succ != 0) {
1209  // connect edge
1210  if (isSource) {
1211  MSEdge::dictionary(myCurrentDistrictID + "-source")->addSuccessor(succ);
1212  } else {
1213  succ->addSuccessor(MSEdge::dictionary(myCurrentDistrictID + "-sink"));
1214  }
1215  } else {
1216  WRITE_ERROR("At district '" + myCurrentDistrictID + "': succeeding edge '" + id + "' does not exist.");
1217  }
1218 }
1219 
1220 
1221 void
1223  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
1224  std::vector<std::string> edgeIDs = attrs.getStringVector(SUMO_ATTR_EDGES);
1225  for (std::vector<std::string>::iterator it = edgeIDs.begin(); it != edgeIDs.end(); ++it) {
1226  MSEdge* edge = MSEdge::dictionary(*it);
1227  if (edge == 0) {
1228  WRITE_ERROR("Unknown edge '" + (*it) + "' in roundabout");
1229  } else {
1230  edge->markAsRoundabout();
1231  }
1232  }
1233  } else {
1234  WRITE_ERROR("Empty edges in roundabout.");
1235  }
1236 }
1237 
1238 
1239 // ----------------------------------
1240 void
1242  try {
1244  } catch (InvalidArgument& e) {
1245  WRITE_ERROR(e.what());
1246  }
1247 }
1248 
1249 
1250 void
1252  if (!myCurrentIsBroken) {
1253  try {
1255  } catch (InvalidArgument& e) {
1256  WRITE_ERROR(e.what());
1257  myCurrentIsBroken = true;
1258  }
1259  }
1260  myCurrentWAUTID = "";
1261 }
1262 
1263 
1264 Position
1265 NLShapeHandler::getLanePos(const std::string& poiID, const std::string& laneID, SUMOReal lanePos) {
1266  MSLane* lane = MSLane::dictionary(laneID);
1267  if (lane == 0) {
1268  WRITE_ERROR("Lane '" + laneID + "' to place poi '" + poiID + "' on is not known.");
1269  return Position::INVALID;
1270  }
1271  if (lanePos < 0) {
1272  lanePos = lane->getLength() + lanePos;
1273  }
1274  return lane->geometryPositionAtOffset(lanePos);
1275 }
1276 /****************************************************************************/
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:71
void parseAndBuildCalibrator(MSNet &net, const SUMOSAXAttributes &attrs, const std::string &base)
Parses his values and builds a mesoscopic or microscopic calibrator.
SUMOReal getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:480
void beginE3Detector(const SUMOSAXAttributes &attrs)
Starts building of an e3 detector using the given specification.
Definition: NLHandler.cpp:917
void initTrafficLightLogic(const std::string &id, const std::string &programID, TrafficLightType type, SUMOTime offset)
Begins the reading of a traffic lights logic.
SumoXMLTag
Numbers representing SUMO-XML - element names.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
void addWAUTJunction(const SUMOSAXAttributes &attrs)
Definition: NLHandler.cpp:584
Builds detectors for microsim.
virtual void addE2Detector(const SUMOSAXAttributes &attrs)
Builds an e2 detector using the given specification.
Definition: NLHandler.cpp:863
static RGBColor parseColor(std::string coldef)
Parses a color information.
Definition: RGBColor.cpp:172
long long int SUMOTime
Definition: SUMOTime.h:43
minimum duration of a phase
bool myCurrentIsInternalToSkip
Information whether the currently parsed edge is internal and not wished, here.
Definition: NLHandler.h:297
Whether vehicles must keep the junction clear.
const SUMOReal SUMO_const_laneWidth
Definition: StdDefs.h:49
void addSuccessor(MSEdge *edge)
Adds an edge to the list of edges which may be reached from this edge and to the incoming of the othe...
Definition: MSEdge.h:323
void addAccess(MSNet &net, const SUMOSAXAttributes &attrs)
Parses the values and adds an access point to the currently parsed stopping place.
std::string next()
virtual MSEdge * closeEdge()
Closes the building of an edge; The edge is completely described by now and may not be opened again...
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
virtual void openWAUT(const SUMOSAXAttributes &attrs)
Definition: NLHandler.cpp:538
bool myCurrentIsBroken
Definition: NLHandler.h:330
void addIncoming(MSEdge *edge)
Definition: MSJunction.h:113
virtual MSEdge * buildEdge(const std::string &id, const MSEdge::EdgeBasicFunction function, const std::string &streetName, const std::string &edgeType, const int priority)
Builds an edge instance (MSEdge in this case)
void addE3Entry(const std::string &lane, SUMOReal pos, bool friendlyPos)
Builds an entry point of an e3 detector.
The base class for an intersection.
Definition: MSJunction.h:64
static std::string getJunctionIDFromInternalEdge(const std::string internalEdge)
return the junction id when given an edge of type internal, crossing or WalkingArea ...
const std::string & getFileName() const
returns the current file name
int SVCPermissions
void addLink(MSLink *link)
Delayed initialization.
Definition: MSLane.cpp:190
virtual void addVTypeProbeDetector(const SUMOSAXAttributes &attrs)
Builds a vtype-detector using the given specification.
Definition: NLHandler.cpp:819
void addRoundabout(const SUMOSAXAttributes &attrs)
Definition: NLHandler.cpp:1222
NLDetectorBuilder & myDetectorBuilder
The detector builder to use.
Definition: NLHandler.h:301
void parseAndBuildChargingStation(MSNet &net, const SUMOSAXAttributes &attrs)
Parses his values and builds a charging station.
foe visibility distance of a link
void parseAndBuildRerouter(MSNet &net, const SUMOSAXAttributes &attrs, const std::string &base)
Parses his values and builds a rerouter.
void closeJunctionLogic()
Ends the building of a junction logic (row-logic)
SUMOReal myNetworkVersion
the loaded network version
Definition: NLHandler.h:346
void addE3Exit(const std::string &lane, SUMOReal pos, bool friendlyPos)
Builds an exit point of an e3 detector.
The edge is a macroscopic connector (source/sink)
Definition: MSEdge.h:95
void addIncomingLane(MSLane *lane, MSLink *viaLink)
Definition: MSLane.cpp:1567
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
void buildRouteProbe(const std::string &id, const std::string &edge, SUMOTime frequency, SUMOTime begin, const std::string &device, const std::string &vTypes)
Builds a routeProbe and adds it to the net.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:427
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn&#39;t already in the dictionary...
Definition: MSEdge.cpp:673
virtual void addE1Detector(const SUMOSAXAttributes &attrs)
Builds an e1 detector using the given specification.
Definition: NLHandler.cpp:764
NLHandler(const std::string &file, MSNet &net, NLDetectorBuilder &detBuilder, NLTriggerBuilder &triggerBuilder, NLEdgeControlBuilder &edgeBuilder, NLJunctionControlBuilder &junctionBuilder)
Constructor.
Definition: NLHandler.cpp:68
void initialize(const std::vector< MSLane *> *lanes)
Initialize the edge.
Definition: MSEdge.cpp:110
void addLink(MSLink *link, MSLane *lane, int pos)
void beginEdgeParsing(const SUMOSAXAttributes &attrs)
begins the processing of an edge
Definition: NLHandler.cpp:297
void buildInstantInductLoop(const std::string &id, const std::string &lane, SUMOReal pos, const std::string &device, bool friendlyPos, const std::string &vTypes)
Builds an instantenous induction and adds it to the net.
maximum duration of a phase
const std::string & getID() const
Returns the id.
Definition: Named.h:66
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
const std::string & getActiveSubKey() const
Returns the active sub key.
static StringBijection< LinkState > LinkStates
const SVCPermissions SVCAll
void createEdgeLaneMeanData(const std::string &id, SUMOTime frequency, SUMOTime begin, SUMOTime end, const std::string &type, const bool useLanes, const bool withEmpty, const bool printDefaults, const bool withInternal, const bool trackVehicles, const SUMOReal maxTravelTime, const SUMOReal minSamples, const SUMOReal haltSpeed, const std::string &vTypes, const std::string &device)
Creates edge based mean data collector using the given specification.
std::string myCurrentDistrictID
The id of the current district.
Definition: NLHandler.h:313
void buildInductLoop(const std::string &id, const std::string &lane, SUMOReal pos, SUMOTime splInterval, const std::string &device, bool friendlyPos, const std::string &vTypes)
Builds an e1 detector and adds it to the net.
EdgeBasicFunction
Defines possible edge types.
Definition: MSEdge.h:89
void closeWAUT(const std::string &wautid)
Closes loading of a WAUT.
void buildVTypeProbe(const std::string &id, const std::string &vtype, SUMOTime frequency, const std::string &device)
Builds a vTypeProbe and adds it to the net.
virtual void endE3Detector()
Builds of an e3 detector using collected values.
Definition: NLHandler.cpp:1241
void endE3Detector()
Builds of an e3 detector using collected values.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
SUMOTime getSUMOTimeReporting(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
virtual SumoXMLEdgeFunc getEdgeFunc(bool &ok) const =0
Returns the value of the named attribute.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
The purpose of the edge is not known.
Definition: MSEdge.h:91
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
The simulated network and simulation perfomer.
Definition: MSNet.h:93
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
bool myAmInTLLogicMode
internal information whether a tls-logic is currently read
Definition: NLHandler.h:316
int getNumberOfLoadedPhases() const
return the number of phases loaded so far (for error reporting)
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
void parseLanes(const std::string &junctionID, const std::string &def, std::vector< MSLane *> &into, bool &ok)
Definition: NLHandler.cpp:500
void closeJunction(const std::string &basePath)
Closes (ends) the processing of the current junction.
MSTLLogicControl::TLSLogicVariants & getTLLogic(const std::string &id) const
Returns a previously build tls logic.
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
void closeWAUT()
Definition: NLHandler.cpp:1251
void addParam(const SUMOSAXAttributes &attrs)
Definition: NLHandler.cpp:520
void addDistrict(const SUMOSAXAttributes &attrs)
Definition: NLHandler.cpp:1150
The state of a link.
static StringBijection< LinkDirection > LinkDirections
void addApproachingLane(MSLane *lane, bool warnMultiCon)
Definition: MSLane.cpp:1577
A road/street connecting two junctions.
Definition: MSEdge.h:80
void setLocation(const SUMOSAXAttributes &attrs)
Parses network location description.
Definition: NLHandler.cpp:1129
void addPhase(SUMOTime duration, const std::string &state, SUMOTime min, SUMOTime max)
Adds a phase to the currently built traffic lights logic.
The definition of a periodic event.
virtual void openJunction(const SUMOSAXAttributes &attrs)
opens a junction for processing
Definition: NLHandler.cpp:450
NLEdgeControlBuilder & myEdgeControlBuilder
The edge builder to use.
Definition: NLHandler.h:307
The edge is a district edge.
Definition: MSEdge.h:99
the edges of a route
void addE3Entry(const SUMOSAXAttributes &attrs)
Adds an entry to the currently processed e3 detector.
Definition: NLHandler.cpp:941
Encapsulated SAX-Attributes.
An instantenous induction loop.
void addE3Exit(const SUMOSAXAttributes &attrs)
Adds an exit to the currently processed e3 detector.
Definition: NLHandler.cpp:954
static StringBijection< TrafficLightType > TrafficLightTypes
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
Builder of microsim-junctions and tls.
Position getLanePos(const std::string &poiID, const std::string &laneID, SUMOReal lanePos)
get position for a given laneID
Definition: NLHandler.cpp:1265
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:430
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
virtual void closeTrafficLightLogic(const std::string &basePath)
Ends the building of a traffic lights logic.
void addWAUTSwitch(const SUMOSAXAttributes &attrs)
Definition: NLHandler.cpp:565
JunctionGraph myJunctionGraph
Definition: NLHandler.h:353
void addRequest(const SUMOSAXAttributes &attrs)
adds a request item to the current junction logic
Definition: NLHandler.cpp:605
void openJunction(const std::string &id, const std::string &key, const SumoXMLNodeType type, SUMOReal x, SUMOReal y, const PositionVector &shape, const std::vector< MSLane *> &incomingLanes, const std::vector< MSLane *> &internalLanes)
Begins the processing of the named junction.
void setPermissionsFound()
Labels the network to contain vehicle class permissions.
Definition: MSNet.h:180
T get(const std::string &str) const
void buildE2Detector(const std::string &id, const std::string &lane, SUMOReal pos, SUMOReal length, bool cont, SUMOTime splInterval, const std::string &device, SUMOTime haltingTimeThreshold, SUMOReal haltingSpeedThreshold, SUMOReal jamDistThreshold, bool friendlyPos, const std::string &vTypes)
Builds an e2 detector with a fixed interval and adds it to the net.
void addConnection(const SUMOSAXAttributes &attrs)
adds a connection
Definition: NLHandler.cpp:1002
std::string myCurrentTypeID
The id of the currently processed edge type.
Definition: NLHandler.h:322
void parseAndBuildLaneSpeedTrigger(MSNet &net, const SUMOSAXAttributes &attrs, const std::string &base)
Parses his values and builds a lane speed trigger.
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
void addAction(const SUMOSAXAttributes &attrs, const std::string &basePath)
Builds an action and saves it for further use.
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:46
Information within the junction logic which internal lanes block external.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Definition: NLHandler.cpp:93
void parseAndBuildStoppingPlace(MSNet &net, const SUMOSAXAttributes &attrs, const SumoXMLTag element)
Parses the values and builds a stopping places for busses, trains or container vehicles.
MSJunction * retrieve(const std::string id)
try to retrieve junction by id
#define POSITION_EPS
Definition: config.h:187
bool myHaveSeenInternalEdge
whether the loaded network contains internal lanes
Definition: NLHandler.h:337
LinkDirection parseLinkDir(const std::string &dir)
Parses the given character into an enumeration typed link direction.
Definition: NLHandler.cpp:1103
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:73
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
void addParam(const std::string &key, const std::string &value)
Adds a parameter.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
std::string getCurrentE3ID() const
Returns the id of the currently built e3 detector.
virtual SumoXMLNodeType getNodeType(bool &ok) const =0
Returns the value of the named attribute.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
virtual void addNeigh(const std::string id)
Adds a neighbor to the current lane.
void addOutgoing(MSEdge *edge)
Definition: MSJunction.h:117
MSTLLogicControl & getTLLogicControlToUse() const
Returns the used tls control.
void addWAUTJunction(const std::string &wautid, const std::string &tls, const std::string &proc, bool synchron)
Adds a tls to the list of tls to be switched by the named WAUT.
virtual bool addPolygon(const std::string &id, const std::string &type, const RGBColor &color, SUMOReal layer, SUMOReal angle, const std::string &imgFile, const PositionVector &shape, bool fill, bool ignorePruning=false)
Builds a polygon using the given values and adds it to the container.
virtual std::vector< std::string > getStringVector(int attr) const =0
Tries to read given attribute assuming it is a string vector.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
void addParameter(const std::string &key, const std::string &value)
Adds a parameter.
std::string myCurrentWAUTID
The id of the currently processed WAUT.
Definition: NLHandler.h:319
The edge is a pedestrian walking area (a special type of internal edge)
Definition: MSEdge.h:103
virtual void myEndElement(int element)
Called when a closing tag occurs.
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:1286
virtual void addInstantE1Detector(const SUMOSAXAttributes &attrs)
Builds an e1 detector using the given specification.
Definition: NLHandler.cpp:793
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
std::vector< std::string > LaneIdVector
virtual void closeEdge()
Closes the process of building an edge.
Definition: NLHandler.cpp:386
virtual void addRouteProbeDetector(const SUMOSAXAttributes &attrs)
Builds a routeProbe-detector using the given specification.
Definition: NLHandler.cpp:839
A train stop (alias for bus stop)
void addLane(const SUMOSAXAttributes &attrs)
adds a lane to the previously opened edge
Definition: NLHandler.cpp:402
bool myHaveSeenNeighs
whether the loaded network contains explicit neighbor lanes
Definition: NLHandler.h:340
virtual ~NLHandler()
Destructor.
Definition: NLHandler.cpp:89
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
NLTriggerBuilder & myTriggerBuilder
The trigger builder to use.
Definition: NLHandler.h:304
void initJunctionLogic(const std::string &id)
Initialises a junction logic.
The edge is a normal street.
Definition: MSEdge.h:93
The link is controlled by a tls which is off and blinks, has to brake.
static std::string checkForRelativity(const std::string &filename, const std::string &basePath)
Returns the path from a configuration so that it is accessable from the current working directory...
bool myNetIsLoaded
whether the location element was already loadee
Definition: NLHandler.h:349
virtual MSLane * addLane(const std::string &id, SUMOReal maxSpeed, SUMOReal length, const PositionVector &shape, SUMOReal width, SVCPermissions permissions, int index)
Adds a lane to the current edge.
void addWAUT(SUMOTime refTime, const std::string &id, const std::string &startProg)
Adds a WAUT definition.
SUMOTime getOptSUMOTimeReporting(int attr, const char *objectid, bool &ok, SUMOTime defaultValue, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
The edge is a pedestrian crossing (a special type of internal edge)
Definition: MSEdge.h:101
virtual std::string getStringSecure(int id, const std::string &def) const =0
Returns the string-value of the named (by its enum-value) attribute.
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:89
SumoXMLEdgeFunc
Numbers representing special SUMO-XML-attribute values for representing edge functions used in netbui...
void addPhase(const SUMOSAXAttributes &attrs)
adds a phase to the traffic lights logic currently build
Definition: NLHandler.cpp:673
void addDistrictEdge(const SUMOSAXAttributes &attrs, bool isSource)
Definition: NLHandler.cpp:1200
MSNet & myNet
The net to fill (preinitialised)
Definition: NLHandler.h:209
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const SUMOReal speed)
Adds a restriction for an edge type.
Definition: MSNet.cpp:290
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
LinkState parseLinkState(const std::string &state)
Parses the given character into an enumeration typed link state.
Definition: NLHandler.cpp:1113
The abstract direction of a link.
void setJunctions(MSJunction *from, MSJunction *to)
Definition: MSEdge.h:392
The parent class for traffic light logics.
A variable speed sign.
void beginEdgeParsing(const std::string &id, const MSEdge::EdgeBasicFunction function, const std::string &streetName, const std::string &edgeType, int priority)
Begins building of an MSEdge.
#define SUMOReal
Definition: config.h:213
NLDiscreteEventBuilder myActionBuilder
A builder for object actions.
Definition: NLHandler.h:294
void addWAUTSwitch(const std::string &wautid, SUMOTime when, const std::string &to)
Adds a WAUT switch step to a previously built WAUT.
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
virtual void addCrossingEdges(const std::vector< std::string > &)
add the crossingEdges in a crossing edge if present
virtual void myEndElement(int element)
Called when a closing tag occurs.
Definition: NLHandler.cpp:240
void beginE3Detector(const std::string &id, const std::string &device, SUMOTime splInterval, SUMOReal haltingSpeedThreshold, SUMOTime haltingTimeThreshold, const std::string &vTypes)
Stores temporary the initial information about an e3 detector to build.
MSTrafficLightLogic * getActive() const
void markAsRoundabout()
Definition: MSEdge.h:642
virtual void addEdgeLaneMeanData(const SUMOSAXAttributes &attrs, int objecttype)
Builds edge or lane base mean data collector using the given specification.
Definition: NLHandler.cpp:967
Builds trigger objects for microsim.
void initJunctionLogic(const SUMOSAXAttributes &attrs)
begins the reading of a junction row logic
Definition: NLHandler.cpp:632
The edge is an internal edge.
Definition: MSEdge.h:97
bool myLefthand
whether the loaded network was built for left hand traffic
Definition: NLHandler.h:343
Parameterised * myLastParameterised
Definition: NLHandler.h:334
An access point for a train stop.
void closePolygon()
ensures that the last position equals the first
Information whether the detector shall be continued on the folowing lanes.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
void buildVaporizer(const SUMOSAXAttributes &attrs)
Builds a vaporization.
const std::string & getActiveKey() const
Returns the active key.
NLJunctionControlBuilder & myJunctionControlBuilder
The junction builder to use.
Definition: NLHandler.h:310
Parser and container for routes during their loading.
const Position geometryPositionAtOffset(SUMOReal offset, SUMOReal lateralOffset=0) const
Definition: MSLane.h:444
TrafficLightType
void initTrafficLightLogic(const SUMOSAXAttributes &attrs)
begins the reading of a traffic lights logic
Definition: NLHandler.cpp:646
static const Position INVALID
Definition: Position.h:261
Interface for building edges.
void addLogicItem(int request, const std::string &response, const std::string &foes, bool cont)
Adds a logic item.