void GNEConnectorFrame::initTargets() { // gather potential targets NBNode* nbn = myCurrentLane->getParentEdge().getGNEJunctionDestiny()->getNBNode(); const EdgeVector& outgoing = nbn->getOutgoingEdges(); for (EdgeVector::const_iterator it = outgoing.begin(); it != outgoing.end(); it++) { GNEEdge* edge = myViewNet->getNet()->retrieveEdge((*it)->getID()); const GNEEdge::LaneVector& lanes = edge->getLanes(); for (GNEEdge::LaneVector::const_iterator it_lane = lanes.begin(); it_lane != lanes.end(); it_lane++) { myPotentialTargets.insert(*it_lane); } } // set color for existing connections const int fromIndex = myCurrentLane->getIndex(); NBEdge* srcEdge = myCurrentLane->getParentEdge().getNBEdge(); std::vector<NBEdge::Connection> connections = srcEdge->getConnectionsFromLane(fromIndex); for (std::set<GNELane*>::iterator it = myPotentialTargets.begin(); it != myPotentialTargets.end(); it++) { switch (getLaneStatus(connections, *it)) { case CONNECTED: (*it)->setSpecialColor(&targetColor); break; case CONNECTED_PASS: (*it)->setSpecialColor(&targetPassColor); break; case CONFLICTED: (*it)->setSpecialColor(&conflictColor); break; case UNCONNECTED: (*it)->setSpecialColor(&potentialTargetColor); break; } } }
long GNEConnectorFrame::onCmdSelectDeadStarts(FXObject*, FXSelector, void*) { GNENet* net = myViewNet->getNet(); std::set<GUIGlID> selectIDs; // every edge knows only its outgoing connections so we look at whole junctions const std::vector<GNEJunction*> junctions = net->retrieveJunctions(); for (std::vector<GNEJunction*>::const_iterator junction_it = junctions.begin(); junction_it != junctions.end(); junction_it++) { // first collect all outgoing lanes const EdgeVector& outgoing = (*junction_it)->getNBNode()->getOutgoingEdges(); for (EdgeVector::const_iterator it = outgoing.begin(); it != outgoing.end(); it++) { GNEEdge* edge = net->retrieveEdge((*it)->getID()); const std::set<GUIGlID> laneIDs = edge->getLaneGlIDs(); for (std::set<GUIGlID>::const_iterator lid_it = laneIDs.begin(); lid_it != laneIDs.end(); lid_it++) { selectIDs.insert(*lid_it); } } // then remove all approached lanes const EdgeVector& incoming = (*junction_it)->getNBNode()->getIncomingEdges(); for (EdgeVector::const_iterator it = incoming.begin(); it != incoming.end(); it++) { GNEEdge* edge = net->retrieveEdge((*it)->getID()); NBEdge* nbe = edge->getNBEdge(); const std::vector<NBEdge::Connection>& connections = nbe->getConnections(); for (std::vector<NBEdge::Connection>::const_iterator con_it = connections.begin(); con_it != connections.end(); con_it++) { GNEEdge* approachedEdge = net->retrieveEdge(con_it->toEdge->getID()); GNELane* approachedLane = approachedEdge->getLanes()[con_it->toLane]; selectIDs.erase(approachedLane->getGlID()); } } } myViewNet->getViewParent()->getSelectorFrame()->handleIDs( std::vector<GUIGlID>(selectIDs.begin(), selectIDs.end()), false, GNESelectorFrame::SET_REPLACE); return 1; }
bool NIImporter_DlrNavteq::TrafficlightsHandler::report(const std::string& result) { // #ID POICOL-TYPE DESCRIPTION LONGITUDE LATITUDE NAVTEQ_LINK_ID NODEID if (result[0] == '#') { return true; } StringTokenizer st(result, StringTokenizer::WHITECHARS); const std::string edgeID = st.get(5); NBEdge* edge = myEdgeCont.retrieve(edgeID); if (edge == nullptr) { WRITE_WARNING("The traffic light edge '" + edgeID + "' could not be found"); } else { NBNode* node = edge->getToNode(); if (node->getType() != NODETYPE_TRAFFIC_LIGHT) { node->reinit(node->getPosition(), NODETYPE_TRAFFIC_LIGHT); // @note. There may be additional information somewhere in the GDF files about traffic light type ... TrafficLightType type = SUMOXMLDefinitions::TrafficLightTypes.get(OptionsCont::getOptions().getString("tls.default-type")); // @note actually we could use the navteq node ID here NBTrafficLightDefinition* tlDef = new NBOwnTLDef(node->getID(), node, 0, type); if (!myTLLogicCont.insert(tlDef)) { // actually, nothing should fail here delete tlDef; throw ProcessError("Could not allocate tls for '" + node->getID() + "'."); } } } return true; }
void NWWriter_DlrNavteq::writeConnectedLanes(const OptionsCont& oc, NBNodeCont& nc) { OutputDevice& device = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_connected_lanes.txt"); writeHeader(device, oc); // write format specifier device << "#Lane connections related to LINK-IDs and NODE-ID.\n"; device << "#column format like pointcollection.\n"; device << "#NODE-ID\tVEHICLE-TYPE\tFROM_LANE\tTO_LANE\tTHROUGH_TRAFFIC\tLINK_IDs[2..*]\n"; // write record for every connection for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { NBNode* n = (*i).second; const EdgeVector& incoming = n->getIncomingEdges(); for (EdgeVector::const_iterator j = incoming.begin(); j != incoming.end(); ++j) { NBEdge* from = *j; const SVCPermissions fromPerm = from->getPermissions(); const std::vector<NBEdge::Connection>& connections = from->getConnections(); for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); it_c++) { const NBEdge::Connection& c = *it_c; device << n->getID() << "\t" << getAllowedTypes(fromPerm & c.toEdge->getPermissions()) << "\t" << c.fromLane + 1 << "\t" // one-based << c.toLane + 1 << "\t" // one-based << 1 << "\t" // no information regarding permissibility of through traffic << from->getID() << "\t" << c.toEdge->getID() << "\t" << "\n"; } } } device.close(); }
void NWWriter_DlrNavteq::writeTrafficSignals(const OptionsCont& oc, NBNodeCont& nc) { OutputDevice& device = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_traffic_signals.txt"); writeHeader(device, oc); const GeoConvHelper& gch = GeoConvHelper::getFinal(); const bool haveGeo = gch.usingGeoProjection(); const SUMOReal geoScale = pow(10.0f, haveGeo ? 5 : 2); // see NIImporter_DlrNavteq::GEO_SCALE device.setPrecision(0); // write format specifier device << "#Traffic signal related to LINK_ID and NODE_ID with location relative to driving direction.\n#column format like pointcollection.\n#DESCRIPTION->LOCATION: 1-rechts von LINK; 2-links von LINK; 3-oberhalb LINK -1-keineAngabe\n#RELATREC_ID\tPOICOL_TYPE\tDESCRIPTION\tLONGITUDE\tLATITUDE\tLINK_ID\n"; // write record for every edge incoming to a tls controlled node for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { NBNode* n = (*i).second; if (n->isTLControlled()) { Position pos = n->getPosition(); gch.cartesian2geo(pos); pos.mul(geoScale); const EdgeVector& incoming = n->getIncomingEdges(); for (EdgeVector::const_iterator it = incoming.begin(); it != incoming.end(); ++it) { NBEdge* e = *it; device << e->getID() << "\t" << "12\t" // POICOL_TYPE << "LSA;NODEIDS#" << n->getID() << "#;LOCATION#-1#;\t" << pos.x() << "\t" << pos.y() << "\t" << e->getID() << "\n"; } } } }
void GNEJunction::setLogicValid(bool valid, GNEUndoList* undoList, const std::string& status) { myHasValidLogic = valid; if (!valid) { assert(undoList != 0); assert(undoList->hasCommandGroup()); undoList->add(new GNEChange_Attribute(this, GNE_ATTR_MODIFICATION_STATUS, status)); // allow edges to recompute their connections NBTurningDirectionsComputer::computeTurnDirectionsForNode(&myNBNode, false); EdgeVector incoming = EdgeVector(myNBNode.getIncomingEdges()); for (EdgeVector::iterator it = incoming.begin(); it != incoming.end(); it++) { NBEdge* srcNBE = *it; NBEdge* turnEdge = srcNBE->getTurnDestination(); GNEEdge* srcEdge = myNet->retrieveEdge(srcNBE->getID()); std::vector<NBEdge::Connection> connections = srcNBE->getConnections(); // make a copy! // delete in reverse so that undoing will add connections in the original order for (std::vector<NBEdge::Connection>::reverse_iterator con_it = connections.rbegin(); con_it != connections.rend(); con_it++) { bool hasTurn = con_it->toEdge == turnEdge; undoList->add(new GNEChange_Connection( srcEdge, con_it->fromLane, con_it->toEdge->getID(), con_it->toLane, con_it->mayDefinitelyPass, false), true); // needs to come after GNEChange_Connection // XXX bug: this code path will not be used on a redo! if (hasTurn) { myNet->addExplicitTurnaround(srcNBE->getID()); } } undoList->add(new GNEChange_Attribute(srcEdge, GNE_ATTR_MODIFICATION_STATUS, status), true); } invalidateTLS(undoList); } else { rebuildCrossings(false); } }
void NWWriter_SUMO::writeConnection(OutputDevice& into, const NBEdge& from, const NBEdge::Connection& c, bool includeInternal, ConnectionStyle style) { assert(c.toEdge != 0); into.openTag(SUMO_TAG_CONNECTION); into.writeAttr(SUMO_ATTR_FROM, from.getID()); into.writeAttr(SUMO_ATTR_TO, c.toEdge->getID()); into.writeAttr(SUMO_ATTR_FROM_LANE, c.fromLane); into.writeAttr(SUMO_ATTR_TO_LANE, c.toLane); if (c.mayDefinitelyPass) { into.writeAttr(SUMO_ATTR_PASS, c.mayDefinitelyPass); } if (style != PLAIN) { if (includeInternal) { into.writeAttr(SUMO_ATTR_VIA, c.id + "_0"); } // set information about the controlling tl if any if (c.tlID != "") { into.writeAttr(SUMO_ATTR_TLID, c.tlID); into.writeAttr(SUMO_ATTR_TLLINKINDEX, c.tlLinkNo); } if (style == SUMONET) { // write the direction information LinkDirection dir = from.getToNode()->getDirection(&from, c.toEdge); assert(dir != LINKDIR_NODIR); into.writeAttr(SUMO_ATTR_DIR, toString(dir)); // write the state information const LinkState linkState = from.getToNode()->getLinkState( &from, c.toEdge, c.toLane, c.mayDefinitelyPass, c.tlID); into.writeAttr(SUMO_ATTR_STATE, linkState); } } into.closeTag(); }
long GNEConnectorFrame::onCmdSelectConflicts(FXObject*, FXSelector, void*) { std::vector<GUIGlID> selectIDs; // conflicts happen per edge so we can look at each edge in isolation const std::vector<GNEEdge*> edges = myViewNet->getNet()->retrieveEdges(); for (std::vector<GNEEdge*>::const_iterator edge_it = edges.begin(); edge_it != edges.end(); edge_it++) { NBEdge* nbe = (*edge_it)->getNBEdge(); const EdgeVector destinations = nbe->getConnectedEdges(); const std::vector<NBEdge::Connection>& connections = nbe->getConnections(); for (EdgeVector::const_iterator dest_it = destinations.begin(); dest_it != destinations.end(); dest_it++) { GNEEdge* dest = myViewNet->getNet()->retrieveEdge((*dest_it)->getID()); const GNEEdge::LaneVector& destLanes = dest->getLanes(); for (GNEEdge::LaneVector::const_iterator it_lane = destLanes.begin(); it_lane != destLanes.end(); it_lane++) { const bool isConflicted = count_if( connections.begin(), connections.end(), NBEdge::connections_toedgelane_finder(*dest_it, (int)(*it_lane)->getIndex(), -1)) > 1; if (isConflicted) { selectIDs.push_back((*it_lane)->getGlID()); } } } } myViewNet->getViewParent()->getSelectorFrame()->handleIDs(selectIDs, false, GNESelectorFrame::SET_REPLACE); return 1; }
// =========================================================================== // method definitions // =========================================================================== // --------------------------------------------------------------------------- // NBRampsComputer // --------------------------------------------------------------------------- void NBRampsComputer::computeRamps(NBNetBuilder& nb, OptionsCont& oc) { SUMOReal minHighwaySpeed = oc.getFloat("ramps.min-highway-speed"); SUMOReal maxRampSpeed = oc.getFloat("ramps.max-ramp-speed"); SUMOReal rampLength = oc.getFloat("ramps.ramp-length"); bool dontSplit = oc.getBool("ramps.no-split"); std::set<NBEdge*> incremented; // check whether on-off ramps shall be guessed if (oc.getBool("ramps.guess")) { NBNodeCont& nc = nb.getNodeCont(); NBEdgeCont& ec = nb.getEdgeCont(); NBDistrictCont& dc = nb.getDistrictCont(); std::set<NBNode*> potOnRamps; std::set<NBNode*> potOffRamps; for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { NBNode* cur = (*i).second; if (mayNeedOnRamp(cur, minHighwaySpeed, maxRampSpeed)) { potOnRamps.insert(cur); } if (mayNeedOffRamp(cur, minHighwaySpeed, maxRampSpeed)) { potOffRamps.insert(cur); } } for (std::set<NBNode*>::const_iterator i = potOnRamps.begin(); i != potOnRamps.end(); ++i) { buildOnRamp(*i, nc, ec, dc, rampLength, dontSplit, incremented); } for (std::set<NBNode*>::const_iterator i = potOffRamps.begin(); i != potOffRamps.end(); ++i) { buildOffRamp(*i, nc, ec, dc, rampLength, dontSplit, incremented); } } // check whether on-off ramps shall be guessed if (oc.isSet("ramps.set")) { std::vector<std::string> edges = oc.getStringVector("ramps.set"); NBNodeCont& nc = nb.getNodeCont(); NBEdgeCont& ec = nb.getEdgeCont(); NBDistrictCont& dc = nb.getDistrictCont(); for (std::vector<std::string>::iterator i = edges.begin(); i != edges.end(); ++i) { NBEdge* e = ec.retrieve(*i); if (e == 0) { WRITE_WARNING("Can not build on ramp on edge '" + *i + "' - the edge is not known."); continue; } NBNode* from = e->getFromNode(); if (from->getIncomingEdges().size() == 2 && from->getOutgoingEdges().size() == 1) { buildOnRamp(from, nc, ec, dc, rampLength, dontSplit, incremented); } // load edge again to check offramps e = ec.retrieve(*i); if (e == 0) { WRITE_WARNING("Can not build off ramp on edge '" + *i + "' - the edge is not known."); continue; } NBNode* to = e->getToNode(); if (to->getIncomingEdges().size() == 1 && to->getOutgoingEdges().size() == 2) { buildOffRamp(to, nc, ec, dc, rampLength, dontSplit, incremented); } } } }
void NIImporter_ArcView::checkSpread(NBEdge* e) { NBEdge* ret = e->getToNode()->getConnectionTo(e->getFromNode()); if (ret != 0) { e->setLaneSpreadFunction(LANESPREAD_RIGHT); ret->setLaneSpreadFunction(LANESPREAD_RIGHT); } }
NBEdge* NBEdgePriorityComputer::extractAndMarkFirst(NBNode& n, std::vector<NBEdge*>& s) { if (s.size() == 0) { return 0; } NBEdge* ret = s.front(); s.erase(s.begin()); ret->setJunctionPriority(&n, 1); return ret; }
void NBOwnTLDef::setTLControllingInformation(const NBEdgeCont&) const { // set the information about the link's positions within the tl into the // edges the links are starting at, respectively for (NBConnectionVector::const_iterator j = myControlledLinks.begin(); j != myControlledLinks.end(); ++j) { const NBConnection& conn = *j; NBEdge* edge = conn.getFrom(); edge->setControllingTLInformation(conn, getID()); } }
void NIXMLTrafficLightsHandler::addTlConnection(const SUMOSAXAttributes& attrs) { bool ok = true; // parse identifying attributes NBEdge* from = retrieveEdge(attrs, SUMO_ATTR_FROM, ok); NBEdge* to = retrieveEdge(attrs, SUMO_ATTR_TO, ok); if (!ok) { return; } int fromLane = retrieveLaneIndex(attrs, SUMO_ATTR_FROM_LANE, from, ok); int toLane = retrieveLaneIndex(attrs, SUMO_ATTR_TO_LANE, to, ok); if (!ok) { return; } // retrieve connection const std::vector<NBEdge::Connection>& connections = from->getConnections(); std::vector<NBEdge::Connection>::const_iterator con_it; con_it = find_if(connections.begin(), connections.end(), NBEdge::connections_finder(fromLane, to, toLane)); if (con_it == connections.end()) { WRITE_ERROR("Connection from=" + from->getID() + " to=" + to->getID() + " fromLane=" + toString(fromLane) + " toLane=" + toString(toLane) + " not found"); return; } NBEdge::Connection c = *con_it; // read other attributes std::string tlID = attrs.getOptStringReporting(SUMO_ATTR_TLID, 0, ok, ""); if (tlID == "") { // we are updating an existing tl-controlled connection tlID = c.tlID; assert(tlID != ""); } int tlIndex = attrs.getOptIntReporting(SUMO_ATTR_TLLINKINDEX, 0, ok, -1); if (tlIndex == -1) { // we are updating an existing tl-controlled connection tlIndex = c.tlLinkNo; } // register the connection with all definitions const std::map<std::string, NBTrafficLightDefinition*>& programs = myTLLCont.getPrograms(tlID); if (programs.size() > 0) { std::map<std::string, NBTrafficLightDefinition*>::const_iterator it; for (it = programs.begin(); it != programs.end(); it++) { NBLoadedSUMOTLDef* tlDef = dynamic_cast<NBLoadedSUMOTLDef*>(it->second); if (tlDef) { tlDef->addConnection(from, c.toEdge, c.fromLane, c.toLane, tlIndex); } else { throw ProcessError("Corrupt traffic light definition '" + tlID + "' (program '" + it->first + "')"); } } } else { WRITE_ERROR("The traffic light '" + tlID + "' is not known."); } }
unsigned int NIVissimConnection::buildEdgeConnections(NBEdgeCont &ec) { unsigned int unsetConnections = 0; // try to determine the connected edges NBEdge *fromEdge = 0; NBEdge *toEdge = 0; NIVissimEdge *vissimFrom = NIVissimEdge::dictionary(getFromEdgeID()); if (vissimFrom->wasWithinAJunction()) { // this edge was not built, try to get one that approaches it vissimFrom = vissimFrom->getBestIncoming(); if (vissimFrom!=0) { fromEdge = ec.retrievePossiblySplitted(toString(vissimFrom->getID()), toString(getFromEdgeID()), true); } } else { // this edge was built, try to get the proper part fromEdge = ec.retrievePossiblySplitted(toString(getFromEdgeID()), toString(getToEdgeID()), true); } NIVissimEdge *vissimTo = NIVissimEdge::dictionary(getToEdgeID()); if (vissimTo->wasWithinAJunction()) { vissimTo = vissimTo->getBestOutgoing(); if (vissimTo!=0) { toEdge = ec.retrievePossiblySplitted(toString(vissimTo->getID()), toString(getToEdgeID()), true); } } else { toEdge = ec.retrievePossiblySplitted(toString(getToEdgeID()), toString(getFromEdgeID()), false); } // try to get the edges the current connection connects /* NBEdge *fromEdge = ec.retrievePossiblySplitted(toString(getFromEdgeID()), toString(getToEdgeID()), true); NBEdge *toEdge = ec.retrievePossiblySplitted(toString(getToEdgeID()), toString(getFromEdgeID()), false); */ if (fromEdge==0||toEdge==0) { WRITE_WARNING("Could not build connection between '" + toString(getFromEdgeID())+ "' and '" + toString(getToEdgeID())+ "'."); return 1; // !!! actually not 1 } recheckLanes(fromEdge, toEdge); const IntVector &fromLanes = getFromLanes(); const IntVector &toLanes = getToLanes(); if (fromLanes.size()!=toLanes.size()) { MsgHandler::getWarningInstance()->inform("Lane sizes differ for connection '" + toString(getID()) + "'."); } else { for (unsigned int index=0; index<fromLanes.size(); ++index) { if (fromEdge->getNoLanes()<=static_cast<unsigned int>(fromLanes[index])) { MsgHandler::getWarningInstance()->inform("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'."); ++unsetConnections; } else if (!fromEdge->addLane2LaneConnection(fromLanes[index], toEdge, toLanes[index], NBEdge::L2L_VALIDATED)) { MsgHandler::getWarningInstance()->inform("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'."); ++unsetConnections; } } } return unsetConnections; }
bool NIImporter_DlrNavteq::ConnectedLanesHandler::report(const std::string& result) { if (result[0] == '#') { return true; } StringTokenizer st(result, StringTokenizer::TAB); if (st.size() == 1) { return true; // one line with the number of data containing lines in it (also starts with a comment # since ersion 6.5) } assert(st.size() >= 7); const std::string nodeID = st.next(); const std::string vehicleType = st.next(); const std::string fromLaneS = st.next(); const std::string toLaneS = st.next(); const std::string throughTraffic = st.next(); const std::string startEdge = st.next(); const std::string endEdge = st.get(st.size() - 1); NBEdge* from = myEdgeCont.retrieve(startEdge); if (from == nullptr) { WRITE_WARNING("Ignoring prohibition from unknown start edge '" + startEdge + "'"); return true; } NBEdge* to = myEdgeCont.retrieve(endEdge); if (to == nullptr) { WRITE_WARNING("Ignoring prohibition from unknown end edge '" + endEdge + "'"); return true; } int fromLane = StringUtils::toInt(fromLaneS) - 1; // one based if (fromLane < 0 || fromLane >= from->getNumLanes()) { WRITE_WARNING("Ignoring invalid lane index '" + fromLaneS + "' in connection from edge '" + startEdge + "' with " + toString(from->getNumLanes()) + " lanes"); return true; } int toLane = StringUtils::toInt(toLaneS) - 1; // one based if (toLane < 0 || toLane >= to->getNumLanes()) { WRITE_WARNING("Ignoring invalid lane index '" + toLaneS + "' in connection to edge '" + endEdge + "' with " + toString(to->getNumLanes()) + " lanes"); return true; } if (!from->addLane2LaneConnection(fromLane, to, toLane, NBEdge::L2L_USER, true)) { 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 // if this connection runs across a node cluster it may not be possible to set this 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, false, warnOnly); } // ensure that connections for other lanes are guessed if not specified from->declareConnectionsAsLoaded(NBEdge::INIT); from->getLaneStruct(fromLane).connectionsDone = true; return true; }
void NWWriter_DlrNavteq::writeLinksUnsplitted(const OptionsCont& oc, NBEdgeCont& ec) { std::map<const std::string, std::string> nameIDs; OutputDevice& device = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_links_unsplitted.txt"); writeHeader(device, oc); // write format specifier device << "# LINK_ID\tNODE_ID_FROM\tNODE_ID_TO\tBETWEEN_NODE_ID\tLENGTH\tVEHICLE_TYPE\tFORM_OF_WAY\tBRUNNEL_TYPE\tFUNCTIONAL_ROAD_CLASS\tSPEED_CATEGORY\tNUMBER_OF_LANES\tSPEED_LIMIT\tSPEED_RESTRICTION\tNAME_ID1_REGIONAL\tNAME_ID2_LOCAL\tHOUSENUMBERS_RIGHT\tHOUSENUMBERS_LEFT\tZIP_CODE\tAREA_ID\tSUBAREA_ID\tTHROUGH_TRAFFIC\tSPECIAL_RESTRICTIONS\tEXTENDED_NUMBER_OF_LANES\tISRAMP\tCONNECTION\n"; // write edges for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) { NBEdge* e = (*i).second; const int kph = speedInKph(e->getSpeed()); const std::string& betweenNodeID = (e->getGeometry().size() > 2) ? e->getID() : UNDEFINED; std::string nameID = UNDEFINED; if (oc.getBool("output.street-names")) { const std::string& name = i->second->getStreetName(); if (name != "" && nameIDs.count(name) == 0) { nameID = toString(nameIDs.size()); nameIDs[name] = nameID; } } device << e->getID() << "\t" << e->getFromNode()->getID() << "\t" << e->getToNode()->getID() << "\t" << betweenNodeID << "\t" << getGraphLength(e) << "\t" << getAllowedTypes(e->getPermissions()) << "\t" << "3\t" // Speed Category 1-8 XXX refine this << UNDEFINED << "\t" // no special brunnel type (we don't know yet) << getRoadClass(e) << "\t" << getSpeedCategory(kph) << "\t" << getNavteqLaneCode(e->getNumLanes()) << "\t" << getSpeedCategoryUpperBound(kph) << "\t" << kph << "\t" << nameID << "\t" // NAME_ID1_REGIONAL XXX << UNDEFINED << "\t" // NAME_ID2_LOCAL XXX << UNDEFINED << "\t" // housenumbers_right << UNDEFINED << "\t" // housenumbers_left << UNDEFINED << "\t" // ZIP_CODE << UNDEFINED << "\t" // AREA_ID << UNDEFINED << "\t" // SUBAREA_ID << "1\t" // through_traffic (allowed) << UNDEFINED << "\t" // special_restrictions << UNDEFINED << "\t" // extended_number_of_lanes << UNDEFINED << "\t" // isRamp << "0\t" // connection (between nodes always in order) << "\n"; } if (oc.getBool("output.street-names")) { OutputDevice& namesDevice = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_names.txt"); writeHeader(namesDevice, oc); // write format specifier namesDevice << "# NAME_ID\tName\n" << nameIDs.size() << "\n"; for (std::map<const std::string, std::string>::const_iterator i = nameIDs.begin(); i != nameIDs.end(); ++i) { namesDevice << i->second << "\t" << i->first << "\n"; } } }
void NIImporter_VISUM::parse_Turns() { if (myLineParser.know("VSYSSET") && myLineParser.get("VSYSSET") == "") { // no vehicle allowed; don't add return; } // retrieve the nodes NBNode* from = getNamedNode("VonKnot", "VonKnotNr"); NBNode* via = getNamedNode("UeberKnot", "UeberKnotNr"); NBNode* to = getNamedNode("NachKnot", "NachKnotNr"); if (from == 0 || via == 0 || to == 0) { return; } // all nodes are known std::string type = myLineParser.know("VSysCode") ? myLineParser.get("VSysCode") : myLineParser.get("VSYSSET"); if (myVSysTypes.find(type) != myVSysTypes.end() && myVSysTypes.find(type)->second == "IV") { // try to set the turning definition NBEdge* src = from->getConnectionTo(via); NBEdge* dest = via->getConnectionTo(to); // check both if (src == 0) { // maybe it was removed due to something if (OptionsCont::getOptions().isSet("keep-edges.min-speed") || OptionsCont::getOptions().isSet("keep-edges.explicit")) { WRITE_WARNING("Could not set connection from node '" + from->getID() + "' to node '" + via->getID() + "'."); } else { if (OptionsCont::getOptions().getBool("visum.verbose-warnings")) { WRITE_WARNING("There is no edge from node '" + from->getID() + "' to node '" + via->getID() + "'."); } } return; } if (dest == 0) { if (OptionsCont::getOptions().isSet("keep-edges.min-speed") || OptionsCont::getOptions().isSet("keep-edges.explicit")) { WRITE_WARNING("Could not set connection from node '" + via->getID() + "' to node '" + to->getID() + "'."); } else { if (OptionsCont::getOptions().getBool("visum.verbose-warnings")) { WRITE_WARNING("There is no edge from node '" + via->getID() + "' to node '" + to->getID() + "'."); } } return; } // both edges found // set them into the edge src->addEdge2EdgeConnection(dest); } }
void NBOwnTLDef::setTLControllingInformation(const NBEdgeCont &) const throw() { // set the information about the link's positions within the tl into the // edges the links are starting at, respectively unsigned int pos = 0; for (NBConnectionVector::const_iterator j=myControlledLinks.begin(); j!=myControlledLinks.end(); ++j) { const NBConnection &conn = *j; NBEdge *edge = conn.getFrom(); if (edge->setControllingTLInformation(conn.getFromLane(), conn.getTo(), conn.getToLane(), getID(), pos)) { pos++; } } }
void NWWriter_XML::writeStreetSigns(const OptionsCont& oc, NBEdgeCont& ec) { OutputDevice& device = OutputDevice::getDevice(oc.getString("street-sign-output")); device.writeXMLHeader("pois", NWFrame::MAJOR_VERSION + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo-sim.org/xsd/poi_file.xsd\""); for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) { NBEdge* e = (*i).second; const std::vector<NBSign>& signs = e->getSigns(); for (std::vector<NBSign>::const_iterator it = signs.begin(); it != signs.end(); ++it) { it->writeAsPOI(device, e); } } device.close(); }
void GNENet::insertEdge(GNEEdge* edge) { NBEdge* nbe = edge->getNBEdge(); myNetBuilder->getEdgeCont().insert(nbe); // should we ignore pruning double edges? // if this edge was previouls extracted from the edgeContainer we have to // rewire the nodes nbe->getFromNode()->addOutgoingEdge(nbe); nbe->getToNode()->addIncomingEdge(nbe); // Add references to this edge in additionalSets for(std::vector<GNEAdditionalSet*>::const_iterator i = edge->getAdditionalSets().begin(); i != edge->getAdditionalSets().end(); i++) { (*i)->addEdgeChild(edge); } registerEdge(edge); }
void NWWriter_DlrNavteq::writeNodesUnsplitted(const OptionsCont& oc, NBNodeCont& nc, NBEdgeCont& ec) { // For "real" nodes we simply use the node id. // For internal nodes (geometry vectors describing edge geometry in the parlance of this format) // we use the id of the edge and do not bother with // compression (each direction gets its own internal node). // XXX add option for generating numerical ids in case the input network has string ids and the target process needs integers OutputDevice& device = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_nodes_unsplitted.txt"); writeHeader(device, oc); const GeoConvHelper& gch = GeoConvHelper::getFinal(); const bool haveGeo = gch.usingGeoProjection(); const SUMOReal geoScale = pow(10.0f, haveGeo ? 5 : 2); // see NIImporter_DlrNavteq::GEO_SCALE device.setPrecision(0); if (!haveGeo) { WRITE_WARNING("DlrNavteq node data will be written in (floating point) cartesian coordinates"); } // write format specifier device << "# NODE_ID\tIS_BETWEEN_NODE\tamount_of_geocoordinates\tx1\ty1\t[x2 y2 ... xn yn]\n"; // write normal nodes for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { NBNode* n = (*i).second; Position pos = n->getPosition(); gch.cartesian2geo(pos); pos.mul(geoScale); device << n->getID() << "\t0\t1\t" << pos.x() << "\t" << pos.y() << "\n"; } // write "internal" nodes for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) { NBEdge* e = (*i).second; const PositionVector& geom = e->getGeometry(); if (geom.size() > 2) { std::string internalNodeID = e->getID(); if (internalNodeID == UNDEFINED || (nc.retrieve(internalNodeID) != 0)) { // need to invent a new name to avoid clashing with the id of a 'real' node or a reserved name internalNodeID += "_geometry"; } device << internalNodeID << "\t1\t" << geom.size() - 2; for (size_t ii = 1; ii < geom.size() - 1; ++ii) { Position pos = geom[(int)ii]; gch.cartesian2geo(pos); pos.mul(geoScale); device << "\t" << pos.x() << "\t" << pos.y(); } device << "\n"; } } device.close(); }
void NIImporter_VISUM::parse_EdgePolys() { // get the from- & to-node and validate them NBNode* from = getNamedNode("VonKnot", "VonKnotNr"); NBNode* to = getNamedNode("NachKnot", "NachKnotNr"); if (!checkNodes(from, to)) { return; } bool failed = false; int index; SUMOReal x, y; try { index = TplConvert::_2int(myLineParser.get("INDEX").c_str()); x = getNamedFloat("XKoord"); y = getNamedFloat("YKoord"); } catch (NumberFormatException&) { WRITE_ERROR("Error in geometry description from node '" + from->getID() + "' to node '" + to->getID() + "'."); return; } Position pos(x, y); if (!NILoader::transformCoordinates(pos)) { WRITE_ERROR("Unable to project coordinates for node '" + from->getID() + "'."); return; } NBEdge* e = from->getConnectionTo(to); if (e != 0) { e->addGeometryPoint(index, pos); } else { failed = true; } e = to->getConnectionTo(from); if (e != 0) { e->addGeometryPoint(-index, pos); failed = false; } // check whether the operation has failed if (failed) { // we should report this to the warning instance only if we have removed // some nodes or edges... if (OptionsCont::getOptions().isSet("keep-edges.min-speed") || OptionsCont::getOptions().isSet("keep-edges.explicit")) { WRITE_WARNING("Could not set geometry between node '" + from->getID() + "' and node '" + to->getID() + "'."); } else { // ... in the other case we report this to the error instance if (OptionsCont::getOptions().getBool("visum.verbose-warnings")) { WRITE_WARNING("There is no edge from node '" + from->getID() + "' to node '" + to->getID() + "'."); } } } }
// ----- Adapting the input void NBEdgeCont::removeUnwishedEdges(NBDistrictCont& dc) { EdgeVector toRemove; for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) { NBEdge* edge = (*i).second; if (!myEdges2Keep.count(edge->getID())) { edge->getFromNode()->removeEdge(edge); edge->getToNode()->removeEdge(edge); toRemove.push_back(edge); } } for (EdgeVector::iterator j = toRemove.begin(); j != toRemove.end(); ++j) { erase(dc, *j); } }
void NBNodeCont::joinSimilarEdges(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc) { // magic values SUMOReal distanceThreshold = 7; // don't merge edges further apart SUMOReal lengthThreshold = 0.05; // don't merge edges with higher relative length-difference for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) { // count the edges to other nodes outgoing from the current node std::map<NBNode*, EdgeVector> connectionCount; const EdgeVector& outgoing = (*i).second->getOutgoingEdges(); for (EdgeVector::const_iterator j = outgoing.begin(); j != outgoing.end(); j++) { NBEdge* e = (*j); NBNode* connected = e->getToNode(); if (connectionCount.find(connected) == connectionCount.end()) { connectionCount[connected] = EdgeVector(); } connectionCount[connected].push_back(e); } // check whether more than a single edge connect another node and join them std::map<NBNode*, EdgeVector>::iterator k; for (k = connectionCount.begin(); k != connectionCount.end(); k++) { // possibly we do not have anything to join... if ((*k).second.size() < 2) { continue; } // for the edges that seem to be a single street, // check whether the geometry is similar const EdgeVector& ev = (*k).second; const NBEdge* const first = ev.front(); EdgeVector::const_iterator jci; // join candidate iterator for (jci = ev.begin() + 1; jci != ev.end(); ++jci) { const SUMOReal relativeLengthDifference = fabs(first->getLoadedLength() - (*jci)->getLoadedLength()) / first->getLoadedLength(); if ((!first->isNearEnough2BeJoined2(*jci, distanceThreshold)) || (relativeLengthDifference > lengthThreshold) || (first->getSpeed() != (*jci)->getSpeed()) // @todo check vclass ) { break; } } // @bug If there are 3 edges of which 2 can be joined, no joining will // take place with the current implementation if (jci == ev.end()) { ec.joinSameNodeConnectingEdges(dc, tlc, ev); } } } }
void NBLoadedTLDef::collectLinks() { myControlledLinks.clear(); // build the list of links which are controled by the traffic light for (EdgeVector::iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) { NBEdge* incoming = *i; unsigned int noLanes = incoming->getNumLanes(); for (unsigned int j = 0; j < noLanes; j++) { std::vector<NBEdge::Connection> elv = incoming->getConnectionsFromLane(j); for (std::vector<NBEdge::Connection>::iterator k = elv.begin(); k != elv.end(); k++) { NBEdge::Connection el = *k; if (el.toEdge != 0) { myControlledLinks.push_back(NBConnection(incoming, j, el.toEdge, el.toLane)); } } } } // assign tl-indices to myControlledLinks unsigned int pos = 0; for (SignalGroupCont::const_iterator m = mySignalGroups.begin(); m != mySignalGroups.end(); m++) { SignalGroup* group = (*m).second; unsigned int linkNo = group->getLinkNo(); for (unsigned int j = 0; j < linkNo; j++) { const NBConnection& conn = group->getConnection(j); assert(conn.getFromLane() < 0 || (int) conn.getFrom()->getNumLanes() > conn.getFromLane()); NBConnection tst(conn); tst.setTLIndex(pos); if (tst.check(*myEdgeCont)) { if (tst.getFrom()->mayBeTLSControlled(tst.getFromLane(), tst.getTo(), tst.getToLane())) { for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) { NBConnection& c = *it; if (c.getTLIndex() == NBConnection::InvalidTlIndex && tst.getFrom() == c.getFrom() && tst.getTo() == c.getTo() && (tst.getFromLane() < 0 || tst.getFromLane() == c.getFromLane()) && (tst.getToLane() < 0 || tst.getToLane() == c.getToLane())) { c.setTLIndex(pos); } } //std::cout << getID() << " group=" << (*m).first << " tst=" << tst << "\n"; pos++; } } else { WRITE_WARNING("Could not set signal on connection (signal: " + getID() + ", group: " + group->getID() + ")"); } } } }
void NBTrafficLightDefinition::collectEdges() { myIncomingEdges.clear(); myEdgesWithin.clear(); EdgeVector myOutgoing; // collect the edges from the participating nodes for (std::vector<NBNode*>::iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) { const EdgeVector& incoming = (*i)->getIncomingEdges(); copy(incoming.begin(), incoming.end(), back_inserter(myIncomingEdges)); const EdgeVector& outgoing = (*i)->getOutgoingEdges(); copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing)); } EdgeVector outer; // check which of the edges are completely within the junction // add them to the list of edges lying within the node for (EdgeVector::iterator j = myIncomingEdges.begin(); j != myIncomingEdges.end(); ++j) { NBEdge* edge = *j; // an edge lies within the logic if it is outgoing as well as incoming EdgeVector::iterator k = find(myOutgoing.begin(), myOutgoing.end(), edge); if (k != myOutgoing.end()) { myEdgesWithin.push_back(edge); } else { outer.push_back(edge); } } // collect edges that are reachable from the outside via controlled connections std::set<NBEdge*> reachable = collectReachable(outer, myEdgesWithin, true); // collect edges that are reachable from the outside regardless of controllability std::set<NBEdge*> reachable2 = collectReachable(outer, myEdgesWithin, false); const bool uncontrolledWithin = OptionsCont::getOptions().getBool("tls.uncontrolled-within"); for (EdgeVector::iterator j = myEdgesWithin.begin(); j != myEdgesWithin.end(); ++j) { NBEdge* edge = *j; // edges that are marked as 'inner' will not get their own phase when // computing traffic light logics (unless they cannot be reached from the outside at all) if (reachable.count(edge) == 1) { edge->setIsInnerEdge(); // legacy behavior if (uncontrolledWithin && myControlledInnerEdges.count(edge->getID()) == 0) { myIncomingEdges.erase(find(myIncomingEdges.begin(), myIncomingEdges.end(), edge)); } } if (reachable2.count(edge) == 0 && edge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD, true) >= 0 && getID() != DummyID) { WRITE_WARNING("Unreachable edge '" + edge->getID() + "' within tlLogic '" + getID() + "'"); } } }
void NBLoadedSUMOTLDef::setTLControllingInformation() const { // if nodes have been removed our links may have been invalidated as well // since no logic will be built anyway there is no reason to inform any edges if (amInvalid()) { return; } // set the information about the link's positions within the tl into the // edges the links are starting at, respectively for (NBConnectionVector::const_iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) { const NBConnection& c = *it; assert(c.getTLIndex() < (int)myTLLogic->getNumLinks()); NBEdge* edge = c.getFrom(); edge->setControllingTLInformation(c, getID()); } }
void NBLoadedTLDef::collectNodes() { myControlledNodes.clear(); SignalGroupCont::const_iterator m; for (m = mySignalGroups.begin(); m != mySignalGroups.end(); m++) { SignalGroup* group = (*m).second; unsigned int linkNo = group->getLinkNo(); for (unsigned int j = 0; j < linkNo; j++) { const NBConnection& conn = group->getConnection(j); NBEdge* edge = conn.getFrom(); NBNode* node = edge->getToNode(); myControlledNodes.push_back(node); } } std::sort(myControlledNodes.begin(), myControlledNodes.end(), NBNode::nodes_by_id_sorter()); }
void NBEdgeCont::recheckPostProcessConnections() { for (std::vector<PostProcessConnection>::const_iterator i = myConnections.begin(); i != myConnections.end(); ++i) { NBEdge* from = retrieve((*i).from); NBEdge* to = retrieve((*i).to); if (from != 0 && to != 0) { if (!from->addLane2LaneConnection((*i).fromLane, to, (*i).toLane, NBEdge::L2L_USER, false, (*i).mayDefinitelyPass)) { WRITE_WARNING("Could not insert connection between '" + (*i).from + "' and '" + (*i).to + "' after build."); } } } // during loading we also kept some ambiguous connections in hope they might be valid after processing // we need to make sure that all invalid connections are removed now for (EdgeCont::iterator it = myEdges.begin(); it != myEdges.end(); ++it) { NBEdge* edge = it->second; NBNode* to = edge->getToNode(); // make a copy because we may delete connections std::vector<NBEdge::Connection> connections = edge->getConnections(); for (std::vector<NBEdge::Connection>::iterator it_con = connections.begin(); it_con != connections.end(); ++it_con) { NBEdge::Connection& c = *it_con; if (c.toEdge != 0 && c.toEdge->getFromNode() != to) { WRITE_WARNING("Found and removed invalid connection from " + edge->getID() + " to " + c.toEdge->getID() + " via " + to->getID()); edge->removeFromConnections(c.toEdge); } } } }
long GNEConnectorFrame::onCmdSelectPass(FXObject*, FXSelector, void*) { std::vector<GUIGlID> selectIDs; const std::vector<GNEEdge*> edges = myViewNet->getNet()->retrieveEdges(); for (std::vector<GNEEdge*>::const_iterator edge_it = edges.begin(); edge_it != edges.end(); edge_it++) { GNEEdge* edge = *edge_it; NBEdge* nbe = edge->getNBEdge(); const std::vector<NBEdge::Connection>& connections = nbe->getConnections(); for (std::vector<NBEdge::Connection>::const_iterator it = connections.begin(); it != connections.end(); ++it) { if (it->mayDefinitelyPass) { GNELane* lane = edge->getLanes()[it->fromLane]; selectIDs.push_back(lane->getGlID()); } } } myViewNet->getViewParent()->getSelectorFrame()->handleIDs(selectIDs, false, GNESelectorFrame::SET_REPLACE); return 1; }