59 #ifdef CHECK_MEMORY_LEAKS
61 #endif // CHECK_MEMORY_LEAKS
80 NodeCont::iterator i =
myNodes.find(
id);
92 NodeCont::iterator i =
myNodes.find(
id);
104 std::pair<SUMOReal, SUMOReal> ret(-1.0, -1.0);
105 NodeCont::iterator i =
myNodes.find(
id);
107 return (*i).second->getPosition();
118 std::string
id = node->
getID();
119 NodeCont::iterator i =
myNodes.find(
id);
130 NodeCont::const_iterator i =
myNodes.find(
id);
140 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
141 NBNode* node = (*i).second;
182 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
183 no += (*i).second->removeSelfLoops(dc, ec, tc);
197 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
199 std::map<NBNode*, EdgeVector> connectionCount;
200 const EdgeVector& outgoing = (*i).second->getOutgoingEdges();
201 for (EdgeVector::const_iterator j = outgoing.begin(); j != outgoing.end(); j++) {
204 if (connectionCount.find(connected) == connectionCount.end()) {
207 connectionCount[connected].push_back(e);
210 std::map<NBNode*, EdgeVector>::iterator k;
211 for (k = connectionCount.begin(); k != connectionCount.end(); k++) {
213 if ((*k).second.size() < 2) {
219 const NBEdge*
const first = ev.front();
220 EdgeVector::const_iterator jci;
221 for (jci = ev.begin() + 1; jci != ev.end(); ++jci) {
224 (relativeLengthDifference > lengthThreshold) ||
225 (first->
getSpeed() != (*jci)->getSpeed())
233 if (jci == ev.end()) {
246 const std::vector<std::string>& edgeNames = ec.
getAllNames();
247 for (std::vector<std::string>::const_iterator it = edgeNames.begin(); it != edgeNames.end(); ++it) {
256 if (outgoingEdges.size() != 1) {
261 if (incomingEdges.size() > 1) {
264 }
else if (incomingEdges.size() == 1) {
265 NBNode* fromNodeOfIncomingEdge = incomingEdges[0]->getFromNode();
266 NBNode* toNodeOfOutgoingEdge = outgoingEdges[0]->getToNode();
267 if (fromNodeOfIncomingEdge != toNodeOfOutgoingEdge) {
275 bool hasJunction =
false;
279 std::set<NBNode*> adjacentNodes;
287 adjacentNodes.clear();
288 for (EdgeVector::const_iterator itOfOutgoings = outgoingEdgesOfToNode.begin(); itOfOutgoings != outgoingEdgesOfToNode.end(); ++itOfOutgoings) {
289 if ((*itOfOutgoings)->getToNode() != from
290 && (*itOfOutgoings)->getToNode() != to
294 adjacentNodes.insert((*itOfOutgoings)->getToNode());
296 for (EdgeVector::const_iterator itOfIncomings = incomingEdgesOfToNode.begin(); itOfIncomings != incomingEdgesOfToNode.end(); ++itOfIncomings) {
297 adjacentNodes.insert((*itOfIncomings)->getFromNode());
299 adjacentNodes.erase(to);
300 if (adjacentNodes.size() > 2) {
303 }
while (!hasJunction && eOld != e);
305 edgeCounter +=
int(road.size());
306 std::string warningString =
"Removed a road without junctions: ";
307 for (EdgeVector::iterator roadIt = road.begin(); roadIt != road.end(); ++roadIt) {
308 if (roadIt == road.begin()) {
309 warningString += (*roadIt)->getID();
311 warningString +=
", " + (*roadIt)->getID();
314 NBNode* fromNode = (*roadIt)->getFromNode();
315 NBNode* toNode = (*roadIt)->getToNode();
316 ec.
erase(dc, *roadIt);
330 WRITE_WARNING(
"Detected isolated roads. Use the option --remove-edges.isolated to get a list of all affected edges.");
338 bool removeGeometryNodes) {
340 std::vector<NBNode*> toRemove;
341 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
342 NBNode* current = (*i).second;
344 std::vector<std::pair<NBEdge*, NBEdge*> > toJoin;
351 if (removeGeometryNodes) {
367 for (std::vector<std::pair<NBEdge*, NBEdge*> >::iterator j = toJoin.begin(); j != toJoin.end(); j++) {
369 NBEdge* continuation = (*j).second;
370 begin->
append(continuation);
374 ec.
erase(dc, continuation);
376 toRemove.push_back(current);
380 for (std::vector<NBNode*>::iterator j = toRemove.begin(); j != toRemove.end(); ++j) {
390 std::set<NBNode*> visited;
391 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
392 std::vector<NBNode*> toProc;
393 if (visited.find((*i).second) != visited.end()) {
396 toProc.push_back((*i).second);
398 while (!toProc.empty()) {
399 NBNode* n = toProc.back();
401 if (visited.find(n) != visited.end()) {
407 for (EdgeVector::const_iterator j = edges.begin(); j != edges.end(); ++j) {
415 if (visited.find(s) != visited.end()) {
433 for (std::vector<std::string>::const_iterator it = ids.begin(); it != ids.end(); it++) {
437 WRITE_WARNING(
"Ignoring join exclusion for node '" + *it +
"' since it already occured in a list of nodes to be joined");
438 }
else if (check &&
retrieve(*it) == 0) {
439 WRITE_WARNING(
"Ignoring join exclusion for unknown node '" + *it +
"'");
450 for (std::set<std::string>::const_iterator it = cluster.begin(); it != cluster.end(); it++) {
452 WRITE_WARNING(
"Ignoring join-cluster because node '" + *it +
"' was already excluded from joining");
454 }
else if (
myJoined.count(*it) > 0) {
455 WRITE_WARNING(
"Ignoring join-cluster because node '" + *it +
"' already occured in another join-cluster");
470 std::set<NBNode*> cluster;
471 for (std::set<std::string>::iterator it_id = it->begin(); it_id != it->end(); it_id++) {
474 WRITE_WARNING(
"Ignoring unknown node '" + *it_id +
"' while joining");
476 cluster.insert(node);
479 if (cluster.size() > 1) {
480 clusters.push_back(cluster);
485 return (
int)clusters.size();
494 for (NodeClusters::iterator i = cands.begin(); i != cands.end(); ++i) {
495 std::set<NBNode*> cluster = (*i);
497 for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end();) {
498 std::set<NBNode*>::iterator check = j;
501 cluster.erase(check);
505 bool pruneFringe =
true;
506 while (pruneFringe) {
508 for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end();) {
509 std::set<NBNode*>::iterator check = j;
520 cluster.erase(check);
525 if (cluster.size() > 1) {
528 std::set<NBEdge*> finalIncoming;
529 std::vector<std::string> nodeIDs;
530 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
531 nodeIDs.push_back((*j)->getID());
532 const EdgeVector& edges = (*j)->getIncomingEdges();
533 for (EdgeVector::const_iterator it_edge = edges.begin(); it_edge != edges.end(); ++it_edge) {
537 finalIncoming.insert(edge);
542 if (finalIncoming.size() > 4) {
543 std::sort(nodeIDs.begin(), nodeIDs.end());
546 clusters.push_back(cluster);
551 return (
int)clusters.size();
558 for (NodeClusters::iterator i = clusters.begin(); i != clusters.end(); ++i) {
559 std::set<NBNode*> cluster = *i;
560 assert(cluster.size() > 1);
577 throw ProcessError(
"Could not allocate tls '" +
id +
"'.");
581 std::set<NBEdge*> allEdges;
582 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
584 allEdges.insert(edges.begin(), edges.end());
588 for (std::set<NBEdge*>::iterator j = allEdges.begin(); j != allEdges.end();) {
592 if (cluster.count(from) > 0 && cluster.count(to) > 0) {
593 for (std::set<NBEdge*>::iterator l = allEdges.begin(); l != allEdges.end(); ++l) {
606 for (std::set<NBEdge*>::iterator j = allEdges.begin(); j != allEdges.end(); ++j) {
609 const bool outgoing = cluster.count(e->
getFromNode()) > 0;
615 for (std::vector<NBEdge::Connection>::iterator k = conns.begin(); k != conns.end(); ++k) {
621 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
630 std::set<std::string> ids;
631 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); j++) {
632 ids.insert((*j)->getID());
643 std::vector<std::string> member_ids;
644 bool ambiguousType =
false;
645 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); j++) {
646 member_ids.push_back((*j)->getID());
647 pos.
add((*j)->getPosition());
649 if ((*j)->isTLControlled()) {
652 type = (*(*j)->getControllingTLS().begin())->getType();
653 }
else if (type != (*(*j)->getControllingTLS().begin())->getType()) {
654 ambiguousType =
true;
659 pos.
mul(1.0 / cluster.size());
661 sort(member_ids.begin(), member_ids.end());
662 for (std::vector<std::string>::iterator j = member_ids.begin(); j != member_ids.end(); j++) {
663 id =
id +
"_" + (*j);
667 WRITE_WARNING(
"Ambiguous traffic light type for node cluster '" +
id +
"' set to '" +
toString(type) +
"'");
675 unsigned int noIncoming = 0;
676 unsigned int noOutgoing = 0;
677 bool tooFast =
false;
679 std::set<NBEdge*> seen;
680 for (std::set<NBNode*>::const_iterator j = c.begin(); j != c.end(); ++j) {
682 for (EdgeVector::const_iterator k = edges.begin(); k != edges.end(); ++k) {
683 if (c.find((*k)->getFromNode()) != c.end() && c.find((*k)->getToNode()) != c.end()) {
686 if ((*j)->hasIncoming(*k)) {
688 f += (
SUMOReal)(*k)->getNumLanes() * (*k)->getLaneSpeed(0);
692 if ((*k)->getLaneSpeed(0) * 3.6 > 79) {
697 return !tooFast && f >= 150. / 3.6 && c.size() != 0;
704 std::vector<NBNode*> ncontrolled;
705 if (oc.
isSet(
"tls.unset")) {
706 std::vector<std::string> notTLControlledNodes = oc.
getStringVector(
"tls.unset");
707 for (std::vector<std::string>::const_iterator i = notTLControlledNodes.begin(); i != notTLControlledNodes.end(); ++i) {
710 throw ProcessError(
" The node '" + *i +
"' to set as not-controlled is not known.");
713 for (std::set<NBTrafficLightDefinition*>::const_iterator j = tls.begin(); j != tls.end(); ++j) {
717 ncontrolled.push_back(n);
724 if (oc.
exists(
"tls.taz-nodes") && oc.
getBool(
"tls.taz-nodes")) {
725 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
726 NBNode* cur = (*i).second;
727 if (cur->
isNearDistrict() && find(ncontrolled.begin(), ncontrolled.end(), cur) == ncontrolled.end()) {
734 if (!oc.
getBool(
"tls.guess")) {
741 std::vector<std::set<NBNode*> > cands;
744 for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end();) {
745 std::set<NBNode*>& c = (*i);
748 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
749 if ((*j)->isTLControlled() || find(ncontrolled.begin(), ncontrolled.end(), *j) != ncontrolled.end()) {
763 unsigned int index = 0;
764 for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
765 std::vector<NBNode*> nodes;
766 for (std::set<NBNode*>::iterator j = (*i).begin(); j != (*i).end(); j++) {
769 std::string
id =
"joinedG_" +
toString(index++);
781 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
782 NBNode* cur = (*i).second;
788 if (find(ncontrolled.begin(), ncontrolled.end(), cur) != ncontrolled.end()) {
803 std::vector<std::set<NBNode*> > cands;
805 unsigned int index = 0;
806 for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
807 std::set<NBNode*>& c = (*i);
808 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
809 if (!(*j)->isTLControlled()) {
824 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); ++j) {
825 std::set<NBTrafficLightDefinition*> tls = (*j)->getControllingTLS();
826 (*j)->removeTrafficLights();
827 for (std::set<NBTrafficLightDefinition*>::iterator k = tls.begin(); k != tls.end(); ++k) {
831 std::string
id =
"joinedS_" +
toString(index++);
832 std::vector<NBNode*> nodes;
833 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); j++) {
856 WRITE_WARNING(
"Building a tl-logic for node '" +
id +
"' twice is not possible.");
866 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
867 (*i).second->computeLanes2Lanes();
875 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
876 (*i).second->computeLogic(ec, oc);
883 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
897 std::string ret =
"SUMOGenerated" + toString<int>(
size());
905 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
906 (*i).second->computeNodeShape(leftHand);
913 int numUnregulatedJunctions = 0;
914 int numDeadEndJunctions = 0;
915 int numPriorityJunctions = 0;
916 int numRightBeforeLeftJunctions = 0;
917 int numAllWayStopJunctions = 0;
918 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
919 switch ((*i).second->getType()) {
922 ++numUnregulatedJunctions;
925 ++numDeadEndJunctions;
930 ++numPriorityJunctions;
933 ++numRightBeforeLeftJunctions;
936 ++numAllWayStopJunctions;
939 ++numRightBeforeLeftJunctions;
949 if (numDeadEndJunctions > 0) {
954 if (numAllWayStopJunctions > 0) {
960 std::vector<std::string>
962 std::vector<std::string> ret;
963 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); ++i) {
964 ret.push_back((*i).first);
972 if (
myNodes.count(newID) != 0) {
973 throw ProcessError(
"Attempt to rename node using existing id '" + newID +
"'");
983 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); ++i) {
988 for (std::set<NBTrafficLightDefinition*>::const_iterator it = tldefs.begin(); it != tldefs.end(); ++it) {
std::set< std::string > myJoinExclusions
NodeCont myNodes
The map of names to nodes.
void joinSimilarEdges(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins edges connecting the same nodes.
void replaceIncoming(NBEdge *which, NBEdge *by, unsigned int laneOff)
Replaces occurences of the first edge within the list of incoming by the second Connections are remap...
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges.
void removeSelfLoops(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tc)
Removes self-loop edges (edges where the source and the destination node are the same) ...
bool insert(const std::string &id, const Position &position, NBDistrict *district)
Inserts a node into the map.
std::vector< std::string > getAllNames() const
Returns all ids of known edges.
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
void add(const Position &pos)
Adds the given position to this one.
unsigned int removeUnwishedNodes(NBDistrictCont &dc, NBEdgeCont &ec, NBJoinedEdgesMap &je, NBTrafficLightLogicCont &tlc, bool removeGeometryNodes)
Removes "unwished" nodes.
A container for traffic light definitions and built programs.
void reinit(const Position &position, SumoXMLNodeType type, bool updateEdgeGeometries=false)
Resets initial values.
bool isTLControlled() const
Returns whether this node is controlled by any tls.
std::vector< std::set< std::string > > myJoinedClusters
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
The representation of a single edge during network building.
void reinitNodes(NBNode *from, NBNode *to)
Resets nodes but keeps all other values the same (used when joining)
A container for districts.
The base class for traffic light logic definitions.
bool addLane2LaneConnection(unsigned int fromLane, NBEdge *dest, unsigned int toLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false)
Adds a connection between the specified this edge's lane and an approached one.
unsigned int joinJunctions(SUMOReal maxdist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins junctions that are very close together.
void guessTLs(OptionsCont &oc, NBTrafficLightLogicCont &tlc)
Guesses which junctions or junction clusters shall be controlled by tls.
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
bool checkIsRemovable() const
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
Removes the given traffic light from this node.
void extract(NBTrafficLightDefinition *definition)
Extracts a traffic light definition from myDefinitions but keeps it in myExtracted for eventual * del...
bool hasIncoming(const NBEdge *const e) const
Returns whether the given edge ends at this node.
SUMOReal x() const
Returns the x-position.
#define UNUSED_PARAMETER(x)
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
void computeLogics(const NBEdgeCont &ec, OptionsCont &oc)
build the list of outgoing edges and lanes
void generateNodeClusters(SUMOReal maxDist, NodeClusters &into) const
Builds node clusters.
A class representing a single district.
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges.
SUMOReal getLoadedLength() const
Returns the length was set explicitly or the computed length if it wasn't set.
const std::string & getID() const
Returns the id.
unsigned int size() const
Returns the number of known nodes.
const Position & getPosition() const
Returns the position of this node.
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node.
void computeLanes2Lanes()
divides the incoming lanes on outgoing lanes
void joinTLS(NBTrafficLightLogicCont &tlc, SUMOReal maxdist)
Builds clusters of tls-controlled junctions and joins the control if possible.
static StringBijection< TrafficLightType > TrafficLightTypes
A point in 2D or 3D with translation and scaling methods.
unsigned int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
bool geometryLike() const
whether this is structurally similar to a geometry node
void removeTrafficLights()
Removes all references to traffic lights that control this tls.
const EdgeVector & getEdges() const
Returns all edges which participate in this node.
Storage for edges, including some functionality operating on multiple edges.
void joinNodeClusters(NodeClusters clusters, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
std::set< NBNode * > myExtractedNodes
The extracted nodes which are kept for reference.
std::vector< std::string > getAllNames() const
get all node names
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
The connection was given by the user.
bool shouldBeTLSControlled(const std::set< NBNode * > &c) const
Returns whethe the given node cluster should be controlled by a tls.
void rename(NBNode *node, const std::string &newID)
Renames the node. Throws exception if newID already exists.
std::vector< std::pair< NBEdge *, NBEdge * > > getEdgesToJoin() const
void joinSameNodeConnectingEdges(NBDistrictCont &dc, NBTrafficLightLogicCont &tlc, EdgeVector edges)
Joins the given edges because they connect the same nodes.
void setAsTLControlled(NBNode *node, NBTrafficLightLogicCont &tlc, TrafficLightType type, std::string id="")
Sets the given node as being controlled by a tls.
T get(const std::string &str)
NBNode * getToNode() const
Returns the destination node of the edge.
bool isNearDistrict() const
void setID(const std::string &newID)
resets the id
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
void addCluster2Join(std::set< std::string > cluster)
add ids of nodes which shall be joined into a single node
A structure storing information about which edges were joined.
std::vector< NBEdge * > EdgeVector
void analyzeCluster(std::set< NBNode * > cluster, std::string &id, Position &pos, bool &hasTLS, TrafficLightType &type)
void removeIsolatedRoads(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tc)
Removes sequences of edges that are not connected with a junction. Simple roads without junctions som...
std::set< std::string > myJoined
ids found in loaded join clusters used for error checking
SUMOReal y() const
Returns the y-position.
A storage for options typed value containers)
std::vector< std::set< NBNode * > > NodeClusters
Definition of a node cluster container.
void erase(NBDistrictCont &dc, NBEdge *edge)
Removes the given edge from the container (deleting it)
void computeNodeShapes(bool leftHand)
void mul(SUMOReal val)
Multiplies both positions with the given value.
void append(NBEdge *continuation)
std::vector< std::set< std::string > > myClusters2Join
Represents a single node (junction) during network building.
bool removeFully(const std::string id)
Removes a logic definition (and all programs) from the dictionary.
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
bool isNearEnough2BeJoined2(NBEdge *e, SUMOReal threshold) const
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
SUMOReal getSpeed() const
Returns the speed allowed on this edge.
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces occurences of the removed edge/lane in all definitions by the given edge.
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike)
A traffic light logics which must be computed (only nodes/edges are given)
void appended(const std::string &to, const std::string &what)
Informs the map that two edges have been joined.
bool extract(NBNode *node, bool remember=false)
Removes the given node but does not delete it.
#define WRITE_MESSAGE(msg)
bool erase(NBNode *node)
Removes the given node, deleting it.
const std::vector< Connection > & getConnections() const
Returns the connections.
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
void registerJoinedCluster(const std::set< NBNode * > &cluster)
gets all joined clusters (see doc for myClusters2Join)
NBNode * getFromNode() const
Returns the origin node of the edge.