dfrouter_main.cpp File Reference


Detailed Description

Author:
Daniel Krajzewicz
Date:
Thu, 16.03.2006
Version:
Id
dfrouter_main.cpp 8648 2010-04-27 09:34:37Z dkrajzew

Definition in file dfrouter_main.cpp.

#include <config.h>
#include <xercesc/sax/SAXException.hpp>
#include <xercesc/sax/SAXParseException.hpp>
#include <utils/common/TplConvert.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <ctime>
#include <router/ROLoader.h>
#include <router/RONet.h>
#include "RODFEdgeBuilder.h"
#include <router/ROFrame.h>
#include <utils/common/MsgHandler.h>
#include <utils/options/Option.h>
#include <utils/options/OptionsCont.h>
#include <utils/options/OptionsIO.h>
#include <utils/common/UtilExceptions.h>
#include <utils/common/SystemFrame.h>
#include <utils/common/ToString.h>
#include <utils/xml/XMLSubSys.h>
#include "RODFFrame.h"
#include "RODFNet.h"
#include "RODFEdge.h"
#include "RODFDetector.h"
#include "RODFDetectorHandler.h"
#include "RODFRouteCont.h"
#include "RODFDetectorFlow.h"
#include "RODFDetFlowLoader.h"
#include <utils/common/FileHelpers.h>
#include <utils/iodevices/OutputDevice.h>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
void readDetectorFlows (RODFDetectorFlows &flows, OptionsCont &oc, RODFDetectorCon &dc)
void readDetectors (RODFDetectorCon &detectors, OptionsCont &oc, RODFNet *optNet)
void startComputation (RODFNet *optNet, RODFDetectorFlows &flows, RODFDetectorCon &detectors, OptionsCont &oc)


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 243 of file dfrouter_main.cpp.

References RODFNet::buildApproachList(), RODFFrame::checkOptions(), SystemFrame::close(), OutputDevice::closeAll(), RODFFrame::fillOptions(), OptionsCont::getBool(), MsgHandler::getErrorInstance(), OptionsIO::getOptions(), OptionsCont::getOptions(), OptionsCont::getString(), MsgHandler::inform(), XMLSubSys::init(), MsgHandler::initOutputOptions(), RandHelper::initRandGlobal(), ROLoader::loadNet(), OptionsCont::processMetaOptions(), readDetectorFlows(), readDetectors(), OptionsCont::setApplicationDescription(), OptionsCont::setApplicationName(), startComputation(), and string2time().

00243                             {
00244     OptionsCont &oc = OptionsCont::getOptions();
00245     // give some application descriptions
00246     oc.setApplicationDescription("Builds vehicle routes for SUMO using detector values.");
00247     oc.setApplicationName("dfrouter", "SUMO dfrouter Version " + (std::string)VERSION_STRING);
00248     int ret = 0;
00249     RODFNet *net = 0;
00250     RODFDetectorCon *detectors = 0;
00251     RODFDetectorFlows *flows = 0;
00252     try {
00253         // initialise the application system (messaging, xml, options)
00254         XMLSubSys::init(false);
00255         RODFFrame::fillOptions();
00256         OptionsIO::getOptions(true, argc, argv);
00257         if (oc.processMetaOptions(argc < 2)) {
00258             SystemFrame::close();
00259             return 0;
00260         }
00261         MsgHandler::initOutputOptions();
00262         if (!RODFFrame::checkOptions()) throw ProcessError();
00263         RandHelper::initRandGlobal();
00264         // load data
00265         ROLoader loader(oc, false);
00266         net = new RODFNet(oc.getBool("highway-mode"));
00267         RODFEdgeBuilder builder;
00268         loader.loadNet(*net, builder);
00269         net->buildApproachList();
00270         // load detectors
00271         detectors = new RODFDetectorCon();
00272         readDetectors(*detectors, oc, net);
00273         // load detector values
00274         flows = new RODFDetectorFlows(string2time(oc.getString("begin"))/1000., string2time(oc.getString("end"))/1000., 60); // !!!
00275         readDetectorFlows(*flows, oc, *detectors);
00276         // build routes
00277         startComputation(net, *flows, *detectors, oc);
00278     } catch (ProcessError &e) {
00279         if (std::string(e.what())!=std::string("Process Error") && std::string(e.what())!=std::string("")) {
00280             MsgHandler::getErrorInstance()->inform(e.what());
00281         }
00282         MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
00283         ret = 1;
00284 #ifndef _DEBUG
00285     } catch (...) {
00286         MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
00287         ret = 1;
00288 #endif
00289     }
00290     delete net;
00291     delete flows;
00292     delete detectors;
00293     OutputDevice::closeAll();
00294     SystemFrame::close();
00295     if (ret==0) {
00296         std::cout << "Success." << std::endl;
00297     }
00298     return ret;
00299 }

void readDetectorFlows ( RODFDetectorFlows flows,
OptionsCont oc,
RODFDetectorCon dc 
)

Definition at line 100 of file dfrouter_main.cpp.

References MsgHandler::beginProcessMsg(), MsgHandler::endProcessMsg(), FileHelpers::exists(), MsgHandler::getMessageInstance(), OptionsCont::getString(), OptionsCont::getStringVector(), OptionsCont::isSet(), RODFDetFlowLoader::read(), and string2time().

Referenced by main().

00100                                                                                   {
00101     if (!oc.isSet("detector-flow-files")) {
00102         // ok, not given, return an empty container
00103         return;
00104     }
00105     // check whether the file exists
00106     std::vector<std::string> files = oc.getStringVector("detector-flow-files");
00107     for (std::vector<std::string>::const_iterator fileIt=files.begin(); fileIt!=files.end(); ++fileIt) {
00108         if (!FileHelpers::exists(*fileIt)) {
00109             throw ProcessError("The detector-flow-file '" + *fileIt + "' can not be opened.");
00110         }
00111         // parse
00112         MsgHandler::getMessageInstance()->beginProcessMsg("Loading flows from '" + *fileIt + "'...");
00113         RODFDetFlowLoader dfl(dc, flows, string2time(oc.getString("begin"))/1000., string2time(oc.getString("end"))/1000., string2time(oc.getString("time-offset"))/1000.);
00114         dfl.read(*fileIt);
00115         MsgHandler::getMessageInstance()->endProcessMsg("done.");
00116     }
00117 }

void readDetectors ( RODFDetectorCon detectors,
OptionsCont oc,
RODFNet optNet 
)

Definition at line 77 of file dfrouter_main.cpp.

References MsgHandler::beginProcessMsg(), MsgHandler::endProcessMsg(), FileHelpers::exists(), OptionsCont::getBool(), MsgHandler::getMessageInstance(), OptionsCont::getStringVector(), OptionsCont::isSet(), and XMLSubSys::runParser().

Referenced by main().

00077                                                                             {
00078     if (!oc.isSet("detector-files")) {
00079         throw ProcessError("No detector file given (use --detector-files <FILE>).");
00080     }
00081     // read definitions stored in XML-format
00082     std::vector<std::string> files = oc.getStringVector("detector-files");
00083     for (std::vector<std::string>::const_iterator fileIt=files.begin(); fileIt!=files.end(); ++fileIt) {
00084         if (!FileHelpers::exists(*fileIt)) {
00085             throw ProcessError("Could not open detector file '" + *fileIt + "'");
00086         }
00087         MsgHandler::getMessageInstance()->beginProcessMsg("Loading detector definitions from '" + *fileIt + "'... ");
00088         RODFDetectorHandler handler(optNet, oc.getBool("ignore-invalid-detectors"), detectors, *fileIt);
00089         if (XMLSubSys::runParser(handler, *fileIt)) {
00090             MsgHandler::getMessageInstance()->endProcessMsg("done.");
00091         } else {
00092             MsgHandler::getMessageInstance()->endProcessMsg("failed.");
00093             throw ProcessError();
00094         }
00095     }
00096 }

void startComputation ( RODFNet optNet,
RODFDetectorFlows flows,
RODFDetectorCon detectors,
OptionsCont oc 
)

Definition at line 121 of file dfrouter_main.cpp.

References MsgHandler::beginProcessMsg(), RODFNet::buildDetectorDependencies(), RODFNet::buildEdgeFlowMap(), RODFNet::buildRoutes(), RODFNet::computeTypes(), RODFDetectorCon::detectorsHaveCompleteTypes(), RODFDetectorCon::detectorsHaveRoutes(), MsgHandler::endProcessMsg(), OptionsCont::getBool(), OptionsCont::getFloat(), OptionsCont::getInt(), MsgHandler::getMessageInstance(), OptionsCont::getString(), RODFDetectorCon::guessEmptyFlows(), OptionsCont::isSet(), RODFDetectorFlows::printAbsolute(), RODFNet::removeEmptyDetectors(), RODFNet::reportEmptyDetectors(), RODFNet::revalidateFlows(), RODFDetectorCon::save(), RODFDetectorCon::saveAsPOIs(), RODFDetectorCon::saveRoutes(), string2time(), RODFDetectorCon::writeEmitterPOIs(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeEndRerouterDetectors(), RODFDetectorCon::writeSpeedTrigger(), and RODFDetectorCon::writeValidationDetectors().

Referenced by main().

00121                                                                                                          {
00122     if (oc.getBool("print-absolute-flows")) {
00123         flows.printAbsolute();
00124     }
00125 
00126     // if a network was loaded... (mode1)
00127     if (optNet!=0) {
00128         if (oc.getBool("remove-empty-detectors")) {
00129             MsgHandler::getMessageInstance()->beginProcessMsg("Removing empty detectors...");
00130             optNet->removeEmptyDetectors(detectors, flows, string2time(oc.getString("begin"))/1000., string2time(oc.getString("end"))/1000., 60);
00131             MsgHandler::getMessageInstance()->endProcessMsg("done.");
00132         } else  if (oc.getBool("report-empty-detectors")) {
00133             MsgHandler::getMessageInstance()->beginProcessMsg("Scanning for empty detectors...");
00134             optNet->reportEmptyDetectors(detectors, flows);
00135             MsgHandler::getMessageInstance()->endProcessMsg("done.");
00136         }
00137         // compute the detector types (optionally)
00138         if (!detectors.detectorsHaveCompleteTypes()||oc.getBool("revalidate-detectors")) {
00139             optNet->computeTypes(detectors, oc.getBool("strict-sources"));
00140         }
00141         // compute routes between the detectors (optionally)
00142         if (!detectors.detectorsHaveRoutes()||oc.getBool("revalidate-routes")||oc.getBool("guess-empty-flows")) {
00143             MsgHandler::getMessageInstance()->beginProcessMsg("Computing routes...");
00144             optNet->buildRoutes(detectors,
00145                                 oc.getBool("all-end-follower"), oc.getBool("keep-unfound-ends"),
00146                                 oc.getBool("routes-for-all"), !oc.getBool("keep-longer-routes"),
00147                                 oc.getInt("max-nodet-follower"));
00148             MsgHandler::getMessageInstance()->endProcessMsg("done.");
00149         }
00150     }
00151 
00152     // check
00153     // whether the detectors are valid
00154     if (!detectors.detectorsHaveCompleteTypes()) {
00155         throw ProcessError("The detector types are not defined; use in combination with a network");
00156     }
00157     // whether the detectors have routes
00158     if (!detectors.detectorsHaveRoutes()) {
00159         throw ProcessError("The emitters have no routes; use in combination with a network");
00160     }
00161 
00162     // save the detectors if wished
00163     if (oc.isSet("detectors-output")) {
00164         detectors.save(oc.getString("detectors-output"));
00165     }
00166     // save their positions as POIs if wished
00167     if (oc.isSet("detectors-poi-output")) {
00168         detectors.saveAsPOIs(oc.getString("detectors-poi-output"));
00169     }
00170 
00171     // save the routes file if it was changed or it's wished
00172     if (detectors.detectorsHaveRoutes()&&oc.isSet("routes-output")) {
00173         detectors.saveRoutes(oc.getString("routes-output"));
00174     }
00175 
00176     // guess flows if wished
00177     if (oc.getBool("guess-empty-flows")) {
00178         optNet->buildDetectorDependencies(detectors);
00179         detectors.guessEmptyFlows(flows);
00180     }
00181 
00182     // save emitters if wished
00183     if (oc.isSet("emitters-output")||oc.isSet("emitters-poi-output")) {
00184         optNet->buildEdgeFlowMap(flows, detectors, string2time(oc.getString("begin"))/1000., string2time(oc.getString("end"))/1000., 60); // !!!
00185         if (oc.getBool("revalidate-flows")) {
00186             MsgHandler::getMessageInstance()->beginProcessMsg("Rechecking loaded flows...");
00187             optNet->revalidateFlows(detectors, flows, string2time(oc.getString("begin"))/1000., string2time(oc.getString("end"))/1000., 60);
00188             MsgHandler::getMessageInstance()->endProcessMsg("done.");
00189         }
00190         if (oc.isSet("emitters-output")) {
00191             MsgHandler::getMessageInstance()->beginProcessMsg("Writing emitters...");
00192             detectors.writeEmitters(oc.getString("emitters-output"), flows,
00193                                     string2time(oc.getString("begin"))/1000., string2time(oc.getString("end"))/1000., 60,
00194                                     *optNet,
00195                                     oc.getBool("write-calibrators"),
00196                                     oc.getBool("include-unused-routes"),
00197                                     oc.getFloat("scale"),
00198                                     oc.getInt("max-nodet-follower"),
00199                                     oc.getBool("emissions-only"));
00200             MsgHandler::getMessageInstance()->endProcessMsg("done.");
00201         }
00202         if (oc.isSet("emitters-poi-output")) {
00203             MsgHandler::getMessageInstance()->beginProcessMsg("Writing emitter pois...");
00204             detectors.writeEmitterPOIs(oc.getString("emitters-poi-output"), flows,
00205                                        string2time(oc.getString("begin"))/1000., string2time(oc.getString("end"))/1000., 60);
00206             MsgHandler::getMessageInstance()->endProcessMsg("done.");
00207         }
00208     }
00209     // save end speed trigger if wished
00210     if (oc.isSet("speed-trigger-output")) {
00211         MsgHandler::getMessageInstance()->beginProcessMsg("Writing speed triggers...");
00212         detectors.writeSpeedTrigger(optNet, oc.getString("speed-trigger-output"), flows,
00213                                     string2time(oc.getString("begin"))/1000., string2time(oc.getString("end"))/1000., 60);
00214         MsgHandler::getMessageInstance()->endProcessMsg("done.");
00215     }
00216     // save checking detectors if wished
00217     if (oc.isSet("validation-output")) {
00218         MsgHandler::getMessageInstance()->beginProcessMsg("Writing validation detectors...");
00219         detectors.writeValidationDetectors(oc.getString("validation-output"),
00220                                            oc.getBool("validation-output.add-sources"), true, true); // !!!
00221         MsgHandler::getMessageInstance()->endProcessMsg("done.");
00222     }
00223     // build global rerouter on end if wished
00224     if (oc.isSet("end-reroute-output")) {
00225         MsgHandler::getMessageInstance()->beginProcessMsg("Writing highway end rerouter...");
00226         detectors.writeEndRerouterDetectors(oc.getString("end-reroute-output")); // !!!
00227         MsgHandler::getMessageInstance()->endProcessMsg("done.");
00228     }
00229     /*
00230        // save the emission definitions
00231        if(oc.isSet("flow-definitions")) {
00232            buildVehicleEmissions(oc.getString("flow-definitions"));
00233        }
00234     */
00235     //
00236 }


Generated on Wed May 5 00:06:37 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6