Eclipse SUMO - Simulation of Urban MObility
NBParking.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 /****************************************************************************/
14 // The representation of an imported parking area
15 /****************************************************************************/
16 
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
26 #include "NBParking.h"
27 #include "NBEdge.h"
28 #include "NBEdgeCont.h"
29 
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
34 NBParking::NBParking(const std::string& id, const std::string& edgeID, const std::string& name) :
35  Named(id),
36  myEdgeID(edgeID),
37  myName(name) {
38 }
39 
40 void
42  const NBEdge* e = ec.retrieve(myEdgeID);
43  if (e != nullptr) {
44  if ((e->getPermissions() & SVC_PASSENGER) == 0) {
45  WRITE_WARNINGF("Ignoring parking area on edge '%' due to invalid permissions.", e->getID());
46  return;
47  }
48  // keep minimum distance of 5m to junction corners
49  const int cornerDistance = 5;
50  int capacity = (int)((e->getFinalLength() - 2 * cornerDistance) / 7.5);
51  if (capacity <= 0) {
52  WRITE_WARNINGF("Ignoring parking area on edge '%' due to insufficient space.", e->getID());
53  return;
54  }
55  int lane = 0;
56  for (; lane < e->getNumLanes(); ++lane) {
57  if ((e->getPermissions(lane) & SVC_PASSENGER) != 0) {
58  break;
59  }
60  }
62  device.writeAttr(SUMO_ATTR_ID, getID());
63  device.writeAttr(SUMO_ATTR_LANE, e->getLaneID(lane));
64  device.writeAttr(SUMO_ATTR_STARTPOS, cornerDistance);
65  device.writeAttr(SUMO_ATTR_ENDPOS, -cornerDistance);
66  device.writeAttr(SUMO_ATTR_ROADSIDE_CAPACITY, capacity);
67  if (!myName.empty()) {
69  }
70  device.closeTag();
71  } else {
72  std::cout << "could not find edge for parkingArea '" << getID() << "'\n";
73  }
74  // XXX else: prevent edge merging via --geometry.remove
75 }
76 
77 
78 void
79 NBParkingCont::addEdges2Keep(const OptionsCont& oc, std::set<std::string>& into) {
80  if (oc.isSet("parking-output")) {
81  for (NBParking& p : *this) {
82  into.insert(p.getEdgeID());
83  }
84  }
85 }
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:135
NBParking::myEdgeID
std::string myEdgeID
Definition: NBParking.h:61
NBParking::write
void write(OutputDevice &device, NBEdgeCont &ec) const
Definition: NBParking.cpp:41
NBEdgeCont::retrieve
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:246
NBParkingCont::addEdges2Keep
void addEdges2Keep(const OptionsCont &oc, std::set< std::string > &into)
add edges that must be kept
Definition: NBParking.cpp:79
Named
Base class for objects which have an id.
Definition: Named.h:56
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:60
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
OptionsCont.h
MsgHandler.h
NBEdgeCont.h
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
WRITE_WARNINGF
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:276
SUMO_ATTR_LANE
Definition: SUMOXMLDefinitions.h:637
NBEdge::getPermissions
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:3404
NBParking::myName
std::string myName
Definition: NBParking.h:62
SUMO_ATTR_ENDPOS
Definition: SUMOXMLDefinitions.h:798
NBParking.h
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
SUMO_ATTR_STARTPOS
Definition: SUMOXMLDefinitions.h:797
NBEdge::getLaneID
std::string getLaneID(int lane) const
get lane ID
Definition: NBEdge.cpp:3093
SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
Definition: SUMOVehicleClass.h:159
SUMO_TAG_PARKING_AREA
A parking area.
Definition: SUMOXMLDefinitions.h:107
NBEdge::getNumLanes
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:477
OutputDevice.h
NBParking::NBParking
NBParking(const std::string &id, const std::string &edgeID, const std::string &name="")
Constructor.
Definition: NBParking.cpp:34
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
SUMO_ATTR_ROADSIDE_CAPACITY
Definition: SUMOXMLDefinitions.h:772
NBParking
The representation of a single pt stop.
Definition: NBParking.h:43
NBEdge::getFinalLength
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:3682
config.h
NBParking::getEdgeID
const std::string getEdgeID() const
Definition: NBParking.h:56
SUMO_ATTR_NAME
Definition: SUMOXMLDefinitions.h:380
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
NBEdge.h
NBEdge::getID
const std::string & getID() const
Definition: NBEdge.h:1380