Skip to content

Commit

Permalink
fix #14205
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Apr 12, 2024
1 parent 59b2744 commit 727e6c2
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/libsumo/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ Simulation::findRoute(const std::string& from, const std::string& to, const std:
if (toEdge == nullptr) {
throw TraCIException("Unknown to edge '" + to + "'.");
}
SUMOVehicle* vehicle = nullptr;
MSBaseVehicle* vehicle = nullptr;
MSVehicleType* type = MSNet::getInstance()->getVehicleControl().getVType(typeID == "" ? DEFAULT_VTYPE_ID : typeID);
if (type == nullptr) {
throw TraCIException("The vehicle type '" + typeID + "' is not known.");
Expand All @@ -579,14 +579,15 @@ Simulation::findRoute(const std::string& from, const std::string& to, const std:
pars->id = "simulation.findRoute";
try {
ConstMSRoutePtr const routeDummy = std::make_shared<MSRoute>("", ConstMSEdgeVector({ fromEdge }), false, nullptr, std::vector<SUMOVehicleParameter::Stop>());
vehicle = MSNet::getInstance()->getVehicleControl().buildVehicle(pars, routeDummy, type, false);
vehicle = dynamic_cast<MSBaseVehicle*>(MSNet::getInstance()->getVehicleControl().buildVehicle(pars, routeDummy, type, false));
std::string msg;
if (!vehicle->hasValidRouteStart(msg)) {
MSNet::getInstance()->getVehicleControl().deleteVehicle(vehicle, true);
throw TraCIException("Invalid departure edge for vehicle type '" + type->getID() + "' (" + msg + ")");
}
// we need to fix the speed factor here for deterministic results
vehicle->setChosenSpeedFactor(type->getSpeedFactor().getParameter()[0]);
vehicle->getBaseInfluencer().setRoutingMode(routingMode);
} catch (ProcessError& e) {
throw TraCIException("Invalid departure edge for vehicle type '" + type->getID() + "' (" + e.what() + ")");
}
Expand Down
14 changes: 14 additions & 0 deletions src/microsim/MSBaseVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,20 @@ MSBaseVehicle::sawBlockedParkingArea(const MSParkingArea* pa, bool local) const
}
}


int
MSBaseVehicle::getRoutingMode() const {
// @note: move myRoutingMode into MSBaseVehicle when allowing to set
// routingMode via xml input (to avoid having an
// influencer in a non-traci simulation)
if (hasInfluencer()) {
return getBaseInfluencer()->getRoutingMode();
} else {
return libsumo::ROUTING_MODE_DEFAULT;
}
}


#ifdef _DEBUG
void
MSBaseVehicle::initMoveReminderOutput(const OptionsCont& oc) {
Expand Down
2 changes: 2 additions & 0 deletions src/microsim/MSBaseVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,8 @@ class MSBaseVehicle : public SUMOVehicle {

virtual bool hasInfluencer() const = 0;

/// @brief return routing mode (configures router choice but also handling of transient permission changes)
int getRoutingMode() const;

/** @brief Returns the vehicle's internal edge travel times/efforts container
*
Expand Down
5 changes: 4 additions & 1 deletion src/microsim/MSEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ MSEdge::rebuildAllowedLanes(const bool onInit) {
}
}
}
if (!onInit) {
if (onInit) {
myOriginalMinimumPermissions = myMinimumPermissions;
myOriginalCombinedPermissions = myCombinedPermissions;
} else {
rebuildAllowedTargets(false);
for (MSEdge* pred : myPredecessors) {
pred->rebuildAllowedTargets(false);
Expand Down
10 changes: 9 additions & 1 deletion src/microsim/MSEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <utils/router/RailEdge.h>
#include <utils/vehicle/SUMOVehicle.h>
#include <utils/vehicle/SUMOTrafficObject.h>
#include <libsumo/TraCIConstants.h>
#include "MSNet.h"


Expand Down Expand Up @@ -606,7 +607,9 @@ class MSEdge : public Named, public Parameterised {
return false;
}
const SUMOVehicleClass svc = vehicle->getVClass();
return (myCombinedPermissions & svc) != svc;
return ((vehicle->getRoutingMode() & libsumo::ROUTING_MODE_IGNORE_TRANSIENT_PERMISSIONS)
? (myOriginalCombinedPermissions & svc) != svc
: (myCombinedPermissions & svc) != svc);
}

/** @brief Returns whether this edge has restriction parameters forbidding the given vehicle to pass it
Expand Down Expand Up @@ -923,6 +926,11 @@ class MSEdge : public Named, public Parameterised {
SVCPermissions myMinimumPermissions = SVCAll;
/// @brief The union of lane permissions for this edge
SVCPermissions myCombinedPermissions = 0;

/// @brief The original intersection of lane permissions for this edge (before temporary modifications)
SVCPermissions myOriginalMinimumPermissions = SVCAll;
/// @brief The original union of lane permissions for this edge (before temporary modifications)
SVCPermissions myOriginalCombinedPermissions;
/// @}

/// @brief the other taz-connector if this edge isTazConnector, otherwise nullptr
Expand Down
6 changes: 6 additions & 0 deletions src/microsim/transportables/MSTransportable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,12 @@ MSTransportable::getVClass() const {
}


int
MSTransportable::getRoutingMode() const {
/// @todo: allow configuring routing mode
return libsumo::ROUTING_MODE_DEFAULT;
}

void
MSTransportable::saveState(OutputDevice& out) {
// this saves lots of departParameters which are only needed for transportables that did not yet depart
Expand Down
3 changes: 3 additions & 0 deletions src/microsim/transportables/MSTransportable.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ class MSTransportable : public SUMOTrafficObject {
return false;
}

/// @brief return routing mode (configures router choice but also handling of transient permission changes)
virtual int getRoutingMode() const;

/** @brief Saves the current state into the given stream
*/
void saveState(OutputDevice& out);
Expand Down
2 changes: 2 additions & 0 deletions src/utils/vehicle/SUMOTrafficObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class SUMOTrafficObject : public Named {
*/
virtual SUMOVehicleClass getVClass() const = 0;

virtual int getRoutingMode() const = 0;

/** @brief Returns the object's maximum speed (minimum of technical and desired maximum speed)
* @return The object's maximum speed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/****************************************************************************/
/// @file Constants.java
/// @author generated by "rebuildConstants.py"
/// @date 2024-04-09 11:14:09.616128
/// @date 2024-04-12 09:29:27.165805
///
// This script contains TraCI constant definitions from <SUMO_HOME>/src/libsumo/TraCIConstants.h.
/****************************************************************************/
Expand Down Expand Up @@ -616,6 +616,9 @@ public class Constants {
public static final int ROUTING_MODE_COMBINED = 0x03;
// use aggregated travel times from device.rerouting enriched with custom weights
public static final int ROUTING_MODE_AGGREGATED_CUSTOM = 0x04;
// when this bit is set, routing does not consider temporary permission changes (i.e. from rerouters)
// note: can be combined with either one of the other modes (bitwise)
public static final int ROUTING_MODE_IGNORE_TRANSIENT_PERMISSIONS = 0x08;

// ****************************************
// Traffic light types
Expand Down
5 changes: 4 additions & 1 deletion tools/traci/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# @file constants.py
# @author generated by "rebuildConstants.py"
# @date 2024-04-09 11:14:09.616128
# @date 2024-04-12 09:29:27.165805

"""
This script contains TraCI constant definitions from <SUMO_HOME>/src/libsumo/TraCIConstants.h.
Expand Down Expand Up @@ -616,6 +616,9 @@
ROUTING_MODE_COMBINED = 0x03
# use aggregated travel times from device.rerouting enriched with custom weights
ROUTING_MODE_AGGREGATED_CUSTOM = 0x04
# when this bit is set, routing does not consider temporary permission changes (i.e. from rerouters)
# note: can be combined with either one of the other modes (bitwise)
ROUTING_MODE_IGNORE_TRANSIENT_PERMISSIONS = 0x08

# ****************************************
# Traffic light types
Expand Down

0 comments on commit 727e6c2

Please sign in to comment.