Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others. 4 : // activitygen module 5 : // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/) 6 : // This program and the accompanying materials are made available under the 7 : // terms of the Eclipse Public License 2.0 which is available at 8 : // https://www.eclipse.org/legal/epl-2.0/ 9 : // This Source Code may also be made available under the following Secondary 10 : // Licenses when the conditions for such availability set forth in the Eclipse 11 : // Public License 2.0 are satisfied: GNU General Public License, version 2 12 : // or later which is available at 13 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 14 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 15 : /****************************************************************************/ 16 : /// @file activitygen_main.cpp 17 : /// @author Piotr Woznica 18 : /// @author Walter Bamberger 19 : /// @author Daniel Krajzewicz 20 : /// @author Jakob Erdmann 21 : /// @author Michael Behrisch 22 : /// @date Tue, 20 Jul 2010 23 : /// 24 : // Main object of the ActivityGen application 25 : /****************************************************************************/ 26 : #include <config.h> 27 : 28 : #ifdef HAVE_VERSION_H 29 : #include <version.h> 30 : #endif 31 : 32 : #include <iostream> 33 : #include <exception> 34 : #include <typeinfo> 35 : #include <router/RONet.h> 36 : #include <router/ROLoader.h> 37 : #include <router/RONetHandler.h> 38 : #include <utils/options/OptionsIO.h> 39 : #include <utils/common/MsgHandler.h> 40 : #include <utils/common/ToString.h> 41 : #include <utils/xml/XMLSubSys.h> 42 : #include <utils/common/FileHelpers.h> 43 : #include <utils/common/RandHelper.h> 44 : #include <utils/common/SystemFrame.h> 45 : #include <utils/options/OptionsCont.h> 46 : #include <utils/iodevices/OutputDevice.h> 47 : #include <utils/iodevices/OutputDevice.h> 48 : //ActivityGen 49 : #include "AGFrame.h" 50 : #include "AGActivityGen.h" 51 : #include "city/AGTime.h" 52 : 53 : 54 : // =========================================================================== 55 : // method definitions 56 : // =========================================================================== 57 : 58 : /// Loads the network 59 : void 60 10 : loadNet(RONet& toFill, ROAbstractEdgeBuilder& eb) { 61 10 : OptionsCont& oc = OptionsCont::getOptions(); 62 20 : std::string file = oc.getString("net-file"); 63 10 : if (file == "") { 64 0 : throw ProcessError(TL("Missing definition of network to load!")); 65 : } 66 20 : if (!FileHelpers::isReadable(file)) { 67 0 : throw ProcessError(TLF("The network file '%' could not be accessed.", file)); 68 : } 69 20 : PROGRESS_BEGIN_MESSAGE(TL("Loading net")); 70 10 : RONetHandler handler(toFill, eb, true, 0, 0); 71 10 : handler.setFileName(file); 72 10 : if (!XMLSubSys::runParser(handler, file, true)) { 73 0 : PROGRESS_FAILED_MESSAGE(); 74 0 : throw ProcessError(); 75 : } else { 76 10 : PROGRESS_DONE_MESSAGE(); 77 : } 78 10 : if (!deprecatedVehicleClassesSeen.empty()) { 79 0 : WRITE_WARNINGF(TL("Deprecated vehicle classes '%' in input network."), toString(deprecatedVehicleClassesSeen)); 80 : deprecatedVehicleClassesSeen.clear(); 81 : } 82 20 : } 83 : 84 : 85 : int 86 14 : main(int argc, char* argv[]) { 87 14 : OptionsCont& oc = OptionsCont::getOptions(); 88 14 : oc.setApplicationDescription( 89 14 : TL("Generates trips of persons throughout a day for the microscopic, multi-modal traffic simulation SUMO.")); 90 28 : oc.setApplicationName("activitygen", "Eclipse SUMO activitygen Version " VERSION_STRING); 91 14 : oc.addCopyrightNotice("Copyright (C) 2010-2012 Technische Universitaet Muenchen"); 92 : int ret = 0; 93 : RONet* net = nullptr; 94 : try { 95 : // Initialise subsystems and process options 96 14 : XMLSubSys::init(); 97 14 : AGFrame::fillOptions(); 98 14 : OptionsIO::setArgs(argc, argv); 99 14 : OptionsIO::getOptions(); 100 14 : if (oc.processMetaOptions(argc < 2)) { 101 4 : SystemFrame::close(); 102 4 : return 0; 103 : } 104 30 : XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"), "never"); 105 10 : MsgHandler::initOutputOptions(); 106 10 : RandHelper::initRandGlobal(); 107 10 : SystemFrame::checkOptions(oc); 108 : 109 : // Load network 110 10 : net = new RONet(); 111 : AGStreet::Builder builder; 112 10 : loadNet(*net, builder); 113 20 : WRITE_MESSAGEF(TL("Loaded % edges."), toString(net->getEdgeNumber())); 114 20 : if (oc.getBool("debug")) { 115 0 : WRITE_MESSAGE("\n\t ---- begin ActivityGen ----\n"); 116 : } 117 : 118 10 : std::string statFile = oc.getString("stat-file"); 119 20 : OutputDevice::createDeviceByOption("output-file", "routes", "routes_file.xsd"); 120 10 : AGTime duration(oc.getInt("duration-d"), 0, 0); 121 10 : AGTime begin(oc.getInt("begin") % 86400); 122 10 : AGTime end(oc.getInt("end") % 86400); 123 42 : AGActivityGen actiGen(statFile, OutputDevice::getDevice(oc.getString("output-file")), net); 124 10 : actiGen.importInfoCity(); 125 9 : actiGen.makeActivityTrips(duration.getDay(), begin.getTime(), end.getTime()); 126 : 127 16 : if (oc.getBool("debug")) { 128 0 : WRITE_MESSAGE("\n\t ---- end of ActivityGen ----\n"); 129 : } 130 : ret = 0; 131 12 : } catch (const ProcessError& e) { 132 5 : if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) { 133 2 : WRITE_ERROR(e.what()); 134 : } 135 2 : MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); 136 : ret = 1; 137 : #ifndef _DEBUG 138 2 : } catch (const std::exception& e) { 139 0 : if (std::string(e.what()) != std::string("")) { 140 0 : WRITE_ERROR(e.what()); 141 : } 142 0 : MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); 143 : ret = 1; 144 0 : } catch (...) { 145 0 : MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false); 146 : ret = 1; 147 : #endif 148 0 : } 149 10 : SystemFrame::close(); 150 : if (ret == 0) { 151 : std::cout << "Success." << std::endl; 152 : } 153 : return ret; 154 : } 155 : 156 : 157 : /****************************************************************************/