std::string MSNet::getBusStopID(const MSLane* lane, const SUMOReal pos) const { const std::map<std::string, MSBusStop*> &vals = myBusStopDict.getMyMap(); for(std::map<std::string, MSBusStop*>::const_iterator it = vals.begin(); it != vals.end(); ++it){ MSBusStop* stop = it->second; if(&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS){ return stop->getID(); } } return ""; }
void MSRouteHandler::addStop(const SUMOSAXAttributes& attrs) { bool ok = true; std::string errorSuffix; if (myActiveRouteID != "") { errorSuffix = " in route '" + myActiveRouteID + "'."; } else if (myActivePlan) { errorSuffix = " in person '" + myVehicleParameter->id + "'."; } else { errorSuffix = " in vehicle '" + myVehicleParameter->id + "'."; } SUMOVehicleParameter::Stop stop; // try to parse the assigned bus stop if (attrs.hasAttribute(SUMO_ATTR_BUS_STOP__DEPRECATED)) { stop.busstop = attrs.getStringReporting(SUMO_ATTR_BUS_STOP__DEPRECATED, 0, ok); if (!myHaveWarnedAboutDeprecatedBusStop) { myHaveWarnedAboutDeprecatedBusStop = true; WRITE_WARNING("'bus_stop' is deprecated, please use 'busStop' instead."); } } else { stop.busstop = attrs.getOptStringReporting(SUMO_ATTR_BUS_STOP, 0, ok, ""); } if (stop.busstop != "") { // ok, we have obviously a bus stop MSBusStop* bs = MSNet::getInstance()->getBusStop(stop.busstop); if (bs != 0) { const MSLane& l = bs->getLane(); stop.lane = l.getID(); stop.endPos = bs->getEndLanePosition(); stop.startPos = bs->getBeginLanePosition(); } else { WRITE_ERROR("The bus stop '" + stop.busstop + "' is not known" + errorSuffix); return; } } else { // no, the lane and the position should be given // get the lane stop.lane = attrs.getOptStringReporting(SUMO_ATTR_LANE, 0, ok, ""); if (ok && stop.lane != "") { if (MSLane::dictionary(stop.lane) == 0) { WRITE_ERROR("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix); return; } } else { WRITE_ERROR("A stop must be placed on a bus stop or a lane" + errorSuffix); return; } if (myActivePlan && !myActivePlan->empty() && &myActivePlan->back()->getDestination() != &MSLane::dictionary(stop.lane)->getEdge()) { throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + MSLane::dictionary(stop.lane)->getEdge().getID() + "!=" + myActivePlan->back()->getDestination().getID() + ")."); } stop.endPos = attrs.getOptSUMORealReporting(SUMO_ATTR_ENDPOS, 0, ok, MSLane::dictionary(stop.lane)->getLength()); if (attrs.hasAttribute(SUMO_ATTR_POSITION)) { WRITE_WARNING("Deprecated attribute 'pos' in description of stop" + errorSuffix); stop.endPos = attrs.getOptSUMORealReporting(SUMO_ATTR_POSITION, 0, ok, stop.endPos); } stop.startPos = attrs.getOptSUMORealReporting(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS); if (attrs.hasAttribute(SUMO_ATTR_FRIENDLY_POS__DEPRECATED) && !myHaveWarnedAboutDeprecatedFriendlyPos) { myHaveWarnedAboutDeprecatedFriendlyPos = true; WRITE_WARNING("'" + toString(SUMO_ATTR_FRIENDLY_POS__DEPRECATED) + "' is deprecated, use '" + toString(SUMO_ATTR_FRIENDLY_POS) + "' instead."); } bool friendlyPos = attrs.hasAttribute(SUMO_ATTR_FRIENDLY_POS__DEPRECATED) ? attrs.getOptBoolReporting(SUMO_ATTR_FRIENDLY_POS__DEPRECATED, 0, ok, false) : attrs.getOptBoolReporting(SUMO_ATTR_FRIENDLY_POS, 0, ok, false); if (!ok || !checkStopPos(stop.startPos, stop.endPos, MSLane::dictionary(stop.lane)->getLength(), POSITION_EPS, friendlyPos)) { WRITE_ERROR("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.getOptBoolReporting(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)) { WRITE_ERROR("Invalid duration or end time is given for a stop" + errorSuffix); return; } stop.triggered = attrs.getOptBoolReporting(SUMO_ATTR_TRIGGERED, 0, ok, false); } stop.parking = attrs.getOptBoolReporting(SUMO_ATTR_PARKING, 0, ok, stop.triggered); if (!ok) { WRITE_ERROR("Invalid bool for 'triggered' or 'parking' for stop" + errorSuffix); return; } const std::string idx = attrs.getOptStringReporting(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.getIntReporting(SUMO_ATTR_INDEX, 0, ok); if (!ok || stop.index < 0) { WRITE_ERROR("Invalid 'index' for stop" + errorSuffix); return; } } if (myActiveRouteID != "") { myActiveRouteStops.push_back(stop); } else if (myActivePlan) { myActivePlan->push_back(new MSPerson::MSPersonStage_Waiting(MSLane::dictionary(stop.lane)->getEdge(), stop.duration, stop.until)); } else { myVehicleParameter->stops.push_back(stop); } }
void MSRouteHandler::myStartElement(SumoXMLTag element, const SUMOSAXAttributes &attrs) throw(ProcessError) { switch (element) { case SUMO_TAG_VEHICLE: delete myVehicleParameter; myVehicleParameter = SUMOVehicleParserHelper::parseVehicleAttributes(attrs); break; case SUMO_TAG_PERSON: delete myVehicleParameter; myVehicleParameter = SUMOVehicleParserHelper::parseVehicleAttributes(attrs); myActivePlan = new MSPerson::MSPersonPlan(); break; case SUMO_TAG_RIDE: { const std::string pid = myVehicleParameter->id; bool ok = true; MSEdge *from = 0; if (attrs.hasAttribute(SUMO_ATTR_FROM)) { const std::string fromID = attrs.getStringReporting(SUMO_ATTR_FROM, "ride", pid.c_str(), ok); from = MSEdge::dictionary(fromID); if (from==0) { throw ProcessError("The from edge '" + fromID + "' within a ride of person '" + pid + "' is not known."); } if (myActivePlan->empty() || &myActivePlan->back()->getDestination() != from) { myActivePlan->push_back(new MSPerson::MSPersonStage_Waiting(*from, -1, myVehicleParameter->depart)); } } const std::string toID = attrs.getStringReporting(SUMO_ATTR_TO, "ride", pid.c_str(), ok); MSEdge *to = MSEdge::dictionary(toID); if (to==0) { throw ProcessError("The to edge '" + toID + "' within a ride of person '" + pid + "' is not known."); } const std::string desc = attrs.getStringReporting(SUMO_ATTR_LINES, "ride", pid.c_str(), ok); StringTokenizer st(desc); myActivePlan->push_back(new MSPerson::MSPersonStage_Driving(*to, st.getVector())); break; } case SUMO_TAG_WALK: { myActiveRoute.clear(); bool ok = true; MSEdge::parseEdgesList(attrs.getStringReporting(SUMO_ATTR_EDGES, "walk", myVehicleParameter->id.c_str(), ok), myActiveRoute, myActiveRouteID); if (myActiveRoute.empty()) { throw ProcessError("No edges to walk for person '" + myVehicleParameter->id + "'."); } if (myActivePlan->empty() || &myActivePlan->back()->getDestination() != myActiveRoute.front()) { myActivePlan->push_back(new MSPerson::MSPersonStage_Waiting(*myActiveRoute.front(), -1, myVehicleParameter->depart)); } const SUMOTime duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, "walk", 0, ok, -1); const SUMOReal speed = attrs.getOptSUMORealReporting(SUMO_ATTR_SPEED, "walk", 0, ok, -1); myActivePlan->push_back(new MSPerson::MSPersonStage_Walking(myActiveRoute, duration, speed)); myActiveRoute.clear(); break; } case SUMO_TAG_FLOW: delete myVehicleParameter; myVehicleParameter = SUMOVehicleParserHelper::parseFlowAttributes(attrs); if (attrs.hasAttribute(SUMO_ATTR_FROM) && attrs.hasAttribute(SUMO_ATTR_TO)) { myActiveRouteID = "!" + myVehicleParameter->id; bool ok = true; MSEdge::parseEdgesList(attrs.getStringReporting(SUMO_ATTR_FROM, "flow", myVehicleParameter->id.c_str(), ok), myActiveRoute, myActiveRouteID); MSEdge::parseEdgesList(attrs.getStringReporting(SUMO_ATTR_TO, "flow", myVehicleParameter->id.c_str(), ok), myActiveRoute, myActiveRouteID); closeRoute(); } break; case SUMO_TAG_VTYPE: myCurrentVType = SUMOVehicleParserHelper::beginVTypeParsing(attrs); break; case SUMO_TAG_VTYPE_DISTRIBUTION: openVehicleTypeDistribution(attrs); break; case SUMO_TAG_ROUTE: openRoute(attrs); break; case SUMO_TAG_ROUTE_DISTRIBUTION: openRouteDistribution(attrs); break; case SUMO_TAG_TRIPDEF: { bool ok = true; myVehicleParameter = SUMOVehicleParserHelper::parseVehicleAttributes(attrs); myActiveRouteID = "!" + myVehicleParameter->id; if (attrs.hasAttribute(SUMO_ATTR_FROM) || !myVehicleParameter->wasSet(VEHPARS_TAZ_SET)) { MSEdge::parseEdgesList(attrs.getStringReporting(SUMO_ATTR_FROM, "tripdef", myVehicleParameter->id.c_str(), ok), myActiveRoute, myActiveRouteID); MSEdge::parseEdgesList(attrs.getStringReporting(SUMO_ATTR_TO, "tripdef", myVehicleParameter->id.c_str(), ok), myActiveRoute, myActiveRouteID); } else { const MSEdge* fromTaz = MSEdge::dictionary(myVehicleParameter->fromTaz+"-source"); if (fromTaz == 0) { WRITE_ERROR("Source district '" + myVehicleParameter->fromTaz + "' not known for '" + myVehicleParameter->id + "'!"); } else if (fromTaz->getNoFollowing() == 0) { WRITE_ERROR("Source district '" + myVehicleParameter->fromTaz + "' has no outgoing edges for '" + myVehicleParameter->id + "'!"); } else { myActiveRoute.push_back(fromTaz->getFollower(0)); } } closeRoute(); closeVehicle(); } break; default: break; } // parse embedded vtype information if (myCurrentVType!=0&&element!=SUMO_TAG_VTYPE) { SUMOVehicleParserHelper::parseVTypeEmbedded(*myCurrentVType, element, attrs); return; } if (element==SUMO_TAG_STOP) { bool ok = true; SUMOVehicleParameter::Stop stop; // try to parse the assigne bus stop stop.busstop = attrs.getOptStringReporting(SUMO_ATTR_BUS_STOP, "stop", 0, ok, ""); if (stop.busstop!="") { // ok, we have obviously a bus stop MSBusStop *bs = MSNet::getInstance()->getBusStop(stop.busstop); if (bs!=0) { const MSLane &l = bs->getLane(); stop.lane = l.getID(); stop.pos = bs->getEndLanePosition(); } else { MsgHandler::getErrorInstance()->inform("The bus stop '" + stop.busstop + "' is not known."); return; } } else { // no, the lane and the position should be given // get the lane stop.lane = attrs.getOptStringReporting(SUMO_ATTR_LANE, "stop", 0, ok, ""); if (stop.lane!="") { if (MSLane::dictionary(stop.lane)==0) { MsgHandler::getErrorInstance()->inform("The lane '" + stop.lane + "' for a stop is not known."); return; } } else { MsgHandler::getErrorInstance()->inform("A stop must be placed on a bus stop or a lane."); return; } // get the position bool ok = true; stop.pos = attrs.getSUMORealReporting(SUMO_ATTR_POSITION, "stop", 0, ok); if (!ok) { return; } } // get the standing duration if (!attrs.hasAttribute(SUMO_ATTR_DURATION) && !attrs.hasAttribute(SUMO_ATTR_UNTIL)) { MsgHandler::getErrorInstance()->inform("The duration of a stop is not defined."); return; } else { bool ok = true; stop.duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, "stop", 0, ok, -1); stop.until = attrs.getOptSUMOTimeReporting(SUMO_ATTR_UNTIL, "stop", 0, ok, -1); if (!ok) { return; } if (stop.duration<0&&stop.until<0) { MsgHandler::getErrorInstance()->inform("Neither the duration nor the end time is given for a stop."); return; } } if (myActiveRouteID != "") { myActiveRouteStops.push_back(stop); } else { myVehicleParameter->stops.push_back(stop); } } }