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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // The representation of one direction of a single pt line
19 /****************************************************************************/
21 
22 #include <utility>
23 #include <utils/common/ToString.h>
25 #include "NBEdgeCont.h"
26 #include "NBPTLine.h"
27 #include "NBPTStop.h"
28 
29 NBPTLine::NBPTLine(const std::string& name, const std::string& type) :
30  myName(name),
31  myType(type),
32  myPTLineId(-1),
33  myRef(name) {
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  device.writeAttr("completeness", toString((double)myPTStops.size() / (double)myNumOfStops));
62 
63  std::vector<std::string> validEdgeIDs;
64  // filter out edges that have been removed due to joining junctions
65  // (therest of the route is valid)
66  for (NBEdge* e : myRoute) {
67  if (ec.retrieve(e->getID())) {
68  validEdgeIDs.push_back(e->getID());
69  }
70  }
71  if (!myRoute.empty()) {
72  device.openTag(SUMO_TAG_ROUTE);
73  device.writeAttr(SUMO_ATTR_EDGES, validEdgeIDs);
74  device.closeTag();
75  }
76 
77  for (auto& myPTStop : myPTStops) {
78  device.openTag(SUMO_TAG_BUS_STOP);
79  device.writeAttr(SUMO_ATTR_ID, myPTStop->getID());
80  device.writeAttr(SUMO_ATTR_NAME, StringUtils::escapeXML(myPTStop->getName()));
81  device.closeTag();
82  }
83 // device.writeAttr(SUMO_ATTR_LANE, myLaneId);
84 // device.writeAttr(SUMO_ATTR_STARTPOS, myStartPos);
85 // device.writeAttr(SUMO_ATTR_ENDPOS, myEndPos);
86 // device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
87  device.closeTag();
88 
89 }
90 void NBPTLine::setId(long long int id) {
91  myPTLineId = id;
92 }
93 void NBPTLine::addWayNode(long long int way, long long int node) {
94  std::string wayStr = toString(way);
95  if (wayStr != myCurrentWay) {
96  myCurrentWay = wayStr;
97  myWays.push_back(wayStr);
98  }
99  myWaysNodes[wayStr].push_back(node);
100 
101 }
102 const std::vector<std::string>& NBPTLine::getMyWays() const {
103  return myWays;
104 }
105 std::vector<long long int>* NBPTLine::getWaysNodes(std::string wayId) {
106  if (myWaysNodes.find(wayId) != myWaysNodes.end()) {
107  return &myWaysNodes[wayId];
108  }
109  return nullptr;
110 }
111 void NBPTLine::setRef(std::string ref) {
112  myRef = std::move(ref);
113 }
114 
115 void NBPTLine::addEdgeVector(std::vector<NBEdge*>::iterator fr, std::vector<NBEdge*>::iterator to) {
116  myRoute.insert(myRoute.end(), fr, to);
117 
118 }
119 void NBPTLine::setMyNumOfStops(int numStops) {
120  myNumOfStops = numStops;
121 }
122 const std::vector<NBEdge*>& NBPTLine::getRoute() const {
123  return myRoute;
124 }
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
std::vector< long long int > * getWaysNodes(std::string wayId)
Definition: NBPTLine.cpp:105
void write(OutputDevice &device, NBEdgeCont &ec)
Definition: NBPTLine.cpp:52
std::string myRef
Definition: NBPTLine.h:66
std::vector< std::string > myWays
Definition: NBPTLine.h:58
std::vector< NBPTStop * > myPTStops
Definition: NBPTLine.h:54
The representation of a single edge during network building.
Definition: NBEdge.h:70
void addPTStop(NBPTStop *pStop)
Definition: NBPTLine.cpp:36
std::string myType
Definition: NBPTLine.h:53
The representation of a single pt stop.
Definition: NBPTStop.h:51
begin/end of the description of a route
const std::vector< std::string > & getMyWays() const
Definition: NBPTLine.cpp:102
NBPTLine(const std::string &name, const std::string &type)
Definition: NBPTLine.cpp:29
const std::vector< NBEdge * > & getRoute() const
Definition: NBPTLine.cpp:122
void addWayNode(long long int way, long long int node)
Definition: NBPTLine.cpp:93
void setMyNumOfStops(int numStops)
Definition: NBPTLine.cpp:119
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
void setRef(std::string basic_string)
Definition: NBPTLine.cpp:111
void addEdgeVector(std::vector< NBEdge *>::iterator fr, std::vector< NBEdge *>::iterator to)
Definition: NBPTLine.cpp:115
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
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:65
std::string myName
Definition: NBPTLine.h:52
std::string myCurrentWay
Definition: NBPTLine.h:64
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:250
const std::string & getName() const
Definition: NBPTLine.cpp:40
std::vector< NBEdge * > myRoute
Definition: NBPTLine.h:72
std::map< std::string, std::vector< long long int > > myWaysNodes
Definition: NBPTLine.h:57
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
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:90
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
int myNumOfStops
Definition: NBPTLine.h:77