Eclipse SUMO - Simulation of Urban MObility
NWWriter_SUMO.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // Exporter writing networks using the SUMO format
22 /****************************************************************************/
23 #include <config.h>
24 #include <cmath>
25 #include <algorithm>
29 #include <utils/common/ToString.h>
34 #include <netbuild/NBEdge.h>
35 #include <netbuild/NBEdgeCont.h>
36 #include <netbuild/NBNode.h>
37 #include <netbuild/NBNodeCont.h>
38 #include <netbuild/NBNetBuilder.h>
40 #include <netbuild/NBDistrict.h>
41 #include <netbuild/NBHelpers.h>
42 #include "NWFrame.h"
43 #include "NWWriter_SUMO.h"
44 
45 
46 //#define DEBUG_OPPOSITE_INTERNAL
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
51 // ---------------------------------------------------------------------------
52 // static methods
53 // ---------------------------------------------------------------------------
54 void
56  // check whether a sumo net-file shall be generated
57  if (!oc.isSet("output-file")) {
58  return;
59  }
60  OutputDevice& device = OutputDevice::getDevice(oc.getString("output-file"));
61  std::map<SumoXMLAttr, std::string> attrs;
63  if (oc.getBool("lefthand") != oc.getBool("flip-y-axis")) {
64  attrs[SUMO_ATTR_LEFTHAND] = "true";
65  } else if (oc.getBool("lefthand")) {
66  // network was flipped, correct written link directions
68  OptionsCont::getOptions().set("lefthand", "false");
69  }
70  const int cornerDetail = oc.getInt("junctions.corner-detail");
71  if (cornerDetail > 0) {
72  attrs[SUMO_ATTR_CORNERDETAIL] = toString(cornerDetail);
73  }
74  if (!oc.isDefault("junctions.internal-link-detail")) {
75  attrs[SUMO_ATTR_LINKDETAIL] = toString(oc.getInt("junctions.internal-link-detail"));
76  }
77  if (oc.getBool("rectangular-lane-cut")) {
78  attrs[SUMO_ATTR_RECTANGULAR_LANE_CUT] = "true";
79  }
80  if (oc.getBool("crossings.guess") || oc.getBool("walkingareas")) {
81  attrs[SUMO_ATTR_WALKINGAREAS] = "true";
82  }
83  if (oc.getFloat("junctions.limit-turn-speed") > 0) {
84  attrs[SUMO_ATTR_LIMIT_TURN_SPEED] = toString(oc.getFloat("junctions.limit-turn-speed"));
85  }
86  if (!oc.isDefault("check-lane-foes.all")) {
87  attrs[SUMO_ATTR_CHECKLANEFOES_ALL] = toString(oc.getBool("check-lane-foes.all"));
88  }
89  if (!oc.isDefault("check-lane-foes.roundabout")) {
90  attrs[SUMO_ATTR_CHECKLANEFOES_ROUNDABOUT] = toString(oc.getBool("check-lane-foes.roundabout"));
91  }
92  if (!oc.isDefault("tls.ignore-internal-junction-jam")) {
93  attrs[SUMO_ATTR_TLS_IGNORE_INTERNAL_JUNCTION_JAM] = toString(oc.getBool("tls.ignore-internal-junction-jam"));
94  }
95  if (oc.getString("default.spreadtype") != "right") {
96  attrs[SUMO_ATTR_SPREADTYPE] = oc.getString("default.spreadtype");
97  }
98  if (oc.exists("geometry.avoid-overlap") && !oc.getBool("geometry.avoid-overlap")) {
99  attrs[SUMO_ATTR_AVOID_OVERLAP] = toString(oc.getBool("geometry.avoid-overlap"));
100  }
101  if (oc.exists("junctions.higher-speed") && oc.getBool("junctions.higher-speed")) {
102  attrs[SUMO_ATTR_HIGHER_SPEED] = toString(oc.getBool("junctions.higher-speed"));
103  }
104  if (oc.exists("internal-junctions.vehicle-width") && !oc.isDefault("internal-junctions.vehicle-width")) {
105  attrs[SUMO_ATTR_INTERNAL_JUNCTIONS_VEHICLE_WIDTH] = toString(oc.getFloat("internal-junctions.vehicle-width"));
106  }
107  device.writeXMLHeader("net", "net_file.xsd", attrs); // street names may contain non-ascii chars
108  device.lf();
109  // get involved container
110  const NBNodeCont& nc = nb.getNodeCont();
111  const NBEdgeCont& ec = nb.getEdgeCont();
112  const NBDistrictCont& dc = nb.getDistrictCont();
113 
114  // write network offsets and projection
116 
117  // write edge types and restrictions
118  nb.getTypeCont().writeEdgeTypes(device);
119 
120  // write inner lanes
121  if (!oc.getBool("no-internal-links")) {
122  bool hadAny = false;
123  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
124  hadAny |= writeInternalEdges(device, ec, *(*i).second);
125  }
126  if (hadAny) {
127  device.lf();
128  }
129  }
130 
131  // write edges with lanes and connected edges
132  bool noNames = !oc.getBool("output.street-names");
133  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
134  writeEdge(device, *(*i).second, noNames);
135  }
136  device.lf();
137 
138  // write tls logics
139  writeTrafficLights(device, nb.getTLLogicCont());
140 
141  // write the nodes (junctions)
142  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
143  writeJunction(device, *(*i).second);
144  }
145  device.lf();
146  const bool includeInternal = !oc.getBool("no-internal-links");
147  if (includeInternal) {
148  // ... internal nodes if not unwanted
149  bool hadAny = false;
150  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
151  hadAny |= writeInternalNodes(device, *(*i).second);
152  }
153  if (hadAny) {
154  device.lf();
155  }
156  }
157 
158  // write the successors of lanes
159  int numConnections = 0;
160  for (std::map<std::string, NBEdge*>::const_iterator it_edge = ec.begin(); it_edge != ec.end(); it_edge++) {
161  NBEdge* from = it_edge->second;
162  const std::vector<NBEdge::Connection> connections = from->getConnections();
163  numConnections += (int)connections.size();
164  for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); it_c++) {
165  writeConnection(device, *from, *it_c, includeInternal);
166  }
167  }
168  if (numConnections > 0) {
169  device.lf();
170  }
171  if (includeInternal) {
172  // ... internal successors if not unwanted
173  bool hadAny = false;
174  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
175  hadAny |= writeInternalConnections(device, *(*i).second);
176  }
177  if (hadAny) {
178  device.lf();
179  }
180  }
181  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
182  NBNode* node = (*i).second;
183  // write connections from pedestrian crossings
184  std::vector<NBNode::Crossing*> crossings = node->getCrossings();
185  for (auto c : crossings) {
186  NWWriter_SUMO::writeInternalConnection(device, c->id, c->nextWalkingArea, 0, 0, "", LinkDirection::STRAIGHT, c->tlID, c->tlLinkIndex2);
187  }
188  // write connections from pedestrian walking areas
189  for (const NBNode::WalkingArea& wa : node->getWalkingAreas()) {
190  for (const std::string& cID : wa.nextCrossings) {
191  const NBNode::Crossing& nextCrossing = *node->getCrossing(cID);
192  // connection to next crossing (may be tls-controlled)
194  device.writeAttr(SUMO_ATTR_FROM, wa.id);
195  device.writeAttr(SUMO_ATTR_TO, cID);
196  device.writeAttr(SUMO_ATTR_FROM_LANE, 0);
197  device.writeAttr(SUMO_ATTR_TO_LANE, 0);
198  if (nextCrossing.tlID != "") {
199  device.writeAttr(SUMO_ATTR_TLID, nextCrossing.tlID);
200  assert(nextCrossing.tlLinkIndex >= 0);
201  device.writeAttr(SUMO_ATTR_TLLINKINDEX, nextCrossing.tlLinkIndex);
202  }
205  device.closeTag();
206  }
207  // optional connections from/to sidewalk
208  std::string edgeID;
209  int laneIndex;
210  for (const std::string& sw : wa.nextSidewalks) {
211  NBHelpers::interpretLaneID(sw, edgeID, laneIndex);
212  NWWriter_SUMO::writeInternalConnection(device, wa.id, edgeID, 0, laneIndex, "");
213  }
214  for (const std::string& sw : wa.prevSidewalks) {
215  NBHelpers::interpretLaneID(sw, edgeID, laneIndex);
216  NWWriter_SUMO::writeInternalConnection(device, edgeID, wa.id, laneIndex, 0, "");
217  }
218  }
219  }
220 
221  // write loaded prohibitions
222  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
223  writeProhibitions(device, i->second->getProhibitions());
224  }
225 
226  // write roundabout information
227  writeRoundabouts(device, ec.getRoundabouts(), ec);
228 
229  // write the districts
230  if (dc.size() != 0 && oc.isDefault("taz-output")) {
231  WRITE_WARNING("Embedding TAZ-data inside the network is deprecated. Use option --taz-output instead");
232  for (std::map<std::string, NBDistrict*>::const_iterator i = dc.begin(); i != dc.end(); i++) {
233  writeDistrict(device, *(*i).second);
234  }
235  device.lf();
236  }
237  device.close();
238 }
239 
240 
241 std::string
242 NWWriter_SUMO::getOppositeInternalID(const NBEdgeCont& ec, const NBEdge* from, const NBEdge::Connection& con, double& oppositeLength) {
243  const NBEdge::Lane& succ = con.toEdge->getLanes()[con.toLane];
244  const NBEdge::Lane& pred = from->getLanes()[con.fromLane];
245  const bool lefthand = OptionsCont::getOptions().getBool("lefthand");
246  if (succ.oppositeID != "" && succ.oppositeID != "-" && pred.oppositeID != "" && pred.oppositeID != "-") {
247 #ifdef DEBUG_OPPOSITE_INTERNAL
248  std::cout << "getOppositeInternalID con=" << con.getDescription(from) << " (" << con.getInternalLaneID() << ")\n";
249 #endif
250  // find the connection that connects succ.oppositeID to pred.oppositeID
251  const NBEdge* succOpp = ec.retrieve(succ.oppositeID.substr(0, succ.oppositeID.rfind("_")));
252  const NBEdge* predOpp = ec.retrieve(pred.oppositeID.substr(0, pred.oppositeID.rfind("_")));
253  assert(succOpp != 0);
254  assert(predOpp != 0);
255  const std::vector<NBEdge::Connection>& connections = succOpp->getConnections();
256  for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); it_c++) {
257  const NBEdge::Connection& conOpp = *it_c;
258  if (succOpp != from // turnaround
259  && predOpp == conOpp.toEdge
260  && succOpp->getLaneID(conOpp.fromLane) == succ.oppositeID
261  && predOpp->getLaneID(conOpp.toLane) == pred.oppositeID
262  && from->getToNode()->getDirection(from, con.toEdge, lefthand) == LinkDirection::STRAIGHT
263  && from->getToNode()->getDirection(succOpp, predOpp, lefthand) == LinkDirection::STRAIGHT
264  ) {
265 #ifdef DEBUG_OPPOSITE_INTERNAL
266  std::cout << " found " << conOpp.getInternalLaneID() << "\n";
267 #endif
268  oppositeLength = conOpp.length;
269  return conOpp.getInternalLaneID();
270  } else {
271  /*
272  #ifdef DEBUG_OPPOSITE_INTERNAL
273  std::cout << " rejected " << conOpp.getInternalLaneID()
274  << "\n succ.oppositeID=" << succ.oppositeID
275  << "\n succOppLane=" << succOpp->getLaneID(conOpp.fromLane)
276  << "\n pred.oppositeID=" << pred.oppositeID
277  << "\n predOppLane=" << predOpp->getLaneID(conOpp.toLane)
278  << "\n predOpp=" << predOpp->getID()
279  << "\n conOppTo=" << conOpp.toEdge->getID()
280  << "\n len1=" << con.shape.length()
281  << "\n len2=" << conOpp.shape.length()
282  << "\n";
283  #endif
284  */
285  }
286  }
287  return "";
288  } else {
289  return "";
290  }
291 }
292 
293 
294 bool
296  bool ret = false;
297  const EdgeVector& incoming = n.getIncomingEdges();
298  // first pass: determine opposite internal edges and average their length
299  std::map<std::string, std::string> oppositeLaneID;
300  std::map<std::string, double> oppositeLengths;
301  for (NBEdge* e : incoming) {
302  for (const NBEdge::Connection& c : e->getConnections()) {
303  double oppositeLength = 0;
304  const std::string op = getOppositeInternalID(ec, e, c, oppositeLength);
305  oppositeLaneID[c.getInternalLaneID()] = op;
306  if (op != "") {
307  oppositeLengths[c.id] = oppositeLength;
308  }
309  }
310  }
311  if (oppositeLengths.size() > 0) {
312  for (NBEdge* e : incoming) {
313  for (NBEdge::Connection& c : e->getConnections()) {
314  if (oppositeLengths.count(c.id) > 0) {
315  c.length = (c.length + oppositeLengths[c.id]) / 2;
316  }
317  }
318  }
319  }
320 
321  for (NBEdge* e : incoming) {
322  const std::vector<NBEdge::Connection>& elv = e->getConnections();
323  if (elv.size() > 0) {
324  bool haveVia = false;
325  std::string edgeID = "";
326  // second pass: write non-via edges
327  for (const NBEdge::Connection& k : elv) {
328  if (k.toEdge == nullptr) {
329  assert(false); // should never happen. tell me when it does
330  continue;
331  }
332  if (edgeID != k.id) {
333  if (edgeID != "") {
334  // close the previous edge
335  into.closeTag();
336  }
337  edgeID = k.id;
338  into.openTag(SUMO_TAG_EDGE);
339  into.writeAttr(SUMO_ATTR_ID, edgeID);
341  if (k.edgeType != "") {
342  into.writeAttr(SUMO_ATTR_TYPE, k.edgeType);
343  }
344  if (e->isBidiRail() && k.toEdge->isBidiRail() &&
345  e != k.toEdge->getTurnDestination(true)) {
346  try {
348  0, e->getTurnDestination(true), 0);
349  into.writeAttr(SUMO_ATTR_BIDI, bidiCon.id);
350  } catch (ProcessError&) {
351  WRITE_WARNINGF("Could not find bidi-connection for edge '%'", edgeID)
352  }
353  }
354  // open a new edge
355  }
356  // to avoid changing to an internal lane which has a successor
357  // with the wrong permissions we need to inherit them from the successor
358  const NBEdge::Lane& successor = k.toEdge->getLanes()[k.toLane];
359  SVCPermissions permissions = (k.permissions != SVC_UNSPECIFIED) ? k.permissions : (
360  successor.permissions & e->getPermissions(k.fromLane));
361  SVCPermissions changeLeft = k.changeLeft != SVC_UNSPECIFIED ? k.changeLeft : SVCAll;
362  SVCPermissions changeRight = k.changeRight != SVC_UNSPECIFIED ? k.changeRight : SVCAll;
363  const double width = n.isConstantWidthTransition() && e->getNumLanes() > k.toEdge->getNumLanes() ? e->getLaneWidth(k.fromLane) : successor.width;
364  writeLane(into, k.getInternalLaneID(), k.vmax,
365  permissions, successor.preferred,
366  changeLeft, changeRight,
368  StopOffset(), width, k.shape, &k,
369  k.length, k.internalLaneIndex, oppositeLaneID[k.getInternalLaneID()], "");
370  haveVia = haveVia || k.haveVia;
371  }
372  ret = true;
373  into.closeTag(); // close the last edge
374  // third pass: write via edges
375  if (haveVia) {
376  for (const NBEdge::Connection& k : elv) {
377  if (!k.haveVia) {
378  continue;
379  }
380  if (k.toEdge == nullptr) {
381  assert(false); // should never happen. tell me when it does
382  continue;
383  }
384  const NBEdge::Lane& successor = k.toEdge->getLanes()[k.toLane];
385  into.openTag(SUMO_TAG_EDGE);
386  into.writeAttr(SUMO_ATTR_ID, k.viaID);
388  if (k.edgeType != "") {
389  into.writeAttr(SUMO_ATTR_TYPE, k.edgeType);
390  }
391  SVCPermissions permissions = (k.permissions != SVC_UNSPECIFIED) ? k.permissions : (
392  successor.permissions & e->getPermissions(k.fromLane));
393  writeLane(into, k.viaID + "_0", k.vmax, permissions, successor.preferred,
394  SVCAll, SVCAll, // #XXX todo
396  StopOffset(), successor.width, k.viaShape, &k,
397  MAX2(k.viaLength, POSITION_EPS), // microsim needs positive length
398  0, "", "");
399  into.closeTag();
400  }
401  }
402  }
403  }
404  // write pedestrian crossings
405  for (auto c : n.getCrossings()) {
406  into.openTag(SUMO_TAG_EDGE);
407  into.writeAttr(SUMO_ATTR_ID, c->id);
409  into.writeAttr(SUMO_ATTR_CROSSING_EDGES, c->edges);
410  writeLane(into, c->id + "_0", 1, SVC_PEDESTRIAN, 0, SVCAll, SVCAll,
412  StopOffset(), c->width, c->shape, nullptr,
413  MAX2(c->shape.length(), POSITION_EPS), 0, "", "", false, c->customShape.size() != 0);
414  into.closeTag();
415  }
416  // write pedestrian walking areas
417  const std::vector<NBNode::WalkingArea>& WalkingAreas = n.getWalkingAreas();
418  for (std::vector<NBNode::WalkingArea>::const_iterator it = WalkingAreas.begin(); it != WalkingAreas.end(); it++) {
419  const NBNode::WalkingArea& wa = *it;
420  into.openTag(SUMO_TAG_EDGE);
421  into.writeAttr(SUMO_ATTR_ID, wa.id);
423  writeLane(into, wa.id + "_0", 1, SVC_PEDESTRIAN, 0, SVCAll, SVCAll,
425  StopOffset(), wa.width, wa.shape, nullptr, wa.length, 0, "", "", false, wa.hasCustomShape);
426  into.closeTag();
427  }
428  return ret;
429 }
430 
431 
432 void
433 NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames) {
434  // write the edge's begin
437  into.writeAttr(SUMO_ATTR_TO, e.getToNode()->getID());
438  if (!noNames && e.getStreetName() != "") {
440  }
442  if (e.getTypeID() != "") {
444  }
445  if (e.isMacroscopicConnector()) {
447  }
448  // write the spread type if not default ("right")
451  }
452  if (e.hasLoadedLength()) {
454  }
455  if (!e.hasDefaultGeometry()) {
457  }
458  if (e.getEdgeStopOffset().isDefined()) {
460  }
461  if (e.isBidiRail()) {
463  }
464  if (e.getDistance() != 0) {
466  }
467 
468  // write the lanes
469  const std::vector<NBEdge::Lane>& lanes = e.getLanes();
470 
471  const double length = e.getFinalLength();
472  double startOffset = e.isBidiRail() ? e.getTurnDestination(true)->getEndOffset() : 0;
473  for (int i = 0; i < (int) lanes.size(); i++) {
474  const NBEdge::Lane& l = lanes[i];
475  StopOffset stopOffset;
476  if (l.laneStopOffset != e.getEdgeStopOffset()) {
477  stopOffset = l.laneStopOffset;
478  }
479  writeLane(into, e.getLaneID(i), l.speed,
480  l.permissions, l.preferred,
481  l.changeLeft, l.changeRight,
482  startOffset, l.endOffset,
483  stopOffset, l.width, l.shape, &l,
484  length, i, l.oppositeID, l.type, l.accelRamp, l.customShape.size() > 0);
485  }
486  // close the edge
487  e.writeParams(into);
488  into.closeTag();
489 }
490 
491 
492 void
493 NWWriter_SUMO::writeLane(OutputDevice& into, const std::string& lID,
494  double speed, SVCPermissions permissions, SVCPermissions preferred,
495  SVCPermissions changeLeft, SVCPermissions changeRight,
496  double startOffset, double endOffset,
497  const StopOffset& stopOffset, double width, PositionVector shape,
498  const Parameterised* params, double length, int index,
499  const std::string& oppositeID,
500  const std::string& type,
501  bool accelRamp, bool customShape) {
502  // output the lane's attributes
504  // the first lane of an edge will be the depart lane
505  into.writeAttr(SUMO_ATTR_INDEX, index);
506  // write the list of allowed/disallowed vehicle classes
507  if (permissions != SVC_UNSPECIFIED) {
508  writePermissions(into, permissions);
509  }
510  writePreferences(into, preferred);
511  // some further information
512  if (speed == 0) {
513  WRITE_WARNINGF("Lane '%' has a maximum allowed speed of 0.", lID);
514  } else if (speed < 0) {
515  throw ProcessError("Negative allowed speed (" + toString(speed) + ") on lane '" + lID + "', use --speed.minimum to prevent this.");
516  }
517  into.writeAttr(SUMO_ATTR_SPEED, speed);
518  into.writeAttr(SUMO_ATTR_LENGTH, length);
519  if (endOffset != NBEdge::UNSPECIFIED_OFFSET) {
520  into.writeAttr(SUMO_ATTR_ENDOFFSET, endOffset);
521  }
522  if (width != NBEdge::UNSPECIFIED_WIDTH) {
523  into.writeAttr(SUMO_ATTR_WIDTH, width);
524  }
525  if (accelRamp) {
526  into.writeAttr<bool>(SUMO_ATTR_ACCELERATION, accelRamp);
527  }
528  if (customShape) {
529  into.writeAttr(SUMO_ATTR_CUSTOMSHAPE, true);
530  }
531  if (endOffset > 0 || startOffset > 0) {
532  if (startOffset + endOffset < shape.length()) {
533  shape = shape.getSubpart(startOffset, shape.length() - endOffset);
534  } else {
535  WRITE_ERROR("Invalid endOffset " + toString(endOffset) + " at lane '" + lID
536  + "' with length " + toString(shape.length()) + " (startOffset " + toString(startOffset) + ")");
537  if (!OptionsCont::getOptions().getBool("ignore-errors")) {
538  throw ProcessError();
539  }
540  }
541  }
542  into.writeAttr(SUMO_ATTR_SHAPE, shape);
543  if (type != "") {
544  into.writeAttr(SUMO_ATTR_TYPE, type);
545  }
546  if (changeLeft != SVC_UNSPECIFIED && changeLeft != SVCAll && changeLeft != SVC_IGNORING) {
548  }
549  if (changeRight != SVC_UNSPECIFIED && changeRight != SVCAll && changeRight != SVC_IGNORING) {
551  }
552  if (stopOffset.isDefined()) {
553  writeStopOffsets(into, stopOffset);
554  }
555 
556  if (oppositeID != "" && oppositeID != "-") {
557  into.openTag(SUMO_TAG_NEIGH);
558  into.writeAttr(SUMO_ATTR_LANE, oppositeID);
559  into.closeTag();
560  }
561 
562  if (params != nullptr) {
563  params->writeParams(into);
564  }
565 
566  into.closeTag();
567 }
568 
569 
570 void
572  // write the attributes
574  into.writeAttr(SUMO_ATTR_TYPE, n.getType());
576  // write the incoming lanes
577  std::vector<std::string> incLanes;
578  const std::vector<NBEdge*>& incoming = n.getIncomingEdges();
579  for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); ++i) {
580  int noLanes = (*i)->getNumLanes();
581  for (int j = 0; j < noLanes; j++) {
582  incLanes.push_back((*i)->getLaneID(j));
583  }
584  }
585  std::vector<NBNode::Crossing*> crossings = n.getCrossings();
586  std::set<std::string> prevWAs;
587  // avoid duplicates
588  for (auto c : crossings) {
589  if (prevWAs.count(c->prevWalkingArea) == 0) {
590  incLanes.push_back(c->prevWalkingArea + "_0");
591  prevWAs.insert(c->prevWalkingArea);
592  }
593  }
594  into.writeAttr(SUMO_ATTR_INCLANES, incLanes);
595  // write the internal lanes
596  std::vector<std::string> intLanes;
597  if (!OptionsCont::getOptions().getBool("no-internal-links")) {
598  for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
599  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
600  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
601  if ((*k).toEdge == nullptr) {
602  continue;
603  }
604  if (!(*k).haveVia) {
605  intLanes.push_back((*k).getInternalLaneID());
606  } else {
607  intLanes.push_back((*k).viaID + "_0");
608  }
609  }
610  }
611  }
613  for (auto c : crossings) {
614  intLanes.push_back(c->id + "_0");
615  }
616  }
617  into.writeAttr(SUMO_ATTR_INTLANES, intLanes);
618  // close writing
620  // write optional radius
623  }
624  // specify whether a custom shape was used
625  if (n.hasCustomShape()) {
626  into.writeAttr(SUMO_ATTR_CUSTOMSHAPE, true);
627  }
628  if (n.getRightOfWay() != RightOfWay::DEFAULT) {
629  into.writeAttr<std::string>(SUMO_ATTR_RIGHT_OF_WAY, toString(n.getRightOfWay()));
630  }
631  if (n.getFringeType() != FringeType::DEFAULT) {
632  into.writeAttr<std::string>(SUMO_ATTR_FRINGE, toString(n.getFringeType()));
633  }
634  if (n.getName() != "") {
635  into.writeAttr<std::string>(SUMO_ATTR_NAME, n.getName());
636  }
637  if (n.getType() != SumoXMLNodeType::DEAD_END) {
638  // write right-of-way logics
639  n.writeLogic(into);
640  }
641  n.writeParams(into);
642  into.closeTag();
643 }
644 
645 
646 bool
648  bool ret = false;
649  const std::vector<NBEdge*>& incoming = n.getIncomingEdges();
650  // build the list of internal lane ids
651  std::vector<std::string> internalLaneIDs;
652  std::map<std::string, std::string> viaIDs;
653  for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
654  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
655  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
656  if ((*k).toEdge != nullptr) {
657  internalLaneIDs.push_back((*k).getInternalLaneID());
658  viaIDs[(*k).getInternalLaneID()] = ((*k).viaID);
659  }
660  }
661  }
662  for (auto c : n.getCrossings()) {
663  internalLaneIDs.push_back(c->id + "_0");
664  }
665  // write the internal nodes
666  for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
667  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
668  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
669  if ((*k).toEdge == nullptr || !(*k).haveVia) {
670  continue;
671  }
672  Position pos = (*k).shape[-1];
673  into.openTag(SUMO_TAG_JUNCTION).writeAttr(SUMO_ATTR_ID, (*k).viaID + "_0");
675  NWFrame::writePositionLong(pos, into);
676  std::string incLanes = (*k).getInternalLaneID();
677  std::vector<std::string> foeIDs;
678  for (std::string incLane : (*k).foeIncomingLanes) {
679  if (incLane[0] == ':') {
680  // intersecting left turns
681  const int index = StringUtils::toInt(incLane.substr(1));
682  incLane = internalLaneIDs[index];
683  if (viaIDs[incLane] != "") {
684  foeIDs.push_back(viaIDs[incLane] + "_0");
685  }
686  }
687  incLanes += " " + incLane;
688  }
689  into.writeAttr(SUMO_ATTR_INCLANES, incLanes);
690  const std::vector<int>& foes = (*k).foeInternalLinks;
691  for (std::vector<int>::const_iterator it = foes.begin(); it != foes.end(); ++it) {
692  foeIDs.push_back(internalLaneIDs[*it]);
693  }
694  into.writeAttr(SUMO_ATTR_INTLANES, joinToString(foeIDs, " "));
695  into.closeTag();
696  ret = true;
697  }
698  }
699  return ret;
700 }
701 
702 
703 void
705  bool includeInternal, ConnectionStyle style, bool geoAccuracy) {
706  assert(c.toEdge != 0);
708  into.writeAttr(SUMO_ATTR_FROM, from.getID());
709  into.writeAttr(SUMO_ATTR_TO, c.toEdge->getID());
712  if (style != TLL) {
713  if (c.mayDefinitelyPass) {
715  }
716  if (c.keepClear == KEEPCLEAR_FALSE) {
717  into.writeAttr<bool>(SUMO_ATTR_KEEP_CLEAR, false);
718  }
721  }
722  if (c.permissions != SVC_UNSPECIFIED) {
723  writePermissions(into, c.permissions);
724  }
727  }
730  }
731  if (c.speed != NBEdge::UNSPECIFIED_SPEED) {
733  }
736  }
737  if (c.customShape.size() != 0) {
738  if (geoAccuracy) {
740  }
742  if (geoAccuracy) {
743  into.setPrecision();
744  }
745  }
746  if (c.uncontrolled != false) {
748  }
749  if (c.indirectLeft != false) {
751  }
752  if (c.edgeType != "") {
754  }
755  }
756  if (style != PLAIN) {
757  if (includeInternal) {
759  }
760  // set information about the controlling tl if any
761  if (c.tlID != "") {
762  into.writeAttr(SUMO_ATTR_TLID, c.tlID);
764  if (c.tlLinkIndex2 >= 0) {
766  }
767  }
768  }
769  if (style != TLL) {
770  if (style == SUMONET) {
771  // write the direction information
772  LinkDirection dir = from.getToNode()->getDirection(&from, c.toEdge, OptionsCont::getOptions().getBool("lefthand"));
773  assert(dir != LinkDirection::NODIR);
774  into.writeAttr(SUMO_ATTR_DIR, toString(dir));
775  // write the state information
776  const LinkState linkState = from.getToNode()->getLinkState(
777  &from, c.toEdge, c.fromLane, c.toLane, c.mayDefinitelyPass, c.tlID);
778  into.writeAttr(SUMO_ATTR_STATE, linkState);
779  if (linkState == LINKSTATE_MINOR
781  && c.toEdge->getJunctionPriority(c.toEdge->getToNode()) == NBEdge::JunctionPriority::ROUNDABOUT) {
782  const double visibilityDistance = OptionsCont::getOptions().getFloat("roundabouts.visibility-distance");
783  if (visibilityDistance != NBEdge::UNSPECIFIED_VISIBILITY_DISTANCE) {
784  into.writeAttr(SUMO_ATTR_VISIBILITY_DISTANCE, visibilityDistance);
785  }
786  }
787  }
790  }
791  }
792  c.writeParams(into);
793  into.closeTag();
794 }
795 
796 
797 bool
799  bool ret = false;
800  const bool lefthand = OptionsCont::getOptions().getBool("lefthand");
801  const std::vector<NBEdge*>& incoming = n.getIncomingEdges();
802  for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); ++i) {
803  NBEdge* from = *i;
804  const std::vector<NBEdge::Connection>& connections = from->getConnections();
805  for (std::vector<NBEdge::Connection>::const_iterator j = connections.begin(); j != connections.end(); ++j) {
806  const NBEdge::Connection& c = *j;
807  LinkDirection dir = n.getDirection(from, c.toEdge, lefthand);
808  assert(c.toEdge != 0);
809  if (c.haveVia) {
810  // internal split with optional signal
811  std::string tlID = "";
812  int linkIndex2 = NBConnection::InvalidTlIndex;
814  linkIndex2 = c.tlLinkIndex2;
815  tlID = c.tlID;
816  }
817  writeInternalConnection(into, c.id, c.toEdge->getID(), c.internalLaneIndex, c.toLane, c.viaID + "_0", dir, tlID, linkIndex2, false, c.visibility);
819  } else {
820  // no internal split
821  writeInternalConnection(into, c.id, c.toEdge->getID(), c.internalLaneIndex, c.toLane, "", dir);
822  }
823  ret = true;
824  }
825  }
826  return ret;
827 }
828 
829 
830 void
832  const std::string& from, const std::string& to,
833  int fromLane, int toLane, const std::string& via,
834  LinkDirection dir,
835  const std::string& tlID, int linkIndex,
836  bool minor,
837  double visibility) {
839  into.writeAttr(SUMO_ATTR_FROM, from);
840  into.writeAttr(SUMO_ATTR_TO, to);
841  into.writeAttr(SUMO_ATTR_FROM_LANE, fromLane);
842  into.writeAttr(SUMO_ATTR_TO_LANE, toLane);
843  if (via != "") {
844  into.writeAttr(SUMO_ATTR_VIA, via);
845  }
846  if (tlID != "" && linkIndex != NBConnection::InvalidTlIndex) {
847  // used for the reverse direction of pedestrian crossings
848  into.writeAttr(SUMO_ATTR_TLID, tlID);
849  into.writeAttr(SUMO_ATTR_TLLINKINDEX, linkIndex);
850  }
851  into.writeAttr(SUMO_ATTR_DIR, dir);
852  into.writeAttr(SUMO_ATTR_STATE, ((via != "" || minor) ? "m" : "M"));
853  if (visibility != NBEdge::UNSPECIFIED_VISIBILITY_DISTANCE) {
854  into.writeAttr(SUMO_ATTR_VISIBILITY_DISTANCE, visibility);
855  }
856  into.closeTag();
857 }
858 
859 
860 void
861 NWWriter_SUMO::writeRoundabouts(OutputDevice& into, const std::set<EdgeSet>& roundabouts,
862  const NBEdgeCont& ec) {
863  // make output deterministic
864  std::vector<std::vector<std::string> > edgeIDs;
865  for (std::set<EdgeSet>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
866  std::vector<std::string> tEdgeIDs;
867  for (EdgeSet::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
868  // the edges may have been erased from NBEdgeCont but their pointers are still valid
869  // we verify their existance in writeRoundabout()
870  tEdgeIDs.push_back((*j)->getID());
871  }
872  std::sort(tEdgeIDs.begin(), tEdgeIDs.end());
873  edgeIDs.push_back(tEdgeIDs);
874  }
875  std::sort(edgeIDs.begin(), edgeIDs.end());
876  // write
877  for (std::vector<std::vector<std::string> >::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) {
878  writeRoundabout(into, *i, ec);
879  }
880  if (roundabouts.size() != 0) {
881  into.lf();
882  }
883 }
884 
885 
886 void
887 NWWriter_SUMO::writeRoundabout(OutputDevice& into, const std::vector<std::string>& edgeIDs,
888  const NBEdgeCont& ec) {
889  std::vector<std::string> validEdgeIDs;
890  std::vector<std::string> invalidEdgeIDs;
891  std::vector<std::string> nodeIDs;
892  for (std::vector<std::string>::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) {
893  const NBEdge* edge = ec.retrieve(*i);
894  if (edge != nullptr) {
895  nodeIDs.push_back(edge->getToNode()->getID());
896  validEdgeIDs.push_back(edge->getID());
897  } else {
898  invalidEdgeIDs.push_back(*i);
899  }
900  }
901  std::sort(nodeIDs.begin(), nodeIDs.end());
902  if (validEdgeIDs.size() > 0) {
904  into.writeAttr(SUMO_ATTR_NODES, joinToString(nodeIDs, " "));
905  into.writeAttr(SUMO_ATTR_EDGES, joinToString(validEdgeIDs, " "));
906  into.closeTag();
907  if (invalidEdgeIDs.size() > 0) {
908  WRITE_WARNING("Writing incomplete roundabout. Edges: '"
909  + joinToString(invalidEdgeIDs, " ") + "' no longer exist'");
910  }
911  }
912 }
913 
914 
915 void
917  std::vector<double> sourceW = d.getSourceWeights();
919  std::vector<double> sinkW = d.getSinkWeights();
921  // write the head and the id of the district
923  if (d.getShape().size() > 0) {
925  }
926  // write all sources
927  const std::vector<NBEdge*>& sources = d.getSourceEdges();
928  for (int i = 0; i < (int)sources.size(); i++) {
929  // write the head and the id of the source
930  into.openTag(SUMO_TAG_TAZSOURCE).writeAttr(SUMO_ATTR_ID, sources[i]->getID()).writeAttr(SUMO_ATTR_WEIGHT, sourceW[i]);
931  into.closeTag();
932  }
933  // write all sinks
934  const std::vector<NBEdge*>& sinks = d.getSinkEdges();
935  for (int i = 0; i < (int)sinks.size(); i++) {
936  // write the head and the id of the sink
937  into.openTag(SUMO_TAG_TAZSINK).writeAttr(SUMO_ATTR_ID, sinks[i]->getID()).writeAttr(SUMO_ATTR_WEIGHT, sinkW[i]);
938  into.closeTag();
939  }
940  // write the tail
941  into.closeTag();
942 }
943 
944 
945 std::string
947  double time = STEPS2TIME(steps);
948  if (time == std::floor(time)) {
949  return toString(int(time));
950  } else {
951  return toString(time);
952  }
953 }
954 
955 
956 void
958  for (NBConnectionProhibits::const_iterator j = prohibitions.begin(); j != prohibitions.end(); j++) {
959  NBConnection prohibited = (*j).first;
960  const NBConnectionVector& prohibiting = (*j).second;
961  for (NBConnectionVector::const_iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
962  NBConnection prohibitor = *k;
966  into.closeTag();
967  }
968  }
969 }
970 
971 
972 std::string
974  return c.getFrom()->getID() + "->" + c.getTo()->getID();
975 }
976 
977 
978 void
980  std::vector<NBTrafficLightLogic*> logics = tllCont.getComputed();
981  for (NBTrafficLightLogic* logic : logics) {
982  writeTrafficLight(into, logic);
983  }
984  if (logics.size() > 0) {
985  into.lf();
986  }
987 }
988 
989 
990 void
993  into.writeAttr(SUMO_ATTR_ID, logic->getID());
994  into.writeAttr(SUMO_ATTR_TYPE, logic->getType());
997  // write the phases
998  const bool varPhaseLength = logic->getType() != TrafficLightType::STATIC;
999  for (const NBTrafficLightLogic::PhaseDefinition& phase : logic->getPhases()) {
1000  into.openTag(SUMO_TAG_PHASE);
1001  into.writeAttr(SUMO_ATTR_DURATION, writeSUMOTime(phase.duration));
1002  if (phase.duration < TIME2STEPS(10)) {
1003  into.writePadding(" ");
1004  }
1005  into.writeAttr(SUMO_ATTR_STATE, phase.state);
1006  if (varPhaseLength) {
1007  if (phase.minDur != NBTrafficLightDefinition::UNSPECIFIED_DURATION) {
1008  into.writeAttr(SUMO_ATTR_MINDURATION, writeSUMOTime(phase.minDur));
1009  }
1010  if (phase.maxDur != NBTrafficLightDefinition::UNSPECIFIED_DURATION) {
1011  into.writeAttr(SUMO_ATTR_MAXDURATION, writeSUMOTime(phase.maxDur));
1012  }
1013  }
1014  if (phase.name != "") {
1015  into.writeAttr(SUMO_ATTR_NAME, phase.name);
1016  }
1017  if (phase.next.size() > 0) {
1018  into.writeAttr(SUMO_ATTR_NEXT, phase.next);
1019  }
1020  into.closeTag();
1021  }
1022  // write params
1023  logic->writeParams(into);
1024  into.closeTag();
1025 }
1026 
1027 
1028 void
1030  if (stopOffset.isDefined()) {
1031  const std::string ss_vclasses = getVehicleClassNames(stopOffset.getPermissions());
1032  if (ss_vclasses.length() == 0) {
1033  // This stopOffset would have no effect...
1034  return;
1035  }
1037  const std::string ss_exceptions = getVehicleClassNames(~stopOffset.getPermissions());
1038  if (ss_vclasses.length() <= ss_exceptions.length()) {
1039  into.writeAttr(SUMO_ATTR_VCLASSES, ss_vclasses);
1040  } else {
1041  if (ss_exceptions.length() == 0) {
1042  into.writeAttr(SUMO_ATTR_VCLASSES, "all");
1043  } else {
1044  into.writeAttr(SUMO_ATTR_EXCEPTIONS, ss_exceptions);
1045  }
1046  }
1047  into.writeAttr(SUMO_ATTR_VALUE, stopOffset.getOffset());
1048  into.closeTag();
1049  }
1050 }
1051 
1052 
1053 /****************************************************************************/
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:281
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:288
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
std::map< NBConnection, NBConnectionVector > NBConnectionProhibits
Definition of a container for connection block dependencies Includes a list of all connections which ...
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
@ KEEPCLEAR_FALSE
Definition: NBCont.h:59
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
long long int SUMOTime
Definition: SUMOTime.h:32
const SVCPermissions SVCAll
all VClasses are allowed
const SVCPermissions SVC_UNSPECIFIED
permissions not specified
const std::string & getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a ' '.
void writePermissions(OutputDevice &into, SVCPermissions permissions)
writes allowed disallowed attributes if needed;
void writePreferences(OutputDevice &into, SVCPermissions preferred)
writes allowed disallowed attributes if needed;
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_PEDESTRIAN
pedestrian
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SUMO_TAG_PHASE
a single phase description
@ SUMO_TAG_STOPOFFSET
Information on vClass specific stop offsets at lane end.
@ SUMO_TAG_TAZ
a traffic assignment zone
@ SUMO_TAG_TAZSINK
a sink within a district (connection road)
@ SUMO_TAG_PROHIBITION
prohibition of circulation between two edges
@ SUMO_TAG_CONNECTION
connectio between two lanes
@ SUMO_TAG_ROUNDABOUT
roundabout defined in junction
@ SUMO_TAG_TLLOGIC
a traffic light logic
@ SUMO_TAG_JUNCTION
begin/end of the description of a junction
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ SUMO_TAG_TAZSOURCE
a source within a district (connection road)
@ SUMO_TAG_NEIGH
begin/end of the description of a neighboring lane
@ SUMO_TAG_EDGE
begin/end of the description of an edge
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
@ STRAIGHT
The link is a straight direction.
@ NODIR
The link has no direction (is a dead end link)
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
@ LINKSTATE_MAJOR
This is an uncontrolled, major link, may pass.
@ LINKSTATE_MINOR
This is an uncontrolled, minor link, has to brake.
@ SUMO_ATTR_LANE
@ SUMO_ATTR_NODES
a list of node ids, used for controlling joining
@ SUMO_ATTR_TLLINKINDEX2
link: the index of the opposite direction link of a pedestrian crossing
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_LINKDETAIL
@ SUMO_ATTR_VALUE
@ SUMO_ATTR_VIA
@ SUMO_ATTR_CORNERDETAIL
@ SUMO_ATTR_RADIUS
The turning radius at an intersection in m.
@ SUMO_ATTR_INDIRECT
Whether this connection is an indirect (left) turn.
@ SUMO_ATTR_RECTANGULAR_LANE_CUT
@ SUMO_ATTR_FROM_LANE
@ SUMO_ATTR_LIMIT_TURN_SPEED
@ SUMO_ATTR_CHECKLANEFOES_ROUNDABOUT
@ SUMO_ATTR_OFFSET
@ SUMO_ATTR_AVOID_OVERLAP
@ SUMO_ATTR_CUSTOMSHAPE
whether a given shape is user-defined
@ SUMO_ATTR_INTLANES
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_FRINGE
Fringe type of node.
@ SUMO_ATTR_BIDI
@ SUMO_ATTR_PROHIBITED
@ SUMO_ATTR_PRIORITY
@ SUMO_ATTR_SHAPE
edge: the shape in xml-definition
@ SUMO_ATTR_LEFTHAND
@ SUMO_ATTR_WEIGHT
@ SUMO_ATTR_NEXT
succesor phase index
@ SUMO_ATTR_INCLANES
@ SUMO_ATTR_CHANGE_LEFT
@ SUMO_ATTR_INDEX
@ SUMO_ATTR_VCLASSES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_EXCEPTIONS
@ SUMO_ATTR_CHECKLANEFOES_ALL
@ SUMO_ATTR_SPREADTYPE
The information about how to spread the lanes from the given position.
@ SUMO_ATTR_PASS
@ SUMO_ATTR_ENDOFFSET
@ SUMO_ATTR_HIGHER_SPEED
@ SUMO_ATTR_TO
@ SUMO_ATTR_FROM
@ SUMO_ATTR_ACCELERATION
@ SUMO_ATTR_CHANGE_RIGHT
@ SUMO_ATTR_TLID
link,node: the traffic light id responsible for this link
@ SUMO_ATTR_DISTANCE
@ SUMO_ATTR_TO_LANE
@ SUMO_ATTR_UNCONTROLLED
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_VERSION
@ SUMO_ATTR_ID
@ SUMO_ATTR_MAXDURATION
maximum duration of a phase
@ SUMO_ATTR_RIGHT_OF_WAY
How to compute right of way.
@ SUMO_ATTR_PROGRAMID
@ SUMO_ATTR_FUNCTION
@ SUMO_ATTR_VISIBILITY_DISTANCE
foe visibility distance of a link
@ SUMO_ATTR_PROHIBITOR
@ SUMO_ATTR_DURATION
@ SUMO_ATTR_CONTPOS
@ SUMO_ATTR_WIDTH
@ SUMO_ATTR_CROSSING_EDGES
the edges crossed by a pedestrian crossing
@ SUMO_ATTR_DIR
The abstract direction of a link.
@ SUMO_ATTR_TLS_IGNORE_INTERNAL_JUNCTION_JAM
@ SUMO_ATTR_TLLINKINDEX
link: the index of the link within the traffic light
@ SUMO_ATTR_MINDURATION
@ SUMO_ATTR_KEEP_CLEAR
Whether vehicles must keep the junction clear.
@ SUMO_ATTR_INTERNAL_JUNCTIONS_VEHICLE_WIDTH
@ SUMO_ATTR_STATE
The state of a link.
@ SUMO_ATTR_WALKINGAREAS
int gPrecisionGeo
Definition: StdDefs.cpp:26
const double NETWORK_VERSION
version for written networks and default version for loading
Definition: StdDefs.h:66
T MAX2(T a, T b)
Definition: StdDefs.h:80
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:269
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static void writeLocation(OutputDevice &into)
writes the location element
NBEdge * getFrom() const
returns the from-edge (start of the connection)
static const int InvalidTlIndex
Definition: NBConnection.h:123
NBEdge * getTo() const
returns the to-edge (end of the connection)
A container for districts.
std::map< std::string, NBDistrict * >::const_iterator begin() const
Returns the pointer to the begin of the stored districts.
std::map< std::string, NBDistrict * >::const_iterator end() const
Returns the pointer to the end of the stored districts.
int size() const
Returns the number of districts inside the container.
A class representing a single district.
Definition: NBDistrict.h:62
const std::vector< double > & getSourceWeights() const
Returns the weights of the sources.
Definition: NBDistrict.h:180
const std::vector< double > & getSinkWeights() const
Returns the weights of the sinks.
Definition: NBDistrict.h:196
const PositionVector & getShape() const
Returns the shape.
Definition: NBDistrict.h:212
const std::vector< NBEdge * > & getSourceEdges() const
Returns the sources.
Definition: NBDistrict.h:188
const std::vector< NBEdge * > & getSinkEdges() const
Returns the sinks.
Definition: NBDistrict.h:204
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:59
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
Definition: NBEdgeCont.h:183
const std::set< EdgeSet > getRoundabouts() const
Returns the determined roundabouts.
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition: NBEdgeCont.h:191
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:275
The representation of a single edge during network building.
Definition: NBEdge.h:91
double getLoadedLength() const
Returns the length was set explicitly or the computed length if it wasn't set.
Definition: NBEdge.h:597
const std::string & getStreetName() const
Returns the street name of this edge.
Definition: NBEdge.h:643
LaneSpreadFunction getLaneSpreadFunction() const
Returns how this edge's lanes' lateral offset is computed.
Definition: NBEdge.cpp:942
bool isBidiRail(bool ignoreSpread=false) const
whether this edge is part of a bidirectional railway
Definition: NBEdge.cpp:742
bool hasLoadedLength() const
Returns whether a length was set explicitly.
Definition: NBEdge.h:607
const std::string & getID() const
Definition: NBEdge.h:1465
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:701
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:541
double getDistance() const
get distance
Definition: NBEdge.h:653
static const double UNSPECIFIED_LOADED_LENGTH
no length override given
Definition: NBEdge.h:364
const StopOffset & getEdgeStopOffset() const
Returns the stopOffset to the end of the edge.
Definition: NBEdge.cpp:3891
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition: NBEdge.h:752
static const double UNSPECIFIED_CONTPOS
unspecified internal junction position
Definition: NBEdge.h:358
static const double UNSPECIFIED_VISIBILITY_DISTANCE
unspecified foe visibility for connections
Definition: NBEdge.h:361
std::string getLaneID(int lane) const
get lane ID
Definition: NBEdge.cpp:3693
static const double UNSPECIFIED_SPEED
unspecified lane speed
Definition: NBEdge.h:355
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
Definition: NBEdge.cpp:2027
NBEdge * getTurnDestination(bool possibleDestination=false) const
Definition: NBEdge.cpp:3684
bool hasDefaultGeometry() const
Returns whether the geometry consists only of the node positions.
Definition: NBEdge.cpp:604
int getPriority() const
Returns the priority of the edge.
Definition: NBEdge.h:522
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:349
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition: NBEdge.h:1006
const std::string & getTypeID() const
get ID of type
Definition: NBEdge.h:1146
double getEndOffset() const
Returns the offset to the destination node.
Definition: NBEdge.h:660
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:352
bool isMacroscopicConnector() const
Returns whether this edge was marked as a macroscopic connector.
Definition: NBEdge.h:1101
Connection getConnection(int fromLane, const NBEdge *to, int toLane) const
Returns the specified connection This method goes through "myConnections" and returns the specified o...
Definition: NBEdge.cpp:1220
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:4354
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:534
static void interpretLaneID(const std::string &lane_id, std::string &edge_id, int &index)
parses edge-id and index from lane-id
Definition: NBHelpers.cpp:119
Instance responsible for building networks.
Definition: NBNetBuilder.h:107
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
Definition: NBNetBuilder.h:168
NBTypeCont & getTypeCont()
Returns a reference to the type container.
Definition: NBNetBuilder.h:158
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:148
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:153
NBTrafficLightLogicCont & getTLLogicCont()
Returns a reference to the traffic light logics container.
Definition: NBNetBuilder.h:163
A definition of a pedestrian crossing.
Definition: NBNode.h:129
int tlLinkIndex
the traffic light index of this crossing (if controlled)
Definition: NBNode.h:154
std::string tlID
The id of the traffic light that controls this connection.
Definition: NBNode.h:160
bool priority
whether the pedestrians have priority
Definition: NBNode.h:150
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:58
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:113
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:118
Represents a single node (junction) during network building.
Definition: NBNode.h:66
LinkState getLinkState(const NBEdge *incoming, NBEdge *outgoing, int fromLane, int toLane, bool mayDefinitelyPass, const std::string &tlID) const
get link state
Definition: NBNode.cpp:2286
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
Definition: NBNode.cpp:2221
RightOfWay getRightOfWay() const
Returns hint on how to compute right of way.
Definition: NBNode.h:288
static const double UNSPECIFIED_RADIUS
unspecified lane width
Definition: NBNode.h:208
Crossing * getCrossing(const std::string &id) const
return the crossing with the given id
Definition: NBNode.cpp:3421
FringeType getFringeType() const
Returns fringe type.
Definition: NBNode.h:293
SumoXMLNodeType getType() const
Returns the type of this node.
Definition: NBNode.h:273
const std::string & getName() const
Returns intersection name.
Definition: NBNode.h:298
bool hasCustomShape() const
return whether the shape was set by the user
Definition: NBNode.h:558
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges (The edges which yield in this node)
Definition: NBNode.h:256
bool brakeForCrossingOnExit(const NBEdge *to) const
whether a connection to the given edge must brake for a crossing when leaving the intersection
Definition: NBNode.cpp:1911
std::vector< Crossing * > getCrossings() const
return this junctions pedestrian crossings
Definition: NBNode.cpp:2725
bool writeLogic(OutputDevice &into) const
writes the XML-representation of the logic as a bitset-logic XML representation
Definition: NBNode.cpp:1027
bool isConstantWidthTransition() const
detects whether a given junction splits or merges lanes while keeping constant road width
Definition: NBNode.cpp:818
const PositionVector & getShape() const
retrieve the junction shape
Definition: NBNode.cpp:2418
const Position & getPosition() const
Definition: NBNode.h:248
double getRadius() const
Returns the turning radius of this node.
Definition: NBNode.h:278
const std::vector< WalkingArea > & getWalkingAreas() const
return this junctions pedestrian walking areas
Definition: NBNode.h:714
static const SUMOTime UNSPECIFIED_DURATION
The definition of a single phase of the logic.
A container for traffic light definitions and built programs.
std::vector< NBTrafficLightLogic * > getComputed() const
Returns a list of all computed logics.
A SUMO-compliant built logic for a traffic light.
SUMOTime getOffset() const
Returns the offset of first switch.
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
const std::string & getProgramID() const
Returns the ProgramID.
TrafficLightType getType() const
get the algorithm type (static etc..)
void writeEdgeTypes(OutputDevice &into) const
writes all EdgeTypes (and their lanes) as XML
Definition: NBTypeCont.cpp:365
static void writePositionLong(const Position &pos, OutputDevice &dev)
Writes the given position to device in long format (one attribute per dimension)
Definition: NWFrame.cpp:187
static void writeConnection(OutputDevice &into, const NBEdge &from, const NBEdge::Connection &c, bool includeInternal, ConnectionStyle style=SUMONET, bool geoAccuracy=false)
Writes connections outgoing from the given edge (also used in NWWriter_XML)
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a SUMO-file.
static void writeLane(OutputDevice &into, const std::string &lID, double speed, SVCPermissions permissions, SVCPermissions preferred, SVCPermissions changeLeft, SVCPermissions changeRight, double startOffset, double endOffset, const StopOffset &stopOffset, double width, PositionVector shape, const Parameterised *params, double length, int index, const std::string &oppositeID, const std::string &type, bool accelRamp=false, bool customShape=false)
Writes a lane (<lane ...) of an edge.
static bool writeInternalNodes(OutputDevice &into, const NBNode &n)
Writes internal junctions (<junction with id[0]==':' ...) of the given node.
static void writeProhibitions(OutputDevice &into, const NBConnectionProhibits &prohibitions)
writes the given prohibitions
static void writeEdge(OutputDevice &into, const NBEdge &e, bool noNames)
Writes an edge (<edge ...)
static std::string getOppositeInternalID(const NBEdgeCont &ec, const NBEdge *from, const NBEdge::Connection &con, double &oppositeLength)
retrieve the id of the opposite direction internal lane if it exists
static std::string writeSUMOTime(SUMOTime time)
writes a SUMOTime as int if possible, otherwise as a float
static void writeJunction(OutputDevice &into, const NBNode &n)
Writes a junction (<junction ...)
static bool writeInternalEdges(OutputDevice &into, const NBEdgeCont &ec, const NBNode &n)
Writes internal edges (<edge ... with id[0]==':') of the given node.
static bool writeInternalConnections(OutputDevice &into, const NBNode &n)
Writes inner connections within the node.
static void writeDistrict(OutputDevice &into, const NBDistrict &d)
Writes a district.
static void writeRoundabouts(OutputDevice &into, const std::set< EdgeSet > &roundabouts, const NBEdgeCont &ec)
Writes roundabouts.
static void writeRoundabout(OutputDevice &into, const std::vector< std::string > &r, const NBEdgeCont &ec)
Writes a roundabout.
static void writeStopOffsets(OutputDevice &into, const StopOffset &stopOffset)
Write a stopOffset element into output device.
static void writeInternalConnection(OutputDevice &into, const std::string &from, const std::string &to, int fromLane, int toLane, const std::string &via, LinkDirection dir=LinkDirection::STRAIGHT, const std::string &tlID="", int linkIndex=NBConnection::InvalidTlIndex, bool minor=false, double visibility=NBEdge::UNSPECIFIED_VISIBILITY_DISTANCE)
Writes a single internal connection.
static void writeTrafficLight(OutputDevice &into, const NBTrafficLightLogic *logic)
writes a single traffic light logic to the given device
static std::string prohibitionConnection(const NBConnection &c)
the attribute value for a prohibition
static void writeTrafficLights(OutputDevice &into, const NBTrafficLightLogicCont &tllCont)
writes the traffic light logics to the given device
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A storage for options typed value containers)
Definition: OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
void resetWritable()
Resets all options to be writeable.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
void lf()
writes a line feed if applicable
Definition: OutputDevice.h:236
void close()
Closes the device and removes it from the dictionary.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
OutputDevice & writePadding(const std::string &val)
writes padding (ignored for binary output)
Definition: OutputDevice.h:311
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >(), bool includeConfig=true)
Writes an XML header with optional configuration.
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.
double length() const
Returns the length.
PositionVector simplified() const
return the same shape with intermediate colinear points removed
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
stop offset
bool isDefined() const
check if stopOffset was defined
SVCPermissions getPermissions() const
get permissions
double getOffset() const
get offset
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
static void normaliseSum(std::vector< T > &v, T msum=1.0)
Definition: VectorHelper.h:47
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:197
bool indirectLeft
Whether this connection is an indirect left turn.
Definition: NBEdge.h:270
int fromLane
The lane the connections starts at.
Definition: NBEdge.h:222
std::string viaID
if Connection have a via, ID of it
Definition: NBEdge.h:288
int toLane
The lane the connections yields in.
Definition: NBEdge.h:228
SVCPermissions permissions
List of vehicle types that are allowed on this connection.
Definition: NBEdge.h:261
double speed
custom speed for connection
Definition: NBEdge.h:252
NBEdge * toEdge
The edge the connections yields in.
Definition: NBEdge.h:225
KeepClear keepClear
whether the junction must be kept clear when using this connection
Definition: NBEdge.h:243
double customLength
custom length for connection
Definition: NBEdge.h:255
std::string edgeType
optional type of Connection
Definition: NBEdge.h:273
bool uncontrolled
check if Connection is uncontrolled
Definition: NBEdge.h:306
PositionVector customShape
custom shape for connection
Definition: NBEdge.h:258
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
Definition: NBEdge.h:240
SVCPermissions changeLeft
List of vehicle types that are allowed to change Left from this connections internal lane(s)
Definition: NBEdge.h:264
SVCPermissions changeRight
List of vehicle types that are allowed to change right from this connections internal lane(s)
Definition: NBEdge.h:267
std::string getDescription(const NBEdge *parent) const
get string describing this connection
Definition: NBEdge.cpp:92
double contPos
custom position for internal junction on this connection
Definition: NBEdge.h:246
std::string getInternalLaneID() const
get ID of internal lane
Definition: NBEdge.cpp:86
int internalLaneIndex
The lane index of this internal lane within the internal edge.
Definition: NBEdge.h:303
std::string tlID
The id of the traffic light that controls this connection.
Definition: NBEdge.h:231
double visibility
custom foe visiblity for connection
Definition: NBEdge.h:249
int tlLinkIndex2
The index of the internal junction within the controlling traffic light (optional)
Definition: NBEdge.h:237
double length
computed length (average of all internal lane shape lengths that share an internal edge)
Definition: NBEdge.h:315
std::string id
id of Connection
Definition: NBEdge.h:276
bool haveVia
check if Connection have a Via
Definition: NBEdge.h:285
int tlLinkIndex
The index of this connection within the controlling traffic light.
Definition: NBEdge.h:234
An (internal) definition of a single lane of an edge.
Definition: NBEdge.h:142
double width
This lane's width.
Definition: NBEdge.h:172
StopOffset laneStopOffset
stopOffsets.second - The stop offset for vehicles stopping at the lane's end. Applies if vClass is in...
Definition: NBEdge.h:169
PositionVector customShape
A custom shape for this lane set by the user.
Definition: NBEdge.h:185
double endOffset
This lane's offset to the intersection begin.
Definition: NBEdge.h:165
std::string type
the type of this lane
Definition: NBEdge.h:188
SVCPermissions preferred
List of vehicle types that are preferred on this lane.
Definition: NBEdge.h:156
double speed
The speed allowed on this lane.
Definition: NBEdge.h:150
std::string oppositeID
An opposite lane ID, if given.
Definition: NBEdge.h:175
SVCPermissions changeRight
List of vehicle types that are allowed to change right from this lane.
Definition: NBEdge.h:162
SVCPermissions changeLeft
List of vehicle types that are allowed to change Left from this lane.
Definition: NBEdge.h:159
SVCPermissions permissions
List of vehicle types that are allowed on this lane.
Definition: NBEdge.h:153
bool accelRamp
Whether this lane is an acceleration lane.
Definition: NBEdge.h:178
PositionVector shape
The lane's shape.
Definition: NBEdge.h:147
A definition of a pedestrian walking area.
Definition: NBNode.h:169
std::string id
the (edge)-id of this walkingArea
Definition: NBNode.h:176
bool hasCustomShape
whether this walkingArea has a custom shape
Definition: NBNode.h:190
double width
This lane's width.
Definition: NBNode.h:178
PositionVector shape
The polygonal shape.
Definition: NBNode.h:182
double length
This lane's width.
Definition: NBNode.h:180