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