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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A mover of vehicles that got stucked due to grid locks
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <iostream>
35 #include "MSNet.h"
36 #include "MSLane.h"
37 #include "MSEdge.h"
38 #include "MSVehicle.h"
40 #include "MSVehicleControl.h"
41 #include "MSInsertionControl.h"
42 #include "MSVehicleTransfer.h"
43 
44 
45 // ===========================================================================
46 // static member definitions
47 // ===========================================================================
50 const std::set<const MSVehicle*> MSVehicleTransfer::myEmptyVehicleSet;
51 
52 // ===========================================================================
53 // member method definitions
54 // ===========================================================================
55 void
57  if (veh->isParking()) {
61  } else {
64  if (veh->succEdge(1) == 0) {
65  WRITE_WARNING("Vehicle '" + veh->getID() + "' teleports beyond arrival edge '" + veh->getEdge()->getID() + "', time " + time2string(t) + ".");
68  return;
69  }
71  veh->enterLaneAtMove(veh->succEdge(1)->getLanes()[0], true);
72  }
73  myVehicles.push_back(VehicleInformation(t, veh,
75  veh->isParking()));
76 }
77 
78 
79 void
81  for (VehicleInfVector::iterator i = myVehicles.begin(); i != myVehicles.end(); ++i) {
82  if (i->myVeh == veh) {
83  if (i->myParking) {
84  veh->getLane()->removeParking(veh);
85  }
86  myVehicles.erase(i);
87  break;
88  }
89  }
90 }
91 
92 
93 void
95  // go through vehicles
96  for (VehicleInfVector::iterator i = myVehicles.begin(); i != myVehicles.end();) {
97  // get the vehicle information
98  VehicleInformation& desc = *i;
99 
100  if (desc.myParking) {
101  // handle parking vehicles
102  if (time != desc.myTransferTime) {
103  // avoid calling processNextStop twice in the transfer step
104  desc.myVeh->processNextStop(1);
105  }
106  if (desc.myVeh->keepStopping(true)) {
107  i++;
108  continue;
109  }
110  // parking finished, head back into traffic
111  }
112  const SUMOVehicleClass vclass = desc.myVeh->getVehicleType().getVehicleClass();
113  const MSEdge* e = desc.myVeh->getEdge();
114  const MSEdge* nextEdge = desc.myVeh->succEdge(1);
115 
116  const double departPos = desc.myParking ? desc.myVeh->getPositionOnLane() : 0;
117 
118  if (desc.myParking) {
119  // handle parking vehicles
120  if (desc.myVeh->getLane()->isInsertionSuccess(desc.myVeh, 0, departPos, desc.myVeh->getLateralPositionOnLane(),
123  desc.myVeh->getLane()->removeParking(desc.myVeh);
124  i = myVehicles.erase(i);
125  } else {
126  i++;
127  }
128  } else {
129  // get the lane on which this vehicle should continue
130  // first select all the lanes which allow continuation onto nextEdge
131  // then pick the one which is least occupied
132  MSLane* l = (nextEdge != 0 ? e->getFreeLane(e->allowedLanes(*nextEdge, vclass), vclass, departPos) :
133  e->getFreeLane(0, vclass, departPos));
134  // handle teleporting vehicles, lane may be 0 because permissions were modified by a closing rerouter or TraCI
135  if (l != 0 && l->freeInsertion(*(desc.myVeh), MIN2(l->getSpeedLimit(), desc.myVeh->getMaxSpeed()), 0, MSMoveReminder::NOTIFICATION_TELEPORT)) {
136  WRITE_WARNING("Vehicle '" + desc.myVeh->getID() + "' ends teleporting on edge '" + e->getID() + "', time " + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
138  i = myVehicles.erase(i);
139  } else {
140  // could not insert. maybe we should proceed in virtual space
141  if (desc.myProceedTime < time) {
142  if (desc.myVeh->succEdge(1) == 0) {
143  WRITE_WARNING("Vehicle '" + desc.myVeh->getID() + "' teleports beyond arrival edge '" + e->getID() + "', time " + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
146  i = myVehicles.erase(i);
147  continue;
148  }
149  // let the vehicle move to the next edge
151  // active move reminders (i.e. rerouters)
152  desc.myVeh->enterLaneAtMove(desc.myVeh->succEdge(1)->getLanes()[0], true);
153  // use current travel time to determine when to move the vehicle forward
155  }
156  ++i;
157  }
158  }
159  }
160 }
161 
162 
163 bool
165  return !myVehicles.empty();
166 }
167 
168 
171  if (myInstance == 0) {
173  }
174  return myInstance;
175 }
176 
177 
179 
180 
182  myInstance = 0;
183 }
184 
185 
186 void
188  for (VehicleInfVector::const_iterator it = myVehicles.begin(); it != myVehicles.end(); ++it) {
190  out.writeAttr(SUMO_ATTR_ID, it->myVeh->getID());
191  out.writeAttr(SUMO_ATTR_DEPART, it->myProceedTime);
192  if (it->myParking) {
193  out.writeAttr(SUMO_ATTR_PARKING, it->myVeh->getLane()->getID());
194  }
195  out.closeTag();
196  }
197 }
198 
199 
200 void
202  MSVehicle* veh = dynamic_cast<MSVehicle*>(vc.getVehicle(attrs.getString(SUMO_ATTR_ID)));
203  if (veh == 0) {
204  // deleted
205  return;
206  }
207  SUMOTime proceedTime = (SUMOTime)attrs.getLong(SUMO_ATTR_DEPART);
209  myVehicles.push_back(VehicleInformation(-1, veh, proceedTime - offset, parkingLane != 0));
210  if (parkingLane != 0) {
211  parkingLane->addParking(veh);
212  veh->setTentativeLaneAndPosition(parkingLane, veh->getPositionOnLane());
213  veh->processNextStop(veh->getSpeed());
214  }
216 }
217 
218 
219 
220 /****************************************************************************/
221 
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
bool enterLaneAtMove(MSLane *enteredLane, bool onTeleporting=false)
Update when the vehicle enters a new lane in the move step.
Definition: MSVehicle.cpp:3478
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
static MSVehicleTransfer * myInstance
The static singleton-instance.
void remove(MSVehicle *veh)
Remove a vehicle from this transfer object.
Holds the information needed to move the vehicle over the network.
virtual void removeParking(MSVehicle *veh)
remove parking vehicle. This must be syncrhonized when running with GUI
Definition: MSLane.cpp:2729
MSVehicleTransfer()
Constructor.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:564
VehicleInfVector myVehicles
The information about stored vehicles to move virtually.
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:582
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:402
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
virtual ~MSVehicleTransfer()
Destructor.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
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:295
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:167
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
const std::string & getID() const
Returns the id.
Definition: Named.h:74
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
bool myParking
whether the vehicle is or was parking
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:3674
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
double getCurrentTravelTime(const double minSpeed=NUMERICAL_EPS) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:727
double getMaxSpeed() const
Returns the maximum speed.
A road/street connecting two junctions.
Definition: MSEdge.h:80
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:3624
void saveState(OutputDevice &out) const
Saves the current state into the given stream.
virtual long long int getLong(int id) const =0
Returns the long-value of the named (by its enum-value) attribute.
The vehicles starts to park.
Definition: MSNet.h:496
void checkInsertions(SUMOTime time)
Checks "movement" of stored vehicles.
Encapsulated SAX-Attributes.
bool hasPending() const
Checks whether stored vehicles are present.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:306
double getSpeedLimit() const
Returns the lane&#39;s maximum allowed speed.
Definition: MSLane.h:489
T MIN2(T a, T b)
Definition: StdDefs.h:67
void add(const SUMOTime t, MSVehicle *veh)
Adds a vehicle to this transfer object.
The vehicle started to teleport.
Definition: MSNet.h:488
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:709
SUMOTime myProceedTime
The time at which the vehicle should be moved virtually one edge further.
static const std::set< const MSVehicle * > myEmptyVehicleSet
an empty set for convenience
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset, MSVehicleControl &vc)
Loads one transfer vehicle state from the given descriptionn.
The vehicle ends to park.
Definition: MSNet.h:498
double getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
Definition: MSVehicle.h:439
void alreadyDeparted(SUMOVehicle *veh)
stops trying to emit the given vehicle (because it already departed)
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
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:345
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:1639
The vehicle starts or ends parking.
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
bool keepStopping(bool afterProcessing=false) const
Returns whether the vehicle is stopped and must continue to do so.
Definition: MSVehicle.cpp:1342
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1376
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:4321
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:359
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle&#39;s state change.
Definition: MSNet.cpp:849
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
long long int SUMOTime
Definition: TraCIDefs.h:51
MSVehicle * myVeh
The vehicle itself.
SUMOTime myTransferTime
the time at which this vehicle was removed from the network
void addParking(MSVehicle *veh)
add parking vehicle. This should only used during state loading
Definition: MSLane.cpp:2723
The vehicle was teleported out of the net.
The class responsible for building and deletion of vehicles.
bool isParking() const
Returns whether the vehicle is parking.
Definition: MSVehicle.cpp:1358
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:482
const std::string & getID() const
Returns the name of the vehicle.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
MSLane * getFreeLane(const std::vector< MSLane *> *allowed, const SUMOVehicleClass vclass, double departPos) const
Finds the emptiest lane allowing the vehicle class.
Definition: MSEdge.cpp:392
The vehicle ended being teleported.
Definition: MSNet.h:490
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static const double TeleportMinSpeed
The minimum speed while teleporting.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
The vehicle is being teleported.
void endLaneChangeManeuver(const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_LANE_CHANGE)