SUMO - Simulation of Urban MObility
NBPTLine.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // The representation of one direction of a single pt line
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
22 
23 #include <utility>
24 #include "NBPTLine.h"
25 #include "NBPTStop.h"
26 
27 NBPTLine::NBPTLine(std::string name)
28  : myName(std::move(name)), myPTLineId(-1), myRef(name) {
29 
30 }
32  myPTStops.push_back(pStop);
33 
34 }
35 std::string NBPTLine::getName() {
36  return myName;
37 }
38 std::vector<NBPTStop*> NBPTLine::getStops() {
39  return myPTStops;
40 }
42  device.openTag(SUMO_TAG_PT_LINE);
44  if (!myName.empty()) {
46  }
48  device.writeAttr("completeness", toString((double)myPTStops.size()/(double)myNumOfStops));
49 
50  if (!myRoute.empty()) {
51  device.openTag(SUMO_TAG_ROUTE);
53  device.closeTag();
54  }
55 
56  for (auto& myPTStop : myPTStops) {
57  device.openTag(SUMO_TAG_BUS_STOP);
58  device.writeAttr(SUMO_ATTR_ID, myPTStop->getID());
59  device.writeAttr(SUMO_ATTR_NAME, myPTStop->getName());
60  device.closeTag();
61  }
62 // device.writeAttr(SUMO_ATTR_LANE, myLaneId);
63 // device.writeAttr(SUMO_ATTR_STARTPOS, myStartPos);
64 // device.writeAttr(SUMO_ATTR_ENDPOS, myEndPos);
65 // device.writeAttr(SUMO_ATTR_FRIENDLY_POS, "true");
66  device.closeTag();
67 
68 }
69 void NBPTLine::setId(long long int id) {
70  myPTLineId = id;
71 }
72 void NBPTLine::addWayNode(long long int way, long long int node) {
73  std::string wayStr = toString(way);
74  if (wayStr != myCurrentWay) {
75  myCurrentWay = wayStr;
76  myWays.push_back(wayStr);
77  }
78  myWaysNodes[wayStr].push_back(node);
79 
80 }
81 const std::vector<std::string>& NBPTLine::getMyWays() const {
82  return myWays;
83 }
84 std::vector<long long int>* NBPTLine::getWaysNodes(std::string wayId) {
85  if (myWaysNodes.find(wayId) != myWaysNodes.end()) {
86  return &myWaysNodes[wayId];
87  }
88  return nullptr;
89 }
90 void NBPTLine::setRef(std::string ref) {
91  myRef = std::move(ref);
92 }
93 
94 std::string NBPTLine::getRoute() {
95  std::string route;
96  for (auto& it : myRoute) {
97  route += (" " + it->getID());
98  }
99  return route;
100 }
101 
102 void NBPTLine::addEdgeVector(std::vector<NBEdge*>::iterator fr, std::vector<NBEdge*>::iterator to) {
103  myRoute.insert(myRoute.end(), fr, to);
104 
105 }
106 void NBPTLine::setMyNumOfStops(unsigned long numStops) {
107  myNumOfStops = numStops;
108 }
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:261
std::vector< long long int > * getWaysNodes(std::string wayId)
Definition: NBPTLine.cpp:84
std::string myRef
Definition: NBPTLine.h:64
std::string getName()
Definition: NBPTLine.cpp:35
std::vector< std::string > myWays
Definition: NBPTLine.h:56
std::vector< NBPTStop * > myPTStops
Definition: NBPTLine.h:52
void addPTStop(NBPTStop *pStop)
Definition: NBPTLine.cpp:31
void setMyNumOfStops(unsigned long numStops)
Definition: NBPTLine.cpp:106
The representation of a single pt stop.
Definition: NBPTStop.h:51
std::string getRoute()
Definition: NBPTLine.cpp:94
begin/end of the description of a route
unsigned long myNumOfStops
Definition: NBPTLine.h:73
void addWayNode(long long int way, long long int node)
Definition: NBPTLine.cpp:72
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
void setRef(std::string basic_string)
Definition: NBPTLine.cpp:90
long long int myPTLineId
Definition: NBPTLine.h:63
std::string myName
Definition: NBPTLine.h:51
std::string myCurrentWay
Definition: NBPTLine.h:62
const std::vector< std::string > & getMyWays() const
Definition: NBPTLine.cpp:81
NBPTLine(std::string name)
Definition: NBPTLine.cpp:27
std::vector< NBEdge * > myRoute
Definition: NBPTLine.h:71
std::map< std::string, std::vector< long long int > > myWaysNodes
Definition: NBPTLine.h:55
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
std::vector< NBPTStop * > getStops()
Definition: NBPTLine.cpp:38
void write(OutputDevice &device)
Definition: NBPTLine.cpp:41
void setId(long long int id)
Definition: NBPTLine.cpp:69
void addEdgeVector(std::vector< NBEdge * >::iterator fr, std::vector< NBEdge * >::iterator to)
Definition: NBPTLine.cpp:102
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.