45 #ifdef CHECK_MEMORY_LEAKS
47 #endif // CHECK_MEMORY_LEAKS
56 FXMutex MSRoute::myDictMutex(
true);
65 const bool isPermanent,
const RGBColor*
const c,
66 const std::vector<SUMOVehicleParameter::Stop>& stops)
67 :
Named(id), myEdges(edges), myAmPermanent(isPermanent),
68 myReferenceCounter(isPermanent ? 1 : 0),
69 myColor(c), myStops(stops) {}
113 FXMutexLock f(myDictMutex);
124 FXMutexLock f(myDictMutex);
137 FXMutexLock f(myDictMutex);
140 myDistDict[id] = std::make_pair(routeDist, permanent);
150 FXMutexLock f(myDictMutex);
152 RouteDict::iterator it =
myDict.find(
id);
154 RouteDistDict::iterator it2 =
myDistDict.find(
id);
155 if (it2 ==
myDistDict.end() || it2->second.first->getOverallProb() == 0) {
158 return it2->second.first->get(rng);
167 FXMutexLock f(myDictMutex);
169 RouteDistDict::iterator it2 =
myDistDict.find(
id);
173 return it2->second.first;
180 FXMutexLock f(myDictMutex);
183 delete i->second.first;
186 for (RouteDict::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
196 FXMutexLock f(myDictMutex);
198 RouteDistDict::iterator it =
myDistDict.find(
id);
199 if (it !=
myDistDict.end() && !it->second.second) {
200 const std::vector<const MSRoute*>& routes = it->second.first->getVals();
201 for (std::vector<const MSRoute*>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
204 delete it->second.first;
213 FXMutexLock f(myDictMutex);
216 for (RouteDict::const_iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
217 into.push_back((*i).first);
220 into.push_back((*i).first);
228 ConstMSEdgeVector::const_iterator i =
myEdges.begin();
232 for (; i !=
myEdges.end(); ++i) {
238 if (upTo || i !=
myEdges.end() - 1) {
248 MSEdgeVector::const_iterator i = edgelist.begin();
249 for (; i != edgelist.end(); ++i) {
267 FXMutexLock f(myDictMutex);
269 for (RouteDict::iterator it =
myDict.begin(); it !=
myDict.end(); ++it) {
286 const MSEdge* fromEdge,
const MSEdge* toEdge,
bool includeInternal)
const {
287 ConstMSEdgeVector::const_iterator it = std::find(
myEdges.begin(),
myEdges.end(), fromEdge);
292 ConstMSEdgeVector::const_iterator it2 = std::find(it + 1,
myEdges.end(), toEdge);
294 if (fromEdge == toEdge) {
295 if (fromPos <= toPos) {
296 return toPos - fromPos;
297 }
else if (it2 ==
myEdges.end()) {
309 bool isFirstIteration =
true;
312 if (fromEdge == toEdge) {
314 if (fromPos <= toPos) {
315 return toPos - fromPos;
320 }
else if (fromEdge > toEdge) {
324 for (; it !=
end(); ++it) {
325 if (it == toEdge && !isFirstIteration) {
329 distance += (*it)->getLength();
330 #ifdef HAVE_INTERNAL_LANES
331 if (includeInternal) {
333 const MSEdge*
internal = (*it)->getInternalFollowingEdge(*(it + 1));
342 isFirstIteration =
false;
357 const std::vector<SUMOVehicleParameter::Stop>&
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
std::map< std::string, const MSRoute * > RouteDict
Definition of the dictionary container.
int writeEdgeIDs(OutputDevice &os, const MSEdge *const from, const MSEdge *const upTo=0) const
Output the edge ids up to but not including the id of the given edge.
const MSEdge * getLastEdge() const
returns the destination edge
std::vector< const MSEdge * > ConstMSEdgeVector
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
#define UNUSED_PARAMETER(x)
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
static void insertIDs(std::vector< std::string > &into)
A road/street connecting two junctions.
SUMOReal getLength() const
return the length of the edge
static void clear()
Clears the dictionary (delete all known routes, too)
SUMOReal getDistanceBetween(SUMOReal fromPos, SUMOReal toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...
static RouteDistDict myDistDict
The dictionary container.
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
int size() const
Returns the number of edges to pass.
MSRoute(const std::string &id, const ConstMSEdgeVector &edges, const bool isPermanent, const RGBColor *const c, const std::vector< SUMOVehicleParameter::Stop > &stops)
Constructor.
ConstMSEdgeVector::const_iterator MSRouteIterator
bool contains(const MSEdge *const edge) const
std::map< std::string, std::pair< RandomDistributor< const MSRoute * > *, bool > > RouteDistDict
Definition of the dictionary container.
virtual ~MSRoute()
Destructor.
void addReference() const
increments the reference counter for the route
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Base class for objects which have an id.
std::string myID
The name of the object.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
ConstMSEdgeVector myEdges
The list of edges to pass.
int myReferenceCounter
Information by how many vehicles the route is used.
Static storage of an output device and its base (abstract) implementation.
const RGBColor & getColor() const
Returns the color.
bool closeTag()
Closes the most recently opened tag.
const MSEdge * operator[](int index) const
std::vector< MSEdge * > MSEdgeVector
void release() const
deletes the route if there are no further references to it
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
static RouteDict myDict
The dictionary container.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
const RGBColor *const myColor
The color.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
bool containsAnyOf(const MSEdgeVector &edgelist) const