SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NWWriter_SUMO.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Exporter writing networks using the SUMO format
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 #include <cmath>
33 #include <algorithm>
37 #include <utils/common/ToString.h>
41 #include <netbuild/NBEdge.h>
42 #include <netbuild/NBEdgeCont.h>
43 #include <netbuild/NBNode.h>
44 #include <netbuild/NBNodeCont.h>
45 #include <netbuild/NBNetBuilder.h>
47 #include <netbuild/NBDistrict.h>
48 #include "NWFrame.h"
49 #include "NWWriter_SUMO.h"
50 
51 #ifdef CHECK_MEMORY_LEAKS
52 #include <foreign/nvwa/debug_new.h>
53 #endif // CHECK_MEMORY_LEAKS
54 
55 
56 
57 // ===========================================================================
58 // method definitions
59 // ===========================================================================
60 // ---------------------------------------------------------------------------
61 // static methods
62 // ---------------------------------------------------------------------------
63 void
65  // check whether a sumo net-file shall be generated
66  if (!oc.isSet("output-file")) {
67  return;
68  }
69  OutputDevice& device = OutputDevice::getDevice(oc.getString("output-file"));
70  device.writeXMLHeader("net", NWFrame::MAJOR_VERSION + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/net_file.xsd\""); // street names may contain non-ascii chars
71  device.lf();
72  // get involved container
73  const NBNodeCont& nc = nb.getNodeCont();
74  const NBEdgeCont& ec = nb.getEdgeCont();
75  const NBDistrictCont& dc = nb.getDistrictCont();
76 
77  // write network offsets and projection
78  writeLocation(device);
79 
80  // write inner lanes
81  bool origNames = oc.getBool("output.original-names");
82  if (!oc.getBool("no-internal-links")) {
83  bool hadAny = false;
84  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
85  hadAny |= writeInternalEdges(device, *(*i).second, origNames);
86  }
87  if (hadAny) {
88  device.lf();
89  }
90  }
91 
92  // write edges with lanes and connected edges
93  bool noNames = !oc.getBool("output.street-names");
94  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
95  writeEdge(device, *(*i).second, noNames, origNames);
96  }
97  device.lf();
98 
99  // write tls logics
100  writeTrafficLights(device, nb.getTLLogicCont());
101 
102  // write the nodes (junctions)
103  std::set<NBNode*> roundaboutNodes;
104  const bool checkLaneFoesAll = oc.getBool("check-lane-foes.all");
105  const bool checkLaneFoesRoundabout = !checkLaneFoesAll && oc.getBool("check-lane-foes.roundabout");
106  if (checkLaneFoesRoundabout) {
107  const std::set<EdgeSet>& roundabouts = ec.getRoundabouts();
108  for (std::set<EdgeSet>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
109  for (EdgeSet::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
110  roundaboutNodes.insert((*j)->getToNode());
111  }
112  }
113  }
114  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
115  const bool checkLaneFoes = checkLaneFoesAll || (checkLaneFoesRoundabout && roundaboutNodes.count((*i).second) > 0);
116  writeJunction(device, *(*i).second, checkLaneFoes);
117  }
118  device.lf();
119  const bool includeInternal = !oc.getBool("no-internal-links");
120  if (includeInternal) {
121  // ... internal nodes if not unwanted
122  bool hadAny = false;
123  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
124  hadAny |= writeInternalNodes(device, *(*i).second);
125  }
126  if (hadAny) {
127  device.lf();
128  }
129  }
130 
131  // write the successors of lanes
132  unsigned int numConnections = 0;
133  for (std::map<std::string, NBEdge*>::const_iterator it_edge = ec.begin(); it_edge != ec.end(); it_edge++) {
134  NBEdge* from = it_edge->second;
136  const std::vector<NBEdge::Connection> connections = from->getConnections();
137  numConnections += (unsigned int)connections.size();
138  for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); it_c++) {
139  writeConnection(device, *from, *it_c, includeInternal);
140  }
141  }
142  if (numConnections > 0) {
143  device.lf();
144  }
145  if (includeInternal) {
146  // ... internal successors if not unwanted
147  bool hadAny = false;
148  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
149  hadAny |= writeInternalConnections(device, *(*i).second);
150  }
151  if (hadAny) {
152  device.lf();
153  }
154  }
155  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
156  NBNode* node = (*i).second;
157  // write connections from pedestrian crossings
158  const std::vector<NBNode::Crossing>& crossings = node->getCrossings();
159  for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) {
160  NWWriter_SUMO::writeInternalConnection(device, (*it).id, (*it).nextWalkingArea, 0, 0, "");
161  }
162  // write connections from pedestrian walking areas
163  const std::vector<NBNode::WalkingArea>& WalkingAreas = node->getWalkingAreas();
164  for (std::vector<NBNode::WalkingArea>::const_iterator it = WalkingAreas.begin(); it != WalkingAreas.end(); it++) {
165  if ((*it).nextCrossing != "") {
166  const NBNode::Crossing& nextCrossing = node->getCrossing((*it).nextCrossing);
167  // connection to next crossing (may be tls-controlled)
169  device.writeAttr(SUMO_ATTR_FROM, (*it).id);
170  device.writeAttr(SUMO_ATTR_TO, (*it).nextCrossing);
171  device.writeAttr(SUMO_ATTR_FROM_LANE, 0);
172  device.writeAttr(SUMO_ATTR_TO_LANE, 0);
173  if ((*it).tlID != "") {
174  device.writeAttr(SUMO_ATTR_TLID, (*it).tlID);
175  assert(nextCrossing.tlLinkNo >= 0);
176  device.writeAttr(SUMO_ATTR_TLLINKINDEX, nextCrossing.tlLinkNo);
177  }
180  device.closeTag();
181  }
182  // optional connections from/to sidewalk
183  for (std::vector<std::string>::const_iterator it_sw = (*it).nextSidewalks.begin(); it_sw != (*it).nextSidewalks.end(); ++it_sw) {
184  NWWriter_SUMO::writeInternalConnection(device, (*it).id, (*it_sw), 0, 0, "");
185  }
186  for (std::vector<std::string>::const_iterator it_sw = (*it).prevSidewalks.begin(); it_sw != (*it).prevSidewalks.end(); ++it_sw) {
187  NWWriter_SUMO::writeInternalConnection(device, (*it_sw), (*it).id, 0, 0, "");
188  }
189  }
190  }
191 
192  // write loaded prohibitions
193  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
194  writeProhibitions(device, i->second->getProhibitions());
195  }
196 
197  // write roundabout information
198  writeRoundabouts(device, ec.getRoundabouts(), ec);
199 
200  // write the districts
201  for (std::map<std::string, NBDistrict*>::const_iterator i = dc.begin(); i != dc.end(); i++) {
202  writeDistrict(device, *(*i).second);
203  }
204  if (dc.size() != 0) {
205  device.lf();
206  }
207  device.close();
208 }
209 
210 
211 bool
212 NWWriter_SUMO::writeInternalEdges(OutputDevice& into, const NBNode& n, bool origNames) {
213  bool ret = false;
214  const EdgeVector& incoming = n.getIncomingEdges();
215  for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
216  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
217  if (elv.size() > 0) {
218  bool haveVia = false;
219  NBEdge* toEdge = 0;
220  std::string internalEdgeID = "";
221  // first pass: compute average lengths of non-via edges
222  std::map<NBEdge*, SUMOReal> lengthSum;
223  std::map<NBEdge*, int> numLanes;
224  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
225  lengthSum[(*k).toEdge] += MAX2((*k).shape.length(), POSITION_EPS);
226  numLanes[(*k).toEdge] += 1;
227  }
228  // second pass: write non-via edges
229  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
230  if ((*k).toEdge == 0) {
231  assert(false); // should never happen. tell me when it does
232  continue;
233  }
234  if (toEdge != (*k).toEdge) {
235  internalEdgeID = (*k).id;
236  if (toEdge != 0) {
237  // close the previous edge
238  into.closeTag();
239  }
240  toEdge = (*k).toEdge;
241  into.openTag(SUMO_TAG_EDGE);
242  into.writeAttr(SUMO_ATTR_ID, internalEdgeID);
244  // open a new edge
245  }
246  // to avoid changing to an internal lane which has a successor
247  // with the wrong permissions we need to inherit them from the successor
248  const NBEdge::Lane& successor = (*k).toEdge->getLanes()[(*k).toLane];
249  const SUMOReal length = lengthSum[toEdge] / numLanes[toEdge];
250  // @note the actual length should be used once sumo supports lanes of
251  // varying length within the same edge
252  //const SUMOReal length = MAX2((*k).shape.length(), POSITION_EPS);
253  writeLane(into, internalEdgeID, (*k).getInternalLaneID(), (*k).vmax,
254  successor.permissions, successor.preferred,
255  NBEdge::UNSPECIFIED_OFFSET, successor.width, (*k).shape, (*k).origID,
256  length, (*k).internalLaneIndex, origNames);
257  haveVia = haveVia || (*k).haveVia;
258  }
259  ret = true;
260  into.closeTag(); // close the last edge
261  // third pass: write via edges
262  if (haveVia) {
263  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
264  if (!(*k).haveVia) {
265  continue;
266  }
267  if ((*k).toEdge == 0) {
268  assert(false); // should never happen. tell me when it does
269  continue;
270  }
271  const NBEdge::Lane& successor = (*k).toEdge->getLanes()[(*k).toLane];
272  into.openTag(SUMO_TAG_EDGE);
273  into.writeAttr(SUMO_ATTR_ID, (*k).viaID);
275  writeLane(into, (*k).viaID, (*k).viaID + "_0", (*k).viaVmax, SVCAll, SVCAll,
276  NBEdge::UNSPECIFIED_OFFSET, successor.width, (*k).viaShape, (*k).origID,
277  MAX2((*k).viaShape.length(), POSITION_EPS), // microsim needs positive length
278  0, origNames);
279  into.closeTag();
280  }
281  }
282  }
283  }
284  // write pedestrian crossings
285  const std::vector<NBNode::Crossing>& crossings = n.getCrossings();
286  for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) {
287  into.openTag(SUMO_TAG_EDGE);
288  into.writeAttr(SUMO_ATTR_ID, (*it).id);
290  into.writeAttr(SUMO_ATTR_CROSSING_EDGES, (*it).edges);
291  writeLane(into, (*it).id, (*it).id + "_0", 1, SVC_PEDESTRIAN, 0,
292  NBEdge::UNSPECIFIED_OFFSET, (*it).width, (*it).shape, "", (*it).shape.length(), 0, false);
293  into.closeTag();
294  }
295  // write pedestrian walking areas
296  const std::vector<NBNode::WalkingArea>& WalkingAreas = n.getWalkingAreas();
297  for (std::vector<NBNode::WalkingArea>::const_iterator it = WalkingAreas.begin(); it != WalkingAreas.end(); it++) {
298  const NBNode::WalkingArea& wa = *it;
299  into.openTag(SUMO_TAG_EDGE);
300  into.writeAttr(SUMO_ATTR_ID, wa.id);
302  writeLane(into, wa.id, wa.id + "_0", 1, SVC_PEDESTRIAN, 0,
303  NBEdge::UNSPECIFIED_OFFSET, wa.width, wa.shape, "", wa.length, 0, false);
304  into.closeTag();
305  }
306  return ret;
307 }
308 
309 
310 void
311 NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames, bool origNames) {
312  // write the edge's begin
315  into.writeAttr(SUMO_ATTR_TO, e.getToNode()->getID());
316  if (!noNames && e.getStreetName() != "") {
318  }
320  if (e.getTypeName() != "") {
322  }
323  if (e.isMacroscopicConnector()) {
325  }
326  // write the spread type if not default ("right")
329  }
330  if (e.hasLoadedLength()) {
332  }
333  if (!e.hasDefaultGeometry()) {
335  }
336  // write the lanes
337  const std::vector<NBEdge::Lane>& lanes = e.getLanes();
338 
339  SUMOReal length = e.getLoadedLength();
340  if (OptionsCont::getOptions().getBool("no-internal-links") && !e.hasLoadedLength()) {
341  // use length to junction center even if a modified geometry was given
342  PositionVector geom = e.getGeometry();
345  length = geom.length();
346  }
347  if (length <= 0) {
348  length = POSITION_EPS;
349  }
350  for (unsigned int i = 0; i < (unsigned int) lanes.size(); i++) {
351  const NBEdge::Lane& l = lanes[i];
352  writeLane(into, e.getID(), e.getLaneID(i), l.speed,
353  l.permissions, l.preferred, l.endOffset, l.width, l.shape, l.origID,
354  length, i, origNames);
355  }
356  // close the edge
357  into.closeTag();
358 }
359 
360 
361 void
362 NWWriter_SUMO::writeLane(OutputDevice& into, const std::string& eID, const std::string& lID,
363  SUMOReal speed, SVCPermissions permissions, SVCPermissions preferred,
364  SUMOReal endOffset, SUMOReal width, const PositionVector& shape,
365  const std::string& origID, SUMOReal length, unsigned int index, bool origNames) {
366  // output the lane's attributes
368  // the first lane of an edge will be the depart lane
369  into.writeAttr(SUMO_ATTR_INDEX, index);
370  // write the list of allowed/disallowed vehicle classes
371  writePermissions(into, permissions);
372  writePreferences(into, preferred);
373  // some further information
374  if (speed == 0) {
375  WRITE_WARNING("Lane #" + toString(index) + " of edge '" + eID + "' has a maximum velocity of 0.");
376  } else if (speed < 0) {
377  throw ProcessError("Negative velocity (" + toString(speed) + " on edge '" + eID + "' lane#" + toString(index) + ".");
378  }
379  if (endOffset > 0) {
380  length = length - endOffset;
381  }
382  into.writeAttr(SUMO_ATTR_SPEED, speed);
383  into.writeAttr(SUMO_ATTR_LENGTH, length);
384  if (endOffset != NBEdge::UNSPECIFIED_OFFSET) {
385  into.writeAttr(SUMO_ATTR_ENDOFFSET, endOffset);
386  }
387  if (width != NBEdge::UNSPECIFIED_WIDTH) {
388  into.writeAttr(SUMO_ATTR_WIDTH, width);
389  }
390  into.writeAttr(SUMO_ATTR_SHAPE, endOffset > 0 ?
391  shape.getSubpart(0, shape.length() - endOffset) : shape);
392  if (origNames && origID != "") {
393  into.openTag(SUMO_TAG_PARAM);
394  into.writeAttr(SUMO_ATTR_KEY, "origId");
395  into.writeAttr(SUMO_ATTR_VALUE, origID);
396  into.closeTag();
397  into.closeTag();
398  } else {
399  into.closeTag();
400  }
401 }
402 
403 
404 void
405 NWWriter_SUMO::writeJunction(OutputDevice& into, const NBNode& n, const bool checkLaneFoes) {
406  // write the attributes
408  into.writeAttr(SUMO_ATTR_TYPE, n.getType());
410  // write the incoming lanes
411  std::string incLanes;
412  const std::vector<NBEdge*>& incoming = n.getIncomingEdges();
413  for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); ++i) {
414  unsigned int noLanes = (*i)->getNumLanes();
415  for (unsigned int j = 0; j < noLanes; j++) {
416  incLanes += (*i)->getLaneID(j);
417  if (i != incoming.end() - 1 || j < noLanes - 1) {
418  incLanes += ' ';
419  }
420  }
421  }
422  const std::vector<NBNode::Crossing>& crossings = n.getCrossings();
423  for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) {
424  incLanes += ' ' + (*it).prevWalkingArea + "_0";
425  }
426  into.writeAttr(SUMO_ATTR_INCLANES, incLanes);
427  // write the internal lanes
428  std::string intLanes;
429  if (!OptionsCont::getOptions().getBool("no-internal-links")) {
430  unsigned int l = 0;
431  for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
432  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
433  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
434  if ((*k).toEdge == 0) {
435  continue;
436  }
437  if (l != 0) {
438  intLanes += ' ';
439  }
440  if (!(*k).haveVia) {
441  intLanes += (*k).getInternalLaneID();
442  } else {
443  intLanes += (*k).viaID + "_0";
444  }
445  l++;
446  }
447  }
448  }
449  for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) {
450  intLanes += ' ' + (*it).id + "_0";
451  }
452  into.writeAttr(SUMO_ATTR_INTLANES, intLanes);
453  // close writing
455  if (n.getType() == NODETYPE_DEAD_END) {
456  into.closeTag();
457  } else {
458  // write right-of-way logics
459  n.writeLogic(into, checkLaneFoes);
460  into.closeTag();
461  }
462 }
463 
464 
465 bool
467  bool ret = false;
468  const std::vector<NBEdge*>& incoming = n.getIncomingEdges();
469  // build the list of internal lane ids
470  std::vector<std::string> internalLaneIDs;
471  for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
472  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
473  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
474  if ((*k).toEdge != 0) {
475  internalLaneIDs.push_back((*k).getInternalLaneID());
476  }
477  }
478  }
479  const std::vector<NBNode::Crossing>& crossings = n.getCrossings();
480  for (std::vector<NBNode::Crossing>::const_iterator it_c = crossings.begin(); it_c != crossings.end(); ++it_c) {
481  internalLaneIDs.push_back((*it_c).id + "_0");
482  }
483  // write the internal nodes
484  for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
485  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
486  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
487  if ((*k).toEdge == 0 || !(*k).haveVia) {
488  continue;
489  }
490  Position pos = (*k).shape[-1];
491  into.openTag(SUMO_TAG_JUNCTION).writeAttr(SUMO_ATTR_ID, (*k).viaID + "_0");
493  NWFrame::writePositionLong(pos, into);
494  std::string incLanes = (*k).getInternalLaneID();
495  if ((*k).foeIncomingLanes.length() != 0) {
496  incLanes += " " + (*k).foeIncomingLanes;
497  }
498  into.writeAttr(SUMO_ATTR_INCLANES, incLanes);
499  const std::vector<unsigned int>& foes = (*k).foeInternalLinks;
500  std::vector<std::string> foeIDs;
501  for (std::vector<unsigned int>::const_iterator it = foes.begin(); it != foes.end(); ++it) {
502  foeIDs.push_back(internalLaneIDs[*it]);
503  }
504  into.writeAttr(SUMO_ATTR_INTLANES, joinToString(foeIDs, " "));
505  into.closeTag();
506  ret = true;
507  }
508  }
509  return ret;
510 }
511 
512 
513 void
515  bool includeInternal, ConnectionStyle style) {
516  assert(c.toEdge != 0);
518  into.writeAttr(SUMO_ATTR_FROM, from.getID());
519  into.writeAttr(SUMO_ATTR_TO, c.toEdge->getID());
522  if (c.mayDefinitelyPass && style != TLL) {
524  }
525  if (style != PLAIN) {
526  if (includeInternal) {
528  }
529  // set information about the controlling tl if any
530  if (c.tlID != "") {
531  into.writeAttr(SUMO_ATTR_TLID, c.tlID);
533  }
534  if (style == SUMONET) {
535  // write the direction information
536  LinkDirection dir = from.getToNode()->getDirection(&from, c.toEdge);
537  assert(dir != LINKDIR_NODIR);
538  into.writeAttr(SUMO_ATTR_DIR, toString(dir));
539  // write the state information
540  const LinkState linkState = from.getToNode()->getLinkState(
541  &from, c.toEdge, c.toLane, c.mayDefinitelyPass, c.tlID);
542  into.writeAttr(SUMO_ATTR_STATE, linkState);
543  }
544  }
545  into.closeTag();
546 }
547 
548 
549 bool
551  bool ret = false;
552  const std::vector<NBEdge*>& incoming = n.getIncomingEdges();
553  for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); ++i) {
554  NBEdge* from = *i;
555  const std::vector<NBEdge::Connection>& connections = from->getConnections();
556  for (std::vector<NBEdge::Connection>::const_iterator j = connections.begin(); j != connections.end(); ++j) {
557  const NBEdge::Connection& c = *j;
558  assert(c.toEdge != 0);
559  if (c.haveVia) {
560  // internal split
561  writeInternalConnection(into, c.id, c.toEdge->getID(), c.internalLaneIndex, c.toLane, c.viaID + "_0");
562  writeInternalConnection(into, c.viaID, c.toEdge->getID(), 0, c.toLane, "");
563  } else {
564  // no internal split
566  }
567  ret = true;
568  }
569  }
570  return ret;
571 }
572 
573 
574 void
576  const std::string& from, const std::string& to,
577  int fromLane, int toLane, const std::string& via) {
579  into.writeAttr(SUMO_ATTR_FROM, from);
580  into.writeAttr(SUMO_ATTR_TO, to);
581  into.writeAttr(SUMO_ATTR_FROM_LANE, fromLane);
582  into.writeAttr(SUMO_ATTR_TO_LANE, toLane);
583  if (via != "") {
584  into.writeAttr(SUMO_ATTR_VIA, via);
585  }
586  into.writeAttr(SUMO_ATTR_DIR, "s");
587  into.writeAttr(SUMO_ATTR_STATE, (via != "" ? "m" : "M"));
588  into.closeTag();
589 }
590 
591 
592 void
593 NWWriter_SUMO::writeRoundabouts(OutputDevice& into, const std::set<EdgeSet>& roundabouts,
594  const NBEdgeCont& ec) {
595  // make output deterministic
596  std::vector<std::vector<std::string> > edgeIDs;
597  for (std::set<EdgeSet>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
598  std::vector<std::string> tEdgeIDs;
599  for (EdgeSet::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
600  tEdgeIDs.push_back((*j)->getID());
601  }
602  std::sort(tEdgeIDs.begin(), tEdgeIDs.end());
603  edgeIDs.push_back(tEdgeIDs);
604  }
605  std::sort(edgeIDs.begin(), edgeIDs.end());
606  // write
607  for (std::vector<std::vector<std::string> >::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) {
608  writeRoundabout(into, *i, ec);
609  }
610  if (roundabouts.size() != 0) {
611  into.lf();
612  }
613 }
614 
615 
616 void
617 NWWriter_SUMO::writeRoundabout(OutputDevice& into, const std::vector<std::string>& edgeIDs,
618  const NBEdgeCont& ec) {
619  std::vector<std::string> validEdgeIDs;
620  std::vector<std::string> invalidEdgeIDs;
621  std::vector<std::string> nodeIDs;
622  for (std::vector<std::string>::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) {
623  const NBEdge* edge = ec.retrieve(*i);
624  if (edge != 0) {
625  nodeIDs.push_back(edge->getToNode()->getID());
626  validEdgeIDs.push_back(edge->getID());
627  } else {
628  invalidEdgeIDs.push_back(*i);
629  }
630  }
631  std::sort(nodeIDs.begin(), nodeIDs.end());
632  if (validEdgeIDs.size() > 0) {
634  into.writeAttr(SUMO_ATTR_NODES, joinToString(nodeIDs, " "));
635  into.writeAttr(SUMO_ATTR_EDGES, joinToString(validEdgeIDs, " "));
636  into.closeTag();
637  if (invalidEdgeIDs.size() > 0) {
638  WRITE_WARNING("Writing incomplete roundabout. Edges: '"
639  + joinToString(invalidEdgeIDs, " ") + "' no longer exist'");
640  }
641  }
642 }
643 
644 
645 void
647  std::vector<SUMOReal> sourceW = d.getSourceWeights();
649  std::vector<SUMOReal> sinkW = d.getSinkWeights();
651  // write the head and the id of the district
653  if (d.getShape().size() > 0) {
655  }
656  size_t i;
657  // write all sources
658  const std::vector<NBEdge*>& sources = d.getSourceEdges();
659  for (i = 0; i < sources.size(); i++) {
660  // write the head and the id of the source
661  into.openTag(SUMO_TAG_TAZSOURCE).writeAttr(SUMO_ATTR_ID, sources[i]->getID()).writeAttr(SUMO_ATTR_WEIGHT, sourceW[i]);
662  into.closeTag();
663  }
664  // write all sinks
665  const std::vector<NBEdge*>& sinks = d.getSinkEdges();
666  for (i = 0; i < sinks.size(); i++) {
667  // write the head and the id of the sink
668  into.openTag(SUMO_TAG_TAZSINK).writeAttr(SUMO_ATTR_ID, sinks[i]->getID()).writeAttr(SUMO_ATTR_WEIGHT, sinkW[i]);
669  into.closeTag();
670  }
671  // write the tail
672  into.closeTag();
673 }
674 
675 
676 std::string
678  SUMOReal time = STEPS2TIME(steps);
679  if (time == std::floor(time)) {
680  return toString(int(time));
681  } else {
682  return toString(time);
683  }
684 }
685 
686 
687 void
689  for (NBConnectionProhibits::const_iterator j = prohibitions.begin(); j != prohibitions.end(); j++) {
690  NBConnection prohibited = (*j).first;
691  const NBConnectionVector& prohibiting = (*j).second;
692  for (NBConnectionVector::const_iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
693  NBConnection prohibitor = *k;
697  into.closeTag();
698  }
699  }
700 }
701 
702 
703 std::string
705  return c.getFrom()->getID() + "->" + c.getTo()->getID();
706 }
707 
708 
709 void
711  std::vector<NBTrafficLightLogic*> logics = tllCont.getComputed();
712  for (std::vector<NBTrafficLightLogic*>::iterator it = logics.begin(); it != logics.end(); it++) {
714  into.writeAttr(SUMO_ATTR_ID, (*it)->getID());
715  into.writeAttr(SUMO_ATTR_TYPE, (*it)->getType());
716  into.writeAttr(SUMO_ATTR_PROGRAMID, (*it)->getProgramID());
717  into.writeAttr(SUMO_ATTR_OFFSET, writeSUMOTime((*it)->getOffset()));
718  // write params
719  const std::map<std::string, std::string>& params = (*it)->getMap();
720  for (std::map<std::string, std::string>::const_iterator i = params.begin(); i != params.end(); ++i) {
721  into.openTag(SUMO_TAG_PARAM);
722  into.writeAttr(SUMO_ATTR_KEY, (*i).first);
723  into.writeAttr(SUMO_ATTR_VALUE, (*i).second);
724  into.closeTag();
725  }
726  // write the phases
727  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = (*it)->getPhases();
728  for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator j = phases.begin(); j != phases.end(); ++j) {
729  into.openTag(SUMO_TAG_PHASE);
730  into.writeAttr(SUMO_ATTR_DURATION, writeSUMOTime(j->duration));
731  into.writeAttr(SUMO_ATTR_STATE, j->state);
732  into.closeTag();
733  }
734  into.closeTag();
735  }
736  if (logics.size() > 0) {
737  into.lf();
738  }
739 }
740 
741 
742 void
744  const GeoConvHelper& geoConvHelper = GeoConvHelper::getFinal();
746  into.writeAttr(SUMO_ATTR_NET_OFFSET, geoConvHelper.getOffsetBase());
747  into.writeAttr(SUMO_ATTR_CONV_BOUNDARY, geoConvHelper.getConvBoundary());
748  if (geoConvHelper.usingGeoProjection()) {
750  }
751  into.writeAttr(SUMO_ATTR_ORIG_BOUNDARY, geoConvHelper.getOrigBoundary());
752  if (geoConvHelper.usingGeoProjection()) {
753  into.setPrecision();
754  }
755  into.writeAttr(SUMO_ATTR_ORIG_PROJ, geoConvHelper.getProjString());
756  into.closeTag();
757  into.lf();
758 }
759 
760 
761 void
763  if (permissions == SVCAll) {
764  return;
765  } else if (permissions == 0) {
766  into.writeAttr(SUMO_ATTR_DISALLOW, "all");
767  return;
768  } else {
769  size_t num_allowed = 0;
770  for (int mask = 1; mask <= SUMOVehicleClass_MAX; mask = mask << 1) {
771  if ((mask & permissions) == mask) {
772  ++num_allowed;
773  }
774  }
775  if (num_allowed <= (SumoVehicleClassStrings.size() - num_allowed) && num_allowed > 0) {
776  into.writeAttr(SUMO_ATTR_ALLOW, getVehicleClassNames(permissions));
777  } else {
779  }
780  }
781 }
782 
783 
784 void
786  if (preferred == SVCAll || preferred == 0) {
787  return;
788  } else {
790  }
791 }
792 /****************************************************************************/
793 
static void writeRoundabout(OutputDevice &into, const std::vector< std::string > &r, const NBEdgeCont &ec)
Writes a roundabout.
std::string id
Definition: NBEdge.h:177
The information about how to spread the lanes from the given position.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
const EdgeVector & getIncomingEdges() const
Returns this node&#39;s incoming edges.
Definition: NBNode.h:244
void close()
Closes the device and removes it from the dictionary.
SUMOReal endOffset
This lane&#39;s offset to the intersection begin.
Definition: NBEdge.h:136
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:148
int toLane
The lane the connections yields in.
Definition: NBEdge.h:166
Position getCenter() const
Returns a position that is guaranteed to lie within the node shape.
Definition: NBNode.cpp:2043
a list of node ids, used for controlling joining
static const SUMOReal UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:201
PositionVector shape
The lane&#39;s shape.
Definition: NBEdge.h:128
is a pedestrian
static void writeDistrict(OutputDevice &into, const NBDistrict &d)
Writes a district.
const std::string & getTypeName() const
Returns the type name.
Definition: NBEdge.h:495
std::string viaID
Definition: NBEdge.h:182
NBEdge * toEdge
The edge the connections yields in.
Definition: NBEdge.h:164
bool hasDefaultGeometry() const
Returns whether the geometry consists only of the node positions.
Definition: NBEdge.cpp:379
const std::set< EdgeSet > getRoundabouts() const
Returns the determined roundabouts.
Definition: NBEdgeCont.cpp:889
size_t size() const
Returns the number of districts inside the container.
A container for traffic light definitions and built programs.
SUMOReal length
This lane&#39;s width.
Definition: NBNode.h:172
static void writeLocation(OutputDevice &into)
writes the location element
SUMOReal width
This lane&#39;s width.
Definition: NBNode.h:170
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:503
const Crossing & getCrossing(const std::string &id) const
return the crossing with the given id
Definition: NBNode.cpp:2019
#define GEO_OUTPUT_ACCURACY
Definition: config.h:16
int SVCPermissions
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
The representation of a single edge during network building.
Definition: NBEdge.h:71
static std::string escapeXML(const std::string &orig)
Replaces the standard escapes by their XML entities.
static void writeProhibitions(OutputDevice &into, const NBConnectionProhibits &prohibitions)
writes the given prohibitions
const std::vector< NBEdge * > & getSinkEdges() const
Returns the sinks.
Definition: NBDistrict.h:214
A container for districts.
const std::vector< Crossing > & getCrossings() const
return this junctions pedestrian crossings
Definition: NBNode.h:572
T MAX2(T a, T b)
Definition: StdDefs.h:74
the weight of a district&#39;s source or sink
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
Definition: NBEdge.h:172
std::string id
the (edge)-id of this walkingArea
Definition: NBNode.h:168
const SVCPermissions SVCAll
static void writeTrafficLights(OutputDevice &into, const NBTrafficLightLogicCont &tllCont)
writes the traffic light logics to the given device
static const SUMOReal UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:203
static void writeInternalConnection(OutputDevice &into, const std::string &from, const std::string &to, int fromLane, int toLane, const std::string &via)
Writes a single internal connection.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
static void writePermissions(OutputDevice &into, SVCPermissions permissions)
writes allowed disallowed attributes if needed;
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
bool priority
whether the pedestrians have priority
Definition: NBNode.h:151
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
bool writeXMLHeader(const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
Writes an XML header with optional configuration.
The link is a straight direction.
The state of a link.
SUMOReal speed
The speed allowed on this lane.
Definition: NBEdge.h:130
A class representing a single district.
Definition: NBDistrict.h:72
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static std::string prohibitionConnection(const NBConnection &c)
the attribute value for a prohibition
SUMOReal getLoadedLength() const
Returns the length was set explicitly or the computed length if it wasn&#39;t set.
Definition: NBEdge.h:412
An (internal) definition of a single lane of an edge.
Definition: NBEdge.h:123
const std::string & getID() const
Returns the id.
Definition: Named.h:60
SVCPermissions permissions
List of vehicle types that are allowed on this lane.
Definition: NBEdge.h:132
void setPrecision(unsigned int precision=OUTPUT_ACCURACY)
Sets the precison or resets it to default.
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a SUMO-file.
void push_front_noDoublePos(const Position &p)
const int SUMOVehicleClass_MAX
const Position & getPosition() const
Returns the position of this node.
Definition: NBNode.h:232
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition: NBEdgeCont.h:198
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:59
the edges of a route
int getPriority() const
Returns the priority of the edge.
Definition: NBEdge.h:352
std::map< std::string, NBDistrict * >::const_iterator begin() const
Returns the pointer to the begin of the stored districts.
std::string getLaneID(unsigned int lane) const
Definition: NBEdge.cpp:1958
const std::vector< NBEdge * > & getSourceEdges() const
Returns the sources.
Definition: NBDistrict.h:198
std::string tlID
The id of the traffic light that controls this connection.
Definition: NBEdge.h:168
SVCPermissions preferred
List of vehicle types that are preferred on this lane.
Definition: NBEdge.h:134
std::string getInternalLaneID() const
Definition: NBEdge.cpp:74
This is an uncontrolled, minor link, has to brake.
static bool writeInternalConnections(OutputDevice &into, const NBNode &n)
Writes inner connections within the node.
int fromLane
The lane the connections starts at.
Definition: NBEdge.h:162
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
std::map< std::string, NBDistrict * >::const_iterator end() const
Returns the pointer to the end of the stored districts.
NBEdgeCont & getEdgeCont()
Returns the edge container.
Definition: NBNetBuilder.h:154
A list of positions.
SumoXMLNodeType getType() const
Returns the type of this node.
Definition: NBNode.h:269
static void writeEdge(OutputDevice &into, const NBEdge &e, bool noNames, bool origNames)
Writes an edge (&lt;edge ...)
bool hasLoadedLength() const
Returns whether a length was set explicitly.
Definition: NBEdge.h:420
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
const PositionVector & getShape() const
Returns the shape.
Definition: NBDistrict.h:222
const std::string & getProjString() const
Returns the network offset.
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
#define POSITION_EPS
Definition: config.h:189
static void writePositionLong(const Position &pos, OutputDevice &dev)
Writes the given position to device in long format (one attribute per dimension)
Definition: NWFrame.cpp:152
const Position getOffsetBase() const
Returns the network base.
std::vector< NBTrafficLightLogic * > getComputed() const
Returns a list of all computed logics.
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:135
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
const Boundary & getConvBoundary() const
Returns the converted boundary.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
static void writeLane(OutputDevice &into, const std::string &eID, const std::string &lID, SUMOReal speed, SVCPermissions permissions, SVCPermissions preferred, SUMOReal endOffset, SUMOReal width, const PositionVector &shape, const std::string &origID, SUMOReal length, unsigned int index, bool origNames)
Writes a lane (&lt;lane ...) of an edge.
const PositionVector & getShape() const
retrieve the junction shape
Definition: NBNode.cpp:1397
std::string getVehicleClassNames(SVCPermissions permissions)
Returns the ids of the given classes, divided using a &#39; &#39;.
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
static void normaliseSum(std::vector< T > &v, T msum=1.0)
Definition: VectorHelper.h:57
std::string origID
An original ID, if given (.
Definition: NBEdge.h:140
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
Definition: NBEdgeCont.h:190
static bool writeInternalEdges(OutputDevice &into, const NBNode &n, bool origNames)
Writes internal edges (&lt;edge ... with id[0]==&#39;:&#39;) of the given node.
SUMOReal length() const
Returns the length.
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:368
std::map< NBConnection, NBConnectionVector > NBConnectionProhibits
Definition of a container for connection block dependencies Includes a list of all connections which ...
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:245
LinkState getLinkState(const NBEdge *incoming, NBEdge *outgoing, int fromLane, bool mayDefinitelyPass, const std::string &tlID) const
Definition: NBNode.cpp:1293
NBNodeCont & getNodeCont()
Returns the node container.
Definition: NBNetBuilder.h:162
Instance responsible for building networks.
Definition: NBNetBuilder.h:113
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
int tlLinkNo
the traffic light index of this crossing (if controlled)
Definition: NBNode.h:153
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:41
static bool writeInternalNodes(OutputDevice &into, const NBNode &n)
Writes internal junctions (&lt;junction with id[0]==&#39;:&#39; ...) of the given node.
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition: NBEdge.h:521
A definition of a pedestrian walking area.
Definition: NBNode.h:160
bool isMacroscopicConnector() const
Returns whether this edge was marked as a macroscopic connector.
Definition: NBEdge.h:839
A storage for options typed value containers)
Definition: OptionsCont.h:108
This is an uncontrolled, major link, may pass.
void sortOutgoingConnectionsByIndex()
sorts the outgoing connections by their from-lane-index and their to-lane-index
Definition: NBEdge.cpp:817
NBTrafficLightLogicCont & getTLLogicCont()
Returns the traffic light logics container.
Definition: NBNetBuilder.h:178
static void writePreferences(OutputDevice &into, SVCPermissions preferred)
writes allowed disallowed attributes if needed;
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
int SUMOTime
Definition: SUMOTime.h:43
unsigned int tlLinkNo
The index of this connection within the controlling traffic light.
Definition: NBEdge.h:170
NBEdge * getTo() const
returns the to-edge (end of the connection)
The abstract direction of a link.
LaneSpreadFunction getLaneSpreadFunction() const
Returns how this edge&#39;s lanes&#39; lateral offset is computed.
Definition: NBEdge.h:597
Represents a single node (junction) during network building.
Definition: NBNode.h:75
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:153
A definition of a pedestrian crossing.
Definition: NBNode.h:132
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:218
static void writeJunction(OutputDevice &into, const NBNode &n, const bool checkLaneFoes)
Writes a junction (&lt;junction ...)
bool writeLogic(OutputDevice &into, const bool checkLaneFoes) const
Definition: NBNode.cpp:640
const std::vector< SUMOReal > & getSourceWeights() const
Returns the weights of the sources.
Definition: NBDistrict.h:190
const Boundary & getOrigBoundary() const
Returns the original boundary.
void push_back_noDoublePos(const Position &p)
const std::vector< SUMOReal > & getSinkWeights() const
Returns the weights of the sinks.
Definition: NBDistrict.h:206
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:64
unsigned int internalLaneIndex
The lane index of this internal lane within the internal edge.
Definition: NBEdge.h:190
const std::vector< WalkingArea > & getWalkingAreas() const
return this junctions pedestrian walking areas
Definition: NBNode.h:577
NBDistrictCont & getDistrictCont()
Returns the districts container.
Definition: NBNetBuilder.h:186
const std::string & getStreetName() const
Returns the street name of this edge.
Definition: NBEdge.h:458
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition: NBEdge.h:747
static const std::string MAJOR_VERSION
The version number for written files.
Definition: NWFrame.h:77
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:127
static void writeRoundabouts(OutputDevice &into, const std::set< EdgeSet > &roundabouts, const NBEdgeCont &ec)
Writes roundabouts.
PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const
static std::string writeSUMOTime(SUMOTime time)
writes a SUMOTime as int if possible, otherwise as a float
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void lf()
writes a line feed if applicable
Definition: OutputDevice.h:235
SUMOReal width
This lane&#39;s width.
Definition: NBEdge.h:138
static void writeConnection(OutputDevice &into, const NBEdge &from, const NBEdge::Connection &c, bool includeInternal, ConnectionStyle style=SUMONET)
Writes connections outgoing from the given edge (also used in NWWriter_XML)
PositionVector shape
The polygonal shape.
Definition: NBNode.h:174
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
The link has no direction (is a dead end link)
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing) const
Returns the representation of the described stream&#39;s direction.
Definition: NBNode.cpp:1247
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:360