34#define DEBUG_COND2(obj) (true)
48 myReservationCount(0),
49 myRoutingMode(
StringUtils::toInt(getParameter(
"routingMode",
"1"))) {
50 const std::string opt =
"device.taxi.dispatch-algorithm.output";
73 const MSEdge* from,
double fromPos,
75 const MSEdge* to,
double toPos,
78 const std::string& line,
80 int maxContainerCapacity) {
93 group = person->
getID();
97 for (
auto item : it2->second) {
102 && (res->
toPos == toPos || res->
toStop == toStop)) {
107 || resID == res->
id) {
111#ifdef DEBUG_RESERVATION
126 if (res->persons.count(person) == 0
129 && (res->fromPos == fromPos || res->fromStop == fromStop)
130 && (res->toPos == toPos || res->toStop == toStop)
131 && (resID.empty() || res->id == resID)) {
132 if (res->persons.size() > 0 && (*res->persons.begin())->isPerson() != person->
isPerson()) {
133 WRITE_WARNINGF(
TL(
"Mixing reservations of persons and containers with the same group is not supported for % and %"),
134 (*res->persons.begin())->getID(), person->
getID());
136 if ((person->
isPerson() && (
int)res->persons.size() >= maxCapacity) ||
137 (!person->
isPerson() && (
int)res->persons.size() >= maxContainerCapacity)) {
141 res->persons.insert(person);
152 Reservation* newRes =
new Reservation(resID, {person}, reservationTime, pickupTime, earliestPickupTime, from, fromPos, fromStop, to, toPos, toStop, group, line);
157#ifdef DEBUG_RESERVATION
159 <<
" addReservation p=" << person->
getID()
160 <<
" addID=" << result->
getID()
163 <<
" from=" << from->
getID() <<
" fromPos=" << fromPos
164 <<
" to=" << to->
getID() <<
" toPos=" << toPos
165 <<
" group=" << group
166 <<
" added=" << added
175 const MSEdge* from,
double fromPos,
176 const MSEdge* to,
double toPos,
181 group = person->
getID();
183 std::string removedID =
"";
186 for (
auto itRes = it->second.begin(); itRes != it->second.end(); itRes++) {
188 if (res->
persons.count(person) != 0
192 && res->
toPos == toPos) {
196 it->second.erase(itRes);
199 if (it->second.empty()) {
209 for (
auto item : it2->second) {
211 if (res->
persons.count(person) != 0
215 && res->
toPos == toPos) {
216 if (res->
persons.size() == 1) {
219 item.second->cancelCustomer(person);
226#ifdef DEBUG_RESERVATION
228 <<
" removeReservation p=" << person->
getID()
229 <<
" from=" << from->
getID() <<
" fromPos=" << fromPos
230 <<
" to=" << to->
getID() <<
" toPos=" << toPos
231 <<
" group=" << group
232 <<
" removedID=" << removedID
242 const MSEdge* from,
double fromPos,
243 const MSEdge* to,
double toPos,
244 std::string group,
double newFromPos) {
248 group = person->
getID();
251 std::string updatedID =
"";
254 for (
auto itRes = it->second.begin(); itRes != it->second.end(); itRes++) {
258 if (res->
persons.count(person) != 0
262 && res->
toPos == toPos) {
271#ifdef DEBUG_RESERVATION
273 <<
" updateReservationFromPos p=" << person->
getID()
274 <<
" from=" << from->
getID() <<
" fromPos=" << fromPos
275 <<
" to=" << to->
getID() <<
" toPos=" << toPos
276 <<
" group=" << group
277 <<
" newFromPos=" << newFromPos
278 <<
" updatedID=" << updatedID
285std::vector<Reservation*>
287 std::vector<Reservation*> reservations;
289 reservations.insert(reservations.end(), it.second.begin(), it.second.end());
295std::vector<const Reservation*>
297 std::vector<const Reservation*> result;
299 for (
auto item2 : item.second) {
300 result.push_back(item2.first);
311#ifdef DEBUG_RESERVATION
312 std::cout <<
SIMTIME <<
" servedReservation res=" << res->
id <<
" taxi=" << taxi->
getID() <<
" (running)\n";
316#ifdef DEBUG_RESERVATION
317 std::cout <<
SIMTIME <<
" servedReservation res=" << res->
id <<
" taxi=" << taxi->
getID() <<
"\n";
323 auto it2 = std::find(it->second.begin(), it->second.end(), res);
324 if (it2 == it->second.end()) {
329 it->second.erase(it2);
330 if (it->second.empty()) {
338#ifdef DEBUG_RESERVATION
347#ifdef DEBUG_RESERVATION
348 std::cout <<
SIMTIME <<
" fullfilled res=" << res->
id <<
"\n";
387 return !edges.empty();
393 const MSEdge* from,
double fromPos,
394 const MSEdge* via,
double viaPos,
395 const MSEdge* to,
double toPos,
397 double& timeDirect) {
399 if (timeDirect < 0) {
400 router.
compute(from, fromPos, to, toPos, &taxi->
getHolder(), t, edges,
true);
405 router.
compute(from, fromPos, via, viaPos, &taxi->
getHolder(), t, edges,
true);
409 std::cout <<
" leg1=" <<
toString(edges) <<
" startPos=" << fromPos <<
" toPos=" << viaPos <<
" time=" << leg1 <<
"\n";
411 const double wait =
MAX2(0.0,
STEPS2TIME(viaTime) - (start + leg1));
414 router.
compute(via, viaPos, to, toPos, &taxi->
getHolder(), timeContinue, edges,
true);
416 const double timeDetour = leg1 + wait + leg2;
418 std::cout <<
" leg2=" <<
toString(edges) <<
" startPos=" << viaPos <<
" toPos=" << toPos <<
" time=" << leg2 <<
"\n";
420 <<
" from=" << from->
getID() <<
" to=" << to->
getID() <<
" via=" << via->
getID()
421 <<
" direct=" << timeDirect <<
" detour=" << timeDetour <<
" wait=" << wait <<
"\n";
429 assert(res->
persons.size() > 0);
430 return ((*res->
persons.begin())->isPerson()
442 std::ostringstream internals;
444 for (
const auto& item : it.second) {
446 internals << t->getID() <<
" " << item.first->id <<
" ";
453 internals << t->getID() <<
" " << res->id <<
" ";
467 std::string tID, rID;
468 while (bis >> tID && bis >> rID) {
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
@ SUMO_TAG_DISPATCHER
Dispatcher state for saving.
@ SUMO_ATTR_NEXT
succesor phase index
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A device which collects info on the vehicle trip (mainly on departure and arrival)
void addCustomer(const MSTransportable *t, const Reservation *res)
add person after extending reservation
bool compatibleLine(const Reservation *res)
whether the given reservation is compatible with the taxi line
OutputDevice * myOutput
optional file output for dispatch information
const int myRoutingMode
which router/edge weights to use
bool isReachable(SUMOTime t, const MSDevice_Taxi *taxi, const Reservation &res, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router)
compute whether the reservation is servable
void swappedRunning(const Reservation *res, MSDevice_Taxi *taxi)
int remainingCapacity(const MSDevice_Taxi *taxi, const Reservation *res)
whether the given taxi has sufficient capacity to serve the reservation
static SUMOTime computePickupTime(SUMOTime t, const MSDevice_Taxi *taxi, const Reservation &res, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router)
compute time to pick up the given reservation
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
bool myHasServableReservations
whether the last call to computeDispatch has left servable reservations
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::map< std::string, std::vector< Reservation * > > myGroupReservations
std::vector< Reservation * > getReservations()
retrieve all reservations
virtual std::vector< const Reservation * > getRunningReservations()
retrieve all reservations that were already dispatched and are still active
SUMOTime myKeepUnreachableResTime
the duration before canceling unreachable reservations
std::map< std::string, std::string > myLoadedReservations
reservations loaded from state
static double computeDetourTime(SUMOTime t, SUMOTime viaTime, const MSDevice_Taxi *taxi, const MSEdge *from, double fromPos, const MSEdge *via, double viaPos, const MSEdge *to, double toPos, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, double &timeDirect)
compute directTime and detourTime
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
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
virtual void fulfilledReservation(const Reservation *res)
erase reservation from storage
virtual void saveState(OutputDevice &out, SUMOTime nextDispatch) const
Saves the state of the device.
MSDispatch(const Parameterised::Map ¶ms)
Constructor;.
std::map< std::string, std::map< const Reservation *, MSDevice_Taxi *, ComparatorIdLess > > myRunningReservations
virtual ~MSDispatch()
Destructor.
void servedReservation(const Reservation *res, MSDevice_Taxi *taxi)
A road/street connecting two junctions.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSVehicleRouter & getRouterTT(int rngIndex, const Prohibitions &prohibited={}) const
static MSVehicleRouter & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const Prohibitions &prohibited={})
return the vehicle router instance
A lane area vehicles can halt at.
bool isPerson() const override
Whether it is a person.
SUMOVehicle & getHolder() const
Returns the vehicle that holds this device.
int getPersonCapacity() const
Get this vehicle type's person capacity.
int getContainerCapacity() const
Get this vehicle type's container capacity.
const std::string & getID() const
Returns the id.
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)
writes a named attribute
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static bool createDeviceByOption(const std::string &optionName, const std::string &rootElement="", const std::string &schemaFile="", const int maximumDepth=2)
Creates the device using the output definition stored in the named option.
An upper class for objects with additional parameters.
std::map< std::string, std::string > Map
parameters 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 const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
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.
virtual ConstMSEdgeVector::const_iterator getRerouteOrigin() const =0
Returns the starting point for reroutes (usually the current edge)
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
std::string line
The vehicle's line (mainly for public transport)
Some static methods for string processing.
const MSStoppingPlace * toStop
const MSStoppingPlace * fromStop
std::string getID() const
for sorting by id
std::set< const MSTransportable *, ComparatorNumericalIdLess > persons