void RORouteHandler::addStop(const SUMOSAXAttributes& attrs) { if (myActivePlan) { myActivePlan->openTag(SUMO_TAG_STOP); (*myActivePlan) << attrs; myActivePlan->closeTag(); myActivePlanSize++; return; } std::string errorSuffix; if (myActiveRouteID != "") { errorSuffix = " in route '" + myActiveRouteID + "'."; } else { errorSuffix = " in vehicle '" + myVehicleParameter->id + "'."; } SUMOVehicleParameter::Stop stop; bool ok = parseStop(stop, attrs, errorSuffix, myErrorOutput); if (!ok) { return; } // try to parse the assigned bus stop if (stop.busstop != "") { const SUMOVehicleParameter::Stop* busstop = myNet.getBusStop(stop.busstop); if (busstop == 0) { myErrorOutput->inform("Unknown bus stop '" + stop.busstop + "'" + errorSuffix); } else { stop.lane = busstop->lane; stop.endPos = busstop->endPos; stop.startPos = busstop->startPos; } } else { // no, the lane and the position should be given stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, ""); if (!ok || stop.lane == "") { myErrorOutput->inform("A stop must be placed on a bus stop or a lane" + errorSuffix); return; } ROEdge* edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_'))); if (edge == 0) { myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix); return; } stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ENDPOS, 0, ok, edge->getLength()); stop.startPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS); const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false); if (!ok || !checkStopPos(stop.startPos, stop.endPos, edge->getLength(), POSITION_EPS, friendlyPos)) { myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix); return; } } if (myVehicleParameter != 0) { myVehicleParameter->stops.push_back(stop); } else { myActiveRouteStops.push_back(stop); } }
void GARDetectorHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) { if (element == SUMO_TAG_DETECTOR_DEFINITION) { try { bool ok = true; // get the id, report an error if not given or empty... std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok); if (!ok) { throw ProcessError(); } std::string lane = attrs.get<std::string>(SUMO_ATTR_LANE, id.c_str(), ok); if (!ok) { throw ProcessError(); } ROEdge* edge = myNet.getEdge(lane.substr(0, lane.rfind('_'))); unsigned int laneIndex = TplConvert::_2intSec( lane.substr(lane.rfind('_') + 1).c_str(), INT_MAX); if (edge == 0 || laneIndex >= edge->getLaneNo()) { throw ProcessError( "Unknown lane '" + lane + "' for detector '" + id + "' in '" + getFileName() + "'."); } SUMOReal pos = attrs.get<SUMOReal>(SUMO_ATTR_POSITION, id.c_str(), ok); std::string mml_type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, ""); if (!ok) { throw ProcessError(); } GARDetectorType type = TYPE_NOT_DEFINED; if (mml_type == "between") { type = BETWEEN_DETECTOR; } else if (mml_type == "source" || mml_type == "highway_source") { // !!! highway-source is legacy (removed accoring output on 06.08.2007) type = SOURCE_DETECTOR; } else if (mml_type == "sink") { type = SINK_DETECTOR; } GARDetector* detector = new GARDetector(id, lane, pos, type); if (!myContainer.addDetector(detector)) { delete detector; throw ProcessError( "Could not add detector '" + id + "' (probably the id is already used)."); } } catch (ProcessError& e) { if (myIgnoreErrors) { WRITE_WARNING(e.what()); } else { throw e; } } } }
void RONetHandler::parseConnection(const SUMOSAXAttributes& attrs) { bool ok = true; std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, 0, ok); std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, 0, ok); int fromLane = attrs.get<int>(SUMO_ATTR_FROM_LANE, 0, ok); int toLane = attrs.get<int>(SUMO_ATTR_TO_LANE, 0, ok); std::string dir = attrs.get<std::string>(SUMO_ATTR_DIR, 0, ok); ROEdge* from = myNet.getEdge(fromID); ROEdge* to = myNet.getEdge(toID); if (from == 0) { throw ProcessError("unknown from-edge '" + fromID + "' in connection"); } if (to == 0) { throw ProcessError("unknown to-edge '" + toID + "' in connection"); } if (from->getFunc() == ROEdge::ET_INTERNAL) { // skip inner lane connections return; } if (from->getLanes().size() <= (size_t)fromLane) { throw ProcessError("invalid fromLane '" + toString(fromLane) + "' in connection from '" + fromID + "'."); } if (to->getLanes().size() <= (size_t)toLane) { throw ProcessError("invalid toLane '" + toString(toLane) + "' in connection to '" + toID + "'."); } from->getLanes()[fromLane]->addOutgoingLane(to->getLanes()[toLane]); from->addSuccessor(to, dir); }
void RONetHandler::parseDistrictEdge(const SUMOSAXAttributes& attrs, bool isSource) { bool ok = true; std::string id = attrs.get<std::string>(SUMO_ATTR_ID, myCurrentName.c_str(), ok); ROEdge* succ = myNet.getEdge(id); if (succ != 0) { // connect edge if (isSource) { myNet.getEdge(myCurrentName + "-source")->addFollower(succ); } else { succ->addFollower(myNet.getEdge(myCurrentName + "-sink")); } } else { WRITE_ERROR("At district '" + myCurrentName + "': succeeding edge '" + id + "' does not exist."); } }
// --------------------------------------------------------------------------- // ROLoader::EdgeFloatTimeLineRetriever_EdgeWeight - methods // --------------------------------------------------------------------------- void ROLoader::EdgeFloatTimeLineRetriever_EdgeWeight::addEdgeWeight(const std::string& id, SUMOReal val, SUMOReal beg, SUMOReal end) const { ROEdge* e = myNet.getEdge(id); if (e != 0) { e->addEffort(val, beg, end); } else { if (id[0] != ':') { if (OptionsCont::getOptions().getBool("ignore-errors")) { WRITE_WARNING("Trying to set a weight for the unknown edge '" + id + "'."); } else { WRITE_ERROR("Trying to set a weight for the unknown edge '" + id + "'."); } } } }
void ROJTRTurnDefLoader::myStartElement(int element, const SUMOSAXAttributes& attrs) { bool ok = true; switch (element) { case SUMO_TAG_INTERVAL: myIntervalBegin = attrs.getSUMOTimeReporting(SUMO_ATTR_BEGIN, 0, ok); myIntervalEnd = attrs.getSUMOTimeReporting(SUMO_ATTR_END, 0, ok); break; case SUMO_TAG_FROMEDGE: beginFromEdge(attrs); break; case SUMO_TAG_TOEDGE: addToEdge(attrs); break; case SUMO_TAG_SINK: if (attrs.hasAttribute(SUMO_ATTR_EDGES)) { std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, 0, ok); StringTokenizer st(edges, StringTokenizer::WHITECHARS); while (st.hasNext()) { std::string id = st.next(); ROEdge* edge = myNet.getEdge(id); if (edge == 0) { throw ProcessError("The edge '" + id + "' declared as a sink is not known."); } edge->setType(ROEdge::ET_SINK); } } break; case SUMO_TAG_SOURCE: if (attrs.hasAttribute(SUMO_ATTR_EDGES)) { std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, 0, ok); StringTokenizer st(edges, StringTokenizer::WHITECHARS); while (st.hasNext()) { std::string id = st.next(); ROEdge* edge = myNet.getEdge(id); if (edge == 0) { throw ProcessError("The edge '" + id + "' declared as a source is not known."); } edge->setType(ROEdge::ET_SOURCE); } } break; default: break; } }
void RODFNet::buildApproachList() { const std::map<std::string, ROEdge*>& edges = getEdgeMap(); for (std::map<std::string, ROEdge*>::const_iterator rit = edges.begin(); rit != edges.end(); ++rit) { ROEdge* ce = (*rit).second; unsigned int i = 0; unsigned int length_size = ce->getNoFollowing(); for (i = 0; i < length_size; i++) { ROEdge* help = ce->getFollower(i); if (find(myDisallowedEdges.begin(), myDisallowedEdges.end(), help->getID()) != myDisallowedEdges.end()) { // edges in sinks will not be used continue; } if (!myKeepTurnarounds && help->getToNode() == ce->getFromNode()) { // do not use turnarounds continue; } // add the connection help->ce to myApproachingEdges if (myApproachingEdges.find(help) == myApproachingEdges.end()) { myApproachingEdges[help] = std::vector<ROEdge*>(); } myApproachingEdges[help].push_back(ce); // add the connection ce->help to myApproachingEdges if (myApproachedEdges.find(ce) == myApproachedEdges.end()) { myApproachedEdges[ce] = std::vector<ROEdge*>(); } myApproachedEdges[ce].push_back(help); } } }
void RONetHandler::parseDistrict(const SUMOSAXAttributes& attrs) { myCurrentEdge = 0; bool ok = true; myCurrentName = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok); if (!ok) { return; } ROEdge* sink = myEdgeBuilder.buildEdge(myCurrentName + "-sink", 0, 0, 0); sink->setType(ROEdge::ET_DISTRICT); myNet.addEdge(sink); ROEdge* source = myEdgeBuilder.buildEdge(myCurrentName + "-source", 0, 0, 0); source->setType(ROEdge::ET_DISTRICT); myNet.addEdge(source); if (attrs.hasAttribute(SUMO_ATTR_EDGES)) { std::vector<std::string> desc = attrs.getStringVector(SUMO_ATTR_EDGES); for (std::vector<std::string>::const_iterator i = desc.begin(); i != desc.end(); ++i) { ROEdge* edge = myNet.getEdge(*i); // check whether the edge exists if (edge == 0) { throw ProcessError("The edge '" + *i + "' within district '" + myCurrentName + "' is not known."); } source->addFollower(edge); edge->addFollower(sink); } } }
void RONetHandler::parseConnection(const SUMOSAXAttributes& attrs) { bool ok = true; std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, 0, ok); std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, 0, ok); std::string dir = attrs.get<std::string>(SUMO_ATTR_DIR, 0, ok); if (fromID[0] == ':') { // skip inner lane connections return; } ROEdge* from = myNet.getEdge(fromID); ROEdge* to = myNet.getEdge(toID); if (from == 0) { throw ProcessError("unknown from-edge '" + fromID + "' in connection"); } if (to == 0) { throw ProcessError("unknown to-edge '" + toID + "' in connection"); } from->addFollower(to, dir); }
void RODFRouteCont::addAllEndFollower() throw() { std::vector<RODFRouteDesc> newRoutes; for (std::vector<RODFRouteDesc>::iterator i=myRoutes.begin(); i!=myRoutes.end(); ++i) { RODFRouteDesc &desc = *i; ROEdge *last = *(desc.edges2Pass.end()-1); if (last->getNoFollowing()==0) { newRoutes.push_back(desc); continue; } for (unsigned int j=0; j<last->getNoFollowing(); ++j) { RODFRouteDesc ndesc(desc); ndesc.edges2Pass.push_back(last->getFollower(j)); setID(ndesc); newRoutes.push_back(ndesc); } } myRoutes = newRoutes; }
void RONetHandler::myEndElement(int element) { switch (element) { case SUMO_TAG_NET: // build junction graph for (JunctionGraph::iterator it = myJunctionGraph.begin(); it != myJunctionGraph.end(); ++it) { ROEdge* edge = myNet.getEdge(it->first); RONode* from = myNet.getNode(it->second.first); RONode* to = myNet.getNode(it->second.second); if (edge != 0 && from != 0 && to != 0) { edge->setJunctions(from, to); from->addOutgoing(edge); to->addIncoming(edge); } } break; default: break; } }
void RODFNet::buildApproachList() { const std::map<std::string, ROEdge*>& edges = getEdgeMap(); for (std::map<std::string, ROEdge*>::const_iterator rit = edges.begin(); rit != edges.end(); ++rit) { ROEdge* ce = (*rit).second; const ROEdgeVector& successors = ce->getSuccessors(); for (ROEdgeVector::const_iterator it = successors.begin(); it != successors.end(); ++it) { ROEdge* help = *it; if (find(myDisallowedEdges.begin(), myDisallowedEdges.end(), help->getID()) != myDisallowedEdges.end()) { // edges in sinks will not be used continue; } if (!myKeepTurnarounds && help->getToJunction() == ce->getFromJunction()) { // do not use turnarounds continue; } // add the connection help->ce to myApproachingEdges if (myApproachingEdges.find(help) == myApproachingEdges.end()) { myApproachingEdges[help] = ROEdgeVector(); } myApproachingEdges[help].push_back(ce); // add the connection ce->help to myApproachingEdges if (myApproachedEdges.find(ce) == myApproachedEdges.end()) { myApproachedEdges[ce] = ROEdgeVector(); } myApproachedEdges[ce].push_back(help); } } }
void RORouteHandler::addStop(const SUMOSAXAttributes& attrs) { if (myActiveContainerPlan != 0) { myActiveContainerPlan->openTag(SUMO_TAG_STOP); (*myActiveContainerPlan) << attrs; myActiveContainerPlan->closeTag(); myActiveContainerPlanSize++; return; } std::string errorSuffix; if (myVehicleParameter != 0) { errorSuffix = " in vehicle '" + myVehicleParameter->id + "'."; } else { errorSuffix = " in route '" + myActiveRouteID + "'."; } SUMOVehicleParameter::Stop stop; bool ok = parseStop(stop, attrs, errorSuffix, myErrorOutput); if (!ok) { return; } // try to parse the assigned bus stop ROEdge* edge = 0; if (stop.busstop != "") { const SUMOVehicleParameter::Stop* busstop = myNet.getStoppingPlace(stop.busstop, SUMO_TAG_BUS_STOP); if (busstop == 0) { myErrorOutput->inform("Unknown bus stop '" + stop.busstop + "'" + errorSuffix); return; } stop.lane = busstop->lane; stop.endPos = busstop->endPos; stop.startPos = busstop->startPos; edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_'))); } // try to parse the assigned container stop else if (stop.containerstop != "") { const SUMOVehicleParameter::Stop* containerstop = myNet.getStoppingPlace(stop.containerstop, SUMO_TAG_CONTAINER_STOP); if (containerstop == 0) { myErrorOutput->inform("Unknown container stop '" + stop.containerstop + "'" + errorSuffix); return; } stop.lane = containerstop->lane; stop.endPos = containerstop->endPos; stop.startPos = containerstop->startPos; edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_'))); } // try to parse the assigned parking area else if (stop.parkingarea != "") { const SUMOVehicleParameter::Stop* parkingarea = myNet.getStoppingPlace(stop.parkingarea, SUMO_TAG_PARKING_AREA); if (parkingarea == 0) { myErrorOutput->inform("Unknown parking area '" + stop.parkingarea + "'" + errorSuffix); return; } stop.lane = parkingarea->lane; stop.endPos = parkingarea->endPos; stop.startPos = parkingarea->startPos; edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_'))); } else { // no, the lane and the position should be given stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, ""); if (!ok || stop.lane == "") { myErrorOutput->inform("A stop must be placed on a bus stop, a container stop, a parking area or a lane" + errorSuffix); return; } edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_'))); if (edge == 0) { myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix); return; } stop.endPos = attrs.getOpt<double>(SUMO_ATTR_ENDPOS, 0, ok, edge->getLength()); stop.startPos = attrs.getOpt<double>(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS); const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false); const double endPosOffset = edge->isInternal() ? edge->getNormalBefore()->getLength() : 0; if (!ok || !checkStopPos(stop.startPos, stop.endPos, edge->getLength() + endPosOffset, POSITION_EPS, friendlyPos)) { myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix); return; } } if (myActivePerson != 0) { myActivePerson->addStop(stop, edge); } else if (myVehicleParameter != 0) { myVehicleParameter->stops.push_back(stop); } else { myActiveRouteStops.push_back(stop); } if (myInsertStopEdgesAt >= 0) { myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge); myInsertStopEdgesAt++; } }
void RODFDetector::computeSplitProbabilities(const RODFNet* net, const RODFDetectorCon& detectors, const RODFDetectorFlows& flows, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset) { if (myRoutes == 0) { return; } // compute edges to determine split probabilities const std::vector<RODFRouteDesc>& routes = myRoutes->get(); std::vector<RODFEdge*> nextDetEdges; std::set<ROEdge*> preSplitEdges; for (std::vector<RODFRouteDesc>::const_iterator i = routes.begin(); i != routes.end(); ++i) { const RODFRouteDesc& rd = *i; bool hadSplit = false; for (ROEdgeVector::const_iterator j = rd.edges2Pass.begin(); j != rd.edges2Pass.end(); ++j) { if (hadSplit && net->hasDetector(*j)) { if (find(nextDetEdges.begin(), nextDetEdges.end(), *j) == nextDetEdges.end()) { nextDetEdges.push_back(static_cast<RODFEdge*>(*j)); } myRoute2Edge[rd.routename] = static_cast<RODFEdge*>(*j); break; } if (!hadSplit) { preSplitEdges.insert(*j); } if ((*j)->getNumSuccessors() > 1) { hadSplit = true; } } } std::map<ROEdge*, SUMOReal> inFlows; if (OptionsCont::getOptions().getBool("respect-concurrent-inflows")) { for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) { std::set<ROEdge*> seen(preSplitEdges); ROEdgeVector pending; pending.push_back(*i); seen.insert(*i); while (!pending.empty()) { ROEdge* e = pending.back(); pending.pop_back(); for (ROEdgeVector::const_iterator it = e->getPredecessors().begin(); it != e->getPredecessors().end(); it++) { ROEdge* e2 = *it; if (e2->getNumSuccessors() == 1 && seen.count(e2) == 0) { if (net->hasDetector(e2)) { inFlows[*i] += detectors.getAggFlowFor(e2, 0, 0, flows); } else { pending.push_back(e2); } seen.insert(e2); } } } } } // compute the probabilities to use a certain direction int index = 0; for (SUMOTime time = startTime; time < endTime; time += stepOffset, ++index) { mySplitProbabilities.push_back(std::map<RODFEdge*, SUMOReal>()); SUMOReal overallProb = 0; // retrieve the probabilities for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) { SUMOReal flow = detectors.getAggFlowFor(*i, time, 60, flows) - inFlows[*i]; overallProb += flow; mySplitProbabilities[index][*i] = flow; } // norm probabilities if (overallProb > 0) { for (std::vector<RODFEdge*>::const_iterator i = nextDetEdges.begin(); i != nextDetEdges.end(); ++i) { mySplitProbabilities[index][*i] = mySplitProbabilities[index][*i] / overallProb; } } } }
void RODFNet::buildEdgeFlowMap(const RODFDetectorFlows& flows, const RODFDetectorCon& detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset) { std::map<ROEdge*, std::vector<std::string>, idComp>::iterator i; for (i = myDetectorsOnEdges.begin(); i != myDetectorsOnEdges.end(); ++i) { ROEdge* into = (*i).first; const std::vector<std::string>& dets = (*i).second; std::map<SUMOReal, std::vector<std::string> > cliques; std::vector<std::string>* maxClique = 0; for (std::vector<std::string>::const_iterator j = dets.begin(); j != dets.end(); ++j) { if (!flows.knows(*j)) { continue; } const RODFDetector& det = detectors.getDetector(*j); bool found = false; for (std::map<SUMOReal, std::vector<std::string> >::iterator k = cliques.begin(); !found && k != cliques.end(); ++k) { if (fabs((*k).first - det.getPos()) < 1) { (*k).second.push_back(*j); if ((*k).second.size() > maxClique->size()) { maxClique = &(*k).second; } found = true; } } if (!found) { cliques[det.getPos()].push_back(*j); maxClique = &cliques[det.getPos()]; } } if (maxClique == 0) { continue; } std::vector<FlowDef> mflows; // !!! reserve for (SUMOTime t = startTime; t < endTime; t += stepOffset) { FlowDef fd; fd.qPKW = 0; fd.qLKW = 0; fd.vLKW = 0; fd.vPKW = 0; fd.fLKW = 0; fd.isLKW = 0; mflows.push_back(fd); } for (std::vector<std::string>::iterator l = maxClique->begin(); l != maxClique->end(); ++l) { bool didWarn = false; const std::vector<FlowDef>& dflows = flows.getFlowDefs(*l); int index = 0; for (SUMOTime t = startTime; t < endTime; t += stepOffset, index++) { const FlowDef& srcFD = dflows[index]; FlowDef& fd = mflows[index]; fd.qPKW += srcFD.qPKW; fd.qLKW += srcFD.qLKW; fd.vLKW += (srcFD.vLKW / (SUMOReal) maxClique->size()); fd.vPKW += (srcFD.vPKW / (SUMOReal) maxClique->size()); fd.fLKW += (srcFD.fLKW / (SUMOReal) maxClique->size()); fd.isLKW += (srcFD.isLKW / (SUMOReal) maxClique->size()); if (!didWarn && srcFD.vPKW > 0 && srcFD.vPKW < 255 && srcFD.vPKW / 3.6 > into->getSpeed()) { WRITE_MESSAGE("Detected PKW speed higher than allowed speed at '" + (*l) + "' on '" + into->getID() + "'."); didWarn = true; } if (!didWarn && srcFD.vLKW > 0 && srcFD.vLKW < 255 && srcFD.vLKW / 3.6 > into->getSpeed()) { WRITE_MESSAGE("Detected LKW speed higher than allowed speed at '" + (*l) + "' on '" + into->getID() + "'."); didWarn = true; } } } static_cast<RODFEdge*>(into)->setFlows(mflows); } }
void RODFNet::buildRoutes(RODFDetectorCon& detcont, bool allEndFollower, bool keepUnfoundEnds, bool includeInBetween, bool keepShortestOnly, int maxFollowingLength) const { // build needed information first buildDetectorEdgeDependencies(detcont); // then build the routes std::map<ROEdge*, RODFRouteCont* > doneEdges; const std::vector< RODFDetector*>& dets = detcont.getDetectors(); for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) { ROEdge* e = getDetectorEdge(**i); if (doneEdges.find(e) != doneEdges.end()) { // use previously build routes (*i)->addRoutes(new RODFRouteCont(*doneEdges[e])); continue; } std::vector<ROEdge*> seen; RODFRouteCont* routes = new RODFRouteCont(); doneEdges[e] = routes; RODFRouteDesc rd; rd.edges2Pass.push_back(e); rd.duration_2 = (e->getLength() / e->getSpeed()); //!!!; rd.endDetectorEdge = 0; rd.lastDetectorEdge = 0; rd.distance = e->getLength(); rd.distance2Last = 0; rd.duration2Last = 0; rd.overallProb = 0; std::vector<ROEdge*> visited; visited.push_back(e); computeRoutesFor(e, rd, 0, keepUnfoundEnds, keepShortestOnly, visited, **i, *routes, detcont, maxFollowingLength, seen); if (allEndFollower) { routes->addAllEndFollower(); } //!!!routes->removeIllegal(illegals); (*i)->addRoutes(routes); // add routes to in-between detectors if wished if (includeInBetween) { // go through the routes const std::vector<RODFRouteDesc>& r = routes->get(); for (std::vector<RODFRouteDesc>::const_iterator j = r.begin(); j != r.end(); ++j) { const RODFRouteDesc& mrd = *j; SUMOReal duration = mrd.duration_2; SUMOReal distance = mrd.distance; // go through each route's edges std::vector<ROEdge*>::const_iterator routeend = mrd.edges2Pass.end(); for (std::vector<ROEdge*>::const_iterator k = mrd.edges2Pass.begin(); k != routeend; ++k) { // check whether any detectors lies on the current edge if (myDetectorsOnEdges.find(*k) == myDetectorsOnEdges.end()) { duration -= (*k)->getLength() / (*k)->getSpeed(); distance -= (*k)->getLength(); continue; } // get the detectors const std::vector<std::string>& dets = myDetectorsOnEdges.find(*k)->second; // go through the detectors for (std::vector<std::string>::const_iterator l = dets.begin(); l != dets.end(); ++l) { const RODFDetector& m = detcont.getDetector(*l); if (m.getType() == BETWEEN_DETECTOR) { RODFRouteDesc nrd; copy(k, routeend, back_inserter(nrd.edges2Pass)); nrd.duration_2 = duration;//!!!; nrd.endDetectorEdge = mrd.endDetectorEdge; nrd.lastDetectorEdge = mrd.lastDetectorEdge; nrd.distance = distance; nrd.distance2Last = mrd.distance2Last; nrd.duration2Last = mrd.duration2Last; nrd.overallProb = mrd.overallProb; nrd.factor = mrd.factor; ((RODFDetector&) m).addRoute(nrd); } } duration -= (*k)->getLength() / (*k)->getSpeed(); distance -= (*k)->getLength(); } } } } }
void RODFNet::computeRoutesFor(ROEdge* edge, RODFRouteDesc& base, int /*no*/, bool keepUnfoundEnds, bool keepShortestOnly, std::vector<ROEdge*>& /*visited*/, const RODFDetector& det, RODFRouteCont& into, const RODFDetectorCon& detectors, int maxFollowingLength, std::vector<ROEdge*>& seen) const { std::vector<RODFRouteDesc> unfoundEnds; std::priority_queue<RODFRouteDesc, std::vector<RODFRouteDesc>, DFRouteDescByTimeComperator> toSolve; std::map<ROEdge*, std::vector<ROEdge*> > dets2Follow; dets2Follow[edge] = std::vector<ROEdge*>(); base.passedNo = 0; SUMOReal minDist = OptionsCont::getOptions().getFloat("min-route-length"); toSolve.push(base); while (!toSolve.empty()) { RODFRouteDesc current = toSolve.top(); toSolve.pop(); ROEdge* last = *(current.edges2Pass.end() - 1); if (hasDetector(last)) { if (dets2Follow.find(last) == dets2Follow.end()) { dets2Follow[last] = std::vector<ROEdge*>(); } for (std::vector<ROEdge*>::reverse_iterator i = current.edges2Pass.rbegin() + 1; i != current.edges2Pass.rend(); ++i) { if (hasDetector(*i)) { dets2Follow[*i].push_back(last); break; } } } // do not process an edge twice if (find(seen.begin(), seen.end(), last) != seen.end() && keepShortestOnly) { continue; } seen.push_back(last); // end if the edge has no further connections if (!hasApproached(last)) { // ok, no further connections to follow current.factor = 1.; SUMOReal cdist = current.edges2Pass[0]->getFromNode()->getPosition().distanceTo(current.edges2Pass.back()->getToNode()->getPosition()); if (minDist < cdist) { into.addRouteDesc(current); } continue; } // check for passing detectors: // if the current last edge is not the one the detector is placed on ... bool addNextNoFurther = false; if (last != getDetectorEdge(det)) { // ... if there is a detector ... if (hasDetector(last)) { if (!hasInBetweenDetectorsOnly(last, detectors)) { // ... and it's not an in-between-detector // -> let's add this edge and the following, but not any further addNextNoFurther = true; current.lastDetectorEdge = last; current.duration2Last = (SUMOTime) current.duration_2; current.distance2Last = current.distance; current.endDetectorEdge = last; if (hasSourceDetector(last, detectors)) { ///!!! //toDiscard.push_back(current); } current.factor = 1.; SUMOReal cdist = current.edges2Pass[0]->getFromNode()->getPosition().distanceTo(current.edges2Pass.back()->getToNode()->getPosition()); if (minDist < cdist) { into.addRouteDesc(current); } continue; } else { // ... if it's an in-between-detector // -> mark the current route as to be continued current.passedNo = 0; current.duration2Last = (SUMOTime) current.duration_2; current.distance2Last = current.distance; current.lastDetectorEdge = last; } } } // check for highway off-ramps if (myAmInHighwayMode) { // if it's beside the highway... if (last->getSpeed() < 19.4 && last != getDetectorEdge(det)) { // ... and has more than one following edge if (myApproachedEdges.find(last)->second.size() > 1) { // -> let's add this edge and the following, but not any further addNextNoFurther = true; } } } // check for missing end connections if (!addNextNoFurther) { // ... if this one would be processed, but already too many edge // without a detector occured if (current.passedNo > maxFollowingLength) { // mark not to process any further WRITE_WARNING("Could not close route for '" + det.getID() + "'"); unfoundEnds.push_back(current); current.factor = 1.; SUMOReal cdist = current.edges2Pass[0]->getFromNode()->getPosition().distanceTo(current.edges2Pass.back()->getToNode()->getPosition()); if (minDist < cdist) { into.addRouteDesc(current); } continue; } } // ... else: loop over the next edges const std::vector<ROEdge*>& appr = myApproachedEdges.find(last)->second; bool hadOne = false; for (size_t i = 0; i < appr.size(); i++) { if (find(current.edges2Pass.begin(), current.edges2Pass.end(), appr[i]) != current.edges2Pass.end()) { // do not append an edge twice (do not build loops) continue; } RODFRouteDesc t(current); t.duration_2 += (appr[i]->getLength() / appr[i]->getSpeed()); //!!! t.distance += appr[i]->getLength(); t.edges2Pass.push_back(appr[i]); if (!addNextNoFurther) { t.passedNo = t.passedNo + 1; toSolve.push(t); } else { if (!hadOne) { t.factor = (SUMOReal) 1. / (SUMOReal) appr.size(); SUMOReal cdist = current.edges2Pass[0]->getFromNode()->getPosition().distanceTo(current.edges2Pass.back()->getToNode()->getPosition()); if (minDist < cdist) { into.addRouteDesc(t); } hadOne = true; } } } } // if (!keepUnfoundEnds) { std::vector<RODFRouteDesc>::iterator i; std::vector<const ROEdge*> lastDetEdges; for (i = unfoundEnds.begin(); i != unfoundEnds.end(); ++i) { if (find(lastDetEdges.begin(), lastDetEdges.end(), (*i).lastDetectorEdge) == lastDetEdges.end()) { lastDetEdges.push_back((*i).lastDetectorEdge); } else { bool ok = into.removeRouteDesc(*i); assert(ok); } } } else { // !!! patch the factors } while (!toSolve.empty()) { // RODFRouteDesc d = toSolve.top(); toSolve.pop(); // delete d; } }
void RORouteHandler::addStop(const SUMOSAXAttributes& attrs) { if (myActivePlan) { myActivePlan->openTag(SUMO_TAG_STOP); (*myActivePlan) << attrs; myActivePlan->closeTag(); return; } bool ok = true; std::string errorSuffix; if (myActiveRouteID != "") { errorSuffix = " in route '" + myActiveRouteID + "'."; } else { errorSuffix = " in vehicle '" + myVehicleParameter->id + "'."; } SUMOVehicleParameter::Stop stop; SUMOVehicleParserHelper::parseStop(stop, attrs); // try to parse the assigned bus stop stop.busstop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, 0, ok, ""); if (stop.busstop == "") { // no, the lane and the position should be given stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, ""); if (!ok || stop.lane == "") { myErrorOutput->inform("A stop must be placed on a bus stop or a lane" + errorSuffix); return; } ROEdge* edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_'))); if (edge == 0) { myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix); return; } stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ENDPOS, 0, ok, edge->getLength()); stop.startPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS); const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false); if (!ok || !checkStopPos(stop.startPos, stop.endPos, edge->getLength(), POSITION_EPS, friendlyPos)) { myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix); return; } } // get the standing duration if (!attrs.hasAttribute(SUMO_ATTR_DURATION) && !attrs.hasAttribute(SUMO_ATTR_UNTIL)) { stop.triggered = attrs.getOpt<bool>(SUMO_ATTR_TRIGGERED, 0, ok, true); stop.duration = -1; stop.until = -1; } else { stop.duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, 0, ok, -1); stop.until = attrs.getOptSUMOTimeReporting(SUMO_ATTR_UNTIL, 0, ok, -1); if (!ok || (stop.duration < 0 && stop.until < 0)) { myErrorOutput->inform("Invalid duration or end time is given for a stop" + errorSuffix); return; } stop.triggered = attrs.getOpt<bool>(SUMO_ATTR_TRIGGERED, 0, ok, false); } stop.parking = attrs.getOpt<bool>(SUMO_ATTR_PARKING, 0, ok, stop.triggered); if (!ok) { myErrorOutput->inform("Invalid bool for 'triggered' or 'parking' for stop" + errorSuffix); return; } // expected persons std::string expectedStr = attrs.getOpt<std::string>(SUMO_ATTR_EXPECTED, 0, ok, ""); std::set<std::string> personIDs; SUMOSAXAttributes::parseStringSet(expectedStr, personIDs); stop.awaitedPersons = personIDs; const std::string idx = attrs.getOpt<std::string>(SUMO_ATTR_INDEX, 0, ok, "end"); if (idx == "end") { stop.index = STOP_INDEX_END; } else if (idx == "fit") { stop.index = STOP_INDEX_FIT; } else { stop.index = attrs.get<int>(SUMO_ATTR_INDEX, 0, ok); if (!ok || stop.index < 0) { myErrorOutput->inform("Invalid 'index' for stop" + errorSuffix); return; } } if (myVehicleParameter != 0) { myVehicleParameter->stops.push_back(stop); } else { myActiveRouteStops.push_back(stop); } }