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.sourceforge.net/
12 // Copyright (C) 2001-2012 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<char>::_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<char>::_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((SUMOReal) .3, (SUMOReal) 0.3, (SUMOReal) 1);
322  myColorMap["gelb"] = RGBColor(1, 1, 0);
323  myColorMap["grau"] = RGBColor((SUMOReal) .5, (SUMOReal) 0.5, (SUMOReal) .5);
324  myColorMap["lila"] = RGBColor(1, 0, 1);
325  myColorMap["gruen"] = RGBColor(0, 1, 0);
326  myColorMap["rot"] = RGBColor(1, 0, 0);
327  myColorMap["schwarz"] = RGBColor(0, 0, 0);
328  myColorMap["tuerkis"] = RGBColor(0, 1, 1);
329  myColorMap["weiss"] = RGBColor(1, 1, 1);
330  myColorMap["keine"] = RGBColor(1, 1, 1);
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 
473  offset);
474  if (OptionsCont::getOptions().getBool("vissim.report-unset-speeds")) {
476  }
484 
485 }
486 
487 
488 void
490  myKnownElements["kennung"] = VE_Kennungszeile;
491  myKnownElements["zufallszahl"] = VE_Startzufallszahl;
492  myKnownElements["simulationsdauer"] = VE_Simdauer;
493  myKnownElements["startuhrzeit"] = VE_Startuhrzeit;
494  myKnownElements["simulationsrate"] = VE_SimRate;
495  myKnownElements["zeitschritt"] = VE_Zeitschrittfaktor;
496  myKnownElements["linksverkehr"] = VE_Linksverkehr;
497  myKnownElements["dynuml"] = VE_DynUml;
499  myKnownElements["gelbverhalten"] = VE_Gelbverhaltendefinition;
502  myKnownElements["richtungsentscheidung"] = VE_Richtungsentscheidungsdefinition;
503  myKnownElements["routenentscheidung"] = VE_Routenentscheidungsdefinition;
504  myKnownElements["vwunschentscheidung"] = VE_VWunschentscheidungsdefinition;
505  myKnownElements["langsamfahrbereich"] = VE_Langsamfahrbereichdefinition;
507  myKnownElements["fahrzeugtyp"] = VE_Fahrzeugtypdefinition;
508  myKnownElements["fahrzeugklasse"] = VE_Fahrzeugklassendefinition;
521  myKnownElements["querverkehrsstoerung"] = VE_Querverkehrsstoerungsdefinition;
524  myKnownElements["signalgeber"] = VE_Signalgeberdefinition;
525  myKnownElements["lsakopplung"] = VE_LSAKopplungdefinition;
533  myKnownElements["querschnittsmessung"] = VE_Querschnittsmessungsdefinition;
534  myKnownElements["stauzaehler"] = VE_Stauzaehlerdefinition;
542  myKnownElements["richtungspfeil"] = VE_Richtungspfeildefinition;
544  myKnownElements["fahrverhalten"] = VE_Fahrverhaltendefinition;
545  myKnownElements["fahrtverlaufdateien"] = VE_Fahrtverlaufdateien;
546  myKnownElements["emission"] = VE_Emission;
548  myKnownElements["streckentyp"] = VE_Streckentypdefinition;
549  myKnownElements["kantensperrung"] = VE_Kantensperrung;
551 
552 
553  myKnownElements["advance"] = VE_DUMMY;
554  myKnownElements["temperatur"] = VE_DUMMY;
555 
556 }
557 
558 
559 
560 void
640 
683 
684 }
685 
686 
687 
688 /****************************************************************************/
689