Skip to content

Commit

Permalink
avoiding redundant permissions for normal lanes. refs #14625
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Apr 1, 2024
1 parent 3ac8e0b commit bd87fd0
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/netimport/NIImporter_SUMO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ NIImporter_SUMO::_loadNetwork(OptionsCont& oc) {
// assign further lane attributes (edges are built)
EdgeVector toRemove;
const bool dismissVclasses = oc.getBool("dismiss-vclasses");
const bool edgeTypePermissions = myNetworkVersion >= MMVersion(1, 20);
const NBTypeCont& tc = myTypesHandler.getTypeCont();
for (std::map<std::string, EdgeAttrs*>::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
EdgeAttrs* ed = (*i).second;
NBEdge* nbe = ed->builtEdge;
Expand Down Expand Up @@ -237,6 +239,9 @@ NIImporter_SUMO::_loadNetwork(OptionsCont& oc) {
// allow/disallow XXX preferred
if (!dismissVclasses) {
nbe->setPermissions(parseVehicleClasses(lane->allow, lane->disallow, myNetworkVersion), fromLaneIndex);
if (lane->allow == "" && lane->disallow == "" && edgeTypePermissions) {
nbe->setPermissions(tc.getEdgeTypePermissions(nbe->getTypeID()));
}
}
nbe->setPermittedChanging(fromLaneIndex, parseVehicleClasses(lane->changeLeft, ""), parseVehicleClasses(lane->changeRight, ""));
// width, offset
Expand Down
4 changes: 4 additions & 0 deletions src/netimport/NIXMLTypesHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class NIXMLTypesHandler : public SUMOSAXHandler {

//@}

const NBTypeCont& getTypeCont() {
return myTypeCont;
}

private:
/// @brief The type container to fill
NBTypeCont& myTypeCont;
Expand Down
9 changes: 6 additions & 3 deletions src/netwrite/NWWriter_SUMO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ NWWriter_SUMO::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
const NBNodeCont& nc = nb.getNodeCont();
const NBEdgeCont& ec = nb.getEdgeCont();
const NBDistrictCont& dc = nb.getDistrictCont();
const NBTypeCont& tc = nb.getTypeCont();

// write network offsets and projection
GeoConvHelper::writeLocation(device);
Expand All @@ -141,7 +142,7 @@ NWWriter_SUMO::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
// write edges with lanes and connected edges
bool noNames = !oc.getBool("output.street-names");
for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
writeEdge(device, *(*i).second, noNames);
writeEdge(device, *(*i).second, noNames, tc);
}
device.lf();

Expand Down Expand Up @@ -471,7 +472,7 @@ NWWriter_SUMO::getInternalBidi(const NBEdge* e, const NBEdge::Connection& k, dou
}

void
NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames) {
NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames, const NBTypeCont& tc) {
// write the edge's begin
into.openTag(SUMO_TAG_EDGE).writeAttr(SUMO_ATTR_ID, e.getID());
into.writeAttr(SUMO_ATTR_FROM, e.getFromNode()->getID());
Expand Down Expand Up @@ -514,14 +515,16 @@ NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames) {
length = (length + e.getBidiEdge()->getFinalLength()) / 2;
}
double startOffset = e.isBidiRail() ? e.getTurnDestination(true)->getEndOffset() : 0;
const bool defaultPermissions = !e.hasLaneSpecificPermissions() && e.getPermissions() == tc.getEdgeTypePermissions(e.getTypeID());
for (int i = 0; i < (int) lanes.size(); i++) {
const NBEdge::Lane& l = lanes[i];
StopOffset stopOffset;
if (l.laneStopOffset != e.getEdgeStopOffset()) {
stopOffset = l.laneStopOffset;
}
writeLane(into, e.getLaneID(i), l.speed, l.friction,
l.permissions, l.preferred,
defaultPermissions ? SVC_UNSPECIFIED : l.permissions,
l.preferred,
l.changeLeft, l.changeRight,
startOffset, l.endOffset,
stopOffset, l.width, l.shape, &l,
Expand Down
2 changes: 1 addition & 1 deletion src/netwrite/NWWriter_SUMO.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class NWWriter_SUMO {
* @param[in] noNames Whether names shall be ignored
* @see writeLane()
*/
static void writeEdge(OutputDevice& into, const NBEdge& e, bool noNames);
static void writeEdge(OutputDevice& into, const NBEdge& e, bool noNames, const NBTypeCont& tc);


/** @brief Writes a lane (<lane ...) of an edge
Expand Down
6 changes: 3 additions & 3 deletions src/netwrite/NWWriter_XML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ NWWriter_XML::writeNetwork(const OptionsCont& oc, const std::string& prefix, NBN
if (nb.getTypeCont().size() > 0) {
writeTypes(prefix, nb.getEdgeCont(), nb.getTypeCont());
}
writeEdgesAndConnections(oc, prefix, nb.getNodeCont(), nb.getEdgeCont());
writeEdgesAndConnections(oc, prefix, nb.getNodeCont(), nb.getEdgeCont(), nb.getTypeCont());
writeTrafficLights(prefix, nb.getTLLogicCont(), nb.getEdgeCont());
}
if (oc.isSet("junctions.join-output")) {
Expand Down Expand Up @@ -184,7 +184,7 @@ NWWriter_XML::writeTypes(const std::string& prefix, NBEdgeCont& ec, NBTypeCont&


void
NWWriter_XML::writeEdgesAndConnections(const OptionsCont& oc, const std::string& prefix, NBNodeCont& nc, NBEdgeCont& ec) {
NWWriter_XML::writeEdgesAndConnections(const OptionsCont& oc, const std::string& prefix, NBNodeCont& nc, NBEdgeCont& ec, const NBTypeCont& tc) {
const GeoConvHelper& gch = GeoConvHelper::getFinal();
bool useGeo = oc.exists("proj.plain-geo") && oc.getBool("proj.plain-geo");
const bool geoAccuracy = useGeo || gch.usingInverseGeoProjection();
Expand Down Expand Up @@ -247,6 +247,7 @@ NWWriter_XML::writeEdgesAndConnections(const OptionsCont& oc, const std::string&
edevice.writeAttr(SUMO_ATTR_ENDOFFSET, e->getEndOffset());
}
if (!e->hasLaneSpecificPermissions()) {
// always write permissions because we don't know whether the types file will be available
writePermissions(edevice, e->getPermissions(0));
}
if (!e->hasLaneSpecificStopOffsets() && e->getEdgeStopOffset().isDefined()) {
Expand Down Expand Up @@ -509,5 +510,4 @@ NWWriter_XML::writeShape(OutputDevice& out, const GeoConvHelper& gch, PositionVe
}
}


/****************************************************************************/
2 changes: 1 addition & 1 deletion src/netwrite/NWWriter_XML.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class NWWriter_XML {
* @param[in] oc The options to use
* @param[in] nb The network build from which to read data
*/
static void writeEdgesAndConnections(const OptionsCont& oc, const std::string& prefix, NBNodeCont& nc, NBEdgeCont& ec);
static void writeEdgesAndConnections(const OptionsCont& oc, const std::string& prefix, NBNodeCont& nc, NBEdgeCont& ec, const NBTypeCont& tc);


/** @brief Writes the traffic lights file
Expand Down
1 change: 1 addition & 0 deletions src/utils/common/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ StringUtils::toBool(const std::string& sData) {
MMVersion
StringUtils::toVersion(const std::string& sData) {
std::vector<std::string> parts = StringTokenizer(sData, ".").getVector();
assert(parts.size() == 2);
return MMVersion(toInt(parts.front()), toDouble(parts.back()));
}

Expand Down

0 comments on commit bd87fd0

Please sign in to comment.