|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Main object of the ActivityGen application 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 // activitygen module 00012 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/) 00013 /****************************************************************************/ 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; either version 2 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 00021 00022 00023 // =========================================================================== 00024 // included modules 00025 // =========================================================================== 00026 #ifdef _MSC_VER 00027 #include <windows_config.h> 00028 #else 00029 #include <config.h> 00030 #endif 00031 00032 #ifdef HAVE_VERSION_H 00033 #include <version.h> 00034 #endif 00035 00036 #include <iostream> 00037 #include <exception> 00038 #include <typeinfo> 00039 #include <router/RONet.h> 00040 #include <router/ROLoader.h> 00041 #include <router/RONetHandler.h> 00042 #include <duarouter/RODUAEdgeBuilder.h> 00043 #include <utils/options/OptionsIO.h> 00044 #include <utils/common/MsgHandler.h> 00045 #include <utils/common/ToString.h> 00046 #include <utils/xml/XMLSubSys.h> 00047 #include <utils/common/FileHelpers.h> 00048 #include <utils/common/RandHelper.h> 00049 #include <utils/common/SystemFrame.h> 00050 #include <utils/options/OptionsCont.h> 00051 #include <utils/iodevices/OutputDevice.h> 00052 //ActivityGen 00053 #include "AGFrame.h" 00054 #include "AGActivityGen.h" 00055 #include "city/AGTime.h" 00056 00057 #ifdef CHECK_MEMORY_LEAKS 00058 #include <foreign/nvwa/debug_new.h> 00059 #endif // CHECK_MEMORY_LEAKS 00060 00061 00062 // =========================================================================== 00063 // method definitions 00064 // =========================================================================== 00065 00067 void loadNet(RONet& toFill, ROAbstractEdgeBuilder& eb) throw(ProcessError) { 00068 OptionsCont& oc = OptionsCont::getOptions(); 00069 std::string file = oc.getString("net-file"); 00070 if (file == "") { 00071 throw ProcessError("Missing definition of network to load!"); 00072 } 00073 if (!FileHelpers::exists(file)) { 00074 throw ProcessError("The network file '" + file 00075 + "' could not be found."); 00076 } 00077 PROGRESS_BEGIN_MESSAGE("Loading net"); 00078 RONetHandler handler(toFill, eb); 00079 handler.setFileName(file); 00080 if (!XMLSubSys::runParser(handler, file)) { 00081 PROGRESS_FAILED_MESSAGE(); 00082 throw ProcessError(); 00083 } else { 00084 PROGRESS_DONE_MESSAGE(); 00085 } 00086 } 00087 00088 /****************************************************************************/ 00089 00090 int main(int argc, char* argv[]) { 00091 int ret = 0; 00092 OptionsCont& oc = OptionsCont::getOptions(); 00093 RONet* net = 0; 00094 try { 00095 // Initialise subsystems and process options 00096 XMLSubSys::init(false); 00097 AGFrame::fillOptions(); 00098 OptionsIO::getOptions(true, argc, argv); 00099 MsgHandler::initOutputOptions(); 00100 RandHelper::initRandGlobal(); 00101 if (oc.processMetaOptions(argc < 2)) { 00102 SystemFrame::close(); 00103 return 0; 00104 } 00105 00106 // Load network 00107 net = new RONet(); 00108 RODUAEdgeBuilder builder(oc.getBool("weights.expand"), oc.getBool("weights.interpolate")); 00109 loadNet(*net, builder); 00110 WRITE_MESSAGE("Loaded " + toString(net->getEdgeNo()) + " edges."); 00111 if (oc.getBool("debug")) { 00112 WRITE_MESSAGE("\n\t ---- begin AcitivtyGen ----\n"); 00113 } 00114 00115 std::string statFile = oc.getString("stat-file"); 00116 std::string routeFile = oc.getString("output-file"); 00117 AGTime duration(1,0,0); 00118 AGTime begin(0); 00119 AGTime end(0); 00120 if (oc.isSet("duration-d")) { 00121 duration.setDay(oc.getInt("duration-d")); 00122 } 00123 if (oc.isSet("begin")) { 00124 begin.addSeconds(oc.getInt("begin") % 86400); 00125 } 00126 if (oc.isSet("end")) { 00127 end.addSeconds(oc.getInt("end") % 86400); 00128 } 00129 AGActivityGen actiGen(statFile, routeFile, net); 00130 actiGen.importInfoCity(); 00131 actiGen.makeActivityTrips(duration.getDay(), begin.getTime(), end.getTime()); 00132 00133 if (oc.getBool("debug")) { 00134 WRITE_MESSAGE("\n\t ---- end of ActivityGen ----\n"); 00135 } 00136 ret = 0; 00137 } catch (ProcessError& pe) { 00138 if (std::string(pe.what())!=std::string("Process Error") && std::string(pe.what())!=std::string("")) { 00139 WRITE_ERROR(pe.what()); 00140 } 00141 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); 00142 ret = 1; 00143 #ifndef _DEBUG 00144 } catch (...) { 00145 MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false); 00146 ret = 1; 00147 #endif 00148 } 00149 OutputDevice::closeAll(); 00150 SystemFrame::close(); 00151 if (ret==0) { 00152 std::cout << "Success." << std::endl; 00153 } 00154 return ret; 00155 } 00156 00157 /****************************************************************************/ 00158