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