diff --git a/data/xsd/state_file.xsd b/data/xsd/state_file.xsd index 16bc3005b57..6d8b359fe24 100644 --- a/data/xsd/state_file.xsd +++ b/data/xsd/state_file.xsd @@ -238,7 +238,7 @@ - + diff --git a/src/microsim/traffic_lights/MSDriveWay.cpp b/src/microsim/traffic_lights/MSDriveWay.cpp index c432bfa7a35..726beb33b5a 100644 --- a/src/microsim/traffic_lights/MSDriveWay.cpp +++ b/src/microsim/traffic_lights/MSDriveWay.cpp @@ -45,9 +45,6 @@ //#define SUBDRIVEWAY_WARN_NOCONFLICT //#define DEBUG_BUILD_DRIVEWAY -//#define DEBUG_BUILD_SUBDRIVEWAY -//#define DEBUG_ADD_FOES -//#define DEBUG_BUILD_SIDINGS //#define DEBUG_DRIVEWAY_BUILDROUTE //#define DEBUG_CHECK_FLANKS //#define DEBUG_SIGNALSTATE_PRIORITY @@ -102,6 +99,8 @@ MSDriveWay::MSDriveWay(const MSLink* origin, const std::string& id, bool tempora myFoundSignal(false), myFoundJump(false), myTerminateRoute(false), + myAbortedBuild(false), + myBidiEnded(false), myIsSubDriveway(false) {} @@ -845,7 +844,11 @@ MSDriveWay::buildRoute(const MSLink* origin, double length, " exceeds maximum length (stopped searching after edge '" + toLane->getEdge().getID() + "' (length=" + toString(length) + "m)."); } myNumWarnings++; + myAbortedBuild = true; // length exceeded +#ifdef DEBUG_DRIVEWAY_BUILDROUTE + if (gDebugFlag4) std::cout << " abort: length=" << length << "\n"; +#endif return; } #ifdef DEBUG_DRIVEWAY_BUILDROUTE @@ -934,6 +937,10 @@ MSDriveWay::buildRoute(const MSLink* origin, double length, if (link == origin) { WRITE_WARNINGF(TL("Found circular block after % (% edges, length %)"), warnID, toString(myRoute.size()), toString(length)); //std::cout << getClickableTLLinkID(origin) << " circularBlock2=" << toString(myRoute) << "\n"; + myAbortedBuild = true; +#ifdef DEBUG_DRIVEWAY_BUILDROUTE + if (gDebugFlag4) std::cout << " abort: found circle\n"; +#endif return; } seekForwardSignal = false; @@ -981,6 +988,10 @@ MSDriveWay::buildRoute(const MSLink* origin, double length, } } } + myBidiEnded = !seekBidiSwitch; +#ifdef DEBUG_DRIVEWAY_BUILDROUTE + if (gDebugFlag4) std::cout << " normalEnd myBidiEnded=" << myBidiEnded << "\n"; +#endif } @@ -1379,7 +1390,7 @@ MSDriveWay::match(MSRouteIterator firstIt, MSRouteIterator endIt) const { // if the vehicle arrives before the end of this driveway, // we'd rather build a new driveway to avoid superfluous restrictions if (match && itDwRoute == myRoute.end() - && (itRoute == endIt || myFoundSignal || myFoundJump || myIsSubDriveway)) { + && (itRoute == endIt || myAbortedBuild || myBidiEnded || myFoundJump || myIsSubDriveway)) { //std::cout << " using dw=" << "\n"; if (itRoute != endIt) { // check whether the current route requires an extended driveway @@ -1722,7 +1733,7 @@ MSDriveWay::addSidings(MSDriveWay* foe, bool addToFoe) { auto itFind = std::find(foeSearchBeg, foeSearchEnd, cur->getBidiEdge()); if (itFind != foeSearchEnd) { #ifdef DEBUG_BUILD_SIDINGS - std::cout << "endSiding " << getID() << " foe=" << foe->getID() << " i=" << i << " curBidi=" << Named::getIDSecure(cur->getBidiEdge()) << " length=" << length << "\n"; + std::cout << "endSiding " << getID() << " foe=" << foe->getID() << " i=" << i << " curBidi=" << Named::getIDSecure(cur->getBidiEdge()) << " length=" << toString(length) << "\n"; #endif const int firstIndex = i + 1; if (addToFoe) { @@ -1876,15 +1887,28 @@ MSDriveWay::saveState(OutputDevice& out) { void MSDriveWay::_saveState(OutputDevice& out) const { - if (!myTrains.empty()) { + if (!myTrains.empty() || haveSubTrains()) { out.openTag(myIsSubDriveway ? SUMO_TAG_SUBDRIVEWAY : SUMO_TAG_DRIVEWAY); out.writeAttr(SUMO_ATTR_ID, getID()); out.writeAttr(SUMO_ATTR_EDGES, toString(myRoute)); - out.writeAttr(SUMO_ATTR_VEHICLES, toString(myTrains)); + if (!myTrains.empty()) { + out.writeAttr(SUMO_ATTR_VEHICLES, toString(myTrains)); + } out.closeTag(); } } + +bool +MSDriveWay::haveSubTrains() const { + for (MSDriveWay* sub : mySubDriveWays) { + if (!sub->myTrains.empty()) { + return true; + } + } + return false; +} + void MSDriveWay::loadState(const SUMOSAXAttributes& attrs, int tag) { if ((int)myDriveWayRouteLookup.size() < myGlobalDriveWayIndex) { @@ -1906,6 +1930,8 @@ MSDriveWay::loadState(const SUMOSAXAttributes& attrs, int tag) { if (tag == SUMO_TAG_DRIVEWAY) { auto it = myDriveWayRouteLookup.find(route); if (it == myDriveWayRouteLookup.end()) { + //WRITE_WARNING(TLF("Unknown driveWay '%' with route '%'", id, edges)); + //return; throw ProcessError(TLF("Unknown driveWay '%' with route '%'", id, edges)); } dw = it->second; @@ -1914,6 +1940,8 @@ MSDriveWay::loadState(const SUMOSAXAttributes& attrs, int tag) { std::string parentID = id.substr(0, id.rfind('.')); auto it = myDriveWayLookup.find(parentID); if (it == myDriveWayLookup.end()) { + //WRITE_WARNING(TLF("Unknown parent driveway '%' for subDriveWay '%'", parentID, id)); + //return; throw ProcessError(TLF("Unknown parent driveway '%' for subDriveWay '%'", parentID, id)); } MSDriveWay* parent = it->second; @@ -1929,7 +1957,7 @@ MSDriveWay::loadState(const SUMOSAXAttributes& attrs, int tag) { return; } } - const std::string vehicles = attrs.get(SUMO_ATTR_VEHICLES, id.c_str(), ok); + const std::string vehicles = attrs.getOpt(SUMO_ATTR_VEHICLES, id.c_str(), ok, ""); for (const std::string& vehID : StringTokenizer(vehicles).getVector()) { MSBaseVehicle* veh = dynamic_cast(c.getVehicle(vehID)); if (veh == nullptr) { diff --git a/src/microsim/traffic_lights/MSDriveWay.h b/src/microsim/traffic_lights/MSDriveWay.h index 595996df198..b8fe937e239 100644 --- a/src/microsim/traffic_lights/MSDriveWay.h +++ b/src/microsim/traffic_lights/MSDriveWay.h @@ -204,6 +204,10 @@ class MSDriveWay : public MSMoveReminder, public Named { bool myFoundSignal; bool myFoundJump; bool myTerminateRoute; + /// @brief whether driveway building was aborted due to MAX_BLOCK_LENGTH + bool myAbortedBuild; + /// @brief whether driveway building was aborted when no further bidi edge was found + bool myBidiEnded; bool myIsSubDriveway; /* @brief the actual driveway part up to the next railsignal (halting position) @@ -296,6 +300,8 @@ class MSDriveWay : public MSMoveReminder, public Named { void addSwitchFoes(MSLink* link); + bool haveSubTrains() const; + static bool hasJoin(const SUMOVehicle* ego, const SUMOVehicle* foe); static bool isSwitch(const MSLink* link); diff --git a/tests/complex/state/rail/save_on_rail_signal/state.complex b/tests/complex/state/rail/save_on_rail_signal/state.complex index 3af4d088bd2..e40609c28ef 100644 --- a/tests/complex/state/rail/save_on_rail_signal/state.complex +++ b/tests/complex/state/rail/save_on_rail_signal/state.complex @@ -26,6 +26,7 @@ --> + diff --git a/tests/complex/state/rail/save_rail_signal2/output.complex b/tests/complex/state/rail/save_rail_signal2/output.complex index 3e975365c10..5510c74ee1c 100644 --- a/tests/complex/state/rail/save_rail_signal2/output.complex +++ b/tests/complex/state/rail/save_rail_signal2/output.complex @@ -1,13 +1,18 @@ Loading net-file from 'net.net.xml' ... done (5ms). Loading done. + Simulation version v1_21_0+0063-40d747df57b started with time: 0.00. Simulation ended at time: 54.00. + Reason: All vehicles have left the simulation. Loading net-file from 'net.net.xml' ... done (6ms). Loading state from 'state.xml' ... done (40ms). Loading done. + +Simulation version v1_20_0+0703-550959f676a started with time: 20.00. + Simulation version v1_21_0+0063-40d747df57b started with time: 20.00. -Simulation ended at time: 54.00. + Reason: All vehicles have left the simulation. < > diff --git a/tests/complex/state/rail/save_rail_signal2/railsignalblocks.complex b/tests/complex/state/rail/save_rail_signal2/railsignalblocks.complex index d75a3e7f0f2..ff045d6d661 100644 --- a/tests/complex/state/rail/save_rail_signal2/railsignalblocks.complex +++ b/tests/complex/state/rail/save_rail_signal2/railsignalblocks.complex @@ -3,6 +3,7 @@ + + @@ -55,4 +58,6 @@ + + diff --git a/tests/complex/state/rail/save_rail_signal_constraint/output.complex b/tests/complex/state/rail/save_rail_signal_constraint/output.complex index 193d48ecd7d..0da3a7538de 100644 --- a/tests/complex/state/rail/save_rail_signal_constraint/output.complex +++ b/tests/complex/state/rail/save_rail_signal_constraint/output.complex @@ -1,19 +1,21 @@ Loading net-file from 'net.net.xml' ... done (0ms). -Loading additional-files from 'input_additional.add.xml' ... done (11ms). -Loading additional-files from 'input_additional2.add.xml' ... done (10ms). + +Loading additional-files from 'input_additional.add.xml' ... done (5ms). +Loading additional-files from 'input_additional2.add.xml' ... done (5ms). Loading done. -Simulation version v1_21_0+0063-40d747df57b started with time: 0.00. -Simulation ended at time: 269.00. +Simulation version v1_20_0+0703-550959f676a started with time: 0.00. +Simulation ended at time: 269.00 Reason: All vehicles have left the simulation. -DijkstraRouter answered 8 queries and explored 1.88 edges on average. +DijkstraRouter answered 7 queries and explored 2.00 edges on average. DijkstraRouter spent 0.00s answering queries (0.00ms on average). Loading net-file from 'net.net.xml' ... done (0ms). -Loading additional-files from 'input_additional.add.xml' ... done (16ms). -Loading additional-files from 'input_additional2.add.xml' ... done (11ms). -Loading state from 'state.xml' ... done (13ms). +Loading additional-files from 'input_additional.add.xml' ... done (7ms). +Loading additional-files from 'input_additional2.add.xml' ... done (6ms). +Loading state from 'state.xml' ... done (6ms). Loading done. -Simulation version v1_21_0+0063-40d747df57b started with time: 60.00. -Simulation ended at time: 269.00. +Simulation version v1_20_0+0703-550959f676a started with time: 60.00. +Simulation ended at time: 269.00 + Reason: All vehicles have left the simulation. DijkstraRouter answered 2 queries and explored 2.00 edges on average. DijkstraRouter spent 0.00s answering queries (0.00ms on average). diff --git a/tests/complex/state/rail/save_rail_signal_constraint/state.complex b/tests/complex/state/rail/save_rail_signal_constraint/state.complex index 1e57e40fcc8..fff511f744e 100644 --- a/tests/complex/state/rail/save_rail_signal_constraint/state.complex +++ b/tests/complex/state/rail/save_rail_signal_constraint/state.complex @@ -1,8 +1,10 @@ + + diff --git a/tests/complex/state/rail/save_rail_signal_constraint/state2.complex b/tests/complex/state/rail/save_rail_signal_constraint/state2.complex index 54af4e7e651..776a627ddff 100644 --- a/tests/complex/state/rail/save_rail_signal_constraint/state2.complex +++ b/tests/complex/state/rail/save_rail_signal_constraint/state2.complex @@ -1,8 +1,10 @@ + + + diff --git a/tests/complex/state/rail/save_rail_signal_constraint_include/output.complex b/tests/complex/state/rail/save_rail_signal_constraint_include/output.complex index f0abd5b115c..d2df338d828 100644 --- a/tests/complex/state/rail/save_rail_signal_constraint_include/output.complex +++ b/tests/complex/state/rail/save_rail_signal_constraint_include/output.complex @@ -1,18 +1,20 @@ -Loading net-file from 'net.net.xml' ... done (0ms). -Loading additional-files from 'input_additional.add.xml' ... done (9ms). -Loading additional-files from 'input_additional2.add.xml' ... done (27ms). + +Loading net-file from 'net.net.xml' ... done (1ms). +Loading additional-files from 'input_additional.add.xml' ... done (6ms). +Loading additional-files from 'input_additional2.add.xml' ... done (5ms). Loading done. -Simulation version v1_21_0+0063-40d747df57b started with time: 0.00. -Simulation ended at time: 269.00. +Simulation version v1_20_0+0703-550959f676a started with time: 0.00. +Simulation ended at time: 269.00 Reason: All vehicles have left the simulation. -DijkstraRouter answered 8 queries and explored 1.88 edges on average. +DijkstraRouter answered 7 queries and explored 2.00 edges on average. DijkstraRouter spent 0.00s answering queries (0.00ms on average). Loading net-file from 'net.net.xml' ... done (0ms). -Loading additional-files from 'input_additional.add.xml' ... done (12ms). -Loading state from 'state.xml' ... done (11ms). +Loading additional-files from 'input_additional.add.xml' ... done (9ms). +Loading state from 'state.xml' ... done (6ms). Loading done. -Simulation version v1_21_0+0063-40d747df57b started with time: 60.00. -Simulation ended at time: 269.00. +Simulation version v1_20_0+0703-550959f676a started with time: 60.00. +Simulation ended at time: 269.00 + Reason: All vehicles have left the simulation. DijkstraRouter answered 2 queries and explored 2.00 edges on average. DijkstraRouter spent 0.00s answering queries (0.00ms on average). diff --git a/tests/complex/state/rail/save_rail_signal_constraint_include/state.complex b/tests/complex/state/rail/save_rail_signal_constraint_include/state.complex index 14c7f5876ec..83c2f042409 100644 --- a/tests/complex/state/rail/save_rail_signal_constraint_include/state.complex +++ b/tests/complex/state/rail/save_rail_signal_constraint_include/state.complex @@ -1,8 +1,10 @@ + + + diff --git a/tests/sumo/rail/rail_signal/driveWayShort_badMatch/railsignalblocks.sumo b/tests/sumo/rail/rail_signal/driveWayShort_badMatch/railsignalblocks.sumo index 3044d0d185e..d4147cfcd0b 100644 --- a/tests/sumo/rail/rail_signal/driveWayShort_badMatch/railsignalblocks.sumo +++ b/tests/sumo/rail/rail_signal/driveWayShort_badMatch/railsignalblocks.sumo @@ -1,6 +1,6 @@ -