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) {
193 delete it->second.first;
202 FXMutexLock f(myDictMutex);
205 for (RouteDict::const_iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
206 into.push_back((*i).first);
209 into.push_back((*i).first);
218 lastIndex = (int)
myEdges.size();
221 for (
int i = firstIndex; i < lastIndex; i++) {
222 os <<
myEdges[i]->getID() <<
' ';
223 if (withInternal && i + 1 < lastIndex) {
225 const MSEdge* edge =
myEdges[i]->getInternalFollowingEdge(next, svc);
227 while (edge !=
nullptr && edge->
isInternal()) {
228 os << edge->
getID() <<
' ';
234 return internal + lastIndex - firstIndex;
240 MSEdgeVector::const_iterator i = edgelist.begin();
241 for (; i != edgelist.end(); ++i) {
259 FXMutexLock f(myDictMutex);
261 for (RouteDict::iterator it =
myDict.begin(); it !=
myDict.end(); ++it) {
267 if (r->myColor !=
nullptr) {
270 for (
auto stop : r->getStops()) {
276 if (item.second.first->getVals().size() > 0) {
279 std::ostringstream oss;
281 for (
const auto& route : item.second.first->getVals()) {
285 oss << route->getID();
299 FXMutexLock f(myDictMutex);
308 const MSEdge* fromEdge,
const MSEdge* toEdge,
bool includeInternal,
int routePosition)
const {
310 if (routePosition < 0 || routePosition >= (
int)
myEdges.size()) {
315 if (fromEdge == toEdge) {
316 if (fromPos <= toPos) {
317 return toPos - fromPos;
320 return fromEdge->
getLength() - fromPos + toPos;
324 if (fromEdge ==
myEdges.front()) {
342 ConstMSEdgeVector::const_iterator it = std::find(
myEdges.begin() + routePosition,
myEdges.end(), fromEdge);
345 return std::numeric_limits<double>::max();
347 ConstMSEdgeVector::const_iterator it2 = std::find(it + 1,
myEdges.end(), toEdge);
349 if (fromEdge == toEdge) {
350 if (fromPos <= toPos) {
351 return toPos - fromPos;
352 }
else if (it2 ==
myEdges.end()) {
354 return std::numeric_limits<double>::max();
364 bool isFirstIteration =
true;
365 double distance = -fromPos;
367 if (fromEdge == toEdge) {
369 if (fromPos <= toPos) {
370 return toPos - fromPos;
373 return std::numeric_limits<double>::max();
375 }
else if (fromEdge > toEdge) {
377 return std::numeric_limits<double>::max();
379 for (; it !=
end(); ++it) {
380 if (it == toEdge && !isFirstIteration) {
384 distance += (*it)->getLength();
385 if (includeInternal && (it + 1) !=
end()) {
387 distance += (*it)->getInternalFollowingLengthTo(*(it + 1),
SVC_IGNORING);
390 isFirstIteration =
false;
405const std::vector<SUMOVehicleParameter::Stop>&
std::vector< const MSEdge * > ConstMSEdgeVector
std::vector< MSEdge * > MSEdgeVector
ConstMSEdgeVector::const_iterator MSRouteIterator
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.
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.
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)
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
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.
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)