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