32#define DEBUG_COND2(obj) (true)
51 myReservationCount(0) {
52 const std::string opt =
"device.taxi.dispatch-algorithm.output";
75 const MSEdge* from,
double fromPos,
77 const MSEdge* to,
double toPos,
80 const std::string& line,
82 int maxContainerCapacity) {
87 group = person->
getID();
95 if (res->persons.count(person) == 0
98 && res->fromPos == fromPos
99 && res->toPos == toPos) {
100 if (res->persons.size() > 0 && (*res->persons.begin())->isPerson() != person->
isPerson()) {
101 WRITE_WARNINGF(
TL(
"Mixing reservations of persons and containers with the same group is not supported for % and %"),
102 (*res->persons.begin())->getID(), person->
getID());
104 if ((person->
isPerson() && (
int)res->persons.size() >= maxCapacity) ||
105 (!person->
isPerson() && (
int)res->persons.size() >= maxContainerCapacity)) {
109 res->persons.insert(person);
117 Reservation* newRes =
new Reservation(
toString(
myReservationCount++), {person}, reservationTime, pickupTime, earliestPickupTime, from, fromPos, fromStop, to, toPos, toStop, group, line);
122#ifdef DEBUG_RESERVATION
124 <<
" addReservation p=" << person->
getID()
127 <<
" from=" << from->
getID() <<
" fromPos=" << fromPos
128 <<
" to=" << to->
getID() <<
" toPos=" << toPos
129 <<
" group=" << group
130 <<
" added=" << added
139 const MSEdge* from,
double fromPos,
140 const MSEdge* to,
double toPos,
145 group = person->
getID();
147 std::string removedID =
"";
150 for (
auto itRes = it->second.begin(); itRes != it->second.end(); itRes++) {
152 if (res->
persons.count(person) != 0
156 && res->
toPos == toPos) {
160 it->second.erase(itRes);
163 if (it->second.empty()) {
173 for (
auto item : it2->second) {
175 if (res->
persons.count(person) != 0
179 && res->
toPos == toPos) {
191#ifdef DEBUG_RESERVATION
193 <<
" removeReservation p=" << person->
getID()
194 <<
" from=" << from->
getID() <<
" fromPos=" << fromPos
195 <<
" to=" << to->
getID() <<
" toPos=" << toPos
196 <<
" group=" << group
197 <<
" removedID=" << removedID
207 const MSEdge* from,
double fromPos,
208 const MSEdge* to,
double toPos,
209 std::string group,
double newFromPos) {
213 group = person->
getID();
216 std::string updatedID =
"";
219 for (
auto itRes = it->second.begin(); itRes != it->second.end(); itRes++) {
223 if (res->
persons.count(person) != 0
227 && res->
toPos == toPos) {
236#ifdef DEBUG_RESERVATION
238 <<
" updateReservationFromPos p=" << person->
getID()
239 <<
" from=" << from->
getID() <<
" fromPos=" << fromPos
240 <<
" to=" << to->
getID() <<
" toPos=" << toPos
241 <<
" group=" << group
242 <<
" newFromPos=" << newFromPos
243 <<
" updatedID=" << updatedID
250std::vector<Reservation*>
252 std::vector<Reservation*> reservations;
254 reservations.insert(reservations.end(), it.second.begin(), it.second.end());
260std::vector<const Reservation*>
262 std::vector<const Reservation*> result;
264 for (
auto item2 : item.second) {
265 result.push_back(item2.first);
282 auto it2 = std::find(it->second.begin(), it->second.end(), res);
283 if (it2 == it->second.end()) {
288 it->second.erase(it2);
289 if (it->second.empty()) {
322 return !edges.empty();
328 const MSEdge* from,
double fromPos,
329 const MSEdge* via,
double viaPos,
330 const MSEdge* to,
double toPos,
332 double& timeDirect) {
334 if (timeDirect < 0) {
335 router.
compute(from, fromPos, to, toPos, &taxi->
getHolder(), t, edges,
true);
340 router.
compute(from, fromPos, via, viaPos, &taxi->
getHolder(), t, edges,
true);
344 std::cout <<
" leg1=" <<
toString(edges) <<
" startPos=" << fromPos <<
" toPos=" << viaPos <<
" time=" << leg1 <<
"\n";
346 const double wait =
MAX2(0.0,
STEPS2TIME(viaTime) - (start + leg1));
349 router.
compute(via, viaPos, to, toPos, &taxi->
getHolder(), timeContinue, edges,
true);
351 const double timeDetour = leg1 + wait + leg2;
353 std::cout <<
" leg2=" <<
toString(edges) <<
" startPos=" << viaPos <<
" toPos=" << toPos <<
" time=" << leg2 <<
"\n";
355 <<
" from=" << from->
getID() <<
" to=" << to->
getID() <<
" via=" << via->
getID()
356 <<
" direct=" << timeDirect <<
" detour=" << timeDetour <<
" wait=" << wait <<
"\n";
364 assert(res->
persons.size() > 0);
365 return ((*res->
persons.begin())->isPerson()
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)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A device which collects info on the vehicle trip (mainly on departure and arrival)
bool cancelCustomer(const MSTransportable *t)
remove person from reservations
OutputDevice * myOutput
optional file output for dispatch information
bool isReachable(SUMOTime t, const MSDevice_Taxi *taxi, const Reservation &res, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router)
compute whether the reservation is servable
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
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 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 fulfilledReservation(const Reservation *res)
erase reservation from storage
MSDispatch(const Parameterised::Map ¶ms)
Constructor;.
std::map< std::string, std::map< const Reservation *, MSDevice_Taxi * > > myRunningReservations
virtual ~MSDispatch()
Destructor.
void servedReservation(const Reservation *res, MSDevice_Taxi *taxi)
A road/street connecting two junctions.
A lane area vehicles can halt at.
bool isPerson() const
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 bool createDeviceByOption(const std::string &optionName, const std::string &rootElement="", const std::string &schemaFile="")
Creates the device using the output definition stored in the named option.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the 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...
virtual double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
double recomputeCostsPos(const std::vector< const E * > &edges, const V *const v, double fromPos, double toPos, SUMOTime msTime, double *lengthp=nullptr) const
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
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.
std::string getID() const
debug identification
std::set< const MSTransportable * > persons