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->getLanes()) {
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];
217 for (
const auto& lane : edge->
getLanes()) {
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) {
258 for (
const auto& fromLane : from->
getLanes()) {
261 for (
const auto& toLane : to->
getLanes()) {
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->
getLanes().size(); laneIndex++) {
295 pedestrianLanes.push_back(edge->
getLanes().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();
375 }
else if (myLaneDrawedElements.count(lane) > 0) {
377 if (myLaneDrawedElements.at(lane).count(tag) > 0) {
382 myLaneDrawedElements.at(lane).insert(tag);
388 myLaneDrawedElements[lane].insert(tag);
404 if (myLane2laneDrawedElements.count(lane2lane) > 0) {
406 if (myLane2laneDrawedElements.at(lane2lane).count(tag) > 0) {
411 myLane2laneDrawedElements.at(lane2lane).insert(tag);
417 myLane2laneDrawedElements[lane2lane].insert(tag);
453 const auto pathElement =
dynamic_cast<const GNEPathElement*
>(GLObject);
454 if (pathElement ==
nullptr) {
458 auto it =
myPaths.find(pathElement);
468const std::vector<GNESegment*>&
470 if (
myPaths.count(pathElement) > 0) {
471 return myPaths.at(pathElement);
487 if (
myPaths.count(pathElement) > 0) {
489 for (
const auto& segment :
myPaths.at(pathElement)) {
491 if (segment->getLane() && segment->getNextLane()) {
505 if ((
myPaths.count(pathElement) > 0) && (
myPaths.at(pathElement).size() > 0)) {
506 return myPaths.at(pathElement).front()->getLane();
518 fromLane,
nullptr, toLane,
nullptr);
526 fromLane,
nullptr,
nullptr, toJunction);
534 nullptr, fromJunction, toLane,
nullptr);
548 if (edges.size() > 0) {
550 edges.front()->getLaneByAllowedVClass(vClass),
nullptr, edges.back()->getLaneByAllowedVClass(vClass),
nullptr);
559 const int firstLaneIndex,
const int lastLaneIndex) {
561 std::vector<GNELane*> lanes;
562 if (edges.size() > 0) {
563 lanes.reserve(edges.size());
565 if ((firstLaneIndex >= 0) && (firstLaneIndex < (
int)edges.front()->getLanes().size())) {
566 lanes.push_back(edges.front()->getLanes().at(firstLaneIndex));
568 lanes.push_back(edges.front()->getLaneByAllowedVClass(vClass));
571 if (edges.size() > 1) {
573 for (
int i = 1; i < ((int)edges.size() - 1); i++) {
574 lanes.push_back(edges[i]->getLaneByAllowedVClass(vClass));
577 if ((lastLaneIndex >= 0) && (lastLaneIndex < (int)edges.back()->getLanes().size())) {
578 lanes.push_back(edges.back()->getLanes().at(lastLaneIndex));
580 lanes.push_back(edges.back()->getLaneByAllowedVClass(vClass));
594 if (lanes.size() > 0) {
596 std::vector<GNESegment*> segments;
598 const int lastIndex = ((int)lanes.size() - 1);
600 segments.reserve(2 * lanes.size());
602 for (
int i = 0; i < (int)lanes.size(); i++) {
604 new GNESegment(
this, pathElement, lanes.at(i), segments);
606 if (i != lastIndex) {
608 new GNESegment(
this, pathElement, lanes.at(i)->getParentEdge()->getToJunction(), segments);
614 myPaths[pathElement] = segments;
624 for (
const auto& segment :
myPaths.at(pathElement)) {
641 segment->getPathElement()->drawLanePartialGL(s, segment, 2);
643 if (segment->getPathElement()->isRoute()) {
651 segment->getPathElement()->drawLanePartialGL(s, segment, 0);
653 if (segment->getPathElement()->isRoute()) {
673 segment->getPathElement()->drawJunctionPartialGL(s, segment, 2);
679 segment->getPathElement()->drawJunctionPartialGL(s, segment, 0);
690 const auto it =
myPaths.find(pathElementToRedraw);
692 for (
const auto& segment : it->second) {
693 if (segment->getLane()) {
695 it->first->drawLanePartialGL(s, segment, 3);
696 }
else if (segment->getJunction()) {
698 it->first->drawJunctionPartialGL(s, segment, 3);
709 std::vector<GNEPathElement*> pathElementsToCompute;
714 pathElementsToCompute.push_back(segment->getPathElement());
718 for (
const auto& pathElement : pathElementsToCompute) {
719 pathElement->computePathElement();
727 std::vector<GNEPathElement*> pathElementsToCompute;
732 pathElementsToCompute.push_back(segment->getPathElement());
736 for (
const auto& pathElement : pathElementsToCompute) {
737 pathElement->computePathElement();
747 for (
const auto& path :
myPaths) {
749 for (
const auto& segment : path.second) {
778 auto lane = segment->
getLane();
804 std::vector<NBEdge::Connection>::const_iterator con_it = find_if(
805 connections.begin(), connections.end(),
808 return (con_it != connections.end());
818 std::vector<GNESegment*> segments;
820 if (path.size() > 0) {
822 const int lastIndex = ((int)path.size() - 1);
824 segments.reserve(2 * path.size());
827 new GNESegment(
this, pathElement, fromJunction, segments);
830 for (
int i = 0; i < (int)path.size(); i++) {
831 if ((i == 0) && fromLane) {
833 new GNESegment(
this, pathElement, fromLane, segments);
835 if (i != lastIndex) {
837 new GNESegment(
this, pathElement, path.at(i)->getToJunction(), segments);
839 }
else if ((i == lastIndex) && toLane) {
841 new GNESegment(
this, pathElement, toLane, segments);
844 const GNELane* lane = path.at(i)->getLaneByAllowedVClass(vClass);
846 new GNESegment(
this, pathElement, lane, segments);
848 if (i != lastIndex) {
850 new GNESegment(
this, pathElement, path.at(i)->getToJunction(), segments);
856 new GNESegment(
this, pathElement, toJunction, segments);
861 myPaths[pathElement] = segments;
868 firstSegment =
new GNESegment(
this, pathElement, fromLane, segments);
869 }
else if (fromJunction) {
870 firstSegment =
new GNESegment(
this, pathElement, fromJunction, segments);
873 lastSegment =
new GNESegment(
this, pathElement, toLane, segments);
874 }
else if (toJunction) {
875 lastSegment =
new GNESegment(
this, pathElement, toJunction, segments);
878 if (firstSegment && lastSegment) {
882 myPaths[pathElement] = segments;
894 std::vector<GNESegment*> laneSegments;
895 laneSegments.reserve(segments.size());
896 for (
const auto& segment : segments) {
897 if (segment->getLane()) {
898 laneSegments.push_back(segment);
902 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.
An Element which don't belong to GNENet but has influence in the simulation.
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< GNELane * > & getLanes() const
returns a reference to the lane vector
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 std::vector< GNELane * > & getParentLanes() const
get parent lanes
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
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, SumoXMLTag tag)
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)