Eclipse 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-2019 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& id, 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(id),
31  myRef(ref != "" ? ref : name),
32  myInterval(interval),
33  myNightService(nightService) {
34 }
35 
37  myPTStops.push_back(pStop);
38 
39 }
40 
41 std::vector<NBPTStop*> NBPTLine::getStops() {
42  return myPTStops;
43 }
45  device.openTag(SUMO_TAG_PT_LINE);
47  if (!myName.empty()) {
49  }
50 
53  if (myInterval > 0) {
54  // write seconds
56  }
57  if (myNightService != "") {
58  device.writeAttr("nightService", myNightService);
59  }
60  device.writeAttr("completeness", toString((double)myPTStops.size() / (double)myNumOfStops));
61 
62  std::vector<std::string> validEdgeIDs;
63  // filter out edges that have been removed due to joining junctions
64  // (therest of the route is valid)
65  for (NBEdge* e : myRoute) {
66  if (ec.retrieve(e->getID())) {
67  validEdgeIDs.push_back(e->getID());
68  }
69  }
70  if (!myRoute.empty()) {
71  device.openTag(SUMO_TAG_ROUTE);
72  device.writeAttr(SUMO_ATTR_EDGES, validEdgeIDs);
73  device.closeTag();
74  }
75 
76  for (auto& myPTStop : myPTStops) {
77  device.openTag(SUMO_TAG_BUS_STOP);
78  device.writeAttr(SUMO_ATTR_ID, myPTStop->getID());
79  device.writeAttr(SUMO_ATTR_NAME, StringUtils::escapeXML(myPTStop->getName()));
80  device.closeTag();
81  }
82 // device.writeAttr(SUMO_ATTR_LANE, myLaneId);
83 // device.writeAttr(SUMO_ATTR_STARTPOS, myStartPos);
84 // device.writeAttr(SUMO_ATTR_ENDPOS, myEndPos);
85 // device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
86  device.closeTag();
87 
88 }
89 
90 void NBPTLine::addWayNode(long long int way, long long int node) {
91  std::string wayStr = toString(way);
92  if (wayStr != myCurrentWay) {
93  myCurrentWay = wayStr;
94  myWays.push_back(wayStr);
95  }
96  myWaysNodes[wayStr].push_back(node);
97 
98 }
99 const std::vector<std::string>& NBPTLine::getMyWays() const {
100  return myWays;
101 }
102 std::vector<long long int>* NBPTLine::getWaysNodes(std::string wayId) {
103  if (myWaysNodes.find(wayId) != myWaysNodes.end()) {
104  return &myWaysNodes[wayId];
105  }
106  return nullptr;
107 }
108 
109 void NBPTLine::addEdgeVector(std::vector<NBEdge*>::iterator fr, std::vector<NBEdge*>::iterator to) {
110  myRoute.insert(myRoute.end(), fr, to);
111 
112 }
113 void NBPTLine::setMyNumOfStops(int numStops) {
114  myNumOfStops = numStops;
115 }
116 const std::vector<NBEdge*>& NBPTLine::getRoute() const {
117  return myRoute;
118 }
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:102
void write(OutputDevice &device, NBEdgeCont &ec)
Definition: NBPTLine.cpp:44
std::string myRef
Definition: NBPTLine.h:84
std::vector< std::string > myWays
Definition: NBPTLine.h:76
std::vector< NBPTStop * > myPTStops
Definition: NBPTLine.h:72
The representation of a single edge during network building.
Definition: NBEdge.h:86
void addPTStop(NBPTStop *pStop)
Definition: NBPTLine.cpp:36
std::string myType
Definition: NBPTLine.h:71
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:99
const std::vector< NBEdge * > & getRoute() const
Definition: NBPTLine.cpp:116
void addWayNode(long long int way, long long int node)
Definition: NBPTLine.cpp:90
void setMyNumOfStops(int numStops)
Definition: NBPTLine.cpp:113
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
void addEdgeVector(std::vector< NBEdge *>::iterator fr, std::vector< NBEdge *>::iterator to)
Definition: NBPTLine.cpp:109
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.
std::string myName
Definition: NBPTLine.h:70
std::string myPTLineId
Definition: NBPTLine.h:83
std::string myCurrentWay
Definition: NBPTLine.h:82
int myInterval
Definition: NBPTLine.h:85
NBPTLine(const std::string &id, const std::string &name, const std::string &type, const std::string &ref, int interval, const std::string &nightService)
Definition: NBPTLine.cpp:27
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:245
std::vector< NBEdge * > myRoute
Definition: NBPTLine.h:92
std::map< std::string, std::vector< long long int > > myWaysNodes
Definition: NBPTLine.h:75
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:41
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
std::string myNightService
Definition: NBPTLine.h:86
int myNumOfStops
Definition: NBPTLine.h:97