Skip to content

Commit

Permalink
fix #4031
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Jul 2, 2018
1 parent abcb09e commit 518b95f
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/guinetload/GUITriggerBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ MSTriggeredRerouter*
GUITriggerBuilder::buildRerouter(MSNet& net, const std::string& id,
MSEdgeVector& edges,
double prob, const std::string& file, bool off,
SUMOTime timeThreshold) {
GUITriggeredRerouter* rr = new GUITriggeredRerouter(id, edges, prob, file, off, timeThreshold,
SUMOTime timeThreshold,
const std::string& vTypes) {
GUITriggeredRerouter* rr = new GUITriggeredRerouter(id, edges, prob, file, off, timeThreshold, vTypes,
dynamic_cast<GUINet&>(net).getVisualisationSpeedUp());
return rr;
}
Expand Down
3 changes: 2 additions & 1 deletion src/guinetload/GUITriggerBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class GUITriggerBuilder : public NLTriggerBuilder {
virtual MSTriggeredRerouter* buildRerouter(MSNet& net,
const std::string& id, MSEdgeVector& edges,
double prob, const std::string& file, bool off,
SUMOTime timeThreshold);
SUMOTime timeThreshold,
const std::string& vTypes);


/** @brief Builds a bus stop
Expand Down
2 changes: 1 addition & 1 deletion src/guisim/GUIEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ void
GUIEdge::addRerouter() {
MSEdgeVector edges;
edges.push_back(this);
GUITriggeredRerouter* rr = new GUITriggeredRerouter(getID() + "_dynamic_rerouter", edges, 1, "", false, 0,
GUITriggeredRerouter* rr = new GUITriggeredRerouter(getID() + "_dynamic_rerouter", edges, 1, "", false, 0, "",
GUINet::getGUIInstance()->getVisualisationSpeedUp());

MSTriggeredRerouter::RerouteInterval ri;
Expand Down
4 changes: 2 additions & 2 deletions src/guisim/GUITriggeredRerouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ GUITriggeredRerouter::GUITriggeredRerouterPopupMenu::onCmdOpenManip(FXObject*,
// -------------------------------------------------------------------------

GUITriggeredRerouter::GUITriggeredRerouter(const std::string& id, const MSEdgeVector& edges, double prob,
const std::string& aXMLFilename, bool off, SUMOTime timeThreshold, SUMORTree& rtree) :
MSTriggeredRerouter(id, edges, prob, aXMLFilename, off, timeThreshold),
const std::string& aXMLFilename, bool off, SUMOTime timeThreshold, const std::string& vTypes, SUMORTree& rtree) :
MSTriggeredRerouter(id, edges, prob, aXMLFilename, off, timeThreshold, vTypes),
GUIGlObject_AbstractAdd(GLO_REROUTER, id) {
// add visualisation objects for edges which trigger the rerouter
for (MSEdgeVector::const_iterator it = edges.begin(); it != edges.end(); ++it) {
Expand Down
1 change: 1 addition & 0 deletions src/guisim/GUITriggeredRerouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class GUITriggeredRerouter
const MSEdgeVector& edges, double prob,
const std::string& aXMLFilename, bool off,
SUMOTime timeThreshold,
const std::string& vTypes,
SUMORTree& rtree);


Expand Down
13 changes: 12 additions & 1 deletion src/microsim/trigger/MSTriggeredRerouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ MSEdge MSTriggeredRerouter::mySpecialDest_terminateRoute("MSTriggeredRerouter_te
MSTriggeredRerouter::MSTriggeredRerouter(const std::string& id,
const MSEdgeVector& edges,
double prob, const std::string& file, bool off,
SUMOTime timeThreshold) :
SUMOTime timeThreshold,
const std::string& vTypes) :
MSTrigger(id),
MSMoveReminder(id),
SUMOSAXHandler(file),
Expand All @@ -93,6 +94,8 @@ MSTriggeredRerouter::MSTriggeredRerouter(const std::string& id,
setUserMode(true);
setUserUsageProbability(0);
}
const std::vector<std::string> vt = StringTokenizer(vTypes).getVector();
myVehicleTypes.insert(vt.begin(), vt.end());
}


Expand Down Expand Up @@ -353,6 +356,9 @@ MSTriggeredRerouter::notifyLeave(SUMOVehicle& /*veh*/, double /*lastPos*/,

bool
MSTriggeredRerouter::notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification /*reason*/, const MSLane* /* enteredLane */) {
if (!vehicleApplies(veh)) {
return false;
}
// check whether the vehicle shall be rerouted
const SUMOTime time = MSNet::getInstance()->getCurrentTimeStep();
const MSTriggeredRerouter::RerouteInterval* rerouteDef = getCurrentReroute(time, veh);
Expand Down Expand Up @@ -806,5 +812,10 @@ MSTriggeredRerouter::rerouteParkingArea(const MSTriggeredRerouter::RerouteInterv
return nearParkArea;
}


bool
MSTriggeredRerouter::vehicleApplies(const SUMOVehicle& veh) const {
return myVehicleTypes.empty() || myVehicleTypes.count(veh.getVehicleType().getID()) > 0;
}
/****************************************************************************/

15 changes: 14 additions & 1 deletion src/microsim/trigger/MSTriggeredRerouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class MSTriggeredRerouter :
MSTriggeredRerouter(const std::string& id,
const MSEdgeVector& edges,
double prob, const std::string& file, bool off,
SUMOTime timeThreshold);
SUMOTime timeThreshold,
const std::string& vTypes);


/** @brief Destructor */
Expand Down Expand Up @@ -178,6 +179,7 @@ class MSTriggeredRerouter :
MSParkingArea* rerouteParkingArea(const MSTriggeredRerouter::RerouteInterval* rerouteDef,
SUMOVehicle& veh, bool& newDestination) const;


protected:
/// @name inherited from GenericSAXHandler
//@{
Expand All @@ -201,6 +203,14 @@ class MSTriggeredRerouter :
*/
virtual void myEndElement(int element);
//@}

/** @brief Checks whether the detector measures vehicles of the given type.
*
* @param[in] veh the vehicle of which the type is checked.
* @return whether it should be measured
*/
bool vehicleApplies(const SUMOVehicle& veh) const;


protected:
/// List of rerouting definition intervals
Expand All @@ -215,6 +225,9 @@ class MSTriggeredRerouter :
// @brief waiting time threshold for activation
SUMOTime myTimeThreshold;

/// @brief The vehicle types to look for (empty means all)
std::set<std::string> myVehicleTypes;

/// @name members used during loading
//@{

Expand Down
8 changes: 5 additions & 3 deletions src/netload/NLTriggerBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,11 @@ NLTriggerBuilder::parseAndBuildRerouter(MSNet& net, const SUMOSAXAttributes& att
double prob = attrs.getOpt<double>(SUMO_ATTR_PROB, id.c_str(), ok, 1);
bool off = attrs.getOpt<bool>(SUMO_ATTR_OFF, id.c_str(), ok, false);
SUMOTime timeThreshold = TIME2STEPS(attrs.getOpt<double>(SUMO_ATTR_HALTING_TIME_THRESHOLD, id.c_str(), ok, 0));
const std::string vTypes = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id.c_str(), ok, "");
if (!ok) {
throw InvalidArgument("Could not parse MSTriggeredRerouter '" + id + "'.");
}
MSTriggeredRerouter* trigger = buildRerouter(net, id, edges, prob, file, off, timeThreshold);
MSTriggeredRerouter* trigger = buildRerouter(net, id, edges, prob, file, off, timeThreshold, vTypes);
// read in the trigger description
if (file == "") {
trigger->registerParent(SUMO_TAG_REROUTER, myHandler);
Expand Down Expand Up @@ -422,8 +423,9 @@ MSTriggeredRerouter*
NLTriggerBuilder::buildRerouter(MSNet&, const std::string& id,
MSEdgeVector& edges,
double prob, const std::string& file, bool off,
SUMOTime timeThreshold) {
return new MSTriggeredRerouter(id, edges, prob, file, off, timeThreshold);
SUMOTime timeThreshold,
const std::string& vTypes) {
return new MSTriggeredRerouter(id, edges, prob, file, off, timeThreshold, vTypes);
}


Expand Down
3 changes: 2 additions & 1 deletion src/netload/NLTriggerBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ class NLTriggerBuilder {
virtual MSTriggeredRerouter* buildRerouter(MSNet& net,
const std::string& id, MSEdgeVector& edges,
double prob, const std::string& file, bool off,
SUMOTime timeThreshold);
SUMOTime timeThreshold,
const std::string& vTypes);
//@}


Expand Down

0 comments on commit 518b95f

Please sign in to comment.