39 const bool firstSegment,
const bool lastSegment) :
40 myPathManager(pathManager),
41 myPathElement(element),
42 myFirstSegment(firstSegment),
43 myLastSegment(lastSegment),
45 myPreviousLane(nullptr),
48 myNextSegment(nullptr),
49 myPreviousSegment(nullptr),
50 myLabelSegment(false) {
58 myPathManager(pathManager),
59 myPathElement(element),
60 myFirstSegment(false),
63 myPreviousLane(previousLane),
66 myNextSegment(nullptr),
67 myPreviousSegment(nullptr),
68 myLabelSegment(false) {
76 myPathManager->clearSegmentFromJunctionAndLaneSegments(
this);
83 return myFirstSegment;
85 throw ProcessError(
"Invalid call: Only allowed in lane segments");
95 throw ProcessError(
"Invalid call: Only allowed in lane segments");
102 return myPathElement;
115 return myPreviousLane;
117 throw ProcessError(
"Invalid call: Only allowed in junction segments");
127 throw ProcessError(
"Invalid call: Only allowed in junction segments");
140 return myNextSegment;
146 myNextSegment = nextSegment;
152 return myPreviousSegment;
158 myPreviousSegment = previousSegment;
164 return myLabelSegment;
170 myLabelSegment =
true;
175 myPathManager(nullptr),
176 myPathElement(nullptr),
177 myFirstSegment(false),
178 myLastSegment(false),
180 myPreviousLane(nullptr),
183 myNextSegment(nullptr),
184 myPreviousSegment(nullptr),
185 myLabelSegment(false) {
203 return (myOption & PathElement::Options::NETWORK_ELEMENT) != 0;
209 return (myOption & PathElement::Options::ADDITIONAL_ELEMENT) != 0;
215 return (myOption & PathElement::Options::DEMAND_ELEMENT) != 0;
221 return (myOption & PathElement::Options::DATA_ELEMENT) != 0;
227 return (myOption & PathElement::Options::ROUTE) != 0;
236 myPathCalculatorUpdated(false),
237 myDijkstraRouter(nullptr) {
246 delete myDijkstraRouter;
253 if (myDijkstraRouter) {
254 delete myDijkstraRouter;
257 myNet->getNetBuilder()->getEdgeCont().getAllRouterEdges(),
260 myPathCalculatorUpdated =
true;
267 std::vector<GNEEdge*> solution;
269 if (partialEdges.size() == 0) {
274 if (!myPathCalculatorUpdated) {
276 solution = partialEdges;
279 if (partialEdges.size() == 1) {
281 solution.push_back(partialEdges.front());
285 NBVehicle tmpVehicle(
"temporalNBVehicle", vClass);
287 GNENet* net = partialEdges.front()->getNet();
289 for (
int i = 1; i < (int)partialEdges.size(); i++) {
291 std::vector<const NBRouterEdge*> partialRoute;
292 myDijkstraRouter->compute(partialEdges.at(i - 1)->getNBEdge(), partialEdges.at(i)->getNBEdge(), &tmpVehicle, 10, partialRoute);
294 for (
const auto& edgeID : partialRoute) {
300 auto solutionIt = solution.begin();
302 while (solutionIt != solution.end()) {
303 if ((solutionIt + 1) != solution.end()) {
305 if (*solutionIt == *(solutionIt + 1)) {
306 solutionIt = solution.erase(solutionIt);
320 std::vector<GNEEdge*> edges;
325 for (
const auto& fromEdge : fromEdges) {
326 for (
const auto& toEdge : toEdges) {
327 edges = calculateDijkstraPath(vClass, {fromEdge, toEdge});
329 if (edges.size() > 0) {
330 return optimizeJunctionPath(edges);
342 for (
const auto& lane : edge.second->getLanes()) {
343 lane->resetReachability();
349 std::map<GNEEdge*, double> reachableEdges;
351 reachableEdges[originEdge] = 0;
353 std::vector<GNEEdge*> check;
355 check.push_back(originEdge);
357 while (check.size() > 0) {
359 check.erase(check.begin());
360 double traveltime = reachableEdges[edge];
361 for (
const auto& lane : edge->
getLanes()) {
368 std::vector<GNEEdge*> sucessors;
372 if (consecutiveEdgesConnected(vClass, edge, sucessorEdge)) {
373 sucessors.push_back(sucessorEdge);
377 for (
const auto& nextEdge : sucessors) {
379 if ((reachableEdges.count(nextEdge) == 0) || (reachableEdges[nextEdge] > traveltime)) {
380 reachableEdges[nextEdge] = traveltime;
381 check.push_back(nextEdge);
391 if ((from ==
nullptr) || (to ==
nullptr)) {
394 }
else if (from == to) {
402 for (
const auto& fromLane : from->
getLanes()) {
405 for (
const auto& toLane : to->
getLanes()) {
406 if (fromConnection->getLaneTo() == toLane) {
411 if (((NBFromLane.
permissions & vClass) == vClass) &&
430 if ((busStop->
getParentLanes().front()->getParentEdge() == edge) &&
436 std::vector<GNELane*> pedestrianLanes;
437 for (
int laneIndex = 0; laneIndex < (int)edge->
getLanes().size(); laneIndex++) {
439 pedestrianLanes.push_back(edge->
getLanes().at(laneIndex));
446 for (
const auto& lane : pedestrianLanes) {
447 if (access->getParentLanes().front() == lane) {
461 return myPathCalculatorUpdated;
467 myPathCalculatorUpdated =
false;
474 std::vector<GNEEdge*> solutionA, solutionB;
476 const auto fromJunction = edges.front()->getFromJunction();
477 const auto toJunction = edges.back()->getToJunction();
479 for (
auto it = edges.rbegin(); (it != edges.rend()) && !stop; it++) {
480 solutionA.insert(solutionA.begin(), *it);
481 if ((*it)->getFromJunction() == fromJunction) {
487 for (
auto it = solutionA.begin(); (it != solutionA.end()) && !stop; it++) {
488 solutionB.push_back(*it);
489 if ((*it)->getToJunction() == toJunction) {
509 myLaneDrawedElements.clear();
510 myLane2laneDrawedElements.clear();
522 }
else if (myLaneDrawedElements.count(lane) > 0) {
524 if (myLaneDrawedElements.at(lane).count(tag) > 0) {
529 myLaneDrawedElements.at(lane).insert(tag);
535 myLaneDrawedElements[lane].insert(tag);
552 const std::pair<const GNELane*, const GNELane*> lane2lane(fromLane, toLane);
554 if (myLane2laneDrawedElements.count(lane2lane) > 0) {
556 if (myLane2laneDrawedElements.at(lane2lane).count(tag) > 0) {
561 myLane2laneDrawedElements.at(lane2lane).insert(tag);
567 myLane2laneDrawedElements[lane2lane].insert(tag);
604 if (pathElement ==
nullptr) {
608 auto it =
myPaths.find(pathElement);
627 if (
myPaths.count(pathElement) > 0) {
629 if (
myPaths.at(pathElement).size() > 0) {
631 return (
myPaths.at(pathElement).front()->getNextSegment() ==
nullptr);
643 if ((
myPaths.count(pathElement) > 0) && (
myPaths.at(pathElement).size() > 0)) {
644 return myPaths.at(pathElement).front()->getLane();
656 for (
const auto& segment :
myPaths.at(pathElement)) {
663 if (edges.size() > 0) {
665 std::vector<Segment*> segments;
667 std::vector<Segment*> laneSegments;
671 if (path.size() > 0) {
673 segments.reserve(2 * (
int)path.size() - 1);
674 laneSegments.reserve(path.size());
676 for (
int i = 0; i < (int)path.size(); i++) {
678 const bool firstSegment = (i == 0);
679 const bool lastSegment = (i == ((int)path.size() - 1));
681 const GNELane* lane = path.at(i)->getLaneByAllowedVClass(vClass);
683 Segment* laneSegment =
new Segment(
this, pathElement, lane, firstSegment, lastSegment);
685 segments.push_back(laneSegment);
686 laneSegments.push_back(laneSegment);
690 const GNELane* nextLane = path.at(i + 1)->getLaneByAllowedVClass(vClass);
692 Segment* junctionSegment =
new Segment(
this, pathElement, path.at(i)->getParentJunctions().at(1), lane, nextLane);
694 segments.push_back(junctionSegment);
698 const int laneSegmentIndex = (int)((
double)laneSegments.size() * 0.5);
700 laneSegments.at(laneSegmentIndex)->markSegmentLabel();
703 Segment* firstSegment =
new Segment(
this, pathElement, edges.front()->getLaneByAllowedVClass(vClass),
true,
false);
707 segments.push_back(firstSegment);
709 Segment* lastSegment =
new Segment(
this, pathElement, edges.back()->getLaneByAllowedVClass(vClass),
false,
true);
711 segments.push_back(lastSegment);
717 myPaths[pathElement] = segments;
725 std::vector<GNEEdge*> edges;
727 edges.reserve(lanes.size());
729 for (
const auto& lane : lanes) {
730 edges.push_back(lane->getParentEdge());
742 if (junctionPath.size() > 0) {
752 std::vector<GNELane*> lanes;
754 lanes.reserve(edges.size());
756 for (
const auto& edge : edges) {
757 lanes.push_back(edge->getLaneByAllowedVClass(vClass));
769 for (
const auto& segment :
myPaths.at(pathElement)) {
776 if (lanes.size() > 0) {
778 std::vector<Segment*> segments;
780 std::vector<Segment*> laneSegments;
782 segments.reserve(2 * (
int)lanes.size() - 1);
783 laneSegments.reserve(lanes.size());
785 for (
int i = 0; i < (int)lanes.size(); i++) {
787 const bool firstSegment = (i == 0);
788 const bool lastSegment = (i == ((int)lanes.size() - 1));
790 Segment* laneSegment =
new Segment(
this, pathElement, lanes.at(i), firstSegment, lastSegment);
792 segments.push_back(laneSegment);
793 laneSegments.push_back(laneSegment);
797 const GNELane* nextLane = lanes.at(i + 1);
799 Segment* junctionSegment =
new Segment(
this, pathElement, lanes.at(i)->getParentEdge()->getParentJunctions().at(1), lanes.at(i), nextLane);
801 segments.push_back(junctionSegment);
805 const int laneSegmentIndex = (int)((
double)laneSegments.size() * 0.5);
807 laneSegments.at(laneSegmentIndex)->markSegmentLabel();
809 myPaths[pathElement] = segments;
819 for (
const auto& segment :
myPaths.at(pathElement)) {
834 segment->getPathElement()->drawPartialGL(s, lane, segment, 0);
836 if (segment->getPathElement()->isRoute()) {
852 segment->getPathElement()->drawPartialGL(s, segment->getPreviousLane(), segment->getNextLane(), segment, 0);
862 for (
const auto& segment : laneSegment.second) {
863 if (segment->getPathElement() == pathElement) {
864 pathElement->
drawPartialGL(s, laneSegment.first, segment, 0);
870 for (
const auto& segment : junctionSegment.second) {
871 if (segment->getPathElement() == pathElement) {
872 segment->getPathElement()->drawPartialGL(s, segment->getPreviousLane(), segment->getNextLane(), segment, 0);
882 std::vector<PathElement*> pathElementsToCompute;
887 pathElementsToCompute.push_back(segment->getPathElement());
891 for (
const auto& pathElement : pathElementsToCompute) {
892 pathElement->computePathElement();
900 std::vector<PathElement*> pathElementsToCompute;
905 pathElementsToCompute.push_back(segment->getPathElement());
909 for (
const auto& pathElement : pathElementsToCompute) {
910 pathElement->computePathElement();
921 if (it->first->isDemandElement()) {
923 for (
const auto& segment : it->second) {
976 for (
const auto& path :
myPaths) {
978 for (
const auto& segment : path.second) {
995 std::vector<NBEdge::Connection>::const_iterator con_it = find_if(
996 connections.begin(), connections.end(),
999 return (con_it != connections.end());
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
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...
std::vector< GNEEdge * > calculateDijkstraPath(const SUMOVehicleClass vClass, const std::vector< GNEEdge * > &partialEdges) const
calculate Dijkstra path between a list of partial edges
const GNENet * myNet
pointer to net
class used to mark path draw
bool drawPathGeometry(const bool dottedElement, 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
virtual void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *lane, const GNEPathManager::Segment *segment, const double offsetFront) const =0
Draws partial object (lane)
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
PathElement * getPathElement() const
get path element
Segment * getPreviousSegment() const
get previous segment
void setNextSegment(Segment *nexSegment)
set next segment
void setPreviousSegment(Segment *nexSegment)
set previous segment
GNEPathManager * myPathManager
path manager
const GNEJunction * getJunction() const
get junction associated with this segment
const GNELane * getNextLane() const
get next lane
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
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
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
void calculatePathJunctions(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEJunction * > junctions)
calculate path junctions (using dijkstra, require path calculator updated)
std::map< const PathElement *, std::vector< Segment * > > myPaths
map with path element and their associated segments
void drawLanePathElements(const GUIVisualizationSettings &s, const GNELane *lane)
draw lane path elements
void removePath(PathElement *pathElement)
remove path
std::map< const GNELane *, std::set< Segment * > > myLaneSegments
map with lane segments
void clearSegmentFromJunctionAndLaneSegments(Segment *segment)
clear segments from junction and lane Segments (called by Segment destructor)
PathDraw * myPathDraw
PathDraw instance.
void calculatePathEdges(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > edges)
calculate path edges (using dijkstra, require path calculator updated)
void drawJunctionPathElements(const GUIVisualizationSettings &s, const GNEJunction *junction)
draw junction path elements
void forceDrawPath(const GUIVisualizationSettings &s, const PathElement *pathElement) const
force draw path (used carefully, ONLY when we're inspecting a path element, due slowdowns)
~GNEPathManager()
destructor
const GNELane * getFirstLane(const PathElement *pathElement) const
get first lane associated with path element
void calculatePathLanes(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNELane * > lanes)
calculate path lanes (using dijkstra, require path calculator updated)
GNEPathManager(const GNENet *net)
constructor
bool isPathValid(const PathElement *pathElement) const
check if path element is valid
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
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
Stores the information about how to visualize structures.
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
RouterEdgeVector getAllRouterEdges() const
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, 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)