SUMO - Simulation of Urban MObility
NBPTLine.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // The representation of one direction of a single pt line
17 /****************************************************************************/
19 
20 #include <utility>
21 #include <utils/common/ToString.h>
23 #include "NBEdgeCont.h"
24 #include "NBPTLine.h"
25 #include "NBPTStop.h"
26 
27 NBPTLine::NBPTLine(const std::string& name, const std::string& type, const std::string& ref, int interval, const std::string& nightService) :
28  myName(name),
29  myType(type),
30  myPTLineId(-1),
31  myRef(ref != "" ? ref : name),
32  myInterval(interval),
33  myNightService(nightService) {
34 }
35 
37  myPTStops.push_back(pStop);
38 
39 }
40 const std::string& NBPTLine::getName() const {
41  return myName;
42 }
43 
44 long long int
46  return myPTLineId;
47 }
48 
49 std::vector<NBPTStop*> NBPTLine::getStops() {
50  return myPTStops;
51 }
53  device.openTag(SUMO_TAG_PT_LINE);
55  if (!myName.empty()) {
57  }
58 
61  if (myInterval > 0) {
62  // write seconds
64  }
65  if (myNightService != "") {
66  device.writeAttr("nightService", myNightService);
67  }
68  device.writeAttr("completeness", toString((double)myPTStops.size() / (double)myNumOfStops));
69 
70  std::vector<std::string> validEdgeIDs;
71  // filter out edges that have been removed due to joining junctions
72  // (therest of the route is valid)
73  for (NBEdge* e : myRoute) {
74  if (ec.retrieve(e->getID())) {
75  validEdgeIDs.push_back(e->getID());
76  }
77  }
78  if (!myRoute.empty()) {
79  device.openTag(SUMO_TAG_ROUTE);
80  device.writeAttr(SUMO_ATTR_EDGES, validEdgeIDs);
81  device.closeTag();
82  }
83 
84  for (auto& myPTStop : myPTStops) {
85  device.openTag(SUMO_TAG_BUS_STOP);
86  device.writeAttr(SUMO_ATTR_ID, myPTStop->getID());
87  device.writeAttr(SUMO_ATTR_NAME, StringUtils::escapeXML(myPTStop->getName()));
88  device.closeTag();
89  }
90 // device.writeAttr(SUMO_ATTR_LANE, myLaneId);
91 // device.writeAttr(SUMO_ATTR_STARTPOS, myStartPos);
92 // device.writeAttr(SUMO_ATTR_ENDPOS, myEndPos);
93 // device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
94  device.closeTag();
95 
96 }
97 void NBPTLine::setId(long long int id) {
98  myPTLineId = id;
99 }
100 void NBPTLine::addWayNode(long long int way, long long int node) {
101  std::string wayStr = toString(way);
102  if (wayStr != myCurrentWay) {
103  myCurrentWay = wayStr;
104  myWays.push_back(wayStr);
105  }
106  myWaysNodes[wayStr].push_back(node);
107 
108 }
109 const std::vector<std::string>& NBPTLine::getMyWays() const {
110  return myWays;
111 }
112 std::vector<long long int>* NBPTLine::getWaysNodes(std::string wayId) {
113  if (myWaysNodes.find(wayId) != myWaysNodes.end()) {
114  return &myWaysNodes[wayId];
115  }
116  return nullptr;
117 }
118 
119 void NBPTLine::addEdgeVector(std::vector<NBEdge*>::iterator fr, std::vector<NBEdge*>::iterator to) {
120  myRoute.insert(myRoute.end(), fr, to);
121 
122 }
123 void NBPTLine::setMyNumOfStops(int numStops) {
124  myNumOfStops = numStops;
125 }
126 const std::vector<NBEdge*>& NBPTLine::getRoute() const {
127  return myRoute;
128 }
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
std::vector< long long int > * getWaysNodes(std::string wayId)
Definition: NBPTLine.cpp:112
void write(OutputDevice &device, NBEdgeCont &ec)
Definition: NBPTLine.cpp:52
std::string myRef
Definition: NBPTLine.h:78
std::vector< std::string > myWays
Definition: NBPTLine.h:70
std::vector< NBPTStop * > myPTStops
Definition: NBPTLine.h:66
The representation of a single edge during network building.
Definition: NBEdge.h:65
void addPTStop(NBPTStop *pStop)
Definition: NBPTLine.cpp:36
std::string myType
Definition: NBPTLine.h:65
The representation of a single pt stop.
Definition: NBPTStop.h:45
begin/end of the description of a route
const std::vector< std::string > & getMyWays() const
Definition: NBPTLine.cpp:109
const std::vector< NBEdge * > & getRoute() const
Definition: NBPTLine.cpp:126
void addWayNode(long long int way, long long int node)
Definition: NBPTLine.cpp:100
void setMyNumOfStops(int numStops)
Definition: NBPTLine.cpp:123
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
void addEdgeVector(std::vector< NBEdge *>::iterator fr, std::vector< NBEdge *>::iterator to)
Definition: NBPTLine.cpp:119
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
long long int myPTLineId
Definition: NBPTLine.h:77
NBPTLine(const std::string &name, const std::string &type, const std::string &ref, int interval, const std::string &nightService)
Definition: NBPTLine.cpp:27
std::string myName
Definition: NBPTLine.h:64
std::string myCurrentWay
Definition: NBPTLine.h:76
int myInterval
Definition: NBPTLine.h:79
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:245
const std::string & getName() const
Definition: NBPTLine.cpp:40
std::vector< NBEdge * > myRoute
Definition: NBPTLine.h:86
std::map< std::string, std::vector< long long int > > myWaysNodes
Definition: NBPTLine.h:69
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
std::vector< NBPTStop * > getStops()
Definition: NBPTLine.cpp:49
long long int getLineID() const
Definition: NBPTLine.cpp:45
void setId(long long int id)
Definition: NBPTLine.cpp:97
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
std::string myNightService
Definition: NBPTLine.h:80
int myNumOfStops
Definition: NBPTLine.h:91