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-2020 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/MSStop.h>
27 #include "MSRoutingEngine.h"
28 #include "MSIdling.h"
29 
30 //#define DEBUG_RESERVATION
31 //#define DEBUG_Idling
32 //#define DEBUG_SERVABLE
33 //#define DEBUG_TRAVELTIME
34 //#define DEBUG_DETOUR
35 //#define DEBUG_COND2(obj) (obj->getID() == "p0")
36 #define DEBUG_COND2(obj) (true)
37 
38 
39 // ===========================================================================
40 // MSIdling_stop methods
41 // ===========================================================================
42 
43 void
45  MSVehicle& veh = dynamic_cast<MSVehicle&>(taxi->getHolder());
46  if (!veh.hasStops()) {
47  //std::cout << SIMTIME << " MSIdling_Stop add stop\n";
48  // add stop
49  std::string errorOut;
50  const double brakeGap = veh.getCarFollowModel().brakeGap(veh.getSpeed());
51  std::pair<const MSLane*, double> stopPos = veh.getLanePosAfterDist(brakeGap);
52  if (stopPos.first != nullptr) {
54  stop.lane = stopPos.first->getID();
55  stop.startPos = stopPos.second;
56  stop.endPos = stopPos.second + POSITION_EPS;
57  if (veh.getVehicleType().getContainerCapacity() > 0) {
58  stop.containerTriggered = true;
59  } else {
60  stop.triggered = true;
61  }
62  stop.actType = "idling";
63  stop.parking = true;
64  veh.addTraciStop(stop, errorOut);
65  if (errorOut != "") {
66  WRITE_WARNING(errorOut);
67  }
68  } else {
69  WRITE_WARNING("Idle taxi '" + veh.getID() + "' could not stop within " + toString(brakeGap) + "m");
70  }
71  } else {
72  //std::cout << SIMTIME << " MSIdling_Stop reuse stop\n";
73  MSStop& stop = veh.getNextStop();
74  if (veh.getVehicleType().getContainerCapacity() > 0) {
75  stop.containerTriggered = true;
76  } else {
77  stop.triggered = true;
78  }
79  }
80 }
81 
82 // ===========================================================================
83 // MSIdling_RandomCircling methods
84 // ===========================================================================
85 
86 void
88  MSVehicle& veh = dynamic_cast<MSVehicle&>(taxi->getHolder());
89  ConstMSEdgeVector edges = veh.getRoute().getEdges();
90  ConstMSEdgeVector newEdges;
91  double remainingDist = -veh.getPositionOnLane();
92  int remainingEdges = 0;
93  int routePos = veh.getRoutePosition();
94  const int routeLength = (int)edges.size();
95  while (routePos + 1 < routeLength && (remainingEdges < 2 || remainingDist < 200)) {
96  const MSEdge* edge = edges[routePos];
97  remainingDist = edge->getLength();
98  remainingEdges++;
99  routePos++;
100  newEdges.push_back(edge);
101  }
102  const MSEdge* lastEdge = edges.back();
103  newEdges.push_back(lastEdge);
104  int added = 0;
105  while (remainingEdges < 2 || remainingDist < 200) {
106  remainingDist += lastEdge->getLength();
107  remainingEdges++;
108  MSEdgeVector successors = lastEdge->getSuccessors(veh.getVClass());
109  if (successors.size() == 0) {
110  WRITE_WARNING("Vehicle '" + veh.getID() + "' ends idling in a cul-de-sac");
111  break;
112  } else {
113  int nextIndex = RandHelper::rand((int)successors.size(), veh.getRNG());
114  newEdges.push_back(successors[nextIndex]);
115  lastEdge = newEdges.back();
116  added++;
117  }
118  }
119  if (added > 0) {
120  //std::cout << SIMTIME << " circleVeh=" << veh.getID() << " newEdges=" << toString(newEdges) << "\n";
121  veh.replaceRouteEdges(newEdges, -1, 0, "taxi:idling:randomCircling", false, false, false);
122  }
123 }
124 
125 
126 /****************************************************************************/
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:276
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
bool replaceRouteEdges(ConstMSEdgeVector &edges, double cost, double savings, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true)
Replaces the current route by the given edges.
std::mt19937 * getRNG() const
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
bool hasStops() const
Returns whether the vehicle has to stop somewhere.
SUMOVehicleClass getVClass() const
Returns the vehicle's access class.
int getRoutePosition() const
return index of edge within route
const MSRoute & getRoute() const
Returns the current route.
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition: MSCFModel.h:311
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_Taxi.h:48
A road/street connecting two junctions.
Definition: MSEdge.h:77
double getLength() const
return the length of the edge
Definition: MSEdge.h:630
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
Definition: MSEdge.cpp:1013
void idle(MSDevice_Taxi *taxi)
computes Idling and updates reservations
Definition: MSIdling.cpp:87
void idle(MSDevice_Taxi *taxi)
computes Idling and updates reservations
Definition: MSIdling.cpp:44
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:120
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
SUMOVehicle & getHolder() const
Returns the vehicle that holds this device.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string &errorMsg)
Definition: MSVehicle.cpp:5852
std::pair< const MSLane *, double > getLanePosAfterDist(double distance) const
return lane and position along bestlanes at the given distance
Definition: MSVehicle.cpp:5277
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:458
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:374
MSStop & getNextStop()
Definition: MSVehicle.cpp:6046
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
Definition: MSVehicle.h:930
int getContainerCapacity() const
Get this vehicle type's container capacity.
const std::string & getID() const
Returns the id.
Definition: Named.h:73
static double rand(std::mt19937 *rng=nullptr)
Returns a random real number in [0, 1)
Definition: RandHelper.h:51
Definition of vehicle stop (position and duration)
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 parking
whether the vehicle is removed from the net while stopping
bool containerTriggered
whether an arriving container lets the vehicle continue