Eclipse SUMO - Simulation of Urban MObility
MSVehicleTransfer.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 // A mover of vehicles that got stucked due to grid locks
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <iostream>
28 #include "MSNet.h"
29 #include "MSLane.h"
30 #include "MSEdge.h"
31 #include "MSVehicle.h"
32 #include "MSParkingArea.h"
34 #include "MSVehicleControl.h"
35 #include "MSInsertionControl.h"
36 #include "MSVehicleTransfer.h"
37 
38 
39 // ===========================================================================
40 // static member definitions
41 // ===========================================================================
44 
45 
46 // ===========================================================================
47 // member method definitions
48 // ===========================================================================
49 bool
51  return myVeh->getNumericalID() < v2.myVeh->getNumericalID();
52 }
53 
54 
55 void
57  if (veh->isParking()) {
61  } else {
64  if (veh->succEdge(1) == nullptr) {
65  WRITE_WARNINGF("Vehicle '%' teleports beyond arrival edge '%', time %.", veh->getID(), veh->getEdge()->getID(), time2string(t));
68  return;
69  }
71  veh->enterLaneAtMove(veh->succEdge(1)->getLanes()[0], true);
72  }
73  myVehicles.push_back(VehicleInformation(t, veh, -1, veh->isParking()));
74 }
75 
76 
77 void
79  auto& vehInfos = myVehicles.getContainer();
80  for (auto i = vehInfos.begin(); i != vehInfos.end(); ++i) {
81  if (i->myVeh == veh) {
82  if (i->myParking) {
83  veh->getLane()->removeParking(veh);
84  }
85  vehInfos.erase(i);
86  break;
87  }
88  }
89  myVehicles.unlock();
90 }
91 
92 
93 void
95  // go through vehicles
96  auto& vehInfos = myVehicles.getContainer();
97  std::sort(vehInfos.begin(), vehInfos.end());
98  for (auto i = vehInfos.begin(); i != vehInfos.end();) {
99  // vehicle information cannot be const because we need to assign the proceed time
100  VehicleInformation& desc = *i;
101 
102  if (desc.myParking) {
103  // handle parking vehicles
104  if (time != desc.myTransferTime) {
105  // avoid calling processNextStop twice in the transfer step
106  desc.myVeh->processNextStop(1);
107  }
108  if (desc.myVeh->keepStopping(true)) {
109  i++;
110  continue;
111  }
112  // parking finished, head back into traffic
113  }
114  const SUMOVehicleClass vclass = desc.myVeh->getVehicleType().getVehicleClass();
115  const MSEdge* e = desc.myVeh->getEdge();
116  const MSEdge* nextEdge = desc.myVeh->succEdge(1);
117 
118 
119  if (desc.myParking) {
121  const double departPos = pa != nullptr ? pa->getInsertionPosition(*desc.myVeh) : desc.myVeh->getPositionOnLane();
122  // handle parking vehicles
123  if (desc.myVeh->getLane()->isInsertionSuccess(desc.myVeh, 0, departPos, desc.myVeh->getLateralPositionOnLane(),
126  desc.myVeh->getLane()->removeParking(desc.myVeh);
127  // at this point we are in the lane, blocking traffic & if required we configure the exit manoeuvre
130  }
131  i = vehInfos.erase(i);
132  } else {
133  // blocked from entering the road
135  // signal wish to re-enter the road
137  if (pa) {
138  // update freePosition so other vehicles can help with insertion
140  }
141  }
142  i++;
143  }
144  } else {
145  const double departPos = 0;
146  // get the lane on which this vehicle should continue
147  // first select all the lanes which allow continuation onto nextEdge
148  // then pick the one which is least occupied
149  MSLane* l = (nextEdge != nullptr ? e->getFreeLane(e->allowedLanes(*nextEdge, vclass), vclass, departPos) :
150  e->getFreeLane(nullptr, vclass, departPos));
151  // handle teleporting vehicles, lane may be 0 because permissions were modified by a closing rerouter or TraCI
152  if (l != nullptr && l->freeInsertion(*(desc.myVeh), MIN2(l->getSpeedLimit(), desc.myVeh->getMaxSpeed()), 0, MSMoveReminder::NOTIFICATION_TELEPORT)) {
153  WRITE_WARNINGF("Vehicle '%' ends teleporting on edge '%', time %.", desc.myVeh->getID(), e->getID(), time2string(time));
155  i = vehInfos.erase(i);
156  } else {
157  // could not insert. maybe we should proceed in virtual space
158  if (desc.myProceedTime < 0) {
159  // initialize proceed time (delayed to avoid lane-order dependency in executeMove)
161  } else if (desc.myProceedTime < time) {
162  if (desc.myVeh->succEdge(1) == nullptr) {
163  WRITE_WARNINGF("Vehicle '%' teleports beyond arrival edge '%', time %.", desc.myVeh->getID(), e->getID(), time2string(time));
166  i = vehInfos.erase(i);
167  continue;
168  }
169  // let the vehicle move to the next edge
171  // active move reminders (i.e. rerouters)
172  desc.myVeh->enterLaneAtMove(desc.myVeh->succEdge(1)->getLanes()[0], true);
173  // use current travel time to determine when to move the vehicle forward
175  }
176  ++i;
177  }
178  }
179  }
180  myVehicles.unlock();
181 }
182 
183 
186  if (myInstance == nullptr) {
188  }
189  return myInstance;
190 }
191 
192 
194 
195 
197  myInstance = nullptr;
198 }
199 
200 
201 void
203  for (const VehicleInformation& vehInfo : myVehicles.getContainer()) {
205  out.writeAttr(SUMO_ATTR_ID, vehInfo.myVeh->getID());
206  out.writeAttr(SUMO_ATTR_DEPART, vehInfo.myProceedTime);
207  if (vehInfo.myParking) {
208  out.writeAttr(SUMO_ATTR_PARKING, vehInfo.myVeh->getLane()->getID());
209  }
210  out.closeTag();
211  }
212  myVehicles.unlock();
213 }
214 
215 
216 void
218  MSVehicle* veh = dynamic_cast<MSVehicle*>(vc.getVehicle(attrs.getString(SUMO_ATTR_ID)));
219  if (veh == nullptr) {
220  // deleted
221  return;
222  }
223  SUMOTime proceedTime = (SUMOTime)attrs.getLong(SUMO_ATTR_DEPART);
224  MSLane* parkingLane = attrs.hasAttribute(SUMO_ATTR_PARKING) ? MSLane::dictionary(attrs.getString(SUMO_ATTR_PARKING)) : nullptr;
225  myVehicles.push_back(VehicleInformation(-1, veh, proceedTime - offset, parkingLane != nullptr));
226  if (parkingLane != nullptr) {
227  parkingLane->addParking(veh);
228  veh->setTentativeLaneAndPosition(parkingLane, veh->getPositionOnLane());
229  veh->processNextStop(veh->getSpeed());
230  }
232 }
233 
234 
235 /****************************************************************************/
MSVehicle::processNextStop
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1806
MSEdge::getCurrentTravelTime
double getCurrentTravelTime(const double minSpeed=NUMERICAL_EPS) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:749
SUMOVehicleClass
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
Definition: SUMOVehicleClass.h:133
MSVehicle::VEH_SIGNAL_BLINKER_LEFT
Left blinker lights are switched on.
Definition: MSVehicle.h:1185
MSVehicleTransfer::VehicleInformation::myTransferTime
SUMOTime myTransferTime
the time at which this vehicle was removed from the network
Definition: MSVehicleTransfer.h:127
MSLane::dictionary
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:1866
SUMO_ATTR_DEPART
Definition: SUMOXMLDefinitions.h:431
SUMOSAXAttributes::hasAttribute
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:73
MSParkingArea
A lane area vehicles can halt at.
Definition: MSParkingArea.h:59
MSVehicle::enterLaneAtMove
bool enterLaneAtMove(MSLane *enteredLane, bool onTeleporting=false)
Update when the vehicle enters a new lane in the move step.
Definition: MSVehicle.cpp:4463
MSNet.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
SUMOSAXAttributes::getString
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
MSVehicleTransfer::remove
void remove(MSVehicle *veh)
Remove a vehicle from this transfer object.
Definition: MSVehicleTransfer.cpp:78
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
MSParkingArea::notifyEgressBlocked
void notifyEgressBlocked()
update state so that vehicles wishing to enter cooperate with exiting vehicles
Definition: MSParkingArea.cpp:365
MSVehicle::VEH_SIGNAL_BLINKER_RIGHT
Right blinker lights are switched on.
Definition: MSVehicle.h:1183
MSVehicleTransfer::MSVehicleTransfer
MSVehicleTransfer()
Constructor.
Definition: MSVehicleTransfer.cpp:193
MSVehicle::setTentativeLaneAndPosition
void setTentativeLaneAndPosition(MSLane *lane, double pos, double posLat=0)
set tentative lane and position during insertion to ensure that all cfmodels work (some of them requi...
Definition: MSVehicle.cpp:5311
MSVehicleTransfer::myVehicles
FXSynchQue< VehicleInformation, std::vector< VehicleInformation > > myVehicles
The information about stored vehicles to move virtually.
Definition: MSVehicleTransfer.h:149
MSNet::informVehicleStateListener
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to, const std::string &info="")
Informs all added listeners about a vehicle's state change.
Definition: MSNet.cpp:894
MsgHandler.h
MSVehicle::isParking
bool isParking() const
Returns whether the vehicle is parking.
Definition: MSVehicle.cpp:1780
MSNet::getInsertionControl
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:389
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSVehicle::keepStopping
bool keepStopping(bool afterProcessing=false) const
Returns whether the vehicle is stopped and must continue to do so.
Definition: MSVehicle.cpp:1753
MSVehicleTransfer::VehicleInformation::myProceedTime
SUMOTime myProceedTime
The time at which the vehicle should be moved virtually one edge further.
Definition: MSVehicleTransfer.h:131
MSParkingArea::getInsertionPosition
double getInsertionPosition(const SUMOVehicle &forVehicle) const
Returns the insertion position of a parked vehicle.
Definition: MSParkingArea.cpp:180
MSVehicle::onRemovalFromNet
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:1060
MSGlobals
Definition: MSGlobals.h:48
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
WRITE_WARNINGF
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:276
MSEdge.h
MSInsertionControl.h
MSVehicleControl::scheduleVehicleRemoval
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
Definition: MSVehicleControl.cpp:117
MSMoveReminder::NOTIFICATION_TELEPORT_ARRIVED
The vehicle was teleported out of the net.
Definition: MSMoveReminder.h:111
MSVehicleTransfer
Definition: MSVehicleTransfer.h:63
MSBaseVehicle::getMaxSpeed
double getMaxSpeed() const
Returns the maximum speed.
Definition: MSBaseVehicle.cpp:165
MSVehicle.h
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
MSVehicleTransfer::getInstance
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
Definition: MSVehicleTransfer.cpp:185
MSVehicle::getLateralPositionOnLane
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition: MSVehicle.h:429
MSBaseVehicle::getEdge
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
Definition: MSBaseVehicle.cpp:181
MSVehicle::switchOnSignal
void switchOnSignal(int signal)
Switches the given signal on.
Definition: MSVehicle.h:1236
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
MSLane::addParking
void addParking(MSVehicle *veh)
add parking vehicle. This should only used during state loading
Definition: MSLane.cpp:3025
MSVehicleTransfer::VehicleInformation::operator<
bool operator<(const VehicleInformation &v2) const
sort by vehicle ID for repeatable parallel simulation
Definition: MSVehicleTransfer.cpp:50
MSVehicle::leaveLane
void leaveLane(const MSMoveReminder::Notification reason, const MSLane *approachedLane=0)
Update of members if vehicle leaves a new lane in the lane change step or at arrival.
Definition: MSVehicle.cpp:4627
MSVehicleControl::getVehicle
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
Definition: MSVehicleControl.cpp:240
MSLane::isInsertionSuccess
bool isInsertionSuccess(MSVehicle *vehicle, double speed, double pos, double posLat, bool recheckNextLanes, MSMoveReminder::Notification notification)
Tries to insert the given vehicle with the given state (speed and pos)
Definition: MSLane.cpp:649
MSNet::VEHICLE_STATE_STARTING_PARKING
The vehicles starts to park.
Definition: MSNet.h:549
MSVehicle::getPositionOnLane
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:392
MSVehicleTransfer::TeleportMinSpeed
static const double TeleportMinSpeed
The minimum speed while teleporting.
Definition: MSVehicleTransfer.h:113
TIME2STEPS
#define TIME2STEPS(x)
Definition: SUMOTime.h:58
MSVehicleTransfer::VehicleInformation::myParking
bool myParking
whether the vehicle is or was parking
Definition: MSVehicleTransfer.h:133
MSVehicleTransfer::myInstance
static MSVehicleTransfer * myInstance
The static singleton-instance.
Definition: MSVehicleTransfer.h:152
MSVehicle::getLaneChangeModel
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:4680
MSNet::VEHICLE_STATE_STARTING_TELEPORT
The vehicle started to teleport.
Definition: MSNet.h:541
SUMO_TAG_VEHICLETRANSFER
Definition: SUMOXMLDefinitions.h:270
MSGlobals::gModelParkingManoeuver
static bool gModelParkingManoeuver
whether parking simulation includes manoeuver time and any associated lane blocking
Definition: MSGlobals.h:135
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
MSLane::freeInsertion
bool freeInsertion(MSVehicle &veh, double speed, double posLat, MSMoveReminder::Notification notification=MSMoveReminder::NOTIFICATION_DEPARTED)
Tries to insert the given vehicle on any place.
Definition: MSLane.cpp:391
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
MSBaseVehicle::getVehicleType
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:123
MSParkingArea.h
MSEdge::allowedLanes
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING) const
Get the allowed lanes to reach the destination-edge.
Definition: MSEdge.cpp:359
MSVehicleTransfer::checkInsertions
void checkInsertions(SUMOTime time)
Checks "movement" of stored vehicles.
Definition: MSVehicleTransfer.cpp:94
MSVehicle::getLane
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:560
MSVehicleTransfer::VehicleInformation
Holds the information needed to move the vehicle over the network.
Definition: MSVehicleTransfer.h:125
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
MSNet::VEHICLE_STATE_MANEUVERING
Vehicle maneuvering either entering or exiting a parking space.
Definition: MSNet.h:561
MSMoveReminder::NOTIFICATION_PARKING
The vehicle starts or ends parking.
Definition: MSMoveReminder.h:105
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
MSEdge::getFreeLane
MSLane * getFreeLane(const std::vector< MSLane * > *allowed, const SUMOVehicleClass vclass, double departPos) const
Finds the emptiest lane allowing the vehicle class.
Definition: MSEdge.cpp:405
MSAbstractLaneChangeModel::endLaneChangeManeuver
void endLaneChangeManeuver(const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_LANE_CHANGE)
Definition: MSAbstractLaneChangeModel.cpp:401
MSBaseVehicle::succEdge
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs'th successor of edge the vehicle is currently at.
Definition: MSBaseVehicle.cpp:171
MSBaseVehicle::getNumericalID
NumericalID getNumericalID() const
return the numerical ID which is only for internal usage
Definition: MSBaseVehicle.h:489
MSVehicleTransfer::~MSVehicleTransfer
virtual ~MSVehicleTransfer()
Destructor.
Definition: MSVehicleTransfer.cpp:196
MSNet::VEHICLE_STATE_ENDING_PARKING
The vehicle ends to park.
Definition: MSNet.h:551
SUMOSAXAttributes.h
MSBaseVehicle::getID
const std::string & getID() const
Returns the name of the vehicle.
Definition: MSBaseVehicle.cpp:138
MSVehicle::signalSet
bool signalSet(int which) const
Returns whether the given signal is on.
Definition: MSVehicle.h:1261
MSEdge::getLanes
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:167
MSLane::removeParking
virtual void removeParking(MSVehicle *veh)
remove parking vehicle. This must be syncrhonized when running with GUI
Definition: MSLane.cpp:3031
MSNet::VEHICLE_STATE_ENDING_TELEPORT
The vehicle ended being teleported.
Definition: MSNet.h:543
SUMO_ATTR_PARKING
Definition: SUMOXMLDefinitions.h:801
MSVehicleTransfer::add
void add(const SUMOTime t, MSVehicle *veh)
Adds a vehicle to this transfer object.
Definition: MSVehicleTransfer.cpp:56
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:71
MSVehicle::getSpeed
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:476
MSVehicleTransfer::loadState
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset, MSVehicleControl &vc)
Loads one transfer vehicle state from the given descriptionn.
Definition: MSVehicleTransfer.cpp:217
MSLane.h
MSVehicle::getCurrentParkingArea
MSParkingArea * getCurrentParkingArea()
get the current parking area stop or nullptr
Definition: MSVehicle.cpp:1727
MSVehicle::setExitManoeuvre
bool setExitManoeuvre()
accessor function to myManoeuvre equivalent
Definition: MSVehicle.cpp:6225
MSLane::getSpeedLimit
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition: MSLane.h:532
MSVehicleType::getVehicleClass
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
Definition: MSVehicleType.h:184
MSVehicleTransfer::saveState
void saveState(OutputDevice &out)
Saves the current state into the given stream.
Definition: MSVehicleTransfer.cpp:202
SUMOSAXAttributes::getLong
virtual long long int getLong(int id) const =0
Returns the long-value of the named (by its enum-value) attribute.
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:56
MSVehicleControl.h
MSVehicleTransfer::VehicleInformation::myVeh
MSVehicle * myVeh
The vehicle itself.
Definition: MSVehicleTransfer.h:129
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
MSVehicleTransfer.h
MSNet::getVehicleControl
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:336
MSMoveReminder::NOTIFICATION_TELEPORT
The vehicle is being teleported.
Definition: MSMoveReminder.h:103
MSAbstractLaneChangeModel.h
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
MSInsertionControl::alreadyDeparted
void alreadyDeparted(SUMOVehicle *veh)
stops trying to emit the given vehicle (because it already departed)
Definition: MSInsertionControl.cpp:277