Skip to content

Commit

Permalink
fixing traffic light reguessing, removing redundant method, refs #1109,
Browse files Browse the repository at this point in the history
#12

git-svn-id: file:///home/behr_mi/git/sumo_synched/trunk@15520 afbd958f-9f77-42d5-a016-97a22340ccf4
  • Loading branch information
behrisch committed Jan 28, 2014
1 parent 9663e6b commit 5f1a47d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
28 changes: 10 additions & 18 deletions sumo/src/netbuild/NBNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,28 +288,20 @@ NBNode::isJoinedTLSControlled() const {
void
NBNode::invalidateTLS(NBTrafficLightLogicCont& tlCont) {
if (isTLControlled()) {
std::set<NBTrafficLightDefinition*> newDefs;
for (std::set<NBTrafficLightDefinition*>::iterator it = myTrafficLights.begin(); it != myTrafficLights.end(); ++it) {
std::set<NBTrafficLightDefinition*> oldDefs(myTrafficLights);
for (std::set<NBTrafficLightDefinition*>::iterator it = oldDefs.begin(); it != oldDefs.end(); ++it) {
NBTrafficLightDefinition* orig = *it;
if (dynamic_cast<NBOwnTLDef*>(orig) != 0) {
// this definition will be guessed anyway. no need to invalidate
newDefs.insert(orig);
} else {
const std::string new_id = orig->getID() + "_reguessed";
NBTrafficLightDefinition* newDef = new NBOwnTLDef(new_id, orig->getOffset(), orig->getType());
if (!tlCont.insert(newDef)) {
// the original definition was shared by other nodes and was already invalidated
delete newDef;
newDef = tlCont.getDefinition(new_id, orig->getProgramID());
assert(newDef != 0);
if (dynamic_cast<NBOwnTLDef*>(orig) == 0) {
NBTrafficLightDefinition* newDef = new NBOwnTLDef(orig->getID(), orig->getOffset(), orig->getType());
const std::vector<NBNode*>& nodes = orig->getNodes();
while (!nodes.empty()) {
nodes.front()->removeTrafficLight(orig);
newDef->addNode(nodes.front());
}
newDefs.insert(newDef);
tlCont.removeFully(orig->getID());
tlCont.insert(newDef);
}
}
removeTrafficLights();
for (std::set<NBTrafficLightDefinition*>::iterator it = newDefs.begin(); it != newDefs.end(); ++it) {
(*it)->addNode(this);
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions sumo/src/netbuild/NBTrafficLightDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,6 @@ class NBTrafficLightDefinition : public Named, public Parameterised {
}


// @breif returns the controlled nodes
const std::vector<NBNode*>& getControlledNodes() const {
return myControlledNodes;
}


/** @brief Returns the ProgramID
* @return The ID of the program (subID)
*/
Expand Down
2 changes: 1 addition & 1 deletion sumo/src/netbuild/NBTrafficLightLogicCont.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class NBTrafficLightLogicCont {
* name and programID exists within this container.
*
* @param[in] logic The logic to add
* @param[in] renameProgram If true, rename the program to make insertion succeed
* @param[in] forceInsert If true, rename the program to make insertion succeed
* @return Whether the logic was valid (no logic with the same id and programID is already known)
*/
bool insert(NBTrafficLightDefinition* logic, bool forceInsert = false);
Expand Down
4 changes: 2 additions & 2 deletions sumo/src/netimport/NIXMLTrafficLightsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ NIXMLTrafficLightsHandler::initTrafficLightLogic(const SUMOSAXAttributes& attrs,
assert(newDef != 0);
loadedDef = new NBLoadedSUMOTLDef(id, programID, offset, type);
// copy nodes
std::vector<NBNode*> nodes = newDef->getControlledNodes();
std::vector<NBNode*> nodes = newDef->getNodes();
for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
loadedDef->addNode(*it);
}
if (programID == NBTrafficLightDefinition::DefaultProgramID) {
// replace default Program
std::vector<NBNode*> nodes = newDef->getControlledNodes();
std::vector<NBNode*> nodes = newDef->getNodes();
for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
(*it)->removeTrafficLight(newDef);
}
Expand Down

0 comments on commit 5f1a47d

Please sign in to comment.