SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
activitygen_main.cpp
Go to the documentation of this file.
1
/****************************************************************************/
11
// Main object of the ActivityGen application
12
/****************************************************************************/
13
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
14
// Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
15
// activitygen module
16
// Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
17
/****************************************************************************/
18
//
19
// This file is part of SUMO.
20
// SUMO is free software: you can redistribute it and/or modify
21
// it under the terms of the GNU General Public License as published by
22
// the Free Software Foundation, either version 3 of the License, or
23
// (at your option) any later version.
24
//
25
/****************************************************************************/
26
27
28
// ===========================================================================
29
// included modules
30
// ===========================================================================
31
#ifdef _MSC_VER
32
#include <
windows_config.h
>
33
#else
34
#include <
config.h
>
35
#endif
36
37
#ifdef HAVE_VERSION_H
38
#include <version.h>
39
#endif
40
41
#include <iostream>
42
#include <exception>
43
#include <typeinfo>
44
#include <
router/RONet.h
>
45
#include <
router/ROLoader.h
>
46
#include <
router/RONetHandler.h
>
47
#include <
duarouter/RODUAEdgeBuilder.h
>
48
#include <
utils/options/OptionsIO.h
>
49
#include <
utils/common/MsgHandler.h
>
50
#include <
utils/common/ToString.h
>
51
#include <
utils/xml/XMLSubSys.h
>
52
#include <
utils/common/FileHelpers.h
>
53
#include <
utils/common/RandHelper.h
>
54
#include <
utils/common/SystemFrame.h
>
55
#include <
utils/options/OptionsCont.h
>
56
#include <
utils/iodevices/OutputDevice.h
>
57
//ActivityGen
58
#include "
AGFrame.h
"
59
#include "
AGActivityGen.h
"
60
#include "
city/AGTime.h
"
61
62
#ifdef CHECK_MEMORY_LEAKS
63
#include <
foreign/nvwa/debug_new.h
>
64
#endif // CHECK_MEMORY_LEAKS
65
66
67
// ===========================================================================
68
// method definitions
69
// ===========================================================================
70
72
void
loadNet
(
RONet
& toFill,
ROAbstractEdgeBuilder
& eb) {
73
OptionsCont
& oc =
OptionsCont::getOptions
();
74
std::string file = oc.
getString
(
"net-file"
);
75
if
(file ==
""
) {
76
throw
ProcessError
(
"Missing definition of network to load!"
);
77
}
78
if
(!
FileHelpers::exists
(file)) {
79
throw
ProcessError
(
"The network file '"
+ file
80
+
"' could not be found."
);
81
}
82
PROGRESS_BEGIN_MESSAGE
(
"Loading net"
);
83
RONetHandler
handler(toFill, eb);
84
handler.
setFileName
(file);
85
if
(!
XMLSubSys::runParser
(handler, file)) {
86
PROGRESS_FAILED_MESSAGE
();
87
throw
ProcessError
();
88
}
else
{
89
PROGRESS_DONE_MESSAGE
();
90
}
91
}
92
93
/****************************************************************************/
94
95
int
main
(
int
argc,
char
* argv[]) {
96
int
ret = 0;
97
OptionsCont
& oc =
OptionsCont::getOptions
();
98
RONet
* net = 0;
99
try
{
100
// Initialise subsystems and process options
101
XMLSubSys::init
();
102
AGFrame::fillOptions
();
103
OptionsIO::getOptions
(
true
, argc, argv);
104
if
(oc.
processMetaOptions
(argc < 2)) {
105
SystemFrame::close
();
106
return
0;
107
}
108
XMLSubSys::setValidation
(oc.
getBool
(
"xml-validation"
));
109
MsgHandler::initOutputOptions
();
110
RandHelper::initRandGlobal
();
111
112
// Load network
113
net =
new
RONet
();
114
RODUAEdgeBuilder
builder(oc.
getBool
(
"weights.expand"
), oc.
getBool
(
"weights.interpolate"
));
115
loadNet
(*net, builder);
116
WRITE_MESSAGE
(
"Loaded "
+
toString
(net->
getEdgeNo
()) +
" edges."
);
117
if
(oc.
getBool
(
"debug"
)) {
118
WRITE_MESSAGE
(
"\n\t ---- begin AcitivtyGen ----\n"
);
119
}
120
121
std::string statFile = oc.
getString
(
"stat-file"
);
122
std::string routeFile = oc.
getString
(
"output-file"
);
123
AGTime
duration(1, 0, 0);
124
AGTime
begin(0);
125
AGTime
end(0);
126
if
(oc.
isSet
(
"duration-d"
)) {
127
duration.
setDay
(oc.
getInt
(
"duration-d"
));
128
}
129
if
(oc.
isSet
(
"begin"
)) {
130
begin.
addSeconds
(oc.
getInt
(
"begin"
) % 86400);
131
}
132
if
(oc.
isSet
(
"end"
)) {
133
end.
addSeconds
(oc.
getInt
(
"end"
) % 86400);
134
}
135
AGActivityGen
actiGen(statFile, routeFile, net);
136
actiGen.
importInfoCity
();
137
actiGen.
makeActivityTrips
(duration.
getDay
(), begin.
getTime
(), end.
getTime
());
138
139
if
(oc.
getBool
(
"debug"
)) {
140
WRITE_MESSAGE
(
"\n\t ---- end of ActivityGen ----\n"
);
141
}
142
ret = 0;
143
}
catch
(
const
ProcessError
& e) {
144
if
(std::string(e.what()) != std::string(
"Process Error"
) && std::string(e.what()) != std::string(
""
)) {
145
WRITE_ERROR
(e.what());
146
}
147
MsgHandler::getErrorInstance
()->
inform
(
"Quitting (on error)."
,
false
);
148
ret = 1;
149
#ifndef _DEBUG
150
}
catch
(
const
std::exception& e) {
151
if
(std::string(e.what()) != std::string(
""
)) {
152
WRITE_ERROR
(e.what());
153
}
154
MsgHandler::getErrorInstance
()->
inform
(
"Quitting (on error)."
,
false
);
155
ret = 1;
156
}
catch
(...) {
157
MsgHandler::getErrorInstance
()->
inform
(
"Quitting (on unknown error)."
,
false
);
158
ret = 1;
159
#endif
160
}
161
SystemFrame::close
();
162
if
(ret == 0) {
163
std::cout <<
"Success."
<< std::endl;
164
}
165
return
ret;
166
}
167
168
/****************************************************************************/
169
home
gladk
tmp
05
sumo-0.17.1~dfsg
src
activitygen
activitygen_main.cpp
Generated on Sun Jun 16 2013 07:06:56 for SUMO - Simulation of Urban MObility by
1.8.1.2