SUMO - Simulation of Urban MObility

activitygen_main.cpp

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