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),
62 myReplacedTime(replacedTime),
63 myReplacedIndex(replacedIndex)
100 FXMutexLock f(myDictMutex);
111 FXMutexLock f(myDictMutex);
124 FXMutexLock f(myDictMutex);
127 myDistDict[id] = std::make_pair(routeDist, permanent);
137 FXMutexLock f(myDictMutex);
139 RouteDict::iterator it =
myDict.find(
id);
141 RouteDistDict::iterator it2 =
myDistDict.find(
id);
142 if (it2 ==
myDistDict.end() || it2->second.first->getOverallProb() == 0) {
145 return it2->second.first->get(rng);
154 FXMutexLock f(myDictMutex);
163 FXMutexLock f(myDictMutex);
165 RouteDistDict::iterator it2 =
myDistDict.find(
id);
169 return it2->second.first;
176 FXMutexLock f(myDictMutex);
179 delete i->second.first;
189 FXMutexLock f(myDictMutex);
191 RouteDistDict::iterator it =
myDistDict.find(
id);
192 if (it !=
myDistDict.end() && !it->second.second) {
197 delete it->second.first;
206 FXMutexLock f(myDictMutex);
209 for (RouteDict::const_iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
210 into.push_back((*i).first);
213 into.push_back((*i).first);
222 lastIndex = (int)
myEdges.size();
225 for (
int i = firstIndex; i < lastIndex; i++) {
226 os <<
myEdges[i]->getID() <<
' ';
227 if (withInternal && i + 1 < lastIndex) {
231 while (edge !=
nullptr && edge->
isInternal()) {
232 os << edge->
getID() <<
' ';
238 return internal + lastIndex - firstIndex;
244 MSEdgeVector::const_iterator i = edgelist.begin();
245 for (; i != edgelist.end(); ++i) {
263 FXMutexLock f(myDictMutex);
265 for (RouteDict::iterator it =
myDict.begin(); it !=
myDict.end(); ++it) {
271 if (r->myColor !=
nullptr) {
274 for (
auto stop : r->getStops()) {
280 if (item.second.first->getVals().size() > 0) {
283 std::ostringstream oss;
285 for (
const auto& route : item.second.first->getVals()) {
289 oss << route->getID();
303 FXMutexLock f(myDictMutex);
312 const MSLane* fromLane,
const MSLane* toLane,
int routePosition)
const {
314 assert(fromPos >= 0. && fromPos <= fromLane->getLength());
315 assert(toPos >= 0. && toPos <= toLane->getLength());
316 assert(routePosition >= 0 && routePosition < (
int)
myEdges.size());
317 assert(routePosition == 0 || !
myEdges.front()->isInternal());
320 if (fromEdge == toEdge && fromPos <= toPos) {
321 return toPos - fromPos;
326 double minDist = std::numeric_limits<double>::max();
328 const MSEdge*
const succ = via.second ==
nullptr ? via.first : via.second;
329 assert(succ !=
nullptr);
332 if (d != std::numeric_limits<double>::max() && fromLane->
getLength() - fromPos + d < minDist) {
333 minDist = fromLane->
getLength() - fromPos + d;
340 assert(pred !=
nullptr);
343 return d == std::numeric_limits<double>::max() ? d : toPos + d;
345 ConstMSEdgeVector::const_iterator fromIt = std::find(
myEdges.begin() + routePosition,
myEdges.end(), fromEdge);
348 return std::numeric_limits<double>::max();
350 ConstMSEdgeVector::const_iterator toIt = std::find(fromIt + 1,
myEdges.end(), toEdge);
353 return std::numeric_limits<double>::max();
362 bool isFirstIteration =
true;
363 double distance = -fromPos;
365 if (fromEdge == toEdge) {
367 if (fromPos <= toPos) {
368 return toPos - fromPos;
371 return std::numeric_limits<double>::max();
373 }
else if (fromEdge > toEdge) {
375 return std::numeric_limits<double>::max();
377 for (; it !=
end(); ++it) {
378 if (it == toEdge && !isFirstIteration) {
382 distance += (*it)->getLength();
383 if (includeInternal && (it + 1) !=
end()) {
385 distance += (*it)->getInternalFollowingLengthTo(*(it + 1),
SVC_IGNORING);
388 isFirstIteration =
false;
403const std::vector<SUMOVehicleParameter::Stop>&
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
@ 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.
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.
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.
static bool hasRoute(const std::string &id)
returns whether a route with the given id exists
std::map< std::string, ConstMSRoutePtr > RouteDict
Definition of the dictionary container.
virtual ~MSRoute()
Destructor.
void checkRemoval() const
removes the route from the internal dict if it is not marked as permanent
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.
static RandomDistributor< ConstMSRoutePtr > * distDictionary(const std::string &id)
Returns the named route distribution.
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
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.
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.