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-sim.org/
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>
40 #include <netbuild/NBEdge.h>
41 #include <netbuild/NBEdgeCont.h>
42 #include <netbuild/NBNode.h>
43 #include <netbuild/NBNodeCont.h>
44 #include <netbuild/NBNetBuilder.h>
46 #include <netbuild/NBDistrict.h>
47 #include "NWFrame.h"
48 #include "NWWriter_SUMO.h"
49 
50 #ifdef CHECK_MEMORY_LEAKS
51 #include <foreign/nvwa/debug_new.h>
52 #endif // CHECK_MEMORY_LEAKS
53 
54 
55 
56 // ===========================================================================
57 // method definitions
58 // ===========================================================================
59 // ---------------------------------------------------------------------------
60 // static methods
61 // ---------------------------------------------------------------------------
62 void
64  // check whether a sumo net-file shall be generated
65  if (!oc.isSet("output-file")) {
66  return;
67  }
68  OutputDevice& device = OutputDevice::getDevice(oc.getString("output-file"));
69  device.writeXMLHeader("net", NWFrame::MAJOR_VERSION + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo-sim.org/xsd/net_file.xsd\""); // street names may contain non-ascii chars
70  device.lf();
71  // get involved container
72  const NBNodeCont& nc = nb.getNodeCont();
73  const NBEdgeCont& ec = nb.getEdgeCont();
74  const NBDistrictCont& dc = nb.getDistrictCont();
75 
76  // write network offsets and projection
77  writeLocation(device);
78 
79  // write inner lanes
80  bool origNames = oc.getBool("output.original-names");
81  if (!oc.getBool("no-internal-links")) {
82  bool hadAny = false;
83  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
84  hadAny |= writeInternalEdges(device, *(*i).second, origNames);
85  }
86  if (hadAny) {
87  device.lf();
88  }
89  }
90 
91  // write edges with lanes and connected edges
92  bool noNames = !oc.getBool("output.street-names");
93  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
94  writeEdge(device, *(*i).second, noNames, origNames);
95  }
96  device.lf();
97 
98  // write tls logics
99  writeTrafficLights(device, nb.getTLLogicCont());
100 
101  // write the nodes (junctions)
102  std::set<NBNode*> roundaboutNodes;
103  const bool checkLaneFoesAll = oc.getBool("check-lane-foes.all");
104  const bool checkLaneFoesRoundabout = !checkLaneFoesAll && oc.getBool("check-lane-foes.roundabout");
105  if (checkLaneFoesRoundabout) {
106  const std::vector<EdgeVector>& roundabouts = nb.getRoundabouts();
107  for (std::vector<EdgeVector>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
108  for (EdgeVector::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
109  roundaboutNodes.insert((*j)->getToNode());
110  }
111  }
112  }
113  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
114  const bool checkLaneFoes = checkLaneFoesAll || (checkLaneFoesRoundabout && roundaboutNodes.count((*i).second) > 0);
115  writeJunction(device, *(*i).second, checkLaneFoes);
116  }
117  device.lf();
118  const bool includeInternal = !oc.getBool("no-internal-links");
119  if (includeInternal) {
120  // ... internal nodes if not unwanted
121  bool hadAny = false;
122  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
123  hadAny |= writeInternalNodes(device, *(*i).second);
124  }
125  if (hadAny) {
126  device.lf();
127  }
128  }
129 
130  // write the successors of lanes
131  unsigned int numConnections = 0;
132  for (std::map<std::string, NBEdge*>::const_iterator it_edge = ec.begin(); it_edge != ec.end(); it_edge++) {
133  NBEdge* from = it_edge->second;
135  const std::vector<NBEdge::Connection> connections = from->getConnections();
136  numConnections += (unsigned int)connections.size();
137  for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); it_c++) {
138  writeConnection(device, *from, *it_c, includeInternal);
139  }
140  }
141  if (numConnections > 0) {
142  device.lf();
143  }
144  if (includeInternal) {
145  // ... internal successors if not unwanted
146  bool hadAny = false;
147  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
148  hadAny |= writeInternalConnections(device, *(*i).second);
149  }
150  if (hadAny) {
151  device.lf();
152  }
153  }
154  // write loaded prohibitions
155  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
156  writeProhibitions(device, i->second->getProhibitions());
157  }
158 
159  // write roundabout information
160  const std::vector<EdgeVector>& roundabouts = nb.getRoundabouts();
161  // make output deterministic
162  std::vector<std::vector<std::string> > edgeIDs;
163  for (std::vector<EdgeVector>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
164  std::vector<std::string> tEdgeIDs;
165  for (EdgeVector::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
166  tEdgeIDs.push_back((*j)->getID());
167  }
168  std::sort(tEdgeIDs.begin(), tEdgeIDs.end());
169  edgeIDs.push_back(tEdgeIDs);
170  }
171  std::sort(edgeIDs.begin(), edgeIDs.end());
172  // write
173  for (std::vector<std::vector<std::string> >::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) {
174  writeRoundabout(device, *i, ec);
175  }
176  if (roundabouts.size() != 0) {
177  device.lf();
178  }
179 
180  // write the districts
181  for (std::map<std::string, NBDistrict*>::const_iterator i = dc.begin(); i != dc.end(); i++) {
182  writeDistrict(device, *(*i).second);
183  }
184  if (dc.size() != 0) {
185  device.lf();
186  }
187  device.close();
188 }
189 
190 
191 bool
192 NWWriter_SUMO::writeInternalEdges(OutputDevice& into, const NBNode& n, bool origNames) {
193  bool ret = false;
194  const EdgeVector& incoming = n.getIncomingEdges();
195  for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
196  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
197  if (elv.size() > 0) {
198  bool haveVia = false;
199  NBEdge* toEdge = 0;
200  std::string internalEdgeID = "";
201  // first pass: compute average lengths of non-via edges
202  std::map<NBEdge*, SUMOReal> lengthSum;
203  std::map<NBEdge*, int> numLanes;
204  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
205  lengthSum[(*k).toEdge] += MAX2((*k).shape.length(), (SUMOReal)POSITION_EPS);
206  numLanes[(*k).toEdge] += 1;
207  }
208  // second pass: write non-via edges
209  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
210  if ((*k).toEdge == 0) {
211  assert(false); // should never happen. tell me when it does
212  continue;
213  }
214  if (toEdge != (*k).toEdge) {
215  internalEdgeID = (*k).id;
216  if (toEdge != 0) {
217  // close the previous edge
218  into.closeTag();
219  }
220  toEdge = (*k).toEdge;
221  into.openTag(SUMO_TAG_EDGE);
222  into.writeAttr(SUMO_ATTR_ID, internalEdgeID);
224  // open a new edge
225  }
226  // to avoid changing to an internal lane which has a successor
227  // with the wrong permissions we need to inherit them from the successor
228  const NBEdge::Lane& successor = (*k).toEdge->getLanes()[(*k).toLane];
229  const SUMOReal length = lengthSum[toEdge] / numLanes[toEdge];
230  writeLane(into, internalEdgeID, (*k).getInternalLaneID(), (*k).vmax,
231  successor.permissions, successor.preferred,
232  NBEdge::UNSPECIFIED_OFFSET, successor.width, (*k).shape, (*k).origID,
233  length, (*k).internalLaneIndex, origNames);
234  haveVia = haveVia || (*k).haveVia;
235  }
236  ret = true;
237  into.closeTag(); // close the last edge
238  // third pass: write via edges
239  if (haveVia) {
240  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
241  if (!(*k).haveVia) {
242  continue;
243  }
244  if ((*k).toEdge == 0) {
245  assert(false); // should never happen. tell me when it does
246  continue;
247  }
248  const NBEdge::Lane& successor = (*k).toEdge->getLanes()[(*k).toLane];
249  into.openTag(SUMO_TAG_EDGE);
250  into.writeAttr(SUMO_ATTR_ID, (*k).viaID);
252  writeLane(into, (*k).viaID, (*k).viaID + "_0", (*k).viaVmax, SVCFreeForAll, SVCFreeForAll,
253  NBEdge::UNSPECIFIED_OFFSET, successor.width, (*k).viaShape, (*k).origID,
254  MAX2((*k).viaShape.length(), (SUMOReal)POSITION_EPS), // microsim needs positive length
255  0, origNames);
256  into.closeTag(); // close the last edge
257  }
258  }
259  }
260  }
261  return ret;
262 }
263 
264 
265 void
266 NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames, bool origNames) {
267  // write the edge's begin
270  into.writeAttr(SUMO_ATTR_TO, e.getToNode()->getID());
271  if (!noNames && e.getStreetName() != "") {
273  }
275  if (e.getTypeName() != "") {
277  }
278  if (e.isMacroscopicConnector()) {
280  }
281  // write the spread type if not default ("right")
284  }
285  if (e.hasLoadedLength()) {
287  }
288  if (!e.hasDefaultGeometry()) {
290  }
291  // write the lanes
292  const std::vector<NBEdge::Lane>& lanes = e.getLanes();
293 
294  SUMOReal length = e.getLoadedLength();
295  if (OptionsCont::getOptions().getBool("no-internal-links") && !e.hasLoadedLength()) {
296  // use length to junction center even if a modified geometry was given
297  PositionVector geom = e.getGeometry();
300  length = geom.length();
301  }
302  if (length <= 0) {
303  length = (SUMOReal)POSITION_EPS;
304  }
305  for (unsigned int i = 0; i < (unsigned int) lanes.size(); i++) {
306  const NBEdge::Lane& l = lanes[i];
307  writeLane(into, e.getID(), e.getLaneID(i), l.speed,
308  l.permissions, l.preferred, l.offset, l.width, l.shape, l.origID,
309  length, i, origNames);
310  }
311  // close the edge
312  into.closeTag();
313 }
314 
315 
316 void
317 NWWriter_SUMO::writeLane(OutputDevice& into, const std::string& eID, const std::string& lID,
318  SUMOReal speed, SVCPermissions permissions, SVCPermissions preferred,
319  SUMOReal offset, SUMOReal width, const PositionVector& shape,
320  const std::string& origID, SUMOReal length, unsigned int index, bool origNames) {
321  // output the lane's attributes
323  // the first lane of an edge will be the depart lane
324  into.writeAttr(SUMO_ATTR_INDEX, index);
325  // write the list of allowed/disallowed vehicle classes
326  writePermissions(into, permissions);
327  writePreferences(into, preferred);
328  // some further information
329  if (speed == 0) {
330  WRITE_WARNING("Lane #" + toString(index) + " of edge '" + eID + "' has a maximum velocity of 0.");
331  } else if (speed < 0) {
332  throw ProcessError("Negative velocity (" + toString(speed) + " on edge '" + eID + "' lane#" + toString(index) + ".");
333  }
334  if (offset > 0) {
335  length = length - offset;
336  }
337  into.writeAttr(SUMO_ATTR_SPEED, speed);
338  into.writeAttr(SUMO_ATTR_LENGTH, length);
339  if (offset != NBEdge::UNSPECIFIED_OFFSET) {
340  into.writeAttr(SUMO_ATTR_ENDOFFSET, offset);
341  }
342  if (width != NBEdge::UNSPECIFIED_WIDTH) {
343  into.writeAttr(SUMO_ATTR_WIDTH, width);
344  }
345  into.writeAttr(SUMO_ATTR_SHAPE, offset > 0 ?
346  shape.getSubpart(0, shape.length() - offset) : shape);
347  if (origNames && origID != "") {
348  into.openTag(SUMO_TAG_PARAM);
349  into.writeAttr(SUMO_ATTR_KEY, "origId");
350  into.writeAttr(SUMO_ATTR_VALUE, origID);
351  into.closeTag();
352  into.closeTag();
353  } else {
354  into.closeTag();
355  }
356 }
357 
358 
359 void
360 NWWriter_SUMO::writeJunction(OutputDevice& into, const NBNode& n, const bool checkLaneFoes) {
361  // write the attributes
363  into.writeAttr(SUMO_ATTR_TYPE, n.getType());
365  // write the incoming lanes
366  std::string incLanes;
367  const std::vector<NBEdge*>& incoming = n.getIncomingEdges();
368  for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); ++i) {
369  unsigned int noLanes = (*i)->getNumLanes();
370  for (unsigned int j = 0; j < noLanes; j++) {
371  incLanes += (*i)->getLaneID(j);
372  if (i != incoming.end() - 1 || j < noLanes - 1) {
373  incLanes += ' ';
374  }
375  }
376  }
377  into.writeAttr(SUMO_ATTR_INCLANES, incLanes);
378  // write the internal lanes
379  std::string intLanes;
380  if (!OptionsCont::getOptions().getBool("no-internal-links")) {
381  unsigned int l = 0;
382  for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
383  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
384  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
385  if ((*k).toEdge == 0) {
386  continue;
387  }
388  if (l != 0) {
389  intLanes += ' ';
390  }
391  if (!(*k).haveVia) {
392  intLanes += (*k).getInternalLaneID();
393  } else {
394  intLanes += (*k).viaID + "_0";
395  }
396  l++;
397  }
398  }
399  }
400  into.writeAttr(SUMO_ATTR_INTLANES, intLanes);
401  // close writing
403  if (n.getType() == NODETYPE_DEAD_END) {
404  into.closeTag();
405  } else {
406  // write right-of-way logics
407  n.writeLogic(into, checkLaneFoes);
408  into.closeTag();
409  }
410 }
411 
412 
413 bool
415  bool ret = false;
416  const std::vector<NBEdge*>& incoming = n.getIncomingEdges();
417  // build the list of internal lane ids
418  std::vector<std::string> internalLaneIDs;
419  for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
420  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
421  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
422  if ((*k).toEdge != 0) {
423  internalLaneIDs.push_back((*k).getInternalLaneID());
424  }
425  }
426  }
427  // write the internal nodes
428  for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
429  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
430  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
431  if ((*k).toEdge == 0 || !(*k).haveVia) {
432  continue;
433  }
434  Position pos = (*k).shape[-1];
435  into.openTag(SUMO_TAG_JUNCTION).writeAttr(SUMO_ATTR_ID, (*k).viaID + "_0");
437  NWFrame::writePositionLong(pos, into);
438  std::string incLanes = (*k).getInternalLaneID();
439  if ((*k).foeIncomingLanes.length() != 0) {
440  incLanes += " " + (*k).foeIncomingLanes;
441  }
442  into.writeAttr(SUMO_ATTR_INCLANES, incLanes);
443  const std::vector<unsigned int>& foes = (*k).foeInternalLinks;
444  std::vector<std::string> foeIDs;
445  for (std::vector<unsigned int>::const_iterator it = foes.begin(); it != foes.end(); ++it) {
446  foeIDs.push_back(internalLaneIDs[*it]);
447  }
448  into.writeAttr(SUMO_ATTR_INTLANES, joinToString(foeIDs, " "));
449  into.closeTag();
450  ret = true;
451  }
452  }
453  return ret;
454 }
455 
456 
457 void
459  bool includeInternal, ConnectionStyle style) {
460  assert(c.toEdge != 0);
462  into.writeAttr(SUMO_ATTR_FROM, from.getID());
463  into.writeAttr(SUMO_ATTR_TO, c.toEdge->getID());
466  if (c.mayDefinitelyPass && style != TLL) {
468  }
469  if (style != PLAIN) {
470  if (includeInternal) {
472  }
473  // set information about the controlling tl if any
474  if (c.tlID != "") {
475  into.writeAttr(SUMO_ATTR_TLID, c.tlID);
477  }
478  if (style == SUMONET) {
479  // write the direction information
480  LinkDirection dir = from.getToNode()->getDirection(&from, c.toEdge);
481  assert(dir != LINKDIR_NODIR);
482  into.writeAttr(SUMO_ATTR_DIR, toString(dir));
483  // write the state information
484  const LinkState linkState = from.getToNode()->getLinkState(
485  &from, c.toEdge, c.toLane, c.mayDefinitelyPass, c.tlID);
486  into.writeAttr(SUMO_ATTR_STATE, linkState);
487  }
488  }
489  into.closeTag();
490 }
491 
492 
493 bool
495  bool ret = false;
496  const std::vector<NBEdge*>& incoming = n.getIncomingEdges();
497  for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); ++i) {
498  NBEdge* from = *i;
499  const std::vector<NBEdge::Connection>& connections = from->getConnections();
500  for (std::vector<NBEdge::Connection>::const_iterator j = connections.begin(); j != connections.end(); ++j) {
501  const NBEdge::Connection& c = *j;
502  assert(c.toEdge != 0);
503  if (c.haveVia) {
504  // internal split
505  writeInternalConnection(into, c.id, c.toEdge->getID(), c.internalLaneIndex, c.toLane, c.viaID + "_0");
506  writeInternalConnection(into, c.viaID, c.toEdge->getID(), 0, c.toLane, "");
507  } else {
508  // no internal split
510  }
511  ret = true;
512  }
513  }
514  return ret;
515 }
516 
517 
518 void
520  const std::string& from, const std::string& to,
521  int fromLane, int toLane, const std::string& via) {
523  into.writeAttr(SUMO_ATTR_FROM, from);
524  into.writeAttr(SUMO_ATTR_TO, to);
525  into.writeAttr(SUMO_ATTR_FROM_LANE, fromLane);
526  into.writeAttr(SUMO_ATTR_TO_LANE, toLane);
527  if (via != "") {
528  into.writeAttr(SUMO_ATTR_VIA, via);
529  }
530  into.writeAttr(SUMO_ATTR_DIR, "s");
531  into.writeAttr(SUMO_ATTR_STATE, (via != "" ? "m" : "M"));
532  into.closeTag();
533 }
534 
535 
536 void
537 NWWriter_SUMO::writeRoundabout(OutputDevice& into, const std::vector<std::string>& edgeIDs,
538  const NBEdgeCont& ec) {
539  std::vector<std::string> nodeIDs;
540  for (std::vector<std::string>::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) {
541  nodeIDs.push_back(ec.retrieve(*i)->getToNode()->getID());
542  }
543  std::sort(nodeIDs.begin(), nodeIDs.end());
545  into.writeAttr(SUMO_ATTR_NODES, joinToString(nodeIDs, " "));
546  into.writeAttr(SUMO_ATTR_EDGES, joinToString(edgeIDs, " "));
547  into.closeTag();
548 }
549 
550 
551 void
553  std::vector<SUMOReal> sourceW = d.getSourceWeights();
555  std::vector<SUMOReal> sinkW = d.getSinkWeights();
557  // write the head and the id of the district
559  if (d.getShape().size() > 0) {
561  }
562  size_t i;
563  // write all sources
564  const std::vector<NBEdge*>& sources = d.getSourceEdges();
565  for (i = 0; i < sources.size(); i++) {
566  // write the head and the id of the source
567  into.openTag(SUMO_TAG_TAZSOURCE).writeAttr(SUMO_ATTR_ID, sources[i]->getID()).writeAttr(SUMO_ATTR_WEIGHT, sourceW[i]);
568  into.closeTag();
569  }
570  // write all sinks
571  const std::vector<NBEdge*>& sinks = d.getSinkEdges();
572  for (i = 0; i < sinks.size(); i++) {
573  // write the head and the id of the sink
574  into.openTag(SUMO_TAG_TAZSINK).writeAttr(SUMO_ATTR_ID, sinks[i]->getID()).writeAttr(SUMO_ATTR_WEIGHT, sinkW[i]);
575  into.closeTag();
576  }
577  // write the tail
578  into.closeTag();
579 }
580 
581 
582 std::string
584  SUMOReal time = STEPS2TIME(steps);
585  if (time == std::floor(time)) {
586  return toString(int(time));
587  } else {
588  return toString(time);
589  }
590 }
591 
592 
593 void
595  for (NBConnectionProhibits::const_iterator j = prohibitions.begin(); j != prohibitions.end(); j++) {
596  NBConnection prohibited = (*j).first;
597  const NBConnectionVector& prohibiting = (*j).second;
598  for (NBConnectionVector::const_iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
599  NBConnection prohibitor = *k;
603  into.closeTag();
604  }
605  }
606 }
607 
608 
609 std::string
611  return c.getFrom()->getID() + "->" + c.getTo()->getID();
612 }
613 
614 
615 void
617  std::vector<NBTrafficLightLogic*> logics = tllCont.getComputed();
618  for (std::vector<NBTrafficLightLogic*>::iterator it = logics.begin(); it != logics.end(); it++) {
620  into.writeAttr(SUMO_ATTR_ID, (*it)->getID());
621  into.writeAttr(SUMO_ATTR_TYPE, (*it)->getType());
622  into.writeAttr(SUMO_ATTR_PROGRAMID, (*it)->getProgramID());
623  into.writeAttr(SUMO_ATTR_OFFSET, writeSUMOTime((*it)->getOffset()));
624  // write params
625  const std::map<std::string, std::string>& params = (*it)->getMap();
626  for (std::map<std::string, std::string>::const_iterator i = params.begin(); i != params.end(); ++i) {
627  into.openTag(SUMO_TAG_PARAM);
628  into.writeAttr(SUMO_ATTR_KEY, (*i).first);
629  into.writeAttr(SUMO_ATTR_VALUE, (*i).second);
630  into.closeTag();
631  }
632  // write the phases
633  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = (*it)->getPhases();
634  for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator j = phases.begin(); j != phases.end(); ++j) {
635  into.openTag(SUMO_TAG_PHASE);
636  into.writeAttr(SUMO_ATTR_DURATION, writeSUMOTime(j->duration));
637  into.writeAttr(SUMO_ATTR_STATE, j->state);
638  into.closeTag();
639  }
640  into.closeTag();
641  }
642  if (logics.size() > 0) {
643  into.lf();
644  }
645 }
646 
647 
648 void
650  const GeoConvHelper& geoConvHelper = GeoConvHelper::getFinal();
652  into.writeAttr(SUMO_ATTR_NET_OFFSET, geoConvHelper.getOffsetBase());
653  into.writeAttr(SUMO_ATTR_CONV_BOUNDARY, geoConvHelper.getConvBoundary());
654  if (geoConvHelper.usingGeoProjection()) {
656  }
657  into.writeAttr(SUMO_ATTR_ORIG_BOUNDARY, geoConvHelper.getOrigBoundary());
658  if (geoConvHelper.usingGeoProjection()) {
659  into.setPrecision();
660  }
661  into.writeAttr(SUMO_ATTR_ORIG_PROJ, geoConvHelper.getProjString());
662  into.closeTag();
663  into.lf();
664 }
665 
666 
667 void
669  if (permissions == SVCFreeForAll) {
670  return;
671  } else if (permissions == 0) {
672  // special case: since all-empty encodes FreeForAll we must list all disallowed
674  return;
675  } else {
676  std::pair<std::string, bool> encoding = getPermissionEncoding(permissions);
677  if (encoding.second) {
678  into.writeAttr(SUMO_ATTR_ALLOW, encoding.first);
679  } else {
680  into.writeAttr(SUMO_ATTR_DISALLOW, encoding.first);
681  }
682  }
683 }
684 
685 
686 void
688  if (preferred == SVCFreeForAll || preferred == 0) {
689  return;
690  } else {
692  }
693 }
694 /****************************************************************************/
695 
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:256
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges.
Definition: NBNode.h:170
void close()
Closes the device and removes it from the dictionary.
static void writeLane(OutputDevice &into, const std::string &eID, const std::string &lID, SUMOReal speed, SVCPermissions permissions, SVCPermissions preferred, SUMOReal offset, SUMOReal width, const PositionVector &shape, const std::string &origID, SUMOReal length, unsigned int index, bool origNames)
Writes a lane (<lane ...) of an edge.
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:1439
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's shape.
Definition: NBEdge.h:128
static void writeDistrict(OutputDevice &into, const NBDistrict &d)
Writes a district.
const std::string & getTypeName() const
Returns the type name.
Definition: NBEdge.h:478
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:368
size_t size() const
Returns the number of districts inside the container.
A container for traffic light definitions and built programs.
static void writeLocation(OutputDevice &into)
writes the location element
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:486
#define GEO_OUTPUT_ACCURACY
Definition: config.h:16
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.
std::string getAllowedVehicleClassNames(SVCPermissions permissions)
Returns the ids of the given classes, divided using a ' '.
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.
T MAX2(T a, T b)
Definition: StdDefs.h:71
the weight of a district's source or sink
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
Definition: NBEdge.h:172
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:196
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
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 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't set.
Definition: NBEdge.h:406
An (internal) definition of a single lane of an edge.
Definition: NBEdge.h:123
const std::vector< EdgeVector > & getRoundabouts() const
Returns the determined roundabouts.
Definition: NBNetBuilder.h:194
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 Position & getPosition() const
Returns the position of this node.
Definition: NBNode.h:158
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:346
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:1895
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:73
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.
std::pair< std::string, bool > getPermissionEncoding(SVCPermissions permissions)
returns the shorter encoding of the given permissions (selects automatically wether to use allow or d...
SumoXMLNodeType getType() const
Returns the type of this node.
Definition: NBNode.h:195
SUMOReal offset
This lane's offset to the intersection begin.
Definition: NBEdge.h:136
static void writeEdge(OutputDevice &into, const NBEdge &e, bool noNames, bool origNames)
Writes an edge (<edge ...)
bool hasLoadedLength() const
Returns whether a length was set explicitly.
Definition: NBEdge.h:414
#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:186
static void writePositionLong(const Position &pos, OutputDevice &dev)
Writes the given position to device in long format (one attribute per dimension)
Definition: NWFrame.cpp:146
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:142
const Boundary & getConvBoundary() const
Returns the converted boundary.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:52
const PositionVector & getShape() const
Definition: NBNode.cpp:1332
const SVCPermissions SVCFreeForAll
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 (<edge ... with id[0]==':') of the given node.
SUMOReal length() const
Returns the length.
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:362
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:251
LinkState getLinkState(const NBEdge *incoming, NBEdge *outgoing, int fromLane, bool mayDefinitelyPass, const std::string &tlID) const
Definition: NBNode.cpp:1228
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.
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:38
static bool writeInternalNodes(OutputDevice &into, const NBNode &n)
Writes internal junctions (<junction with id[0]==':' ...) of the given node.
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition: NBEdge.h:499
bool isMacroscopicConnector() const
Returns whether this edge was marked as a macroscopic connector.
Definition: NBEdge.h:813
A storage for options typed value containers)
Definition: OptionsCont.h:108
void sortOutgoingConnectionsByIndex()
sorts the outgoing connections by their from-lane-index and their to-lane-index
Definition: NBEdge.cpp:806
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...
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's lanes' lateral offset is computed.
Definition: NBEdge.h:575
Represents a single node (junction) during network building.
Definition: NBNode.h:74
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:152
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:215
static void writeJunction(OutputDevice &into, const NBNode &n, const bool checkLaneFoes)
Writes a junction (<junction ...)
bool writeLogic(OutputDevice &into, const bool checkLaneFoes) const
Definition: NBNode.cpp:595
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
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:452
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition: NBEdge.h:724
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:134
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:234
SUMOReal width
This lane'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)
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's direction.
Definition: NBNode.cpp:1182
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:354