54 #define DEBUG_COND (true)
69 #define TAXI_SERVICE "taxi"
70 #define TAXI_SERVICE_PREFIX "taxi:"
84 oc.
addDescription(
"device.taxi.dispatch-algorithm",
"Taxi Device",
TL(
"The dispatch algorithm [greedy|greedyClosest|greedyShared|routeExtension|traci]"));
87 oc.
addDescription(
"device.taxi.dispatch-algorithm.output",
"Taxi Device",
TL(
"Write information from the dispatch algorithm to FILE"));
90 oc.
addDescription(
"device.taxi.dispatch-algorithm.params",
"Taxi Device",
TL(
"Load dispatch algorithm parameters in format KEY1:VALUE1[,KEY2:VALUE]"));
93 oc.
addDescription(
"device.taxi.dispatch-period",
"Taxi Device",
TL(
"The period between successive calls to the dispatcher"));
96 oc.
addDescription(
"device.taxi.idle-algorithm",
"Taxi Device",
TL(
"The behavior of idle taxis [stop|randomCircling]"));
99 oc.
addDescription(
"device.taxi.idle-algorithm.output",
"Taxi Device",
TL(
"Write information from the idling algorithm to FILE"));
109 into.push_back(device);
123 if (personCapacity < 1 && containerCapacity < 1) {
135 std::string algo = oc.
getString(
"device.taxi.dispatch-algorithm");
138 if (algo ==
"greedy") {
140 }
else if (algo ==
"greedyClosest") {
142 }
else if (algo ==
"greedyShared") {
144 }
else if (algo ==
"routeExtension") {
146 }
else if (algo ==
"traci") {
161 return lines.size() == 1 && (
168 const std::set<std::string>& lines,
172 const MSEdge* from,
double fromPos,
174 const MSEdge* to,
double toPos,
176 const std::string& group) {
181 throw ProcessError(
"Cannot add taxi reservation for " + std::string(person->
isPerson() ?
"person" :
"container")
182 +
" '" + person->
getID() +
"' because destination edge '" + to->
getID() +
"'"
183 +
" does not permit taxi access");
186 throw ProcessError(
"Cannot add taxi reservation for " + std::string(person->
isPerson() ?
"person" :
"container")
187 +
" '" + person->
getID() +
"' because origin edge '" + from->
getID() +
"'"
188 +
" does not permit taxi access");
193 if (fromStop !=
nullptr && &fromStop->
getLane().
getEdge() == from) {
197 myDispatcher->
addReservation(person, reservationTime, pickupTime, earliestPickupTime, from, fromPos, fromStop, to, toPos, toStop, group, *lines.begin(),
myMaxCapacity,
myMaxContainerCapacity);
202 const std::set<std::string>& lines,
203 const MSEdge* from,
double fromPos,
204 const MSEdge* to,
double toPos,
205 const std::string& group) {
213 const std::set<std::string>& lines,
214 const MSEdge* from,
double fromPos,
215 const MSEdge* to,
double toPos,
216 const std::string& group,
double newFromPos) {
225 std::vector<MSDevice_Taxi*> active;
227 if (taxi->getHolder().hasDeparted()) {
228 active.push_back(taxi);
254 std::string defaultServiceEnd =
toString(1e15);
256 if (algo ==
"stop") {
258 }
else if (algo ==
"randomCircling") {
265 }
else if (algo ==
"taxistand") {
267 if (rerouterID.empty()) {
268 throw ProcessError(
"Idle algorithm '" + algo +
"' requires a rerouter id to be defined using device param 'stands-rerouter' for vehicle '" +
myHolder.
getID() +
"'");
271 throw ProcessError(
"Unknown rerouter '" + rerouterID +
"' when loading taxi stands for vehicle '" +
myHolder.
getID() +
"'");
299 return &
myFleet[0]->getHolder();
314 #ifdef DEBUG_DISPATCH
318 std::cout <<
" persons=" <<
toString(res->persons) <<
"\n";
324 std::vector<SUMOVehicleParameter::Stop> stops;
336 tmpEdges.push_back(rerouteOrigin);
341 std::map<const MSTransportable*, int> nOccur;
347 throw ProcessError(
TLF(
"Invalid Re-dispatch for existing customer '%' with a new reservation", person->
getID()));
352 #ifdef DEBUG_DISPATCH
354 for (
auto item : nOccur) {
355 std::cout <<
" previousCustomer=" << item.first->getID() <<
" occurs=" << item.second <<
"\n";
359 if (nOccur.size() == 0) {
363 #ifdef DEBUG_DISPATCH
365 std::cout <<
" re-dispatch with route-extension\n";
370 std::set<const MSTransportable*> onBoard;
373 onBoard.insert(onBoardP.begin(), onBoardP.end());
374 onBoard.insert(onBoardC.begin(), onBoardC.end());
375 std::set<const MSTransportable*> redundantPickup;
376 for (
auto item : nOccur) {
377 if (item.second == 1) {
379 if (onBoard.count(item.first) == 0) {
380 throw ProcessError(
TLF(
"Re-dispatch did not mention pickup for existing customer '%'", item.first->getID()));
382 }
else if (item.second == 2) {
383 if (onBoard.count(item.first) == 0) {
388 redundantPickup.insert(item.first);
391 throw ProcessError(
"Re-dispatch mentions existing customer '" + item.first->getID() +
"' " +
toString(item.second) +
" times");
395 if (!redundantPickup.empty()) {
396 for (
auto it = reservations.begin(); it != reservations.end();) {
397 bool isRedundant =
false;
399 if (redundantPickup.count(person) != 0) {
406 redundantPickup.erase(person);
408 it = reservations.erase(it);
419 tmpEdges.push_back(rerouteOrigin);
421 #ifdef DEBUG_DISPATCH
423 std::cout <<
" re-dispatch from scratch\n";
428 std::vector<std::string> missing;
430 if (nOccur.count(c) == 0) {
431 missing.push_back(c->getID());
439 bool hasPickup =
false;
442 bool isPickup =
false;
451 prepareStop(tmpEdges, stops, lastPos, res->from, res->fromPos, res->fromStop,
"pickup " +
toString(res->persons) +
" (" + res->id +
")", res, isPickup);
454 stops.back().triggered =
true;
456 stops.back().containerTriggered =
true;
458 stops.back().permitted.insert(transportable->
getID());
461 std::set<const MSTransportable*> persons = res->persons;
462 for (
auto itr = persons.begin(); itr != persons.end(); itr++) {
463 stops.back().awaitedPersons.insert((*itr)->getID());
467 if (stops.back().duration == -1) {
472 prepareStop(tmpEdges, stops, lastPos, res->to, res->toPos, res->toStop,
"dropOff " +
toString(res->persons) +
" (" + res->id +
")", res, isPickup);
476 #ifdef DEBUG_DISPATCH
478 std::cout <<
" tmpEdges=" <<
toString(tmpEdges) <<
"\n";
485 #ifdef DEBUG_DISPATCH
499 #ifdef DEBUG_DISPATCH
517 std::set<const MSTransportable*> customersToBeRemoved;
523 if (t->getID() == tID) {
525 customersToBeRemoved.insert(t);
534 for (
auto t : customersToBeRemoved) {
549 bool fulfilled =
false;
550 if ((*resIt)->persons.size() == 1 && (*resIt)->persons.count(t) != 0) {
589 std::vector<SUMOVehicleParameter::Stop>& stops,
590 double& lastPos,
const MSEdge* stopEdge,
double stopPos,
592 const std::string& action,
const Reservation* res,
const bool isPickup) {
593 assert(!edges.empty());
594 if (stopPlace !=
nullptr && &stopPlace->
getLane().
getEdge() == stopEdge) {
597 if (stopPos < lastPos && stopPos + NUMERICAL_EPS >= lastPos) {
603 double distToStop = stopPos - lastPos;
608 if (stopEdge != edges.back()) {
609 distToStop += edges.back()->getLength();
610 if (distToStop < brakeGap) {
615 for (
int i = 1; i < (int)toFirstStop.size() - 1; i++) {
616 distToStop += toFirstStop[i]->getLength();
620 if (distToStop < brakeGap) {
623 edges.push_back(stopEdge);
627 if (stopEdge == edges.back() && !stops.empty()) {
628 if (stopPos >= lastPos && stopPos <= stops.back().endPos) {
630 stops.back().actType +=
"," + action;
636 stops.back().actType +=
"," + action;
640 if (stopEdge != edges.back() || stopPos < lastPos) {
641 edges.push_back(stopEdge);
646 if (stopPlace !=
nullptr && &stopPlace->
getLane().
getEdge() == stopEdge) {
658 if (isPickup && earliestPickupTime >= 0) {
663 stops.push_back(stop);
670 if (allowedLanes ==
nullptr) {
673 return allowedLanes->front();
712 #ifdef DEBUG_DISPATCH
723 double newPos,
double ) {
732 const double timeOnLane,
735 const double travelledDistanceFrontOnLane,
775 WRITE_WARNINGF(
TL(
"All customers left vehicle '%' at time=% but there are % remaining stops"),
794 bool fulfilled =
true;
818 if (stop.pars.permitted.size() > 0) {
827 if (tripinfoOut !=
nullptr) {
838 if (key ==
"customers") {
840 }
else if (key ==
"occupiedDistance") {
842 }
else if (key ==
"occupiedTime") {
844 }
else if (key ==
"state") {
846 }
else if (key ==
"currentCustomers") {
848 }
else if (key ==
"pickUpDuration") {
850 }
else if (key ==
"dropOffDuration") {
865 if (key ==
"pickUpDuration" || key ==
"dropOffDuration") {
#define TAXI_SERVICE_PREFIX
std::vector< const MSEdge * > ConstMSEdgeVector
#define WRITE_WARNINGF(...)
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
@ SVC_TAXI
vehicle is a taxi
const int STOP_PERMITTED_SET
@ GIVEN
The time is given.
#define UNUSED_PARAMETER(x)
std::string joinToStringSorting(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
std::string joinNamedToStringSorting(const std::set< T * > &ns, const T_BETWEEN &between)
Base (microsim) event class.
A device that performs vehicle rerouting based on current edge speeds.
void setActive(bool active)
A device which collects info on the vehicle trip (mainly on departure and arrival)
static void initDispatch()
initialize the dispatch algorithm
static Command * myDispatchCommand
The repeated call to the dispatcher.
void customerArrived(const MSTransportable *person)
called by MSDevice_Transportable upon unloading a person
static SUMOTime triggerDispatch(SUMOTime currentTime)
period command to trigger the dispatch algorithm
void dispatch(const Reservation &res)
service the given reservation
std::set< const MSTransportable * > myCustomers
the customer of the current reservation
SUMOTime myServiceEnd
the time at which the taxi service ends (end the vehicle may leave the simulation)
static void updateReservationFromPos(MSTransportable *person, const std::set< std::string > &lines, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, const std::string &group, double newFromPos)
update reservation's fromPos due to pre-booking
bool cancelCustomer(const MSTransportable *t)
remove person from reservations
void generateOutput(OutputDevice *tripinfoOut) const
Called on writing tripinfo output.
void dispatchShared(std::vector< const Reservation * > reservations)
service the given reservations
static void addReservation(MSTransportable *person, const std::set< std::string > &lines, SUMOTime reservationTime, SUMOTime pickupTime, SUMOTime earliestPickupTime, const MSEdge *from, double fromPos, const MSStoppingPlace *fromStop, const MSEdge *to, double toPos, const MSStoppingPlace *toStop, const std::string &group)
add new reservation
MSIdling * myIdleAlgorithm
algorithm for controlling idle behavior
std::set< const Reservation * > myCurrentReservations
reservations currently being served
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks for waiting steps when the vehicle moves.
bool hasFuturePickup()
whether the taxi has another pickup scheduled
void cancelCurrentCustomers()
remove the persons the taxi is currently waiting for from reservations
std::vector< const Reservation * > myLastDispatch
the last dispatch order
static MSDispatch * myDispatcher
the dispatch algorithm
int myCustomersServed
number of customers that were served
void updateMove(const SUMOTime traveltime, const double travelledDist)
void notifyMoveInternal(const SUMOTrafficObject &veh, const double frontOnLane, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double meanLengthOnLane)
Internal notification about the vehicle moves, see MSMoveReminder::notifyMoveInternal()
static int myMaxContainerCapacity
MSDevice_Routing * myRoutingDevice
routing device (if the vehicle has one)
bool isEmpty()
whether the taxi is empty
const std::string deviceName() const
return the name for this type of device
static std::vector< MSDevice_Taxi * > myFleet
static void removeReservation(MSTransportable *person, const std::set< std::string > &lines, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, const std::string &group)
retract reservation
static SUMOTime myDispatchPeriod
the time between successive calls to the dispatcher
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Saves departure info on insertion.
static void cleanup()
resets counters
static bool isReservation(const std::set< std::string > &lines)
whether the given lines description is a taxi call
double myOccupiedDistance
distance driven with customers
MSDevice_Taxi(SUMOVehicle &holder, const std::string &id)
Constructor.
bool allowsBoarding(const MSTransportable *t) const
whether the given person is allowed to board this taxi
static bool hasServableReservations()
check whether there are still (servable) reservations in the system
static SUMOVehicle * getTaxi()
returns a taxi if any exist or nullptr
void customerEntered(const MSTransportable *t)
called by MSDevice_Transportable upon loading a person
bool compatibleLine(const Reservation *res)
whether the given reservation is compatible with the taxi line
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Taxi-options.
bool myIsStopped
whether the vehicle is currently stopped
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this device. Throw exception for unsupported key
SUMOTime myOccupiedTime
time spent driving with customers
bool myReachedServiceEnd
whether the taxi has reached its schedule service end
~MSDevice_Taxi()
Destructor.
void prepareStop(ConstMSEdgeVector &edges, std::vector< SUMOVehicleParameter::Stop > &stops, double &lastPos, const MSEdge *stopEdge, double stopPos, const MSStoppingPlace *stopPlace, const std::string &action, const Reservation *res, const bool isPickup)
prepare stop for the given action
MSLane * getStopLane(const MSEdge *edge, const std::string &action)
determine stopping lane for taxi
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key
static double getFloatParam(const SUMOVehicle &v, const OptionsCont &oc, const std::string ¶mName, const double deflt, bool required=false)
static std::string getStringParam(const SUMOVehicle &v, const OptionsCont &oc, const std::string ¶mName, const std::string &deflt, bool required=false)
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
A dispatch algorithm that services the reservations with the shortest traveltime-to-pickup first.
A dispatch algorithm that services customers in reservation order and always sends the closest availa...
A dispatch algorithm that services customers in reservation order and always sends the closest availa...
An algorithm that performs distpach for a taxi fleet.
virtual std::string removeReservation(MSTransportable *person, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, std::string group)
remove person from reservation. If the whole reservation is removed, return its id
virtual Reservation * updateReservationFromPos(MSTransportable *person, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, std::string group, double newFromPos)
update fromPos of the person's reservation. TODO: if there is already a reservation with the newFromP...
virtual Reservation * addReservation(MSTransportable *person, SUMOTime reservationTime, SUMOTime pickupTime, SUMOTime earliestPickupTime, const MSEdge *from, double fromPos, const MSStoppingPlace *fromStop, const MSEdge *to, double toPos, const MSStoppingPlace *tostop, std::string group, const std::string &line, int maxCapacity, int maxContainerCapacity)
add a new reservation
bool hasServableReservations()
check whether there are still (servable) reservations in the system
virtual void fulfilledReservation(const Reservation *res)
erase reservation from storage
virtual void computeDispatch(SUMOTime now, const std::vector< MSDevice_Taxi * > &fleet)=0
computes dispatch and updates reservations
A road/street connecting two junctions.
SVCPermissions getPermissions() const
Returns the combined permissions of all lanes of this edge.
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING, bool ignoreTransientPermissions=false) const
Get the allowed lanes to reach the destination-edge.
double getLength() const
return the length of the edge
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
virtual void idle(MSDevice_Taxi *taxi)=0
computes Idling and updates reservations
Representation of a lane in the micro simulation.
double getLength() const
Returns the lane's length.
MSEdge & getEdge() const
Returns the lane's edge.
Notification
Definition of a vehicle state.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
const ConstMSEdgeVector & getEdges() const
static MSVehicleRouter & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const MSEdgeVector &prohibited=MSEdgeVector())
return the vehicle router instance
SUMOTime endBoarding
the maximum time at which persons may board this vehicle
A lane area vehicles can halt at.
double getBeginLanePosition() const
Returns the begin position of this stop.
double getEndLanePosition() const
Returns the end position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
bool isPerson() const
Whether it is a person.
Reroutes traffic objects passing an edge.
static const std::map< std::string, MSTriggeredRerouter * > & getInstances()
return all rerouter instances
Abstract in-vehicle device.
SUMOVehicle & myHolder
The vehicle that stores the device.
int getPersonCapacity() const
Get this vehicle type's person capacity.
double getLength() const
Get vehicle's length [m].
int getContainerCapacity() const
Get this vehicle type's container capacity.
const std::string & getID() const
Returns the id.
A storage for options typed value containers)
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
An upper class for objects with additional parameters.
void setParametersStr(const std::string ¶msString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
Representation of a vehicle, person, or container.
virtual MSDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or nullptr if not.
virtual int getRNGIndex() const =0
virtual bool isStopped() const =0
Returns whether the object is at a stop.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
virtual int getRoutePosition() const =0
return index of edge within route
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual const MSEdge * getEdge() const =0
Returns the edge the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
virtual ConstMSEdgeVector::const_iterator getRerouteOrigin() const =0
Returns the starting point for reroutes (usually the current edge)
virtual bool reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false, const bool silent=false, const MSEdge *sink=nullptr)=0
Performs a rerouting using the given router.
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 const std::list< MSStop > & getStops() const =0
virtual const std::vector< MSTransportable * > & getContainers() const =0
retrieve riding containers
virtual bool hasStops() const =0
Returns whether the vehicle has to stop somewhere.
virtual bool addStop(const SUMOVehicleParameter::Stop &stopPar, std::string &errorMsg, SUMOTime untilOffset=0, ConstMSEdgeVector::const_iterator *searchStart=0)=0
Adds a stop.
virtual MSStop & getNextStop()=0
virtual int getPersonNumber() const =0
Returns the number of persons.
virtual const std::vector< MSTransportable * > & getPersons() const =0
retrieve riding persons
virtual int getContainerNumber() const =0
Returns the number of containers.
virtual double getBrakeGap(bool delayed=false) const =0
get distance for coming to a stop (used for rerouting checks)
virtual const SUMOVehicleParameter::Stop * getNextStopParameter() const =0
Returns parameters of the next stop or nullptr.
virtual bool abortNextStop(int nextStopIndex=0)=0
deletes the next stop at the given index if it exists
Definition of vehicle stop (position and duration)
ParkingType parking
whether the vehicle is removed from the net while stopping
std::string lane
The lane to stop at.
SUMOTime extension
The maximum time extension for boarding / loading.
double startPos
The stopping position start.
std::set< std::string > permitted
IDs of persons or containers that may board/load at this stop.
int index
at which position in the stops list
std::string actType
act Type (only used by Persons) (used by netedit)
double endPos
The stopping position end.
SUMOTime waitUntil
The earliest pickup time for a taxi stop.
Structure representing possible vehicle parameter.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
std::string line
The vehicle's line (mainly for public transport)
static ParkingType parseParkingType(const std::string &value)
parses parking type value
A wrapper for a Command function.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
SUMOTime earliestPickupTime