32 #define DEBUG_COND2(obj) (true)
51 myReservationCount(0) {
52 const std::string opt =
"device.taxi.dispatch-algorithm.output";
64 const MSEdge* from,
double fromPos,
65 const MSEdge* to,
double toPos,
67 const std::string& line,
69 int maxContainerCapacity) {
74 group = person->
getID();
82 if (res->
persons.count(person) == 0
86 && res->
toPos == toPos) {
88 WRITE_WARNINGF(
"Mixing reservations of persons and containers with the same group is not supported for % and %",
92 (!person->
isPerson() && (
int)res->
persons.size() >= maxContainerCapacity)) {
109 #ifdef DEBUG_RESERVATION
111 <<
" addReservation p=" << person->
getID()
114 <<
" from=" << from->
getID() <<
" fromPos=" << fromPos
115 <<
" to=" << to->
getID() <<
" toPos=" << toPos
116 <<
" group=" << group
117 <<
" added=" << added
126 const MSEdge* from,
double fromPos,
127 const MSEdge* to,
double toPos,
132 group = person->
getID();
134 std::string removedID =
"";
138 for (
auto itRes = it->second.begin(); itRes != it->second.end(); itRes++) {
140 if (res->
persons.count(person) != 0
144 && res->
toPos == toPos) {
149 it->second.erase(itRes);
155 #ifdef DEBUG_RESERVATION
157 <<
" removeReservation p=" << person->
getID()
158 <<
" from=" << from->
getID() <<
" fromPos=" << fromPos
159 <<
" to=" << to->
getID() <<
" toPos=" << toPos
160 <<
" group=" << group
161 <<
" removedID=" << removedID
168 std::vector<Reservation*>
170 std::vector<Reservation*> reservations;
172 reservations.insert(reservations.end(), it.second.begin(), it.second.end());
178 std::vector<const Reservation*>
193 auto it2 = std::find(it->second.begin(), it->second.end(), res);
194 if (it2 == it->second.end()) {
195 throw ProcessError(
"Inconsistent group reservations (2).");
199 it->second.erase(it2);
200 if (it->second.empty()) {
224 const MSEdge* from,
double fromPos,
225 const MSEdge* via,
double viaPos,
226 const MSEdge* to,
double toPos,
228 double& timeDirect) {
230 if (timeDirect < 0) {
231 router.
compute(from, fromPos, to, toPos, &taxi->
getHolder(), t, edges,
true);
236 router.
compute(from, fromPos, via, viaPos, &taxi->
getHolder(), t, edges,
true);
240 std::cout <<
" leg1=" <<
toString(edges) <<
" startPos=" << fromPos <<
" toPos=" << viaPos <<
" time=" << leg1 <<
"\n";
242 const double wait =
MAX2(0.0,
STEPS2TIME(viaTime) - (start + leg1));
245 router.
compute(via, viaPos, to, toPos, &taxi->
getHolder(), timeContinue, edges,
true);
247 const double timeDetour = leg1 + wait + leg2;
249 std::cout <<
" leg2=" <<
toString(edges) <<
" startPos=" << viaPos <<
" toPos=" << toPos <<
" time=" << leg2 <<
"\n";
251 <<
" from=" << from->
getID() <<
" to=" << to->
getID() <<
" via=" << via->
getID()
252 <<
" direct=" << timeDirect <<
" detour=" << timeDetour <<
" wait=" << wait <<
"\n";
260 assert(res->
persons.size() > 0);
261 return ((*res->
persons.begin())->isPerson()
std::vector< const MSEdge * > ConstMSEdgeVector
#define WRITE_WARNINGF(...)
std::string time2string(SUMOTime t)
convert SUMOTime to string
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 it's id
bool myHasServableReservations
whether the last call to computeDispatch has left servable reservations
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, const MSEdge *from, double fromPos, const MSEdge *to, double toPos, std::string group, const std::string &line, int maxCapacity, int maxContainerCapacity)
add a new reservation
MSDispatch(const std::map< std::string, std::string > ¶ms)
Constructor;.
virtual void fulfilledReservation(const Reservation *res)
erase reservation from storage
void servedReservation(const Reservation *res)
std::set< const Reservation * > myRunningReservations
A road/street connecting two junctions.
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.
double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
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 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< MSTransportable * > persons