Skip to content

Commit

Permalink
fix #2956, fix #2599
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Jan 25, 2019
1 parent 9d973fa commit d0f7885
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 77 deletions.
29 changes: 7 additions & 22 deletions src/netbuild/NBEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2706,12 +2706,12 @@ NBEdge::getMaxLaneOffset() {

bool
NBEdge::mayBeTLSControlled(int fromLane, NBEdge* toEdge, int toLane) const {
TLSDisabledConnection tpl;
tpl.fromLane = fromLane;
tpl.to = toEdge;
tpl.toLane = toLane;
std::vector<TLSDisabledConnection>::const_iterator i = find_if(myTLSDisabledConnections.begin(), myTLSDisabledConnections.end(), tls_disable_finder(tpl));
return i == myTLSDisabledConnections.end();
for (const Connection& c : myConnections) {
if (c.fromLane == fromLane && c.toEdge == toEdge && c.toLane == toLane && c.uncontrolled) {
return false;
}
}
return true;
}


Expand All @@ -2722,12 +2722,7 @@ NBEdge::setControllingTLInformation(const NBConnection& c, const std::string& tl
const int toLane = c.getToLane();
const int tlIndex = c.getTLIndex();
// check whether the connection was not set as not to be controled previously
TLSDisabledConnection tpl;
tpl.fromLane = fromLane;
tpl.to = toEdge;
tpl.toLane = toLane;
std::vector<TLSDisabledConnection>::iterator i = find_if(myTLSDisabledConnections.begin(), myTLSDisabledConnections.end(), tls_disable_finder(tpl));
if (i != myTLSDisabledConnections.end()) {
if (!mayBeTLSControlled(fromLane, toEdge, toLane)) {
return false;
}

Expand Down Expand Up @@ -2788,16 +2783,6 @@ NBEdge::clearControllingTLInformation() {
}


void
NBEdge::disableConnection4TLS(int fromLane, NBEdge* toEdge, int toLane) {
TLSDisabledConnection c;
c.fromLane = fromLane;
c.to = toEdge;
c.toLane = toLane;
myTLSDisabledConnections.push_back(c);
}


PositionVector
NBEdge::getCWBoundaryLine(const NBNode& n) const {
PositionVector ret;
Expand Down
39 changes: 0 additions & 39 deletions src/netbuild/NBEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -1518,16 +1518,6 @@ class NBEdge : public Named, public Parameterised {
/// @brief Information whether this edge is a (macroscopic) connector
bool myAmMacroscopicConnector;

/// @brief TLS Disabled Connections
struct TLSDisabledConnection {
int fromLane;
NBEdge* to;
int toLane;
};

/// @brief vector with the disabled connections
std::vector<TLSDisabledConnection> myTLSDisabledConnections;

/// @brief The street name (or whatever arbitrary string you wish to attach)
std::string myStreetName;

Expand All @@ -1554,35 +1544,6 @@ class NBEdge : public Named, public Parameterised {
mutable NBConstEdgePairVector myViaSuccessors;

public:
/// @class tls_disable_finder
class tls_disable_finder {
public:
/// @brief constructor
tls_disable_finder(const TLSDisabledConnection& tpl) : myDefinition(tpl) { }

/// @brief operator ()
bool operator()(const TLSDisabledConnection& e) const {
if (e.to != myDefinition.to) {
return false;
}
if (e.fromLane != myDefinition.fromLane) {
return false;
}
if (e.toLane != myDefinition.toLane) {
return false;
}
return true;
}

private:
/// @brief definition of disable connection
TLSDisabledConnection myDefinition;

private:
/// @brief invalidated assignment operator
tls_disable_finder& operator=(const tls_disable_finder& s);
};


/// @class connections_toedge_finder
class connections_toedge_finder {
Expand Down
6 changes: 3 additions & 3 deletions src/netbuild/NBEdgeCont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,8 +1018,8 @@ NBEdgeCont::getByID(const std::string& edgeID) const {
void
NBEdgeCont::addPostProcessConnection(const std::string& from, int fromLane, const std::string& to, int toLane, bool mayDefinitelyPass,
bool keepClear, double contPos, double visibility, double speed,
const PositionVector& customShape, bool warnOnly) {
myConnections.push_back(PostProcessConnection(from, fromLane, to, toLane, mayDefinitelyPass, keepClear, contPos, visibility, speed, customShape, warnOnly));
const PositionVector& customShape, bool uncontrolled, bool warnOnly) {
myConnections.push_back(PostProcessConnection(from, fromLane, to, toLane, mayDefinitelyPass, keepClear, contPos, visibility, speed, customShape, uncontrolled, warnOnly));
}


Expand All @@ -1031,7 +1031,7 @@ NBEdgeCont::recheckPostProcessConnections() {
NBEdge* to = retrievePossiblySplit((*i).to, false);
if (from == nullptr || to == nullptr ||
!from->addLane2LaneConnection((*i).fromLane, to, (*i).toLane, NBEdge::L2L_USER, true, (*i).mayDefinitelyPass,
(*i).keepClear, (*i).contPos, (*i).visibility, (*i).speed, (*i).customShape)) {
(*i).keepClear, (*i).contPos, (*i).visibility, (*i).speed, (*i).customShape, (*i).uncontrolled)) {
const std::string msg = "Could not insert connection between '" + (*i).from + "' and '" + (*i).to + "' after build.";
if (warnOnly || (*i).warnOnly) {
WRITE_WARNING(msg);
Expand Down
9 changes: 7 additions & 2 deletions src/netbuild/NBEdgeCont.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ class NBEdgeCont {
void addPostProcessConnection(const std::string& from, int fromLane, const std::string& to, int toLane, bool mayDefinitelyPass,
bool keepClear, double contPos, double visibility, double speed,
const PositionVector& customShape,
bool warnOnly = false);
bool uncontrolled,
bool warnOnly);


/** @brief Try to set any stored connections
Expand Down Expand Up @@ -616,11 +617,13 @@ class NBEdgeCont {
PostProcessConnection(const std::string& from_, int fromLane_, const std::string& to_, int toLane_,
bool mayDefinitelyPass_, bool keepClear_, double contPos_, double visibility_, double speed_,
const PositionVector& customShape_,
bool warnOnly_ = false) :
bool uncontrolled_,
bool warnOnly_) :
from(from_), fromLane(fromLane_), to(to_), toLane(toLane_), mayDefinitelyPass(mayDefinitelyPass_), keepClear(keepClear_), contPos(contPos_),
visibility(visibility_),
speed(speed_),
customShape(customShape_),
uncontrolled(uncontrolled_),
warnOnly(warnOnly_) {
}
/// @brief The id of the edge the connection starts at
Expand All @@ -643,6 +646,8 @@ class NBEdgeCont {
double speed;
/// @brief custom shape for connection
PositionVector customShape;
/// @brief whether this connection shall not be controlled by a traffic light
bool uncontrolled;
/// @brief whether a failure to set this connection is a warning or an error
bool warnOnly;
};
Expand Down
2 changes: 1 addition & 1 deletion src/netimport/NIImporter_DlrNavteq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ NIImporter_DlrNavteq::ConnectedLanesHandler::report(const std::string& result) {
const bool warnOnly = st.size() > 7;
myEdgeCont.addPostProcessConnection(from->getID(), fromLane, to->getID(), toLane, false, true,
NBEdge::UNSPECIFIED_CONTPOS, NBEdge::UNSPECIFIED_VISIBILITY_DISTANCE,
NBEdge::UNSPECIFIED_SPEED, PositionVector::EMPTY, warnOnly);
NBEdge::UNSPECIFIED_SPEED, PositionVector::EMPTY, false, warnOnly);
}
// ensure that connections for other lanes are guessed if not specified
from->declareConnectionsAsLoaded(NBEdge::INIT);
Expand Down
15 changes: 12 additions & 3 deletions src/netimport/NIImporter_SUMO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ NIImporter_SUMO::_loadNetwork(OptionsCont& oc) {
if (nbe == nullptr) { // inner edge or removed by explicit list, vclass, ...
continue;
}
const SumoXMLNodeType toType = nbe->getToNode()->getType();
for (int fromLaneIndex = 0; fromLaneIndex < (int) ed->lanes.size(); ++fromLaneIndex) {
LaneAttrs* lane = ed->lanes[fromLaneIndex];
// connections
const std::vector<Connection>& connections = lane->connections;
for (std::vector<Connection>::const_iterator c_it = connections.begin(); c_it != connections.end(); c_it++) {
const Connection& c = *c_it;
for (const Connection& c : connections) {
if (myEdges.count(c.toEdgeID) == 0) {
WRITE_ERROR("Unknown edge '" + c.toEdgeID + "' given in connection.");
continue;
Expand All @@ -192,9 +192,16 @@ NIImporter_SUMO::_loadNetwork(OptionsCont& oc) {
if (nbe->hasConnectionTo(toEdge, c.toLaneIdx)) {
WRITE_WARNING("Target lane '" + toEdge->getLaneID(c.toLaneIdx) + "' has multiple connections from '" + nbe->getID() + "'.");
}
// patch attribute uncontrolled for legacy networks where it is not set explicitly
bool uncontrolled = c.uncontrolled;

if ((NBNode::isTrafficLight(toType) || toType == NODETYPE_RAIL_SIGNAL)
&& c.tlLinkIndex == NBConnection::InvalidTlIndex) {
uncontrolled = true;
}
nbe->addLane2LaneConnection(
fromLaneIndex, toEdge, c.toLaneIdx, NBEdge::L2L_VALIDATED,
true, c.mayDefinitelyPass, c.keepClear, c.contPos, c.visibility, c.speed, c.customShape, c.uncontrolled);
true, c.mayDefinitelyPass, c.keepClear, c.contPos, c.visibility, c.speed, c.customShape, uncontrolled);

// maybe we have a tls-controlled connection
if (c.tlID != "" && myRailSignals.count(c.tlID) == 0) {
Expand Down Expand Up @@ -733,6 +740,8 @@ NIImporter_SUMO::addConnection(const SUMOSAXAttributes& attrs) {
conn.uncontrolled = attrs.getOpt<bool>(SUMO_ATTR_UNCONTROLLED, nullptr, ok, NBEdge::UNSPECIFIED_CONNECTION_UNCONTROLLED, false);
if (conn.tlID != "") {
conn.tlLinkIndex = attrs.get<int>(SUMO_ATTR_TLLINKINDEX, nullptr, ok);
} else {
conn.tlLinkIndex = NBConnection::InvalidTlIndex;
}
if ((int)from->lanes.size() <= fromLaneIdx) {
WRITE_ERROR("Invalid lane index '" + toString(fromLaneIdx) + "' for connection from '" + fromID + "'.");
Expand Down
11 changes: 4 additions & 7 deletions src/netimport/NIXMLConnectionsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ NIXMLConnectionsHandler::parseLaneBound(const SUMOSAXAttributes& attrs, NBEdge*
const double contPos = attrs.getOpt<double>(SUMO_ATTR_CONTPOS, nullptr, ok, NBEdge::UNSPECIFIED_CONTPOS);
const double visibility = attrs.getOpt<double>(SUMO_ATTR_VISIBILITY_DISTANCE, nullptr, ok, NBEdge::UNSPECIFIED_VISIBILITY_DISTANCE);
const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, nullptr, ok, NBEdge::UNSPECIFIED_SPEED);
const bool uncontrolled = attrs.getOpt<bool>(SUMO_ATTR_UNCONTROLLED, nullptr, ok, false);
PositionVector customShape = attrs.getOpt<PositionVector>(SUMO_ATTR_SHAPE, nullptr, ok, PositionVector::EMPTY);
if (!NBNetBuilder::transformCoordinates(customShape)) {
WRITE_ERROR("Unable to project shape for connection from edge '" + from->getID() + "' to edge '" + to->getID() + "'.");
Expand Down Expand Up @@ -236,21 +237,17 @@ NIXMLConnectionsHandler::parseLaneBound(const SUMOSAXAttributes& attrs, NBEdge*
if (from->hasConnectionTo(to, toLane) && from->getToNode()->getType() != NODETYPE_ZIPPER) {
WRITE_WARNING("Target lane '" + to->getLaneID(toLane) + "' is already connected from '" + from->getID() + "'.");
}
if (!from->addLane2LaneConnection(fromLane, to, toLane, NBEdge::L2L_USER, true, mayDefinitelyPass, keepClear, contPos, visibility, speed, customShape)) {
if (!from->addLane2LaneConnection(fromLane, to, toLane, NBEdge::L2L_USER, true, mayDefinitelyPass,
keepClear, contPos, visibility, speed, customShape, uncontrolled)) {
if (OptionsCont::getOptions().getBool("show-errors.connections-first-try")) {
WRITE_WARNING("Could not set loaded connection from '" + from->getLaneID(fromLane) + "' to '" + to->getLaneID(toLane) + "'.");
}
// set as to be re-applied after network processing
myEdgeCont.addPostProcessConnection(from->getID(), fromLane, to->getID(), toLane, mayDefinitelyPass, keepClear, contPos, visibility, speed, customShape);
myEdgeCont.addPostProcessConnection(from->getID(), fromLane, to->getID(), toLane, mayDefinitelyPass, keepClear, contPos, visibility, speed, customShape, uncontrolled, false);
}
} catch (NumberFormatException&) {
myErrorMsgHandler->inform("At least one of the defined lanes was not numeric");
}
//
bool keepUncontrolled = attrs.getOpt<bool>(SUMO_ATTR_UNCONTROLLED, nullptr, ok, false);
if (keepUncontrolled) {
from->disableConnection4TLS(fromLane, to, toLane);
}
}

bool
Expand Down

0 comments on commit d0f7885

Please sign in to comment.