Eclipse SUMO - Simulation of Urban MObility
MSIdling.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2007-2022 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// An algorithm that performs Idling for the taxi device
19/****************************************************************************/
20#include <config.h>
21
22#include <limits>
23#include <microsim/MSNet.h>
24#include <microsim/MSEdge.h>
25#include <microsim/MSLane.h>
26#include <microsim/MSStop.h>
28#include "MSRoutingEngine.h"
29#include "MSIdling.h"
30
31//#define DEBUG_IDLING
32//#define DEBUG_COND(obj) (obj->getHolder().getID() == "p0")
33//#define DEBUG_COND(obj) (obj->getHolder().isSelected())
34#define DEBUG_COND(obj) (true)
35
36
37// ===========================================================================
38// MSIdling_stop methods
39// ===========================================================================
40
41void
43 if (!taxi->getHolder().hasStops()) {
44#ifdef DEBUG_IDLING
45 if (DEBUG_COND(taxi)) {
46 std::cout << SIMTIME << " MSIdling_Stop add stop\n";
47 }
48#endif
49 std::string errorOut;
50 double brakeGap = 0;
51 std::pair<const MSLane*, double> stopPos;
53 stopPos = std::make_pair((*taxi->getHolder().getCurrentRouteEdge())->getLanes()[0], taxi->getHolder().getPositionOnLane());
54 } else {
55 MSVehicle& veh = dynamic_cast<MSVehicle&>(taxi->getHolder());
56 brakeGap = veh.getCarFollowModel().brakeGap(veh.getSpeed());
57 stopPos = veh.getLanePosAfterDist(brakeGap);
58 }
59 if (stopPos.first != nullptr) {
62 stop.edge = stopPos.first->getEdge().getID();
63 } else {
64 stop.lane = stopPos.first->getID();
65 }
66 stop.startPos = stopPos.second;
67 stop.endPos = stopPos.second + POSITION_EPS;
68 if (taxi->getHolder().getVehicleType().getContainerCapacity() > 0) {
69 stop.containerTriggered = true;
70 } else {
71 stop.triggered = true;
72 }
73 stop.actType = "idling";
75 taxi->getHolder().addTraciStop(stop, errorOut);
76 if (errorOut != "") {
77 WRITE_WARNING(errorOut);
78 }
79 } else {
80 WRITE_WARNING("Idle taxi '" + taxi->getHolder().getID() + "' could not stop within " + toString(brakeGap) + "m");
81 }
82 } else {
83 MSStop& stop = taxi->getHolder().getNextStop();
84#ifdef DEBUG_IDLING
85 if (DEBUG_COND(taxi)) {
86 std::cout << SIMTIME << " MSIdling_Stop reusing stop with duration " << time2string(stop.duration) << "\n";
87 }
88#endif
89 if (taxi->getHolder().getVehicleType().getContainerCapacity() > 0) {
90 stop.containerTriggered = true;
91 } else {
92 stop.triggered = true;
93 }
94 }
95}
96
97
98// ===========================================================================
99// MSIdling_RandomCircling methods
100// ===========================================================================
101
102void
104 SUMOVehicle& veh = taxi->getHolder();
105 ConstMSEdgeVector edges = veh.getRoute().getEdges();
106 ConstMSEdgeVector newEdges;
107 double remainingDist = -veh.getPositionOnLane();
108 int remainingEdges = 0;
109 int routePos = veh.getRoutePosition();
110 const int routeLength = (int)edges.size();
111 while (routePos + 1 < routeLength && (remainingEdges < 2 || remainingDist < 200)) {
112 const MSEdge* edge = edges[routePos];
113 remainingDist += edge->getLength();
114 remainingEdges++;
115 routePos++;
116 newEdges.push_back(edge);
117 }
118 const MSEdge* lastEdge = edges.back();
119 newEdges.push_back(lastEdge);
120 int added = 0;
121 while (remainingEdges < 2 || remainingDist < 200) {
122 remainingDist += lastEdge->getLength();
123 remainingEdges++;
124 MSEdgeVector successors = lastEdge->getSuccessors(veh.getVClass());
125 for (auto it = successors.begin(); it != successors.end();) {
126 if ((*it)->getFunction() == SumoXMLEdgeFunc::CONNECTOR) {
127 it = successors.erase(it);
128 } else {
129 it++;
130 }
131 }
132 if (successors.size() == 0) {
133 WRITE_WARNING("Vehicle '" + veh.getID() + "' ends idling in a cul-de-sac");
134 break;
135 } else {
136 int nextIndex = RandHelper::rand((int)successors.size(), veh.getRNG());
137 newEdges.push_back(successors[nextIndex]);
138 lastEdge = newEdges.back();
139 added++;
140 }
141 }
142 if (added > 0) {
143 //std::cout << SIMTIME << " circleVeh=" << veh.getID() << " newEdges=" << toString(newEdges) << "\n";
144 veh.replaceRouteEdges(newEdges, -1, 0, "taxi:idling:randomCircling", false, false, false);
145 }
146}
147
148
149/****************************************************************************/
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
#define DEBUG_COND(obj)
Definition: MSIdling.cpp:34
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:265
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define SIMTIME
Definition: SUMOTime.h:61
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition: MSCFModel.h:373
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_Taxi.h:49
A road/street connecting two junctions.
Definition: MSEdge.h:77
double getLength() const
return the length of the edge
Definition: MSEdge.h:658
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
Definition: MSEdge.cpp:1155
static bool gUseMesoSim
Definition: MSGlobals.h:103
void idle(MSDevice_Taxi *taxi)
computes Idling and updates reservations
Definition: MSIdling.cpp:103
void idle(MSDevice_Taxi *taxi)
computes Idling and updates reservations
Definition: MSIdling.cpp:42
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:124
Definition: MSStop.h:44
bool triggered
whether an arriving person lets the vehicle continue
Definition: MSStop.h:69
bool containerTriggered
whether an arriving container lets the vehicle continue
Definition: MSStop.h:71
SUMOTime duration
The stopping duration.
Definition: MSStop.h:67
SUMOVehicle & getHolder() const
Returns the vehicle that holds this device.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
std::pair< const MSLane *, double > getLanePosAfterDist(double distance) const
return lane and position along bestlanes at the given distance
Definition: MSVehicle.cpp:6054
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:486
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
Definition: MSVehicle.h:966
int getContainerCapacity() const
Get this vehicle type's container capacity.
const std::string & getID() const
Returns the id.
Definition: Named.h:74
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Definition: RandHelper.cpp:94
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
virtual SumoRNG * getRNG() const =0
Returns the associated RNG for this object.
virtual int getRoutePosition() const =0
return index of edge within route
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
virtual bool replaceRouteEdges(ConstMSEdgeVector &edges, double cost, double savings, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true, std::string *msgReturn=nullptr)=0
Replaces the current route by the given edges.
virtual bool hasStops() const =0
Returns whether the vehicle has to stop somewhere.
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
virtual MSStop & getNextStop()=0
virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string &errorMsg)=0
virtual const MSRoute & getRoute() const =0
Returns the current route.
Definition of vehicle stop (position and duration)
std::string edge
The edge to stop at (used only in NETEDIT)
ParkingType parking
whether the vehicle is removed from the net while stopping
std::string lane
The lane to stop at.
double startPos
The stopping position start.
std::string actType
act Type (only used by Persons) (used by NETEDIT)
bool triggered
whether an arriving person lets the vehicle continue
double endPos
The stopping position end.
bool containerTriggered
whether an arriving container lets the vehicle continue