32#define DEBUG_COND2(obj) (true)
51 myReservationCount(0) {
52 const std::string opt =
"device.taxi.dispatch-algorithm.output";
74 const MSEdge* from,
double fromPos,
76 const MSEdge* to,
double toPos,
79 const std::string& line,
81 int maxContainerCapacity) {
86 group = person->
getID();
94 if (res->persons.count(person) == 0
97 && res->fromPos == fromPos
98 && res->toPos == toPos) {
99 if (res->persons.size() > 0 && (*res->persons.begin())->isPerson() != person->
isPerson()) {
100 WRITE_WARNINGF(
TL(
"Mixing reservations of persons and containers with the same group is not supported for % and %"),
101 (*res->persons.begin())->getID(), person->
getID());
103 if ((person->
isPerson() && (
int)res->persons.size() >= maxCapacity) ||
104 (!person->
isPerson() && (
int)res->persons.size() >= maxContainerCapacity)) {
108 res->persons.insert(person);
116 Reservation* newRes =
new Reservation(
toString(
myReservationCount++), {person}, reservationTime, pickupTime, earliestPickupTime, from, fromPos, fromStop, to, toPos, toStop, group, line);
121#ifdef DEBUG_RESERVATION
123 <<
" addReservation p=" << person->
getID()
126 <<
" from=" << from->
getID() <<
" fromPos=" << fromPos
127 <<
" to=" << to->
getID() <<
" toPos=" << toPos
128 <<
" group=" << group
129 <<
" added=" << added
138 const MSEdge* from,
double fromPos,
139 const MSEdge* to,
double toPos,
144 group = person->
getID();
146 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) {
161 it->second.erase(itRes);
167#ifdef DEBUG_RESERVATION
169 <<
" removeReservation p=" << person->
getID()
170 <<
" from=" << from->
getID() <<
" fromPos=" << fromPos
171 <<
" to=" << to->
getID() <<
" toPos=" << toPos
172 <<
" group=" << group
173 <<
" removedID=" << removedID
182 const MSEdge* from,
double fromPos,
183 const MSEdge* to,
double toPos,
184 std::string group,
double newFromPos) {
188 group = person->
getID();
191 std::string updatedID =
"";
194 for (
auto itRes = it->second.begin(); itRes != it->second.end(); itRes++) {
198 if (res->
persons.count(person) != 0
202 && res->
toPos == toPos) {
211#ifdef DEBUG_RESERVATION
213 <<
" updateReservationFromPos p=" << person->
getID()
214 <<
" from=" << from->
getID() <<
" fromPos=" << fromPos
215 <<
" to=" << to->
getID() <<
" toPos=" << toPos
216 <<
" group=" << group
217 <<
" newFromPos=" << newFromPos
218 <<
" updatedID=" << updatedID
225std::vector<Reservation*>
227 std::vector<Reservation*> reservations;
229 reservations.insert(reservations.end(), it.second.begin(), it.second.end());
235std::vector<const Reservation*>
250 auto it2 = std::find(it->second.begin(), it->second.end(), res);
251 if (it2 == it->second.end()) {
256 it->second.erase(it2);
257 if (it->second.empty()) {
281 const MSEdge* from,
double fromPos,
282 const MSEdge* via,
double viaPos,
283 const MSEdge* to,
double toPos,
285 double& timeDirect) {
287 if (timeDirect < 0) {
288 router.
compute(from, fromPos, to, toPos, &taxi->
getHolder(), t, edges,
true);
293 router.
compute(from, fromPos, via, viaPos, &taxi->
getHolder(), t, edges,
true);
297 std::cout <<
" leg1=" <<
toString(edges) <<
" startPos=" << fromPos <<
" toPos=" << viaPos <<
" time=" << leg1 <<
"\n";
299 const double wait =
MAX2(0.0,
STEPS2TIME(viaTime) - (start + leg1));
302 router.
compute(via, viaPos, to, toPos, &taxi->
getHolder(), timeContinue, edges,
true);
304 const double timeDetour = leg1 + wait + leg2;
306 std::cout <<
" leg2=" <<
toString(edges) <<
" startPos=" << viaPos <<
" toPos=" << toPos <<
" time=" << leg2 <<
"\n";
308 <<
" from=" << from->
getID() <<
" to=" << to->
getID() <<
" via=" << via->
getID()
309 <<
" direct=" << timeDirect <<
" detour=" << timeDetour <<
" wait=" << wait <<
"\n";
317 assert(res->
persons.size() > 0);
318 return ((*res->
persons.begin())->isPerson()
std::vector< const MSEdge * > ConstMSEdgeVector
#define WRITE_WARNINGF(...)
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)
OutputDevice * myOutput
optional file output for dispatch information
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
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;.
void servedReservation(const Reservation *res)
std::set< const Reservation * > myRunningReservations
virtual ~MSDispatch()
Destructor.
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