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-2013 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, NBEdge::UNSPECIFIED_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  into.openTag(SUMO_TAG_EDGE);
249  into.writeAttr(SUMO_ATTR_ID, (*k).viaID);
251  writeLane(into, (*k).viaID, (*k).viaID + "_0", (*k).viaVmax, SVCFreeForAll, SVCFreeForAll,
252  NBEdge::UNSPECIFIED_OFFSET, NBEdge::UNSPECIFIED_WIDTH, (*k).viaShape, (*k).origID,
253  MAX2((*k).viaShape.length(), (SUMOReal)POSITION_EPS), // microsim needs positive length
254  0, origNames);
255  into.closeTag(); // close the last edge
256  }
257  }
258  }
259  }
260  return ret;
261 }
262 
263 
264 void
265 NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames, bool origNames) {
266  // write the edge's begin
269  into.writeAttr(SUMO_ATTR_TO, e.getToNode()->getID());
270  if (!noNames && e.getStreetName() != "") {
272  }
274  if (e.getTypeName() != "") {
276  }
277  if (e.isMacroscopicConnector()) {
279  }
280  // write the spread type if not default ("right")
283  }
284  if (e.hasLoadedLength()) {
286  }
287  if (!e.hasDefaultGeometry()) {
289  }
290  // write the lanes
291  const std::vector<NBEdge::Lane>& lanes = e.getLanes();
292 
293  SUMOReal length = e.getLoadedLength();
294  if (OptionsCont::getOptions().getBool("no-internal-links") && !e.hasLoadedLength()) {
295  // use length to junction center even if a modified geometry was given
296  PositionVector geom = e.getGeometry();
299  length = geom.length();
300  }
301  if (length <= 0) {
302  length = (SUMOReal)POSITION_EPS;
303  }
304  for (unsigned int i = 0; i < (unsigned int) lanes.size(); i++) {
305  const NBEdge::Lane& l = lanes[i];
306  writeLane(into, e.getID(), e.getLaneID(i), l.speed,
307  l.permissions, l.preferred, l.offset, l.width, l.shape, l.origID,
308  length, i, origNames);
309  }
310  // close the edge
311  into.closeTag();
312 }
313 
314 
315 void
316 NWWriter_SUMO::writeLane(OutputDevice& into, const std::string& eID, const std::string& lID,
317  SUMOReal speed, SVCPermissions permissions, SVCPermissions preferred,
318  SUMOReal offset, SUMOReal width, const PositionVector& shape,
319  const std::string& origID, SUMOReal length, unsigned int index, bool origNames) {
320  // output the lane's attributes
322  // the first lane of an edge will be the depart lane
323  into.writeAttr(SUMO_ATTR_INDEX, index);
324  // write the list of allowed/disallowed vehicle classes
325  writePermissions(into, permissions);
326  writePreferences(into, preferred);
327  // some further information
328  if (speed == 0) {
329  WRITE_WARNING("Lane #" + toString(index) + " of edge '" + eID + "' has a maximum velocity of 0.");
330  } else if (speed < 0) {
331  throw ProcessError("Negative velocity (" + toString(speed) + " on edge '" + eID + "' lane#" + toString(index) + ".");
332  }
333  if (offset > 0) {
334  length = length - offset;
335  }
336  into.writeAttr(SUMO_ATTR_SPEED, speed);
337  into.writeAttr(SUMO_ATTR_LENGTH, length);
338  if (offset != NBEdge::UNSPECIFIED_OFFSET) {
339  into.writeAttr(SUMO_ATTR_ENDOFFSET, offset);
340  }
341  if (width != NBEdge::UNSPECIFIED_WIDTH) {
342  into.writeAttr(SUMO_ATTR_WIDTH, width);
343  }
344  into.writeAttr(SUMO_ATTR_SHAPE, offset > 0 ?
345  shape.getSubpart(0, shape.length() - offset) : shape);
346  if (origNames && origID != "") {
347  into.openTag(SUMO_TAG_PARAM);
348  into.writeAttr(SUMO_ATTR_KEY, "origId");
349  into.writeAttr(SUMO_ATTR_VALUE, origID);
350  into.closeTag();
351  into.closeTag();
352  } else {
353  into.closeTag();
354  }
355 }
356 
357 
358 void
359 NWWriter_SUMO::writeJunction(OutputDevice& into, const NBNode& n, const bool checkLaneFoes) {
360  // write the attributes
362  into.writeAttr(SUMO_ATTR_TYPE, n.getType());
364  // write the incoming lanes
365  std::string incLanes;
366  const std::vector<NBEdge*>& incoming = n.getIncomingEdges();
367  for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); ++i) {
368  unsigned int noLanes = (*i)->getNumLanes();
369  for (unsigned int j = 0; j < noLanes; j++) {
370  incLanes += (*i)->getLaneID(j);
371  if (i != incoming.end() - 1 || j < noLanes - 1) {
372  incLanes += ' ';
373  }
374  }
375  }
376  into.writeAttr(SUMO_ATTR_INCLANES, incLanes);
377  // write the internal lanes
378  std::string intLanes;
379  if (!OptionsCont::getOptions().getBool("no-internal-links")) {
380  unsigned int l = 0;
381  for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
382  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
383  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
384  if ((*k).toEdge == 0) {
385  continue;
386  }
387  if (l != 0) {
388  intLanes += ' ';
389  }
390  if (!(*k).haveVia) {
391  intLanes += (*k).getInternalLaneID();
392  } else {
393  intLanes += (*k).viaID + "_0";
394  }
395  l++;
396  }
397  }
398  }
399  into.writeAttr(SUMO_ATTR_INTLANES, intLanes);
400  // close writing
402  if (n.getType() == NODETYPE_DEAD_END) {
403  into.closeTag();
404  } else {
405  // write right-of-way logics
406  n.writeLogic(into, checkLaneFoes);
407  into.closeTag();
408  }
409 }
410 
411 
412 bool
414  bool ret = false;
415  const std::vector<NBEdge*>& incoming = n.getIncomingEdges();
416  // build the list of internal lane ids
417  std::vector<std::string> internalLaneIDs;
418  for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
419  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
420  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
421  if ((*k).toEdge != 0) {
422  internalLaneIDs.push_back((*k).getInternalLaneID());
423  }
424  }
425  }
426  // write the internal nodes
427  for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
428  const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
429  for (std::vector<NBEdge::Connection>::const_iterator k = elv.begin(); k != elv.end(); ++k) {
430  if ((*k).toEdge == 0 || !(*k).haveVia) {
431  continue;
432  }
433  Position pos = (*k).shape[-1];
434  into.openTag(SUMO_TAG_JUNCTION).writeAttr(SUMO_ATTR_ID, (*k).viaID + "_0");
436  NWFrame::writePositionLong(pos, into);
437  std::string incLanes = (*k).getInternalLaneID();
438  if ((*k).foeIncomingLanes.length() != 0) {
439  incLanes += " " + (*k).foeIncomingLanes;
440  }
441  into.writeAttr(SUMO_ATTR_INCLANES, incLanes);
442  const std::vector<unsigned int>& foes = (*k).foeInternalLinks;
443  std::vector<std::string> foeIDs;
444  for (std::vector<unsigned int>::const_iterator it = foes.begin(); it != foes.end(); ++it) {
445  foeIDs.push_back(internalLaneIDs[*it]);
446  }
447  into.writeAttr(SUMO_ATTR_INTLANES, joinToString(foeIDs, " "));
448  into.closeTag();
449  ret = true;
450  }
451  }
452  return ret;
453 }
454 
455 
456 void
458  bool includeInternal, ConnectionStyle style) {
459  assert(c.toEdge != 0);
461  into.writeAttr(SUMO_ATTR_FROM, from.getID());
462  into.writeAttr(SUMO_ATTR_TO, c.toEdge->getID());
465  if (c.mayDefinitelyPass) {
467  }
468  if (style != PLAIN) {
469  if (includeInternal) {
471  }
472  // set information about the controlling tl if any
473  if (c.tlID != "") {
474  into.writeAttr(SUMO_ATTR_TLID, c.tlID);
476  }
477  if (style == SUMONET) {
478  // write the direction information
479  LinkDirection dir = from.getToNode()->getDirection(&from, c.toEdge);
480  assert(dir != LINKDIR_NODIR);
481  into.writeAttr(SUMO_ATTR_DIR, toString(dir));
482  // write the state information
483  const LinkState linkState = from.getToNode()->getLinkState(
484  &from, c.toEdge, c.toLane, c.mayDefinitelyPass, c.tlID);
485  into.writeAttr(SUMO_ATTR_STATE, linkState);
486  }
487  }
488  into.closeTag();
489 }
490 
491 
492 bool
494  bool ret = false;
495  const std::vector<NBEdge*>& incoming = n.getIncomingEdges();
496  for (std::vector<NBEdge*>::const_iterator i = incoming.begin(); i != incoming.end(); ++i) {
497  NBEdge* from = *i;
498  const std::vector<NBEdge::Connection>& connections = from->getConnections();
499  for (std::vector<NBEdge::Connection>::const_iterator j = connections.begin(); j != connections.end(); ++j) {
500  const NBEdge::Connection& c = *j;
501  assert(c.toEdge != 0);
502  if (c.haveVia) {
503  // internal split
504  writeInternalConnection(into, c.id, c.toEdge->getID(), c.internalLaneIndex, c.toLane, c.viaID + "_0");
505  writeInternalConnection(into, c.viaID, c.toEdge->getID(), 0, c.toLane, "");
506  } else {
507  // no internal split
509  }
510  ret = true;
511  }
512  }
513  return ret;
514 }
515 
516 
517 void
519  const std::string& from, const std::string& to,
520  int fromLane, int toLane, const std::string& via) {
522  into.writeAttr(SUMO_ATTR_FROM, from);
523  into.writeAttr(SUMO_ATTR_TO, to);
524  into.writeAttr(SUMO_ATTR_FROM_LANE, fromLane);
525  into.writeAttr(SUMO_ATTR_TO_LANE, toLane);
526  if (via != "") {
527  into.writeAttr(SUMO_ATTR_VIA, via);
528  }
529  into.writeAttr(SUMO_ATTR_DIR, "s");
530  into.writeAttr(SUMO_ATTR_STATE, "M");
531  into.closeTag();
532 }
533 
534 
535 void
536 NWWriter_SUMO::writeRoundabout(OutputDevice& into, const std::vector<std::string>& edgeIDs,
537  const NBEdgeCont& ec) {
538  std::vector<std::string> nodeIDs;
539  for (std::vector<std::string>::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) {
540  nodeIDs.push_back(ec.retrieve(*i)->getToNode()->getID());
541  }
542  std::sort(nodeIDs.begin(), nodeIDs.end());
544  into.writeAttr(SUMO_ATTR_NODES, joinToString(nodeIDs, " "));
545  into.writeAttr(SUMO_ATTR_EDGES, joinToString(edgeIDs, " "));
546  into.closeTag();
547 }
548 
549 
550 void
552  std::vector<SUMOReal> sourceW = d.getSourceWeights();
554  std::vector<SUMOReal> sinkW = d.getSinkWeights();
556  // write the head and the id of the district
558  if (d.getShape().size() > 0) {
560  }
561  size_t i;
562  // write all sources
563  const std::vector<NBEdge*>& sources = d.getSourceEdges();
564  for (i = 0; i < sources.size(); i++) {
565  // write the head and the id of the source
566  into.openTag(SUMO_TAG_TAZSOURCE).writeAttr(SUMO_ATTR_ID, sources[i]->getID()).writeAttr(SUMO_ATTR_WEIGHT, sourceW[i]);
567  into.closeTag();
568  }
569  // write all sinks
570  const std::vector<NBEdge*>& sinks = d.getSinkEdges();
571  for (i = 0; i < sinks.size(); i++) {
572  // write the head and the id of the sink
573  into.openTag(SUMO_TAG_TAZSINK).writeAttr(SUMO_ATTR_ID, sinks[i]->getID()).writeAttr(SUMO_ATTR_WEIGHT, sinkW[i]);
574  into.closeTag();
575  }
576  // write the tail
577  into.closeTag();
578 }
579 
580 
581 std::string
583  SUMOReal time = STEPS2TIME(steps);
584  if (time == std::floor(time)) {
585  return toString(int(time));
586  } else {
587  return toString(time);
588  }
589 }
590 
591 
592 void
594  for (NBConnectionProhibits::const_iterator j = prohibitions.begin(); j != prohibitions.end(); j++) {
595  NBConnection prohibited = (*j).first;
596  const NBConnectionVector& prohibiting = (*j).second;
597  for (NBConnectionVector::const_iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
598  NBConnection prohibitor = *k;
602  into.closeTag();
603  }
604  }
605 }
606 
607 
608 std::string
610  return c.getFrom()->getID() + "->" + c.getTo()->getID();
611 }
612 
613 
614 void
616  std::vector<NBTrafficLightLogic*> logics = tllCont.getComputed();
617  for (std::vector<NBTrafficLightLogic*>::iterator it = logics.begin(); it != logics.end(); it++) {
619  into.writeAttr(SUMO_ATTR_ID, (*it)->getID());
620  into.writeAttr(SUMO_ATTR_TYPE, (*it)->getType());
621  into.writeAttr(SUMO_ATTR_PROGRAMID, (*it)->getProgramID());
622  into.writeAttr(SUMO_ATTR_OFFSET, writeSUMOTime((*it)->getOffset()));
623  // write params
624  const std::map<std::string, std::string>& params = (*it)->getMap();
625  for (std::map<std::string, std::string>::const_iterator i = params.begin(); i != params.end(); ++i) {
626  into.openTag(SUMO_TAG_PARAM);
627  into.writeAttr(SUMO_ATTR_KEY, (*i).first);
628  into.writeAttr(SUMO_ATTR_VALUE, (*i).second);
629  into.closeTag();
630  }
631  // write the phases
632  const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = (*it)->getPhases();
633  for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator j = phases.begin(); j != phases.end(); ++j) {
634  into.openTag(SUMO_TAG_PHASE);
635  into.writeAttr(SUMO_ATTR_DURATION, writeSUMOTime(j->duration));
636  into.writeAttr(SUMO_ATTR_STATE, j->state);
637  into.closeTag();
638  }
639  into.closeTag();
640  }
641  if (logics.size() > 0) {
642  into.lf();
643  }
644 }
645 
646 
647 void
649  const GeoConvHelper& geoConvHelper = GeoConvHelper::getFinal();
651  into.writeAttr(SUMO_ATTR_NET_OFFSET, geoConvHelper.getOffsetBase());
652  into.writeAttr(SUMO_ATTR_CONV_BOUNDARY, geoConvHelper.getConvBoundary());
653  if (geoConvHelper.usingGeoProjection()) {
655  }
656  into.writeAttr(SUMO_ATTR_ORIG_BOUNDARY, geoConvHelper.getOrigBoundary());
657  if (geoConvHelper.usingGeoProjection()) {
658  into.setPrecision();
659  }
660  into.writeAttr(SUMO_ATTR_ORIG_PROJ, geoConvHelper.getProjString());
661  into.closeTag();
662  into.lf();
663 }
664 
665 
666 void
668  if (permissions == SVCFreeForAll) {
669  return;
670  } else if (permissions == 0) {
671  // special case: since all-empty encodes FreeForAll we must list all disallowed
673  return;
674  } else {
675  std::pair<std::string, bool> encoding = getPermissionEncoding(permissions);
676  if (encoding.second) {
677  into.writeAttr(SUMO_ATTR_ALLOW, encoding.first);
678  } else {
679  into.writeAttr(SUMO_ATTR_DISALLOW, encoding.first);
680  }
681  }
682 }
683 
684 
685 void
687  if (preferred == SVCFreeForAll || preferred == 0) {
688  return;
689  } else {
691  }
692 }
693 /****************************************************************************/
694 
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:254
const EdgeVector & getIncomingEdges() const
Returns this node&#39;s incoming edges.
Definition: NBNode.h:177
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 (&lt;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:1445
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
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:365
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 &#39; &#39;.
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:63
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
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&#39;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:165
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:1869
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:202
SUMOReal offset
This lane&#39;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 (&lt;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:149
const Boundary & getConvBoundary() const
Returns the converted boundary.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:51
const PositionVector & getShape() const
Definition: NBNode.cpp:1338
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 (&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: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:1234
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 (&lt;junction with id[0]==&#39;:&#39; ...) 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:802
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&#39;s lanes&#39; 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:142
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 (&lt;junction ...)
bool writeLogic(OutputDevice &into, const bool checkLaneFoes) const
Definition: NBNode.cpp:610
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:63
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:141
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:232
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)
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:1188
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:354