// =========================================================================== // method definitions // =========================================================================== // --------------------------------------------------------------------------- // static methods (interface in this case) // --------------------------------------------------------------------------- void NIImporter_RobocupRescue::loadNetwork(const OptionsCont& oc, NBNetBuilder& nb) { // check whether the option is set (properly) if (!oc.isSet("robocup-dir")) { return; } // build the handler NIImporter_RobocupRescue handler(nb.getNodeCont(), nb.getEdgeCont()); // parse file(s) std::vector<std::string> files = oc.getStringVector("robocup-dir"); for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { // nodes std::string nodesName = (*file) + "/node.bin"; if (!FileHelpers::exists(nodesName)) { WRITE_ERROR("Could not open robocup-node-file '" + nodesName + "'."); return; } PROGRESS_BEGIN_MESSAGE("Parsing robocup-nodes from '" + nodesName + "'"); handler.loadNodes(nodesName); PROGRESS_DONE_MESSAGE(); // edges std::string edgesName = (*file) + "/road.bin"; if (!FileHelpers::exists(edgesName)) { WRITE_ERROR("Could not open robocup-road-file '" + edgesName + "'."); return; } PROGRESS_BEGIN_MESSAGE("Parsing robocup-roads from '" + edgesName + "'"); handler.loadEdges(edgesName); PROGRESS_DONE_MESSAGE(); } }
void NBHeightMapper::loadIfSet(OptionsCont& oc) { if (oc.isSet("heightmap.geotiff")) { // parse file(s) std::vector<std::string> files = oc.getStringVector("heightmap.geotiff"); for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { PROGRESS_BEGIN_MESSAGE("Parsing from GeoTIFF '" + *file + "'"); int numFeatures = Singleton.loadTiff(*file); MsgHandler::getMessageInstance()->endProcessMsg( " done (parsed " + toString(numFeatures) + " features, Boundary: " + toString(Singleton.getBoundary()) + ")."); } } if (oc.isSet("heightmap.shapefiles")) { // parse file(s) std::vector<std::string> files = oc.getStringVector("heightmap.shapefiles"); for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { PROGRESS_BEGIN_MESSAGE("Parsing from shape-file '" + *file + "'"); int numFeatures = Singleton.loadShapeFile(*file); MsgHandler::getMessageInstance()->endProcessMsg( " done (parsed " + toString(numFeatures) + " features, Boundary: " + toString(Singleton.getBoundary()) + ")."); } } }
// =========================================================================== // method definitions // =========================================================================== // --------------------------------------------------------------------------- // static methods // --------------------------------------------------------------------------- void NIImporter_MATSim::loadNetwork(const OptionsCont& oc, NBNetBuilder& nb) { // check whether the option is set (properly) if (!oc.isSet("matsim-files")) { return; } /* Parse file(s) * Each file is parsed twice: first for nodes, second for edges. */ std::vector<std::string> files = oc.getStringVector("matsim-files"); // load nodes, first NodesHandler nodesHandler(nb.getNodeCont()); for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { // nodes if (!FileHelpers::isReadable(*file)) { WRITE_ERROR("Could not open matsim-file '" + *file + "'."); return; } nodesHandler.setFileName(*file); PROGRESS_BEGIN_MESSAGE("Parsing nodes from matsim-file '" + *file + "'"); if (!XMLSubSys::runParser(nodesHandler, *file)) { return; } PROGRESS_DONE_MESSAGE(); } // load edges, then EdgesHandler edgesHandler(nb.getNodeCont(), nb.getEdgeCont(), oc.getBool("matsim.keep-length"), oc.getBool("matsim.lanes-from-capacity"), NBCapacity2Lanes(oc.getFloat("lanes-from-capacity.norm"))); for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { // edges edgesHandler.setFileName(*file); PROGRESS_BEGIN_MESSAGE("Parsing edges from matsim-file '" + *file + "'"); XMLSubSys::runParser(edgesHandler, *file); PROGRESS_DONE_MESSAGE(); } }
void ROLoader::loadNet(RONet& toFill, ROAbstractEdgeBuilder& eb) { std::string file = myOptions.getString("net-file"); if (file == "") { throw ProcessError("Missing definition of network to load!"); } if (!FileHelpers::exists(file)) { throw ProcessError("The network file '" + file + "' could not be found."); } PROGRESS_BEGIN_MESSAGE("Loading net"); RONetHandler handler(toFill, eb); handler.setFileName(file); if (!XMLSubSys::runParser(handler, file)) { PROGRESS_FAILED_MESSAGE(); throw ProcessError(); } else { PROGRESS_DONE_MESSAGE(); } if (myOptions.isSet("taz-files", false)) { // dfrouter does not register this option file = myOptions.getString("taz-files"); if (!FileHelpers::exists(file)) { throw ProcessError("The districts file '" + file + "' could not be found."); } PROGRESS_BEGIN_MESSAGE("Loading districts"); handler.setFileName(file); if (!XMLSubSys::runParser(handler, file)) { PROGRESS_FAILED_MESSAGE(); throw ProcessError(); } else { PROGRESS_DONE_MESSAGE(); } } }
// =========================================================================== // method definitions // =========================================================================== // --------------------------------------------------------------------------- // static methods // --------------------------------------------------------------------------- void NIImporter_ITSUMO::loadNetwork(const OptionsCont& oc, NBNetBuilder& nb) { // check whether the option is set (properly) if (!oc.isSet("itsumo-files")) { return; } /* Parse file(s) * Each file is parsed twice: first for nodes, second for edges. */ std::vector<std::string> files = oc.getStringVector("itsumo-files"); // load nodes, first Handler Handler(nb); for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { // nodes if (!FileHelpers::exists(*file)) { WRITE_ERROR("Could not open itsumo-file '" + *file + "'."); return; } Handler.setFileName(*file); PROGRESS_BEGIN_MESSAGE("Parsing nodes from itsumo-file '" + *file + "'"); if (!XMLSubSys::runParser(Handler, *file)) { return; } PROGRESS_DONE_MESSAGE(); } }
void OptionsIO::loadConfiguration() { OptionsCont& oc = OptionsCont::getOptions(); if (!oc.exists("configuration-file") || !oc.isSet("configuration-file")) { return; } std::string path = oc.getString("configuration-file"); if (!FileHelpers::exists(path)) { throw ProcessError("Could not find configuration '" + oc.getString("configuration-file") + "'."); } PROGRESS_BEGIN_MESSAGE("Loading configuration"); // build parser SAXParser parser; parser.setValidationScheme(SAXParser::Val_Auto); parser.setDoNamespaces(false); parser.setDoSchema(false); // start the parsing OptionsLoader handler; try { parser.setDocumentHandler(&handler); parser.setErrorHandler(&handler); parser.parse(path.c_str()); if (handler.errorOccured()) { throw ProcessError("Could not load configuration '" + path + "'."); } } catch (const XMLException& e) { throw ProcessError("Could not load configuration '" + path + "':\n " + TplConvert<XMLCh>::_2str(e.getMessage())); } oc.relocateFiles(path); PROGRESS_DONE_MESSAGE(); }
void NILoader::loadXMLType(SUMOSAXHandler* handler, const std::vector<std::string>& files, const std::string& type) { // build parser std::string exceptMsg = ""; // start the parsing try { for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { if (!FileHelpers::exists(*file)) { WRITE_ERROR("Could not open " + type + "-file '" + *file + "'."); exceptMsg = "Process Error"; continue; } PROGRESS_BEGIN_MESSAGE("Parsing " + type + " from '" + *file + "'"); XMLSubSys::runParser(*handler, *file); PROGRESS_DONE_MESSAGE(); } } catch (const XERCES_CPP_NAMESPACE::XMLException& toCatch) { exceptMsg = TplConvert::_2str(toCatch.getMessage()) + "\n The " + type + " could not be loaded from '" + handler->getFileName() + "'."; } catch (const ProcessError& toCatch) { exceptMsg = std::string(toCatch.what()) + "\n The " + type + " could not be loaded from '" + handler->getFileName() + "'."; } catch (...) { exceptMsg = "The " + type + " could not be loaded from '" + handler->getFileName() + "'."; } delete handler; if (exceptMsg != "") { throw ProcessError(exceptMsg); } }
void NWFrame::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) { long before = SysUtils::getCurrentMillis(); PROGRESS_BEGIN_MESSAGE("Writing network"); NWWriter_SUMO::writeNetwork(oc, nb); NWWriter_Amitran::writeNetwork(oc, nb); NWWriter_MATSim::writeNetwork(oc, nb); NWWriter_OpenDrive::writeNetwork(oc, nb); NWWriter_DlrNavteq::writeNetwork(oc, nb); NWWriter_XML::writeNetwork(oc, nb); PROGRESS_TIME_MESSAGE(before); }
void ROLoader::loadNet(RONet& toFill, ROAbstractEdgeBuilder& eb) { std::string file = myOptions.getString("net-file"); if (file == "") { throw ProcessError("Missing definition of network to load!"); } if (!FileHelpers::isReadable(file)) { throw ProcessError("The network file '" + file + "' is not accessible."); } PROGRESS_BEGIN_MESSAGE("Loading net"); RONetHandler handler(toFill, eb); handler.setFileName(file); if (!XMLSubSys::runParser(handler, file, true)) { PROGRESS_FAILED_MESSAGE(); throw ProcessError(); } else { PROGRESS_DONE_MESSAGE(); } if (!deprecatedVehicleClassesSeen.empty()) { WRITE_WARNING("Deprecated vehicle classes '" + toString(deprecatedVehicleClassesSeen) + "' in input network."); deprecatedVehicleClassesSeen.clear(); } if (myOptions.isSet("additional-files", false)) { // dfrouter does not register this option std::vector<std::string> files = myOptions.getStringVector("additional-files"); for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) { if (!FileHelpers::isReadable(*fileIt)) { throw ProcessError("The additional file '" + *fileIt + "' is not accessible."); } PROGRESS_BEGIN_MESSAGE("Loading additional file '" + *fileIt + "' "); handler.setFileName(*fileIt); if (!XMLSubSys::runParser(handler, *fileIt)) { PROGRESS_FAILED_MESSAGE(); throw ProcessError(); } else { PROGRESS_DONE_MESSAGE(); } } } }
void PCLoaderDlrNavteq::loadPolyFiles(OptionsCont& oc, PCPolyContainer& toFill, PCTypeMap& tm) { std::vector<std::string> files = oc.getStringVector("dlr-navteq-poly-files"); for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { if (!FileHelpers::isReadable(*file)) { throw ProcessError("Could not open dlr-navteq-poly-file '" + *file + "'."); } PROGRESS_BEGIN_MESSAGE("Parsing pois from dlr-navteq-poly-file '" + *file + "'"); loadPolyFile(*file, oc, toFill, tm); PROGRESS_DONE_MESSAGE(); } }
// =========================================================================== // method definitions // =========================================================================== void AGActivityGen::importInfoCity() { AGActivityGenHandler handler(city, net); PROGRESS_BEGIN_MESSAGE("Reading input"); if (!XMLSubSys::runParser(handler, inputFile)) { PROGRESS_FAILED_MESSAGE(); throw ProcessError(); } else { PROGRESS_DONE_MESSAGE(); } PROGRESS_BEGIN_MESSAGE("Consolidating statistics"); city.statData.consolidateStat(); //some maps are still not PROGRESS_DONE_MESSAGE(); PROGRESS_BEGIN_MESSAGE("Building street representation"); city.completeStreets(); PROGRESS_DONE_MESSAGE(); PROGRESS_BEGIN_MESSAGE("Generating work positions"); city.generateWorkPositions(); PROGRESS_DONE_MESSAGE(); PROGRESS_BEGIN_MESSAGE("Building bus lines"); city.completeBusLines(); PROGRESS_DONE_MESSAGE(); PROGRESS_BEGIN_MESSAGE("Generating population"); city.generatePopulation(); PROGRESS_DONE_MESSAGE(); PROGRESS_BEGIN_MESSAGE("Allocating schools"); city.schoolAllocation(); PROGRESS_DONE_MESSAGE(); PROGRESS_BEGIN_MESSAGE("Allocating work places"); city.workAllocation(); PROGRESS_DONE_MESSAGE(); PROGRESS_BEGIN_MESSAGE("Allocating car places"); city.carAllocation(); PROGRESS_DONE_MESSAGE(); }
void ODDistrictCont::loadDistricts(std::string districtfile) { if (!FileHelpers::exists(districtfile)) { throw ProcessError("Could not find network '" + districtfile + "' to load."); } PROGRESS_BEGIN_MESSAGE("Loading districts from '" + districtfile + "'"); // build the xml-parser and handler ODDistrictHandler handler(*this, districtfile); if (!XMLSubSys::runParser(handler, districtfile)) { PROGRESS_FAILED_MESSAGE(); } else { PROGRESS_DONE_MESSAGE(); } }
// =========================================================================== // method definitions // =========================================================================== void PCLoaderArcView::loadIfSet(OptionsCont& oc, PCPolyContainer& toFill, PCTypeMap& tm) { if (!oc.isSet("shapefile-prefixes")) { return; } // parse file(s) std::vector<std::string> files = oc.getStringVector("shapefile-prefixes"); for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { PROGRESS_BEGIN_MESSAGE("Parsing from shape-file '" + *file + "'"); load(*file, oc, toFill, tm); PROGRESS_DONE_MESSAGE(); } }
void ODMatrix::loadRoutes(OptionsCont& oc, SUMOSAXHandler& handler) { std::vector<std::string> routeFiles = oc.getStringVector("route-files"); for (std::vector<std::string>::iterator i = routeFiles.begin(); i != routeFiles.end(); ++i) { if (!FileHelpers::isReadable(*i)) { throw ProcessError("Could not access route file '" + *i + "' to load."); } PROGRESS_BEGIN_MESSAGE("Loading routes and trips from '" + *i + "'"); if (!XMLSubSys::runParser(handler, *i)) { PROGRESS_FAILED_MESSAGE(); } else { PROGRESS_DONE_MESSAGE(); } } }
void ODMatrix::readO(LineReader& lr, double scale, std::string vehType, bool matrixHasVehType) { PROGRESS_BEGIN_MESSAGE("Reading matrix '" + lr.getFileName() + "' stored as OR"); // parse first defs std::string line; if (matrixHasVehType) { line = getNextNonCommentLine(lr); int type = TplConvert::_2int(StringUtils::prune(line).c_str()); if (vehType == "") { vehType = toString(type); } } // parse time std::pair<SUMOTime, SUMOTime> times = readTime(lr); SUMOTime begin = times.first; SUMOTime end = times.second; // factor double factor = readFactor(lr, scale); // parse the cells while (lr.hasMore()) { line = getNextNonCommentLine(lr); if (line.length() == 0) { continue; } StringTokenizer st2(line, StringTokenizer::WHITECHARS); if (st2.size() == 0) { continue; } try { std::string sourceD = st2.next(); std::string destD = st2.next(); double vehNumber = TplConvert::_2double(st2.next().c_str()) * factor; if (vehNumber != 0) { add(vehNumber, begin, end, sourceD, destD, vehType); } } catch (OutOfBoundsException&) { throw ProcessError("Missing at least one information in line '" + line + "'."); } catch (NumberFormatException&) { throw ProcessError("Not numeric vehicle number in line '" + line + "'."); } } PROGRESS_DONE_MESSAGE(); }
bool NLBuilder::load(const std::string& mmlWhat, const bool isNet) { if (!myOptions.isUsableFileList(mmlWhat)) { return false; } std::vector<std::string> files = myOptions.getStringVector(mmlWhat); for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) { PROGRESS_BEGIN_MESSAGE("Loading " + mmlWhat + " from '" + *fileIt + "'"); long before = SysUtils::getCurrentMillis(); if (!XMLSubSys::runParser(myXMLHandler, *fileIt, isNet)) { WRITE_MESSAGE("Loading of " + mmlWhat + " failed."); return false; } PROGRESS_TIME_MESSAGE(before); } return true; }
// =========================================================================== // method definitions // =========================================================================== void PCLoaderVisum::loadIfSet(OptionsCont& oc, PCPolyContainer& toFill, PCTypeMap& tm) { if (!oc.isSet("visum-files")) { return; } // parse file(s) std::vector<std::string> files = oc.getStringVector("visum-files"); for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { if (!FileHelpers::exists(*file)) { throw ProcessError("Could not open visum-file '" + *file + "'."); } PROGRESS_BEGIN_MESSAGE("Parsing from visum-file '" + *file + "'"); load(*file, oc, toFill, tm); PROGRESS_DONE_MESSAGE(); } }
void ODMatrix::loadMatrix(OptionsCont& oc) { std::vector<std::string> files = oc.getStringVector("od-matrix-files"); for (std::vector<std::string>::iterator i = files.begin(); i != files.end(); ++i) { LineReader lr(*i); if (!lr.good()) { throw ProcessError("Could not open '" + (*i) + "'."); } std::string type = lr.readLine(); // get the type only if (type.find(';') != std::string::npos) { type = type.substr(0, type.find(';')); } // parse type-dependant if (type.length() > 1 && type[1] == 'V') { // process ptv's 'V'-matrices if (type.find('N') != std::string::npos) { throw ProcessError("'" + *i + "' does not contain the needed information about the time described."); } readV(lr, oc.getFloat("scale"), oc.getString("vtype"), type.find('M') != std::string::npos); } else if (type.length() > 1 && type[1] == 'O') { // process ptv's 'O'-matrices if (type.find('N') != std::string::npos) { throw ProcessError("'" + *i + "' does not contain the needed information about the time described."); } readO(lr, oc.getFloat("scale"), oc.getString("vtype"), type.find('M') != std::string::npos); } else { throw ProcessError("'" + *i + "' uses an unknown matrix type '" + type + "'."); } } std::vector<std::string> amitranFiles = oc.getStringVector("od-amitran-files"); for (std::vector<std::string>::iterator i = amitranFiles.begin(); i != amitranFiles.end(); ++i) { if (!FileHelpers::isReadable(*i)) { throw ProcessError("Could not access matrix file '" + *i + "' to load."); } PROGRESS_BEGIN_MESSAGE("Loading matrix in Amitran format from '" + *i + "'"); ODAmitranHandler handler(*this, *i); if (!XMLSubSys::runParser(handler, *i)) { PROGRESS_FAILED_MESSAGE(); } else { PROGRESS_DONE_MESSAGE(); } } }
// =========================================================================== // method definitions // =========================================================================== // --------------------------------------------------------------------------- // static interface // --------------------------------------------------------------------------- void PCLoaderXML::loadIfSet(OptionsCont& oc, PCPolyContainer& toFill, PCTypeMap& tm) { if (!oc.isSet("xml-files")) { return; } PCLoaderXML handler(toFill, tm, oc); // parse file(s) std::vector<std::string> files = oc.getStringVector("xml"); for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { if (!FileHelpers::isReadable(*file)) { throw ProcessError("Could not open xml-file '" + *file + "'."); } PROGRESS_BEGIN_MESSAGE("Parsing XML from '" + *file + "'"); if (!XMLSubSys::runParser(handler, *file)) { throw ProcessError(); } PROGRESS_DONE_MESSAGE(); } }
void readDetectorFlows(RODFDetectorFlows& flows, OptionsCont& oc, RODFDetectorCon& dc) { if (!oc.isSet("measure-files")) { // ok, not given, return an empty container return; } // check whether the file exists std::vector<std::string> files = oc.getStringVector("measure-files"); for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) { if (!FileHelpers::exists(*fileIt)) { throw ProcessError("The measure-file '" + *fileIt + "' can not be opened."); } // parse PROGRESS_BEGIN_MESSAGE("Loading flows from '" + *fileIt + "'"); RODFDetFlowLoader dfl(dc, flows, string2time(oc.getString("begin")), string2time(oc.getString("end")), string2time(oc.getString("time-offset")), string2time(oc.getString("time-factor"))); dfl.read(*fileIt); PROGRESS_DONE_MESSAGE(); } }
bool ROLoader::loadWeights(RONet& net, const std::string& optionName, const std::string& measure, bool useLanes) { // check whether the file exists if (!myOptions.isUsableFileList(optionName)) { return false; } // build and prepare the weights handler std::vector<SAXWeightsHandler::ToRetrieveDefinition*> retrieverDefs; // travel time, first (always used) EdgeFloatTimeLineRetriever_EdgeTravelTime ttRetriever(net); retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition("traveltime", !useLanes, ttRetriever)); // the measure to use, then EdgeFloatTimeLineRetriever_EdgeWeight eRetriever(net); if (measure != "traveltime") { std::string umeasure = measure; if (measure == "CO" || measure == "CO2" || measure == "HC" || measure == "PMx" || measure == "NOx" || measure == "fuel") { umeasure = measure + "_perVeh"; } retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition(umeasure, !useLanes, eRetriever)); } // set up handler SAXWeightsHandler handler(retrieverDefs, ""); // go through files std::vector<std::string> files = myOptions.getStringVector(optionName); for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) { PROGRESS_BEGIN_MESSAGE("Loading precomputed net weights from '" + *fileIt + "'"); if (XMLSubSys::runParser(handler, *fileIt)) { PROGRESS_DONE_MESSAGE(); } else { WRITE_MESSAGE("failed."); return false; } } // build edge-internal time lines const std::map<std::string, ROEdge*>& edges = net.getEdgeMap(); for (std::map<std::string, ROEdge*>::const_iterator i = edges.begin(); i != edges.end(); ++i) { (*i).second->buildTimeLines(measure); } return true; }
void NBNetBuilder::moveToOrigin(GeoConvHelper& geoConvHelper, bool lefthand) { long before = SysUtils::getCurrentMillis(); PROGRESS_BEGIN_MESSAGE("Moving network to origin"); Boundary boundary = geoConvHelper.getConvBoundary(); const SUMOReal x = -boundary.xmin(); const SUMOReal y = -(lefthand ? boundary.ymax() : boundary.ymin()); //if (lefthand) { // y = boundary.ymax(); //} for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) { (*i).second->reshiftPosition(x, y); } for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) { (*i).second->reshiftPosition(x, y); } for (std::map<std::string, NBDistrict*>::const_iterator i = myDistrictCont.begin(); i != myDistrictCont.end(); ++i) { (*i).second->reshiftPosition(x, y); } geoConvHelper.moveConvertedBy(x, y); PROGRESS_TIME_MESSAGE(before); }
void RODFNet::computeTypes(RODFDetectorCon& detcont, bool sourcesStrict) const { PROGRESS_BEGIN_MESSAGE("Computing detector types"); const std::vector< RODFDetector*>& dets = detcont.getDetectors(); // build needed information. first buildDetectorEdgeDependencies(detcont); // compute detector types then for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) { if (isSource(**i, detcont, sourcesStrict)) { (*i)->setType(SOURCE_DETECTOR); mySourceNumber++; } if (isDestination(**i, detcont)) { (*i)->setType(SINK_DETECTOR); mySinkNumber++; } if ((*i)->getType() == TYPE_NOT_DEFINED) { (*i)->setType(BETWEEN_DETECTOR); myInBetweenNumber++; } } // recheck sources for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) { if ((*i)->getType() == SOURCE_DETECTOR && isFalseSource(**i, detcont)) { (*i)->setType(DISCARDED_DETECTOR); myInvalidNumber++; mySourceNumber--; } } // print results PROGRESS_DONE_MESSAGE(); WRITE_MESSAGE("Computed detector types:"); WRITE_MESSAGE(" " + toString(mySourceNumber) + " source detectors"); WRITE_MESSAGE(" " + toString(mySinkNumber) + " sink detectors"); WRITE_MESSAGE(" " + toString(myInBetweenNumber) + " in-between detectors"); WRITE_MESSAGE(" " + toString(myInvalidNumber) + " invalid detectors"); }
/* ------------------------------------------------------------------------- * data processing methods * ----------------------------------------------------------------------- */ void readDetectors(RODFDetectorCon& detectors, OptionsCont& oc, RODFNet* optNet) { if (!oc.isSet("detector-files")) { throw ProcessError("No detector file given (use --detector-files <FILE>)."); } // read definitions stored in XML-format std::vector<std::string> files = oc.getStringVector("detector-files"); for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) { if (!FileHelpers::exists(*fileIt)) { throw ProcessError("Could not open detector file '" + *fileIt + "'"); } PROGRESS_BEGIN_MESSAGE("Loading detector definitions from '" + *fileIt + "'"); RODFDetectorHandler handler(optNet, oc.getBool("ignore-invalid-detectors"), detectors, *fileIt); if (XMLSubSys::runParser(handler, *fileIt)) { PROGRESS_DONE_MESSAGE(); } else { PROGRESS_FAILED_MESSAGE(); throw ProcessError(); } } if (detectors.getDetectors().empty()) { throw ProcessError("No detectors found."); } }
void NIImporter_VISUM::load() { // open the file if (!myLineReader.setFile(myFileName)) { throw ProcessError("Can not open visum-file '" + myFileName + "'."); } // scan the file for data positions while (myLineReader.hasMore()) { std::string line = myLineReader.readLine(); if (line.length() > 0 && line[0] == '$') { ParserVector::iterator i; for (i = mySingleDataParsers.begin(); i != mySingleDataParsers.end(); i++) { std::string dataName = "$" + (*i).name + ":"; if (line.substr(0, dataName.length()) == dataName) { (*i).position = myLineReader.getPosition(); (*i).pattern = line.substr(dataName.length()); WRITE_MESSAGE("Found: " + dataName + " at " + toString<int>(myLineReader.getPosition())); } } } } // go through the parsers and process all entries for (ParserVector::iterator i = mySingleDataParsers.begin(); i != mySingleDataParsers.end(); i++) { if ((*i).position < 0) { // do not process using parsers for which no information was found continue; } // ok, the according information is stored in the file PROGRESS_BEGIN_MESSAGE("Parsing " + (*i).name); // reset the line reader and let it point to the begin of the according data field myLineReader.reinit(); myLineReader.setPos((*i).position); // prepare the line parser myLineParser.reinit((*i).pattern); // read bool singleDataEndFound = false; while (myLineReader.hasMore() && !singleDataEndFound) { std::string line = myLineReader.readLine(); if (line.length() == 0 || line[0] == '*' || line[0] == '$') { singleDataEndFound = true; } else { myLineParser.parseLine(line); try { myCurrentID = "<unknown>"; (this->*(*i).function)(); } catch (OutOfBoundsException&) { WRITE_ERROR("Too short value line in " + (*i).name + " occured."); } catch (NumberFormatException&) { WRITE_ERROR("A value in " + (*i).name + " should be numeric but is not (id='" + myCurrentID + "')."); } catch (UnknownElement& e) { WRITE_ERROR("One of the needed values ('" + std::string(e.what()) + "') is missing in " + (*i).name + "."); } } } // close single reader processing PROGRESS_DONE_MESSAGE(); } // build traffic lights for (NIVisumTL_Map::iterator j = myTLS.begin(); j != myTLS.end(); j++) { j->second->build(myNetBuilder.getTLLogicCont()); } // build district shapes for (std::map<NBDistrict*, PositionVector>::const_iterator k = myDistrictShapes.begin(); k != myDistrictShapes.end(); ++k) { (*k).first->addShape((*k).second); } }
void NIImporter_SUMO::_loadNetwork(OptionsCont& oc) { // check whether the option is set (properly) if (!oc.isUsableFileList("sumo-net-file")) { return; } // parse file(s) std::vector<std::string> files = oc.getStringVector("sumo-net-file"); for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { if (!FileHelpers::isReadable(*file)) { WRITE_ERROR("Could not open sumo-net-file '" + *file + "'."); return; } setFileName(*file); PROGRESS_BEGIN_MESSAGE("Parsing sumo-net from '" + *file + "'"); XMLSubSys::runParser(*this, *file, true); PROGRESS_DONE_MESSAGE(); } // build edges for (std::map<std::string, EdgeAttrs*>::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) { EdgeAttrs* ed = (*i).second; // skip internal edges if (ed->func == EDGEFUNC_INTERNAL || ed->func == EDGEFUNC_CROSSING || ed->func == EDGEFUNC_WALKINGAREA) { continue; } // get and check the nodes NBNode* from = myNodeCont.retrieve(ed->fromNode); NBNode* to = myNodeCont.retrieve(ed->toNode); if (from == 0) { WRITE_ERROR("Edge's '" + ed->id + "' from-node '" + ed->fromNode + "' is not known."); continue; } if (to == 0) { WRITE_ERROR("Edge's '" + ed->id + "' to-node '" + ed->toNode + "' is not known."); continue; } // edge shape PositionVector geom; if (ed->shape.size() > 0) { geom = ed->shape; } else { // either the edge has default shape consisting only of the two node // positions or we have a legacy network geom = reconstructEdgeShape(ed, from->getPosition(), to->getPosition()); } // build and insert the edge NBEdge* e = new NBEdge(ed->id, from, to, ed->type, ed->maxSpeed, (unsigned int) ed->lanes.size(), ed->priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, geom, ed->streetName, "", ed->lsf, true); // always use tryIgnoreNodePositions to keep original shape e->setLoadedLength(ed->length); if (!myNetBuilder.getEdgeCont().insert(e)) { WRITE_ERROR("Could not insert edge '" + ed->id + "'."); delete e; continue; } ed->builtEdge = myNetBuilder.getEdgeCont().retrieve(ed->id); } // assign further lane attributes (edges are built) for (std::map<std::string, EdgeAttrs*>::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) { EdgeAttrs* ed = (*i).second; NBEdge* nbe = ed->builtEdge; if (nbe == 0) { // inner edge or removed by explicit list, vclass, ... continue; } for (unsigned int fromLaneIndex = 0; fromLaneIndex < (unsigned int) ed->lanes.size(); ++fromLaneIndex) { LaneAttrs* lane = ed->lanes[fromLaneIndex]; // connections const std::vector<Connection>& connections = lane->connections; for (std::vector<Connection>::const_iterator c_it = connections.begin(); c_it != connections.end(); c_it++) { const Connection& c = *c_it; if (myEdges.count(c.toEdgeID) == 0) { WRITE_ERROR("Unknown edge '" + c.toEdgeID + "' given in connection."); continue; } NBEdge* toEdge = myEdges[c.toEdgeID]->builtEdge; if (toEdge == 0) { // removed by explicit list, vclass, ... continue; } if (nbe->hasConnectionTo(toEdge, c.toLaneIdx)) { WRITE_WARNING("Target lane '" + toEdge->getLaneID(c.toLaneIdx) + "' has multiple connections from '" + nbe->getID() + "'."); } nbe->addLane2LaneConnection( fromLaneIndex, toEdge, c.toLaneIdx, NBEdge::L2L_VALIDATED, true, c.mayDefinitelyPass, c.keepClear, c.contPos); // maybe we have a tls-controlled connection if (c.tlID != "" && myRailSignals.count(c.tlID) == 0) { const std::map<std::string, NBTrafficLightDefinition*>& programs = myTLLCont.getPrograms(c.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(nbe, toEdge, fromLaneIndex, c.toLaneIdx, c.tlLinkNo); } else { throw ProcessError("Corrupt traffic light definition '" + c.tlID + "' (program '" + it->first + "')"); } } } else { WRITE_ERROR("The traffic light '" + c.tlID + "' is not known."); } } } // allow/disallow XXX preferred nbe->setPermissions(parseVehicleClasses(lane->allow, lane->disallow), fromLaneIndex); // width, offset nbe->setLaneWidth(fromLaneIndex, lane->width); nbe->setEndOffset(fromLaneIndex, lane->endOffset); nbe->setSpeed(fromLaneIndex, lane->maxSpeed); } nbe->declareConnectionsAsLoaded(); if (!nbe->hasLaneSpecificWidth() && nbe->getLanes()[0].width != NBEdge::UNSPECIFIED_WIDTH) { nbe->setLaneWidth(-1, nbe->getLaneWidth(0)); } if (!nbe->hasLaneSpecificEndOffset() && nbe->getEndOffset(0) != NBEdge::UNSPECIFIED_OFFSET) { nbe->setEndOffset(-1, nbe->getEndOffset(0)); } } // insert loaded prohibitions for (std::vector<Prohibition>::const_iterator it = myProhibitions.begin(); it != myProhibitions.end(); it++) { NBEdge* prohibitedFrom = myEdges[it->prohibitedFrom]->builtEdge; NBEdge* prohibitedTo = myEdges[it->prohibitedTo]->builtEdge; NBEdge* prohibitorFrom = myEdges[it->prohibitorFrom]->builtEdge; NBEdge* prohibitorTo = myEdges[it->prohibitorTo]->builtEdge; if (prohibitedFrom == 0) { WRITE_WARNING("Edge '" + it->prohibitedFrom + "' in prohibition was not built"); } else if (prohibitedTo == 0) { WRITE_WARNING("Edge '" + it->prohibitedTo + "' in prohibition was not built"); } else if (prohibitorFrom == 0) { WRITE_WARNING("Edge '" + it->prohibitorFrom + "' in prohibition was not built"); } else if (prohibitorTo == 0) { WRITE_WARNING("Edge '" + it->prohibitorTo + "' in prohibition was not built"); } else { NBNode* n = prohibitedFrom->getToNode(); n->addSortedLinkFoes( NBConnection(prohibitorFrom, prohibitorTo), NBConnection(prohibitedFrom, prohibitedTo)); } } if (!myHaveSeenInternalEdge) { myNetBuilder.haveLoadedNetworkWithoutInternalEdges(); } if (oc.isDefault("lefthand")) { oc.set("lefthand", toString(myAmLefthand)); } if (oc.isDefault("junctions.corner-detail")) { oc.set("junctions.corner-detail", toString(myCornerDetail)); } if (oc.isDefault("junctions.internal-link-detail") && myLinkDetail > 0) { oc.set("junctions.internal-link-detail", toString(myLinkDetail)); } if (!deprecatedVehicleClassesSeen.empty()) { WRITE_WARNING("Deprecated vehicle class(es) '" + toString(deprecatedVehicleClassesSeen) + "' in input network."); deprecatedVehicleClassesSeen.clear(); } // add loaded crossings if (!oc.getBool("no-internal-links")) { for (std::map<std::string, std::vector<Crossing> >::const_iterator it = myPedestrianCrossings.begin(); it != myPedestrianCrossings.end(); ++it) { NBNode* node = myNodeCont.retrieve((*it).first); for (std::vector<Crossing>::const_iterator it_c = (*it).second.begin(); it_c != (*it).second.end(); ++it_c) { const Crossing& crossing = (*it_c); EdgeVector edges; for (std::vector<std::string>::const_iterator it_e = crossing.crossingEdges.begin(); it_e != crossing.crossingEdges.end(); ++it_e) { NBEdge* edge = myNetBuilder.getEdgeCont().retrieve(*it_e); // edge might have been removed due to options if (edge != 0) { edges.push_back(edge); } } if (edges.size() > 0) { node->addCrossing(edges, crossing.width, crossing.priority, true); } } } } // add roundabouts for (std::vector<std::vector<std::string> >::const_iterator it = myRoundabouts.begin(); it != myRoundabouts.end(); ++it) { EdgeSet roundabout; for (std::vector<std::string>::const_iterator it_r = it->begin(); it_r != it->end(); ++it_r) { NBEdge* edge = myNetBuilder.getEdgeCont().retrieve(*it_r); if (edge == 0) { if (!myNetBuilder.getEdgeCont().wasIgnored(*it_r)) { WRITE_ERROR("Unknown edge '" + (*it_r) + "' in roundabout"); } } else { roundabout.insert(edge); } } myNetBuilder.getEdgeCont().addRoundabout(roundabout); } }
void NIImporter_SUMO::_loadNetwork(const OptionsCont& oc) { // check whether the option is set (properly) if (!oc.isUsableFileList("sumo-net-file")) { return; } // parse file(s) std::vector<std::string> files = oc.getStringVector("sumo-net-file"); for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { if (!FileHelpers::exists(*file)) { WRITE_ERROR("Could not open sumo-net-file '" + *file + "'."); return; } setFileName(*file); PROGRESS_BEGIN_MESSAGE("Parsing sumo-net from '" + *file + "'"); XMLSubSys::runParser(*this, *file); PROGRESS_DONE_MESSAGE(); } // build edges for (std::map<std::string, EdgeAttrs*>::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) { EdgeAttrs* ed = (*i).second; // skip internal edges if (ed->func == toString(EDGEFUNC_INTERNAL)) { continue; } // get and check the nodes NBNode* from = myNodeCont.retrieve(ed->fromNode); NBNode* to = myNodeCont.retrieve(ed->toNode); if (from == 0) { WRITE_ERROR("Edge's '" + ed->id + "' from-node '" + ed->fromNode + "' is not known."); continue; } if (to == 0) { WRITE_ERROR("Edge's '" + ed->id + "' to-node '" + ed->toNode + "' is not known."); continue; } // edge shape PositionVector geom; if (ed->shape.size() > 0) { geom = ed->shape; mySuspectKeepShape = false; // no problem with reconstruction if edge shape is given explicit } else { // either the edge has default shape consisting only of the two node // positions or we have a legacy network geom = reconstructEdgeShape(ed, from->getPosition(), to->getPosition()); } // build and insert the edge NBEdge* e = new NBEdge(ed->id, from, to, ed->type, ed->maxSpeed, (unsigned int) ed->lanes.size(), ed->priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, geom, ed->streetName, ed->lsf, true); // always use tryIgnoreNodePositions to keep original shape e->setLoadedLength(ed->length); if (!myNetBuilder.getEdgeCont().insert(e)) { WRITE_ERROR("Could not insert edge '" + ed->id + "'."); delete e; continue; } ed->builtEdge = myNetBuilder.getEdgeCont().retrieve(ed->id); } // assign further lane attributes (edges are built) for (std::map<std::string, EdgeAttrs*>::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) { EdgeAttrs* ed = (*i).second; NBEdge* nbe = ed->builtEdge; if (nbe == 0) { // inner edge or removed by explicit list, vclass, ... continue; } for (unsigned int fromLaneIndex = 0; fromLaneIndex < (unsigned int) ed->lanes.size(); ++fromLaneIndex) { LaneAttrs* lane = ed->lanes[fromLaneIndex]; // connections const std::vector<Connection> &connections = lane->connections; for (std::vector<Connection>::const_iterator c_it = connections.begin(); c_it != connections.end(); c_it++) { const Connection& c = *c_it; if (myEdges.count(c.toEdgeID) == 0) { WRITE_ERROR("Unknown edge '" + c.toEdgeID + "' given in connection."); continue; } NBEdge* toEdge = myEdges[c.toEdgeID]->builtEdge; if (toEdge == 0) { // removed by explicit list, vclass, ... continue; } nbe->addLane2LaneConnection( fromLaneIndex, toEdge, c.toLaneIdx, NBEdge::L2L_VALIDATED, false, c.mayDefinitelyPass); // maybe we have a tls-controlled connection if (c.tlID != "") { const std::map<std::string, NBTrafficLightDefinition*>& programs = myTLLCont.getPrograms(c.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(nbe, toEdge, fromLaneIndex, c.toLaneIdx, c.tlLinkNo); } else { throw ProcessError("Corrupt traffic light definition '" + c.tlID + "' (program '" + it->first + "')"); } } } else { WRITE_ERROR("The traffic light '" + c.tlID + "' is not known."); } } } // allow/disallow SUMOVehicleClasses allowed; SUMOVehicleClasses disallowed; parseVehicleClasses(lane->allow, lane->disallow, allowed, disallowed); nbe->setVehicleClasses(allowed, disallowed, fromLaneIndex); // width, offset nbe->setWidth(fromLaneIndex, lane->width); nbe->setOffset(fromLaneIndex, lane->offset); nbe->setSpeed(fromLaneIndex, lane->maxSpeed); } nbe->declareConnectionsAsLoaded(); } // insert loaded prohibitions for (std::vector<Prohibition>::const_iterator it = myProhibitions.begin(); it != myProhibitions.end(); it++) { NBEdge* prohibitedFrom = myEdges[it->prohibitedFrom]->builtEdge; if (prohibitedFrom == 0) { WRITE_ERROR("Edge '" + it->prohibitedFrom + "' in prohibition was not built"); } else { NBNode* n = prohibitedFrom->getToNode(); n->addSortedLinkFoes( NBConnection(myEdges[it->prohibitorFrom]->builtEdge, myEdges[it->prohibitorTo]->builtEdge), NBConnection(prohibitedFrom, myEdges[it->prohibitedTo]->builtEdge)); } } // final warning if (mySuspectKeepShape) { WRITE_WARNING("The input network may have been built using option 'xml.keep-shape'.\n... Accuracy of junction positions cannot be guaranteed."); } }
void NIImporter_ArcView::load() { #ifdef HAVE_GDAL PROGRESS_BEGIN_MESSAGE("Loading data from '" + mySHPName + "'"); #if GDAL_VERSION_MAJOR < 2 OGRRegisterAll(); OGRDataSource* poDS = OGRSFDriverRegistrar::Open(mySHPName.c_str(), FALSE); #else GDALAllRegister(); GDALDataset* poDS = (GDALDataset*)GDALOpenEx(mySHPName.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL); #endif if (poDS == NULL) { WRITE_ERROR("Could not open shape description '" + mySHPName + "'."); return; } // begin file parsing OGRLayer* poLayer = poDS->GetLayer(0); poLayer->ResetReading(); // build coordinate transformation OGRSpatialReference* origTransf = poLayer->GetSpatialRef(); OGRSpatialReference destTransf; // use wgs84 as destination destTransf.SetWellKnownGeogCS("WGS84"); OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf); if (poCT == NULL) { if (myOptions.isSet("shapefile.guess-projection")) { OGRSpatialReference origTransf2; origTransf2.SetWellKnownGeogCS("WGS84"); poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf); } if (poCT == 0) { WRITE_WARNING("Could not create geocoordinates converter; check whether proj.4 is installed."); } } OGRFeature* poFeature; poLayer->ResetReading(); while ((poFeature = poLayer->GetNextFeature()) != NULL) { // read in edge attributes std::string id, name, from_node, to_node; if (!getStringEntry(poFeature, "shapefile.street-id", "LINK_ID", true, id)) { WRITE_ERROR("Needed field '" + id + "' (from node id) is missing."); } if (id == "") { WRITE_ERROR("Could not obtain edge id."); return; } getStringEntry(poFeature, "shapefile.street-id", "ST_NAME", true, name); name = StringUtils::replace(name, "&", "&"); if (!getStringEntry(poFeature, "shapefile.from-id", "REF_IN_ID", true, from_node)) { WRITE_ERROR("Needed field '" + from_node + "' (from node id) is missing."); } if (!getStringEntry(poFeature, "shapefile.to-id", "NREF_IN_ID", true, to_node)) { WRITE_ERROR("Needed field '" + to_node + "' (to node id) is missing."); } if (from_node == "" || to_node == "") { from_node = toString(myRunningNodeID++); to_node = toString(myRunningNodeID++); } std::string type; if (myOptions.isSet("shapefile.type-id") && poFeature->GetFieldIndex(myOptions.getString("shapefile.type-id").c_str()) >= 0) { type = poFeature->GetFieldAsString(myOptions.getString("shapefile.type-id").c_str()); } else if (poFeature->GetFieldIndex("ST_TYP_AFT") >= 0) { type = poFeature->GetFieldAsString("ST_TYP_AFT"); } SUMOReal width = myTypeCont.getWidth(type); SUMOReal speed = getSpeed(*poFeature, id); int nolanes = getLaneNo(*poFeature, id, speed); int priority = getPriority(*poFeature, id); if (nolanes == 0 || speed == 0) { if (myOptions.getBool("shapefile.use-defaults-on-failure")) { nolanes = myTypeCont.getNumLanes(""); speed = myTypeCont.getSpeed(""); } else { OGRFeature::DestroyFeature(poFeature); WRITE_ERROR("The description seems to be invalid. Please recheck usage of types."); return; } } if (mySpeedInKMH) { speed = speed / (SUMOReal) 3.6; } // read in the geometry OGRGeometry* poGeometry = poFeature->GetGeometryRef(); OGRwkbGeometryType gtype = poGeometry->getGeometryType(); assert(gtype == wkbLineString); UNUSED_PARAMETER(gtype); // ony used for assertion OGRLineString* cgeom = (OGRLineString*) poGeometry; if (poCT != 0) { // try transform to wgs84 cgeom->transform(poCT); } PositionVector shape; for (int j = 0; j < cgeom->getNumPoints(); j++) { Position pos((SUMOReal) cgeom->getX(j), (SUMOReal) cgeom->getY(j)); if (!NBNetBuilder::transformCoordinate(pos)) { WRITE_WARNING("Unable to project coordinates for edge '" + id + "'."); } shape.push_back_noDoublePos(pos); } // build from-node NBNode* from = myNodeCont.retrieve(from_node); if (from == 0) { Position from_pos = shape[0]; from = myNodeCont.retrieve(from_pos); if (from == 0) { from = new NBNode(from_node, from_pos); if (!myNodeCont.insert(from)) { WRITE_ERROR("Node '" + from_node + "' could not be added"); delete from; continue; } } } // build to-node NBNode* to = myNodeCont.retrieve(to_node); if (to == 0) { Position to_pos = shape[-1]; to = myNodeCont.retrieve(to_pos); if (to == 0) { to = new NBNode(to_node, to_pos); if (!myNodeCont.insert(to)) { WRITE_ERROR("Node '" + to_node + "' could not be added"); delete to; continue; } } } if (from == to) { WRITE_WARNING("Edge '" + id + "' connects identical nodes, skipping."); continue; } // retrieve the information whether the street is bi-directional std::string dir; int index = poFeature->GetDefnRef()->GetFieldIndex("DIR_TRAVEL"); if (index >= 0 && poFeature->IsFieldSet(index)) { dir = poFeature->GetFieldAsString(index); } // add positive direction if wanted if (dir == "B" || dir == "F" || dir == "" || myOptions.getBool("shapefile.all-bidirectional")) { if (myEdgeCont.retrieve(id) == 0) { LaneSpreadFunction spread = dir == "B" || dir == "FALSE" ? LANESPREAD_RIGHT : LANESPREAD_CENTER; NBEdge* edge = new NBEdge(id, from, to, type, speed, nolanes, priority, width, NBEdge::UNSPECIFIED_OFFSET, shape, name, id, spread); myEdgeCont.insert(edge); checkSpread(edge); } } // add negative direction if wanted if (dir == "B" || dir == "T" || myOptions.getBool("shapefile.all-bidirectional")) { if (myEdgeCont.retrieve("-" + id) == 0) { LaneSpreadFunction spread = dir == "B" || dir == "FALSE" ? LANESPREAD_RIGHT : LANESPREAD_CENTER; NBEdge* edge = new NBEdge("-" + id, to, from, type, speed, nolanes, priority, width, NBEdge::UNSPECIFIED_OFFSET, shape.reverse(), name, id, spread); myEdgeCont.insert(edge); checkSpread(edge); } } // OGRFeature::DestroyFeature(poFeature); } #if GDAL_VERSION_MAJOR < 2 OGRDataSource::DestroyDataSource(poDS); #else GDALClose(poDS); #endif PROGRESS_DONE_MESSAGE(); #else WRITE_ERROR("SUMO was compiled without GDAL support."); #endif }
// =========================================================================== // method definitions // =========================================================================== // --------------------------------------------------------------------------- // static methods // --------------------------------------------------------------------------- void NIImporter_DlrNavteq::loadNetwork(const OptionsCont& oc, NBNetBuilder& nb) { // check whether the option is set (properly) if (!oc.isSet("dlr-navteq-prefix")) { return; } time_t csTime; time(&csTime); // parse file(s) LineReader lr; // load nodes std::map<std::string, PositionVector> myGeoms; PROGRESS_BEGIN_MESSAGE("Loading nodes"); std::string file = oc.getString("dlr-navteq-prefix") + "_nodes_unsplitted.txt"; NodesHandler handler1(nb.getNodeCont(), file, myGeoms); if (!lr.setFile(file)) { throw ProcessError("The file '" + file + "' could not be opened."); } lr.readAll(handler1); PROGRESS_DONE_MESSAGE(); // load street names if given and wished std::map<std::string, std::string> streetNames; // nameID : name if (oc.getBool("output.street-names")) { file = oc.getString("dlr-navteq-prefix") + "_names.txt"; if (lr.setFile(file)) { PROGRESS_BEGIN_MESSAGE("Loading Street Names"); NamesHandler handler4(file, streetNames); lr.readAll(handler4); PROGRESS_DONE_MESSAGE(); } else { WRITE_WARNING("Output will not contain street names because the file '" + file + "' was not found"); } } // load edges PROGRESS_BEGIN_MESSAGE("Loading edges"); file = oc.getString("dlr-navteq-prefix") + "_links_unsplitted.txt"; // parse the file EdgesHandler handler2(nb.getNodeCont(), nb.getEdgeCont(), nb.getTypeCont(), file, myGeoms, streetNames); if (!lr.setFile(file)) { throw ProcessError("The file '" + file + "' could not be opened."); } lr.readAll(handler2); nb.getEdgeCont().recheckLaneSpread(); PROGRESS_DONE_MESSAGE(); // load traffic lights if given file = oc.getString("dlr-navteq-prefix") + "_traffic_signals.txt"; if (lr.setFile(file)) { PROGRESS_BEGIN_MESSAGE("Loading traffic lights"); TrafficlightsHandler handler3(nb.getNodeCont(), nb.getTLLogicCont(), nb.getEdgeCont(), file); lr.readAll(handler3); PROGRESS_DONE_MESSAGE(); } // load prohibited manoeuvres if given file = oc.getString("dlr-navteq-prefix") + "_prohibited_manoeuvres.txt"; if (lr.setFile(file)) { PROGRESS_BEGIN_MESSAGE("Loading prohibited manoeuvres"); ProhibitionHandler handler6(nb.getEdgeCont(), file, csTime); lr.readAll(handler6); PROGRESS_DONE_MESSAGE(); } // load connected lanes if given file = oc.getString("dlr-navteq-prefix") + "_connected_lanes.txt"; if (lr.setFile(file)) { PROGRESS_BEGIN_MESSAGE("Loading connected lanes"); ConnectedLanesHandler handler7(nb.getEdgeCont()); lr.readAll(handler7); PROGRESS_DONE_MESSAGE(); } // load time restrictions if given file = oc.getString("dlr-navteq-prefix") + "_links_timerestrictions.txt"; if (lr.setFile(file)) { PROGRESS_BEGIN_MESSAGE("Loading time restrictions"); if (!oc.isDefault("construction-date")) { csTime = readDate(oc.getString("construction-date")); } TimeRestrictionsHandler handler5(nb.getEdgeCont(), nb.getDistrictCont(), csTime); lr.readAll(handler5); handler5.printSummary(); PROGRESS_DONE_MESSAGE(); } }
bool NLBuilder::build() { // try to build the net if (!load("net-file", true)) { return false; } // check whether the loaded net agrees with the simulation options if (myOptions.getBool("no-internal-links") && myXMLHandler.haveSeenInternalEdge()) { WRITE_WARNING("Network contains internal links but option --no-internal-links is set. Vehicles will 'jump' across junctions and thus underestimate route lengths and travel times."); } if (myOptions.getString("lanechange.duration") != "0" && myXMLHandler.haveSeenNeighs()) { throw ProcessError("Network contains explicit neigh lanes which do not work together with option --lanechange.duration."); } buildNet(); // @note on loading order constraints: // - additional-files before route-files and state-files due to referencing // - additional-files before weight-files since the latter might contain intermodal edge data and the intermodal net depends on the stops and public transport from the additionals // load additional net elements (sources, detectors, ...) if (myOptions.isSet("additional-files")) { if (!load("additional-files")) { return false; } // load shapes with separate handler NLShapeHandler sh("", myNet.getShapeContainer()); if (!ShapeHandler::loadFiles(myOptions.getStringVector("additional-files"), sh)) { return false; } if (myXMLHandler.haveSeenAdditionalSpeedRestrictions()) { myNet.getEdgeControl().setAdditionalRestrictions(); } } // load weights if wished if (myOptions.isSet("weight-files")) { if (!myOptions.isUsableFileList("weight-files")) { return false; } // build and prepare the weights handler std::vector<SAXWeightsHandler::ToRetrieveDefinition*> retrieverDefs; // travel time, first (always used) EdgeFloatTimeLineRetriever_EdgeTravelTime ttRetriever(myNet); retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition("traveltime", true, ttRetriever)); // the measure to use, then EdgeFloatTimeLineRetriever_EdgeEffort eRetriever(myNet); std::string measure = myOptions.getString("weight-attribute"); if (!myOptions.isDefault("weight-attribute")) { if (measure == "CO" || measure == "CO2" || measure == "HC" || measure == "PMx" || measure == "NOx" || measure == "fuel" || measure == "electricity") { measure += "_perVeh"; } retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition(measure, true, eRetriever)); } // set up handler SAXWeightsHandler handler(retrieverDefs, ""); // start parsing; for each file in the list std::vector<std::string> files = myOptions.getStringVector("weight-files"); for (std::vector<std::string>::iterator i = files.begin(); i != files.end(); ++i) { // report about loading when wished WRITE_MESSAGE("Loading weights from '" + *i + "'..."); // parse the file if (!XMLSubSys::runParser(handler, *i)) { return false; } } } // load the previous state if wished if (myOptions.isSet("load-state")) { long before = SysUtils::getCurrentMillis(); const std::string& f = myOptions.getString("load-state"); PROGRESS_BEGIN_MESSAGE("Loading state from '" + f + "'"); MSStateHandler h(f, string2time(myOptions.getString("load-state.offset"))); XMLSubSys::runParser(h, f); if (myOptions.isDefault("begin")) { myOptions.set("begin", time2string(h.getTime())); if (TraCIServer::getInstance() != 0) { TraCIServer::getInstance()->setTargetTime(h.getTime()); } } if (MsgHandler::getErrorInstance()->wasInformed()) { return false; } if (h.getTime() != string2time(myOptions.getString("begin"))) { WRITE_WARNING("State was written at a different time " + time2string(h.getTime()) + " than the begin time " + myOptions.getString("begin") + "!"); } PROGRESS_TIME_MESSAGE(before); } // load routes if (myOptions.isSet("route-files") && string2time(myOptions.getString("route-steps")) <= 0) { if (!load("route-files")) { return false; } } // optionally switch off traffic lights if (myOptions.getBool("tls.all-off")) { myNet.getTLSControl().switchOffAll(); } WRITE_MESSAGE("Loading done."); return true; }