45 FXMutex MSRoute::myDictMutex(
true);
54 const bool isPermanent,
const RGBColor*
const c,
55 const std::vector<SUMOVehicleParameter::Stop>& stops)
56 :
Named(id), myEdges(edges), myAmPermanent(isPermanent),
57 myReferenceCounter(isPermanent ? 1 : 0),
58 myColor(c), myStops(stops) {}
102 FXMutexLock f(myDictMutex);
113 FXMutexLock f(myDictMutex);
126 FXMutexLock f(myDictMutex);
129 myDistDict[id] = std::make_pair(routeDist, permanent);
139 FXMutexLock f(myDictMutex);
141 RouteDict::iterator it =
myDict.find(
id);
143 RouteDistDict::iterator it2 =
myDistDict.find(
id);
144 if (it2 ==
myDistDict.end() || it2->second.first->getOverallProb() == 0) {
147 return it2->second.first->get(rng);
156 FXMutexLock f(myDictMutex);
158 RouteDistDict::iterator it2 =
myDistDict.find(
id);
162 return it2->second.first;
169 FXMutexLock f(myDictMutex);
172 delete i->second.first;
175 for (RouteDict::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
185 FXMutexLock f(myDictMutex);
187 RouteDistDict::iterator it =
myDistDict.find(
id);
188 if (it !=
myDistDict.end() && !it->second.second) {
189 const std::vector<const MSRoute*>& routes = it->second.first->getVals();
190 for (std::vector<const MSRoute*>::const_iterator i = routes.begin(); i != routes.end(); ++i) {
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);
217 ConstMSEdgeVector::const_iterator i =
myEdges.begin();
221 for (; i !=
myEdges.end(); ++i) {
227 if (upTo || i !=
myEdges.end() - 1) {
237 MSEdgeVector::const_iterator i = edgelist.begin();
238 for (; i != edgelist.end(); ++i) {
256 FXMutexLock f(myDictMutex);
258 for (RouteDict::iterator it =
myDict.begin(); it !=
myDict.end(); ++it) {
275 const MSEdge* fromEdge,
const MSEdge* toEdge,
bool includeInternal)
const {
279 if (fromEdge ==
myEdges.front()) {
297 ConstMSEdgeVector::const_iterator it = std::find(
myEdges.begin(),
myEdges.end(), fromEdge);
300 return std::numeric_limits<double>::max();
302 ConstMSEdgeVector::const_iterator it2 = std::find(it + 1,
myEdges.end(), toEdge);
304 if (fromEdge == toEdge) {
305 if (fromPos <= toPos) {
306 return toPos - fromPos;
307 }
else if (it2 ==
myEdges.end()) {
309 return std::numeric_limits<double>::max();
319 bool isFirstIteration =
true;
320 double distance = -fromPos;
322 if (fromEdge == toEdge) {
324 if (fromPos <= toPos) {
325 return toPos - fromPos;
328 return std::numeric_limits<double>::max();
330 }
else if (fromEdge > toEdge) {
332 return std::numeric_limits<double>::max();
334 for (; it !=
end(); ++it) {
335 if (it == toEdge && !isFirstIteration) {
339 distance += (*it)->getLength();
340 if (includeInternal && (it + 1) !=
end()) {
341 distance += (*it)->getInternalFollowingLengthTo(*(it + 1));
344 isFirstIteration =
false;
359 const std::vector<SUMOVehicleParameter::Stop>&
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
std::map< std::string, const MSRoute * > RouteDict
Definition of the dictionary container.
void release() const
deletes the route if there are no further references to it
Represents a generic random distribution.
const MSEdgeVector & getPredecessors() const
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...
const RGBColor & getColor() const
Returns the color.
const MSEdge * getLastEdge() const
returns the destination edge
std::vector< const MSEdge * > ConstMSEdgeVector
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
double getLength() const
return the length of the edge
int size() const
Returns the number of edges to pass.
begin/end of the description of a route
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
static void insertIDs(std::vector< std::string > &into)
A road/street connecting two junctions.
static void clear()
Clears the dictionary (delete all known routes, too)
static RouteDistDict myDistDict
The dictionary container.
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
MSRoute(const std::string &id, const ConstMSEdgeVector &edges, const bool isPermanent, const RGBColor *const c, const std::vector< SUMOVehicleParameter::Stop > &stops)
Constructor.
ConstMSEdgeVector::const_iterator MSRouteIterator
std::map< std::string, std::pair< RandomDistributor< const MSRoute * > *, bool > > RouteDistDict
Definition of the dictionary container.
virtual ~MSRoute()
Destructor.
bool isInternal() const
return whether this edge is an internal edge
int writeEdgeIDs(OutputDevice &os, const MSEdge *const from, const MSEdge *const upTo=0) const
Output the edge ids up to but not including the id of the given edge.
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Base class for objects which have an id.
const MSEdge * operator[](int index) const
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
std::string myID
The name of the object.
bool containsAnyOf(const MSEdgeVector &edgelist) const
ConstMSEdgeVector myEdges
The list of edges to pass.
void addReference() const
increments the reference counter for the route
int myReferenceCounter
Information by how many vehicles the route is used.
Static storage of an output device and its base (abstract) implementation.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
std::vector< MSEdge * > MSEdgeVector
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
static RouteDict myDict
The dictionary container.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool contains(const MSEdge *const edge) const
const RGBColor *const myColor
The color.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.