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-2014 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()) {
62  MSNet::getInstance()->informVehicleStateListener(veh, MSNet::VEHICLE_STATE_STARTING_PARKING);
63  myParkingVehicles[veh->getLane()].insert(veh); // initialized to empty set on first use
65  } else {
66  MSNet::getInstance()->informVehicleStateListener(veh, MSNet::VEHICLE_STATE_STARTING_TELEPORT);
67  if (veh->succEdge(1) == 0) {
68  WRITE_WARNING("Vehicle '" + veh->getID() + "' teleports beyond end of route ('" + veh->getEdge()->getID() + "'), time " + time2string(t) + ".");
70  MSNet::getInstance()->getVehicleControl().scheduleVehicleRemoval(veh);
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  for (VehicleInfVector::iterator i = myVehicles.begin(); i != myVehicles.end(); ++i) {
85  if (i->myVeh == veh) {
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 (desc.myVeh->processNextStop(1) == 0) {
103  ++i;
104  continue;
105  }
106  // parking finished, head back into traffic
107  }
108  const SUMOVehicleClass vclass = desc.myVeh->getVehicleType().getVehicleClass();
109  const MSEdge* e = desc.myVeh->getEdge();
110  const MSEdge* nextEdge = desc.myVeh->succEdge(1);
111 
112  // get the lane on which this vehicle should continue
113  // first select all the lanes which allow continuation onto nextEdge
114  // then pick the one which is least occupied
115  // @todo maybe parking vehicles should always continue on the rightmost lane?
116  MSLane* l = (nextEdge != 0 ? e->getFreeLane(e->allowedLanes(*nextEdge, vclass), vclass) :
117  e->getFreeLane(0, vclass));
118 
119  if (desc.myParking) {
120  // handle parking vehicles
122  MSNet::getInstance()->informVehicleStateListener(desc.myVeh, MSNet::VEHICLE_STATE_ENDING_PARKING);
123  myParkingVehicles[desc.myVeh->getLane()].erase(desc.myVeh);
124  i = myVehicles.erase(i);
125  } else {
126  i++;
127  }
128  } else {
129  // handle teleporting vehicles
131  WRITE_WARNING("Vehicle '" + desc.myVeh->getID() + "' ends teleporting on edge '" + e->getID() + "', time " + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
132  MSNet::getInstance()->informVehicleStateListener(desc.myVeh, MSNet::VEHICLE_STATE_ENDING_TELEPORT);
133  i = myVehicles.erase(i);
134  } else {
135  // could not insert. maybe we should proceed in virtual space
136  if (desc.myProceedTime < time) {
137  if (desc.myVeh->succEdge(1) == 0) {
138  WRITE_WARNING("Vehicle '" + desc.myVeh->getID() + "' teleports beyond end of route ('" + e->getID() + "'), time " + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
140  MSNet::getInstance()->getVehicleControl().scheduleVehicleRemoval(desc.myVeh);
141  i = myVehicles.erase(i);
142  continue;
143  }
144  // let the vehicle move to the next edge
146  // active move reminders (i.e. rerouters)
147  desc.myVeh->enterLaneAtMove(desc.myVeh->succEdge(1)->getLanes()[0], true);
148  // use current travel time to determine when to move the vehicle forward
150  }
151  ++i;
152  }
153  }
154  }
155 }
156 
157 
158 bool
160  return !myVehicles.empty();
161 }
162 
163 
166  if (myInstance == 0) {
168  }
169  return myInstance;
170 }
171 
172 
174 
175 
177  myInstance = 0;
178 }
179 
180 
181 const std::set<const MSVehicle*>&
183  ParkingVehicles::const_iterator it = myParkingVehicles.find(lane);
184  if (it != myParkingVehicles.end()) {
185  return it->second;
186  } else {
187  return myEmptyVehicleSet;
188  }
189 }
190 
191 
192 /****************************************************************************/
193