39 myPathManager(pathManager),
40 myPathElement(element),
43 myNextSegment(nullptr),
44 myPreviousSegment(nullptr),
45 myLabelSegment(false),
48 if (segments.size() > 0) {
54 segments.push_back(
this);
61 myPathManager(pathManager),
62 myPathElement(element),
65 myNextSegment(nullptr),
66 myPreviousSegment(nullptr),
67 myLabelSegment(false),
70 if (segments.size() > 0) {
76 segments.push_back(
this);
84 if (!myPathManager->myCleaningSegments) {
86 myPathManager->clearSegmentFromJunctionAndLaneSegments(
this);
88 if (myPreviousSegment) {
89 myPreviousSegment->myNextSegment =
nullptr;
92 myNextSegment->myPreviousSegment =
nullptr;
108 return (myPreviousSegment ==
nullptr);
114 return (myNextSegment ==
nullptr);
120 return myPathElement;
132 if (myPreviousSegment) {
133 return myPreviousSegment->getLane();
143 return myNextSegment->getLane();
158 return myNextSegment;
164 return myPreviousSegment;
170 return myLabelSegment;
176 myLabelSegment =
true;
181 myPathManager(nullptr),
182 myPathElement(nullptr),
185 myNextSegment(nullptr),
186 myPreviousSegment(nullptr),
187 myLabelSegment(false) {
238 myPathCalculatorUpdated(false),
239 myDijkstraRouter(nullptr) {
248 delete myDijkstraRouter;
255 if (myDijkstraRouter) {
256 delete myDijkstraRouter;
259 myNet->getNetBuilder()->getEdgeCont().getAllRouterEdges(),
262 myPathCalculatorUpdated =
true;
269 std::vector<GNEEdge*> solution;
271 if (!myPathCalculatorUpdated) {
277 if (edges.size() == 0) {
280 }
else if (edges.size() == 1) {
282 solution.push_back(edges.front());
284 }
else if ((edges.size() == 2) && (edges.front() == edges.back())) {
286 solution.push_back(edges.front());
290 NBVehicle tmpVehicle(
"temporalNBVehicle", vClass);
292 GNENet* net = edges.front()->getNet();
294 for (
int i = 1; i < (int)edges.size(); i++) {
296 if (edges.at(i - 1)->getNBEdge() != edges.at(i)->getNBEdge()) {
298 std::vector<const NBRouterEdge*> partialRoute;
299 myDijkstraRouter->compute(edges.at(i - 1)->getNBEdge(), edges.at(i)->getNBEdge(), &tmpVehicle, 10, partialRoute);
301 if (partialRoute.empty()) {
305 for (
const auto& edgeID : partialRoute) {
313 auto solutionIt = solution.begin();
315 while (solutionIt != solution.end()) {
316 if ((solutionIt + 1) != solution.end()) {
318 if (*solutionIt == *(solutionIt + 1)) {
319 solutionIt = solution.erase(solutionIt);
333 return calculateDijkstraPath(vClass, {fromEdge, toEdge});
339 std::vector<GNEEdge*> edges;
343 for (
const auto& toEdge : toEdges) {
344 edges = calculateDijkstraPath(vClass, fromEdge, toEdge);
346 if (edges.size() > 0) {
347 return optimizeJunctionPath(edges);
356 std::vector<GNEEdge*> edges;
360 for (
const auto& fromEdge : fromEdges) {
361 edges = calculateDijkstraPath(vClass, fromEdge, toEdge);
363 if (edges.size() > 0) {
364 return optimizeJunctionPath(edges);
373 std::vector<GNEEdge*> edges;
378 for (
const auto& fromEdge : fromEdges) {
379 for (
const auto& toEdge : toEdges) {
380 edges = calculateDijkstraPath(vClass, fromEdge, toEdge);
382 if (edges.size() > 0) {
383 return optimizeJunctionPath(edges);
395 for (
const auto& lane : edge.second->getLanes()) {
396 lane->resetReachability();
402 std::map<GNEEdge*, double> reachableEdges;
404 reachableEdges[originEdge] = 0;
406 std::vector<GNEEdge*> check;
408 check.push_back(originEdge);
410 while (check.size() > 0) {
412 check.erase(check.begin());
413 double traveltime = reachableEdges[edge];
414 for (
const auto& lane : edge->
getLanes()) {
421 std::vector<GNEEdge*> sucessors;
425 if (consecutiveEdgesConnected(vClass, edge, sucessorEdge)) {
426 sucessors.push_back(sucessorEdge);
430 for (
const auto& nextEdge : sucessors) {
432 if ((reachableEdges.count(nextEdge) == 0) || (reachableEdges[nextEdge] > traveltime)) {
433 reachableEdges[nextEdge] = traveltime;
434 check.push_back(nextEdge);
444 if ((from ==
nullptr) || (to ==
nullptr)) {
447 }
else if (from == to) {
455 for (
const auto& fromLane : from->
getLanes()) {
458 for (
const auto& toLane : to->
getLanes()) {
459 if (fromConnection->getLaneTo() == toLane) {
464 if (((NBFromLane.
permissions & vClass) == vClass) &&
483 if ((busStop->
getParentLanes().front()->getParentEdge() == edge) &&
489 std::vector<GNELane*> pedestrianLanes;
490 for (
int laneIndex = 0; laneIndex < (int)edge->
getLanes().size(); laneIndex++) {
492 pedestrianLanes.push_back(edge->
getLanes().at(laneIndex));
499 for (
const auto& lane : pedestrianLanes) {
500 if (access->getParentLanes().front() == lane) {
514 return myPathCalculatorUpdated;
520 myPathCalculatorUpdated =
false;
527 std::vector<GNEEdge*> solutionA, solutionB;
529 const auto fromJunction = edges.front()->getFromJunction();
530 const auto toJunction = edges.back()->getToJunction();
532 for (
auto it = edges.rbegin(); (it != edges.rend()) && !stop; it++) {
533 solutionA.insert(solutionA.begin(), *it);
534 if ((*it)->getFromJunction() == fromJunction) {
540 for (
auto it = solutionA.begin(); (it != solutionA.end()) && !stop; it++) {
541 solutionB.push_back(*it);
542 if ((*it)->getToJunction() == toJunction) {
562 myLaneDrawedElements.clear();
563 myLane2laneDrawedElements.clear();
572 }
else if (myLaneDrawedElements.count(lane) > 0) {
574 if (myLaneDrawedElements.at(lane).count(tag) > 0) {
579 myLaneDrawedElements.at(lane).insert(tag);
585 myLaneDrawedElements[lane].insert(tag);
601 if (myLane2laneDrawedElements.count(lane2lane) > 0) {
603 if (myLane2laneDrawedElements.at(lane2lane).count(tag) > 0) {
608 myLane2laneDrawedElements.at(lane2lane).insert(tag);
614 myLane2laneDrawedElements[lane2lane].insert(tag);
651 if (pathElement ==
nullptr) {
655 auto it =
myPaths.find(pathElement);
665const std::vector<GNEPathManager::Segment*>&
667 if (
myPaths.count(pathElement) > 0) {
668 return myPaths.at(pathElement);
684 if (
myPaths.count(pathElement) > 0) {
686 for (
const auto& segment :
myPaths.at(pathElement)) {
688 if (segment->getLane() && segment->getNextLane()) {
702 if ((
myPaths.count(pathElement) > 0) && (
myPaths.at(pathElement).size() > 0)) {
703 return myPaths.at(pathElement).front()->getLane();
715 fromLane,
nullptr, toLane,
nullptr);
723 fromLane,
nullptr,
nullptr, toJunction);
731 nullptr, fromJunction, toLane,
nullptr);
745 if (edges.size() > 0) {
747 edges.front()->getLaneByAllowedVClass(vClass),
nullptr, edges.back()->getLaneByAllowedVClass(vClass),
nullptr);
756 const int firstLaneIndex,
const int lastLaneIndex) {
758 std::vector<GNELane*> lanes;
759 if (edges.size() > 0) {
760 lanes.reserve(edges.size());
762 if ((firstLaneIndex >= 0) && (firstLaneIndex < (
int)edges.front()->getLanes().size())) {
763 lanes.push_back(edges.front()->getLanes().at(firstLaneIndex));
765 lanes.push_back(edges.front()->getLaneByAllowedVClass(vClass));
768 if (edges.size() > 1) {
770 for (
int i = 1; i < ((int)edges.size() - 1); i++) {
771 lanes.push_back(edges[i]->getLaneByAllowedVClass(vClass));
774 if ((lastLaneIndex >= 0) && (lastLaneIndex < (int)edges.back()->getLanes().size())) {
775 lanes.push_back(edges.back()->getLanes().at(lastLaneIndex));
777 lanes.push_back(edges.back()->getLaneByAllowedVClass(vClass));
791 if (lanes.size() > 0) {
793 std::vector<Segment*> segments;
795 const int lastIndex = ((int)lanes.size() - 1);
797 segments.reserve(2 * lanes.size());
799 for (
int i = 0; i < (int)lanes.size(); i++) {
801 new Segment(
this, pathElement, lanes.at(i), segments);
803 if (i != lastIndex) {
805 new Segment(
this, pathElement, lanes.at(i)->getParentEdge()->getToJunction(), segments);
811 myPaths[pathElement] = segments;
821 for (
const auto& segment :
myPaths.at(pathElement)) {
837 if (segment->getPathElement()->isPathElementSelected()) {
839 segment->getPathElement()->drawLanePartialGL(s, segment, 2);
841 if (segment->getPathElement()->isRoute()) {
848 if (!segment->getPathElement()->isPathElementSelected()) {
850 segment->getPathElement()->drawLanePartialGL(s, segment, 0);
852 if (segment->getPathElement()->isRoute()) {
871 if (segment->getPathElement()->isPathElementSelected()) {
872 segment->getPathElement()->drawJunctionPartialGL(s, segment, 0);
877 if (!segment->getPathElement()->isPathElementSelected()) {
878 segment->getPathElement()->drawJunctionPartialGL(s, segment, 0);
887 for (
const auto& segment :
myPaths.at(pathElement)) {
888 if (segment->getLane()) {
890 }
else if (segment->getJunction()) {
900 std::vector<PathElement*> pathElementsToCompute;
905 pathElementsToCompute.push_back(segment->getPathElement());
909 for (
const auto& pathElement : pathElementsToCompute) {
910 pathElement->computePathElement();
918 std::vector<PathElement*> pathElementsToCompute;
923 pathElementsToCompute.push_back(segment->getPathElement());
927 for (
const auto& pathElement : pathElementsToCompute) {
928 pathElement->computePathElement();
938 for (
const auto& path :
myPaths) {
940 for (
const auto& segment : path.second) {
969 auto lane = segment->
getLane();
995 std::vector<NBEdge::Connection>::const_iterator con_it = find_if(
996 connections.begin(), connections.end(),
999 return (con_it != connections.end());
1009 std::vector<Segment*> segments;
1011 if (path.size() > 0) {
1013 const int lastIndex = ((int)path.size() - 1);
1015 segments.reserve(2 * path.size());
1018 new Segment(
this, pathElement, fromJunction, segments);
1021 for (
int i = 0; i < (int)path.size(); i++) {
1022 if ((i == 0) && fromLane) {
1024 new Segment(
this, pathElement, fromLane, segments);
1026 if (i != lastIndex) {
1028 new Segment(
this, pathElement, path.at(i)->getToJunction(), segments);
1030 }
else if ((i == lastIndex) && toLane) {
1032 new Segment(
this, pathElement, toLane, segments);
1035 const GNELane* lane = path.at(i)->getLaneByAllowedVClass(vClass);
1037 new Segment(
this, pathElement, lane, segments);
1039 if (i != lastIndex) {
1041 new Segment(
this, pathElement, path.at(i)->getToJunction(), segments);
1047 new Segment(
this, pathElement, toJunction, segments);
1052 myPaths[pathElement] = segments;
1055 Segment* firstSegment =
nullptr;
1056 Segment* lastSegment =
nullptr;
1059 firstSegment =
new Segment(
this, pathElement, fromLane, segments);
1060 }
else if (fromJunction) {
1061 firstSegment =
new Segment(
this, pathElement, fromJunction, segments);
1064 lastSegment =
new Segment(
this, pathElement, toLane, segments);
1065 }
else if (toJunction) {
1066 lastSegment =
new Segment(
this, pathElement, toJunction, segments);
1069 if (firstSegment && lastSegment) {
1073 myPaths[pathElement] = segments;
1075 delete firstSegment;
1085 std::vector<Segment*> laneSegments;
1086 laneSegments.reserve(segments.size());
1087 for (
const auto& segment : segments) {
1088 if (segment->getLane()) {
1089 laneSegments.push_back(segment);
1093 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
class used for path elements
bool isDataElement() const
check if pathElement is a data element
bool isDemandElement() const
check if pathElement is a demand element
bool isNetworkElement() const
check if pathElement is a network element
virtual ~PathElement()
destructor
bool isAdditionalElement() const
check if pathElement is an additional element
bool isRoute() const
check if pathElement is a route
PathElement()=delete
invalidate default constructor
const GNELane * getPreviousLane() const
get previous lane
Segment * myNextSegment
pointer to next segment (use for draw red line)
PathElement * getPathElement() const
get path element
Segment * getPreviousSegment() const
get previous segment
GNEContour * getContour() const
getcontour associated with segment
GNEPathManager * myPathManager
path manager
const GNEJunction * getJunction() const
get junction associated with this segment
const GNELane * getNextLane() const
get next lane
Segment * myPreviousSegment
pointer to previous segment (use for draw red line)
bool isLabelSegment() const
check if segment is label segment
void markSegmentLabel()
mark segment as middle segment
Segment()
default constructor
Segment * getNextSegment() const
get next segment
const GNELane * getLane() const
get lane associated with this segment
bool isLastSegment() const
check if segment is the last path's segment
bool isFirstSegment() const
check if segment is the first path's segment
PathCalculator * getPathCalculator()
obtain instance of PathCalculator
const std::vector< Segment * > & getPathElementSegments(PathElement *pathElement) const
get path segments
const std::vector< Segment * > myEmptySegments
empty segments (used in getPathElementSegments)
void addSegmentInJunctionSegments(Segment *segment, const GNEJunction *junction)
add segments int junctionSegments (called by Segment constructor)
std::map< const GNEJunction *, std::set< Segment * > > myJunctionSegments
map with junction segments
void invalidateJunctionPath(const GNEJunction *junction)
invalidate junction path
const PathElement * getPathElement(const GUIGlObject *GLObject) const
get path element
PathDraw * getPathDraw()
obtain instance of PathDraw
void clearSegments()
clear segments
void addPathElementToRedrawBuffer(const GNEPathManager::PathElement *pathElement) const
add path elements to redraw buffer
void markLabelSegment(const std::vector< Segment * > &segments) const
mark label segment
PathCalculator * myPathCalculator
PathCalculator instance.
void invalidateLanePath(const GNELane *lane)
invalidate lane path
void addSegmentInLaneSegments(Segment *segment, const GNELane *lane)
add segments int laneSegments (called by Segment constructor)
bool connectedLanes(const GNELane *fromLane, const GNELane *toLane) const
check if given lanes are connected
std::map< const PathElement *, std::vector< Segment * > > myPaths
map with path element and their associated segments
void removePath(PathElement *pathElement)
remove path
void drawLanePathElements(const GUIVisualizationSettings &s, const GNELane *lane) const
draw lane path elements
std::map< const GNELane *, std::set< Segment * > > myLaneSegments
map with lane segments
void drawJunctionPathElements(const GUIVisualizationSettings &s, const GNEJunction *junction) const
draw junction path elements
void clearSegmentFromJunctionAndLaneSegments(Segment *segment)
clear segments from junction and lane Segments (called by Segment destructor)
bool myCleaningSegments
flag for clear segments quickly
void calculateConsecutivePathEdges(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > &edges, const int firstLaneIndex=-1, const int lastLaneIndex=-1)
calculate consecutive path edges
PathDraw * myPathDraw
PathDraw instance.
void buildPath(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > path, GNELane *fromLane, GNEJunction *fromJunction, GNELane *toLane, GNEJunction *toJunction)
build path
~GNEPathManager()
destructor
const GNELane * getFirstLane(const PathElement *pathElement) const
get first lane associated with path element
void calculateConsecutivePathLanes(PathElement *pathElement, const std::vector< GNELane * > &lanes)
calculate consecutive path lanes
GNEPathManager(const GNENet *net)
constructor
bool isPathValid(const PathElement *pathElement) const
check if path element is valid
void calculatePath(PathElement *pathElement, SUMOVehicleClass vClass, GNELane *fromLane, GNELane *toLane)
calculate path between from-to edges (using dijkstra, require path calculator updated)
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
void addToRedrawObjects(const GUIGlObject *GLObject)
get redrawing objects
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)