#include <NLBuilder.h>
It is a black-box where only the options and factories must be supplied on the constructor call. An (empty) instance of the network must be supplied, too, and is filled during loading.
Definition at line 68 of file NLBuilder.h.
Public Member Functions | |
| virtual bool | build () throw (ProcessError) |
| Builds and initialises the simulation. | |
| NLBuilder (OptionsCont &oc, MSNet &net, NLEdgeControlBuilder &eb, NLJunctionControlBuilder &jb, NLDetectorBuilder &db, NLHandler &xmlHandler) throw () | |
| Constructor. | |
| virtual | ~NLBuilder () throw () |
| Destructor. | |
Protected Member Functions | |
| void | buildNet () throw (ProcessError) |
| Closes the net building process. | |
| MSRouteLoaderControl * | buildRouteLoaderControl (const OptionsCont &oc) throw (ProcessError) |
| Builds the route loader control. | |
| bool | load (const std::string &mmlWhat) |
| Loads a described subpart form the given list of files. | |
Protected Attributes | |
| NLDetectorBuilder & | myDetectorBuilder |
| The detector control builder to use. | |
| NLEdgeControlBuilder & | myEdgeBuilder |
| The edge control builder to use. | |
| NLJunctionControlBuilder & | myJunctionBuilder |
| The junction control builder to use. | |
| MSNet & | myNet |
| The net to fill. | |
| OptionsCont & | myOptions |
| The options to get the names of the files to load and further information from. | |
| NLHandler & | myXMLHandler |
| The handler used to parse the net. | |
Private Member Functions | |
| NLBuilder (const NLBuilder &s) | |
| invalidated copy operator | |
| NLBuilder & | operator= (const NLBuilder &s) |
| invalidated assignment operator | |
Data Structures | |
| class | EdgeFloatTimeLineRetriever_EdgeEffort |
| class | EdgeFloatTimeLineRetriever_EdgeTravelTime |
| Obtains edge efforts from a weights handler and stores them within the edges. More... | |
| NLBuilder::NLBuilder | ( | OptionsCont & | oc, | |
| MSNet & | net, | |||
| NLEdgeControlBuilder & | eb, | |||
| NLJunctionControlBuilder & | jb, | |||
| NLDetectorBuilder & | db, | |||
| NLHandler & | xmlHandler | |||
| ) | throw () |
Constructor.
| [in] | oc | The options to use |
| [in,out] | net | The network to fill |
| [in] | eb | The builder of edges to use |
| [in] | jb | The builder of junctions to use |
| [in] | db | The detector builder to use |
| [in] | tb | The trigger builder to use |
| [in] | xmlHandler | The xml handler to use |
Definition at line 105 of file NLBuilder.cpp.
00111 : myOptions(oc), myEdgeBuilder(eb), myJunctionBuilder(jb), 00112 myDetectorBuilder(db), 00113 myNet(net), myXMLHandler(xmlHandler) {}
| NLBuilder::~NLBuilder | ( | ) | throw () [virtual] |
| NLBuilder::NLBuilder | ( | const NLBuilder & | s | ) | [private] |
invalidated copy operator
| bool NLBuilder::build | ( | ) | throw (ProcessError) [virtual] |
Builds and initialises the simulation.
At first, the network is loaded and the built using "buildNet". If this could be done, additional information is loaded (state dump, weight files, route files, and additional files). If everything could be done, true is returned, otherwise false.
| ProcessError | If something fails on network building |
Definition at line 120 of file NLBuilder.cpp.
References MsgHandler::beginProcessMsg(), buildNet(), MsgHandler::endProcessMsg(), SysUtils::getCurrentMillis(), MsgHandler::getErrorInstance(), OptionsCont::getInt(), MsgHandler::getMessageInstance(), OptionsCont::getString(), OptionsCont::getStringVector(), MsgHandler::inform(), OptionsCont::isDefault(), OptionsCont::isSet(), OptionsCont::isUsableFileList(), load(), myNet, myOptions, XMLSubSys::runParser(), OptionsCont::set(), toString(), WRITE_MESSAGE, and WRITE_WARNING.
Referenced by load(), and GUILoadThread::run().
00120 { 00121 // try to build the net 00122 if (!load("net-file")) { 00123 return false; 00124 } 00125 buildNet(); 00126 #ifdef HAVE_MESOSIM 00127 // load the previous state if wished 00128 if (myOptions.isSet("load-state")) { 00129 long before = SysUtils::getCurrentMillis(); 00130 BinaryInputDevice strm(myOptions.getString("load-state")); 00131 if (!strm.good()) { 00132 MsgHandler::getErrorInstance()->inform("Could not read state from '" + myOptions.getString("load-state") + "'!"); 00133 } else { 00134 MsgHandler::getMessageInstance()->beginProcessMsg("Loading state from '" + myOptions.getString("load-state") + "'..."); 00135 unsigned int step = myNet.loadState(strm); 00136 if (myOptions.isDefault("begin")) { 00137 myOptions.set("begin", toString(step)); 00138 } 00139 if (step != myOptions.getInt("begin")) { 00140 WRITE_WARNING("State was written at a different time " + toString(step) + " than the begin time " + toString(myOptions.getInt("begin")) + "!"); 00141 } 00142 } 00143 if (MsgHandler::getErrorInstance()->wasInformed()) { 00144 return false; 00145 } 00146 MsgHandler::getMessageInstance()->endProcessMsg("done (" + toString(SysUtils::getCurrentMillis()-before) + "ms)."); 00147 } 00148 #endif 00149 // load weights if wished 00150 if (myOptions.isSet("weight-files")) { 00151 if (!myOptions.isUsableFileList("weight-files")) { 00152 return false; 00153 } 00154 // build and prepare the weights handler 00155 std::vector<SAXWeightsHandler::ToRetrieveDefinition*> retrieverDefs; 00156 // travel time, first (always used) 00157 EdgeFloatTimeLineRetriever_EdgeTravelTime ttRetriever(myNet); 00158 retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition("traveltime", true, ttRetriever)); 00159 // the measure to use, then 00160 EdgeFloatTimeLineRetriever_EdgeEffort eRetriever(myNet); 00161 std::string measure = myOptions.isSet("measure") ? myOptions.getString("measure") : "traveltime"; 00162 if (measure!="traveltime") { 00163 std::string umeasure = measure; 00164 if (measure=="CO"||measure=="CO2"||measure=="HC"||measure=="PMx"||measure=="NOx"||measure=="fuel") { 00165 umeasure = measure + "_perVeh"; 00166 } 00167 retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition(umeasure, true, eRetriever)); 00168 } 00169 // set up handler 00170 SAXWeightsHandler handler(retrieverDefs, ""); 00171 // start parsing; for each file in the list 00172 std::vector<std::string> files = myOptions.getStringVector("weight-files"); 00173 for (std::vector<std::string>::iterator i=files.begin(); i!=files.end(); ++i) { 00174 // report about loading when wished 00175 WRITE_MESSAGE("Loading weights from '" + *i + "'..."); 00176 // parse the file 00177 if (!XMLSubSys::runParser(handler, *i)) { 00178 return false; 00179 } 00180 } 00181 } 00182 // load routes 00183 if (myOptions.isSet("route-files")&&myOptions.getInt("route-steps")<=0) { 00184 if (!load("route-files")) { 00185 return false; 00186 } 00187 } 00188 // load additional net elements (sources, detectors, ...) 00189 if (myOptions.isSet("additional-files")) { 00190 if (!load("additional-files")) { 00191 return false; 00192 } 00193 } 00194 WRITE_MESSAGE("Loading done."); 00195 return true; 00196 }
| void NLBuilder::buildNet | ( | ) | throw (ProcessError) [protected] |
Closes the net building process.
Builds the microsim-structures which belong to a MSNet using the factories filled while loading. Initialises the network using these structures by calling MSNet::closeBuilding. If an error occurs, all built structures are deleted and a ProcessError is thrown.
| ProcessError | If the loaded structures could not be built |
Definition at line 200 of file NLBuilder.cpp.
References NLJunctionControlBuilder::build(), NLEdgeControlBuilder::build(), buildRouteLoaderControl(), MSFrame::buildStreams(), NLJunctionControlBuilder::buildTLLogics(), MSNet::closeBuilding(), NLJunctionControlBuilder::closeJunctions(), OptionsCont::getIntVector(), OptionsCont::getString(), OptionsCont::isDefault(), myDetectorBuilder, myEdgeBuilder, myJunctionBuilder, myNet, myOptions, TIME2STEPS, and toString().
Referenced by build().
00200 { 00201 MSEdgeControl *edges = 0; 00202 MSJunctionControl *junctions = 0; 00203 MSRouteLoaderControl *routeLoaders = 0; 00204 MSTLLogicControl *tlc = 0; 00205 try { 00206 myJunctionBuilder.closeJunctions(myDetectorBuilder); 00207 edges = myEdgeBuilder.build(); 00208 junctions = myJunctionBuilder.build(); 00209 routeLoaders = buildRouteLoaderControl(myOptions); 00210 tlc = myJunctionBuilder.buildTLLogics(); 00211 MSFrame::buildStreams(); 00212 std::vector<SUMOTime> stateDumpTimes; 00213 std::vector<std::string> stateDumpFiles; 00214 #ifdef HAVE_MESOSIM 00215 const std::vector<int> times = myOptions.getIntVector("save-state.times"); 00216 for (std::vector<int>::const_iterator i = times.begin(); i != times.end(); ++i) { 00217 stateDumpTimes.push_back(TIME2STEPS(*i)); 00218 } 00219 if (!myOptions.isDefault("save-state.prefix")) { 00220 const std::string prefix = myOptions.getString("save-state.prefix"); 00221 for (std::vector<SUMOTime>::iterator i = stateDumpTimes.begin(); i != stateDumpTimes.end(); ++i) { 00222 stateDumpFiles.push_back(prefix + "_" + toString(*i) + ".bin"); 00223 } 00224 } else { 00225 stateDumpFiles = StringTokenizer(myOptions.getString("save-state.files")).getVector() ; 00226 } 00227 #endif 00228 myNet.closeBuilding(edges, junctions, routeLoaders, tlc, stateDumpTimes, stateDumpFiles); 00229 } catch (IOError &e) { 00230 delete edges; 00231 delete junctions; 00232 delete routeLoaders; 00233 delete tlc; 00234 throw ProcessError(e.what()); 00235 } catch (ProcessError &) { 00236 delete edges; 00237 delete junctions; 00238 delete routeLoaders; 00239 delete tlc; 00240 throw; 00241 } 00242 }
| MSRouteLoaderControl * NLBuilder::buildRouteLoaderControl | ( | const OptionsCont & | oc | ) | throw (ProcessError) [protected] |
Builds the route loader control.
Goes through the list of route files to open defined in the option "route-files" and builds loaders reading these files
| [in] | oc | The options to read the list of route files to open from |
| ProcessError | If an error occured |
Definition at line 269 of file NLBuilder.cpp.
References FileHelpers::exists(), and myNet.
Referenced by buildNet().
00269 { 00270 // build the loaders 00271 MSRouteLoaderControl::LoaderVector loaders; 00272 // check whether a list is existing 00273 if (oc.isSet("route-files")&&oc.getInt("route-steps")>0) { 00274 std::vector<std::string> files = oc.getStringVector("route-files"); 00275 for (std::vector<std::string>::const_iterator fileIt=files.begin(); fileIt!=files.end(); ++fileIt) { 00276 if (!FileHelpers::exists(*fileIt)) { 00277 throw ProcessError("The route file '" + *fileIt + "' does not exist."); 00278 } 00279 } 00280 // open files for reading 00281 for (std::vector<std::string>::const_iterator fileIt=files.begin(); fileIt!=files.end(); ++fileIt) { 00282 loaders.push_back(new MSRouteLoader(myNet, new MSRouteHandler(*fileIt, false))); 00283 } 00284 } 00285 // build the route control 00286 return new MSRouteLoaderControl(myNet, oc.getInt("route-steps"), loaders); 00287 }
| bool NLBuilder::load | ( | const std::string & | mmlWhat | ) | [protected] |
Loads a described subpart form the given list of files.
Assuming the given string to be an option name behind which a list of files is stored, this method invokes an XML reader on all the files set for this option.
| [in] | mmlWhat | The option to get the file list from |
Definition at line 246 of file NLBuilder.cpp.
References MsgHandler::beginProcessMsg(), MsgHandler::endProcessMsg(), SysUtils::getCurrentMillis(), MsgHandler::getMessageInstance(), OptionsCont::getOptions(), OptionsCont::getStringVector(), gSuppressMessages, myXMLHandler, XMLSubSys::runParser(), toString(), and WRITE_MESSAGE.
Referenced by build().
00246 { 00247 if (!OptionsCont::getOptions().isUsableFileList(mmlWhat)) { 00248 return false; 00249 } 00250 std::vector<std::string> files = OptionsCont::getOptions().getStringVector(mmlWhat); 00251 for (std::vector<std::string>::const_iterator fileIt=files.begin(); fileIt!=files.end(); ++fileIt) { 00252 if (!gSuppressMessages) { 00253 MsgHandler::getMessageInstance()->beginProcessMsg("Loading " + mmlWhat + " from '" + *fileIt + "' ..."); 00254 } 00255 long before = SysUtils::getCurrentMillis(); 00256 if (!XMLSubSys::runParser(myXMLHandler, *fileIt)) { 00257 WRITE_MESSAGE("Loading of " + mmlWhat + " failed."); 00258 return false; 00259 } 00260 if (!gSuppressMessages) { 00261 MsgHandler::getMessageInstance()->endProcessMsg(" done (" + toString(SysUtils::getCurrentMillis()-before) + "ms)."); 00262 } 00263 } 00264 return true; 00265 }
NLDetectorBuilder& NLBuilder::myDetectorBuilder [protected] |
The detector control builder to use.
Definition at line 212 of file NLBuilder.h.
Referenced by buildNet().
NLEdgeControlBuilder& NLBuilder::myEdgeBuilder [protected] |
The edge control builder to use.
Definition at line 206 of file NLBuilder.h.
Referenced by buildNet().
NLJunctionControlBuilder& NLBuilder::myJunctionBuilder [protected] |
The junction control builder to use.
Definition at line 209 of file NLBuilder.h.
Referenced by buildNet().
MSNet& NLBuilder::myNet [protected] |
The net to fill.
Definition at line 215 of file NLBuilder.h.
Referenced by build(), buildNet(), and buildRouteLoaderControl().
OptionsCont& NLBuilder::myOptions [protected] |
The options to get the names of the files to load and further information from.
Definition at line 203 of file NLBuilder.h.
Referenced by build(), and buildNet().
NLHandler& NLBuilder::myXMLHandler [protected] |
The handler used to parse the net.
Definition at line 218 of file NLBuilder.h.
Referenced by load().
1.5.6