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_RESERVATION
32 //#define DEBUG_Idling
33 //#define DEBUG_SERVABLE
34 //#define DEBUG_TRAVELTIME
35 //#define DEBUG_DETOUR
36 //#define DEBUG_COND2(obj) (obj->getID() == "p0")
37 #define DEBUG_COND2(obj) (true)
38 
39 
40 // ===========================================================================
41 // MSIdling_stop methods
42 // ===========================================================================
43 
44 void
46  if (!taxi->getHolder().hasStops()) {
47  //std::cout << SIMTIME << " MSIdling_Stop add stop\n";
48  // add stop
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";
74  stop.parking = true;
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  //std::cout << SIMTIME << " MSIdling_Stop reuse stop\n";
84  MSStop& stop = taxi->getHolder().getNextStop();
85  if (taxi->getHolder().getVehicleType().getContainerCapacity() > 0) {
86  stop.containerTriggered = true;
87  } else {
88  stop.triggered = true;
89  }
90  }
91 }
92 
93 // ===========================================================================
94 // MSIdling_RandomCircling methods
95 // ===========================================================================
96 
97 void
99  SUMOVehicle& veh = taxi->getHolder();
100  ConstMSEdgeVector edges = veh.getRoute().getEdges();
101  ConstMSEdgeVector newEdges;
102  double remainingDist = -veh.getPositionOnLane();
103  int remainingEdges = 0;
104  int routePos = veh.getRoutePosition();
105  const int routeLength = (int)edges.size();
106  while (routePos + 1 < routeLength && (remainingEdges < 2 || remainingDist < 200)) {
107  const MSEdge* edge = edges[routePos];
108  remainingDist += edge->getLength();
109  remainingEdges++;
110  routePos++;
111  newEdges.push_back(edge);
112  }
113  const MSEdge* lastEdge = edges.back();
114  newEdges.push_back(lastEdge);
115  int added = 0;
116  while (remainingEdges < 2 || remainingDist < 200) {
117  remainingDist += lastEdge->getLength();
118  remainingEdges++;
119  MSEdgeVector successors = lastEdge->getSuccessors(veh.getVClass());
120  for (auto it = successors.begin(); it != successors.end();) {
121  if ((*it)->getFunction() == SumoXMLEdgeFunc::CONNECTOR) {
122  it = successors.erase(it);
123  } else {
124  it++;
125  }
126  }
127  if (successors.size() == 0) {
128  WRITE_WARNING("Vehicle '" + veh.getID() + "' ends idling in a cul-de-sac");
129  break;
130  } else {
131  int nextIndex = RandHelper::rand((int)successors.size(), veh.getRNG());
132  newEdges.push_back(successors[nextIndex]);
133  lastEdge = newEdges.back();
134  added++;
135  }
136  }
137  if (added > 0) {
138  //std::cout << SIMTIME << " circleVeh=" << veh.getID() << " newEdges=" << toString(newEdges) << "\n";
139  veh.replaceRouteEdges(newEdges, -1, 0, "taxi:idling:randomCircling", false, false, false);
140  }
141 }
142 
143 
144 /****************************************************************************/
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
virtual double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition: MSCFModel.h:334
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:641
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
Definition: MSEdge.cpp:1084
static bool gUseMesoSim
Definition: MSGlobals.h:94
void idle(MSDevice_Taxi *taxi)
computes Idling and updates reservations
Definition: MSIdling.cpp:98
void idle(MSDevice_Taxi *taxi)
computes Idling and updates reservations
Definition: MSIdling.cpp:45
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:75
std::pair< const MSLane *, double > getLanePosAfterDist(double distance) const
return lane and position along bestlanes at the given distance
Definition: MSVehicle.cpp:5693
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:462
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
Definition: MSVehicle.h:917
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.h:119
virtual SumoRNG * getRNG() const =0
Returns the associated RNG for this object.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
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 const MSRoute & getRoute() const =0
Returns the current route.
virtual bool hasStops() const =0
Returns whether the vehicle has to stop somewhere.
virtual MSStop & getNextStop()=0
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
virtual int getRoutePosition() const =0
return index of edge within route
virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string &errorMsg)=0
Definition of vehicle stop (position and duration)
std::string edge
The edge to stop at (used only in NETEDIT)
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