SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
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>
34
#include <
utils/common/MsgHandler.h
>
35
#include "
MSNet.h
"
36
#include "
MSLane.h
"
37
#include "
MSEdge.h
"
38
#include "
MSVehicle.h
"
39
#include "
MSAbstractLaneChangeModel.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
// ===========================================================================
51
MSVehicleTransfer
*
MSVehicleTransfer::myInstance
= 0;
52
const
SUMOReal
MSVehicleTransfer::TeleportMinSpeed
= 1;
53
const
std::set<const MSVehicle*>
MSVehicleTransfer::myEmptyVehicleSet
;
54
55
// ===========================================================================
56
// member method definitions
57
// ===========================================================================
58
void
59
MSVehicleTransfer::addVeh
(
const
SUMOTime
t,
MSVehicle
* veh) {
60
veh->
getLaneChangeModel
().
endLaneChangeManeuver
();
61
if
(veh->
isParking
()) {
62
myParkingVehicles
[veh->
getLane
()].insert(veh);
// initialized to empty set on first use
63
veh->
onRemovalFromNet
(
MSMoveReminder::NOTIFICATION_PARKING
);
64
}
else
{
65
veh->
onRemovalFromNet
(
MSMoveReminder::NOTIFICATION_TELEPORT
);
66
MSNet::getInstance
()->
informVehicleStateListener
(veh,
MSNet::VEHICLE_STATE_STARTING_TELEPORT
);
67
if
((veh->
succEdge
(1) == 0) || veh->
enterLaneAtMove
(veh->
succEdge
(1)->
getLanes
()[0],
true
)) {
68
MSNet::getInstance
()->
getVehicleControl
().
scheduleVehicleRemoval
(veh);
69
return
;
70
}
71
}
72
myVehicles
.push_back(
VehicleInformation
(veh,
73
t +
TIME2STEPS
(veh->
getEdge
()->
getCurrentTravelTime
(
TeleportMinSpeed
)),
74
veh->
isParking
()));
75
}
76
77
78
void
79
MSVehicleTransfer::checkInsertions
(
SUMOTime
time) {
80
// go through vehicles
81
for
(VehicleInfVector::iterator i =
myVehicles
.begin(); i !=
myVehicles
.end();) {
82
// get the vehicle information
83
VehicleInformation
& desc = *i;
84
85
if
(desc.
myParking
) {
86
// handle parking vehicles
87
if
(desc.
myVeh
->
processNextStop
(1) == 0) {
88
++i;
89
continue
;
90
}
91
// parking finished, head back into traffic
92
}
93
const
SUMOVehicleClass
vclass = desc.
myVeh
->
getVehicleType
().
getVehicleClass
();
94
const
MSEdge
* e = desc.
myVeh
->
getEdge
();
95
const
MSEdge
* nextEdge = desc.
myVeh
->
succEdge
(1);
96
97
// get the lane on which this vehicle should continue
98
// first select all the lanes which allow continuation onto nextEdge
99
// then pick the one which is least occupied
100
// @todo maybe parking vehicles should always continue on the rightmost lane?
101
MSLane
* l = e->
getFreeLane
(e->
allowedLanes
(*nextEdge, vclass), vclass);
102
103
if
(desc.
myParking
) {
104
// handle parking vehicles
105
if
(l->
isInsertionSuccess
(desc.
myVeh
, 0, desc.
myVeh
->
getPositionOnLane
(),
false
,
MSMoveReminder::NOTIFICATION_PARKING
)) {
106
myParkingVehicles
[desc.
myVeh
->
getLane
()].erase(desc.
myVeh
);
107
i =
myVehicles
.erase(i);
108
}
else
{
109
i++;
110
}
111
}
else
{
112
// handle teleporting vehicles
113
if
(l->
freeInsertion
(*(desc.
myVeh
),
MIN2
(l->
getSpeedLimit
(), desc.
myVeh
->
getMaxSpeed
()),
MSMoveReminder::NOTIFICATION_TELEPORT
)) {
114
WRITE_WARNING
(
"Vehicle '"
+ desc.
myVeh
->
getID
() +
"' ends teleporting on edge '"
+ e->
getID
() +
"', simulation time "
+
time2string
(
MSNet::getInstance
()->getCurrentTimeStep()) +
"."
);
115
MSNet::getInstance
()->
informVehicleStateListener
(desc.
myVeh
,
MSNet::VEHICLE_STATE_ENDING_TELEPORT
);
116
i =
myVehicles
.erase(i);
117
}
else
{
118
// could not insert. maybe we should proceed in virtual space
119
if
(desc.
myProceedTime
< time) {
120
// active move reminders
121
desc.
myVeh
->
leaveLane
(
MSMoveReminder::NOTIFICATION_TELEPORT
);
122
// let the vehicle move to the next edge
123
const
bool
hasArrived = (desc.
myVeh
->
succEdge
(1) == 0 ||
124
desc.
myVeh
->
enterLaneAtMove
(desc.
myVeh
->
succEdge
(1)->
getLanes
()[0],
true
));
125
if
(hasArrived) {
126
WRITE_WARNING
(
"Vehicle '"
+ desc.
myVeh
->
getID
() +
"' ends teleporting on end edge '"
+ e->
getID
() +
"'."
);
127
MSNet::getInstance
()->
getVehicleControl
().
scheduleVehicleRemoval
(desc.
myVeh
);
128
i =
myVehicles
.erase(i);
129
continue
;
130
}
131
// use current travel time to determine when to move the vehicle forward
132
desc.
myProceedTime
= time +
TIME2STEPS
(e->
getCurrentTravelTime
(
TeleportMinSpeed
));
133
}
134
++i;
135
}
136
}
137
}
138
}
139
140
141
bool
142
MSVehicleTransfer::hasPending
()
const
{
143
return
!
myVehicles
.empty();
144
}
145
146
147
MSVehicleTransfer
*
148
MSVehicleTransfer::getInstance
() {
149
if
(
myInstance
== 0) {
150
myInstance
=
new
MSVehicleTransfer
();
151
}
152
return
myInstance
;
153
}
154
155
156
MSVehicleTransfer::MSVehicleTransfer
() {}
157
158
159
MSVehicleTransfer::~MSVehicleTransfer
() {
160
myInstance
= 0;
161
}
162
163
164
const
std::set<const MSVehicle*>&
165
MSVehicleTransfer::getParkingVehicles
(
const
MSLane
* lane)
const
{
166
ParkingVehicles::const_iterator it =
myParkingVehicles
.find(lane);
167
if
(it !=
myParkingVehicles
.end()) {
168
return
it->second;
169
}
else
{
170
return
myEmptyVehicleSet
;
171
}
172
}
173
174
175
/****************************************************************************/
176
build
buildd
sumo-0.18~dfsg
src
microsim
MSVehicleTransfer.cpp
Generated on Wed Oct 23 2013 01:15:10 for SUMO - Simulation of Urban MObility by
1.8.4