SUMO - Simulation of Urban MObility
MSVehicleTransfer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A mover of vehicles that got stucked due to grid locks
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <iostream>
36 #include "MSNet.h"
37 #include "MSLane.h"
38 #include "MSEdge.h"
39 #include "MSVehicle.h"
41 #include "MSVehicleControl.h"
42 #include "MSInsertionControl.h"
43 #include "MSVehicleTransfer.h"
44 
45 
46 // ===========================================================================
47 // static member definitions
48 // ===========================================================================
51 const std::set<const MSVehicle*> MSVehicleTransfer::myEmptyVehicleSet;
52 
53 // ===========================================================================
54 // member method definitions
55 // ===========================================================================
56 void
58  if (veh->isParking()) {
62  } else {
65  if (veh->succEdge(1) == 0) {
66  WRITE_WARNING("Vehicle '" + veh->getID() + "' teleports beyond arrival edge '" + veh->getEdge()->getID() + "', time " + time2string(t) + ".");
69  return;
70  }
72  veh->enterLaneAtMove(veh->succEdge(1)->getLanes()[0], true);
73  }
74  myVehicles.push_back(VehicleInformation(t, veh,
76  veh->isParking()));
77 }
78 
79 
80 void
82  for (VehicleInfVector::iterator i = myVehicles.begin(); i != myVehicles.end(); ++i) {
83  if (i->myVeh == veh) {
84  myVehicles.erase(i);
85  break;
86  }
87  }
88 }
89 
90 
91 void
93  // go through vehicles
94  for (VehicleInfVector::iterator i = myVehicles.begin(); i != myVehicles.end();) {
95  // get the vehicle information
96  VehicleInformation& desc = *i;
97 
98  if (desc.myParking) {
99  // handle parking vehicles
100  if (time != desc.myTransferTime) {
101  // avoid calling processNextStop twice in the transfer step
102  desc.myVeh->processNextStop(1);
103  }
104  if (desc.myVeh->keepStopping(true)) {
105  i++;
106  continue;
107  }
108  // parking finished, head back into traffic
109  }
110  const SUMOVehicleClass vclass = desc.myVeh->getVehicleType().getVehicleClass();
111  const MSEdge* e = desc.myVeh->getEdge();
112  const MSEdge* nextEdge = desc.myVeh->succEdge(1);
113 
114  const double departPos = desc.myParking ? desc.myVeh->getPositionOnLane() : 0;
115 
116  if (desc.myParking) {
117  // handle parking vehicles
118  if (desc.myVeh->getLane()->isInsertionSuccess(desc.myVeh, 0, departPos, desc.myVeh->getLateralPositionOnLane(),
121  desc.myVeh->getLane()->removeParking(desc.myVeh);
122  i = myVehicles.erase(i);
123  } else {
124  i++;
125  }
126  } else {
127  // get the lane on which this vehicle should continue
128  // first select all the lanes which allow continuation onto nextEdge
129  // then pick the one which is least occupied
130  MSLane* l = (nextEdge != 0 ? e->getFreeLane(e->allowedLanes(*nextEdge, vclass), vclass, departPos) :
131  e->getFreeLane(0, vclass, departPos));
132  // handle teleporting vehicles, lane may be 0 because permissions were modified by a closing rerouter or TraCI
133  if (l != 0 && l->freeInsertion(*(desc.myVeh), MIN2(l->getSpeedLimit(), desc.myVeh->getMaxSpeed()), 0, MSMoveReminder::NOTIFICATION_TELEPORT)) {
134  WRITE_WARNING("Vehicle '" + desc.myVeh->getID() + "' ends teleporting on edge '" + e->getID() + "', time " + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
136  i = myVehicles.erase(i);
137  } else {
138  // could not insert. maybe we should proceed in virtual space
139  if (desc.myProceedTime < time) {
140  if (desc.myVeh->succEdge(1) == 0) {
141  WRITE_WARNING("Vehicle '" + desc.myVeh->getID() + "' teleports beyond arrival edge '" + e->getID() + "', time " + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
144  i = myVehicles.erase(i);
145  continue;
146  }
147  // let the vehicle move to the next edge
149  // active move reminders (i.e. rerouters)
150  desc.myVeh->enterLaneAtMove(desc.myVeh->succEdge(1)->getLanes()[0], true);
151  // use current travel time to determine when to move the vehicle forward
153  }
154  ++i;
155  }
156  }
157  }
158 }
159 
160 
161 bool
163  return !myVehicles.empty();
164 }
165 
166 
169  if (myInstance == 0) {
171  }
172  return myInstance;
173 }
174 
175 
177 
178 
180  myInstance = 0;
181 }
182 
183 
184 void
186  for (VehicleInfVector::const_iterator it = myVehicles.begin(); it != myVehicles.end(); ++it) {
188  out.writeAttr(SUMO_ATTR_ID, it->myVeh->getID());
189  out.writeAttr(SUMO_ATTR_DEPART, it->myProceedTime);
190  if (it->myParking) {
191  out.writeAttr(SUMO_ATTR_PARKING, it->myVeh->getLane()->getID());
192  }
193  out.closeTag();
194  }
195 }
196 
197 
198 void
200  MSVehicle* veh = dynamic_cast<MSVehicle*>(vc.getVehicle(attrs.getString(SUMO_ATTR_ID)));
201  if (veh == 0) {
202  // deleted
203  return;
204  }
205  SUMOTime proceedTime = (SUMOTime)attrs.getLong(SUMO_ATTR_DEPART);
207  myVehicles.push_back(VehicleInformation(-1, veh, proceedTime - offset, parkingLane != 0));
208  if (parkingLane != 0) {
209  parkingLane->addParking(veh);
210  veh->setTentativeLaneAndPosition(parkingLane, veh->getPositionOnLane());
211  veh->processNextStop(veh->getSpeed());
212  }
214 }
215 
216 
217 
218 /****************************************************************************/
219 
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:261
double getSpeedLimit() const
Returns the lane&#39;s maximum allowed speed.
Definition: MSLane.h:476
bool enterLaneAtMove(MSLane *enteredLane, bool onTeleporting=false)
Update when the vehicle enters a new lane in the move step.
Definition: MSVehicle.cpp:2951
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
static MSVehicleTransfer * myInstance
The static singleton-instance.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
void remove(MSVehicle *veh)
Remove a vehicle from this transfer object.
Holds the information needed to move the vehicle over the network.
double getMaxSpeed() const
Returns the maximum speed.
virtual void removeParking(MSVehicle *veh)
remove parking vehicle. This must be syncrhonized when running with GUI
Definition: MSLane.cpp:2634
MSVehicleTransfer()
Constructor.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:168
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:553
bool hasPending() const
Checks whether stored vehicles are present.
void saveState(OutputDevice &out) const
Saves the current state into the given stream.
virtual ~MSVehicleTransfer()
Destructor.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:60
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:169
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:375
virtual long long int getLong(int id) const =0
Returns the long-value of the named (by its enum-value) attribute.
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
bool myParking
whether the vehicle is or was parking
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:3144
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A road/street connecting two junctions.
Definition: MSEdge.h:81
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:3094
The vehicles starts to park.
Definition: MSNet.h:585
void checkInsertions(SUMOTime time)
Checks "movement" of stored vehicles.
Encapsulated SAX-Attributes.
bool keepStopping(bool afterProcessing=false) const
Returns whether the vehicle is stopped and must continue to do so.
Definition: MSVehicle.cpp:1250
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:305
T MIN2(T a, T b)
Definition: StdDefs.h:68
void add(const SUMOTime t, MSVehicle *veh)
Adds a vehicle to this transfer object.
The vehicle started to teleport.
Definition: MSNet.h:577
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:627
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:587
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
bool isParking() const
Returns whether the vehicle is parking.
Definition: MSVehicle.cpp:1266
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
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:316
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:1553
The vehicle starts or ends parking.
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1284
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:3808
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:358
MSLane * getFreeLane(const std::vector< MSLane * > *allowed, const SUMOVehicleClass vclass, double departPos) const
Finds the emptiest lane allowing the vehicle class.
Definition: MSEdge.cpp:393
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:296
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
double getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
Definition: MSVehicle.h:407
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle&#39;s state change.
Definition: MSNet.cpp:848
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
long long int SUMOTime
Definition: TraCIDefs.h:52
MSVehicle * myVeh
The vehicle itself.
SUMOTime myTransferTime
the time at which this vehicle was removed from the network
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
void addParking(MSVehicle *veh)
add parking vehicle. This should only used during state loading
Definition: MSLane.cpp:2628
The vehicle was teleported out of the net.
The class responsible for building and deletion of vehicles.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:499
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
The vehicle ended being teleported.
Definition: MSNet.h:579
double getCurrentTravelTime(const double minSpeed=NUMERICAL_EPS) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:728
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static const double TeleportMinSpeed
The minimum speed while teleporting.
The vehicle is being teleported.
const std::string & getID() const
Returns the name of the vehicle.
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:443
void endLaneChangeManeuver(const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_LANE_CHANGE)