Skip to content

Commit

Permalink
fix #4585
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Sep 13, 2018
1 parent 0d4c314 commit 25847b4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
41 changes: 33 additions & 8 deletions src/netwrite/NWWriter_SUMO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,10 @@ NWWriter_SUMO::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {


std::string
NWWriter_SUMO::getOppositeInternalID(const NBEdgeCont& ec, const NBEdge* from, const NBEdge::Connection& con) {
NWWriter_SUMO::getOppositeInternalID(const NBEdgeCont& ec, const NBEdge* from, const NBEdge::Connection& con, double& oppositeLength) {
const NBEdge::Lane& succ = con.toEdge->getLanes()[con.toLane];
const NBEdge::Lane& pred = from->getLanes()[con.fromLane];
const bool lefthand = OptionsCont::getOptions().getBool("lefthand");
if (succ.oppositeID != "" && succ.oppositeID != "-" && pred.oppositeID != "" && pred.oppositeID != "-") {
#ifdef DEBUG_OPPOSITE_INTERNAL
std::cout << "getOppositeInternalID con=" << con.getDescription(from) << " (" << con.getInternalLaneID() << ")\n";
Expand All @@ -242,16 +243,17 @@ NWWriter_SUMO::getOppositeInternalID(const NBEdgeCont& ec, const NBEdge* from, c
const std::vector<NBEdge::Connection>& connections = succOpp->getConnections();
for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); it_c++) {
const NBEdge::Connection& conOpp = *it_c;
if (succOpp != from && // turnaround
succOpp->getLaneID(conOpp.fromLane) == succ.oppositeID &&
predOpp == conOpp.toEdge &&
predOpp->getLaneID(conOpp.toLane) == pred.oppositeID &&
// same lengths (@note: averaging is not taken into account)
con.shape.length() == conOpp.shape.length()
if (succOpp != from // turnaround
&& predOpp == conOpp.toEdge
&& succOpp->getLaneID(conOpp.fromLane) == succ.oppositeID
&& predOpp->getLaneID(conOpp.toLane) == pred.oppositeID
&& from->getToNode()->getDirection(from, con.toEdge, lefthand) == LINKDIR_STRAIGHT
&& from->getToNode()->getDirection(succOpp, predOpp, lefthand) == LINKDIR_STRAIGHT
) {
#ifdef DEBUG_OPPOSITE_INTERNAL
std::cout << " found " << conOpp.getInternalLaneID() << "\n";
#endif
oppositeLength = conOpp.length;
return conOpp.getInternalLaneID();
} else {
/*
Expand Down Expand Up @@ -281,6 +283,29 @@ bool
NWWriter_SUMO::writeInternalEdges(OutputDevice& into, const NBEdgeCont& ec, const NBNode& n) {
bool ret = false;
const EdgeVector& incoming = n.getIncomingEdges();
// first pass: determine opposite internal edges and average their length
std::map<std::string, std::string> oppositeLaneID;
std::map<std::string, double> oppositeLengths;
for (NBEdge* e : incoming) {
for (const NBEdge::Connection& c : e->getConnections()) {
double oppositeLength = 0;
const std::string op = getOppositeInternalID(ec, e, c, oppositeLength);
oppositeLaneID[c.getInternalLaneID()] = op;
if (op != "") {
oppositeLengths[c.id] = oppositeLength;
}
}
}
if (oppositeLengths.size() > 0) {
for (NBEdge* e : incoming) {
for (NBEdge::Connection& c : e->getConnections()) {
if (oppositeLengths.count(c.id) > 0) {
c.length = (c.length + oppositeLengths[c.id]) / 2;
}
}
}
}

for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
const std::vector<NBEdge::Connection>& elv = (*i)->getConnections();
if (elv.size() > 0) {
Expand Down Expand Up @@ -310,7 +335,7 @@ NWWriter_SUMO::writeInternalEdges(OutputDevice& into, const NBEdgeCont& ec, cons
writeLane(into, (*k).getInternalLaneID(), (*k).vmax,
successor.permissions, successor.preferred,
NBEdge::UNSPECIFIED_OFFSET, std::map<int, double>(), width, (*k).shape, &(*k),
(*k).length, (*k).internalLaneIndex, getOppositeInternalID(ec, *i, *k));
(*k).length, (*k).internalLaneIndex, oppositeLaneID[(*k).getInternalLaneID()]);
haveVia = haveVia || (*k).haveVia;
}
ret = true;
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 @@ -197,7 +197,7 @@ class NWWriter_SUMO {
const NBEdgeCont& ec);

/// @brief retrieve the id of the opposite direction internal lane if it exists
static std::string getOppositeInternalID(const NBEdgeCont& ec, const NBEdge* from, const NBEdge::Connection& con);
static std::string getOppositeInternalID(const NBEdgeCont& ec, const NBEdge* from, const NBEdge::Connection& con, double& oppositeLength);

};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on Thu Sep 13 10:07:11 2018 by Eclipse SUMO netconvert Version v1_0_0+0161-7e6aac7
<!-- generated on Thu Sep 13 11:21:57 2018 by Eclipse SUMO netconvert Version v1_0_0+0164-bf187b7
This data file and the accompanying materials
are made available under the terms of the Eclipse Public License v2.0
which accompanies this distribution, and is available at
Expand Down Expand Up @@ -46,8 +46,10 @@ SPDX-License-Identifier: EPL-2.0
<location netOffset="100.00,100.00" convBoundary="100.00,0.00,103.52,200.88" origBoundary="-10000000000.00,-10000000000.00,10000000000.00,10000000000.00" projParameter="!"/>

<edge id=":C_0" function="internal">
<lane id=":C_0_0" index="0" speed="13.89" length="0.35" shape="95.21,100.29 95.20,99.88"/>
<lane id=":C_0_1" index="1" speed="13.89" length="0.35" shape="98.41,100.18 98.40,99.88"/>
<lane id=":C_0_0" index="0" speed="13.89" length="0.25" shape="95.21,100.29 95.20,99.88"/>
<lane id=":C_0_1" index="1" speed="13.89" length="0.25" shape="98.41,100.18 98.40,99.88">
<neigh lane=":C_3_1"/>
</lane>
</edge>
<edge id=":C_2" function="internal">
<lane id=":C_2_0" index="0" speed="13.89" length="2.34" shape="98.41,100.18 99.16,98.95 99.95,98.52"/>
Expand All @@ -56,8 +58,10 @@ SPDX-License-Identifier: EPL-2.0
<lane id=":C_6_0" index="0" speed="13.89" length="2.34" shape="99.95,98.52 100.76,98.89 101.60,100.06"/>
</edge>
<edge id=":C_3" function="internal">
<lane id=":C_3_0" index="0" speed="13.89" length="0.14" shape="104.80,99.88 104.80,99.95"/>
<lane id=":C_3_1" index="1" speed="13.89" length="0.14" shape="101.60,99.88 101.60,100.06"/>
<lane id=":C_3_0" index="0" speed="13.89" length="0.25" shape="104.80,99.88 104.80,99.95"/>
<lane id=":C_3_1" index="1" speed="13.89" length="0.25" shape="101.60,99.88 101.60,100.06">
<neigh lane=":C_0_1"/>
</lane>
</edge>
<edge id=":C_5" function="internal">
<lane id=":C_5_0" index="0" speed="13.89" length="2.34" shape="101.60,99.88 100.80,101.08 100.00,101.48"/>
Expand Down

0 comments on commit 25847b4

Please sign in to comment.