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();
232 for (
int i = firstIndex; i < lastIndex; i++) {
233 os <<
myEdges[i]->getID() <<
' ';
234 if (withInternal && i + 1 < lastIndex) {
238 while (edge !=
nullptr && edge->
isInternal()) {
239 os << edge->
getID() <<
' ';
245 return internal + lastIndex - firstIndex;
251 MSEdgeVector::const_iterator i = edgelist.begin();
252 for (; i != edgelist.end(); ++i) {
270 FXMutexLock f(myDictMutex);
272 for (RouteDict::iterator it =
myDict.begin(); it !=
myDict.end(); ++it) {
278 if (r->myColor !=
nullptr) {
281 for (
auto stop : r->getStops()) {
287 if (item.second.first->getVals().size() > 0) {
290 std::ostringstream oss;
292 for (
const auto& route : item.second.first->getVals()) {
296 oss << route->getID();
310 FXMutexLock f(myDictMutex);
319 const MSLane* fromLane,
const MSLane* toLane,
int routePosition)
const {
321 assert(fromPos >= 0. && fromPos <= fromLane->getLength());
322 assert(toPos >= 0. && toPos <= toLane->getLength());
323 assert(routePosition >= 0 && routePosition < (
int)
myEdges.size());
324 assert(routePosition == 0 || !
myEdges.front()->isInternal());
327 if (fromEdge == toEdge && fromPos <= toPos) {
328 return toPos - fromPos;
333 double minDist = std::numeric_limits<double>::max();
335 const MSEdge*
const succ = via.second ==
nullptr ? via.first : via.second;
336 assert(succ !=
nullptr);
339 if (d != std::numeric_limits<double>::max() && fromLane->
getLength() - fromPos + d < minDist) {
340 minDist = fromLane->
getLength() - fromPos + d;
347 assert(pred !=
nullptr);
350 return d == std::numeric_limits<double>::max() ? d : toPos + d;
352 ConstMSEdgeVector::const_iterator fromIt = std::find(
myEdges.begin() + routePosition,
myEdges.end(), fromEdge);
355 return std::numeric_limits<double>::max();
357 ConstMSEdgeVector::const_iterator toIt = std::find(fromIt + 1,
myEdges.end(), toEdge);
360 return std::numeric_limits<double>::max();
369 bool isFirstIteration =
true;
370 double distance = -fromPos;
372 if (fromEdge == toEdge) {
374 if (fromPos <= toPos) {
375 return toPos - fromPos;
378 return std::numeric_limits<double>::max();
380 }
else if (fromEdge > toEdge) {
382 return std::numeric_limits<double>::max();
384 for (; it !=
end(); ++it) {
385 if (it == toEdge && !isFirstIteration) {
389 distance += (*it)->getLength();
390 if (includeInternal && (it + 1) !=
end()) {
392 distance += (*it)->getInternalFollowingLengthTo(*(it + 1),
SVC_IGNORING);
395 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 & 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)
Represents a generic random distribution.