Definition in file jtrrouter_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 <set>
#include <router/ROFrame.h>
#include <router/ROLoader.h>
#include <router/RONet.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/common/RandHelper.h>
#include <utils/common/StringTokenizer.h>
#include <utils/xml/XMLSubSys.h>
#include "ROJTREdgeBuilder.h"
#include "ROJTRRouter.h"
#include "ROJTREdge.h"
#include "ROJTRTurnDefLoader.h"
#include "ROJTRFrame.h"
#include <utils/iodevices/OutputDevice.h>
Go to the source code of this file.
Functions | |
| void | computeRoutes (RONet &net, ROLoader &loader, OptionsCont &oc) |
| std::vector< SUMOReal > | getTurningDefaults (OptionsCont &oc) |
| void | initNet (RONet &net, ROLoader &loader, OptionsCont &oc, const std::vector< SUMOReal > &turnDefs) |
| void | loadJTRDefinitions (RONet &net, OptionsCont &oc) |
| int | main (int argc, char **argv) |
| void computeRoutes | ( | RONet & | net, | |
| ROLoader & | loader, | |||
| OptionsCont & | oc | |||
| ) |
Computes the routes saving them
Definition at line 147 of file jtrrouter_main.cpp.
References RONet::closeOutput(), OptionsCont::getBool(), OptionsCont::getString(), RONet::openOutput(), ROLoader::openRoutes(), ROLoader::processAllRoutes(), ROLoader::processRoutesStepWise(), and string2time().
00147 { 00148 // initialise the loader 00149 loader.openRoutes(net); 00150 // prepare the output 00151 try { 00152 net.openOutput(oc.getString("output"), false); 00153 } catch (IOError &e) { 00154 throw e; 00155 } 00156 // build the router 00157 ROJTRRouter router(net, oc.getBool("continue-on-unbuild"), 00158 oc.getBool("accept-all-destinations")); 00159 // the routes are sorted - process stepwise 00160 if (!oc.getBool("unsorted")) { 00161 loader.processRoutesStepWise(string2time(oc.getString("begin")), string2time(oc.getString("end")), net, router); 00162 } 00163 // the routes are not sorted: load all and process 00164 else { 00165 loader.processAllRoutes(string2time(oc.getString("begin")), string2time(oc.getString("end")), net, router); 00166 } 00167 // end the processing 00168 net.closeOutput(); 00169 }
| std::vector<SUMOReal> getTurningDefaults | ( | OptionsCont & | oc | ) |
Definition at line 99 of file jtrrouter_main.cpp.
References TplConvert< E >::_2SUMOReal(), OptionsCont::getStringVector(), and SUMOReal.
Referenced by main().
00099 { 00100 std::vector<SUMOReal> ret; 00101 std::vector<std::string> defs = oc.getStringVector("turn-defaults"); 00102 if (defs.size()<2) { 00103 throw ProcessError("The defaults for turnings must be a tuple of at least two numbers divided by ','."); 00104 } 00105 for (std::vector<std::string>::const_iterator i=defs.begin(); i!=defs.end(); ++i) { 00106 try { 00107 SUMOReal val = TplConvert<char>::_2SUMOReal((*i).c_str()); 00108 ret.push_back(val); 00109 } catch (NumberFormatException&) { 00110 throw ProcessError("A turn default is not numeric."); 00111 } 00112 } 00113 return ret; 00114 }
| void initNet | ( | RONet & | net, | |
| ROLoader & | loader, | |||
| OptionsCont & | oc, | |||
| const std::vector< SUMOReal > & | turnDefs | |||
| ) |
loads the net The net is in this meaning made up by the net itself and the dynamic weights which may be supplied in a separate file
Definition at line 79 of file jtrrouter_main.cpp.
References RONet::getEdgeMap(), OptionsCont::getString(), OptionsCont::isSet(), ROLoader::loadNet(), and ROLoader::loadWeights().
00080 { 00081 // load the net 00082 ROJTREdgeBuilder builder; 00083 loader.loadNet(net, builder); 00084 // set the turn defaults 00085 const std::map<std::string, ROEdge*> &edges = net.getEdgeMap(); 00086 for (std::map<std::string, ROEdge*>::const_iterator i=edges.begin(); i!=edges.end(); ++i) { 00087 static_cast<ROJTREdge*>((*i).second)->setTurnDefaults(turnDefs); 00088 } 00089 // load the weights when wished/available 00090 if (oc.isSet("weights")) { 00091 loader.loadWeights(net, "weights", oc.getString("measure"), false); 00092 } 00093 if (oc.isSet("lane-weights")) { 00094 loader.loadWeights(net, "lane-weights", oc.getString("measure"), true); 00095 } 00096 }
| void loadJTRDefinitions | ( | RONet & | net, | |
| OptionsCont & | oc | |||
| ) |
Definition at line 118 of file jtrrouter_main.cpp.
References MsgHandler::clear(), ROEdge::ET_SINK, OptionsCont::getBool(), RONet::getEdge(), MsgHandler::getErrorInstance(), OptionsCont::getString(), OptionsCont::getStringVector(), OptionsCont::isSet(), XMLSubSys::runParser(), and ROEdge::setType().
Referenced by main().
00118 { 00119 // load the turning definitions (and possible sink definition) 00120 if (oc.isSet("turn-definition")) { 00121 ROJTRTurnDefLoader loader(net); 00122 if (!XMLSubSys::runParser(loader, oc.getString("turn-definition"))) { 00123 throw ProcessError(); 00124 } 00125 } 00126 if (MsgHandler::getErrorInstance()->wasInformed() && oc.getBool("dismiss-loading-errors")) { 00127 MsgHandler::getErrorInstance()->clear(); 00128 } 00129 // parse sink edges specified at the input/within the configuration 00130 if (oc.isSet("sinks")) { 00131 std::vector<std::string> edges = oc.getStringVector("sinks"); 00132 for (std::vector<std::string>::const_iterator i=edges.begin(); i!=edges.end(); ++i) { 00133 ROJTREdge *edge = static_cast<ROJTREdge*>(net.getEdge(*i)); 00134 if (edge==0) { 00135 throw ProcessError("The edge '" + *i + "' declared as a sink is not known."); 00136 } 00137 edge->setType(ROEdge::ET_SINK); 00138 } 00139 } 00140 }
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 176 of file jtrrouter_main.cpp.
References ROJTRFrame::checkOptions(), SystemFrame::close(), OutputDevice::closeAll(), computeRoutes(), ROJTRFrame::fillOptions(), MsgHandler::getErrorInstance(), OptionsIO::getOptions(), OptionsCont::getOptions(), getTurningDefaults(), MsgHandler::inform(), XMLSubSys::init(), initNet(), MsgHandler::initOutputOptions(), RandHelper::initRandGlobal(), loadJTRDefinitions(), OptionsCont::processMetaOptions(), OptionsCont::setApplicationDescription(), OptionsCont::setApplicationName(), toString(), and MsgHandler::wasInformed().
00176 { 00177 OptionsCont &oc = OptionsCont::getOptions(); 00178 // give some application descriptions 00179 oc.setApplicationDescription("Router for the microscopic road traffic simulation SUMO based on junction turning ratios."); 00180 oc.setApplicationName("jtrrouter", "SUMO jtrrouter Version " + (std::string)VERSION_STRING); 00181 int ret = 0; 00182 RONet *net = 0; 00183 try { 00184 // initialise the application system (messaging, xml, options) 00185 XMLSubSys::init(false); 00186 ROJTRFrame::fillOptions(); 00187 OptionsIO::getOptions(true, argc, argv); 00188 if (oc.processMetaOptions(argc < 2)) { 00189 SystemFrame::close(); 00190 return 0; 00191 } 00192 MsgHandler::initOutputOptions(); 00193 if (!ROJTRFrame::checkOptions()) throw ProcessError(); 00194 RandHelper::initRandGlobal(); 00195 std::vector<SUMOReal> defs = getTurningDefaults(oc); 00196 // load data 00197 ROLoader loader(oc, true); 00198 net = new RONet(); 00199 initNet(*net, loader, oc, defs); 00200 try { 00201 // parse and set the turn defaults first 00202 loadJTRDefinitions(*net, oc); 00203 // build routes 00204 computeRoutes(*net, loader, oc); 00205 } catch (SAXParseException &e) { 00206 MsgHandler::getErrorInstance()->inform(toString(e.getLineNumber())); 00207 ret = 1; 00208 } catch (SAXException &e) { 00209 MsgHandler::getErrorInstance()->inform(TplConvert<XMLCh>::_2str(e.getMessage())); 00210 ret = 1; 00211 } 00212 if (MsgHandler::getErrorInstance()->wasInformed()) { 00213 throw ProcessError(); 00214 } 00215 } catch (ProcessError &e) { 00216 if (std::string(e.what())!=std::string("Process Error") && std::string(e.what())!=std::string("")) { 00217 MsgHandler::getErrorInstance()->inform(e.what()); 00218 } 00219 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); 00220 ret = 1; 00221 #ifndef _DEBUG 00222 } catch (...) { 00223 MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false); 00224 ret = 1; 00225 #endif 00226 } 00227 delete net; 00228 OutputDevice::closeAll(); 00229 SystemFrame::close(); 00230 if (ret==0) { 00231 std::cout << "Success." << std::endl; 00232 } 00233 return ret; 00234 }
1.5.6