42FXMutex MSRoute::myDictMutex(
true);
51 const bool isPermanent,
const RGBColor*
const c,
55 Named(id), myEdges(edges), myAmPermanent(isPermanent),
62 myReplacedTime(replacedTime),
63 myReplacedIndex(replacedIndex)
107 FXMutexLock f(myDictMutex);
118 FXMutexLock f(myDictMutex);
131 FXMutexLock f(myDictMutex);
134 myDistDict[id] = std::make_pair(routeDist, permanent);
144 FXMutexLock f(myDictMutex);
146 RouteDict::iterator it =
myDict.find(
id);
148 RouteDistDict::iterator it2 =
myDistDict.find(
id);
149 if (it2 ==
myDistDict.end() || it2->second.first->getOverallProb() == 0) {
152 return it2->second.first->get(rng);
161 FXMutexLock f(myDictMutex);
170 FXMutexLock f(myDictMutex);
172 RouteDistDict::iterator it2 =
myDistDict.find(
id);
176 return it2->second.first;
183 FXMutexLock f(myDictMutex);
186 delete i->second.first;
196 FXMutexLock f(myDictMutex);
198 RouteDistDict::iterator it =
myDistDict.find(
id);
199 if (it !=
myDistDict.end() && !it->second.second) {
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);
229 lastIndex = (int)
myEdges.size();
234 for (
int i = firstIndex; i < lastIndex; i++) {
237 if (withInternal && i + 1 < lastIndex) {
241 while (edge !=
nullptr && edge->
isInternal()) {
242 ids += 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) {
283 if (r->myColor !=
nullptr) {
286 for (
auto stop : r->getStops()) {
292 if (item.second.first->getVals().size() > 0) {
295 std::ostringstream oss;
297 for (
const auto& route : item.second.first->getVals()) {
301 oss << route->getID();
315 FXMutexLock f(myDictMutex);
324 const MSLane* fromLane,
const MSLane* toLane,
int routePosition)
const {
326 assert(fromPos >= 0. && fromPos <= fromLane->getLength());
327 assert(toPos >= 0. && toPos <= toLane->getLength());
328 assert(routePosition >= 0 && routePosition < (
int)
myEdges.size());
329 assert(routePosition == 0 || !
myEdges.front()->isInternal());
332 if (fromEdge == toEdge && fromPos <= toPos) {
333 return toPos - fromPos;
338 double minDist = std::numeric_limits<double>::max();
340 const MSEdge*
const succ = via.second ==
nullptr ? via.first : via.second;
341 assert(succ !=
nullptr);
344 if (d != std::numeric_limits<double>::max() && fromLane->
getLength() - fromPos + d < minDist) {
345 minDist = fromLane->
getLength() - fromPos + d;
352 assert(pred !=
nullptr);
355 return d == std::numeric_limits<double>::max() ? d : toPos + d;
357 ConstMSEdgeVector::const_iterator fromIt = std::find(
myEdges.begin() + routePosition,
myEdges.end(), fromEdge);
360 return std::numeric_limits<double>::max();
362 ConstMSEdgeVector::const_iterator toIt = std::find(fromIt + 1,
myEdges.end(), toEdge);
365 return std::numeric_limits<double>::max();
374 bool isFirstIteration =
true;
375 double distance = -fromPos;
377 if (fromEdge == toEdge) {
379 if (fromPos <= toPos) {
380 return toPos - fromPos;
383 return std::numeric_limits<double>::max();
385 }
else if (fromEdge > toEdge) {
387 return std::numeric_limits<double>::max();
389 for (; it !=
end(); ++it) {
390 if (it == toEdge && !isFirstIteration) {
394 distance += (*it)->getLength();
395 if (includeInternal && (it + 1) !=
end()) {
397 distance += (*it)->getInternalFollowingLengthTo(*(it + 1),
SVC_IGNORING);
400 isFirstIteration =
false;
std::vector< const MSEdge * > ConstMSEdgeVector
ConstMSEdgeVector::const_iterator MSRouteIterator
std::vector< MSEdge * > MSEdgeVector
std::shared_ptr< const MSRoute > ConstMSRoutePtr
std::shared_ptr< const MSRoute > ConstMSRoutePtr
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
std::vector< SUMOVehicleParameter::Stop > StopParVector
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
@ SUMO_TAG_ROUTE
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.
A road/street connecting two junctions.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
const MSConstEdgePairVector & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING, bool ignoreTransientPermissions=false) const
Returns the following edges with internal vias, restricted by vClass.
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
Representation of a lane in the micro simulation.
double getLength() const
Returns the lane's length.
MSEdge & getEdge() const
Returns the lane's edge.
static void dict_clearState()
Decrement all route references before quick-loading state.
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.
StopParVector myStops
List of the stops on the parsed route.
static RouteDict myDict
The dictionary container.
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.
static bool hasRoute(const std::string &id)
returns whether a route with the given id exists
void checkRemoval(bool force=false) const
removes the route from the internal dict if it is not marked as permanent
std::map< std::string, ConstMSRoutePtr > RouteDict
Definition of the dictionary container.
virtual ~MSRoute()
Destructor.
const MSEdge * operator[](int index) const
bool contains(const MSEdge *const edge) const
const MSEdge * getLastEdge() const
returns the destination edge
ConstMSEdgeVector myEdges
The list of edges to pass.
static void insertIDs(std::vector< std::string > &into)
bool containsAnyOf(const MSEdgeVector &edgelist) const
std::map< std::string, std::pair< RandomDistributor< ConstMSRoutePtr > *, bool > > RouteDistDict
Definition of the dictionary container.
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
const RGBColor & getColor() const
Returns the color.
MSRoute(const std::string &id, const ConstMSEdgeVector &edges, const bool isPermanent, const RGBColor *const c, const StopParVector &stops, SUMOTime replacedTime=-1, int replacedIndex=0)
Constructor.
static RandomDistributor< ConstMSRoutePtr > * distDictionary(const std::string &id)
Returns the named route distribution.
const MSEdge * getFirstEdge() const
returns the origin edge
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
double getDistanceBetween(double fromPos, double toPos, const MSLane *fromLane, const MSLane *toLane, int routePosition=0) const
Compute the distance between 2 given edges on this route, optionally including the length of internal...
const bool myAmPermanent
whether the route may be deleted after the last vehicle abandoned it
const StopParVector & getStops() const
Returns the stops.
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.
const std::string & getID() const
Returns the id.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
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)
Represents a generic random distribution.