/* ------------------------------------------------------------------------- * main * ----------------------------------------------------------------------- */ int main(int argc, char** argv) { OptionsCont& oc = OptionsCont::getOptions(); // give some application descriptions oc.setApplicationDescription("A microscopic road traffic simulation."); oc.setApplicationName("sumo", "SUMO Version " VERSION_STRING); int ret = 0; MSNet* net = 0; try { // initialise subsystems XMLSubSys::init(); MSFrame::fillOptions(); OptionsIO::setArgs(argc, argv); OptionsIO::getOptions(); if (oc.processMetaOptions(argc < 2)) { SystemFrame::close(); return 0; } XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net")); if (!MSFrame::checkOptions()) { throw ProcessError(); } MsgHandler::initOutputOptions(); RandHelper::initRandGlobal(); RandHelper::initRandGlobal(MSRouteHandler::getParsingRNG()); // load the net net = load(oc); if (net != 0) { ret = net->simulate(string2time(oc.getString("begin")), string2time(oc.getString("end"))); } } catch (const ProcessError& e) { if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) { WRITE_ERROR(e.what()); } MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); ret = 1; #ifndef _DEBUG } catch (const std::exception& e) { if (std::string(e.what()) != std::string("")) { WRITE_ERROR(e.what()); } MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); ret = 1; } catch (...) { MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false); ret = 1; #endif } delete net; SystemFrame::close(); return ret; }
/* ------------------------------------------------------------------------- * MSTriggeredReader::UserCommand-methods * ----------------------------------------------------------------------- */ MSCalibrator::MSCalibrator_FileTriggeredChild::MSCalibrator_FileTriggeredChild( MSNet &net, const std::string &aXMLFilename, MSCalibrator &parent, MSVehicleControl &vc) throw() : MSTriggeredXMLReader(net, aXMLFilename), MSCalibratorChild(parent, vc), myHaveNext(false), myFlow(-1), myHaveInitialisedFlow(false), myRunningID(0) { myBeginTime = net.getCurrentTimeStep(); }
// =========================================================================== // method definitions // =========================================================================== MSCalibrator::MSCalibrator(const std::string &id, MSNet &net, MSLane* destLane, SUMOReal pos, const std::string &aXMLFilename) throw() : MSTrigger(id), myNet(net), myDestLane(destLane), myPos((SUMOReal) pos), myDb(net), myDebugLevel(0), myDebugFilesBaseName("x:\\temp\\dbg_") { assert(myPos>=0); myToCalibrate = 0; //myInterval=atof(getenv("TM_INTERV")?getenv("TM_INTERV"):"1"); //1 //myNumVehicles=atof(getenv("TM_NUMVEH")?getenv("TM_NUMVEH"):"0"); //14.0 myInterval = 60; myNumVehicles= -1; std::string ilId = "Calib_InductLoopOn_" + myDestLane->getID(); myIL = myDb.createInductLoop(ilId, myDestLane, myPos); MSNet::getInstance()->getEmissionEvents().addEvent( new WrappingCommand<MSCalibrator>(this, &MSCalibrator::execute), //MSNet::getInstance()->getCurrentTimeStep() + 5, 0, MSEventControl::ADAPT_AFTER_EXECUTION); //TODO clean up in destructor!!! MSCalibrator::calibratorMap[id]=this; myActiveChild = new MSCalibrator_FileTriggeredChild(net, aXMLFilename, *this, net.getVehicleControl()); myFileBasedCalibrator = myActiveChild; }
MSNet* NLBuilder::init() { OptionsCont& oc = OptionsCont::getOptions(); oc.clear(); MSFrame::fillOptions(); OptionsIO::getOptions(); if (oc.processMetaOptions(OptionsIO::getArgC() < 2)) { SystemFrame::close(); return nullptr; } XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net")); if (!MSFrame::checkOptions()) { throw ProcessError(); } MsgHandler::initOutputOptions(); RandHelper::initRandGlobal(); RandHelper::initRandGlobal(MSRouteHandler::getParsingRNG()); RandHelper::initRandGlobal(MSDevice::getEquipmentRNG()); MSFrame::setMSGlobals(oc); MSVehicleControl* vc = 0; if (MSGlobals::gUseMesoSim) { vc = new MEVehicleControl(); } else { vc = new MSVehicleControl(); } MSNet* net = new MSNet(vc, new MSEventControl(), new MSEventControl(), new MSEventControl()); // need to init TraCI-Server before loading routes to catch VEHICLE_STATE_BUILT TraCIServer::openSocket(std::map<int, TraCIServer::CmdExecutor>()); NLEdgeControlBuilder eb; NLDetectorBuilder db(*net); NLJunctionControlBuilder jb(*net, db); NLTriggerBuilder tb; NLHandler handler("", *net, db, tb, eb, jb); tb.setHandler(&handler); NLBuilder builder(oc, *net, eb, jb, db, handler); MsgHandler::getErrorInstance()->clear(); MsgHandler::getWarningInstance()->clear(); MsgHandler::getMessageInstance()->clear(); if (builder.build()) { // preload the routes especially for TraCI net->loadRoutes(); return net; } delete net; throw ProcessError(); }
// =========================================================================== // method definitions // =========================================================================== MSTriggeredXMLReader::MSTriggeredXMLReader(MSNet& net, const std::string& filename) : MSTriggeredReader(net), SUMOSAXHandler(filename), myParser(0), myHaveMore(true) { Command* c = new WrappingCommand< MSTriggeredReader >(this, &MSTriggeredReader::wrappedExecute); MSNet::getInstance()->getInsertionEvents().addEvent(c, net.getCurrentTimeStep(), MSEventControl::NO_CHANGE); }
void NLTriggerBuilder::buildBusStop(MSNet& net, const std::string& id, const std::vector<std::string>& lines, MSLane* lane, SUMOReal frompos, SUMOReal topos) { MSBusStop* stop = new MSBusStop(id, lines, *lane, frompos, topos); if (!net.addBusStop(stop)) { delete stop; throw InvalidArgument("Could not build bus stop '" + id + "'; probably declared twice."); } }
void GUITriggerBuilder::buildBusStop(MSNet& net, const std::string& id, const std::vector<std::string>& lines, MSLane* lane, SUMOReal frompos, SUMOReal topos) throw(InvalidArgument) { GUIBusStop* stop = new GUIBusStop(id, lines, *lane, frompos, topos); if (!net.addBusStop(stop)) { delete stop; throw InvalidArgument("Could not build bus stop '" + id + "'; probably declared twice."); } static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(stop); }
// =========================================================================== // method definitions // =========================================================================== NLGeomShapeBuilder::NLGeomShapeBuilder(MSNet &net) throw() : myShapeContainer(net.getShapeContainer()) {}
void MSNet::updateWeather() { OptionsCont &oc = OptionsCont::getOptions(); std::string currentTimeString, initialTimeString = MyHandler2::getInitialTimeString(); MSNet *net = MSNet::getInstance(); if(oc.getAnyVerbosity()>1) std::cout<<"----> void MSNet::updateWeather()"<<std::endl; if(oc.getAnyVerbosity()>2) std::cout<<"initialTimeString{"<<initialTimeString<<"}"<<std::endl; int tempTendingTo; if(oc.getSafeBool("rlwc")) { // Update time string to catch night or day becoming currentTimeString = net->makeTimeString(net->getCurrentTimeStep()); if(getCity()=="cambiano") { // Real Life simulation envtemp update // Month depending analysis if(extractMonth(initialTimeString) < 3 || extractMonth(initialTimeString) > 11) { // December, January or February if(net->isNight(currentTimeString)) tempTendingTo = 0; else tempTendingTo = 5; } else if(extractMonth(initialTimeString)<6) { // March, April or May if(net->isNight(currentTimeString)) tempTendingTo = 10; else tempTendingTo = 15; } else if(extractMonth(initialTimeString)<9) { // June, July or August if(net->isNight(currentTimeString)) tempTendingTo = 15; else tempTendingTo = 20; } else { // September, October or November if(net->isNight(currentTimeString)) tempTendingTo = 5; else tempTendingTo = 10; } // Real Life simulation envhum update if(rand()%10==0) { rand()%2==0? setCurrentEnvHum(getCurrentEnvHum() + ((float)rand()) / RAND_MAX) : setCurrentEnvHum(getCurrentEnvHum() - ((float)rand()) / RAND_MAX); } } else if(getCity()=="munchen") { // Real Life simulation envtemp update // Month depending analysis if((extractMonth(initialTimeString)<3)|| extractMonth(initialTimeString)>11) { // December, January or February if(net->isNight(currentTimeString)) tempTendingTo = 0; else tempTendingTo = 5; } else if(extractMonth(initialTimeString)<6) { // March, April or May if(net->isNight(currentTimeString)) tempTendingTo = 10; else tempTendingTo = 15; } else if(extractMonth(initialTimeString)<9) { // June, July or August if(net->isNight(currentTimeString)) tempTendingTo = 15; else tempTendingTo = 20; } else { // September, October or November if(net->isNight(currentTimeString)) tempTendingTo = 5; else tempTendingTo = 10; } // Real Life simulation envhum update if(rand() % 10 == 0) { (rand() % 2 == 0) ? setCurrentEnvHum(getCurrentEnvHum() + ((float)rand()) / RAND_MAX) : setCurrentEnvHum(getCurrentEnvHum() - ((float)rand()) / RAND_MAX); } } // Envtemp update if(rand() % 10 == 0) { if(rand() % 2 == 0) { // Adding if(getCurrentEnvTemp() > tempTendingTo) { rand() % 3 == 0 ? setCurrentEnvTemp(getCurrentEnvTemp() + ((float)rand()) / RAND_MAX) : setCurrentEnvTemp(getCurrentEnvTemp() - ((float)rand()) / RAND_MAX); } else { rand() % 2 == 0 ? setCurrentEnvTemp(getCurrentEnvTemp() + ((float)rand()) / RAND_MAX) : setCurrentEnvTemp(getCurrentEnvTemp() - ((float)rand()) / RAND_MAX); } } else { // Substracting if(getCurrentEnvTemp() > tempTendingTo) { rand() % 2 == 0 ? setCurrentEnvTemp(getCurrentEnvTemp() + ((float)rand()) / RAND_MAX) : setCurrentEnvTemp(getCurrentEnvTemp() - ((float)rand()) / RAND_MAX); } else { rand() % 3 == 0 ? setCurrentEnvTemp(getCurrentEnvTemp() - ((float)rand()) / RAND_MAX) : setCurrentEnvTemp(getCurrentEnvTemp() + ((float)rand()) / RAND_MAX); } } } } else if((oc.getSafeBool("rwc") || (oc.getSafeBool("rlwc") && (getCity() == "unknown")))) { tag: // Random envtemp update if(rand() % 10 == 0) { (rand() % 2 == 0) ? setCurrentEnvTemp(getCurrentEnvTemp() + ((float)rand())/RAND_MAX) : setCurrentEnvTemp(getCurrentEnvTemp() - ((float)rand())/RAND_MAX); } // Random envhum update if(rand()%10==0) { (rand()%2==0)? setCurrentEnvHum(getCurrentEnvHum()+((float)rand())/RAND_MAX) : setCurrentEnvHum(getCurrentEnvHum()-((float)rand())/RAND_MAX); } } // else weather is constant }