42FXMutex MSRoute::myDictMutex(
true);
51 const bool isPermanent,
const RGBColor*
const c,
52 const std::vector<SUMOVehicleParameter::Stop>& stops,
55 Named(id), myEdges(edges), myAmPermanent(isPermanent),
56 myReferenceCounter(isPermanent ? 1 : 0),
63 myReplacedTime(replacedTime),
64 myReplacedIndex(replacedIndex)
109 FXMutexLock f(myDictMutex);
120 FXMutexLock f(myDictMutex);
133 FXMutexLock f(myDictMutex);
136 myDistDict[id] = std::make_pair(routeDist, permanent);
146 FXMutexLock f(myDictMutex);
148 RouteDict::iterator it =
myDict.find(
id);
150 RouteDistDict::iterator it2 =
myDistDict.find(
id);
151 if (it2 ==
myDistDict.end() || it2->second.first->getOverallProb() == 0) {
154 return it2->second.first->get(rng);
163 FXMutexLock f(myDictMutex);
172 FXMutexLock f(myDictMutex);
174 RouteDistDict::iterator it2 =
myDistDict.find(
id);
178 return it2->second.first;
185 FXMutexLock f(myDictMutex);
188 delete i->second.first;
191 for (RouteDict::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
201 FXMutexLock f(myDictMutex);
203 RouteDistDict::iterator it =
myDistDict.find(
id);
204 if (it !=
myDistDict.end() && !it->second.second) {
205 const std::vector<const MSRoute*>& routes = it->second.first->getVals();
206 for (std::vector<const MSRoute*>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
209 delete it->second.first;
218 FXMutexLock f(myDictMutex);
221 for (RouteDict::const_iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
222 into.push_back((*i).first);
225 into.push_back((*i).first);
234 lastIndex = (int)
myEdges.size();
237 for (
int i = firstIndex; i < lastIndex; i++) {
238 os <<
myEdges[i]->getID() <<
' ';
239 if (withInternal && i + 1 < lastIndex) {
241 const MSEdge* edge =
myEdges[i]->getInternalFollowingEdge(next, svc);
243 while (edge !=
nullptr && edge->
isInternal()) {
244 os << edge->
getID() <<
' ';
250 return internal + lastIndex - firstIndex;
256 MSEdgeVector::const_iterator i = edgelist.begin();
257 for (; i != edgelist.end(); ++i) {
275 FXMutexLock f(myDictMutex);
277 for (RouteDict::iterator it =
myDict.begin(); it !=
myDict.end(); ++it) {
278 const MSRoute* r = (*it).second;
292 if (item.second.first->getVals().size() > 0) {
305 FXMutexLock f(myDictMutex);
307 for (
auto item :
myDict) {
317 const MSEdge* fromEdge,
const MSEdge* toEdge,
bool includeInternal,
int routePosition)
const {
319 if (routePosition < 0 || routePosition >= (
int)
myEdges.size()) {
324 if (fromEdge == toEdge) {
325 if (fromPos <= toPos) {
326 return toPos - fromPos;
329 return fromEdge->
getLength() - fromPos + toPos;
333 if (fromEdge ==
myEdges.front()) {
351 ConstMSEdgeVector::const_iterator it = std::find(
myEdges.begin() + routePosition,
myEdges.end(), fromEdge);
354 return std::numeric_limits<double>::max();
356 ConstMSEdgeVector::const_iterator it2 = std::find(it + 1,
myEdges.end(), toEdge);
358 if (fromEdge == toEdge) {
359 if (fromPos <= toPos) {
360 return toPos - fromPos;
361 }
else if (it2 ==
myEdges.end()) {
363 return std::numeric_limits<double>::max();
373 bool isFirstIteration =
true;
374 double distance = -fromPos;
376 if (fromEdge == toEdge) {
378 if (fromPos <= toPos) {
379 return toPos - fromPos;
382 return std::numeric_limits<double>::max();
384 }
else if (fromEdge > toEdge) {
386 return std::numeric_limits<double>::max();
388 for (; it !=
end(); ++it) {
389 if (it == toEdge && !isFirstIteration) {
393 distance += (*it)->getLength();
394 if (includeInternal && (it + 1) !=
end()) {
396 distance += (*it)->getInternalFollowingLengthTo(*(it + 1),
SVC_IGNORING);
399 isFirstIteration =
false;
414const std::vector<SUMOVehicleParameter::Stop>&
std::vector< const MSEdge * > ConstMSEdgeVector
std::vector< MSEdge * > MSEdgeVector
ConstMSEdgeVector::const_iterator MSRouteIterator
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ 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_COLOR
A color information.
@ 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 MSJunction * getToJunction() const
double getLength() const
return the length of the edge
bool isInternal() const
return whether this edge is an internal edge
const MSEdgeVector & getPredecessors() const
const MSEdge * getInternalFollowingEdge(const MSEdge *followerAfterInternal, SUMOVehicleClass vClass) 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 writeEdgeIDs(OutputDevice &os, int firstIndex=0, int lastIndex=-1, bool withInternal=false, SUMOVehicleClass svc=SVC_IGNORING) const
Output the edge ids up to but not including the id of the given edge.
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
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
const RGBColor & getColor() const
Returns the color.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
const bool myAmPermanent
whether the route may be deleted after the last vehicle abandoned it
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
MSRoute(const std::string &id, const ConstMSEdgeVector &edges, const bool isPermanent, const RGBColor *const c, const std::vector< SUMOVehicleParameter::Stop > &stops, SUMOTime replacedTime=-1, int replacedIndex=0)
Constructor.
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.
const std::string & getID() const
Returns the id.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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)