#include <ROLoader.h>
Loads the network and route descriptions using further classes.
Is capable to either load all routes in one step or go through them step wise.
Definition at line 62 of file ROLoader.h.
Public Member Functions | |
| virtual void | loadNet (RONet &toFill, ROAbstractEdgeBuilder &eb) |
| Loads the network. | |
| bool | loadWeights (RONet &net, const std::string &optionName, const std::string &measure, bool useLanes) |
| Loads the net weights. | |
| bool | makeSingleStep (SUMOTime end, RONet &net, SUMOAbstractRouter< ROEdge, ROVehicle > &router) |
| unsigned int | openRoutes (RONet &net) |
| Builds and opens all route loaders Route loaders are derived from ROAbstractRouteDefLoader. | |
| virtual void | processAllRoutes (SUMOTime start, SUMOTime end, RONet &net, SUMOAbstractRouter< ROEdge, ROVehicle > &router) |
| Loads all routes at once This is done for all previously build route loaders. | |
| virtual void | processRoutesStepWise (SUMOTime start, SUMOTime end, RONet &net, SUMOAbstractRouter< ROEdge, ROVehicle > &router) |
| Loads routes stepwise This is done for all previously build route loaders. | |
| ROLoader (OptionsCont &oc, bool emptyDestinationsAllowed) throw () | |
| Constructor. | |
| virtual | ~ROLoader () |
| Destructor. | |
Protected Types | |
| typedef std::vector < ROAbstractRouteDefLoader * > | RouteLoaderCont |
| Definition of route loader list. | |
Protected Member Functions | |
| ROAbstractRouteDefLoader * | buildNamedHandler (const std::string &optionName, const std::string &file, RONet &net) throw (ProcessError) |
| void | destroyHandlers () throw () |
| Deletes all handlers and clears their container ("myHandler"). | |
| SUMOTime | getMinTimeStep () const throw () |
| Returns the first time step known by the built handlers. | |
| bool | openTypedRoutes (const std::string &optionName, RONet &net) throw () |
| Opens route handler of the given type. | |
| void | writeStats (SUMOTime time, SUMOTime start, int absNo) throw () |
Protected Attributes | |
| bool | myEmptyDestinationsAllowed |
| Information whether empty destinations are allowed. | |
| RouteLoaderCont | myHandler |
| List of route loaders. | |
| OptionsCont & | myOptions |
| Options to use. | |
Private Member Functions | |
| ROLoader & | operator= (const ROLoader &src) |
| Invalidated assignment operator. | |
| ROLoader (const ROLoader &src) | |
| Invalidated copy constructor. | |
Data Structures | |
| class | EdgeFloatTimeLineRetriever_EdgeTravelTime |
| Obtains edge travel times from a weights handler and stores them within the edges. More... | |
| class | EdgeFloatTimeLineRetriever_EdgeWeight |
| Obtains edge weights from a weights handler and stores them within the edges. More... | |
typedef std::vector<ROAbstractRouteDefLoader*> ROLoader::RouteLoaderCont [protected] |
| ROLoader::ROLoader | ( | OptionsCont & | oc, | |
| bool | emptyDestinationsAllowed | |||
| ) | throw () |
Constructor.
| [in] | oc | The options to use |
| [in] | emptyDestinationsAllowed | Whether tripdefs may be given without destinations |
Definition at line 99 of file ROLoader.cpp.
00100 : myOptions(oc), myEmptyDestinationsAllowed(emptyDestinationsAllowed) {}
| ROLoader::~ROLoader | ( | ) | [virtual] |
Destructor.
Definition at line 103 of file ROLoader.cpp.
References destroyHandlers().
00103 { 00104 destroyHandlers(); 00105 }
| ROLoader::ROLoader | ( | const ROLoader & | src | ) | [private] |
Invalidated copy constructor.
| ROAbstractRouteDefLoader * ROLoader::buildNamedHandler | ( | const std::string & | optionName, | |
| const std::string & | file, | |||
| RONet & | net | |||
| ) | throw (ProcessError) [protected] |
Definition at line 296 of file ROLoader.cpp.
References OptionsCont::getBool(), OptionsCont::getFloat(), OptionsCont::getInt(), OptionsCont::getString(), myEmptyDestinationsAllowed, myOptions, and string2time().
Referenced by openTypedRoutes().
00298 { 00299 if (optionName=="sumo-input") { 00300 return new RORDLoader_SUMOBase(net, 00301 string2time(myOptions.getString("begin")), string2time(myOptions.getString("end")), 00302 myOptions.getFloat("gBeta"), myOptions.getFloat("gA"), 00303 myOptions.getInt("max-alternatives"), myOptions.getBool("repair"), 00304 myOptions.getBool("with-taz"), file); 00305 } 00306 if (optionName=="trip-defs") { 00307 return new RORDLoader_TripDefs(net, 00308 string2time(myOptions.getString("begin")), string2time(myOptions.getString("end")), 00309 myEmptyDestinationsAllowed, myOptions.getBool("with-taz"), file); 00310 } 00311 if (optionName=="alternatives") { 00312 return new RORDLoader_SUMOBase(net, 00313 string2time(myOptions.getString("begin")), string2time(myOptions.getString("end")), 00314 myOptions.getFloat("gBeta"), myOptions.getFloat("gA"), 00315 myOptions.getInt("max-alternatives"), myOptions.getBool("repair"), 00316 myOptions.getBool("with-taz"), file); 00317 } 00318 if (optionName=="flows") { 00319 return new RORDGenerator_ODAmounts(net, 00320 string2time(myOptions.getString("begin")), string2time(myOptions.getString("end")), 00321 myEmptyDestinationsAllowed, myOptions.getBool("randomize-flows"), file); 00322 } 00323 return 0; 00324 }
| void ROLoader::destroyHandlers | ( | ) | throw () [protected] |
Deletes all handlers and clears their container ("myHandler").
Definition at line 383 of file ROLoader.cpp.
References myHandler.
Referenced by openRoutes(), and ~ROLoader().
00383 { 00384 for (RouteLoaderCont::const_iterator i=myHandler.begin(); i!=myHandler.end(); ++i) { 00385 delete *i; 00386 } 00387 myHandler.clear(); 00388 }
| SUMOTime ROLoader::getMinTimeStep | ( | ) | const throw () [protected] |
Returns the first time step known by the built handlers.
The handlers are responsible for not adding route definitions prior to "begin"-Option's value. These priori departures must also not be reported by them whaen asking via "getLastReadTimeStep".
Definition at line 225 of file ROLoader.cpp.
References myHandler.
Referenced by openRoutes(), and processRoutesStepWise().
00225 { 00226 RouteLoaderCont::const_iterator i=myHandler.begin(); 00227 SUMOTime ret = (*i)->getLastReadTimeStep(); 00228 ++i; 00229 for (; i!=myHandler.end(); i++) { 00230 SUMOTime akt = (*i)->getLastReadTimeStep(); 00231 if (akt<ret) { 00232 ret = akt; 00233 } 00234 } 00235 return ret; 00236 }
| void ROLoader::loadNet | ( | RONet & | toFill, | |
| ROAbstractEdgeBuilder & | eb | |||
| ) | [virtual] |
Loads the network.
Definition at line 109 of file ROLoader.cpp.
References MsgHandler::beginProcessMsg(), MsgHandler::endProcessMsg(), FileHelpers::exists(), MsgHandler::getMessageInstance(), OptionsCont::getString(), OptionsCont::isSet(), myOptions, XMLSubSys::runParser(), and GenericSAXHandler::setFileName().
Referenced by initNet(), and main().
00109 { 00110 std::string file = myOptions.getString("net-file"); 00111 if (file=="") { 00112 throw ProcessError("Missing definition of network to load!"); 00113 } 00114 if (!FileHelpers::exists(file)) { 00115 throw ProcessError("The network file '" + file + "' could not be found."); 00116 } 00117 MsgHandler::getMessageInstance()->beginProcessMsg("Loading net..."); 00118 RONetHandler handler(toFill, eb); 00119 handler.setFileName(file); 00120 if (!XMLSubSys::runParser(handler, file)) { 00121 MsgHandler::getMessageInstance()->endProcessMsg("failed."); 00122 throw ProcessError(); 00123 } else { 00124 MsgHandler::getMessageInstance()->endProcessMsg("done."); 00125 } 00126 if (myOptions.isSet("districts")) { 00127 file = myOptions.getString("districts"); 00128 if (!FileHelpers::exists(file)) { 00129 throw ProcessError("The districts file '" + file + "' could not be found."); 00130 } 00131 MsgHandler::getMessageInstance()->beginProcessMsg("Loading districts..."); 00132 handler.setFileName(file); 00133 if (!XMLSubSys::runParser(handler, file)) { 00134 MsgHandler::getMessageInstance()->endProcessMsg("failed."); 00135 throw ProcessError(); 00136 } else { 00137 MsgHandler::getMessageInstance()->endProcessMsg("done."); 00138 } 00139 } 00140 }
| bool ROLoader::loadWeights | ( | RONet & | net, | |
| const std::string & | optionName, | |||
| const std::string & | measure, | |||
| bool | useLanes | |||
| ) |
Loads the net weights.
Definition at line 328 of file ROLoader.cpp.
References MsgHandler::beginProcessMsg(), MsgHandler::endProcessMsg(), RONet::getEdgeMap(), MsgHandler::getMessageInstance(), OptionsCont::getStringVector(), OptionsCont::isUsableFileList(), myOptions, XMLSubSys::runParser(), and WRITE_MESSAGE.
Referenced by initNet().
00329 { 00330 // check whether the file exists 00331 if (!myOptions.isUsableFileList(optionName)) { 00332 return false; 00333 } 00334 // build and prepare the weights handler 00335 std::vector<SAXWeightsHandler::ToRetrieveDefinition*> retrieverDefs; 00336 // travel time, first (always used) 00337 EdgeFloatTimeLineRetriever_EdgeTravelTime ttRetriever(net); 00338 retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition("traveltime", !useLanes, ttRetriever)); 00339 // the measure to use, then 00340 EdgeFloatTimeLineRetriever_EdgeWeight eRetriever(net); 00341 if (measure!="traveltime") { 00342 std::string umeasure = measure; 00343 if (measure=="CO"||measure=="CO2"||measure=="HC"||measure=="PMx"||measure=="NOx"||measure=="fuel") { 00344 umeasure = measure + "_perVeh"; 00345 } 00346 retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition(umeasure, !useLanes, eRetriever)); 00347 } 00348 // set up handler 00349 SAXWeightsHandler handler(retrieverDefs, ""); 00350 // go through files 00351 std::vector<std::string> files = myOptions.getStringVector(optionName); 00352 for (std::vector<std::string>::const_iterator fileIt=files.begin(); fileIt!=files.end(); ++fileIt) { 00353 MsgHandler::getMessageInstance()->beginProcessMsg("Loading precomputed net weights from '" + *fileIt + "' ..."); 00354 if (XMLSubSys::runParser(handler, *fileIt)) { 00355 MsgHandler::getMessageInstance()->endProcessMsg(" done."); 00356 } else { 00357 WRITE_MESSAGE("failed."); 00358 return false; 00359 } 00360 } 00361 // build edge-internal time lines 00362 const std::map<std::string, ROEdge*> &edges = net.getEdgeMap(); 00363 for (std::map<std::string, ROEdge*>::const_iterator i=edges.begin(); i!=edges.end(); ++i) { 00364 (*i).second->buildTimeLines(measure); 00365 } 00366 return true; 00367 }
| bool ROLoader::makeSingleStep | ( | SUMOTime | end, | |
| RONet & | net, | |||
| SUMOAbstractRouter< ROEdge, ROVehicle > & | router | |||
| ) |
Definition at line 204 of file ROLoader.cpp.
References MsgHandler::getErrorInstance(), myHandler, myOptions, RONet::saveAndRemoveRoutesUntil(), and MsgHandler::wasInformed().
Referenced by processRoutesStepWise().
00204 { 00205 RouteLoaderCont::iterator i; 00206 // go through all handlers 00207 if (myHandler.size()!= 0) { 00208 for (i=myHandler.begin(); i!=myHandler.end(); i++) { 00209 // load routes until the time point is reached 00210 if ((*i)->readRoutesAtLeastUntil(end, false)) { 00211 // save the routes 00212 net.saveAndRemoveRoutesUntil(myOptions, router, end); 00213 } else { 00214 return false; 00215 } 00216 } 00217 return MsgHandler::getErrorInstance()->wasInformed(); 00218 } else { 00219 return false; 00220 } 00221 }
| unsigned int ROLoader::openRoutes | ( | RONet & | net | ) |
Builds and opens all route loaders Route loaders are derived from ROAbstractRouteDefLoader.
Definition at line 144 of file ROLoader.cpp.
References destroyHandlers(), OptionsCont::getBool(), MsgHandler::getMessageInstance(), getMinTimeStep(), OptionsCont::getString(), MsgHandler::inform(), myHandler, myOptions, openTypedRoutes(), string2time(), and time2string().
Referenced by computeRoutes().
00144 { 00145 // build loader 00146 // load sumo-routes when wished 00147 bool ok = openTypedRoutes("sumo-input", net); 00148 // load the XML-trip definitions when wished 00149 ok &= openTypedRoutes("trip-defs", net); 00150 // load the sumo-alternative file when wished 00151 ok &= openTypedRoutes("alternatives", net); 00152 // load the amount definitions if wished 00153 ok &= openTypedRoutes("flows", net); 00154 // check 00155 if (ok&&myHandler.size()==0) { 00156 throw ProcessError("No route input specified."); 00157 } 00158 // skip routes prior to the begin time 00159 if (ok&&!myOptions.getBool("unsorted")) { 00160 MsgHandler::getMessageInstance()->inform("Skipping..."); 00161 for (RouteLoaderCont::iterator i=myHandler.begin(); ok&&i!=myHandler.end(); i++) { 00162 ok &= (*i)->readRoutesAtLeastUntil(string2time(myOptions.getString("begin")), true); 00163 } 00164 MsgHandler::getMessageInstance()->inform("Skipped until: " + time2string(getMinTimeStep())); 00165 } 00166 // check whether everything's ok 00167 if (!ok) { 00168 destroyHandlers(); 00169 throw ProcessError(); 00170 } 00171 return (unsigned int) myHandler.size(); 00172 }
Opens route handler of the given type.
Checks whether the given option name is known, returns true if not (this means that everything's ok, though the according handler is not built).
Checks then whether the given option name is set and his value is one or a set of valid (existing) files. This is done via a call to "OptionsCont::isUsableFileList" (which generates a proper error message).
If the given files are valid, the proper instance(s) is built using "buildNamedHandler" and if this could be done, it is added to the list of route handlers to use ("myHandler")
Returns whether the wished handler(s) could be built.
| [in] | optionName | The name of the option that refers to which handler and which files shall be used |
| [in] | net | The net to assign to the built handlers |
Definition at line 260 of file ROLoader.cpp.
References buildNamedHandler(), OptionsCont::exists(), MsgHandler::getErrorInstance(), OptionsCont::getStringVector(), MsgHandler::inform(), OptionsCont::isSet(), OptionsCont::isUsableFileList(), myHandler, and myOptions.
Referenced by openRoutes().
00261 { 00262 // check whether the current loader is known 00263 // (not all routers import all route formats) 00264 if (!myOptions.exists(optionName)) { 00265 return true; 00266 } 00267 // check whether the current loader is wished 00268 // and the file(s) can be used 00269 if (!myOptions.isUsableFileList(optionName)) { 00270 return !myOptions.isSet(optionName); 00271 } 00272 bool ok = true; 00273 std::vector<std::string> files = myOptions.getStringVector(optionName); 00274 for (std::vector<std::string>::const_iterator fileIt=files.begin(); fileIt!=files.end(); ++fileIt) { 00275 // build the instance when everything's all right 00276 try { 00277 ROAbstractRouteDefLoader *instance = buildNamedHandler(optionName, *fileIt, net); 00278 myHandler.push_back(instance); 00279 } catch (ProcessError &e) { 00280 std::string msg = "The loader for " + optionName + " from file '" + *fileIt + "' could not be initialised;"; 00281 std::string reason = e.what(); 00282 if (reason!="Process Error"&&reason!="") { 00283 msg = msg + "\n Reason: " + reason + "."; 00284 } else { 00285 msg = msg + "\n (unknown reason)."; 00286 } 00287 MsgHandler::getErrorInstance()->inform(msg); 00288 ok = false; 00289 } 00290 } 00291 return ok; 00292 }
| void ROLoader::processAllRoutes | ( | SUMOTime | start, | |
| SUMOTime | end, | |||
| RONet & | net, | |||
| SUMOAbstractRouter< ROEdge, ROVehicle > & | router | |||
| ) | [virtual] |
Loads all routes at once This is done for all previously build route loaders.
Definition at line 240 of file ROLoader.cpp.
References myHandler, myOptions, RONet::saveAndRemoveRoutesUntil(), SUMOTime_MAX, and writeStats().
Referenced by computeRoutes().
00241 { 00242 long absNo = end - start; 00243 bool ok = true; 00244 for (RouteLoaderCont::iterator i=myHandler.begin(); ok&&i!=myHandler.end(); i++) { 00245 ok &= (*i)->readRoutesAtLeastUntil(SUMOTime_MAX, false); 00246 } 00247 // save the routes 00248 SUMOTime time = start; 00249 for (; time<end;) { 00250 writeStats(time, start, absNo); 00251 time = net.saveAndRemoveRoutesUntil(myOptions, router, time); 00252 if (time<0) { 00253 time = end; 00254 } 00255 } 00256 }
| void ROLoader::processRoutesStepWise | ( | SUMOTime | start, | |
| SUMOTime | end, | |||
| RONet & | net, | |||
| SUMOAbstractRouter< ROEdge, ROVehicle > & | router | |||
| ) | [virtual] |
Loads routes stepwise This is done for all previously build route loaders.
Definition at line 176 of file ROLoader.cpp.
References DELTA_T, RONet::furtherStored(), OptionsCont::getBool(), MsgHandler::getErrorInstance(), MsgHandler::getMessageInstance(), getMinTimeStep(), MsgHandler::inform(), makeSingleStep(), myHandler, myOptions, time2string(), MsgHandler::wasInformed(), and writeStats().
Referenced by computeRoutes().
00177 { 00178 SUMOTime absNo = end - start; 00179 // skip routes that begin before the simulation's begin 00180 // loop till the end 00181 bool endReached = false; 00182 bool errorOccured = false; 00183 SUMOTime time = myHandler.size()!=0 ? getMinTimeStep() : start; 00184 SUMOTime firstStep = time; 00185 SUMOTime lastStep = time; 00186 for (; time<end&&!errorOccured&&!endReached; time+=DELTA_T) { 00187 writeStats(time, start, absNo); 00188 makeSingleStep(time, net, router); 00189 // check whether further data exist 00190 endReached = !net.furtherStored(); 00191 lastStep = time; 00192 for (RouteLoaderCont::iterator i=myHandler.begin(); endReached&&i!=myHandler.end(); i++) { 00193 if (!(*i)->ended()) { 00194 endReached = false; 00195 } 00196 } 00197 errorOccured = MsgHandler::getErrorInstance()->wasInformed() && !myOptions.getBool("continue-on-unbuild"); 00198 } 00199 MsgHandler::getMessageInstance()->inform("Routes found between time steps " + time2string(firstStep) + " and " + time2string(lastStep) + "."); 00200 }
Definition at line 371 of file ROLoader.cpp.
References OptionsCont::getBool(), MsgHandler::getMessageInstance(), myOptions, OUTPUT_ACCURACY, MsgHandler::progressMsg(), SUMOReal, time2string(), and toString().
Referenced by processAllRoutes(), and processRoutesStepWise().
00371 { 00372 if (myOptions.getBool("verbose")) { 00373 SUMOReal perc = (SUMOReal)(time-start) / (SUMOReal) absNo; 00374 std::cout.setf(std::ios::fixed, std::ios::floatfield); // use decimal format 00375 std::cout.setf(std::ios::showpoint); // print decimal point 00376 std::cout << std::setprecision(OUTPUT_ACCURACY); 00377 MsgHandler::getMessageInstance()->progressMsg("Reading time step: " + time2string(time) + " (" + time2string(time-start) + "/" + time2string(absNo) + " = " + toString(perc * 100) + "% done) "); 00378 } 00379 }
bool ROLoader::myEmptyDestinationsAllowed [protected] |
Information whether empty destinations are allowed.
Definition at line 223 of file ROLoader.h.
Referenced by buildNamedHandler().
RouteLoaderCont ROLoader::myHandler [protected] |
List of route loaders.
Definition at line 220 of file ROLoader.h.
Referenced by destroyHandlers(), getMinTimeStep(), makeSingleStep(), openRoutes(), openTypedRoutes(), processAllRoutes(), and processRoutesStepWise().
OptionsCont& ROLoader::myOptions [protected] |
Options to use.
Definition at line 214 of file ROLoader.h.
Referenced by buildNamedHandler(), loadNet(), loadWeights(), makeSingleStep(), openRoutes(), openTypedRoutes(), processAllRoutes(), processRoutesStepWise(), and writeStats().
1.5.6