42 FXMutex MSRoute::myDictMutex(
true);
51 const bool isPermanent,
const RGBColor*
const c,
52 const std::vector<SUMOVehicleParameter::Stop>& stops) :
53 Named(id), myEdges(edges), myAmPermanent(isPermanent),
54 myReferenceCounter(isPermanent ? 1 : 0),
104 FXMutexLock f(myDictMutex);
115 FXMutexLock f(myDictMutex);
128 FXMutexLock f(myDictMutex);
131 myDistDict[id] = std::make_pair(routeDist, permanent);
141 FXMutexLock f(myDictMutex);
143 RouteDict::iterator it =
myDict.find(
id);
145 RouteDistDict::iterator it2 =
myDistDict.find(
id);
146 if (it2 ==
myDistDict.end() || it2->second.first->getOverallProb() == 0) {
149 return it2->second.first->get(rng);
158 FXMutexLock f(myDictMutex);
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();
229 if (from !=
nullptr) {
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) {
275 if (item.second.first->getVals().size() > 0) {
288 FXMutexLock f(myDictMutex);
290 for (
auto item :
myDict) {
300 const MSEdge* fromEdge,
const MSEdge* toEdge,
bool includeInternal,
int routePosition)
const {
302 if (routePosition < 0 || routePosition >= (
int)
myEdges.size()) {
307 if (fromEdge == toEdge) {
308 if (fromPos <= toPos) {
309 return toPos - fromPos;
312 return fromEdge->
getLength() - fromPos + toPos;
316 if (fromEdge ==
myEdges.front()) {
334 ConstMSEdgeVector::const_iterator it = std::find(
myEdges.begin() + routePosition,
myEdges.end(), fromEdge);
337 return std::numeric_limits<double>::max();
339 ConstMSEdgeVector::const_iterator it2 = std::find(it + 1,
myEdges.end(), toEdge);
341 if (fromEdge == toEdge) {
342 if (fromPos <= toPos) {
343 return toPos - fromPos;
344 }
else if (it2 ==
myEdges.end()) {
346 return std::numeric_limits<double>::max();
356 bool isFirstIteration =
true;
357 double distance = -fromPos;
359 if (fromEdge == toEdge) {
361 if (fromPos <= toPos) {
362 return toPos - fromPos;
365 return std::numeric_limits<double>::max();
367 }
else if (fromEdge > toEdge) {
369 return std::numeric_limits<double>::max();
371 for (; it !=
end(); ++it) {
372 if (it == toEdge && !isFirstIteration) {
376 distance += (*it)->getLength();
377 if (includeInternal && (it + 1) !=
end()) {
378 distance += (*it)->getInternalFollowingLengthTo(*(it + 1));
381 isFirstIteration =
false;
396 const std::vector<SUMOVehicleParameter::Stop>&
std::vector< const MSEdge * > ConstMSEdgeVector
std::vector< MSEdge * > MSEdgeVector
ConstMSEdgeVector::const_iterator MSRouteIterator
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_STATE
The state of a link.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A road/street connecting two junctions.
const MSEdgeVector & getPredecessors() const
double getLength() const
return the length of the edge
bool isInternal() const
return whether this edge is an internal edge
const MSJunction * getToJunction() const
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
static void dict_clearState()
Decrement all route references before quick-loading state.
void addReference() const
increments the reference counter for the route
int size() const
Returns the number of edges to pass.
static RouteDistDict myDistDict
The dictionary container.
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
const RGBColor *const myColor
The color.
static RouteDict myDict
The dictionary container.
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
int myReferenceCounter
Information by how many vehicles the route is used.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
static bool hasRoute(const std::string &id)
returns whether a route with the given id exists
virtual ~MSRoute()
Destructor.
const MSEdge * operator[](int index) const
bool contains(const MSEdge *const edge) const
void release() const
deletes the route if there are no further references to it
const MSEdge * getLastEdge() const
returns the destination edge
MSRoute(const std::string &id, const ConstMSEdgeVector &edges, const bool isPermanent, const RGBColor *const c, const std::vector< SUMOVehicleParameter::Stop > &stops)
Constructor.
ConstMSEdgeVector myEdges
The list of edges to pass.
std::map< std::string, const MSRoute * > RouteDict
Definition of the dictionary container.
std::map< std::string, std::pair< RandomDistributor< const MSRoute * > *, bool > > RouteDistDict
Definition of the dictionary container.
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
static void insertIDs(std::vector< std::string > &into)
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true, int routePosition=0) const
Compute the distance between 2 given edges on this route, including the length of internal lanes....
bool containsAnyOf(const MSEdgeVector &edgelist) const
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 RGBColor & getColor() const
Returns the color.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
static void clear()
Clears the dictionary (delete all known routes, too)
Base class for objects which have an id.
std::string myID
The name of the object.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)