Skip to content

Commit

Permalink
fix #3824
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Feb 19, 2018
1 parent bbb81ba commit 08ab7e7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/netbuild/NBLoadedSUMOTLDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ NBLoadedSUMOTLDef::NBLoadedSUMOTLDef(NBTrafficLightDefinition* def, NBTrafficLig
assert(def->getType() == logic->getType());
myControlledLinks = def->getControlledLinks();
myControlledNodes = def->getNodes();
NBLoadedSUMOTLDef* sumoDef = dynamic_cast<NBLoadedSUMOTLDef*>(def);
if (sumoDef != 0) {
myReconstructAddedConnections = sumoDef->myReconstructAddedConnections;
myReconstructRemovedConnections = sumoDef->myReconstructRemovedConnections;
}
}


Expand Down Expand Up @@ -435,15 +440,15 @@ NBLoadedSUMOTLDef::reconstructLogic() {
const bool netedit = NBNetBuilder::runningNetedit();
#ifdef DEBUG_RECONSTRUCTION
bool debugPrintModified = myReconstructAddedConnections || myReconstructRemovedConnections;
std::cout << " reconstructLogic added=" << myReconstructAddedConnections << " removed=" << myReconstructRemovedConnections << " oldLinks:\n";
std::cout << " reconstructLogic added=" << myReconstructAddedConnections << " removed=" << myReconstructRemovedConnections << " valid=" << hasValidIndices() << " oldLinks:\n";
for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); ++it) {
std::cout << " " << *it << "\n";
}
#endif
if (myReconstructAddedConnections) {
myReconstructAddedConnections = false;
// do not rebuild the logic when running netedit and all links are already covered by the program
if (!myPhasesLoaded && (!netedit || getMaxIndex() >= myTLLogic->getNumLinks())) {
if (!myPhasesLoaded && !(netedit && hasValidIndices())) {
// rebuild the logic from scratch
// XXX if a connection with the same from- and to-edge already exisits, its states could be copied instead
NBOwnTLDef dummy(DummyID, myControlledNodes, 0, TLTYPE_STATIC);
Expand All @@ -463,6 +468,13 @@ NBLoadedSUMOTLDef::reconstructLogic() {
newLogic->setType(getType());
newLogic->setOffset(getOffset());
setTLControllingInformation();
// reset crossing custom indices
for (NBNode* n : myControlledNodes) {
for (NBNode::Crossing* c : n->getCrossings()) {
c->customTLIndex = NBConnection::InvalidTlIndex;
}
}

}
} else {
setTLControllingInformation();
Expand All @@ -485,7 +497,7 @@ NBLoadedSUMOTLDef::reconstructLogic() {
const int removed = con.getTLIndex();
it = myControlledLinks.erase(it);
// no automatic modificaions when running netedit
if (!myPhasesLoaded && !netedit) {
if (!myPhasesLoaded && !(netedit && hasValidIndices())) {
// shift index off successive connections and remove entry from all phases if the tlIndex was only used by this connection
bool exclusive = true;
for (NBConnection& other : myControlledLinks) {
Expand Down Expand Up @@ -550,6 +562,23 @@ NBLoadedSUMOTLDef::getMaxIndex() const {
return maxIndex;
}

bool
NBLoadedSUMOTLDef::hasValidIndices() const {
for (const NBConnection& c : myControlledLinks) {
if (c.getTLIndex() == NBConnection::InvalidTlIndex) {
return false;
}
}
for (NBNode* n : myControlledNodes) {
for (NBNode::Crossing* c : n->getCrossings()) {
if (c->tlLinkIndex == NBConnection::InvalidTlIndex) {
return false;
}
}
}
return getMaxIndex() < myTLLogic->getNumLinks();
}


bool
NBLoadedSUMOTLDef::cleanupStates() {
Expand Down
3 changes: 3 additions & 0 deletions src/netbuild/NBLoadedSUMOTLDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ class NBLoadedSUMOTLDef : public NBTrafficLightDefinition {

/// @brief return the highest known tls link index used by any controlled connection or crossing
int getMaxIndex() const;

/// @brief return whether all tls link indices are valid
bool hasValidIndices() const;

private:
/// @brief class for identifying connections
Expand Down
6 changes: 6 additions & 0 deletions src/netedit/GNEJunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,12 @@ GNEJunction::invalidateTLS(GNEUndoList* undoList, const NBConnection& deletedCon
repl->removeConnection(deletedConnection);
replacementDef = repl;
} else if (addedConnection != NBConnection::InvalidConnection) {
if (addedConnection.getTLIndex() == NBConnection::InvalidTlIndex) {
// custom tl indices of crossings might become invalid upon recomputation so we must save them
for (GNECrossing* c : myGNECrossings) {
undoList->add(new GNEChange_Attribute(c, SUMO_ATTR_TLLINKINDEX, toString(NBConnection::InvalidTlIndex)), true);
}
}
NBLoadedSUMOTLDef* repl = new NBLoadedSUMOTLDef(tlDef, tlDef->getLogic());
repl->addConnection(addedConnection.getFrom(), addedConnection.getTo(),
addedConnection.getFromLane(), addedConnection.getToLane(), addedConnection.getTLIndex());
Expand Down

0 comments on commit 08ab7e7

Please sign in to comment.