Skip to content

Commit

Permalink
refactoring refs #12
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Apr 15, 2024
1 parent c25abe8 commit c1f228d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/microsim/MSVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6026,10 +6026,7 @@ MSVehicle::updateBestLanes(bool forceRebuild, const MSLane* startLane) {
for (const LaneQ& m : nextLanes) {
if ((m.lane->allowsVehicleClass(getVClass()) || m.lane->hadPermissionChanges())
&& m.lane->isApproachedFrom(cE, j.lane)) {
if (bestConnectedNext == nullptr || ((bestConnectedNext->length < m.length
|| (bestConnectedNext->length == m.length && abs(bestConnectedNext->bestLaneOffset) > abs(m.bestLaneOffset))
|| (bestConnectedNext->lane->getBidiLane() != nullptr && m.lane->getBidiLane() == nullptr))
&& (m.lane->getBidiLane() == nullptr || bestConnectedNext->lane->getBidiLane() != nullptr))) {
if (betterContinuation(bestConnectedNext, m)) {
bestConnectedNext = &m;
}
}
Expand Down Expand Up @@ -6173,6 +6170,23 @@ MSVehicle::updateBestLanes(bool forceRebuild, const MSLane* startLane) {
}


bool
MSVehicle::betterContinuation(const LaneQ* bestConnectedNext, const LaneQ& m) {
if (bestConnectedNext == nullptr) {
return true;
} else if (m.lane->getBidiLane() != nullptr && bestConnectedNext->lane->getBidiLane() == nullptr) {
return false;
} else if (bestConnectedNext->lane->getBidiLane() != nullptr && m.lane->getBidiLane() == nullptr) {
return true;
} else if (bestConnectedNext->length < m.length) {
return true;
} else if (bestConnectedNext->length == m.length && abs(bestConnectedNext->bestLaneOffset) > abs(m.bestLaneOffset)) {
return true;
}
return false;
}


int
MSVehicle::nextLinkPriority(const std::vector<MSLane*>& conts) {
if (conts.size() < 2) {
Expand Down
3 changes: 3 additions & 0 deletions src/microsim/MSVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,9 @@ class MSVehicle : public MSBaseVehicle {
/// @brief remove vehicle from further lanes (on leaving the network)
void cleanupFurtherLanes();

/// @brief comparison between different continuations from the same lane
static bool betterContinuation(const LaneQ* bestConnectedNext, const LaneQ& m);

private:
/// @brief The per vehicle variables of the car following model
MSCFModel::VehicleVariables* myCFVariables;
Expand Down

0 comments on commit c1f228d

Please sign in to comment.