41 myPathCalculatorUpdated(false),
42 myDijkstraRouter(nullptr) {
51 delete myDijkstraRouter;
58 if (myDijkstraRouter) {
59 delete myDijkstraRouter;
62 myNet->getNetBuilder()->getEdgeCont().getAllRouterEdges(),
65 myPathCalculatorUpdated =
true;
72 std::vector<GNEEdge*> solution;
74 if (!myPathCalculatorUpdated) {
80 if (edges.size() == 0) {
83 }
else if (edges.size() == 1) {
85 solution.push_back(edges.front());
87 }
else if ((edges.size() == 2) && (edges.front() == edges.back())) {
89 solution.push_back(edges.front());
93 NBVehicle tmpVehicle(
"temporalNBVehicle", vClass);
95 GNENet* net = edges.front()->getNet();
97 for (
int i = 1; i < (int)edges.size(); i++) {
99 if (edges.at(i - 1)->getNBEdge() != edges.at(i)->getNBEdge()) {
101 std::vector<const NBRouterEdge*> partialRoute;
102 myDijkstraRouter->compute(edges.at(i - 1)->getNBEdge(), edges.at(i)->getNBEdge(), &tmpVehicle, 10, partialRoute);
104 if (partialRoute.empty()) {
108 for (
const auto& edgeID : partialRoute) {
116 auto solutionIt = solution.begin();
118 while (solutionIt != solution.end()) {
119 if ((solutionIt + 1) != solution.end()) {
121 if (*solutionIt == *(solutionIt + 1)) {
122 solutionIt = solution.erase(solutionIt);
136 return calculateDijkstraPath(vClass, {fromEdge, toEdge});
142 std::vector<GNEEdge*> edges;
146 for (
const auto& toEdge : toEdges) {
147 edges = calculateDijkstraPath(vClass, fromEdge, toEdge);
149 if (edges.size() > 0) {
150 return optimizeJunctionPath(edges);
159 std::vector<GNEEdge*> edges;
163 for (
const auto& fromEdge : fromEdges) {
164 edges = calculateDijkstraPath(vClass, fromEdge, toEdge);
166 if (edges.size() > 0) {
167 return optimizeJunctionPath(edges);
176 std::vector<GNEEdge*> edges;
181 for (
const auto& fromEdge : fromEdges) {
182 for (
const auto& toEdge : toEdges) {
183 edges = calculateDijkstraPath(vClass, fromEdge, toEdge);
185 if (edges.size() > 0) {
186 return optimizeJunctionPath(edges);
198 for (
const auto& lane : edge.second->getChildLanes()) {
199 lane->resetReachability();
205 std::map<GNEEdge*, double> reachableEdges;
207 reachableEdges[originEdge] = 0;
209 std::vector<GNEEdge*> check;
211 check.push_back(originEdge);
213 while (check.size() > 0) {
215 check.erase(check.begin());
216 double traveltime = reachableEdges[edge];
224 std::vector<GNEEdge*> sucessors;
228 if (consecutiveEdgesConnected(vClass, edge, sucessorEdge)) {
229 sucessors.push_back(sucessorEdge);
233 for (
const auto& nextEdge : sucessors) {
235 if ((reachableEdges.count(nextEdge) == 0) || (reachableEdges[nextEdge] > traveltime)) {
236 reachableEdges[nextEdge] = traveltime;
237 check.push_back(nextEdge);
247 if ((from ==
nullptr) || (to ==
nullptr)) {
250 }
else if (from == to) {
262 if (fromConnection->getLaneTo() == toLane) {
267 if (((NBFromLane.
permissions & vClass) == vClass) &&
286 if ((busStop->
getParentLanes().front()->getParentEdge() == edge) &&
292 std::vector<GNELane*> pedestrianLanes;
293 for (
int laneIndex = 0; laneIndex < (int)edge->
getChildLanes().size(); laneIndex++) {
295 pedestrianLanes.push_back(edge->
getChildLanes().at(laneIndex));
302 for (
const auto& lane : pedestrianLanes) {
303 if (access->getParentLanes().front() == lane) {
317 return myPathCalculatorUpdated;
323 myPathCalculatorUpdated =
false;
330 std::vector<GNEEdge*> solutionA, solutionB;
332 const auto fromJunction = edges.front()->getFromJunction();
333 const auto toJunction = edges.back()->getToJunction();
335 for (
auto it = edges.rbegin(); (it != edges.rend()) && !stop; it++) {
336 solutionA.insert(solutionA.begin(), *it);
337 if ((*it)->getFromJunction() == fromJunction) {
343 for (
auto it = solutionA.begin(); (it != solutionA.end()) && !stop; it++) {
344 solutionB.push_back(*it);
345 if ((*it)->getToJunction() == toJunction) {
365 myLaneDrawedElements.clear();
366 myLane2laneDrawedElements.clear();
376 }
else if (myLaneDrawedElements.count(lane) > 0) {
378 if (!isPlan && myLaneDrawedElements.at(lane).count(tag) > 0) {
383 myLaneDrawedElements.at(lane).insert(tag);
389 myLaneDrawedElements[lane].insert(tag);
406 if (myLane2laneDrawedElements.count(lane2lane) > 0) {
408 if (!isPlan && myLane2laneDrawedElements.at(lane2lane).count(tag) > 0) {
413 myLane2laneDrawedElements.at(lane2lane).insert(tag);
419 myLane2laneDrawedElements[lane2lane].insert(tag);
455 const auto pathElement =
dynamic_cast<const GNEPathElement*
>(GLObject);
456 if (pathElement ==
nullptr) {
460 auto it =
myPaths.find(pathElement);
470const std::vector<GNESegment*>&
472 if (
myPaths.count(pathElement) > 0) {
473 return myPaths.at(pathElement);
489 if (
myPaths.count(pathElement) > 0) {
491 for (
const auto& segment :
myPaths.at(pathElement)) {
493 if (segment->getLane() && segment->getNextLane()) {
507 if ((
myPaths.count(pathElement) > 0) && (
myPaths.at(pathElement).size() > 0)) {
508 return myPaths.at(pathElement).front()->getLane();
520 fromLane,
nullptr, toLane,
nullptr);
528 fromLane,
nullptr,
nullptr, toJunction);
536 nullptr, fromJunction, toLane,
nullptr);
550 if (edges.size() > 0) {
552 edges.front()->getLaneByAllowedVClass(vClass),
nullptr, edges.back()->getLaneByAllowedVClass(vClass),
nullptr);
561 const int firstLaneIndex,
const int lastLaneIndex) {
563 std::vector<GNELane*> lanes;
564 if (edges.size() > 0) {
565 lanes.reserve(edges.size());
567 if ((firstLaneIndex >= 0) && (firstLaneIndex < (
int)edges.front()->getChildLanes().size())) {
568 lanes.push_back(edges.front()->getChildLanes().at(firstLaneIndex));
570 lanes.push_back(edges.front()->getLaneByAllowedVClass(vClass));
573 if (edges.size() > 1) {
575 for (
int i = 1; i < ((int)edges.size() - 1); i++) {
576 lanes.push_back(edges[i]->getLaneByAllowedVClass(vClass));
579 if ((lastLaneIndex >= 0) && (lastLaneIndex < (int)edges.back()->getChildLanes().size())) {
580 lanes.push_back(edges.back()->getChildLanes().at(lastLaneIndex));
582 lanes.push_back(edges.back()->getLaneByAllowedVClass(vClass));
596 if (lanes.size() > 0) {
598 std::vector<GNESegment*> segments;
600 const int lastIndex = ((int)lanes.size() - 1);
602 segments.reserve(2 * lanes.size());
604 for (
int i = 0; i < (int)lanes.size(); i++) {
606 new GNESegment(
this, pathElement, lanes.at(i), segments);
608 if (i != lastIndex) {
610 new GNESegment(
this, pathElement, lanes.at(i)->getParentEdge()->getToJunction(), segments);
616 myPaths[pathElement] = segments;
626 for (
const auto& segment :
myPaths.at(pathElement)) {
643 segment->getPathElement()->drawLanePartialGL(s, segment, 2);
645 if (segment->getPathElement()->isRoute()) {
653 segment->getPathElement()->drawLanePartialGL(s, segment, 0);
655 if (segment->getPathElement()->isRoute()) {
675 segment->getPathElement()->drawJunctionPartialGL(s, segment, 2);
681 segment->getPathElement()->drawJunctionPartialGL(s, segment, 0);
692 const auto it =
myPaths.find(pathElementToRedraw);
694 for (
const auto& segment : it->second) {
695 if (segment->getLane()) {
697 it->first->drawLanePartialGL(s, segment, 3);
698 }
else if (segment->getJunction()) {
700 it->first->drawJunctionPartialGL(s, segment, 3);
711 std::vector<GNEPathElement*> pathElementsToCompute;
716 pathElementsToCompute.push_back(segment->getPathElement());
720 for (
const auto& pathElement : pathElementsToCompute) {
721 pathElement->computePathElement();
729 std::vector<GNEPathElement*> pathElementsToCompute;
734 pathElementsToCompute.push_back(segment->getPathElement());
738 for (
const auto& pathElement : pathElementsToCompute) {
739 pathElement->computePathElement();
749 for (
const auto& path :
myPaths) {
751 for (
const auto& segment : path.second) {
780 auto lane = segment->
getLane();
806 std::vector<NBEdge::Connection>::const_iterator con_it = find_if(
807 connections.begin(), connections.end(),
810 return (con_it != connections.end());
820 std::vector<GNESegment*> segments;
822 if (path.size() > 0) {
824 const int lastIndex = ((int)path.size() - 1);
826 segments.reserve(2 * path.size());
829 new GNESegment(
this, pathElement, fromJunction, segments);
832 for (
int i = 0; i < (int)path.size(); i++) {
833 if ((i == 0) && fromLane) {
835 new GNESegment(
this, pathElement, fromLane, segments);
837 if (i != lastIndex) {
839 new GNESegment(
this, pathElement, path.at(i)->getToJunction(), segments);
841 }
else if ((i == lastIndex) && toLane) {
843 new GNESegment(
this, pathElement, toLane, segments);
846 const GNELane* lane = path.at(i)->getLaneByAllowedVClass(vClass);
848 new GNESegment(
this, pathElement, lane, segments);
850 if (i != lastIndex) {
852 new GNESegment(
this, pathElement, path.at(i)->getToJunction(), segments);
858 new GNESegment(
this, pathElement, toJunction, segments);
863 myPaths[pathElement] = segments;
870 firstSegment =
new GNESegment(
this, pathElement, fromLane, segments);
871 }
else if (fromJunction) {
872 firstSegment =
new GNESegment(
this, pathElement, fromJunction, segments);
875 lastSegment =
new GNESegment(
this, pathElement, toLane, segments);
876 }
else if (toJunction) {
877 lastSegment =
new GNESegment(
this, pathElement, toJunction, segments);
880 if (firstSegment && lastSegment) {
884 myPaths[pathElement] = segments;
896 std::vector<GNESegment*> laneSegments;
897 laneSegments.reserve(segments.size());
898 for (
const auto& segment : segments) {
899 if (segment->getLane()) {
900 laneSegments.push_back(segment);
904 const int laneSegmentIndex = (int)((
double)laneSegments.size() * 0.5);
GUIViewObjectsHandler gViewObjectsHandler
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_PEDESTRIAN
pedestrian
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_ACCESS
An access point for a train stop.
@ SUMO_TAG_BUS_STOP
A bus stop.
Computes the shortest path through a network using the Dijkstra algorithm.
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * getNet() const
get pointer to net
void setReachability(const double reachability)
set current reachability (traveltime)
A road/street connecting two junctions (netedit-version)
NBEdge * getNBEdge() const
returns the internal NBEdge
const std::vector< GNEConnection * > & getGNEConnections() const
returns a reference to the GNEConnection vector
GNEJunction * getToJunction() const
get from Junction (only used to increase readability)
const GNEHierarchicalContainerChildren< GNELane * > & getChildLanes() const
get child lanes
const GNEHierarchicalContainerChildren< GNEAdditional * > & getChildAdditionals() const
return child additionals
const GNEHierarchicalContainerParents< GNELane * > & getParentLanes() const
get parent lanes
const std::vector< GNEEdge * > & getGNEIncomingEdges() const
Returns incoming GNEEdges.
const std::vector< GNEEdge * > & getGNEOutgoingEdges() const
Returns incoming GNEEdges.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
int getIndex() const
returns the index of the lane
void drawOverlappedRoutes(const int numRoutes) const
draw overlapped routes
GNEEdge * getParentEdge() const
get parent edge
const std::map< std::string, GNEEdge * > & getEdges() const
map with the ID and pointer to edges of net
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
A NBNetBuilder extended by visualisation and editing capabilities.
NBNetBuilder * getNetBuilder() const
get net builder
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
GNEViewNet * getViewNet() const
get view net
class used to calculate paths in nets
std::vector< GNEEdge * > calculateDijkstraPath(const SUMOVehicleClass vClass, const std::vector< GNEEdge * > &edges) const
calculate Dijkstra path between a list of edges (for example, from-via-to edges)
bool consecutiveEdgesConnected(const SUMOVehicleClass vClass, const GNEEdge *from, const GNEEdge *to) const
check if exist a path between the two given consecutive edges for the given VClass
void updatePathCalculator()
update DijkstraRouter (needed a good calculation of dijkstra path after modifying network)
bool isPathCalculatorUpdated() const
check if pathCalculator is updated
SUMOAbstractRouter< NBRouterEdge, NBVehicle > * myDijkstraRouter
SUMO Abstract myDijkstraRouter.
void invalidatePathCalculator()
invalidate pathCalculator
void calculateReachability(const SUMOVehicleClass vClass, GNEEdge *originEdge)
calculate reachability for given edge
std::vector< GNEEdge * > optimizeJunctionPath(const std::vector< GNEEdge * > &edges) const
optimize junction path
~PathCalculator()
destructor
PathCalculator(const GNENet *net)
constructor
bool busStopConnected(const GNEAdditional *busStop, const GNEEdge *edge) const
check if exist a path between the given busStop and edge (Either a valid lane or an acces) for pedest...
const GNENet * myNet
pointer to net
class used to mark path draw
bool checkDrawPathGeometry(const GUIVisualizationSettings &s, const GNELane *lane, const SumoXMLTag tag, const bool isPlan)
check if path element geometry must be drawn in the given lane
void clearPathDraw()
clear path draw
PathCalculator * getPathCalculator()
obtain instance of PathCalculator
void buildPath(GNEPathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > path, GNELane *fromLane, GNEJunction *fromJunction, GNELane *toLane, GNEJunction *toJunction)
build path
void calculatePath(GNEPathElement *pathElement, SUMOVehicleClass vClass, GNELane *fromLane, GNELane *toLane)
calculate path between from-to edges (using dijkstra, require path calculator updated)
void invalidateJunctionPath(const GNEJunction *junction)
invalidate junction path
const std::vector< GNESegment * > & getPathElementSegments(GNEPathElement *pathElement) const
get path segments
const GNEPathElement * getPathElement(const GUIGlObject *GLObject) const
get path element
PathDraw * getPathDraw()
obtain instance of PathDraw
void clearSegments()
clear segments
void addSegmentInLaneSegments(GNESegment *segment, const GNELane *lane)
add segments int laneSegments (called by GNESegment constructor)
PathCalculator * myPathCalculator
PathCalculator instance.
void invalidateLanePath(const GNELane *lane)
invalidate lane path
friend class GNESegment
friend class declaration
void markLabelSegment(const std::vector< GNESegment * > &segments) const
mark label segment
void calculateConsecutivePathLanes(GNEPathElement *pathElement, const std::vector< GNELane * > &lanes)
calculate consecutive path lanes
bool connectedLanes(const GNELane *fromLane, const GNELane *toLane) const
check if given lanes are connected
void drawLanePathElements(const GUIVisualizationSettings &s, const GNELane *lane) const
draw lane path elements
bool isPathValid(const GNEPathElement *pathElement) const
check if path element is valid
std::map< const GNEJunction *, std::set< GNESegment * > > myJunctionSegments
map with junction segments
void removePath(GNEPathElement *pathElement)
remove path
void drawJunctionPathElements(const GUIVisualizationSettings &s, const GNEJunction *junction) const
draw junction path elements
const GNELane * getFirstLane(const GNEPathElement *pathElement) const
get first lane associated with path element
bool myCleaningSegments
flag for clear segments quickly
PathDraw * myPathDraw
PathDraw instance.
void clearSegmentFromJunctionAndLaneSegments(GNESegment *segment)
clear segments from junction and lane Segments (called by GNESegment destructor)
std::map< const GNELane *, std::set< GNESegment * > > myLaneSegments
map with lane segments
~GNEPathManager()
destructor
void addSegmentInJunctionSegments(GNESegment *segment, const GNEJunction *junction)
add segments int junctionSegments (called by GNESegment constructor)
GNEPathManager(const GNENet *net)
constructor
void calculateConsecutivePathEdges(GNEPathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > &edges, const int firstLaneIndex=-1, const int lastLaneIndex=-1)
calculate consecutive path edges
void redrawPathElements(const GUIVisualizationSettings &s) const
redraw path elements saved in gViewObjectsHandler buffer
std::map< const GNEPathElement *, std::vector< GNESegment * > > myPaths
map with path element and their associated segments
const std::vector< GNESegment * > myEmptySegments
empty segments (used in getPathElementSegments)
const GNELane * getLane() const
get lane associated with this segment
void markSegmentLabel()
mark segment as middle segment
const GNEJunction * getJunction() const
get junction associated with this segment
const GNELane * getNextLane() const
get next lane
const GNELane * getPreviousLane() const
get previous lane
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
bool isPathElementMarkForRedraw(const GNEPathElement *pathElement) const
check if the given path element has to be redraw again
const std::set< const GNEPathElement * > & getRedrawPathElements() const
Stores the information about how to visualize structures.
bool drawForViewObjectsHandler
whether drawing is performed for the purpose of selecting objects in view using ViewObjectsHandler
RouterEdgeVector getAllRouterEdges() const
return all router edges
The representation of a single edge during network building.
double getLength() const
Returns the computed length of the edge.
Lane & getLaneStruct(int lane)
double getSpeed() const
Returns the speed allowed on this edge.
std::vector< Connection > getConnectionsFromLane(int lane, const NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
NBEdgeCont & getEdgeCont()
static double getTravelTimeStatic(const NBRouterEdge *const edge, const NBVehicle *const, double)
A vehicle as used by router.
bool showOverlappedRoutes() const
show overlapped routes
An (internal) definition of a single lane of an edge.
SVCPermissions permissions
List of vehicle types that are allowed on this lane.
struct for default values that depend of VClass
double maxSpeed
The vehicle type's maximum speed [m/s] (technical limit, not subject to speed deviation)