Skip to content

Commit

Permalink
refactoring stage function #12
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Jan 16, 2024
1 parent 3cd8add commit d91e667
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/libsumo/Person.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ Person::getEdges(const std::string& personID, int nextStageIndex) {
throw TraCIException("The negative stage index must refer to a valid previous stage.");
}
std::vector<std::string> edgeIDs;
for (auto& e : p->getEdges(nextStageIndex)) {
for (auto& e : p->getNextStage(nextStageIndex)->getEdges()) {
if (e != nullptr) {
edgeIDs.push_back(e->getID());
}
Expand Down Expand Up @@ -788,7 +788,7 @@ Person::rerouteTraveltime(const std::string& personID) {
if (newEdges.empty()) {
throw TraCIException("Could not find new route for person '" + personID + "'.");
}
ConstMSEdgeVector oldEdges = p->getEdges(firstIndex);
ConstMSEdgeVector oldEdges = p->getNextStage(firstIndex)->getEdges();
assert(!oldEdges.empty());
if (oldEdges.front()->getFunction() != SumoXMLEdgeFunc::NORMAL) {
oldEdges.erase(oldEdges.begin());
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/output/MSDetectorFileOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ MSDetectorFileOutput::vehicleApplies(const SUMOTrafficObject& veh) const {
end = v.getRoute().end();
} else if (veh.isPerson()) {
const MSTransportable& p = dynamic_cast<const MSTransportable&>(veh);
route = p.getEdges(0);
route = p.getCurrentStage()->getEdges();
it = route.begin() + p.getRoutePosition();
end = route.end();
}
Expand Down
17 changes: 5 additions & 12 deletions src/microsim/transportables/MSTransportable.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,11 @@ class MSTransportable : public SUMOTrafficObject {
return *myStep;
}

/// @brief Return the current stage
MSStage* getNextStage(int next) const {
assert(myStep + next >= myPlan->begin());
assert(myStep + next < myPlan->end());
return *(myStep + next);
}

/// @brief Return the edges of the nth next stage
ConstMSEdgeVector getEdges(int next) const {
assert(myStep + next < myPlan->end());
assert(myStep + next >= myPlan->begin());
return (*(myStep + next))->getEdges();
/// @brief Return the next (or previous) stage denoted by the offset
inline MSStage* getNextStage(int offset) const {
assert(myStep + offset >= myPlan->begin());
assert(myStep + offset < myPlan->end());
return *(myStep + offset);
}

/// @brief returns the numerical IDs of edges to be used (possibly of future stages)
Expand Down

0 comments on commit d91e667

Please sign in to comment.