Skip to content

Commit

Permalink
refactoring to prepare rerouters for persons #12 #1722
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Dec 20, 2023
1 parent 44dd95c commit 4e671d5
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 123 deletions.
9 changes: 2 additions & 7 deletions src/mesosim/MEVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ class MEVehicle : public MSBaseVehicle {


/// @brief Returns the duration for which the vehicle was blocked
inline SUMOTime getWaitingTime() const {
inline SUMOTime getWaitingTime(const bool accumulated=false) const {
UNUSED_PARAMETER(accumulated);
return MAX2(SUMOTime(0), myEventTime - myBlockTime);
}

Expand All @@ -277,12 +278,6 @@ class MEVehicle : public MSBaseVehicle {
return getWaitingTime();
}

/// @brief Returns the duration for which the vehicle was blocked
inline SUMOTime getAccumulatedWaitingTime() const {
return getWaitingTime();
}


/// @brief Returns the earliest leave time for the current segment
double getEventTimeSeconds() const {
return STEPS2TIME(getEventTime());
Expand Down
12 changes: 11 additions & 1 deletion src/microsim/MSBaseVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ MSBaseVehicle::getEdge() const {
}


const std::set<SUMOTrafficObject::NumericalID>
MSBaseVehicle::getUpcomingEdgeIDs() const {
std::set<SUMOTrafficObject::NumericalID> result;
for (auto e = myCurrEdge; e != myRoute->end(); ++e) {
result.insert((*e)->getNumericalID());
}
return result;
}


bool
MSBaseVehicle::stopsAt(MSStoppingPlace* stop) const {
if (stop == nullptr) {
Expand Down Expand Up @@ -924,7 +934,7 @@ MSBaseVehicle::getImpatience() const {
}


MSVehicleDevice*
MSDevice*
MSBaseVehicle::getDevice(const std::type_info& type) const {
for (MSVehicleDevice* const dev : myDevices) {
if (typeid(*dev) == type) {
Expand Down
13 changes: 12 additions & 1 deletion src/microsim/MSBaseVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ class MSBaseVehicle : public SUMOVehicle {
return getEdge();
}

/// @brief returns the numerical ids of edges to travel
const std::set<SUMOTrafficObject::NumericalID> getUpcomingEdgeIDs() const;

/** @brief Returns whether the vehicle stops at the given stopping place */
bool stopsAt(MSStoppingPlace* stop) const;

Expand Down Expand Up @@ -251,6 +254,14 @@ class MSBaseVehicle : public SUMOVehicle {
return myCurrEdge;
}

/** @brief Returns the end point for reroutes (usually the last edge of the route)
*
* @return The rerouting end point
*/
virtual const MSEdge* getRerouteDestination() const {
return myRoute->getLastEdge();
}

/** @brief Returns the time loss in seconds
*/
virtual double getTimeLossSeconds() const {
Expand Down Expand Up @@ -546,7 +557,7 @@ class MSBaseVehicle : public SUMOVehicle {
}

/// @brief Returns a device of the given type if it exists, nullptr otherwise
MSVehicleDevice* getDevice(const std::type_info& type) const;
MSDevice* getDevice(const std::type_info& type) const;


/** @brief Replaces the current vehicle type by the one given
Expand Down
18 changes: 7 additions & 11 deletions src/microsim/MSVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,14 @@ class MSVehicle : public MSBaseVehicle {
*
* The value is reset if the vehicle moves faster than 0.1m/s
* Intentional stopping does not count towards this time.
* If accumulated is true the time is aggregated over a configurable interval.
* @return The time the vehicle is standing
*/
SUMOTime getWaitingTime() const {
return myWaitingTime;
SUMOTime getWaitingTime(const bool accumulated=false) const {
if (!accumulated) {
return myWaitingTime;
}
return myWaitingTimeCollector.cumulatedWaitingTime(MSGlobals::gWaitingTimeMemory);
}

/** @brief Returns the SUMOTime spent driving since startup (speed was larger than 0.1m/s)
Expand Down Expand Up @@ -701,21 +705,13 @@ class MSVehicle : public MSBaseVehicle {
}


/** @brief Returns the SUMOTime waited (speed was lesser than 0.1m/s) within the last t millisecs
*
* @return The time the vehicle was standing within the configured memory interval
*/
SUMOTime getAccumulatedWaitingTime() const {
return myWaitingTimeCollector.cumulatedWaitingTime(MSGlobals::gWaitingTimeMemory);
}

/** @brief Returns the number of seconds waited (speed was lesser than 0.1m/s) within the last millisecs
*
* @return The time the vehicle was standing within the last t millisecs
*/

double getAccumulatedWaitingSeconds() const {
return STEPS2TIME(getAccumulatedWaitingTime());
return STEPS2TIME(getWaitingTime(true));
}

/** @brief Returns the time loss in seconds
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/devices/MSDevice_ElecHybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ MSDevice_ElecHybrid::notifyLeave(
//TODO the second argument of getStoptime should change
std::cout << "getSpeed: '" << v.getSpeed() << "' | getAverageSpeed: '" << v.getAverageSpeed() << "' | getStoptime: '" << v.getStoptime(v.getSegment(), 0) << "' \n";
std::cout << "getStopEdges: '" << "' | getLastEntryTime: '" << v.getLastEntryTime() << "' | getBlockTimeSeconds: '" << v.getBlockTimeSeconds() << "' \n";
std::cout << "getWaitingTime: '" << v.getWaitingTime() << "' | getAccumulatedWaitingTime: '" << v.getAccumulatedWaitingTime() << "' | getLastEntryTimeSeconds: '" << v.getLastEntryTimeSeconds() << "' \n";
std::cout << "getWaitingTime: '" << v.getWaitingTime() << "' | getAccumulatedWaitingTime: '" << v.getWaitingTime(true) << "' | getLastEntryTimeSeconds: '" << v.getLastEntryTimeSeconds() << "' \n";
std::cout << "***************** MESO - notifyLeave*** END ****************** '" << v.getID() << "' \n";
}
#endif
Expand Down
28 changes: 25 additions & 3 deletions src/microsim/transportables/MSTransportable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ MSTransportable::proceed(MSNet* net, SUMOTime time, const bool vehicleArrived) {
/* We need to check whether an access stage is needed (or maybe even two).
The general scheme is: If the prior stage ended at a stop and the next stage
starts at an edge which is not the one the stop is at, but the stop has an access to it
we need an access stage. The same is true if prior ends at an edge, the next stage
we need an access stage. The same is true if prior ends at an edge, the next stage
is allowed to start at any stop the edge has access to.
If we start at a stop or end at a stop no access is needed.
*/
Expand Down Expand Up @@ -309,6 +309,13 @@ MSTransportable::setSpeed(double speed) {
}


bool
MSTransportable::replaceRoute(ConstMSRoutePtr newRoute, const std::string& info, bool onInit, int offset, bool addRouteStops, bool removeStops, std::string* msgReturn) {
const ConstMSEdgeVector& edges = newRoute->getEdges();
return true;
}


void
MSTransportable::replaceVehicleType(MSVehicleType* type) {
const SUMOVehicleClass oldVClass = myVType->getVehicleClass();
Expand Down Expand Up @@ -362,6 +369,18 @@ MSTransportable::getStageSummary(int stageIndex) const {
}


const std::set<SUMOTrafficObject::NumericalID>
MSTransportable::getUpcomingEdgeIDs() const {
std::set<SUMOTrafficObject::NumericalID> result;
for (auto step = myStep; step != myPlan->end(); ++step) {
for (const MSEdge* const e : (*step)->getEdges()) {
result.insert(e->getNumericalID());
}
}
return result;
}


bool
MSTransportable::hasArrived() const {
return myStep == myPlan->end();
Expand Down Expand Up @@ -457,7 +476,7 @@ MSTransportable::rerouteParkingArea(MSStoppingPlace* orig, MSStoppingPlace* repl
}


MSTransportableDevice*
MSDevice*
MSTransportable::getDevice(const std::type_info& type) const {
for (MSTransportableDevice* const dev : myDevices) {
if (typeid(*dev) == type) {
Expand Down Expand Up @@ -488,16 +507,19 @@ MSTransportable::getSlope() const {
return edge->getLanes()[0]->getShape().slopeDegreeAtOffset(gp);
}


SUMOTime
MSTransportable::getWaitingTime() const {
MSTransportable::getWaitingTime(const bool /* accumulated */) const {
return (*myStep)->getWaitingTime(MSNet::getInstance()->getCurrentTimeStep());
}


double
MSTransportable::getMaxSpeed() const {
return MIN2(getVehicleType().getMaxSpeed(), getVehicleType().getDesiredMaxSpeed() * getChosenSpeedFactor());
}


SUMOVehicleClass
MSTransportable::getVClass() const {
return getVehicleType().getVehicleClass();
Expand Down
22 changes: 17 additions & 5 deletions src/microsim/transportables/MSTransportable.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class MSTransportable : public SUMOTrafficObject {
*/
double getMaxSpeed() const;

SUMOTime getWaitingTime() const;
SUMOTime getWaitingTime(const bool accumulated=false) const;

double getPreviousSpeed() const {
return getSpeed();
Expand Down Expand Up @@ -244,6 +244,9 @@ class MSTransportable : public SUMOTrafficObject {
return (*(myStep + next))->getEdges();
}

/// @brief returns the numerical IDs of edges to be used (possibly of future stages)
const std::set<NumericalID> getUpcomingEdgeIDs() const;

/// @brief Return the total number stages in this person's plan
inline int getNumStages() const {
return (int)myPlan->size();
Expand Down Expand Up @@ -322,6 +325,17 @@ class MSTransportable : public SUMOTrafficObject {
return myPlan->back()->getEdges().back();
}

/** @brief Returns the end point for reroutes (usually the last edge of the route)
*
* @return The rerouting end point
*/
const MSEdge* getRerouteDestination() const {
return getArrivalEdge();
}

/// Replaces the current route by the given one
bool replaceRoute(ConstMSRoutePtr route, const std::string& info, bool onInit = false, int offset = 0, bool addStops = true, bool removeStops = true, std::string* msgReturn = nullptr);

/** @brief Replaces the current vehicle type by the one given
*
* If the currently used vehicle type is marked as being used by this vehicle
Expand All @@ -332,7 +346,6 @@ class MSTransportable : public SUMOTrafficObject {
*/
void replaceVehicleType(MSVehicleType* type);


/** @brief Replaces the current vehicle type with a new one used by this vehicle only
*
* If the currently used vehicle type is already marked as being used by this vehicle
Expand All @@ -342,7 +355,6 @@ class MSTransportable : public SUMOTrafficObject {
*/
MSVehicleType& getSingularType();


/// @brief return the bounding box of the person
PositionVector getBoundingBox() const;

Expand All @@ -355,8 +367,8 @@ class MSTransportable : public SUMOTrafficObject {
/// @brief adapt plan when the vehicle reroutes and now stops at replacement instead of orig
void rerouteParkingArea(MSStoppingPlace* orig, MSStoppingPlace* replacement);

/// @brief Returns a device of the given type if it exists or 0
MSTransportableDevice* getDevice(const std::type_info& type) const;
/// @brief Returns a device of the given type if it exists or nullptr if not
MSDevice* getDevice(const std::type_info& type) const;

/// @brief set individual junction model paramete (not type related)
void setJunctionModelParameter(const std::string& key, const std::string& value);
Expand Down

0 comments on commit 4e671d5

Please sign in to comment.