void AGActivityGenHandler::parseBusLine(const SUMOSAXAttributes& attrs) { try { myCurrentObject = "busLine"; AGBusLine busL(attrs.getString(SUMO_ATTR_ID)); busL.setMaxTripTime(attrs.getInt(AGEN_ATTR_MAX_TRIP_DURATION)); myCity.busLines.push_front(busL); currentBusLine = &*myCity.busLines.begin(); } catch (const std::exception& e) { WRITE_ERROR("Error while parsing the element " + SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BUSLINE) + ": " + e.what()); throw ProcessError(); } }
// =========================================================================== // method definitions // =========================================================================== // --------------------------------------------------------------------------- // ROLoader::EdgeFloatTimeLineRetriever_EdgeTravelTime - methods // --------------------------------------------------------------------------- void ROLoader::EdgeFloatTimeLineRetriever_EdgeTravelTime::addEdgeWeight(const std::string& id, SUMOReal val, SUMOReal beg, SUMOReal end) const { ROEdge* e = myNet.getEdge(id); if (e != 0) { e->addTravelTime(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 AGActivityGenHandler::parseParameters(const SUMOSAXAttributes& attrs) { try { bool ok; myCity.statData.carPreference = attrs.getOpt<SUMOReal>(AGEN_ATTR_CARPREF, 0, ok, 0.0); myCity.statData.speedTimePerKm = attrs.getOpt<SUMOReal>(AGEN_ATTR_CITYSPEED, 0, ok, 360.0); myCity.statData.freeTimeActivityRate = attrs.getOpt<SUMOReal>(AGEN_ATTR_FREETIMERATE, 0, ok, 0.15); myCity.statData.uniformRandomTrafficRate = attrs.getOpt<SUMOReal>(AGEN_ATTR_UNI_RAND_TRAFFIC, 0, ok, 0.0); myCity.statData.departureVariation = attrs.getOpt<SUMOReal>(AGEN_ATTR_DEP_VARIATION, 0, ok, 0.0); } catch (const std::exception& e) { WRITE_ERROR("Error while parsing the element " + SUMOXMLDefinitions::Tags.getString(AGEN_TAG_PARAM) + ": " + e.what()); throw ProcessError(); } }
SUMOVehicleShape SUMOVehicleParserHelper::parseGuiShape(const SUMOSAXAttributes& attrs, const std::string& id) { bool ok = true; std::string vclassS = attrs.getOpt<std::string>(SUMO_ATTR_GUISHAPE, id.c_str(), ok, ""); if (SumoVehicleShapeStrings.hasString(vclassS)) { const SUMOVehicleShape result = SumoVehicleShapeStrings.get(vclassS); const std::string& realName = SumoVehicleShapeStrings.getString(result); if (realName != vclassS) { WRITE_WARNING("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is deprecated, use '" + realName + "' instead."); } return result; } else { WRITE_ERROR("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is not known."); return SVS_UNKNOWN; } }
void AGActivityGenHandler::parseBusStation(const SUMOSAXAttributes& attrs) { try { std::string edge = attrs.getString(SUMO_ATTR_EDGE); SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION); int id = attrs.getInt(SUMO_ATTR_ID); AGPosition posi(myCity.getStreet(edge), positionOnEdge); myCity.statData.busStations.insert(std::pair<int, AGPosition>(id, posi)); } catch (const std::exception& e) { WRITE_ERROR("Error while parsing the element " + SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BUSSTATION) + ": " + e.what()); throw ProcessError(); } }
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."); } }
void NIImporter_SUMO::addEdge(const SUMOSAXAttributes& attrs) { // get the id, report an error if not given or empty... bool ok = true; std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok); if (!ok) { return; } myCurrentEdge = new EdgeAttrs(); myCurrentEdge->builtEdge = 0; myCurrentEdge->id = id; // get the function myCurrentEdge->func = attrs.getOptStringReporting(SUMO_ATTR_FUNCTION, id.c_str(), ok, "normal"); if (myCurrentEdge->func == toString(EDGEFUNC_INTERNAL)) { return; // skip internal edges } // get the type myCurrentEdge->type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, id.c_str(), ok, ""); // get the origin and the destination node myCurrentEdge->fromNode = attrs.getOptStringReporting(SUMO_ATTR_FROM, id.c_str(), ok, ""); myCurrentEdge->toNode = attrs.getOptStringReporting(SUMO_ATTR_TO, id.c_str(), ok, ""); myCurrentEdge->priority = attrs.getOptIntReporting(SUMO_ATTR_PRIORITY, id.c_str(), ok, -1); myCurrentEdge->type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, id.c_str(), ok, ""); myCurrentEdge->shape = GeomConvHelper::parseShapeReporting( attrs.getOptStringReporting(SUMO_ATTR_SHAPE, id.c_str(), ok, ""), attrs.getObjectType(), id.c_str(), ok, true); NILoader::transformCoordinates(myCurrentEdge->shape, true, myLocation); myCurrentEdge->length = attrs.getOptSUMORealReporting(SUMO_ATTR_LENGTH, id.c_str(), ok, NBEdge::UNSPECIFIED_LOADED_LENGTH); myCurrentEdge->maxSpeed = 0; myCurrentEdge->streetName = attrs.getOptStringReporting(SUMO_ATTR_NAME, id.c_str(), ok, ""); std::string lsfS = toString(LANESPREAD_RIGHT); if (attrs.hasAttribute(SUMO_ATTR_SPREADFUNC__DEPRECATED)) { lsfS = attrs.getStringReporting(SUMO_ATTR_SPREADFUNC__DEPRECATED, id.c_str(), ok); if (!myHaveWarnedAboutDeprecatedSpreadType) { WRITE_WARNING("'" + toString(SUMO_ATTR_SPREADFUNC__DEPRECATED) + "' is deprecated; please use '" + toString(SUMO_ATTR_SPREADTYPE) + "'."); myHaveWarnedAboutDeprecatedSpreadType = true; } } else { lsfS = attrs.getOptStringReporting(SUMO_ATTR_SPREADTYPE, id.c_str(), ok, lsfS); } if (SUMOXMLDefinitions::LaneSpreadFunctions.hasString(lsfS)) { myCurrentEdge->lsf = SUMOXMLDefinitions::LaneSpreadFunctions.get(lsfS); } else { WRITE_ERROR("Unknown spreadType '" + lsfS + "' for edge '" + id + "'."); } }
void NIImporter_SUMO::addEdge(const SUMOSAXAttributes& attrs) { // get the id, report an error if not given or empty... bool ok = true; std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok); if (!ok) { return; } myCurrentEdge = new EdgeAttrs(); myCurrentEdge->builtEdge = 0; myCurrentEdge->id = id; // get the function myCurrentEdge->func = attrs.getEdgeFunc(ok); if (myCurrentEdge->func == EDGEFUNC_CROSSING) { // add the crossing but don't do anything else Crossing c; c.edgeID = id; SUMOSAXAttributes::parseStringVector(attrs.get<std::string>(SUMO_ATTR_CROSSING_EDGES, 0, ok), c.crossingEdges); myPedestrianCrossings[SUMOXMLDefinitions::getJunctionIDFromInternalEdge(id)].push_back(c); return; } else if (myCurrentEdge->func == EDGEFUNC_INTERNAL || myCurrentEdge->func == EDGEFUNC_WALKINGAREA) { return; // skip internal edges } // get the type myCurrentEdge->type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, ""); // get the origin and the destination node myCurrentEdge->fromNode = attrs.getOpt<std::string>(SUMO_ATTR_FROM, id.c_str(), ok, ""); myCurrentEdge->toNode = attrs.getOpt<std::string>(SUMO_ATTR_TO, id.c_str(), ok, ""); myCurrentEdge->priority = attrs.getOpt<int>(SUMO_ATTR_PRIORITY, id.c_str(), ok, -1); myCurrentEdge->type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, ""); myCurrentEdge->shape = attrs.getOpt<PositionVector>(SUMO_ATTR_SHAPE, id.c_str(), ok, PositionVector()); NBNetBuilder::transformCoordinates(myCurrentEdge->shape, true, myLocation); myCurrentEdge->length = attrs.getOpt<SUMOReal>(SUMO_ATTR_LENGTH, id.c_str(), ok, NBEdge::UNSPECIFIED_LOADED_LENGTH); myCurrentEdge->maxSpeed = 0; myCurrentEdge->streetName = attrs.getOpt<std::string>(SUMO_ATTR_NAME, id.c_str(), ok, ""); if (myCurrentEdge->streetName != "" && OptionsCont::getOptions().isDefault("output.street-names")) { OptionsCont::getOptions().set("output.street-names", "true"); } std::string lsfS = toString(LANESPREAD_RIGHT); lsfS = attrs.getOpt<std::string>(SUMO_ATTR_SPREADTYPE, id.c_str(), ok, lsfS); if (SUMOXMLDefinitions::LaneSpreadFunctions.hasString(lsfS)) { myCurrentEdge->lsf = SUMOXMLDefinitions::LaneSpreadFunctions.get(lsfS); } else { WRITE_ERROR("Unknown spreadType '" + lsfS + "' for edge '" + id + "'."); } }
void AGActivityGenHandler::parseBracket(const SUMOSAXAttributes& attrs) { try { //TODO beginAge needs to be evaluated // int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE); //included in the bracket int endAge = attrs.getInt(AGEN_ATTR_ENDAGE); //NOT included in the bracket if (myCurrentObject == "population") { myCity.statData.population[endAge] = attrs.getInt(AGEN_ATTR_PEOPLENBR); } } catch (const std::exception& e) { WRITE_ERROR("Error while parsing the element " + SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BRACKET) + ": " + e.what()); throw ProcessError(); } }
void NLHandler::addWAUTSwitch(const SUMOSAXAttributes& attrs) { bool ok = true; SUMOTime t = attrs.getSUMOTimeReporting(SUMO_ATTR_TIME, myCurrentWAUTID.c_str(), ok); std::string to = attrs.get<std::string>(SUMO_ATTR_TO, myCurrentWAUTID.c_str(), ok); if (!ok) { myCurrentIsBroken = true; } if (!myCurrentIsBroken) { try { myJunctionControlBuilder.getTLLogicControlToUse().addWAUTSwitch(myCurrentWAUTID, t, to); } catch (InvalidArgument& e) { WRITE_ERROR(e.what()); myCurrentIsBroken = true; } } }
void AGActivityGenHandler::parseCityGates(const SUMOSAXAttributes& attrs) { try { std::string edge = attrs.getString(SUMO_ATTR_EDGE); SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION); AGPosition posi(myCity.getStreet(edge), positionOnEdge); myCity.statData.incoming[(int)myCity.cityGates.size()] = attrs.getFloat(AGEN_ATTR_INCOMING); myCity.statData.outgoing[(int)myCity.cityGates.size()] = attrs.getFloat(AGEN_ATTR_OUTGOING); myCity.cityGates.push_back(posi); } catch (const std::exception& e) { WRITE_ERROR("Error while parsing the element " + SUMOXMLDefinitions::Tags.getString(AGEN_TAG_CITYGATES) + ": " + e.what()); throw ProcessError(); } }
bool OptionsCont::set(const std::string& name, const std::string& value) { Option* o = getSecure(name); if (!o->isWriteable()) { reportDoubleSetting(name); return false; } try { if (!o->set(value)) { return false; } } catch (ProcessError& e) { WRITE_ERROR("While processing option '" + name + "':\n " + e.what()); return false; } return true; }
bool NBFrame::checkOptions() { OptionsCont& oc = OptionsCont::getOptions(); bool ok = true; // if (!oc.isDefault("tls-guess.joining")) { WRITE_WARNING("'--tls-guess.joining' was joined with '--tls.join'.\n Please use '--tls.join' in future only."); if (!oc.isSet("tls.join")) { oc.set("tls.join", "true"); } } if (!SUMOXMLDefinitions::TrafficLightTypes.hasString(oc.getString("tls.default-type"))) { WRITE_ERROR("unsupported value '" + oc.getString("tls.default-type") + "' for option '--tls.default-type'"); ok = false; } return ok; }
bool NIVissimSingleTypeParser_Lichtsignalanlagendefinition::parse(std::istream& from) { // int id; from >> id; // std::string tag, name; tag = myRead(from); if (tag == "name") { name = readName(from); tag = myRead(from); } // type std::string type; type = myRead(from); if (type == "festzeit") { return parseFixedTime(id, name, from); } if (type == "vas") { return parseVAS(id, name, from); } if (type == "vsplus") { return parseRestActuated(id, name, from, type); } if (type == "trends") { return parseRestActuated(id, name, from, type); } if (type == "vap") { return parseRestActuated(id, name, from, type); } if (type == "tl") { return parseRestActuated(id, name, from, type); } if (type == "pos") { return parseRestActuated(id, name, from, type); } if (type == "nema") { return parseRestActuated(id, name, from, type); } if (type == "extern") { return parseRestActuated(id, name, from, type); } WRITE_ERROR("Unsupported LSA-Type '" + type + "' occured."); return false; }
void NIImporter_SUMO::addLane(const SUMOSAXAttributes& attrs) { bool ok = true; std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok); if (!ok) { return; } if (!myCurrentEdge) { WRITE_ERROR("Found lane '" + id + "' not within edge element"); return; } if (attrs.getOpt<bool>(SUMO_ATTR_CUSTOMSHAPE, 0, ok, false)) { const std::string nodeID = NBNode::getNodeIDFromInternalLane(id); myCustomShapeMaps[nodeID][id] = attrs.get<PositionVector>(SUMO_ATTR_SHAPE, id.c_str(), ok); } myCurrentLane = new LaneAttrs; if (myCurrentEdge->func == EDGEFUNC_CROSSING) { // save the width and the lane id of the crossing but don't do anything else std::vector<Crossing>& crossings = myPedestrianCrossings[SUMOXMLDefinitions::getJunctionIDFromInternalEdge(myCurrentEdge->id)]; assert(crossings.size() > 0); crossings.back().width = attrs.get<SUMOReal>(SUMO_ATTR_WIDTH, id.c_str(), ok); return; } else if (myCurrentEdge->func == EDGEFUNC_INTERNAL || myCurrentEdge->func == EDGEFUNC_WALKINGAREA) { myHaveSeenInternalEdge = true; return; // skip internal lanes } if (attrs.hasAttribute("maxspeed")) { // !!! deprecated myCurrentLane->maxSpeed = attrs.getFloat("maxspeed"); } else { myCurrentLane->maxSpeed = attrs.get<SUMOReal>(SUMO_ATTR_SPEED, id.c_str(), ok); } try { myCurrentLane->allow = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, id.c_str(), ok, "", false); } catch (EmptyData e) { // !!! deprecated myCurrentLane->allow = ""; } myCurrentLane->disallow = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, id.c_str(), ok, ""); myCurrentLane->width = attrs.getOpt<SUMOReal>(SUMO_ATTR_WIDTH, id.c_str(), ok, (SUMOReal) NBEdge::UNSPECIFIED_WIDTH); myCurrentLane->endOffset = attrs.getOpt<SUMOReal>(SUMO_ATTR_ENDOFFSET, id.c_str(), ok, (SUMOReal) NBEdge::UNSPECIFIED_OFFSET); myCurrentLane->shape = attrs.get<PositionVector>(SUMO_ATTR_SHAPE, id.c_str(), ok); // lane coordinates are derived (via lane spread) do not include them in convex boundary NBNetBuilder::transformCoordinates(myCurrentLane->shape, false, myLocation); }
void GeomConvHelper::emitError(bool report, const std::string& what, const std::string& objecttype, const char* objectid, const std::string& desc) { if (!report) { return; } std::ostringstream oss; oss << what << " of "; if (objectid == 0) { oss << "a(n) "; } oss << objecttype; if (objectid != 0) { oss << " '" << objectid << "'"; } oss << " is broken: " << desc << "."; WRITE_ERROR(oss.str()); }
int NBHeightMapper::loadTiff(const std::string& file) { #ifdef HAVE_GDAL GDALAllRegister(); GDALDataset* poDataset = (GDALDataset*)GDALOpen(file.c_str(), GA_ReadOnly); if (poDataset == 0) { WRITE_ERROR("Cannot load GeoTIFF file."); return 0; } const int xSize = poDataset->GetRasterXSize(); const int ySize = poDataset->GetRasterYSize(); double adfGeoTransform[6]; if (poDataset->GetGeoTransform(adfGeoTransform) == CE_None) { Position topLeft(adfGeoTransform[0], adfGeoTransform[3]); mySizeOfPixel.set(adfGeoTransform[1], adfGeoTransform[5]); const double horizontalSize = xSize * mySizeOfPixel.x(); const double verticalSize = ySize * mySizeOfPixel.y(); myBoundary.add(topLeft); myBoundary.add(topLeft.x() + horizontalSize, topLeft.y() + verticalSize); } else { WRITE_ERROR("Could not parse geo information from " + file + "."); return 0; } const int picSize = xSize * ySize; myRaster = (int16_t*)CPLMalloc(sizeof(int16_t) * picSize); for (int i = 1; i <= poDataset->GetRasterCount(); i++) { GDALRasterBand* poBand = poDataset->GetRasterBand(i); if (poBand->GetColorInterpretation() != GCI_GrayIndex) { WRITE_ERROR("Unknown color band in " + file + "."); clearData(); break; } if (poBand->GetRasterDataType() != GDT_Int16) { WRITE_ERROR("Unknown data type in " + file + "."); clearData(); break; } assert(xSize == poBand->GetXSize() && ySize == poBand->GetYSize()); if (poBand->RasterIO(GF_Read, 0, 0, xSize, ySize, myRaster, xSize, ySize, GDT_Int16, 0, 0) == CE_Failure) { WRITE_ERROR("Failure in reading " + file + "."); clearData(); break; } } GDALClose(poDataset); return picSize; #else UNUSED_PARAMETER(file); WRITE_ERROR("Cannot load GeoTIFF file since SUMO was compiled without GDAL support."); return 0; #endif }
int GUITexturesHelper::getTextureID(const std::string& filename) { if (myTextures.count(filename) == 0) { try { FXImage* i = MFXImageHelper::loadImage(GUIMainWindow::getInstance()->getApp(), filename); if (MFXImageHelper::scalePower2(i, getMaxTextureSize())) { WRITE_WARNING("Scaling '" + filename + "'."); } GUIGlID id = add(i); delete i; myTextures[filename] = (int)id; } catch (InvalidArgument& e) { WRITE_ERROR("Could not load '" + filename + "'.\n" + e.what()); myTextures[filename] = -1; } } return myTextures[filename]; }
PositionVector NIXMLEdgesHandler::tryGetShape(const SUMOSAXAttributes& attrs) { if (!attrs.hasAttribute(SUMO_ATTR_SHAPE)) { return myShape; } // try to build shape bool ok = true; if (!attrs.hasAttribute(SUMO_ATTR_SHAPE)) { myReinitKeepEdgeShape = false; return PositionVector(); } PositionVector shape = attrs.getOpt<PositionVector>(SUMO_ATTR_SHAPE, 0, ok, PositionVector()); if (!NILoader::transformCoordinates(shape)) { WRITE_ERROR("Unable to project coordinates for edge '" + myCurrentID + "'."); } myReinitKeepEdgeShape = myKeepEdgeShape; return shape; }
void NLHandler::parseLanes(const std::string& junctionID, const std::string& def, std::vector<MSLane*>& into, bool& ok) { StringTokenizer st(def); while (ok && st.hasNext()) { std::string laneID = st.next(); MSLane* lane = MSLane::dictionary(laneID); if (!MSGlobals::gUsingInternalLanes && laneID[0] == ':') { continue; } if (lane == 0) { WRITE_ERROR("An unknown lane ('" + laneID + "') was tried to be set as incoming to junction '" + junctionID + "'."); ok = false; continue; } into.push_back(lane); } }
void NIXMLTrafficLightsHandler::myEndElement(int element) { switch (element) { case SUMO_TAG_TLLOGIC: if (!myCurrentTL) { WRITE_ERROR("Unmatched closing tag for tl-logic."); } else { if (!myTLLCont.insert(myCurrentTL)) { WRITE_MESSAGE("Updating program '" + myCurrentTL->getProgramID() + "' for traffic light '" + myCurrentTL->getID() + "'"); } myCurrentTL = 0; } break; default: break; } }
void ShapeHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) { try { switch (element) { case SUMO_TAG_POLY: addPoly(attrs); break; case SUMO_TAG_POI: addPOI(attrs); break; default: break; } } catch (InvalidArgument& e) { WRITE_ERROR(e.what()); } }
bool NWFrame::checkOptions() { OptionsCont& oc = OptionsCont::getOptions(); bool ok = true; // check whether the output is valid and can be build if (!oc.isSet("output-file") && !oc.isSet("plain-output-prefix") && !oc.isSet("matsim-output") && !oc.isSet("opendrive-output") && !oc.isSet("dlr-navteq-output")) { oc.set("output-file", "net.net.xml"); } // some outputs need internal lanes if (oc.isSet("opendrive-output") && oc.getBool("no-internal-links")) { WRITE_ERROR("openDRIVE export needs internal links computation."); ok = false; } return ok; }
void NLHandler::addWAUTJunction(const SUMOSAXAttributes& attrs) { bool ok = true; std::string wautID = attrs.get<std::string>(SUMO_ATTR_WAUT_ID, 0, ok); std::string junctionID = attrs.get<std::string>(SUMO_ATTR_JUNCTION_ID, 0, ok); std::string procedure = attrs.getOpt<std::string>(SUMO_ATTR_PROCEDURE, 0, ok, ""); bool synchron = attrs.getOpt<bool>(SUMO_ATTR_SYNCHRON, 0, ok, false); if (!ok) { myCurrentIsBroken = true; } try { if (!myCurrentIsBroken) { myJunctionControlBuilder.getTLLogicControlToUse().addWAUTJunction(wautID, junctionID, procedure, synchron); } } catch (InvalidArgument& e) { WRITE_ERROR(e.what()); myCurrentIsBroken = true; } }
void AGActivityGenHandler::parseFrequency(const SUMOSAXAttributes& attrs) { if (myCurrentObject != "busLine") { return; } try { int beginB = attrs.getInt(SUMO_ATTR_BEGIN); int endB = attrs.getInt(SUMO_ATTR_END); int rateB = attrs.getInt(AGEN_ATTR_RATE); currentBusLine->generateBuses(beginB, endB, rateB); } catch (const std::exception& e) { WRITE_ERROR("Error while parsing the element " + SUMOXMLDefinitions::Tags.getString(AGEN_TAG_FREQUENCY) + ": " + e.what()); throw ProcessError(); } }
NBLoadedSUMOTLDef* NIXMLTrafficLightsHandler::initTrafficLightLogic(const SUMOSAXAttributes& attrs, NBLoadedSUMOTLDef* currentTL) { if (currentTL) { WRITE_ERROR("Definition of tl-logic '" + currentTL->getID() + "' was not finished."); return 0; } bool ok = true; std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok); std::string programID = attrs.getOptStringReporting(SUMO_ATTR_PROGRAMID, id.c_str(), ok, "<unknown>"); SUMOTime offset = attrs.hasAttribute(SUMO_ATTR_OFFSET) ? TIME2STEPS(attrs.getSUMORealReporting(SUMO_ATTR_OFFSET, id.c_str(), ok)) : 0; // there are two scenarios to consider // 1) the tll.xml is loaded to update traffic lights defined in a net.xml: // simply retrieve the loaded definitions and update them // 2) the tll.xml is loaded to define new traffic lights // nod.xml will have triggered building of NBOwnTLDef. Replace it with NBLoadedSUMOTLDef NBLoadedSUMOTLDef* loadedDef = dynamic_cast<NBLoadedSUMOTLDef*>(myTLLCont.getDefinition(id, programID)); if (loadedDef == 0) { // case 2 NBOwnTLDef* newDef = dynamic_cast<NBOwnTLDef*>(myTLLCont.getDefinition( id, NBTrafficLightDefinition::DefaultProgramID)); assert(newDef != 0); loadedDef = new NBLoadedSUMOTLDef(id, programID, offset); std::vector<NBNode*> nodes = newDef->getControlledNodes(); for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) { (*it)->removeTrafficLight(newDef); (*it)->addTrafficLight(loadedDef); } myTLLCont.removeProgram(id, NBTrafficLightDefinition::DefaultProgramID); myTLLCont.insert(loadedDef); std::string type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, 0, ok, toString(TLTYPE_STATIC)); if (type != toString(TLTYPE_STATIC)) { WRITE_WARNING("Traffic light '" + id + "' has unsupported type '" + type + "' and will be converted to '" + toString(TLTYPE_STATIC) + "'"); } } if (ok) { myResetPhases = true; return loadedDef; } else { return 0; } }
bool MSTLLogicControl::TLSLogicVariants::checkOriginalTLS() const { bool hadErrors = false; for (std::map<std::string, MSTrafficLightLogic*>::const_iterator j = myVariants.begin(); j != myVariants.end(); ++j) { const MSTrafficLightLogic::Phases& phases = (*j).second->getPhases(); unsigned int linkNo = (unsigned int)(*j).second->getLinks().size(); bool hadProgramErrors = false; for (MSTrafficLightLogic::Phases::const_iterator i = phases.begin(); i != phases.end(); ++i) { if ((*i)->getState().length() < linkNo) { hadProgramErrors = true; } } if (hadProgramErrors) { WRITE_ERROR("Mismatching phase size in tls '" + (*j).second->getID() + "', program '" + (*j).first + "'."); hadErrors = true; } } return !hadErrors; }
void MSRouteHandler::openRoute(const SUMOSAXAttributes& attrs) { // check whether the id is really necessary std::string rid; if (myCurrentRouteDistribution != 0) { myActiveRouteID = myCurrentRouteDistributionID + "#" + toString(myCurrentRouteDistribution->getProbs().size()); // !!! document this rid = "distribution '" + myCurrentRouteDistributionID + "'"; } else if (myVehicleParameter != 0) { // ok, a vehicle is wrapping the route, // we may use this vehicle's id as default myActiveRouteID = "!" + myVehicleParameter->id; // !!! document this if (attrs.hasAttribute(SUMO_ATTR_ID)) { WRITE_WARNING("Ids of internal routes are ignored (vehicle '" + myVehicleParameter->id + "')."); } } else { bool ok = true; myActiveRouteID = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok, false); if (!ok) { return; } rid = "'" + myActiveRouteID + "'"; } if (myVehicleParameter != 0) { // have to do this here for nested route distributions rid = "for vehicle '" + myVehicleParameter->id + "'"; } bool ok = true; if (attrs.hasAttribute(SUMO_ATTR_EDGES)) { MSEdge::parseEdgesList(attrs.getStringReporting(SUMO_ATTR_EDGES, myActiveRouteID.c_str(), ok), myActiveRoute, rid); } myActiveRouteRefID = attrs.getOptStringReporting(SUMO_ATTR_REFID, myActiveRouteID.c_str(), ok, ""); if (attrs.hasAttribute(SUMO_ATTR_REFID__DEPRECATED)) { myActiveRouteRefID = attrs.getOptStringReporting(SUMO_ATTR_REFID__DEPRECATED, myActiveRouteID.c_str(), ok, ""); if (!myHaveWarnedAboutDeprecatedRefID) { myHaveWarnedAboutDeprecatedRefID = true; WRITE_WARNING("'" + toString(SUMO_ATTR_REFID__DEPRECATED) + "' is deprecated, please use '" + toString(SUMO_ATTR_REFID) + "' instead."); } } if (myActiveRouteRefID != "" && MSRoute::dictionary(myActiveRouteRefID) == 0) { WRITE_ERROR("Invalid reference to route '" + myActiveRouteRefID + "' in route " + rid + "."); } myActiveRouteProbability = attrs.getOptSUMORealReporting(SUMO_ATTR_PROB, myActiveRouteID.c_str(), ok, DEFAULT_VEH_PROB); myActiveRouteColor = attrs.hasAttribute(SUMO_ATTR_COLOR) ? RGBColor::parseColorReporting(attrs.getString(SUMO_ATTR_COLOR), attrs.getObjectType(), myActiveRouteID.c_str(), true, ok) : RGBColor::getDefaultColor(); }
void NIImporter_SUMO::addJunction(const SUMOSAXAttributes& attrs) { // get the id, report an error if not given or empty... bool ok = true; std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok); if (!ok) { return; } if (id[0] == ':') { // internal node return; } SumoXMLNodeType type = NODETYPE_UNKNOWN; std::string typeS = attrs.getStringReporting(SUMO_ATTR_TYPE, id.c_str(), ok); if (SUMOXMLDefinitions::NodeTypes.hasString(typeS)) { type = SUMOXMLDefinitions::NodeTypes.get(typeS); if (type == NODETYPE_DEAD_END_DEPRECATED) { // patch legacy type type = NODETYPE_DEAD_END; } } else { WRITE_WARNING("Unknown node type '" + typeS + "' for junction '" + id + "'."); } Position pos = readPosition(attrs, id, ok); NILoader::transformCoordinates(pos, true, myLocation); // the network may have been built with the option "plain.keep-edge-shape" this // makes accurate reconstruction of legacy networks impossible. We ought to warn about this std::string shapeS = attrs.getStringReporting(SUMO_ATTR_SHAPE, id.c_str(), ok, false); if (shapeS != "") { PositionVector shape = GeomConvHelper::parseShapeReporting( shapeS, attrs.getObjectType(), id.c_str(), ok, false); shape.push_back_noDoublePos(shape[0]); // need closed shape if (!shape.around(pos) && shape.distance(pos) > 1) { // MAGIC_THRESHOLD // WRITE_WARNING("Junction '" + id + "': distance between pos and shape is " + toString(shape.distance(pos))); mySuspectKeepShape = true; } } NBNode* node = new NBNode(id, pos, type); if (!myNodeCont.insert(node)) { WRITE_ERROR("Problems on adding junction '" + id + "'."); delete node; return; } }
void RODFDetector::buildDestinationDistribution(const RODFDetectorCon& detectors, SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, const RODFNet& net, std::map<size_t, RandomDistributor<size_t>* >& into) const { if (myRoutes == 0) { if (myType != DISCARDED_DETECTOR && myType != BETWEEN_DETECTOR) { WRITE_ERROR("Missing routes for detector '" + myID + "'."); } return; } std::vector<RODFRouteDesc>& descs = myRoutes->get(); // iterate through time (in output interval steps) for (SUMOTime time = startTime; time < endTime; time += stepOffset) { into[time] = new RandomDistributor<size_t>(); std::map<ROEdge*, SUMOReal> flowMap; // iterate through the routes size_t index = 0; for (std::vector<RODFRouteDesc>::iterator ri = descs.begin(); ri != descs.end(); ++ri, index++) { SUMOReal prob = 1.; for (std::vector<ROEdge*>::iterator j = (*ri).edges2Pass.begin(); j != (*ri).edges2Pass.end() && prob > 0; ++j) { if (!net.hasDetector(*j)) { continue; } const RODFDetector& det = detectors.getAnyDetectorForEdge(static_cast<RODFEdge*>(*j)); const std::vector<std::map<RODFEdge*, SUMOReal> >& probs = det.getSplitProbabilities(); if (probs.size() == 0) { prob = 0; continue; } const std::map<RODFEdge*, SUMOReal>& tprobs = probs[(time - startTime) / stepOffset]; for (std::map<RODFEdge*, SUMOReal>::const_iterator k = tprobs.begin(); k != tprobs.end(); ++k) { if (find(j, (*ri).edges2Pass.end(), (*k).first) != (*ri).edges2Pass.end()) { prob *= (*k).second; } } } into[time]->add(prob, index); (*ri).overallProb = prob; } } }