SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RORDLoader_TripDefs.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // The basic class for loading trip definitions
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 #include <string>
37 #include <utils/common/ToString.h>
38 #include "RORoute.h"
39 #include "RONet.h"
40 #include "RORouteDef.h"
41 #include "RORDLoader_TripDefs.h"
42 #include "ROVehicle.h"
44 
45 #ifdef CHECK_MEMORY_LEAKS
46 #include <foreign/nvwa/debug_new.h>
47 #endif // CHECK_MEMORY_LEAKS
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
54  SUMOTime begin, SUMOTime end,
55  bool emptyDestinationsAllowed, bool withTaz,
56  const std::string& fileName)
57  : ROTypedXMLRoutesLoader(net, begin, end, fileName),
58  myEmptyDestinationsAllowed(emptyDestinationsAllowed),
59  myWithTaz(withTaz), myCurrentVehicleType(0),
60  myParameter(0) {}
61 
62 
64 
65 
66 void
68  const SUMOSAXAttributes& attrs) {
69  // check whether a trip definition shall be parsed
70  if (element == SUMO_TAG_TRIP) {
71  bool ok = true;
72  // get the vehicle id, the edges, the speed and position and
73  // the departure time and other information
74  std::string id = getVehicleID(attrs);
75  myCurrentDepart = attrs.getSUMOTimeReporting(SUMO_ATTR_DEPART, id.c_str(), ok);
76  if (myWithTaz) {
77  myBeginEdge = getEdge(attrs, "origin", SUMO_ATTR_FROM_TAZ, id, false);
78  myEndEdge = getEdge(attrs, "destination", SUMO_ATTR_TO_TAZ, id, myEmptyDestinationsAllowed);
79  } else {
80  myBeginEdge = getEdge(attrs, "origin", SUMO_ATTR_FROM, id, false);
81  myEndEdge = getEdge(attrs, "destination", SUMO_ATTR_TO, id, myEmptyDestinationsAllowed);
82  }
84  myParameter->id = id;
85  // recheck attributes
86  if (!ok) {
87  return;
88  }
89  if (myCurrentDepart < 0) {
90  WRITE_ERROR("The departure time must be positive.");
91  return;
92  }
93  }
94  // check whether a vehicle type shall be parsed
95  if (element == SUMO_TAG_VTYPE) {
97  } else if (myCurrentVehicleType != 0) {
99  }
100 }
101 
102 
103 std::string
105  // try to get the id, do not report an error if not given or empty...
106  bool ok = true;
107  std::string id = attrs.getOptStringReporting(SUMO_ATTR_ID, 0, ok, "", false);
108  // get a valid vehicle id
109  if (id == "") {
110  return myIdSupplier.getNext();
111  } else {
112  return id;
113  }
114 }
115 
116 
117 ROEdge*
119  const std::string& purpose,
120  SumoXMLAttr which, const std::string& vid,
121  bool emptyAllowed) {
122  UNUSED_PARAMETER(purpose);
123  bool ok = true;
124  std::string id = attrs.getStringReporting(which, 0, ok, !emptyAllowed);
125  if (which == SUMO_ATTR_FROM_TAZ) {
126  id += "-source";
127  }
128  if (which == SUMO_ATTR_TO_TAZ) {
129  id += "-sink";
130  }
131  ROEdge* e = myNet.getEdge(id);
132  if (e == 0 && !emptyAllowed) {
133  WRITE_ERROR("The edge '" + id + "' is not known.\n Vehicle id='" + vid + "'.");
134  }
135  return e;
136 }
137 
138 
139 void
141  if (element == SUMO_TAG_TRIP && !MsgHandler::getErrorInstance()->wasInformed()) {
142  if (myCurrentDepart < myBegin || myCurrentDepart >= myEnd) {
143  delete myParameter;
144  return;
145  }
147  RORouteDef* route = new RORouteDef(myParameter->id, 0, true);
148  std::vector<const ROEdge*> edges;
149  edges.push_back(myBeginEdge);
150  edges.push_back(myEndEdge);
151  route->addLoadedAlternative(new RORoute(myParameter->id, 0, 1, edges, col));
153  // check whether any errors occured
154  if (MsgHandler::getErrorInstance()->wasInformed()) {
155  return;
156  }
157  if (myNet.addRouteDef(route)) {
158  myNextRouteRead = true;
159  // build the vehicle
160  ROVehicle* veh = new ROVehicle(*myParameter, route, type);
162  } else {
163  WRITE_ERROR("The vehicle '" + myParameter->id + "' occurs at least twice.");
164  delete route;
165  }
166  delete myParameter;
167  myParameter = 0;
168  }
169  if (element == SUMO_TAG_VTYPE) {
173  }
174 }
175 
176 
177 /****************************************************************************/
178