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
sumo_main.cpp
Go to the documentation of this file.
1
/****************************************************************************/
11
// Main for SUMO
12
/****************************************************************************/
13
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
14
// Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
15
/****************************************************************************/
16
//
17
// This file is part of SUMO.
18
// SUMO is free software: you can redistribute it and/or modify
19
// it under the terms of the GNU General Public License as published by
20
// the Free Software Foundation, either version 3 of the License, or
21
// (at your option) any later version.
22
//
23
/****************************************************************************/
24
25
26
// ===========================================================================
27
// included modules
28
// ===========================================================================
29
#ifdef _MSC_VER
30
#include <
windows_config.h
>
31
#else
32
#include <
config.h
>
33
#endif
34
35
#ifdef HAVE_VERSION_H
36
#include <version.h>
37
#endif
38
39
#include <ctime>
40
#include <string>
41
#include <iostream>
42
#include <
microsim/MSNet.h
>
43
#include <
microsim/MSRoute.h
>
44
#include <
microsim/MSVehicleControl.h
>
45
#include <
netload/NLBuilder.h
>
46
#include <
netload/NLHandler.h
>
47
#include <
netload/NLTriggerBuilder.h
>
48
#include <
netload/NLEdgeControlBuilder.h
>
49
#include <
netload/NLJunctionControlBuilder.h
>
50
#include <
netload/NLDetectorBuilder.h
>
51
#include <
utils/options/OptionsCont.h
>
52
#include <
utils/options/OptionsIO.h
>
53
#include <
utils/common/MsgHandler.h
>
54
#include <
utils/common/SystemFrame.h
>
55
#include <
utils/common/UtilExceptions.h
>
56
#include <
utils/common/FileHelpers.h
>
57
#include <
utils/common/StringTokenizer.h
>
58
#include <
utils/common/ToString.h
>
59
#include <
utils/xml/XMLSubSys.h
>
60
#include <
microsim/MSFrame.h
>
61
#include <
microsim/output/MSDetectorControl.h
>
62
#include <
utils/iodevices/OutputDevice.h
>
63
64
#ifdef HAVE_INTERNAL
65
#include <mesosim/MEVehicleControl.h>
66
#endif
67
68
#ifndef NO_TRACI
69
#include <
traci-server/TraCIServer.h
>
70
#endif
71
72
73
#ifdef CHECK_MEMORY_LEAKS
74
#include <
foreign/nvwa/debug_new.h
>
75
#endif
76
77
// ===========================================================================
78
// functions
79
// ===========================================================================
80
/* -------------------------------------------------------------------------
81
* data processing methods
82
* ----------------------------------------------------------------------- */
86
MSNet
*
87
load
(
OptionsCont
& oc) {
88
MSFrame::setMSGlobals
(oc);
89
MSVehicleControl
* vc = 0;
90
#ifdef HAVE_INTERNAL
91
if
(
MSGlobals::gUseMesoSim
) {
92
vc =
new
MEVehicleControl();
93
}
else
{
94
#endif
95
vc =
new
MSVehicleControl
();
96
#ifdef HAVE_INTERNAL
97
}
98
#endif
99
MSNet
* net =
new
MSNet
(vc,
new
MSEventControl
(),
100
new
MSEventControl
(),
new
MSEventControl
());
101
#ifndef NO_TRACI
102
// need to init TraCI-Server before loading routes to catch VEHICLE_STATE_BUILT
103
TraCIServer::openSocket
(std::map<int, TraCIServer::CmdExecutor>());
104
#endif
105
106
NLEdgeControlBuilder
eb;
107
NLDetectorBuilder
db(*net);
108
NLJunctionControlBuilder
jb(*net, db);
109
NLTriggerBuilder
tb;
110
NLHandler
handler(
""
, *net, db, tb, eb, jb);
111
tb.
setHandler
(&handler);
112
NLBuilder
builder(oc, *net, eb, jb, db, handler);
113
if
(!builder.
build
()) {
114
delete
net;
115
throw
ProcessError
();
116
}
117
return
net;
118
}
119
120
121
/* -------------------------------------------------------------------------
122
* main
123
* ----------------------------------------------------------------------- */
124
int
125
main
(
int
argc,
char
** argv) {
126
OptionsCont
& oc =
OptionsCont::getOptions
();
127
// give some application descriptions
128
oc.
setApplicationDescription
(
"A microscopic road traffic simulation."
);
129
oc.
setApplicationName
(
"sumo"
,
"SUMO sumo Version "
+ (std::string)
VERSION_STRING
);
130
int
ret = 0;
131
MSNet
* net = 0;
132
try
{
133
// initialise subsystems
134
XMLSubSys::init
();
135
MSFrame::fillOptions
();
136
OptionsIO::getOptions
(
true
, argc, argv);
137
if
(oc.
processMetaOptions
(argc < 2)) {
138
SystemFrame::close
();
139
return
0;
140
}
141
XMLSubSys::setValidation
(oc.
getString
(
"xml-validation"
), oc.
getString
(
"xml-validation.net"
));
142
MsgHandler::initOutputOptions
();
143
if
(!
MSFrame::checkOptions
()) {
144
throw
ProcessError
();
145
}
146
RandHelper::initRandGlobal
();
147
RandHelper::initRandGlobal
(&
MSVehicleControl::myVehicleParamsRNG
);
148
// load the net
149
net =
load
(oc);
150
if
(net != 0) {
151
ret = net->
simulate
(
string2time
(oc.
getString
(
"begin"
)),
string2time
(oc.
getString
(
"end"
)));
152
}
153
}
catch
(
const
ProcessError
& e) {
154
if
(std::string(e.what()) != std::string(
"Process Error"
) && std::string(e.what()) != std::string(
""
)) {
155
WRITE_ERROR
(e.what());
156
}
157
MsgHandler::getErrorInstance
()->
inform
(
"Quitting (on error)."
,
false
);
158
ret = 1;
159
#ifndef _DEBUG
160
}
catch
(
const
std::exception& e) {
161
if
(std::string(e.what()) != std::string(
""
)) {
162
WRITE_ERROR
(e.what());
163
}
164
MsgHandler::getErrorInstance
()->
inform
(
"Quitting (on error)."
,
false
);
165
ret = 1;
166
}
catch
(...) {
167
MsgHandler::getErrorInstance
()->
inform
(
"Quitting (on unknown error)."
,
false
);
168
ret = 1;
169
#endif
170
}
171
delete
net;
172
SystemFrame::close
();
173
return
ret;
174
}
175
176
177
/****************************************************************************/
tmp
buildd
sumo-0.21.0+dfsg
src
sumo_main.cpp
Generated on Thu Nov 20 2014 19:49:59 for SUMO - Simulation of Urban MObility by
1.8.1.2