#include <config.h>
#ifdef HAVE_VERSION_H
#include <version.h>
#endif
#include <iostream>
#include <exception>
#include <typeinfo>
#include <router/RONet.h>
#include <router/ROLoader.h>
#include <router/RONetHandler.h>
#include <utils/options/OptionsIO.h>
#include <utils/common/MsgHandler.h>
#include <utils/common/ToString.h>
#include <utils/xml/XMLSubSys.h>
#include <utils/common/FileHelpers.h>
#include <utils/common/RandHelper.h>
#include <utils/common/SystemFrame.h>
#include <utils/options/OptionsCont.h>
#include <utils/iodevices/OutputDevice.h>
#include <utils/iodevices/OutputDevice.h>
#include "AGFrame.h"
#include "AGActivityGen.h"
#include "city/AGTime.h"
void
loadNet(RONet& toFill, ROAbstractEdgeBuilder& eb) {
OptionsCont& oc = OptionsCont::getOptions();
std::string file = oc.getString("net-file");
if (file == "") {
throw ProcessError(TL("Missing definition of network to load!"));
}
if (!FileHelpers::isReadable(file)) {
throw ProcessError(TLF("The network file '%' could not be accessed.", file));
}
PROGRESS_BEGIN_MESSAGE(TL("Loading net"));
RONetHandler handler(toFill, eb, true, 0, 0, 0);
handler.setFileName(file);
if (!XMLSubSys::runParser(handler, file, true)) {
PROGRESS_FAILED_MESSAGE();
throw ProcessError();
} else {
PROGRESS_DONE_MESSAGE();
}
if (!deprecatedVehicleClassesSeen.empty()) {
WRITE_WARNINGF(TL("Deprecated vehicle classes '%' in input network."), toString(deprecatedVehicleClassesSeen));
deprecatedVehicleClassesSeen.clear();
}
}
int
main(int argc, char* argv[]) {
OptionsCont& oc = OptionsCont::getOptions();
oc.setApplicationDescription(
TL("Generates trips of persons throughout a day for the microscopic, multi-modal traffic simulation SUMO."));
oc.setApplicationName("activitygen", "Eclipse SUMO activitygen " VERSION_STRING);
oc.addCopyrightNotice("Copyright (C) 2010-2012 Technische Universitaet Muenchen");
int ret = 0;
RONet* net = nullptr;
try {
XMLSubSys::init();
AGFrame::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"), "never");
MsgHandler::initOutputOptions();
RandHelper::initRandGlobal();
SystemFrame::checkOptions(oc);
net = new RONet();
AGStreet::Builder builder;
loadNet(*net, builder);
WRITE_MESSAGEF(TL("Loaded % edges."), toString(net->getEdgeNumber()));
if (oc.getBool("debug")) {
WRITE_MESSAGE("\n\t ---- begin ActivityGen ----\n");
}
std::string statFile = oc.getString("stat-file");
OutputDevice::createDeviceByOption("output-file", "routes", "routes_file.xsd");
AGTime duration(oc.getInt("duration-d"), 0, 0);
AGTime begin(oc.getInt("begin") % 86400);
AGTime end(oc.getInt("end") % 86400);
AGActivityGen actiGen(statFile, OutputDevice::getDevice(oc.getString("output-file")), net);
actiGen.importInfoCity();
actiGen.makeActivityTrips(duration.getDay(), begin.getTime(), end.getTime());
if (oc.getBool("debug")) {
WRITE_MESSAGE("\n\t ---- end of ActivityGen ----\n");
}
ret = 0;
} 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
}
SystemFrame::close();
if (ret == 0) {
std::cout << "Success." << std::endl;
}
return ret;
}