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 myPathManager->clearSegmentFromJunctionAndLaneSegments(
this);
86 if (myPreviousSegment) {
87 myPreviousSegment->myNextSegment =
nullptr;
90 myNextSegment->myPreviousSegment =
nullptr;
105 return (myPreviousSegment ==
nullptr);
111 return (myNextSegment ==
nullptr);
117 return myPathElement;
129 if (myPreviousSegment) {
130 return myPreviousSegment->getLane();
140 return myNextSegment->getLane();
155 return myNextSegment;
161 return myPreviousSegment;
167 return myLabelSegment;
173 myLabelSegment =
true;
178 myPathManager(nullptr),
179 myPathElement(nullptr),
182 myNextSegment(nullptr),
183 myPreviousSegment(nullptr),
184 myLabelSegment(false) {
202 return (myOption & PathElement::Options::NETWORK_ELEMENT) != 0;
208 return (myOption & PathElement::Options::ADDITIONAL_ELEMENT) != 0;
214 return (myOption & PathElement::Options::DEMAND_ELEMENT) != 0;
220 return (myOption & PathElement::Options::DATA_ELEMENT) != 0;
226 return (myOption & PathElement::Options::ROUTE) != 0;
235 myPathCalculatorUpdated(false),
236 myDijkstraRouter(nullptr) {
245 delete myDijkstraRouter;
252 if (myDijkstraRouter) {
253 delete myDijkstraRouter;
256 myNet->getNetBuilder()->getEdgeCont().getAllRouterEdges(),
259 myPathCalculatorUpdated =
true;
263 std::vector<GNEEdge*>
266 std::vector<GNEEdge*> solution;
268 if (!myPathCalculatorUpdated) {
274 if (edges.size() == 0) {
277 }
else if (edges.size() == 1) {
279 solution.push_back(edges.front());
281 }
else if ((edges.size() == 2) && (edges.front() == edges.back())) {
283 solution.push_back(edges.front());
287 NBVehicle tmpVehicle(
"temporalNBVehicle", vClass);
289 GNENet* net = edges.front()->getNet();
291 for (
int i = 1; i < (int)edges.size(); i++) {
293 if (edges.at(i - 1)->getNBEdge() != edges.at(i)->getNBEdge()) {
295 std::vector<const NBRouterEdge*> partialRoute;
296 myDijkstraRouter->compute(edges.at(i - 1)->getNBEdge(), edges.at(i)->getNBEdge(), &tmpVehicle, 10, partialRoute);
298 if (partialRoute.empty()) {
302 for (
const auto& edgeID : partialRoute) {
310 auto solutionIt = solution.begin();
312 while (solutionIt != solution.end()) {
313 if ((solutionIt + 1) != solution.end()) {
315 if (*solutionIt == *(solutionIt + 1)) {
316 solutionIt = solution.erase(solutionIt);
328 std::vector<GNEEdge*>
330 return calculateDijkstraPath(vClass, {fromEdge, toEdge});
334 std::vector<GNEEdge*>
336 std::vector<GNEEdge*> edges;
340 for (
const auto& toEdge : toEdges) {
341 edges = calculateDijkstraPath(vClass, fromEdge, toEdge);
343 if (edges.size() > 0) {
344 return optimizeJunctionPath(edges);
351 std::vector<GNEEdge*>
353 std::vector<GNEEdge*> edges;
357 for (
const auto& fromEdge : fromEdges) {
358 edges = calculateDijkstraPath(vClass, fromEdge, toEdge);
360 if (edges.size() > 0) {
361 return optimizeJunctionPath(edges);
368 std::vector<GNEEdge*>
370 std::vector<GNEEdge*> edges;
375 for (
const auto& fromEdge : fromEdges) {
376 for (
const auto& toEdge : toEdges) {
377 edges = calculateDijkstraPath(vClass, fromEdge, toEdge);
379 if (edges.size() > 0) {
380 return optimizeJunctionPath(edges);
392 for (
const auto& lane : edge.second->getLanes()) {
393 lane->resetReachability();
399 std::map<GNEEdge*, double> reachableEdges;
401 reachableEdges[originEdge] = 0;
403 std::vector<GNEEdge*> check;
405 check.push_back(originEdge);
407 while (check.size() > 0) {
409 check.erase(check.begin());
410 double traveltime = reachableEdges[edge];
411 for (
const auto& lane : edge->
getLanes()) {
418 std::vector<GNEEdge*> sucessors;
422 if (consecutiveEdgesConnected(vClass, edge, sucessorEdge)) {
423 sucessors.push_back(sucessorEdge);
427 for (
const auto& nextEdge : sucessors) {
429 if ((reachableEdges.count(nextEdge) == 0) || (reachableEdges[nextEdge] > traveltime)) {
430 reachableEdges[nextEdge] = traveltime;
431 check.push_back(nextEdge);
441 if ((from ==
nullptr) || (to ==
nullptr)) {
444 }
else if (from == to) {
452 for (
const auto& fromLane : from->
getLanes()) {
455 for (
const auto& toLane : to->
getLanes()) {
456 if (fromConnection->getLaneTo() == toLane) {
461 if (((NBFromLane.
permissions & vClass) == vClass) &&
480 if ((busStop->
getParentLanes().front()->getParentEdge() == edge) &&
486 std::vector<GNELane*> pedestrianLanes;
487 for (
int laneIndex = 0; laneIndex < (int)edge->
getLanes().size(); laneIndex++) {
489 pedestrianLanes.push_back(edge->
getLanes().at(laneIndex));
496 for (
const auto& lane : pedestrianLanes) {
497 if (access->getParentLanes().front() == lane) {
511 return myPathCalculatorUpdated;
517 myPathCalculatorUpdated =
false;
521 std::vector<GNEEdge*>
524 std::vector<GNEEdge*> solutionA, solutionB;
526 const auto fromJunction = edges.front()->getFromJunction();
527 const auto toJunction = edges.back()->getToJunction();
529 for (
auto it = edges.rbegin(); (it != edges.rend()) && !stop; it++) {
530 solutionA.insert(solutionA.begin(), *it);
531 if ((*it)->getFromJunction() == fromJunction) {
537 for (
auto it = solutionA.begin(); (it != solutionA.end()) && !stop; it++) {
538 solutionB.push_back(*it);
539 if ((*it)->getToJunction() == toJunction) {
559 myLaneDrawedElements.clear();
560 myLane2laneDrawedElements.clear();
569 }
else if (myLaneDrawedElements.count(lane) > 0) {
571 if (myLaneDrawedElements.at(lane).count(tag) > 0) {
576 myLaneDrawedElements.at(lane).insert(tag);
582 myLaneDrawedElements[lane].insert(tag);
598 if (myLane2laneDrawedElements.count(lane2lane) > 0) {
600 if (myLane2laneDrawedElements.at(lane2lane).count(tag) > 0) {
605 myLane2laneDrawedElements.at(lane2lane).insert(tag);
611 myLane2laneDrawedElements[lane2lane].insert(tag);
648 if (pathElement ==
nullptr) {
652 auto it =
myPaths.find(pathElement);
662 const std::vector<GNEPathManager::Segment*>&
664 if (
myPaths.count(pathElement) > 0) {
665 return myPaths.at(pathElement);
681 if (
myPaths.count(pathElement) > 0) {
683 for (
const auto& segment :
myPaths.at(pathElement)) {
685 if (segment->getLane() && segment->getNextLane()) {
699 if ((
myPaths.count(pathElement) > 0) && (
myPaths.at(pathElement).size() > 0)) {
700 return myPaths.at(pathElement).front()->getLane();
712 fromLane,
nullptr, toLane,
nullptr);
720 fromLane,
nullptr,
nullptr, toJunction);
728 nullptr, fromJunction, toLane,
nullptr);
742 if (edges.size() > 0) {
744 edges.front()->getLaneByAllowedVClass(vClass),
nullptr, edges.back()->getLaneByAllowedVClass(vClass),
nullptr);
754 std::vector<GNELane*> lanes;
756 lanes.reserve(edges.size());
758 for (
const auto& edge : edges) {
759 lanes.push_back(edge->getLaneByAllowedVClass(vClass));
771 if (lanes.size() > 0) {
773 std::vector<Segment*> segments;
775 const int lastIndex = ((int)lanes.size() - 1);
777 segments.reserve(2 * lanes.size());
779 for (
int i = 0; i < (int)lanes.size(); i++) {
781 new Segment(
this, pathElement, lanes.at(i), segments);
783 if (i != lastIndex) {
785 new Segment(
this, pathElement, lanes.at(i)->getParentEdge()->getToJunction(), segments);
791 myPaths[pathElement] = segments;
801 for (
const auto& segment :
myPaths.at(pathElement)) {
817 if (segment->getPathElement()->isPathElementSelected()) {
819 segment->getPathElement()->drawLanePartialGL(s, segment, 2);
821 if (segment->getPathElement()->isRoute()) {
828 if (!segment->getPathElement()->isPathElementSelected()) {
830 segment->getPathElement()->drawLanePartialGL(s, segment, 0);
832 if (segment->getPathElement()->isRoute()) {
851 if (segment->getPathElement()->isPathElementSelected()) {
852 segment->getPathElement()->drawJunctionPartialGL(s, segment, 0);
857 if (!segment->getPathElement()->isPathElementSelected()) {
858 segment->getPathElement()->drawJunctionPartialGL(s, segment, 0);
869 for (
const auto& segment : laneSegment.second) {
870 if (segment->getPathElement() == pathElement) {
877 for (
const auto& segment : junctionSegment.second) {
878 if (segment->getPathElement() == pathElement) {
879 segment->getPathElement()->drawJunctionPartialGL(s, segment, 0);
889 std::vector<PathElement*> pathElementsToCompute;
894 pathElementsToCompute.push_back(segment->getPathElement());
898 for (
const auto& pathElement : pathElementsToCompute) {
899 pathElement->computePathElement();
907 std::vector<PathElement*> pathElementsToCompute;
912 pathElementsToCompute.push_back(segment->getPathElement());
916 for (
const auto& pathElement : pathElementsToCompute) {
917 pathElement->computePathElement();
928 if (it->first->isDemandElement()) {
930 for (
const auto& segment : it->second) {
958 auto lane = segment->
getLane();
962 if (*it == segment) {
978 if (*it == segment) {
995 for (
const auto& path :
myPaths) {
997 for (
const auto& segment : path.second) {
1014 std::vector<NBEdge::Connection>::const_iterator con_it = find_if(
1015 connections.begin(), connections.end(),
1018 return (con_it != connections.end());
1028 std::vector<Segment*> segments;
1030 if (path.size() > 0) {
1032 const int lastIndex = ((int)path.size() - 1);
1034 segments.reserve(2 * path.size());
1037 new Segment(
this, pathElement, fromJunction, segments);
1040 for (
int i = 0; i < (int)path.size(); i++) {
1041 if ((i == 0) && fromLane) {
1043 new Segment(
this, pathElement, fromLane, segments);
1045 if (i != lastIndex) {
1047 new Segment(
this, pathElement, path.at(i)->getToJunction(), segments);
1049 }
else if ((i == lastIndex) && toLane) {
1051 new Segment(
this, pathElement, toLane, segments);
1054 const GNELane* lane = path.at(i)->getLaneByAllowedVClass(vClass);
1056 new Segment(
this, pathElement, lane, segments);
1058 if (i != lastIndex) {
1060 new Segment(
this, pathElement, path.at(i)->getToJunction(), segments);
1066 new Segment(
this, pathElement, toJunction, segments);
1071 myPaths[pathElement] = segments;
1074 Segment* firstSegment =
nullptr;
1075 Segment* lastSegment =
nullptr;
1078 firstSegment =
new Segment(
this, pathElement, fromLane, segments);
1079 }
else if (fromJunction) {
1080 firstSegment =
new Segment(
this, pathElement, fromJunction, segments);
1083 lastSegment =
new Segment(
this, pathElement, toLane, segments);
1084 }
else if (toJunction) {
1085 lastSegment =
new Segment(
this, pathElement, toJunction, segments);
1088 if (firstSegment && lastSegment) {
1092 myPaths[pathElement] = segments;
1094 delete firstSegment;
1104 std::vector<Segment*> laneSegments;
1105 laneSegments.reserve(segments.size());
1106 for (
const auto& segment : segments) {
1107 if (segment->getLane()) {
1108 laneSegments.push_back(segment);
1112 const int laneSegmentIndex = (int)((
double)laneSegments.size() * 0.5);
1114 laneSegments.at(laneSegmentIndex)->markSegmentLabel();
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
GNEJunction * getToJunction() const
get from Junction (only used to increase readability)
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
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 path calculator (called when SuperModes Demand or Data is selected)
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
virtual void drawLanePartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const =0
Draws partial object over lane.
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)
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
std::map< const GNELane *, std::vector< Segment * > > myLaneSegments
map with lane segments
void markLabelSegment(const std::vector< Segment * > &segments) const
mark label segment
PathCalculator * myPathCalculator
PathCalculator instance.
void invalidateLanePath(const GNELane *lane)
invalidate lane path
void clearDemandPaths()
clear demand paths
void calculateConsecutivePathEdges(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > edges)
calculate consecutive path edges
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 GNEJunction *, std::vector< Segment * > > myJunctionSegments
map with junction 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)
PathDraw * myPathDraw
PathDraw instance.
void forceDrawPath(const GUIVisualizationSettings &s, const PathElement *pathElement) const
force draw path (used carefully, ONLY when we're inspecting a path element, due slowdowns)
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
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)
void calculateConsecutivePathLanes(PathElement *pathElement, const std::vector< GNELane * > lanes)
calculate consecutive path lanes
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
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.
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.
Lane & getLaneStruct(int 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)