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             OutputDevice::closeAll();
00108             SystemFrame::close();
00109             return 0;
00110         }
00111 
00112         // Load network
00113         net = new RONet();
00114         RODUAEdgeBuilder builder(oc.getBool("weights.expand"), oc.getBool("weights.interpolate"));
00115         loadNet(*net, builder);
00116         WRITE_MESSAGE("Loaded " + toString(net->getEdgeNo()) + " edges.");
00117         if (oc.getBool("debug")) {
00118             WRITE_MESSAGE("\n\t ---- begin AcitivtyGen ----\n");
00119         }
00120 
00121         std::string statFile = oc.getString("stat-file");
00122         std::string routeFile = oc.getString("output-file");
00123         AGTime duration(1, 0, 0);
00124         AGTime begin(0);
00125         AGTime end(0);
00126         if (oc.isSet("duration-d")) {
00127             duration.setDay(oc.getInt("duration-d"));
00128         }
00129         if (oc.isSet("begin")) {
00130             begin.addSeconds(oc.getInt("begin") % 86400);
00131         }
00132         if (oc.isSet("end")) {
00133             end.addSeconds(oc.getInt("end") % 86400);
00134         }
00135         AGActivityGen actiGen(statFile, routeFile, net);
00136         actiGen.importInfoCity();
00137         actiGen.makeActivityTrips(duration.getDay(), begin.getTime(), end.getTime());
00138 
00139         if (oc.getBool("debug")) {
00140             WRITE_MESSAGE("\n\t ---- end of ActivityGen ----\n");
00141         }
00142         ret = 0;
00143     } catch (ProcessError& pe) {
00144         if (std::string(pe.what()) != std::string("Process Error") && std::string(pe.what()) != std::string("")) {
00145             WRITE_ERROR(pe.what());
00146         }
00147         MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
00148         ret = 1;
00149 #ifndef _DEBUG
00150     } catch (...) {
00151         MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
00152         ret = 1;
00153 #endif
00154     }
00155     OutputDevice::closeAll();
00156     SystemFrame::close();
00157     if (ret == 0) {
00158         std::cout << "Success." << std::endl;
00159     }
00160     return ret;
00161 }
00162 
00163 /****************************************************************************/
00164 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines