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.sourceforge.net/
14
// Copyright (C) 2001-2012 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_MESOSIM
65
#include <mesosim/MEVehicleControl.h>
66
#endif
67
68
#ifdef CHECK_MEMORY_LEAKS
69
#include <
foreign/nvwa/debug_new.h
>
70
#endif
71
72
// ===========================================================================
73
// functions
74
// ===========================================================================
75
/* -------------------------------------------------------------------------
76
* data processing methods
77
* ----------------------------------------------------------------------- */
81
MSNet
*
82
load
(
OptionsCont
& oc) {
83
MSFrame::setMSGlobals
(oc);
84
MSVehicleControl
* vc = 0;
85
#ifdef HAVE_MESOSIM
86
if
(
MSGlobals::gUseMesoSim
) {
87
vc =
new
MEVehicleControl();
88
}
else
{
89
#endif
90
vc =
new
MSVehicleControl
();
91
#ifdef HAVE_MESOSIM
92
}
93
#endif
94
MSNet
* net =
new
MSNet
(vc,
new
MSEventControl
(),
95
new
MSEventControl
(),
new
MSEventControl
());
96
NLEdgeControlBuilder
eb;
97
NLDetectorBuilder
db(*net);
98
NLJunctionControlBuilder
jb(*net, db);
99
NLTriggerBuilder
tb;
100
NLHandler
handler(
""
, *net, db, tb, eb, jb);
101
tb.
setHandler
(&handler);
102
NLBuilder
builder(oc, *net, eb, jb, db, handler);
103
if
(!builder.
build
()) {
104
delete
net;
105
throw
ProcessError
();
106
}
107
return
net;
108
}
109
110
111
/* -------------------------------------------------------------------------
112
* main
113
* ----------------------------------------------------------------------- */
114
int
115
main
(
int
argc,
char
** argv) {
116
OptionsCont
& oc =
OptionsCont::getOptions
();
117
// give some application descriptions
118
oc.
setApplicationDescription
(
"A microscopic road traffic simulation."
);
119
oc.
setApplicationName
(
"sumo"
,
"SUMO sumo Version "
+ (std::string)
VERSION_STRING
);
120
int
ret = 0;
121
MSNet
* net = 0;
122
try
{
123
// initialise subsystems
124
XMLSubSys::init
(
false
);
125
MSFrame::fillOptions
();
126
OptionsIO::getOptions
(
true
, argc, argv);
127
if
(oc.
processMetaOptions
(argc < 2)) {
128
OutputDevice::closeAll
();
129
SystemFrame::close
();
130
return
0;
131
}
132
MsgHandler::initOutputOptions
();
133
if
(!
MSFrame::checkOptions
()) {
134
throw
ProcessError
();
135
}
136
RandHelper::initRandGlobal
();
137
// load the net
138
net =
load
(oc);
139
if
(net != 0) {
140
ret = net->
simulate
(
string2time
(oc.
getString
(
"begin"
)),
string2time
(oc.
getString
(
"end"
)));
141
}
142
}
catch
(
ProcessError
& e) {
143
if
(std::string(e.what()) != std::string(
"Process Error"
) && std::string(e.what()) != std::string(
""
)) {
144
WRITE_ERROR
(e.what());
145
}
146
MsgHandler::getErrorInstance
()->
inform
(
"Quitting (on error)."
,
false
);
147
ret = 1;
148
#ifndef _DEBUG
149
}
catch
(...) {
150
MsgHandler::getErrorInstance
()->
inform
(
"Quitting (on unknown error)."
,
false
);
151
ret = 1;
152
#endif
153
}
154
delete
net;
155
OutputDevice::closeAll
();
156
SystemFrame::close
();
157
return
ret;
158
}
159
160
161
162
/****************************************************************************/
163
build
buildd
sumo-0.15.0~dfsg
src
sumo_main.cpp
Generated on Wed Jul 18 2012 22:58:36 for SUMO - Simulation of Urban MObility by
1.8.1.1