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 bool splitByType = attrs.getOpt<bool>(SUMO_ATTR_SPLIT_VTYPE, id.c_str(), ok, false);
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, splitByType);
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  if (!ok) {
805  return;
806  }
807  try {
808  myDetectorBuilder.buildInstantInductLoop(id, lane, position, FileHelpers::checkForRelativity(file, getFileName()), friendlyPos);
809  } catch (InvalidArgument& e) {
810  WRITE_ERROR(e.what());
811  } catch (IOError& e) {
812  WRITE_ERROR(e.what());
813  }
814 }
815 
816 
817 void
819  bool ok = true;
820  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
821  SUMOTime frequency = attrs.getSUMOTimeReporting(SUMO_ATTR_FREQUENCY, id.c_str(), ok);
822  std::string type = attrs.getStringSecure(SUMO_ATTR_TYPE, "");
823  std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, id.c_str(), ok);
824  if (!ok) {
825  return;
826  }
827  try {
829  } catch (InvalidArgument& e) {
830  WRITE_ERROR(e.what());
831  } catch (IOError& e) {
832  WRITE_ERROR(e.what());
833  }
834 }
835 
836 
837 void
839  bool ok = true;
840  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
841  SUMOTime frequency = attrs.getSUMOTimeReporting(SUMO_ATTR_FREQUENCY, id.c_str(), ok);
842  SUMOTime begin = attrs.getOptSUMOTimeReporting(SUMO_ATTR_BEGIN, id.c_str(), ok, -1);
843  std::string edge = attrs.get<std::string>(SUMO_ATTR_EDGE, id.c_str(), ok);
844  std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, id.c_str(), ok);
845  if (!ok) {
846  return;
847  }
848  try {
849  myDetectorBuilder.buildRouteProbe(id, edge, frequency, begin,
851  } catch (InvalidArgument& e) {
852  WRITE_ERROR(e.what());
853  } catch (IOError& e) {
854  WRITE_ERROR(e.what());
855  }
856 }
857 
858 
859 
860 void
862  // check whether this is a detector connected to a tls an optionally to a link
863  bool ok = true;
864  const std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
865  const std::string lsaid = attrs.getOpt<std::string>(SUMO_ATTR_TLID, id.c_str(), ok, "<invalid>");
866  const std::string toLane = attrs.getOpt<std::string>(SUMO_ATTR_TO, id.c_str(), ok, "<invalid>");
867  const SUMOTime haltingTimeThreshold = attrs.getOptSUMOTimeReporting(SUMO_ATTR_HALTING_TIME_THRESHOLD, id.c_str(), ok, TIME2STEPS(1));
868  const SUMOReal haltingSpeedThreshold = attrs.getOpt<SUMOReal>(SUMO_ATTR_HALTING_SPEED_THRESHOLD, id.c_str(), ok, 5.0f / 3.6f);
869  const SUMOReal jamDistThreshold = attrs.getOpt<SUMOReal>(SUMO_ATTR_JAM_DIST_THRESHOLD, id.c_str(), ok, 10.0f);
870  const SUMOReal position = attrs.get<SUMOReal>(SUMO_ATTR_POSITION, id.c_str(), ok);
871  const SUMOReal length = attrs.get<SUMOReal>(SUMO_ATTR_LENGTH, id.c_str(), ok);
872  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, id.c_str(), ok, false);
873  const bool cont = attrs.getOpt<bool>(SUMO_ATTR_CONT, id.c_str(), ok, false);
874  const std::string lane = attrs.get<std::string>(SUMO_ATTR_LANE, id.c_str(), ok);
875  const std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, id.c_str(), ok);
876  if (!ok) {
877  return;
878  }
879  try {
880  if (lsaid != "<invalid>") {
881  if (toLane == "<invalid>") {
882  myDetectorBuilder.buildE2Detector(id, lane, position, length, cont,
885  haltingTimeThreshold, haltingSpeedThreshold, jamDistThreshold,
886  friendlyPos);
887  } else {
888  myDetectorBuilder.buildE2Detector(id, lane, position, length, cont,
889  myJunctionControlBuilder.getTLLogic(lsaid), toLane,
891  haltingTimeThreshold, haltingSpeedThreshold, jamDistThreshold,
892  friendlyPos);
893  }
894  } else {
895  bool ok = true;
896  SUMOTime frequency = attrs.getSUMOTimeReporting(SUMO_ATTR_FREQUENCY, id.c_str(), ok);
897  if (!ok) {
898  return;
899  }
900  myDetectorBuilder.buildE2Detector(id, lane, position, length, cont, frequency,
902  haltingTimeThreshold, haltingSpeedThreshold, jamDistThreshold,
903  friendlyPos);
904  }
905  } catch (InvalidArgument& e) {
906  WRITE_ERROR(e.what());
907  } catch (IOError& e) {
908  WRITE_ERROR(e.what());
909  }
910 }
911 
912 
913 void
915  bool ok = true;
916  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
917  const SUMOTime frequency = attrs.getSUMOTimeReporting(SUMO_ATTR_FREQUENCY, id.c_str(), ok);
918  const SUMOTime haltingTimeThreshold = attrs.getOptSUMOTimeReporting(SUMO_ATTR_HALTING_TIME_THRESHOLD, id.c_str(), ok, TIME2STEPS(1));
919  const SUMOReal haltingSpeedThreshold = attrs.getOpt<SUMOReal>(SUMO_ATTR_HALTING_SPEED_THRESHOLD, id.c_str(), ok, 5.0f / 3.6f);
920  const std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, id.c_str(), ok);
921  if (!ok) {
922  return;
923  }
924  try {
927  frequency, haltingSpeedThreshold, haltingTimeThreshold);
928  } catch (InvalidArgument& e) {
929  WRITE_ERROR(e.what());
930  } catch (IOError& e) {
931  WRITE_ERROR(e.what());
932  }
933 }
934 
935 
936 void
938  bool ok = true;
939  const SUMOReal position = attrs.get<SUMOReal>(SUMO_ATTR_POSITION, myDetectorBuilder.getCurrentE3ID().c_str(), ok);
940  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, myDetectorBuilder.getCurrentE3ID().c_str(), ok, false);
941  const std::string lane = attrs.get<std::string>(SUMO_ATTR_LANE, myDetectorBuilder.getCurrentE3ID().c_str(), ok);
942  if (!ok) {
943  return;
944  }
945  myDetectorBuilder.addE3Entry(lane, position, friendlyPos);
946 }
947 
948 
949 void
951  bool ok = true;
952  const SUMOReal position = attrs.get<SUMOReal>(SUMO_ATTR_POSITION, myDetectorBuilder.getCurrentE3ID().c_str(), ok);
953  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, myDetectorBuilder.getCurrentE3ID().c_str(), ok, false);
954  const std::string lane = attrs.get<std::string>(SUMO_ATTR_LANE, myDetectorBuilder.getCurrentE3ID().c_str(), ok);
955  if (!ok) {
956  return;
957  }
958  myDetectorBuilder.addE3Exit(lane, position, friendlyPos);
959 }
960 
961 
962 void
963 NLHandler::addEdgeLaneMeanData(const SUMOSAXAttributes& attrs, int objecttype) {
964  bool ok = true;
965  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
966  const SUMOReal maxTravelTime = attrs.getOpt<SUMOReal>(SUMO_ATTR_MAX_TRAVELTIME, id.c_str(), ok, 100000);
967  const SUMOReal minSamples = attrs.getOpt<SUMOReal>(SUMO_ATTR_MIN_SAMPLES, id.c_str(), ok, 0);
968  const SUMOReal haltingSpeedThreshold = attrs.getOpt<SUMOReal>(SUMO_ATTR_HALTING_SPEED_THRESHOLD, id.c_str(), ok, POSITION_EPS);
969  const std::string excludeEmpty = attrs.getOpt<std::string>(SUMO_ATTR_EXCLUDE_EMPTY, id.c_str(), ok, "false");
970  const bool withInternal = attrs.getOpt<bool>(SUMO_ATTR_WITH_INTERNAL, id.c_str(), ok, false);
971  const bool trackVehicles = attrs.getOpt<bool>(SUMO_ATTR_TRACK_VEHICLES, id.c_str(), ok, false);
972  const std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, id.c_str(), ok);
973  const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, "performance");
974  std::string vtypes = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id.c_str(), ok, "");
975  const SUMOTime frequency = attrs.getOptSUMOTimeReporting(SUMO_ATTR_FREQUENCY, id.c_str(), ok, -1);
976  const SUMOTime begin = attrs.getOptSUMOTimeReporting(SUMO_ATTR_BEGIN, id.c_str(), ok, string2time(OptionsCont::getOptions().getString("begin")));
977  const SUMOTime end = attrs.getOptSUMOTimeReporting(SUMO_ATTR_END, id.c_str(), ok, string2time(OptionsCont::getOptions().getString("end")));
978  if (!ok) {
979  return;
980  }
981  try {
982  myDetectorBuilder.createEdgeLaneMeanData(id, frequency, begin, end,
983  type, objecttype == SUMO_TAG_MEANDATA_LANE,
984  // equivalent to TplConvert::_2bool used in SUMOSAXAttributes::getBool
985  excludeEmpty[0] != 't' && excludeEmpty[0] != 'T' && excludeEmpty[0] != '1' && excludeEmpty[0] != 'x',
986  excludeEmpty == "defaults", withInternal, trackVehicles,
987  maxTravelTime, minSamples, haltingSpeedThreshold, vtypes,
989  } catch (InvalidArgument& e) {
990  WRITE_ERROR(e.what());
991  } catch (IOError& e) {
992  WRITE_ERROR(e.what());
993  }
994 }
995 
996 
997 void
999  bool ok = true;
1000  std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, 0, ok);
1001  if (!MSGlobals::gUsingInternalLanes && fromID[0] == ':') {
1002  return;
1003  }
1004 
1005  MSLink* link = 0;
1006  try {
1007  bool ok = true;
1008  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, 0, ok);
1009  const int fromLaneIdx = attrs.get<int>(SUMO_ATTR_FROM_LANE, 0, ok);
1010  const int toLaneIdx = attrs.get<int>(SUMO_ATTR_TO_LANE, 0, ok);
1011  LinkDirection dir = parseLinkDir(attrs.get<std::string>(SUMO_ATTR_DIR, 0, ok));
1012  LinkState state = parseLinkState(attrs.get<std::string>(SUMO_ATTR_STATE, 0, ok));
1013  bool keepClear = attrs.getOpt<bool>(SUMO_ATTR_KEEP_CLEAR, 0, ok, true);
1014  std::string tlID = attrs.getOpt<std::string>(SUMO_ATTR_TLID, 0, ok, "");
1015 #ifdef HAVE_INTERNAL_LANES
1016  std::string viaID = attrs.getOpt<std::string>(SUMO_ATTR_VIA, 0, ok, "");
1017 #endif
1018 
1019  MSEdge* from = MSEdge::dictionary(fromID);
1020  if (from == 0) {
1021  WRITE_ERROR("Unknown from-edge '" + fromID + "' in connection");
1022  return;
1023  }
1024  MSEdge* to = MSEdge::dictionary(toID);
1025  if (to == 0) {
1026  WRITE_ERROR("Unknown to-edge '" + toID + "' in connection");
1027  return;
1028  }
1029  if (fromLaneIdx < 0 || fromLaneIdx >= (int)from->getLanes().size() ||
1030  toLaneIdx < 0 || toLaneIdx >= (int)to->getLanes().size()) {
1031  WRITE_ERROR("Invalid lane index in connection from '" + from->getID() + "' to '" + to->getID() + "'.");
1032  return;
1033  }
1034  MSLane* fromLane = from->getLanes()[fromLaneIdx];
1035  MSLane* toLane = to->getLanes()[toLaneIdx];
1036  assert(fromLane);
1037  assert(toLane);
1038 
1039  MSTrafficLightLogic* logic = 0;
1040  int tlLinkIdx = -1;
1041  if (tlID != "") {
1042  tlLinkIdx = attrs.get<int>(SUMO_ATTR_TLLINKINDEX, 0, ok);
1043  // make sure that the index is in range
1045  if ((tlLinkIdx < 0 || tlLinkIdx >= (int)logic->getCurrentPhaseDef().getState().size())
1046  && logic->getLogicType() != "railSignal"
1047  && logic->getLogicType() != "railCrossing") {
1048  WRITE_ERROR("Invalid " + toString(SUMO_ATTR_TLLINKINDEX) + " '" + toString(tlLinkIdx) +
1049  "' in connection controlled by '" + tlID + "'");
1050  return;
1051  }
1052  if (!ok) {
1053  return;
1054  }
1055  }
1056  SUMOReal length = fromLane->getShape()[-1].distanceTo(toLane->getShape()[0]);
1057 
1058  // build the link
1059 #ifdef HAVE_INTERNAL_LANES
1060  MSLane* via = 0;
1061  if (viaID != "" && MSGlobals::gUsingInternalLanes) {
1062  via = MSLane::dictionary(viaID);
1063  if (via == 0) {
1064  WRITE_ERROR("An unknown lane ('" + viaID +
1065  "') should be set as a via-lane for lane '" + toLane->getID() + "'.");
1066  return;
1067  }
1068  length = via->getLength();
1069  }
1070  link = new MSLink(fromLane, toLane, via, dir, state, length, keepClear, logic, tlLinkIdx);
1071  if (via != 0) {
1072  via->addIncomingLane(fromLane, link);
1073  } else {
1074  toLane->addIncomingLane(fromLane, link);
1075  }
1076 #else
1077  link = new MSLink(fromLane, toLane, dir, state, length, keepClear, logic, tlLinkIdx);
1078  toLane->addIncomingLane(fromLane, link);
1079 #endif
1080  toLane->addApproachingLane(fromLane, myNetworkVersion < 0.25);
1081 
1082  // if a traffic light is responsible for it, inform the traffic light
1083  // check whether this link is controlled by a traffic light
1084  // we can not reuse logic here because it might be an inactive one
1085  if (tlID != "") {
1086  myJunctionControlBuilder.getTLLogic(tlID).addLink(link, fromLane, tlLinkIdx);
1087  }
1088  // add the link
1089  fromLane->addLink(link);
1090 
1091  } catch (InvalidArgument& e) {
1092  WRITE_ERROR(e.what());
1093  }
1094 }
1095 
1096 
1098 NLHandler::parseLinkDir(const std::string& dir) {
1099  if (SUMOXMLDefinitions::LinkDirections.hasString(dir)) {
1101  } else {
1102  throw InvalidArgument("Unrecognised link direction '" + dir + "'.");
1103  }
1104 }
1105 
1106 
1107 LinkState
1108 NLHandler::parseLinkState(const std::string& state) {
1109  if (SUMOXMLDefinitions::LinkStates.hasString(state)) {
1110  return SUMOXMLDefinitions::LinkStates.get(state);
1111  } else {
1112  if (state == "t") { // legacy networks
1113  // WRITE_WARNING("Obsolete link state 't'. Use 'o' instead");
1115  } else {
1116  throw InvalidArgument("Unrecognised link state '" + state + "'.");
1117  }
1118  }
1119 }
1120 
1121 
1122 // ----------------------------------
1123 void
1125  if (myNetIsLoaded) {
1126  //WRITE_WARNING("POIs and Polygons should be loaded using option --po-files")
1127  return;
1128  }
1129  bool ok = true;
1131  Boundary convBoundary = attrs.get<Boundary>(SUMO_ATTR_CONV_BOUNDARY, 0, ok);
1132  Boundary origBoundary = attrs.get<Boundary>(SUMO_ATTR_ORIG_BOUNDARY, 0, ok);
1133  std::string proj = attrs.get<std::string>(SUMO_ATTR_ORIG_PROJ, 0, ok);
1134  if (ok) {
1135  Position networkOffset = s[0];
1136  GeoConvHelper::init(proj, networkOffset, origBoundary, convBoundary);
1137  if (OptionsCont::getOptions().getBool("fcd-output.geo") && !GeoConvHelper::getFinal().usingGeoProjection()) {
1138  WRITE_WARNING("no valid geo projection loaded from network. fcd-output.geo will not work");
1139  }
1140  }
1141 }
1142 
1143 
1144 void
1146  bool ok = true;
1147  myCurrentIsBroken = false;
1148  // get the id, report an error if not given or empty...
1149  myCurrentDistrictID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
1150  if (!ok) {
1151  myCurrentIsBroken = true;
1152  return;
1153  }
1154  try {
1156  if (!MSEdge::dictionary(myCurrentDistrictID + "-sink", sink)) {
1157  delete sink;
1158  throw InvalidArgument("Another edge with the id '" + myCurrentDistrictID + "-sink' exists.");
1159  }
1160  sink->initialize(new std::vector<MSLane*>());
1162  if (!MSEdge::dictionary(myCurrentDistrictID + "-source", source)) {
1163  delete source;
1164  throw InvalidArgument("Another edge with the id '" + myCurrentDistrictID + "-source' exists.");
1165  }
1166  source->initialize(new std::vector<MSLane*>());
1167  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
1168  std::vector<std::string> desc = attrs.getStringVector(SUMO_ATTR_EDGES);
1169  for (std::vector<std::string>::const_iterator i = desc.begin(); i != desc.end(); ++i) {
1170  MSEdge* edge = MSEdge::dictionary(*i);
1171  // check whether the edge exists
1172  if (edge == 0) {
1173  throw InvalidArgument("The edge '" + *i + "' within district '" + myCurrentDistrictID + "' is not known.");
1174  }
1175  source->addSuccessor(edge);
1176  edge->addSuccessor(sink);
1177  }
1178  }
1179  if (attrs.hasAttribute(SUMO_ATTR_SHAPE)) {
1181  if (shape.size() != 0) {
1182  if (!myNet.getShapeContainer().addPolygon(myCurrentDistrictID, "taz", RGBColor::parseColor("1.0,.33,.33"), 0, 0, "", shape, false)) {
1183  WRITE_WARNING("Skipping visualization of taz '" + myCurrentDistrictID + "', polygon already exists.");
1184  }
1185  }
1186  }
1187  } catch (InvalidArgument& e) {
1188  WRITE_ERROR(e.what());
1189  myCurrentIsBroken = true;
1190  }
1191 }
1192 
1193 
1194 void
1195 NLHandler::addDistrictEdge(const SUMOSAXAttributes& attrs, bool isSource) {
1196  if (myCurrentIsBroken) {
1197  // earlier error
1198  return;
1199  }
1200  bool ok = true;
1201  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, myCurrentDistrictID.c_str(), ok);
1202  MSEdge* succ = MSEdge::dictionary(id);
1203  if (succ != 0) {
1204  // connect edge
1205  if (isSource) {
1206  MSEdge::dictionary(myCurrentDistrictID + "-source")->addSuccessor(succ);
1207  } else {
1208  succ->addSuccessor(MSEdge::dictionary(myCurrentDistrictID + "-sink"));
1209  }
1210  } else {
1211  WRITE_ERROR("At district '" + myCurrentDistrictID + "': succeeding edge '" + id + "' does not exist.");
1212  }
1213 }
1214 
1215 
1216 void
1218  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
1219  std::vector<std::string> edgeIDs = attrs.getStringVector(SUMO_ATTR_EDGES);
1220  for (std::vector<std::string>::iterator it = edgeIDs.begin(); it != edgeIDs.end(); ++it) {
1221  MSEdge* edge = MSEdge::dictionary(*it);
1222  if (edge == 0) {
1223  WRITE_ERROR("Unknown edge '" + (*it) + "' in roundabout");
1224  } else {
1225  edge->markAsRoundabout();
1226  }
1227  }
1228  } else {
1229  WRITE_ERROR("Empty edges in roundabout.");
1230  }
1231 }
1232 
1233 
1234 // ----------------------------------
1235 void
1237  try {
1239  } catch (InvalidArgument& e) {
1240  WRITE_ERROR(e.what());
1241  }
1242 }
1243 
1244 
1245 void
1247  if (!myCurrentIsBroken) {
1248  try {
1250  } catch (InvalidArgument& e) {
1251  WRITE_ERROR(e.what());
1252  myCurrentIsBroken = true;
1253  }
1254  }
1255  myCurrentWAUTID = "";
1256 }
1257 
1258 
1259 Position
1260 NLShapeHandler::getLanePos(const std::string& poiID, const std::string& laneID, SUMOReal lanePos) {
1261  MSLane* lane = MSLane::dictionary(laneID);
1262  if (lane == 0) {
1263  WRITE_ERROR("Lane '" + laneID + "' to place poi '" + poiID + "' on is not known.");
1264  return Position::INVALID;
1265  }
1266  if (lanePos < 0) {
1267  lanePos = lane->getLength() + lanePos;
1268  }
1269  return lane->geometryPositionAtOffset(lanePos);
1270 }
1271 /****************************************************************************/
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:914
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:861
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:319
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
void initialize(const std::vector< MSLane * > *lanes)
Initialize the edge.
Definition: MSEdge.cpp:110
bool myCurrentIsBroken
Definition: NLHandler.h:330
void addIncoming(MSEdge *edge)
Definition: MSJunction.h:113
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
void parseLanes(const std::string &junctionID, const std::string &def, std::vector< MSLane * > &into, bool &ok)
Definition: NLHandler.cpp:500
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:475
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:189
virtual void addVTypeProbeDetector(const SUMOSAXAttributes &attrs)
Builds a vtype-detector using the given specification.
Definition: NLHandler.cpp:818
void addRoundabout(const SUMOSAXAttributes &attrs)
Definition: NLHandler.cpp:1217
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.
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: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:1500
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:666
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 addLink(MSLink *link, MSLane *lane, int pos)
void beginEdgeParsing(const SUMOSAXAttributes &attrs)
begins the processing of an edge
Definition: NLHandler.cpp:297
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:313
EdgeBasicFunction
Defines possible edge types.
Definition: MSEdge.h:89
void closeWAUT(const std::string &wautid)
Closes loading of a WAUT.
const Position geometryPositionAtOffset(SUMOReal offset, SUMOReal lateralOffset=0) const
Definition: MSLane.h:439
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:1236
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: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
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
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.
int getNumberOfLoadedPhases() const
return the number of phases loaded so far (for error reporting)
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
void closeWAUT()
Definition: NLHandler.cpp:1246
void addParam(const SUMOSAXAttributes &attrs)
Definition: NLHandler.cpp:520
void addDistrict(const SUMOSAXAttributes &attrs)
Definition: NLHandler.cpp:1145
The state of a link.
static StringBijection< LinkDirection > LinkDirections
void addApproachingLane(MSLane *lane, bool warnMultiCon)
Definition: MSLane.cpp:1510
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A road/street connecting two junctions.
Definition: MSEdge.h:80
void setLocation(const SUMOSAXAttributes &attrs)
Parses network location description.
Definition: NLHandler.cpp:1124
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
const std::string & getFileName() const
returns the current file name
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
MSTrafficLightLogic * getActive() const
void addE3Entry(const SUMOSAXAttributes &attrs)
Adds an entry to the currently processed e3 detector.
Definition: NLHandler.cpp:937
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:950
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:1260
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 setPermissionsFound()
Labels the network to contain vehicle class permissions.
Definition: MSNet.h:180
void addConnection(const SUMOSAXAttributes &attrs)
adds a connection
Definition: NLHandler.cpp:998
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:1098
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:55
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;.
virtual void addNeigh(const std::string id)
Adds a neighbor to the current lane.
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 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:1226
virtual void addInstantE1Detector(const SUMOSAXAttributes &attrs)
Builds an e1 detector using the given specification.
Definition: NLHandler.cpp:793
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:838
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.
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:1195
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:1108
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:388
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:422
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.
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:240
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:636
virtual void addEdgeLaneMeanData(const SUMOSAXAttributes &attrs, int objecttype)
Builds edge or lane base mean data collector using the given specification.
Definition: NLHandler.cpp:963
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
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: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.
NLJunctionControlBuilder & myJunctionControlBuilder
The junction builder to use.
Definition: NLHandler.h:310
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: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.