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.sourceforge.net/
12 // Copyright (C) 2001-2012 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>
34 #include <cassert>
36 #include "MSNet.h"
37 #include "MSLane.h"
38 #include "MSEdge.h"
39 #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 // ===========================================================================
52 
53 
54 // ===========================================================================
55 // member method definitions
56 // ===========================================================================
57 void
59  // get the current edge of the vehicle
60  const MSEdge* e = veh->getEdge();
61  if (veh->isParking()) {
63  } else {
64  if ((veh->succEdge(1) == 0) || veh->enterLaneAtMove(veh->succEdge(1)->getLanes()[0], true)) {
66  MSNet::getInstance()->getVehicleControl().scheduleVehicleRemoval(veh);
67  return;
68  }
70  MSNet::getInstance()->informVehicleStateListener(veh, MSNet::VEHICLE_STATE_STARTING_TELEPORT);
71  }
72  myVehicles.push_back(VehicleInformation(veh, t + TIME2STEPS(e->getCurrentTravelTime()), veh->isParking()));
73 }
74 
75 
76 void
78  // go through vehicles
79  for (VehicleInfVector::iterator i = myVehicles.begin(); i != myVehicles.end();) {
80  // get the vehicle information
81  VehicleInformation& desc = *i;
82 
83  if (desc.myParking) {
84  // handle parking vehicles
85  if (desc.myVeh->processNextStop(1) == 0) {
86  ++i;
87  continue;
88  }
89  // parking finished, head back into traffic
90  }
91  const SUMOVehicleClass vclass = desc.myVeh->getVehicleType().getVehicleClass();
92  const MSEdge* e = desc.myVeh->getEdge();
93  const MSEdge* nextEdge = desc.myVeh->succEdge(1);
94 
95  // get the lane on which this vehicle should continue
96  // first select all the lanes which allow continuation onto nextEdge
97  // then pick the one which is least occupied
98  // @todo maybe parking vehicles should always continue on the rightmost lane?
99  MSLane* l = e->getFreeLane(e->allowedLanes(*nextEdge, vclass), vclass);
100 
101  if (desc.myParking) {
102  // handle parking vehicles
104  i = myVehicles.erase(i);
105  } else {
106  i++;
107  }
108  } else {
109  // handle teleporting vehicles
111  WRITE_WARNING("Vehicle '" + desc.myVeh->getID() + "' ends teleporting on edge '" + e->getID() + "', simulation time " + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
112  MSNet::getInstance()->informVehicleStateListener(desc.myVeh, MSNet::VEHICLE_STATE_ENDING_TELEPORT);
113  i = myVehicles.erase(i);
114  } else {
115  // could not insert. maybe we should proceed in virtual space
116  if (desc.myProceedTime < time) {
117  // get the lanes of the next edge (the one the vehicle wiil be
118  // virtually on after all these computations)
120  // get the one beyond the one the vehicle moved to
121  // !!! only move reminders are called but the edge is not advanced
122  const MSEdge* nextEdge = desc.myVeh->succEdge(1);
123  // let the vehicle move to the next edge
124  if (nextEdge == 0) {
125  WRITE_WARNING("Vehicle '" + desc.myVeh->getID() + "' ends teleporting on end edge '" + e->getID() + "'.");
126  MSNet::getInstance()->getVehicleControl().scheduleVehicleRemoval(desc.myVeh);
127  i = myVehicles.erase(i);
128  continue;
129  }
130  // use current travel time to determine when to move the vehicle forward
131  desc.myProceedTime = time + TIME2STEPS(e->getCurrentTravelTime());
132  }
133  ++i;
134  }
135  }
136  }
137 }
138 
139 
140 bool
142  return !myVehicles.empty();
143 }
144 
145 
148  if (myInstance == 0) {
150  }
151  return myInstance;
152 }
153 
154 
156 
157 
159  myInstance = 0;
160 }
161 
162 
163 
164 /****************************************************************************/
165