SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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-sim.org/
12 // Copyright (C) 2001-2013 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
61  if (veh->isParking()) {
63  myParkingVehicles[veh->getLane()].insert(veh); // initialized to empty set on first use
65  } else {
67  if (veh->succEdge(1) == 0) {
68  WRITE_WARNING("Vehicle '" + veh->getID() + "' teleports beyond end of route ('" + veh->getEdge()->getID() + "'), time " + time2string(t) + ".");
71  return;
72  }
74  veh->enterLaneAtMove(veh->succEdge(1)->getLanes()[0], true);
75  }
76  myVehicles.push_back(VehicleInformation(veh,
78  veh->isParking()));
79 }
80 
81 
82 void
84  // go through vehicles
85  for (VehicleInfVector::iterator i = myVehicles.begin(); i != myVehicles.end();) {
86  // get the vehicle information
87  VehicleInformation& desc = *i;
88 
89  if (desc.myParking) {
90  // handle parking vehicles
91  if (desc.myVeh->processNextStop(1) == 0) {
92  ++i;
93  continue;
94  }
95  // parking finished, head back into traffic
96  }
97  const SUMOVehicleClass vclass = desc.myVeh->getVehicleType().getVehicleClass();
98  const MSEdge* e = desc.myVeh->getEdge();
99  const MSEdge* nextEdge = desc.myVeh->succEdge(1);
100 
101  // get the lane on which this vehicle should continue
102  // first select all the lanes which allow continuation onto nextEdge
103  // then pick the one which is least occupied
104  // @todo maybe parking vehicles should always continue on the rightmost lane?
105  MSLane* l = e->getFreeLane(e->allowedLanes(*nextEdge, vclass), vclass);
106 
107  if (desc.myParking) {
108  // handle parking vehicles
111  myParkingVehicles[desc.myVeh->getLane()].erase(desc.myVeh);
112  i = myVehicles.erase(i);
113  } else {
114  i++;
115  }
116  } else {
117  // handle teleporting vehicles
119  WRITE_WARNING("Vehicle '" + desc.myVeh->getID() + "' ends teleporting on edge '" + e->getID() + "', time " + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
121  i = myVehicles.erase(i);
122  } else {
123  // could not insert. maybe we should proceed in virtual space
124  if (desc.myProceedTime < time) {
125  if (desc.myVeh->succEdge(1) == 0) {
126  WRITE_WARNING("Vehicle '" + desc.myVeh->getID() + "' teleports beyond end of route ('" + e->getID() + "'), time " + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
129  i = myVehicles.erase(i);
130  continue;
131  }
132  // let the vehicle move to the next edge
134  // active move reminders (i.e. rerouters)
135  desc.myVeh->enterLaneAtMove(desc.myVeh->succEdge(1)->getLanes()[0], true);
136  // use current travel time to determine when to move the vehicle forward
138  }
139  ++i;
140  }
141  }
142  }
143 }
144 
145 
146 bool
148  return !myVehicles.empty();
149 }
150 
151 
154  if (myInstance == 0) {
156  }
157  return myInstance;
158 }
159 
160 
162 
163 
165  myInstance = 0;
166 }
167 
168 
169 const std::set<const MSVehicle*>&
171  ParkingVehicles::const_iterator it = myParkingVehicles.find(lane);
172  if (it != myParkingVehicles.end()) {
173  return it->second;
174  } else {
175  return myEmptyVehicleSet;
176  }
177 }
178 
179 
180 /****************************************************************************/
181 
bool enterLaneAtMove(MSLane *enteredLane, bool onTeleporting=false)
Update when the vehicle enters a new lane in the move step.
Definition: MSVehicle.cpp:1514
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
static MSVehicleTransfer * myInstance
The static singleton-instance.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
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&#39;s lanes.
Definition: MSEdge.h:168
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:61
SUMOReal getCurrentTravelTime(const SUMOReal minSpeed=0.00001) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:437
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:150
MSLane * getFreeLane(const std::vector< MSLane * > *allowed, const SUMOVehicleClass vclass) const
Finds the emptiest lane allowing the vehicle class.
Definition: MSEdge.cpp:288
SUMOReal getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:283
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
SUMOReal processNextStop(SUMOReal currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:719
bool freeInsertion(MSVehicle &veh, SUMOReal speed, MSMoveReminder::Notification notification=MSMoveReminder::NOTIFICATION_DEPARTED)
Tries to insert the given vehicle on any place.
Definition: MSLane.cpp:269
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:196
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:1661
const std::string & getID() const
Returns the id.
Definition: Named.h:60
A road/street connecting two junctions.
Definition: MSEdge.h:73
virtual bool isInsertionSuccess(MSVehicle *vehicle, SUMOReal speed, SUMOReal pos, bool recheckNextLanes, MSMoveReminder::Notification notification=MSMoveReminder::NOTIFICATION_DEPARTED)
Tries to insert the given vehicle with the given state (speed and pos)
Definition: MSLane.cpp:424
The vehicles starts to park.
Definition: MSNet.h:421
void addVeh(const SUMOTime t, MSVehicle *veh)
Adds a vehicle to this transfer object.
void checkInsertions(SUMOTime time)
Checks &quot;movement&quot; of stored vehicles.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:253
const MSEdge * succEdge(unsigned int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
T MIN2(T a, T b)
Definition: StdDefs.h:57
The vehicle started to teleport.
Definition: MSNet.h:413
SUMOReal getSpeedLimit() const
Returns the lane&#39;s maximum allowed speed.
Definition: MSLane.h:357
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:429
SUMOTime myProceedTime
The time at which the vehicle should be moved virtually one edge further.
static const std::set< const MSVehicle * > myEmptyVehicleSet
an empty vector for convenience
The vehicle ends to park.
Definition: MSNet.h:423
bool isParking() const
Returns whether the vehicle is parking.
Definition: MSVehicle.cpp:707
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:1630
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_UNKNOWN) const
Get the allowed lanes to reach the destination-edge.
Definition: MSEdge.cpp:213
The vehicle starts or ends parking.
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
Definition: MSBaseVehicle.h:94
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle&#39;s state change.
Definition: MSNet.cpp:668
#define SUMOReal
Definition: config.h:215
MSVehicle * myVeh
The vehicle itself.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
The vehicle was teleported out of the net.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:322
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
The vehicle ended being teleported.
Definition: MSNet.h:415
The vehicle is being teleported.
const std::string & getID() const
Returns the name of the vehicle.