Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSDevice_Taxi.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2013-2026 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// A device which controls a taxi
19/****************************************************************************/
20#include <config.h>
21
32#include <microsim/MSGlobals.h>
34#include <microsim/MSVehicle.h>
35#include <microsim/MSEdge.h>
36#include <microsim/MSLane.h>
37#include <microsim/MSStop.h>
40
41#include "MSDispatch.h"
42#include "MSDispatch_Greedy.h"
45#include "MSDispatch_TraCI.h"
46
47#include "MSIdling.h"
48
49#include "MSRoutingEngine.h"
50#include "MSDevice_Routing.h"
51#include "MSDevice_Taxi.h"
52
53//#define DEBUG_DISPATCH
54//#define DEBUG_CANCEL
55
56//#define DEBUG_COND (myHolder.isSelected())
57#define DEBUG_COND (true)
58
59// ===========================================================================
60// static member variables
61// ===========================================================================
67// @brief the list of available taxis
68std::vector<MSDevice_Taxi*> MSDevice_Taxi::myFleet;
71std::map<SUMOVehicleClass, std::string> MSDevice_Taxi::myTaxiTypes;
73std::map<std::string, MSDevice_Taxi*> MSDevice_Taxi::myStateLoadedCustomers;
74std::map<std::string, MSDevice_Taxi*> MSDevice_Taxi::myStateLoadedReservations;
75
76#define TAXI_SERVICE "taxi"
77#define TAXI_SERVICE_PREFIX "taxi:"
78#define SWAP_THRESHOLD 5
79
80// ===========================================================================
81// method definitions
82// ===========================================================================
83// ---------------------------------------------------------------------------
84// static initialisation methods
85// ---------------------------------------------------------------------------
86void
88 oc.addOptionSubTopic("Taxi Device");
89 insertDefaultAssignmentOptions("taxi", "Taxi Device", oc);
90
91 oc.doRegister("device.taxi.dispatch-algorithm", new Option_String("greedy"));
92 oc.addDescription("device.taxi.dispatch-algorithm", "Taxi Device", TL("The dispatch algorithm [greedy|greedyClosest|greedyShared|routeExtension|traci]"));
93
94 oc.doRegister("device.taxi.dispatch-algorithm.output", new Option_FileName());
95 oc.addDescription("device.taxi.dispatch-algorithm.output", "Taxi Device", TL("Write information from the dispatch algorithm to FILE"));
96
97 oc.doRegister("device.taxi.dispatch-algorithm.params", new Option_String(""));
98 oc.addDescription("device.taxi.dispatch-algorithm.params", "Taxi Device", TL("Load dispatch algorithm parameters in format KEY1:VALUE1[,KEY2:VALUE]"));
99
100 oc.doRegister("device.taxi.dispatch-period", new Option_String("60", "TIME"));
101 oc.addDescription("device.taxi.dispatch-period", "Taxi Device", TL("The period between successive calls to the dispatcher"));
102
103 oc.doRegister("device.taxi.dispatch-keep-unreachable", new Option_String("3600", "TIME"));
104 oc.addDescription("device.taxi.dispatch-keep-unreachable", "Taxi Device", TL("The time before aborting unreachable reservations"));
105
106 oc.doRegister("device.taxi.idle-algorithm", new Option_String("stop"));
107 oc.addDescription("device.taxi.idle-algorithm", "Taxi Device", TL("The behavior of idle taxis [stop|randomCircling|taxistand]"));
108
109 oc.doRegister("device.taxi.idle-algorithm.output", new Option_FileName());
110 oc.addDescription("device.taxi.idle-algorithm.output", "Taxi Device", TL("Write information from the idling algorithm to FILE"));
111
112 oc.doRegister("device.taxi.vclasses", new Option_StringVector({"taxi"}));
113 oc.addSynonyme("device.taxi.vclasses", "taxi.vclasses");
114 oc.addDescription("device.taxi.vclasses", "Taxi Device", TL("Network permissions that can be accessed by taxis"));
115}
116
117
118void
119MSDevice_Taxi::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
121 if (equippedByDefaultAssignmentOptions(oc, "taxi", v, false)) {
122 // build the device
123 MSDevice_Taxi* device = new MSDevice_Taxi(v, "taxi_" + v.getID());
124 into.push_back(device);
125 myFleet.push_back(device);
126 if (v.getParameter().line == "") {
127 // automatically set the line so that persons are willing to enter
128 // (see MSStageDriving::isWaitingFor)
129 const_cast<SUMOVehicleParameter&>(v.getParameter()).line = TAXI_SERVICE;
130 }
131 const int personCapacity = v.getVehicleType().getPersonCapacity();
132 const int containerCapacity = v.getVehicleType().getContainerCapacity();
133 myMaxCapacity = MAX2(myMaxCapacity, personCapacity);
135 if (myTaxiTypes[v.getVClass()] == "") {
137 }
138 if ((gTaxiClasses & v.getVClass()) == 0) {
139 gTaxiClasses |= v.getVClass();
141 }
142 if (personCapacity < 1 && containerCapacity < 1) {
143 WRITE_WARNINGF(TL("Vehicle '%' with personCapacity % and containerCapacity % is not usable as taxi."), v.getID(), toString(personCapacity), toString(containerCapacity));
144 }
145 }
146}
147
152
153void
156 myDispatchPeriod = string2time(oc.getString("device.taxi.dispatch-period"));
157 // init dispatch algorithm
158 std::string algo = oc.getString("device.taxi.dispatch-algorithm");
159 Parameterised params;
160 params.setParametersStr(OptionsCont::getOptions().getString("device.taxi.dispatch-algorithm.params"), ":", ",");
161 if (algo == "greedy") {
163 } else if (algo == "greedyClosest") {
165 } else if (algo == "greedyShared") {
167 } else if (algo == "routeExtension") {
169 } else if (algo == "traci") {
171 } else {
172 throw ProcessError(TLF("Dispatch algorithm '%' is not known", algo));
173 }
175 // round to next multiple of myDispatchPeriod
176 if (next < 0) {
178 const SUMOTime begin = string2time(oc.getString("begin"));
179 const SUMOTime delay = (myDispatchPeriod - ((now - begin) % myDispatchPeriod)) % myDispatchPeriod;
180 next = now + delay;
181 }
182 myNextDispatchTime = next;
184}
185
186bool
187MSDevice_Taxi::isReservation(const std::set<std::string>& lines) {
188 return lines.size() == 1 && (
189 *lines.begin() == TAXI_SERVICE
190 || StringUtils::startsWith(*lines.begin(), TAXI_SERVICE_PREFIX));
191}
192
193void
195 const std::set<std::string>& lines,
196 SUMOTime reservationTime,
197 SUMOTime pickupTime,
198 SUMOTime earliestPickupTime,
199 const MSEdge* from, double fromPos,
200 const MSStoppingPlace* fromStop,
201 const MSEdge* to, double toPos,
202 const MSStoppingPlace* toStop,
203 const std::string& group) {
204 if (!isReservation(lines)) {
205 return;
206 }
207 if ((to->getPermissions() & gTaxiClasses) == 0) {
208 throw ProcessError("Cannot add taxi reservation for " + std::string(person->isPerson() ? "person" : "container")
209 + " '" + person->getID() + "' because destination edge '" + to->getID() + "'"
210 + " does not permit taxi access");
211 }
212 if ((from->getPermissions() & gTaxiClasses) == 0) {
213 throw ProcessError("Cannot add taxi reservation for " + std::string(person->isPerson() ? "person" : "container")
214 + " '" + person->getID() + "' because origin edge '" + from->getID() + "'"
215 + " does not permit taxi access");
216 }
217 if (myDispatchCommand == nullptr) {
218 initDispatch();
219 }
220 if (fromStop != nullptr && &fromStop->getLane().getEdge() == from) {
221 // pickup position should be at the stop-endPos
222 fromPos = fromStop->getEndLanePosition();
223 }
224 Reservation* res = myDispatcher->addReservation(person, reservationTime, pickupTime, earliestPickupTime, from, fromPos, fromStop, to, toPos, toStop, group, *lines.begin(), myMaxCapacity, myMaxContainerCapacity);
225 if (myStateLoadedCustomers.size() > 0) {
226 auto it = myStateLoadedCustomers.find(person->getID());
227 if (it != myStateLoadedCustomers.end()) {
228 //std::cout << SIMTIME << " loadedServed p=" << person->getID() << " res=" << res->getID() << " taxi=" << it->second->getID() << "\n";
229 myDispatcher->servedReservation(res, it->second);
230 }
231 }
232}
233
234void
236 const std::set<std::string>& lines,
237 const MSEdge* from, double fromPos,
238 const MSEdge* to, double toPos,
239 const std::string& group) {
240 if (myDispatcher != nullptr && lines.size() == 1 && *lines.begin() == TAXI_SERVICE) {
241 myDispatcher->removeReservation(person, from, fromPos, to, toPos, group);
242 }
243}
244
245void
247 const std::set<std::string>& lines,
248 const MSEdge* from, double fromPos,
249 const MSEdge* to, double toPos,
250 const std::string& group, double newFromPos) {
251 if (myDispatcher != nullptr && lines.size() == 1 && *lines.begin() == TAXI_SERVICE) {
252 myDispatcher->updateReservationFromPos(person, from, fromPos, to, toPos, group, newFromPos);
253 }
254}
255
256
259 std::vector<MSDevice_Taxi*> active;
260 for (MSDevice_Taxi* taxi : myFleet) {
261 if (taxi->getHolder().hasDeparted()) {
262 active.push_back(taxi);
263 }
264 }
265 myDispatcher->computeDispatch(currentTime, active);
266 myNextDispatchTime = currentTime + myDispatchPeriod;
267 return myDispatchPeriod;
268}
269
270bool
272 if (myDispatcher == nullptr || !myDispatcher->hasServableReservations()) {
273 return false;
274 }
275 MSNet* const net = MSNet::getInstance();
277 return true;
278 }
279 if (!myDispatcher->getRunningReservations().empty()) {
280 return true;
281 }
282 for (const Reservation* const res : myDispatcher->getReservations()) {
283 if (res->persons.empty()) {
284 continue;
285 }
286 const bool isPerson = (*res->persons.begin())->isPerson();
287 for (MSDevice_Taxi* const taxi : myFleet) {
288 const int cap = isPerson
289 ? taxi->getHolder().getVehicleType().getPersonCapacity()
290 : taxi->getHolder().getVehicleType().getContainerCapacity();
291 if (cap >= (int)res->persons.size() && taxi->compatibleLine(res)) {
292 return true;
293 }
294 }
295 }
296 return false;
297}
298
299void
301 if (myDispatcher != nullptr) {
302 delete myDispatcher;
303 myDispatcher = nullptr;
304 }
305 myDispatchCommand = nullptr;
306 myTaxiTypes.clear();
307}
308
309
310void
312 for (MSDevice_Taxi* taxi : myFleet) {
313 // disable taskSwap
314 taxi->myState = EMPTY;
315 }
316}
317
318
319const std::map<SUMOVehicleClass, std::string>&
321 if (myTaxiTypes.size() < std::bitset<64>(gTaxiClasses).count()) {
322 for (const std::string& vClassName : OptionsCont::getOptions().getStringVector("device.taxi.vclasses")) {
324 if (myTaxiTypes[svc] == "") {
325 switch(svc) {
326 // @see MSVehicleControl::initDefaultTypes()
327 case SVC_TAXI:
329 break;
330 case SVC_RAIL:
332 break;
333 case SVC_BICYCLE:
335 break;
336 case SVC_PASSENGER:
338 break;
339 default: {
340 const std::string typeID = "DEFAULT_" + StringUtils::to_upper_case(vClassName) + "TYPE";
342 if (!vc.hasVType(typeID)) {
343 SUMOVTypeParameter tp(typeID, svc);
345 vc.addVType(t);
346 }
347 myTaxiTypes[svc] = typeID;;
348 }
349 }
350 }
351 }
352 }
353 return myTaxiTypes;
354}
355
356
357// ---------------------------------------------------------------------------
358// MSDevice_Taxi-methods
359// ---------------------------------------------------------------------------
360MSDevice_Taxi::MSDevice_Taxi(SUMOVehicle& holder, const std::string& id) :
361 MSVehicleDevice(holder, id) {
362 std::string defaultServiceEnd = toString(1e15);
363 const std::string algo = holder.getStringParam("device.taxi.idle-algorithm");
364 if (algo == "stop") {
366 } else if (algo == "randomCircling") {
368 // make sure simulation terminates
369 defaultServiceEnd = toString(STEPS2TIME(
372 : MSNet::getInstance()->getCurrentTimeStep()) + (3600 * 8));
373 } else if (algo == "taxistand") {
374 const std::string rerouterID = holder.getStringParam("device.taxi.stands-rerouter");
375 if (rerouterID.empty()) {
376 throw ProcessError("Idle algorithm '" + algo + "' requires a rerouter id to be defined using device param 'stands-rerouter' for vehicle '" + myHolder.getID() + "'");
377 }
378 if (MSTriggeredRerouter::getInstances().count(rerouterID) == 0) {
379 throw ProcessError("Unknown rerouter '" + rerouterID + "' when loading taxi stands for vehicle '" + myHolder.getID() + "'");
380 }
381 MSTriggeredRerouter* rerouter = MSTriggeredRerouter::getInstances().find(rerouterID)->second;
382 myIdleAlgorithm = new MSIdling_TaxiStand(rerouter);
383 } else {
384 throw ProcessError("Idle algorithm '" + algo + "' is not known for vehicle '" + myHolder.getID() + "'");
385 }
386 myServiceEnd = string2time(holder.getStringParam("device.taxi.end", false, defaultServiceEnd));
388}
389
390
392 myFleet.erase(std::find(myFleet.begin(), myFleet.end(), this));
393 // recompute myMaxCapacity
394 myMaxCapacity = 0;
396 for (MSDevice_Taxi* taxi : myFleet) {
397 myMaxCapacity = MAX2(myMaxCapacity, taxi->getHolder().getVehicleType().getPersonCapacity());
398 myMaxContainerCapacity = MAX2(myMaxContainerCapacity, taxi->getHolder().getVehicleType().getContainerCapacity());
399 }
400 delete myIdleAlgorithm;
401}
402
403
404bool
406 return myFleet.size() > 0;;
407}
408
409
410void
412 dispatchShared({&res, &res});
413}
414
415
416void
417MSDevice_Taxi::dispatchShared(std::vector<const Reservation*> reservations) {
418#ifdef DEBUG_DISPATCH
419 if (DEBUG_COND) {
420 std::cout << SIMTIME << " taxi=" << myHolder.getID() << " dispatch:\n";
421 for (const Reservation* res : reservations) {
422 std::cout << " res=" << res->getID();
423 std::cout << " persons=" << toString(res->persons) << "\n";
424 }
425 }
426#endif
427 myLastDispatch = reservations;
428 ConstMSEdgeVector tmpEdges;
429 StopParVector stops;
430 double lastPos = myHolder.getPositionOnLane();
431 const MSEdge* rerouteOrigin = *myHolder.getRerouteOrigin();
432 if (isEmpty()) {
433 // start fresh from the current edge
435 // parking stop must be ended normally
437 stop.duration = 0;
438 lastPos = stop.pars.endPos;
440 stop.triggered = false;
441 stop.containerTriggered = false;
442 stop.joinTriggered = false;
444 }
445 // prevent unauthorized/premature entry
446 const_cast<SUMOVehicleParameter::Stop&>(stop.pars).permitted.insert("");
447 while (myHolder.getStops().size() > 1) {
449 }
450 } else {
451 while (myHolder.hasStops()) {
452 // in meso there might be more than 1 stop at this point
454 }
455 assert(!myHolder.hasStops());
456 }
457 tmpEdges.push_back(myHolder.getEdge());
458 if (myHolder.getEdge() != rerouteOrigin) {
459 tmpEdges.push_back(rerouteOrigin);
460 }
461 } else {
462 assert(myHolder.hasStops());
463 // check how often existing customers appear in the new reservations
464 std::map<const MSTransportable*, int> nOccur;
465 for (const Reservation* res : reservations) {
466 for (const MSTransportable* person : res->persons) {
467 if (myCustomers.count(person) != 0) {
468 nOccur[person] += 1;
469 if (myCurrentReservations.count(res) == 0) {
470 throw ProcessError(TLF("Invalid Re-dispatch for existing customer '%' with a new reservation", person->getID()));
471 }
472 }
473 }
474 }
475#ifdef DEBUG_DISPATCH
476 if (DEBUG_COND) {
477 for (auto item : nOccur) {
478 std::cout << " previousCustomer=" << item.first->getID() << " occurs=" << item.second << "\n";
479 }
480 }
481#endif
482 if (nOccur.size() == 0) {
483 // no overlap with existing customers - extend route
484 tmpEdges = myHolder.getRoute().getEdges();
485 lastPos = myHolder.getStops().back().pars.endPos;
486#ifdef DEBUG_DISPATCH
487 if (DEBUG_COND) {
488 std::cout << " re-dispatch with route-extension\n";
489 }
490#endif
491 } else if (nOccur.size() == myCustomers.size()) {
492 // redefine route (verify correct number of mentions)
493 std::set<const MSTransportable*> onBoard;
494 const std::vector<MSTransportable*>& onBoardP = myHolder.getPersons();
495 const std::vector<MSTransportable*>& onBoardC = myHolder.getContainers();
496 onBoard.insert(onBoardP.begin(), onBoardP.end());
497 onBoard.insert(onBoardC.begin(), onBoardC.end());
498 std::set<const MSTransportable*> redundantPickup;
499 for (auto item : nOccur) {
500 if (item.second == 1) {
501 // customers must already be on board
502 if (onBoard.count(item.first) == 0) {
503 throw ProcessError(TLF("Re-dispatch did not mention pickup for existing customer '%'", item.first->getID()));
504 }
505 } else if (item.second == 2) {
506 if (onBoard.count(item.first) == 0) {
507 // treat like a new customer
508 // TODO: need to be checked
509 myCustomers.erase(item.first);
510 } else {
511 redundantPickup.insert(item.first);
512 }
513 } else {
514 throw ProcessError("Re-dispatch mentions existing customer '" + item.first->getID() + "' " + toString(item.second) + " times");
515 }
516 }
517 // remove redundancy
518 if (!redundantPickup.empty()) {
519 for (auto it = reservations.begin(); it != reservations.end();) {
520 bool isRedundant = false;
521 for (const MSTransportable* person : (*it)->persons) {
522 if (redundantPickup.count(person) != 0) {
523 isRedundant = true;
524 break;
525 }
526 }
527 if (isRedundant) {
528 for (const MSTransportable* person : (*it)->persons) {
529 redundantPickup.erase(person);
530 }
531 it = reservations.erase(it);
532 } else {
533 it++;
534 }
535 }
536 }
537 while (myHolder.hasStops()) {
539 }
540 tmpEdges.push_back(myHolder.getEdge());
541 if (myHolder.getEdge() != rerouteOrigin) {
542 tmpEdges.push_back(rerouteOrigin);
543 }
544#ifdef DEBUG_DISPATCH
545 if (DEBUG_COND) {
546 std::cout << " re-dispatch from scratch\n";
547 }
548#endif
549 } else {
550 // inconsistent re-dispatch
551 std::vector<std::string> missing;
552 for (const MSTransportable* c : myCustomers) {
553 if (nOccur.count(c) == 0) {
554 missing.push_back(c->getID());
555 }
556 }
557 throw ProcessError("Re-dispatch did mention some customers but failed to mention " + joinToStringSorting(missing, " "));
558 }
559 }
560
561 bool hasPickup = false;
562 for (const Reservation* res : reservations) {
563 myCurrentReservations.insert(res);
564 bool isPickup = false;
565 for (const MSTransportable* person : res->persons) {
566 if (myCustomers.count(person) == 0) {
567 myCustomers.insert(person);
568 isPickup = true;
569 hasPickup = true;
570 }
571 }
572 if (isPickup) {
573 prepareStop(tmpEdges, stops, lastPos, res->from, res->fromPos, res->fromStop, "pickup " + toString(res->persons) + " (" + res->id + ")", res, isPickup);
574 for (const MSTransportable* const transportable : res->persons) {
575 if (transportable->isPerson()) {
576 stops.back().triggered = true;
577 } else {
578 stops.back().containerTriggered = true;
579 }
580 stops.back().permitted.insert(transportable->getID());
581 stops.back().parametersSet |= STOP_PERMITTED_SET | STOP_TRIGGER_SET;
582 }
583 for (const MSTransportable* t : res->persons) {
584 stops.back().awaitedPersons.insert(t->getID());
585 }
586
587 if (stops.back().duration == -1) {
588 // keep dropOffDuration if the stop is dropOff and pickUp
589 stops.back().duration = TIME2STEPS(myHolder.getFloatParam("device.taxi.pickUpDuration", false, 0));
590 }
591 } else {
592 prepareStop(tmpEdges, stops, lastPos, res->to, res->toPos, res->toStop, "dropOff " + toString(res->persons) + " (" + res->id + ")", res, isPickup);
593 stops.back().duration = TIME2STEPS(myHolder.getFloatParam("device.taxi.dropOffDuration", false, 60)); // pay and collect bags
594 }
595 stops.back().parametersSet |= STOP_DURATION_SET | STOP_PARKING_SET;
596 }
597#ifdef DEBUG_DISPATCH
598 if (DEBUG_COND) {
599 std::cout << " tmpEdges=" << toString(tmpEdges) << "\n";
600 }
601#endif
602 const SUMOTime t = SIMSTEP;
603 if (!myHolder.replaceRouteEdges(tmpEdges, -1, 0, "taxi:prepare_dispatch", false, false, false)) {
604 throw ProcessError("Route replacement for taxi dispatch failed for vehicle '" + myHolder.getID()
605 + "' at time=" + time2string(t) + ".");
606 }
607#ifdef DEBUG_DISPATCH
608 if (DEBUG_COND) std::cout << " replacedRoute=" << toString(tmpEdges)
609 << "\n actualRoute=" << toString(myHolder.getRoute().getEdges()) << "\n";
610#endif
611 for (SUMOVehicleParameter::Stop& stop : stops) {
612 std::string error;
613 if (!myHolder.addStop(stop, error)) {
614 WRITE_WARNINGF(TL("Could not add taxi stop for %, desc=% time=% error=%"), myHolder.getID(), stop.actType, time2string(t), error)
615 }
616 }
618 // SUMOAbstractRouter<MSEdge, SUMOVehicle>& router = myHolder.getInfluencer().getRouterTT(veh->getRNGIndex())
619 myHolder.reroute(t, "taxi:dispatch", router, false);
620#ifdef DEBUG_DISPATCH
621 if (DEBUG_COND) {
622 std::cout << "\n finalRoute=" << toString(myHolder.getRoute().getEdges()) << " routeIndex=" << myHolder.getRoutePosition() << "\n";
623 }
624#endif
625 if (hasPickup) {
626 myState |= PICKUP;
627 }
628}
629
630
631void
633 // check if taxi has stopped
634 if (myHolder.getNextStopParameter() == nullptr) {
635 return;
636 }
637 // find customers of the current stop
638 std::set<const MSTransportable*> customersToBeRemoved;
639 std::set<const MSTransportable*> onBoard;
640 onBoard.insert(myHolder.getPersons().begin(), myHolder.getPersons().end());
641 onBoard.insert(myHolder.getContainers().begin(), myHolder.getContainers().end());
642 for (std::string tID : myHolder.getNextStopParameter()->permitted) {
643 for (auto t : myCustomers) {
644 if (t->getID() == tID && onBoard.count(t) == 0) {
645 customersToBeRemoved.insert(t);
646 }
647 }
648 }
649 if (!customersToBeRemoved.empty()) {
650 WRITE_WARNINGF(TL("Taxi '%' aborts waiting for customers: % at time=%."),
651 myHolder.getID(), toString(customersToBeRemoved), time2string(SIMSTEP));
652 }
653 for (auto t : customersToBeRemoved) {
655 }
656}
657
658
659bool
661#ifdef DEBUG_CANCEL
662 if (DEBUG_COND) {
663 std::cout << SIMTIME << " taxi=" << myHolder.getID() << " cancelCustomer " << t->getID() << "\n";
664 }
665#endif
666
667 // is the given transportable a customer of the reservations?
668 if (myCustomers.count(t) == 0) {
669 return false;
670 }
671 myCustomers.erase(t);
672 // check whether a single reservation has been fulfilled or another customer is part of the reservation
673 for (auto resIt = myCurrentReservations.begin(); resIt != myCurrentReservations.end();) {
674 bool fulfilled = false;
675 if ((*resIt)->persons.size() == 1 && (*resIt)->persons.count(t) != 0) {
676 // the reservation contains only the customer
677 fulfilled = true;
678 }
679 if (fulfilled) {
680 const Reservation* res = *resIt;
681 // remove reservation from the current dispatch
682 for (auto it = myLastDispatch.begin(); it != myLastDispatch.end();) {
683 if (*it == res) {
684 it = myLastDispatch.erase(it);
685 } else {
686 ++it;
687 }
688 }
689 // remove reservation from the served reservations
690 resIt = myCurrentReservations.erase(resIt);
691 // delete the reservation
693 } else {
694 ++resIt;
695 }
696 }
697 myState &= ~PICKUP; // remove state PICKUP
698 for (const Reservation* res : myCurrentReservations) {
699 // if there is another pickup in the dispatch left, add the state PICKUP
700 if (std::count(myLastDispatch.begin(), myLastDispatch.end(), res) == 2) {
701 myState |= PICKUP; // add state PICKUP
702 }
703 }
704 // we also have to clean reservations from myLastDispatch where the customers arrived in the meantime
705 for (auto it = myLastDispatch.begin(); it != myLastDispatch.end();) {
706 if (myCurrentReservations.count(*it) == 0) {
707 it = myLastDispatch.erase(it);
708 } else {
709 ++it;
710 }
711 }
712 // if there are reservations left, go on with the dispatch
713 // in meso, wait for the next dispatch cycle to avoid updating stops in this stage
716 }
717 return true;
718}
719
720
721void
723 myCustomers.insert(t);
724 MSBaseVehicle& veh = dynamic_cast<MSBaseVehicle&>(myHolder);
725 for (const MSStop& stop : veh.getStops()) {
726 SUMOVehicleParameter::Stop& pars = const_cast<SUMOVehicleParameter::Stop&>(stop.pars);
727 //std::cout << " sE=" << (*stop.edge)->getID() << " sStart=" << pars.startPos << " sEnd=" << pars.endPos << " rFrom=" <<
728 // res->from->getID() << " rTo=" << res->to->getID() << " rFromPos=" << res->fromPos << " resToPos=" << res->toPos << "\n";
729 if (*stop.edge == res->from
730 && pars.startPos <= res->fromPos
731 && pars.endPos >= res->fromPos) {
732 pars.awaitedPersons.insert(t->getID());
733 pars.permitted.insert(t->getID());
734 pars.actType += " +" + t->getID();
735 } else if (*stop.edge == res->to
736 && pars.startPos <= res->toPos
737 && pars.endPos >= res->toPos) {
738 pars.actType += " +" + t->getID();
739 break;
740 }
741 }
742}
743
744
745void
747 StopParVector& stops,
748 double& lastPos, const MSEdge* stopEdge, double stopPos,
749 const MSStoppingPlace* stopPlace,
750 const std::string& action, const Reservation* res, const bool isPickup) {
751 assert(!edges.empty());
752 if (stopPlace != nullptr && &stopPlace->getLane().getEdge() == stopEdge) {
753 stopPos = stopPlace->getEndLanePosition();
754 }
755 if (stopPos < lastPos && stopPos + NUMERICAL_EPS >= lastPos) {
756 stopPos = lastPos;
757 }
758 bool addedEdge = false;
759
760 if (stops.empty()) {
761 // check brakeGap
762 double distToStop = stopPos - lastPos;
763 const double brakeGap = myHolder.getBrakeGap();
764 if (myHolder.getLane() != nullptr && myHolder.getLane()->isInternal()) {
765 distToStop += myHolder.getLane()->getLength();
766 }
767 if (stopEdge != edges.back()) {
768 distToStop += edges.back()->getLength();
769 if (distToStop < brakeGap) {
770 // the distance between current edge and stop edge may be small
772 ConstMSEdgeVector toFirstStop;
773 router.compute(edges.back(), stopEdge, &myHolder, SIMSTEP, toFirstStop, true);
774 for (int i = 1; i < (int)toFirstStop.size() - 1; i++) {
775 distToStop += toFirstStop[i]->getLength();
776 }
777 }
778 }
779 if (distToStop < brakeGap) {
780 // circle back to stopEdge
781 //std::cout << SIMTIME << " taxi=" << getID() << " brakeGap=" << brakeGap << " distToStop=" << distToStop << "\n";
782 edges.push_back(stopEdge);
783 addedEdge = true;
784 }
785 }
786
787 if (stopEdge == edges.back() && !stops.empty()) {
788 if (stopPos >= lastPos && stopPos <= stops.back().endPos) {
789 // no new stop and no adaption needed
790 stops.back().actType += "," + action;
791 return;
792 }
793 if (stopPos >= lastPos && stopPos <= lastPos + myHolder.getVehicleType().getLength()) {
794 // stop length adaption needed
795 stops.back().endPos = MIN2(lastPos + myHolder.getVehicleType().getLength(), stopEdge->getLength());
796 stops.back().actType += "," + action;
797 return;
798 }
799 }
800 if (!addedEdge && (stopEdge != edges.back() || stopPos < lastPos)) {
801 //std::cout << SIMTIME << " stopPos=" << stopPos << " lastPos=" << lastPos << "\n";
802 edges.push_back(stopEdge);
803 }
804 lastPos = stopPos;
806 stop.lane = getStopLane(stopEdge, action)->getID();
807 if (stopPlace != nullptr && &stopPlace->getLane().getEdge() == stopEdge) {
808 stop.startPos = stopPlace->getBeginLanePosition();
809 stop.endPos = stopPlace->getEndLanePosition();
810 const SumoXMLTag tag = stopPlace->getElement();
811 if (tag == SUMO_TAG_BUS_STOP || tag == SUMO_TAG_TRAIN_STOP) {
812 stop.busstop = stopPlace->getID();
813 } else if (tag == SUMO_TAG_PARKING_AREA) {
814 stop.parkingarea = stopPlace->getID();
815 } else if (tag == SUMO_TAG_CONTAINER_STOP) {
816 stop.containerstop = stopPlace->getID();
817 }
818 } else {
819 stop.startPos = stopPos;
820 stop.endPos = MAX2(stopPos, MIN2(myHolder.getVehicleType().getLength(), stopEdge->getLength()));
822 }
823 stop.parking = SUMOVehicleParameter::parseParkingType(myHolder.getStringParam("device.taxi.parking", false, "true"));
824 stop.actType = action;
825 stop.index = STOP_INDEX_END;
826 // In case of prebooking if person is not there/ comes to late for pickup set maximum waiting time:
827 SUMOTime earliestPickupTime = res->earliestPickupTime;
828 if (isPickup && earliestPickupTime >= 0) {
829 stop.waitUntil = earliestPickupTime;
830 // TODO: replace hard coded extension with parameter
831 stop.extension = static_cast<SUMOTime>(3 * 60 * 1000); // 3mins
832 }
833 stops.push_back(stop);
834}
835
836
837MSLane*
838MSDevice_Taxi::getStopLane(const MSEdge* edge, const std::string& action) {
839 const std::vector<MSLane*>* allowedLanes = edge->allowedLanes(myHolder.getVClass());
840 if (allowedLanes == nullptr) {
841 throw ProcessError("Taxi vehicle '" + myHolder.getID() + "' cannot stop on edge '" + edge->getID() + "' (" + action + ")");
842 }
843 return allowedLanes->front();
844}
845
846bool
848 return myState == EMPTY;
849}
850
851
852bool
854 return myCustomers.count(t) != 0;
855}
856
857
858void
859MSDevice_Taxi::updateMove(const SUMOTime traveltime, const double travelledDist) {
861 myOccupiedDistance += travelledDist;
862 myOccupiedTime += traveltime;
863 }
864 if (isEmpty()) {
865 if (MSNet::getInstance()->getCurrentTimeStep() < myServiceEnd) {
866 myIdleAlgorithm->idle(this);
867 if (myRoutingDevice != nullptr) {
868 // prevent rerouting during idling (#11079)
870 }
871 } else if (!myReachedServiceEnd) {
872 WRITE_WARNINGF(TL("Taxi '%' reaches scheduled end of service at time=%."), myHolder.getID(), time2string(SIMSTEP));
873 myReachedServiceEnd = true;
874 }
875 } else if (myRoutingDevice != nullptr) {
877 }
879 // limit duration of stop (but only for idling-related stops)
881 }
882#ifdef DEBUG_DISPATCH
884 std::cout << SIMTIME << " updateMove veh=" << myHolder.getID() << " myIsStopped=" << myIsStopped << " myHolderStopped=" << myHolder.isStopped() << " myState=" << myState << "\n";
885 }
886#endif
888}
889
890
891bool
893 double newPos, double /*newSpeed*/) {
894 updateMove(DELTA_T, newPos - oldPos);
895 return true; // keep the device
896}
897
898
899void
901 const double /* frontOnLane */,
902 const double timeOnLane,
903 const double /* meanSpeedFrontOnLane */,
904 const double /* meanSpeedVehicleOnLane */,
905 const double travelledDistanceFrontOnLane,
906 const double /* travelledDistanceVehicleOnLane */,
907 const double /* meanLengthOnLane */) {
908 updateMove(TIME2STEPS(timeOnLane), travelledDistanceFrontOnLane);
909}
910
911
912bool
914 if (isEmpty() && MSNet::getInstance()->getCurrentTimeStep() < myServiceEnd) {
915 myIdleAlgorithm->idle(this);
916 }
917 return true; // keep the device
918}
919
920
921void
923 myState |= OCCUPIED;
924 if (!hasFuturePickup()) {
925 myState &= ~PICKUP;
926 }
927 for (const Reservation* res : myCurrentReservations) {
928 for (const MSTransportable* cand : res->persons) {
929 if (cand == t) {
930 const_cast<Reservation*>(res)->state = Reservation::ONBOARD;
931 break;
932 }
933 }
934 }
935}
936
937
938void
941 myCustomers.erase(person);
943 myState &= ~OCCUPIED;
944 if (myHolder.getStops().size() > 1 && (myState & PICKUP) == 0) {
945 WRITE_WARNINGF(TL("All customers left vehicle '%' at time=% but there are % remaining stops"),
947 while (myHolder.getStops().size() > 1) {
949 }
950 }
951 }
952 if (isEmpty()) {
953 // cleanup
954 for (const Reservation* res : myCurrentReservations) {
956 }
957 myCurrentReservations.clear();
959 if (isEmpty()) {
960 if (MSGlobals::gUseMesoSim && MSNet::getInstance()->getCurrentTimeStep() < myServiceEnd) {
961 myIdleAlgorithm->idle(this);
962 }
963 }
964 } else {
965 // check whether a single reservation has been fulfilled
966 for (auto resIt = myCurrentReservations.begin(); resIt != myCurrentReservations.end();) {
967 bool fulfilled = true;
968 for (const MSTransportable* t : (*resIt)->persons) {
969 if (myCustomers.count(t) != 0) {
970 fulfilled = false;
971 break;
972 }
973 }
974 if (fulfilled) {
976 resIt = myCurrentReservations.erase(resIt);
977 } else {
978 ++resIt;
979 }
980 }
981 }
982}
983
984
985void
987 const std::string swapGroup = myHolder.getStringParam("device.taxi.swapGroup", false, "");
988 if (swapGroup != "") {
990 const double stopTime = myHolder.isStopped() ? MAX2(0.0, STEPS2TIME(myHolder.getNextStop().duration)) : 0;
991 double maxSaving = 0;
992 MSDevice_Taxi* bestSwap = nullptr;
993 for (MSDevice_Taxi* taxi : myFleet) {
994 if (taxi->getHolder().hasDeparted() && taxi->getState() == PICKUP
995 && taxi->getHolder().getStringParam("device.taxi.swapGroup", false, "") == swapGroup) {
996 SUMOVehicle& veh = taxi->getHolder();
997 const MSStop& stop = veh.getNextStop();
998 ConstMSEdgeVector toPickup(veh.getCurrentRouteEdge(), stop.edge + 1);
999 const double cost = router.recomputeCostsPos(toPickup, &veh, veh.getPositionOnLane(), stop.pars.endPos, SIMSTEP);
1000 ConstMSEdgeVector toPickup2;
1001 router.compute(myHolder.getEdge(), myHolder.getPositionOnLane(), *stop.edge, stop.pars.endPos, &myHolder, SIMSTEP, toPickup2, true);
1002 if (!toPickup2.empty()) {
1003 const double cost2 = router.recomputeCostsPos(toPickup2, &myHolder, myHolder.getPositionOnLane(), stop.pars.endPos, SIMSTEP);
1004 const double saving = cost - cost2 - stopTime;
1005 //std::cout << SIMTIME << " taxi=" << getID() << " other=" << veh.getID() << " cost=" << cost << " cost2=" << cost2 << " stopTime=" << stopTime << " saving=" << saving << " route1=" << toString(toPickup) << " route2=" << toString(toPickup2) << "\n";
1006 if (saving > maxSaving) {
1007 maxSaving = saving;
1008 bestSwap = taxi;
1009 }
1010 }
1011 }
1012 }
1013 if (maxSaving > SWAP_THRESHOLD) {
1014#ifdef DEBUG_DISPATCH
1015 if (DEBUG_COND) {
1016 std::cout << SIMTIME << " taxi=" << myHolder.getID() << " swapWith=" << bestSwap->getHolder().getID() << " saving=" << maxSaving << " lastDispatch=";
1017 for (const Reservation* res : bestSwap->myLastDispatch) {
1018 std::cout << toString(res->persons) << "; ";
1019 }
1020 std::cout << "\n";
1021 }
1022#endif
1023 dispatchShared(bestSwap->myLastDispatch);
1024 bestSwap->myCurrentReservations.clear();
1025 bestSwap->myCustomers.clear();
1026 bestSwap->myState = EMPTY;
1027 while (bestSwap->getHolder().hasStops()) {
1028 bestSwap->getHolder().abortNextStop();
1029 }
1030 for (const Reservation* res : myCurrentReservations) {
1031 myDispatcher->swappedRunning(res, this);
1032 }
1033 }
1034 }
1035}
1036
1037
1038bool
1040 for (const auto& stop : myHolder.getStops()) {
1041 if (stop.reached) {
1042 continue;
1043 }
1044 if (stop.pars.permitted.size() > 0) {
1045 return true;
1046 }
1047 }
1048 return false;
1049}
1050
1051void
1053 if (tripinfoOut != nullptr) {
1054 tripinfoOut->openTag("taxi");
1055 tripinfoOut->writeAttr("customers", toString(myCustomersServed));
1056 tripinfoOut->writeAttr("occupiedDistance", toString(myOccupiedDistance));
1057 tripinfoOut->writeAttr("occupiedTime", time2string(myOccupiedTime));
1058 tripinfoOut->closeTag();
1059 }
1060}
1061
1062std::string
1063MSDevice_Taxi::getParameter(const std::string& key) const {
1064 if (key == "customers") {
1066 } else if (key == "occupiedDistance") {
1068 } else if (key == "occupiedTime") {
1070 } else if (key == "state") {
1071 return toString(myState);
1072 } else if (key == "currentCustomers") {
1074 } else if (key == "pickUpDuration") {
1075 return myHolder.getStringParam("device.taxi.pickUpDuration", false, "0");
1076 } else if (key == "dropOffDuration") {
1077 return myHolder.getStringParam("device.taxi.dropOffDuration", false, "60");
1078 }
1079 throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
1080}
1081
1082
1083void
1084MSDevice_Taxi::setParameter(const std::string& key, const std::string& value) {
1085 double doubleValue;
1086 try {
1087 doubleValue = StringUtils::toDouble(value);
1088 } catch (NumberFormatException&) {
1089 throw InvalidArgument("Setting parameter '" + key + "' requires a number for device of type '" + deviceName() + "'");
1090 }
1091 if (key == "pickUpDuration" || key == "dropOffDuration") {
1092 // store as generic vehicle parameters
1093 ((SUMOVehicleParameter&)myHolder.getParameter()).setParameter("device.taxi." + key, value);
1094 } else {
1095 UNUSED_PARAMETER(doubleValue);
1096 throw InvalidArgument("Setting parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
1097 }
1098}
1099
1100
1101void
1105 std::ostringstream internals;
1106 internals << myState
1107 << " " << myCustomersServed
1108 << " " << myOccupiedDistance
1109 << " " << myOccupiedTime;
1110 out.writeAttr(SUMO_ATTR_STATE, internals.str());
1111 if (myCustomers.size() > 0) {
1113 }
1114 if (myCurrentReservations.size() > 0) {
1116 }
1117 out.closeTag();
1118}
1119
1120
1121void
1123 bool ok = true;
1124 std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
1125 bis >> myState;
1126 bis >> myCustomersServed;
1127 bis >> myOccupiedDistance;
1128 bis >> myOccupiedTime;
1129 if (attrs.hasAttribute(SUMO_ATTR_CUSTOMERS)) {
1130 for (const std::string& id : attrs.get<std::vector<std::string> >(SUMO_ATTR_CUSTOMERS, getID().c_str(), ok)) {
1131 myStateLoadedCustomers[id] = this;
1132 }
1133 }
1135 for (const std::string& id : attrs.get<std::vector<std::string> >(SUMO_ATTR_RESERVATIONS, getID().c_str(), ok)) {
1136 myStateLoadedReservations[id] = this;
1137 }
1138 }
1139}
1140
1141
1142void
1144 if (myStateLoadedCustomers.size() > 0) {
1145 MSNet* net = MSNet::getInstance();
1146 MSTransportableControl* pc = net->hasPersons() ? &net->getPersonControl() : nullptr;
1147 MSTransportableControl* cc = net->hasContainers() ? &net->getContainerControl() : nullptr;
1148 for (auto item : myStateLoadedCustomers) {
1149 MSTransportable* t = nullptr;
1150 if (pc != nullptr) {
1151 t = pc->get(item.first);
1152 }
1153 if (t == nullptr && cc != nullptr) {
1154 t = cc->get(item.first);
1155 }
1156 if (t == nullptr) {
1157 WRITE_ERRORF("Could not find taxi customer '%'. Ensure state contains transportables", item.first);
1158 } else {
1159 item.second->myCustomers.insert(t);
1160 }
1161 }
1162 }
1163 if (myStateLoadedReservations.size() > 0) {
1164 assert(myDispatcher != nullptr);
1165 std::map<std::string, const Reservation*> resLookup;
1166 for (const Reservation* res : myDispatcher->getReservations()) {
1167 resLookup[res->getID()] = res;
1168 }
1169 for (const Reservation* res : myDispatcher->getRunningReservations()) {
1170 resLookup[res->getID()] = res;
1171 }
1172 for (auto item : myStateLoadedReservations) {
1173 auto it = resLookup.find(item.first);
1174 if (it == resLookup.end()) {
1175 WRITE_ERRORF("Could not find taxi reservation '%'.", item.first);
1176 } else {
1177 item.second->myCurrentReservations.insert(it->second);
1178 }
1179 }
1180 }
1181 myStateLoadedCustomers.clear();
1183}
1184
1185
1186bool
1187MSDevice_Taxi::compatibleLine(const std::string& taxiLine, const std::string& rideLine) {
1188 return ((taxiLine == rideLine && StringUtils::startsWith(rideLine, "taxi") && StringUtils::startsWith(taxiLine, "taxi"))
1189 || (taxiLine == TAXI_SERVICE && StringUtils::startsWith(rideLine, "taxi:"))
1190 || (rideLine == TAXI_SERVICE && StringUtils::startsWith(taxiLine, "taxi:")));
1191}
1192
1193bool
1197
1198
1199/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define TAXI_SERVICE
#define SWAP_THRESHOLD
#define TAXI_SERVICE_PREFIX
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:75
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:299
#define WRITE_ERRORF(...)
Definition MsgHandler.h:308
#define TL(string)
Definition MsgHandler.h:316
#define TLF(string,...)
Definition MsgHandler.h:318
SUMOTime DELTA_T
Definition SUMOTime.cpp:39
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:47
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:107
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SIMSTEP
Definition SUMOTime.h:69
constexpr SUMOTime TIME2STEPS(double x)
Definition SUMOTime.h:60
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define SIMTIME
Definition SUMOTime.h:70
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
const std::string DEFAULT_TAXITYPE_ID
const std::string DEFAULT_RAILTYPE_ID
const std::string DEFAULT_VTYPE_ID
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_RAIL
vehicle is a not electrified rail
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_TAXI
vehicle is a taxi
const std::string DEFAULT_BIKETYPE_ID
const int STOP_DURATION_SET
const int STOP_INDEX_END
const int STOP_PARKING_SET
std::vector< SUMOVehicleParameter::Stop > StopParVector
const int STOP_PERMITTED_SET
const int STOP_START_SET
const int STOP_TRIGGER_SET
const int STOP_END_SET
@ GIVEN
The time is given.
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_DEVICE
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
@ SUMO_ATTR_CUSTOMERS
@ SUMO_ATTR_ID
@ SUMO_ATTR_RESERVATIONS
@ SUMO_ATTR_STATE
The state of a link.
int gTaxiClasses
Definition StdDefs.cpp:38
T MIN2(T a, T b)
Definition StdDefs.h:80
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string joinToStringSorting(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:347
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
std::string joinNamedToStringSorting(const std::set< T * > &ns, const T_BETWEEN &between)
Definition ToString.h:355
Base (microsim) event class.
Definition Command.h:50
The base class for microscopic and mesoscopic vehicles.
const std::list< MSStop > & getStops() const
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)
void prepareStop(ConstMSEdgeVector &edges, StopParVector &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
void addCustomer(const MSTransportable *t, const Reservation *res)
add person after extending reservation
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.
static int myMaxCapacity
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
static std::map< std::string, MSDevice_Taxi * > myStateLoadedCustomers
ids of customers loaded from state
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
static SUMOTime myNextDispatchTime
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.
static bool hasFleet()
returns whether taxis have been loaded
static void allCustomersErased()
signal the end of the simulation and the removal of all customers
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 const std::map< SUMOVehicleClass, std::string > & getTaxiTypes()
return all types that are known to carry a taxi device (or the default type if no devices are initial...
static SUMOTime getNextDispatchTime()
void saveState(OutputDevice &out) const
Saves the state of the device.
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 finalizeLoadState()
call during state loading after all transportables are loaded
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
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
SUMOTime myOccupiedTime
time spent driving with customers
bool myReachedServiceEnd
whether the taxi has reached its schedule service end
~MSDevice_Taxi()
Destructor.
static std::map< std::string, MSDevice_Taxi * > myStateLoadedReservations
ids of reservations loaded from state
static std::map< SUMOVehicleClass, std::string > myTaxiTypes
storing only one type per vClass
MSLane * getStopLane(const MSEdge *edge, const std::string &action)
determine stopping lane for taxi
void checkTaskSwap()
optionally swap tasks when a taxi becomes idle
static void initDispatch(SUMOTime next=-1)
initialize the dispatch algorithm
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key
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.
Definition MSDevice.cpp:181
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.
Definition MSDevice.h:213
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.
Definition MSDispatch.h:114
void swappedRunning(const Reservation *res, MSDevice_Taxi *taxi)
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...
std::vector< Reservation * > getReservations()
retrieve all reservations
virtual std::vector< const Reservation * > getRunningReservations()
retrieve all reservations that were already dispatched and are still active
virtual SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouter() const
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
Definition MSDispatch.h:176
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
void servedReservation(const Reservation *res, MSDevice_Taxi *taxi)
A road/street connecting two junctions.
Definition MSEdge.h:78
SVCPermissions getPermissions() const
Returns the combined permissions of all lanes of this edge.
Definition MSEdge.h:659
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.
Definition MSEdge.cpp:516
double getLength() const
return the length of the edge
Definition MSEdge.h:695
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static bool gUseMesoSim
Definition MSGlobals.h:106
virtual void idle(MSDevice_Taxi *taxi)=0
computes Idling and updates reservations
int getPendingFlowCount() const
Returns the number of flows that are still active.
Representation of a lane in the micro simulation.
Definition MSLane.h:84
double getLength() const
Returns the lane's length.
Definition MSLane.h:632
bool isInternal() const
Definition MSLane.cpp:2669
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:790
Notification
Definition of a vehicle state.
The simulated network and simulation perfomer.
Definition MSNet.h:90
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
SUMOTime getLoaderTime() const
Definition MSNet.cpp:1153
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition MSNet.h:506
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1326
void resetIntermodalRouter() const
force reconstruction of intermodal network
Definition MSNet.cpp:1762
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:335
bool hasContainers() const
Returns whether containers are simulated.
Definition MSNet.h:436
bool hasPersons() const
Returns whether persons are simulated.
Definition MSNet.h:420
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:456
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:403
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1317
const ConstMSEdgeVector & getEdges() const
Definition MSRoute.h:128
static MSVehicleRouter & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const Prohibitions &prohibited={})
return the vehicle router instance
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
bool joinTriggered
whether coupling another vehicle (train) the vehicle continue
Definition MSStop.h:73
MSRouteIterator edge
The edge in the route to stop at.
Definition MSStop.h:48
SUMOTime endBoarding
the maximum time at which persons may board this vehicle
Definition MSStop.h:85
SUMOTime duration
The stopping duration.
Definition MSStop.h:67
const SUMOVehicleParameter::Stop pars
The stop parameter.
Definition MSStop.h:65
A lane area vehicles can halt at.
double getBeginLanePosition() const
Returns the begin position of this stop.
SumoXMLTag getElement() const
return the type of this stopping place
double getEndLanePosition() const
Returns the end position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
MSTransportable * get(const std::string &id) const
Returns the named transportable, if existing.
bool isPerson() const override
Whether it is a person.
Reroutes traffic objects passing an edge.
static const std::map< std::string, MSTriggeredRerouter * > & getInstances()
return all rerouter instances
The class responsible for building and deletion of vehicles.
bool hasVType(const std::string &id) const
Asks for existence of a vehicle type.
bool addVType(MSVehicleType *vehType)
Adds a vehicle type.
Abstract in-vehicle device.
SUMOVehicle & myHolder
The vehicle that stores the device.
SUMOVehicle & getHolder() const
Returns the vehicle that holds this device.
The car-following model and parameter.
int getPersonCapacity() const
Get this vehicle type's person capacity.
const std::string & getID() const
Returns the name of the vehicle type.
static MSVehicleType * build(SUMOVTypeParameter &from, const std::string &fileName="")
Builds the microsim vehicle type described by the given parameter.
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.
Definition Named.h:73
A storage for options typed value containers)
Definition OptionsCont.h:92
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 addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
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.
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
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 ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
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 &paramsString, 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...
double recomputeCostsPos(const std::vector< const E * > &edges, const V *const v, double fromPos, double toPos, SUMOTime msTime, double *lengthp=nullptr) const
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
Representation of a vehicle, person, or container.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
std::string getStringParam(const std::string &paramName, const bool required=false, const std::string &deflt="") const
Retrieve a string parameter for the traffic object.
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual int getRNGIndex() const =0
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 const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
double getFloatParam(const std::string &paramName, const bool required=false, const double deflt=INVALID_DOUBLE, bool checkDist=true) const
Retrieve a floating point parameter for the traffic object.
virtual const MSEdge * getEdge() const =0
Returns the (normal) route edge the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Structure representing possible vehicle parameter.
Representation of a vehicle.
Definition SUMOVehicle.h:63
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 std::vector< MSTransportable * > & getContainers() const =0
retrieve riding containers
virtual bool isStopped() const =0
Returns whether the vehicle is at a stop and waiting for a person or container to continue.
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 const std::list< MSStop > & getStops() const =0
virtual int getPersonNumber() const =0
Returns the number of persons.
virtual void unregisterWaiting()=0
mark vehicle as active
virtual bool isStoppedTriggered() const =0
Returns whether the vehicle is at a stop and waiting for a person or container to continue.
virtual const std::vector< MSTransportable * > & getPersons() const =0
retrieve riding persons
virtual int getContainerNumber() const =0
Returns the number of containers.
virtual const MSStop & getNextStop() const =0
virtual MSStop & getNextStopMutable()=0
virtual double getBrakeGap(bool delayed=false) const =0
get distance for coming to a stop (used for rerouting checks)
virtual bool isStoppedParking() const =0
Returns whether the vehicle is at a stop and parking.
virtual int getRoutePosition() const =0
return index of edge within route
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
virtual const SUMOVehicleParameter::Stop * getNextStopParameter() const =0
Returns parameters of the next stop or nullptr.
virtual const MSRoute & getRoute() const =0
Returns the current route.
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.
std::string parkingarea
(Optional) parking area if one is assigned to the stop
double startPos
The stopping position start.
std::set< std::string > permitted
IDs of persons or containers that may board/load at this stop.
int parametersSet
Information for the output which parameter were set.
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.
std::set< std::string > awaitedPersons
IDs of persons the vehicle has to wait for until departing.
std::string busstop
(Optional) bus stop if one is assigned to the stop
std::string containerstop
(Optional) container stop if one is assigned to the 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 std::string to_upper_case(const std::string &str)
Transfers the content to upper case.
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.
#define UNUSED_PARAMETER(x)
#define DEBUG_COND
const MSEdge * to
Definition MSDispatch.h:84
double fromPos
Definition MSDispatch.h:82
std::string line
Definition MSDispatch.h:88
const MSEdge * from
Definition MSDispatch.h:81
SUMOTime earliestPickupTime
Definition MSDispatch.h:80
double toPos
Definition MSDispatch.h:85