SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NIImporter_Vissim.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // -------------------
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 
34 #include <string>
35 #include <fstream>
40 #include <netbuild/NBNetBuilder.h>
41 #include "NIImporter_Vissim.h"
97 
98 
99 #include "tempstructs/NIVissimTL.h"
111 
112 #include <netbuild/NBEdgeCont.h> // !!! only for debugging purposes
113 
114 #ifdef CHECK_MEMORY_LEAKS
115 #include <foreign/nvwa/debug_new.h>
116 #endif // CHECK_MEMORY_LEAKS
117 
118 
119 // ===========================================================================
120 // method definitions
121 // ===========================================================================
122 // ---------------------------------------------------------------------------
123 // static methods (interface in this case)
124 // ---------------------------------------------------------------------------
125 void
127  if (!oc.isSet("vissim-file")) {
128  return;
129  }
130  // load the visum network
131  NIImporter_Vissim loader(nb, oc.getString("vissim-file"));
132  loader.load(oc);
133 }
134 
135 
136 /* -------------------------------------------------------------------------
137  * NIImporter_Vissim::VissimSingleTypeParser-methods
138  * ----------------------------------------------------------------------- */
140  : myVissimParent(parent) {}
141 
142 
144 
145 
146 std::string
148  std::string tmp;
149  from >> tmp;
150  return StringUtils::to_lower_case(tmp);
151 }
152 
153 
154 
155 std::string
157  const std::string& excl) {
158  std::string myExcl = StringUtils::to_lower_case(excl);
159  std::string tmp = myRead(from);
160  if (tmp == "") {
161  return "DATAEND";
162  }
163  if (tmp != myExcl
164  &&
165  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
166  ) {
167  return "DATAEND";
168  }
169  return StringUtils::to_lower_case(tmp);
170 }
171 
172 
173 std::string
175  const std::vector<std::string>& excl) {
176  std::vector<std::string> myExcl;
177  std::vector<std::string>::const_iterator i;
178  for (i = excl.begin(); i != excl.end(); i++) {
179  std::string mes = StringUtils::to_lower_case(*i);
180  myExcl.push_back(mes);
181  }
182  std::string tmp = myRead(from);
183  if (tmp == "") {
184  return "DATAEND";
185  }
186 
187  bool equals = false;
188  for (i = myExcl.begin(); i != myExcl.end() && !equals; i++) {
189  if ((*i) == tmp) {
190  equals = true;
191  }
192  }
193  if (!equals
194  &&
195  (tmp.substr(0, 2) == "--" || !myVissimParent.admitContinue(tmp))
196  ) {
197  return "DATAEND";
198  }
199  return StringUtils::to_lower_case(tmp);
200 }
201 
202 
203 std::string
205  const std::string& tag) {
206  std::string tmp;
207  if (tag == "") {
208  tmp = myRead(from);
209  } else {
210  tmp = tag;
211  }
212  if (tmp == "beschriftung") {
213  tmp = myRead(from);
214  if (tmp == "keine") {
215  from >> tmp;
216  }
217  tmp = myRead(from);
218  tmp = myRead(from);
219  }
220  return tmp;
221 }
222 
223 
224 Position
226  SUMOReal x, y;
227  from >> x; // type-checking is missing!
228  from >> y; // type-checking is missing!
229  return Position(x, y);
230 }
231 
232 
233 std::vector<int>
235  std::istream& from, const std::string& next) {
236  std::string tmp = readEndSecure(from);
237  std::vector<int> ret;
238  if (tmp == "alle") {
239  ret.push_back(-1);
240  return ret;
241  }
242  while (tmp != "DATAEND" && tmp != next) {
243  ret.push_back(TplConvert::_2int(tmp.c_str()));
244  tmp = readEndSecure(from);
245  }
246  return ret;
247 }
248 
249 
252  std::istream& from) {
253  std::string tag;
254  from >> tag; // "Strecke"
255  int edgeid;
256  from >> edgeid; // type-checking is missing!
257  from >> tag; // "Spuren"
258  std::vector<int> lanes;
259  while (tag != "bei") {
260  tag = readEndSecure(from);
261  if (tag != "bei") {
262  int lane = TplConvert::_2int(tag.c_str());
263  lanes.push_back(lane - 1);
264  }
265  }
266  SUMOReal position;
267  from >> position;
268  std::vector<int> dummy;
269  return NIVissimExtendedEdgePoint(edgeid, lanes, position, dummy);
270 }
271 
272 
273 std::string
275  std::string name;
276  from >> name;
277  if (name[0] == '"') {
278  while (name[name.length() - 1] != '"') {
279  std::string tmp;
280  from >> tmp;
281  name = name + " " + tmp;
282  }
283  name = name.substr(1, name.length() - 2);
284  }
285  return StringUtils::convertUmlaute(name);
286 }
287 
288 
289 void
291  const std::string& name) {
292  std::string tag;
293  while (tag != name) {
294  tag = myRead(from);
295  }
296 }
297 
298 bool
300  const std::string& name) {
301  std::string tag;
302  while (tag != name) {
303  tag = myRead(from);
304  }
305  while (tag != "DATAEND") {
306  tag = readEndSecure(from);
307  }
308  return true;
309 }
310 
311 
312 
313 /* -------------------------------------------------------------------------
314  * NIImporter_Vissim-methods
315  * ----------------------------------------------------------------------- */
317  : myNetBuilder(nb) {
318  UNUSED_PARAMETER(file);
320  buildParsers();
321  myColorMap["blau"] = RGBColor(77, 77, 255, 255);
322  myColorMap["gelb"] = RGBColor::YELLOW;
323  myColorMap["grau"] = RGBColor::GREY;
324  myColorMap["lila"] = RGBColor::MAGENTA;
325  myColorMap["gruen"] = RGBColor::GREEN;
326  myColorMap["rot"] = RGBColor::RED;
327  myColorMap["schwarz"] = RGBColor::BLACK;
328  myColorMap["tuerkis"] = RGBColor::CYAN;
329  myColorMap["weiss"] = RGBColor::WHITE;
330  myColorMap["keine"] = RGBColor::WHITE;
331 }
332 
333 
334 
335 
354  for (ToParserMap::iterator i = myParsers.begin(); i != myParsers.end(); i++) {
355  delete(*i).second;
356  }
357 }
358 
359 
360 void
362  // load file contents
363  // try to open the file
364  std::ifstream strm(options.getString("vissim-file").c_str());
365  if (!strm.good()) {
366  WRITE_ERROR("The vissim-file '" + options.getString("vissim-file") + "' was not found.");
367  return;
368  }
369  if (!readContents(strm)) {
370  return;
371  }
372  postLoadBuild(options.getFloat("vissim.join-distance"));
373 }
374 
375 
376 bool
377 NIImporter_Vissim::admitContinue(const std::string& tag) {
378  ToElemIDMap::const_iterator i = myKnownElements.find(tag);
379  if (i == myKnownElements.end()) {
380  return true;
381  }
382  myLastSecure = tag;
383  return false;
384 }
385 
386 
387 bool
388 NIImporter_Vissim::readContents(std::istream& strm) {
389  // read contents
390  bool ok = true;
391  while (strm.good() && ok) {
392  std::string tag;
393  if (myLastSecure != "") {
394  tag = myLastSecure;
395  } else {
396  strm >> tag;
397  }
398  myLastSecure = "";
399  bool parsed = false;
400  while (!parsed && strm.good() && ok) {
401  ToElemIDMap::iterator i = myKnownElements.find(StringUtils::to_lower_case(tag));
402  if (i != myKnownElements.end()) {
403  ToParserMap::iterator j = myParsers.find((*i).second);
404  if (j != myParsers.end()) {
405  VissimSingleTypeParser* parser = (*j).second;
406  ok = parser->parse(strm);
407  parsed = true;
408  }
409  }
410  if (!parsed) {
411  std::string line;
412  std::streamoff pos;
413  do {
414  pos = strm.tellg();
415  getline(strm, line);
416  } while (strm.good() && (line == "" || line[0] == ' ' || line[0] == '-'));
417  if (!strm.good()) {
418  return true;
419  }
420  strm.seekg(pos);
421  strm >> tag;
422  }
423  }
424  }
425  return ok;
426 }
427 
428 
429 void
431  // close the loading process
435  // build district->connections map
437  // build clusters around nodes
438 // NIVissimNodeDef::buildNodeClusters();
439  // build node clusters around traffic lights
440 // NIVissimTL::buildNodeClusters();
441 
442  // when connections or disturbances are left, build nodes around them
443 
444  // try to assign connection clusters to nodes
445  // only left connections will be processed in
446  // buildConnectionClusters & join
447 //30.4. brauchen wir noch! NIVissimNodeDef::dict_assignConnectionsToNodes();
448 
449  // build clusters of connections with the same direction and a similar position along the streets
451  // check whether further nodes (connection clusters by now) must be added
453 
454  // join clusters when overlapping (different streets are possible)
457 // NIVissimConnectionCluster::joinByDisturbances(offset);
458 
459 // NIVissimConnectionCluster::addTLs(offset);
460 
461  // build nodes from clusters
464 
465 // NIVissimNodeCluster::dict_recheckEdgeChanges();
466 
472  if (OptionsCont::getOptions().getBool("vissim.report-unset-speeds")) {
474  }
479 }
480 
481 
482 void
484  myKnownElements["kennung"] = VE_Kennungszeile;
485  myKnownElements["zufallszahl"] = VE_Startzufallszahl;
486  myKnownElements["simulationsdauer"] = VE_Simdauer;
487  myKnownElements["startuhrzeit"] = VE_Startuhrzeit;
488  myKnownElements["simulationsrate"] = VE_SimRate;
489  myKnownElements["zeitschritt"] = VE_Zeitschrittfaktor;
490  myKnownElements["linksverkehr"] = VE_Linksverkehr;
491  myKnownElements["dynuml"] = VE_DynUml;
493  myKnownElements["gelbverhalten"] = VE_Gelbverhaltendefinition;
496  myKnownElements["richtungsentscheidung"] = VE_Richtungsentscheidungsdefinition;
497  myKnownElements["routenentscheidung"] = VE_Routenentscheidungsdefinition;
498  myKnownElements["vwunschentscheidung"] = VE_VWunschentscheidungsdefinition;
499  myKnownElements["langsamfahrbereich"] = VE_Langsamfahrbereichdefinition;
501  myKnownElements["fahrzeugtyp"] = VE_Fahrzeugtypdefinition;
502  myKnownElements["fahrzeugklasse"] = VE_Fahrzeugklassendefinition;
515  myKnownElements["querverkehrsstoerung"] = VE_Querverkehrsstoerungsdefinition;
518  myKnownElements["signalgeber"] = VE_Signalgeberdefinition;
519  myKnownElements["lsakopplung"] = VE_LSAKopplungdefinition;
527  myKnownElements["querschnittsmessung"] = VE_Querschnittsmessungsdefinition;
528  myKnownElements["stauzaehler"] = VE_Stauzaehlerdefinition;
536  myKnownElements["richtungspfeil"] = VE_Richtungspfeildefinition;
538  myKnownElements["fahrverhalten"] = VE_Fahrverhaltendefinition;
539  myKnownElements["fahrtverlaufdateien"] = VE_Fahrtverlaufdateien;
540  myKnownElements["emission"] = VE_Emission;
542  myKnownElements["streckentyp"] = VE_Streckentypdefinition;
543  myKnownElements["kantensperrung"] = VE_Kantensperrung;
545 
546 
547  myKnownElements["advance"] = VE_DUMMY;
548  myKnownElements["temperatur"] = VE_DUMMY;
549 
550 }
551 
552 
553 
554 void
634 
677 
678 }
679 
680 
681 
682 /****************************************************************************/
683 
static void clearDict()
void readUntil(std::istream &from, const std::string &name)
Reads from the stream until the keywor occurs.
static void dict_BuildDistricts(NBDistrictCont &dc, NBEdgeCont &ec, NBNodeCont &nc)
Builds the districts.
static void dict_buildNBEdgeConnections(NBEdgeCont &ec)
static void joinBySameEdges(SUMOReal offset)
Tries to joind clusters participating within a node This is done by joining clusters which overlap...
static const RGBColor WHITE
Definition: RGBColor.h:194
std::string myRead(std::istream &from)
reads from the stream and returns the lower case version of the read value
static void dict_checkEdges2Join()
static void reportUnsetSpeeds()
Writes edges with unset speeds to the warnings message log instance.
std::string readEndSecure(std::istream &from, const std::string &excl="")
as myRead, but returns &quot;DATAEND&quot; when the current field has ended
~NIImporter_Vissim()
destructor
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static void clearDict()
Importer for networks stored in Vissim format.
VissimSingleTypeParser(NIImporter_Vissim &parent)
Constructor.
virtual bool parse(std::istream &from)=0
Parses a single data type. Returns whether no error occured.
bool readContents(std::istream &strm)
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
static const RGBColor BLACK
Definition: RGBColor.h:195
static void clearDict()
static int getMaxID()
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:36
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
ToParserMap myParsers
Parsers by element id.
static void dict_assignToEdges()
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void insertKnownElements()
adds name-to-id - relationships of known elements into myKnownElements
ToElemIDMap myKnownElements
Map from element names to their numerical representation.
static void setCurrentVirtID(int id)
static const RGBColor GREEN
Definition: RGBColor.h:189
static const RGBColor GREY
Definition: RGBColor.h:196
NIVissimExtendedEdgePoint readExtEdgePointDef(std::istream &from)
static void dict_addDisturbances(NBDistrictCont &dc, NBNodeCont &nc, NBEdgeCont &ec)
static void dict_propagateSpeeds()
void load(const OptionsCont &options)
loads the vissim file
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
NBEdgeCont & getEdgeCont()
Returns the edge container.
Definition: NBNetBuilder.h:154
ColorMap myColorMap
a map from color names to color definitions
static bool dict_SetSignals(NBTrafficLightLogicCont &tlc, NBEdgeCont &ec)
Definition: NIVissimTL.cpp:375
static const RGBColor MAGENTA
Definition: RGBColor.h:193
Position getPosition(std::istream &from)
returns the 2d-position saved as next within the stream
std::string readName(std::istream &from)
Reads the structures name We cannot use the &quot;&lt;&lt;&quot; operator, as names may contain more than one wor...
void postLoadBuild(SUMOReal offset)
static std::string convertUmlaute(std::string str)
Converts german &quot;Umlaute&quot; to their latin-version.
Definition: StringUtils.cpp:78
void buildParsers()
adds id-to-parser - relationships of elements to parse into myParsers
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:201
static void clearDict()
Clears the dictionary.
static void buildConnectionClusters()
Clusters connections of each edge.
static std::string to_lower_case(std::string str)
Transfers the content to lower case.
Definition: StringUtils.cpp:67
static const RGBColor YELLOW
Definition: RGBColor.h:191
static int _2int(const E *const data)
Definition: TplConvert.h:114
static const RGBColor RED
Definition: RGBColor.h:188
static const RGBColor CYAN
Definition: RGBColor.h:192
NIImporter_Vissim(NBNetBuilder &nb, const std::string &file)
constructor
NBNodeCont & getNodeCont()
Returns the node container.
Definition: NBNetBuilder.h:162
Instance responsible for building networks.
Definition: NBNetBuilder.h:113
A storage for options typed value containers)
Definition: OptionsCont.h:108
bool skipOverreading(std::istream &from, const std::string &name="")
Overreads the named parameter (if) given and skips the rest until &quot;DATAEND&quot;.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads network definition from the assigned option and stores it in the given network builder...
NBTrafficLightLogicCont & getTLLogicCont()
Returns the traffic light logics container.
Definition: NBNetBuilder.h:178
static void buildNBNodes(NBNodeCont &nc)
static void clearDict()
Definition: NIVissimTL.cpp:363
#define SUMOReal
Definition: config.h:221
static void dict_SetDisturbances()
NBNetBuilder & myNetBuilder
std::string myLastSecure
NBDistrictCont & getDistrictCont()
Returns the districts container.
Definition: NBNetBuilder.h:186
bool admitContinue(const std::string &tag)
static void dict_buildNBEdges(NBDistrictCont &dc, NBNodeCont &nc, NBEdgeCont &ec, SUMOReal offset)
Builds NBEdges from the VissimEdges within the dictionary.
std::string overrideOptionalLabel(std::istream &from, const std::string &tag="")
overrides the optional label definition; returns the next tag as done by readEndSecure ...
std::vector< int > parseAssignedVehicleTypes(std::istream &from, const std::string &next)
parses a listof vehicle types assigned to the current data field One should remeber, that -1 means &quot;all&quot; vehicle types
static void dict_BuildDistrictNodes(NBDistrictCont &dc, NBNodeCont &nc)
Builds the nodes that belong to a district.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.