Skip to content

Commit

Permalink
add earliestPickupTime to reservation and do prebooking, ref. #10447
Browse files Browse the repository at this point in the history
  • Loading branch information
rummel123 committed Feb 28, 2024
1 parent 6638b8c commit e356a15
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/microsim/devices/MSDevice_Taxi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ MSDevice_Taxi::addReservation(MSTransportable* person,
const std::set<std::string>& lines,
SUMOTime reservationTime,
SUMOTime pickupTime,
SUMOTime earliestPickupTime,
const MSEdge* from, double fromPos,
const MSEdge* to, double toPos,
const std::string& group) {
Expand All @@ -187,7 +188,7 @@ MSDevice_Taxi::addReservation(MSTransportable* person,
if (myDispatchCommand == nullptr) {
initDispatch();
}
myDispatcher->addReservation(person, reservationTime, pickupTime, from, fromPos, to, toPos, group, *lines.begin(), myMaxCapacity, myMaxContainerCapacity);
myDispatcher->addReservation(person, reservationTime, pickupTime, earliestPickupTime, from, fromPos, to, toPos, group, *lines.begin(), myMaxCapacity, myMaxContainerCapacity);
}

void
Expand Down
1 change: 1 addition & 0 deletions src/microsim/devices/MSDevice_Taxi.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class MSDevice_Taxi : public MSVehicleDevice {
const std::set<std::string>& lines,
SUMOTime reservationTime,
SUMOTime pickupTime,
SUMOTime earliestPickupTime,
const MSEdge* from, double fromPos,
const MSEdge* to, double toPos,
const std::string& group);
Expand Down
3 changes: 2 additions & 1 deletion src/microsim/devices/MSDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Reservation*
MSDispatch::addReservation(MSTransportable* person,
SUMOTime reservationTime,
SUMOTime pickupTime,
SUMOTime earliestPickupTime,
const MSEdge* from, double fromPos,
const MSEdge* to, double toPos,
std::string group,
Expand Down Expand Up @@ -110,7 +111,7 @@ MSDispatch::addReservation(MSTransportable* person,
}
}
if (!added) {
Reservation* newRes = new Reservation(toString(myReservationCount++), {person}, reservationTime, pickupTime, from, fromPos, to, toPos, group, line);
Reservation* newRes = new Reservation(toString(myReservationCount++), {person}, reservationTime, pickupTime, earliestPickupTime, from, fromPos, to, toPos, group, line);
myGroupReservations[group].push_back(newRes);
result = newRes;
}
Expand Down
4 changes: 4 additions & 0 deletions src/microsim/devices/MSDispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct Reservation {
const std::vector<MSTransportable*>& _persons,
SUMOTime _reservationTime,
SUMOTime _pickupTime,
SUMOTime _earliestPickupTime,
const MSEdge* _from, double _fromPos,
const MSEdge* _to, double _toPos,
const std::string& _group,
Expand All @@ -56,6 +57,7 @@ struct Reservation {
persons(_persons.begin(), _persons.end()),
reservationTime(_reservationTime),
pickupTime(_pickupTime),
earliestPickupTime(_earliestPickupTime),
from(_from),
fromPos(_fromPos),
to(_to),
Expand All @@ -70,6 +72,7 @@ struct Reservation {
std::set<MSTransportable*> persons;
SUMOTime reservationTime;
SUMOTime pickupTime;
SUMOTime earliestPickupTime;
const MSEdge* from;
double fromPos;
const MSEdge* to;
Expand Down Expand Up @@ -124,6 +127,7 @@ class MSDispatch : public Parameterised {
virtual Reservation* addReservation(MSTransportable* person,
SUMOTime reservationTime,
SUMOTime pickupTime,
SUMOTime earliestPickupTime,
const MSEdge* from, double fromPos,
const MSEdge* to, double toPos,
std::string group,
Expand Down
5 changes: 3 additions & 2 deletions src/microsim/devices/MSDispatch_TraCI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ Reservation*
MSDispatch_TraCI::addReservation(MSTransportable* person,
SUMOTime reservationTime,
SUMOTime pickupTime,
SUMOTime earliestPickupTime,
const MSEdge* from, double fromPos,
const MSEdge* to, double toPos,
std::string group,
const std::string& line,
int maxCapacity,
int maxContainerCapacity) {
Reservation* res = MSDispatch::addReservation(person, reservationTime, pickupTime, from, fromPos, to, toPos, group, line, maxCapacity, maxContainerCapacity);
Reservation* res = MSDispatch::addReservation(person, reservationTime, pickupTime, earliestPickupTime, from, fromPos, to, toPos, group, line, maxCapacity, maxContainerCapacity);
if (!myReservationLookup.has(res)) {
myReservationLookup.insert(res->id, res);
}
Expand Down Expand Up @@ -131,7 +132,7 @@ MSDispatch_TraCI::splitReservation(std::string resID, std::vector<std::string> p
}
Reservation* newRes = new Reservation(toString(myReservationCount++), split,
res->reservationTime, res->pickupTime,
res->from, res->fromPos,
res->earliestPickupTime, res->from, res->fromPos,
res->to, res->toPos, res->group, res->line);
myGroupReservations[res->group].push_back(newRes);
myReservationLookup.insert(newRes->id, newRes);
Expand Down
1 change: 1 addition & 0 deletions src/microsim/devices/MSDispatch_TraCI.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class MSDispatch_TraCI : public MSDispatch {
Reservation* addReservation(MSTransportable* person,
SUMOTime reservationTime,
SUMOTime pickupTime,
SUMOTime earliestPickupTime,
const MSEdge* from, double fromPos,
const MSEdge* to, double toPos,
std::string group,
Expand Down
1 change: 1 addition & 0 deletions src/microsim/transportables/MSStage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ MSStage::MSStage(const MSEdge* destination, MSStoppingPlace* toStop, const doubl

MSStage::~MSStage() {}


const MSEdge*
MSStage::getDestination() const {
return myDestination;
Expand Down
3 changes: 3 additions & 0 deletions src/microsim/transportables/MSStage.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class MSStage : public Parameterised {
/// destructor
virtual ~MSStage();

/// initialization, e.g. for param-related events
virtual void init(MSTransportable* /*transportable*/) {};

/// returns the destination edge
const MSEdge* getDestination() const;

Expand Down
35 changes: 33 additions & 2 deletions src/microsim/transportables/MSStageDriving.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <utils/router/PedestrianRouter.h>
#include <utils/router/IntermodalRouter.h>
#include <microsim/MSEdge.h>
#include <microsim/MSEventControl.h>
#include <microsim/MSLane.h>
#include <microsim/MSNet.h>
#include <microsim/MSStop.h>
Expand All @@ -37,6 +38,7 @@
#include <microsim/devices/MSTransportableDevice.h>
#include <microsim/devices/MSDevice_Taxi.h>
#include <microsim/devices/MSDevice_Tripinfo.h>
#include <microsim/devices/MSDispatch.h>
#include <microsim/transportables/MSTransportableControl.h>
#include <microsim/transportables/MSStageDriving.h>
#include <microsim/transportables/MSPModel.h>
Expand All @@ -58,12 +60,14 @@ MSStageDriving::MSStageDriving(const MSEdge* origin, const MSEdge* destination,
myVehicleVClass(SVC_IGNORING),
myVehicleDistance(-1.),
myTimeLoss(-1),
myWaitingPos(-1),
myWaitingSince(-1),
myWaitingEdge(nullptr),
myStopWaitPos(Position::INVALID),
myOriginStop(nullptr),
myIntendedVehicleID(intendedVeh),
myIntendedDepart(intendedDepart) {
myIntendedDepart(intendedDepart),
myReservationCommand(nullptr) {
}


Expand All @@ -80,6 +84,20 @@ MSStageDriving::clone() const {
MSStageDriving::~MSStageDriving() {}


void
MSStageDriving::init(MSTransportable* transportable) {
if (hasParameter("earliestPickupTime")) {
SUMOTime reservationTime = MSNet::getInstance()->getCurrentTimeStep();
if (hasParameter("reservationTime")) {
reservationTime = string2time(getParameter("reservationTime"));
}
SUMOTime earliestPickupTime = string2time(getParameter("earliestPickupTime"));
myReservationCommand = new BookReservation(transportable, earliestPickupTime, this);
MSNet::getInstance()->getBeginOfTimestepEvents()->addEvent(myReservationCommand, reservationTime);
}
}


const MSEdge*
MSStageDriving::getEdge() const {
if (myVehicle != nullptr) {
Expand Down Expand Up @@ -285,7 +303,11 @@ MSStageDriving::registerWaiting(MSTransportable* transportable, SUMOTime now) {
}
}
}
MSDevice_Taxi::addReservation(transportable, getLines(), now, now, myWaitingEdge, myWaitingPos, to, toPos, myGroup);
// Create reservation only if not already created by previous reservationTime
if (myReservationCommand == nullptr) {
MSDevice_Taxi::addReservation(transportable, getLines(), now, now, now, myWaitingEdge, myWaitingPos, to, toPos, myGroup);
}

}
if (transportable->isPerson()) {
MSNet::getInstance()->getPersonControl().addWaiting(myWaitingEdge, transportable);
Expand Down Expand Up @@ -581,5 +603,14 @@ MSStageDriving::loadState(MSTransportable* transportable, std::istringstream& st
}
}

// ---------------------------------------------------------------------------
// MSStageDriving::BookReservation method definitions
// ---------------------------------------------------------------------------
SUMOTime
MSStageDriving::BookReservation::execute(SUMOTime currentTime) {
MSDevice_Taxi::addReservation(myTransportable, myStage->getLines(), currentTime, currentTime, myEarliestPickupTime, myStage->myOrigin, myStage->myOrigin->getLength()/2, myStage->getDestination(), myStage->getArrivalPos(), myStage->myGroup);
// do not repeat if execution fails
return 0;
}

/****************************************************************************/
18 changes: 18 additions & 0 deletions src/microsim/transportables/MSStageDriving.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <set>
#include <cassert>
#include <utils/common/Command.h>
#include <utils/common/SUMOTime.h>
#include <utils/common/SUMOVehicleClass.h>
#include <utils/geom/Position.h>
Expand Down Expand Up @@ -77,6 +78,9 @@ class MSStageDriving : public MSStage {
/// abort this stage (TraCI)
void abort(MSTransportable* t);

/// initialization, e.g. for param-related events
void init(MSTransportable* transportable);

/// Returns the current edge
const MSEdge* getEdge() const;
const MSEdge* getFromEdge() const;
Expand Down Expand Up @@ -209,6 +213,7 @@ class MSStageDriving : public MSStage {

std::string myIntendedVehicleID;
SUMOTime myIntendedDepart;
Command* myReservationCommand;

private:
/// brief register waiting person (on proceed or loadState)
Expand All @@ -221,4 +226,17 @@ class MSStageDriving : public MSStage {
/// @brief Invalidated assignment operator.
MSStageDriving& operator=(const MSStageDriving&) = delete;

private:
class BookReservation : public Command {
public:
BookReservation(MSTransportable* transportable, SUMOTime earliestPickupTime, MSStageDriving* stage) :
myTransportable(transportable), myEarliestPickupTime(earliestPickupTime), myStage(stage) {}
SUMOTime execute(SUMOTime currentTime);

private:
MSTransportable* myTransportable;
SUMOTime myEarliestPickupTime;
MSStageDriving* myStage;
};

};
3 changes: 3 additions & 0 deletions src/microsim/transportables/MSTransportable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ MSTransportable::MSTransportable(const SUMOVehicleParameter* pars, MSVehicleType
myStep = myPlan->begin();
// init devices
MSDevice::buildTransportableDevices(*this, myDevices);
for (MSStage* const stage : * myPlan) {
stage->init(this);
}
}


Expand Down

0 comments on commit e356a15

Please sign in to comment.