SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2016 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>
35 #include "MSNet.h"
36 #include "MSLane.h"
37 #include "MSEdge.h"
38 #include "MSVehicle.h"
40 #include "MSVehicleControl.h"
41 #include "MSVehicleTransfer.h"
42 
43 #ifdef CHECK_MEMORY_LEAKS
44 #include <foreign/nvwa/debug_new.h>
45 #endif // CHECK_MEMORY_LEAKS
46 
47 
48 // ===========================================================================
49 // static member definitions
50 // ===========================================================================
53 const std::set<const MSVehicle*> MSVehicleTransfer::myEmptyVehicleSet;
54 
55 // ===========================================================================
56 // member method definitions
57 // ===========================================================================
58 void
60  if (veh->isParking()) {
64  myParkingVehicles[veh->getLane()].insert(veh); // initialized to empty set on first use
65  } else {
68  if (veh->succEdge(1) == 0) {
69  WRITE_WARNING("Vehicle '" + veh->getID() + "' teleports beyond arrival edge '" + veh->getEdge()->getID() + "', time " + time2string(t) + ".");
72  return;
73  }
75  veh->enterLaneAtMove(veh->succEdge(1)->getLanes()[0], true);
76  }
77  myVehicles.push_back(VehicleInformation(veh,
79  veh->isParking()));
80 }
81 
82 
83 void
85  for (VehicleInfVector::iterator i = myVehicles.begin(); i != myVehicles.end(); ++i) {
86  if (i->myVeh == veh) {
87  myVehicles.erase(i);
88  break;
89  }
90  }
91  if (veh->getLane() != 0) {
92  myParkingVehicles[veh->getLane()].erase(veh);
93  }
94 }
95 
96 
97 void
99  // go through vehicles
100  for (VehicleInfVector::iterator i = myVehicles.begin(); i != myVehicles.end();) {
101  // get the vehicle information
102  VehicleInformation& desc = *i;
103 
104  if (desc.myParking) {
105  // handle parking vehicles
106  if (desc.myVeh->processNextStop(1) <= 0) {
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  // get the lane on which this vehicle should continue
117  // first select all the lanes which allow continuation onto nextEdge
118  // then pick the one which is least occupied
119  // @todo maybe parking vehicles should always continue on the rightmost lane?
120  const MSLane* oldLane = desc.myVeh->getLane();
121  MSLane* l = (nextEdge != 0 ? e->getFreeLane(e->allowedLanes(*nextEdge, vclass), vclass) :
122  e->getFreeLane(0, vclass));
123 
124  if (desc.myParking) {
125  // handle parking vehicles
128  myParkingVehicles[oldLane].erase(desc.myVeh);
129  i = myVehicles.erase(i);
130  } else {
131  i++;
132  }
133  } else {
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()), 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 const std::set<const MSVehicle*>&
188  ParkingVehicles::const_iterator it = myParkingVehicles.find(lane);
189  if (it != myParkingVehicles.end()) {
190  return it->second;
191  } else {
192  return myEmptyVehicleSet;
193  }
194 }
195 
196 
197 /****************************************************************************/
198 
bool enterLaneAtMove(MSLane *enteredLane, bool onTeleporting=false)
Update when the vehicle enters a new lane in the move step.
Definition: MSVehicle.cpp:2524
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
long long int SUMOTime
Definition: SUMOTime.h:43
static MSVehicleTransfer * myInstance
The static singleton-instance.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type'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.
static const SUMOReal TeleportMinSpeed
The minimum speed while teleporting.
MSVehicleTransfer()
Constructor.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
SUMOReal getMaxSpeed() const
Returns the maximum speed.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:192
VehicleInfVector myVehicles
The information about stored vehicles to move virtually.
bool hasPending() const
Checks whether stored vehicles are present.
virtual ~MSVehicleTransfer()
Destructor.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
MSLane * getFreeLane(const std::vector< MSLane * > *allowed, const SUMOVehicleClass vclass) const
Finds the emptiest lane allowing the vehicle class.
Definition: MSEdge.cpp:397
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:374
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
SUMOReal processNextStop(SUMOReal currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1027
bool freeInsertion(MSVehicle &veh, SUMOReal speed, MSMoveReminder::Notification notification=MSMoveReminder::NOTIFICATION_DEPARTED)
Tries to insert the given vehicle on any place.
Definition: MSLane.cpp:284
bool myParking
whether the vehicle is or was parking
const std::set< const MSVehicle * > & getParkingVehicles(const MSLane *lane) const
return parking vehicles on the given lane
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:2702
SUMOReal getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition: MSVehicle.h:406
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A road/street connecting two junctions.
Definition: MSEdge.h:80
The vehicles starts to park.
Definition: MSNet.h:551
void checkInsertions(SUMOTime time)
Checks "movement" of stored vehicles.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:307
T MIN2(T a, T b)
Definition: StdDefs.h:69
void add(const SUMOTime t, MSVehicle *veh)
Adds a vehicle to this transfer object.
The vehicle started to teleport.
Definition: MSNet.h:543
SUMOReal getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition: MSLane.h:472
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:601
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
The vehicle ends to park.
Definition: MSNet.h:553
bool isParking() const
Returns whether the vehicle is parking.
Definition: MSVehicle.cpp:1009
ParkingVehicles myParkingVehicles
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
void leaveLane(const MSMoveReminder::Notification reason)
Update of members if vehicle leaves a new lane in the lane change step or at arrival.
Definition: MSVehicle.cpp:2653
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'th successor of edge the vehicle is currently at.
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:300
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle's state change.
Definition: MSNet.cpp:773
#define SUMOReal
Definition: config.h:214
MSVehicle * myVeh
The vehicle itself.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
bool isInsertionSuccess(MSVehicle *vehicle, SUMOReal speed, SUMOReal pos, SUMOReal posLat, bool recheckNextLanes, MSMoveReminder::Notification notification)
Tries to insert the given vehicle with the given state (speed and pos)
Definition: MSLane.cpp:506
The vehicle was teleported out of the net.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:487
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
The vehicle ended being teleported.
Definition: MSNet.h:545
SUMOReal getCurrentTravelTime(const SUMOReal minSpeed=NUMERICAL_EPS) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:656
The vehicle is being teleported.
const std::string & getID() const
Returns the name of the vehicle.
void endLaneChangeManeuver(const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_LANE_CHANGE)