Skip to content

Commit

Permalink
preparing driveway check during reservation. refs #7578
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Jun 21, 2024
1 parent 68dd0dd commit f53b889
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
61 changes: 60 additions & 1 deletion src/microsim/traffic_lights/MSDriveWay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
//#define DEBUG_SIGNALSTATE_PRIORITY
//#define DEBUG_FIND_PROTECTION
//#define DEBUG_ADD_FOES
//#define DEBUG_SIGNALSTATE

#define DEBUG_COND DEBUG_HELPER(this)
//#define DEBUG_HELPER(obj) ((obj)->isSelected())
Expand Down Expand Up @@ -85,8 +86,8 @@ MSDriveWay::init() {

MSDriveWay::MSDriveWay(const std::string& id, bool temporary) :
MSMoveReminder("DriveWay_" + (temporary ? "tmp" : toString(myGlobalDriveWayIndex))),
Named(id),
myNumericalID(temporary ? -1 : myGlobalDriveWayIndex++),
myID(id),
myMaxFlankLength(0),
myActive(nullptr),
myProtectedBidi(nullptr),
Expand Down Expand Up @@ -391,6 +392,64 @@ MSDriveWay::conflictLaneOccupied(const std::string& joinVehicle, bool store, con
return false;
}


bool
MSDriveWay::foeDriveWayOccupied(const std::string& joinVehicle, bool store, const SUMOVehicle* ego) const {
for (const MSDriveWay* foeDW : myFoes) {
if (!foeDW->myTrains.empty()) {
#ifdef DEBUG_SIGNALSTATE
if (gDebugFlag4) {
std::cout << SIMTIME << " foeDriveWay " << foeDW->getID() << " occupied ego=" << Named::getIDSecure(ego) << " foeVeh=" << toString(foeDW->myTrains) << "\n";
if (joinVehicle != "") {
std::cout << " joinVehicle=" << joinVehicle << "\n";
}
}
#endif
if (foeDW->myTrains.size() == 1) {
SUMOVehicle* foe = *foeDW->myTrains.begin();
if (joinVehicle != "") {
if (foe->getID() == joinVehicle && foe->isStopped()) {
#ifdef DEBUG_SIGNALSTATE
if (gDebugFlag4) {
std::cout << " ignore join-target '" << joinVehicle << "\n";
}
#endif
continue;
}
}
if (ego != nullptr) {
/*
if (foe == ego && std::find(myBidi.begin(), myBidi.end(), lane) != myBidi.end()) {
#ifdef DEBUG_SIGNALSTATE
if (gDebugFlag4) {
std::cout << " ignore ego as oncoming '" << ego->getID() << "\n";
}
#endif
continue;
}
*/
if (foe->isStopped() && foe->getNextStopParameter()->join == ego->getID()) {
#ifdef DEBUG_SIGNALSTATE
if (gDebugFlag4) {
std::cout << " ignore " << foe->getID() << " for which ego is join-target\n";
}
#endif
continue;
}
}
}
if (MSRailSignal::storeVehicles() && store) {
for (SUMOVehicle* foe : foeDW->myTrains) {
MSRailSignal::blockingVehicles().push_back(foe);
}
}
return true;
}
}
return false;
}


bool
MSDriveWay::deadlockLaneOccupied(bool store) const {
for (const MSLane* lane : myBidiExtended) {
Expand Down
8 changes: 4 additions & 4 deletions src/microsim/traffic_lights/MSDriveWay.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MSLink;
/**
* @class MSDriveWay
*/
class MSDriveWay : public MSMoveReminder {
class MSDriveWay : public MSMoveReminder, public Named {
public:
typedef std::pair<const SUMOVehicle* const, const MSLink::ApproachingVehicleInformation> Approaching;
typedef std::set<const MSLane*, ComparatorNumericalIdLess> LaneSet;
Expand Down Expand Up @@ -65,6 +65,9 @@ class MSDriveWay : public MSMoveReminder {
/// @brief whether any of myConflictLanes is occupied (vehicles that are the target of a join must be ignored)
bool conflictLaneOccupied(const std::string& joinVehicle = "", bool store = true, const SUMOVehicle* ego = nullptr) const;

/// @brief whether any of myFoes is occupied (vehicles that are the target of a join must be ignored)
bool foeDriveWayOccupied(const std::string& joinVehicle, bool store, const SUMOVehicle* ego) const;

/// @brief Whether any of the conflict links have approaching vehicles
bool conflictLinkApproached() const;

Expand Down Expand Up @@ -121,9 +124,6 @@ class MSDriveWay : public MSMoveReminder {
/// @brief global driveway index
int myNumericalID;

/// @brief driveway name
std::string myID;

/// @brief the maximum flank length searched while building this driveway
double myMaxFlankLength;

Expand Down
3 changes: 3 additions & 0 deletions src/utils/vehicle/SUMOVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ class SUMOVehicle : public SUMOTrafficObject {
/// @brief Returns the remaining stop duration for a stopped vehicle or 0
virtual SUMOTime remainingStopDuration() const = 0;

/** @brief Returns whether the vehicle is at a stop and waiting for a person or container to continue
*/
virtual bool isStopped() const = 0;
/** @brief Returns whether the vehicle is at a stop and waiting for a person or container to continue
*/
virtual bool isStoppedTriggered() const = 0;
Expand Down

0 comments on commit f53b889

Please sign in to comment.