40 const bool firstSegment,
const bool lastSegment) :
41 myPathManager(pathManager),
42 myPathElement(element),
43 myFirstSegment(firstSegment),
44 myLastSegment(lastSegment),
46 myPreviousLane(nullptr),
49 myNextSegment(nullptr),
50 myPreviousSegment(nullptr),
51 myLabelSegment(false) {
59 myPathManager(pathManager),
60 myPathElement(element),
61 myFirstSegment(false),
64 myPreviousLane(previousLane),
67 myNextSegment(nullptr),
68 myPreviousSegment(nullptr),
69 myLabelSegment(false) {
77 myPathManager->clearSegmentFromJunctionAndLaneSegments(
this);
84 return myFirstSegment;
86 throw ProcessError(
"Invalid call: Only allowed in lane segments");
96 throw ProcessError(
"Invalid call: Only allowed in lane segments");
103 return myPathElement;
116 return myPreviousLane;
118 throw ProcessError(
"Invalid call: Only allowed in junction segments");
128 throw ProcessError(
"Invalid call: Only allowed in junction segments");
141 return myNextSegment;
147 myNextSegment = nextSegment;
153 return myPreviousSegment;
159 myPreviousSegment = previousSegment;
165 return myLabelSegment;
171 myLabelSegment =
true;
176 myPathManager(nullptr),
177 myPathElement(nullptr),
178 myFirstSegment(false),
179 myLastSegment(false),
181 myPreviousLane(nullptr),
184 myNextSegment(nullptr),
185 myPreviousSegment(nullptr) {
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;
240 myPathCalculatorUpdated(false),
241 myDijkstraRouter(nullptr) {
250 delete myDijkstraRouter;
257 if (myDijkstraRouter) {
258 delete myDijkstraRouter;
261 myNet->getNetBuilder()->getEdgeCont().getAllRouterEdges(),
264 myPathCalculatorUpdated =
true;
268 std::vector<GNEEdge*>
271 std::vector<GNEEdge*> solution;
273 if (partialEdges.size() == 0) {
278 if (!myPathCalculatorUpdated) {
280 solution = partialEdges;
283 if (partialEdges.size() == 1) {
285 solution.push_back(partialEdges.front());
289 NBVehicle tmpVehicle(
"temporalNBVehicle", vClass);
291 GNENet* net = partialEdges.front()->getNet();
293 for (
int i = 1; i < (int)partialEdges.size(); i++) {
295 std::vector<const NBRouterEdge*> partialRoute;
296 myDijkstraRouter->compute(partialEdges.at(i - 1)->getNBEdge(), partialEdges.at(i)->getNBEdge(), &tmpVehicle, 10, partialRoute);
298 for (
const auto& edgeID : partialRoute) {
304 auto solutionIt = solution.begin();
306 while (solutionIt != solution.end()) {
307 if ((solutionIt + 1) != solution.end()) {
309 if (*solutionIt == *(solutionIt + 1)) {
310 solutionIt = solution.erase(solutionIt);
322 std::vector<GNEEdge*>
325 return std::vector<GNEEdge*> ();
334 for (
const auto& lane : edge.second->getLanes()) {
335 lane->resetReachability();
341 std::map<GNEEdge*, double> reachableEdges;
343 reachableEdges[originEdge] = 0;
345 std::vector<GNEEdge*> check;
347 check.push_back(originEdge);
349 while (check.size() > 0) {
351 check.erase(check.begin());
352 double traveltime = reachableEdges[edge];
353 for (
const auto& lane : edge->
getLanes()) {
360 std::vector<GNEEdge*> sucessors;
364 if (consecutiveEdgesConnected(vClass, edge, sucessorEdge)) {
365 sucessors.push_back(sucessorEdge);
369 for (
const auto& nextEdge : sucessors) {
371 if ((reachableEdges.count(nextEdge) == 0) || (reachableEdges[nextEdge] > traveltime)) {
372 reachableEdges[nextEdge] = traveltime;
373 check.push_back(nextEdge);
383 if ((from ==
nullptr) || (to ==
nullptr)) {
386 }
else if (from == to) {
394 for (
const auto& fromLane : from->
getLanes()) {
397 for (
const auto& toLane : to->
getLanes()) {
398 if (fromConnection->getLaneTo() == toLane) {
403 if (((NBFromLane.
permissions & vClass) == vClass) &&
422 if ((busStop->
getParentLanes().front()->getParentEdge() == edge) &&
428 std::vector<GNELane*> pedestrianLanes;
429 for (
int laneIndex = 0; laneIndex < (int)edge->
getLanes().size(); laneIndex++) {
431 pedestrianLanes.push_back(edge->
getLanes().at(laneIndex));
438 for (
const auto& lane : pedestrianLanes) {
439 if (access->getParentLanes().front() == lane) {
453 return myPathCalculatorUpdated;
459 myPathCalculatorUpdated =
false;
475 myLaneDrawedElements.clear();
476 myLane2laneDrawedElements.clear();
488 }
else if (myLaneDrawedElements.count(lane) > 0) {
490 if (myLaneDrawedElements.at(lane).count(tag) > 0) {
495 myLaneDrawedElements.at(lane).insert(tag);
501 myLaneDrawedElements[lane].insert(tag);
518 const std::pair<const GNELane*, const GNELane*> lane2lane(fromLane, toLane);
520 if (myLane2laneDrawedElements.count(lane2lane) > 0) {
522 if (myLane2laneDrawedElements.at(lane2lane).count(tag) > 0) {
527 myLane2laneDrawedElements.at(lane2lane).insert(tag);
533 myLane2laneDrawedElements[lane2lane].insert(tag);
575 if (
myPaths.count(pathElement) > 0) {
577 if (
myPaths.at(pathElement).size() > 0) {
579 return (
myPaths.at(pathElement).front()->getNextSegment() ==
nullptr);
591 if ((
myPaths.count(pathElement) > 0) && (
myPaths.at(pathElement).size() > 0)) {
592 return myPaths.at(pathElement).front()->getLane();
604 for (
const auto& segment :
myPaths.at(pathElement)) {
611 if (edges.size() > 0) {
613 std::vector<Segment*> segments;
615 std::vector<Segment*> laneSegments;
619 if (path.size() > 0) {
621 segments.reserve(2 * (
int)path.size() - 1);
622 laneSegments.reserve(path.size());
624 for (
int i = 0; i < (int)path.size(); i++) {
626 const bool firstSegment = (i == 0);
627 const bool lastSegment = (i == ((int)path.size() - 1));
629 const GNELane* lane = path.at(i)->getLaneByAllowedVClass(vClass);
631 Segment* laneSegment =
new Segment(
this, pathElement, lane, firstSegment, lastSegment);
633 segments.push_back(laneSegment);
634 laneSegments.push_back(laneSegment);
638 const GNELane* nextLane = path.at(i + 1)->getLaneByAllowedVClass(vClass);
640 Segment* junctionSegment =
new Segment(
this, pathElement, path.at(i)->getParentJunctions().at(1), lane, nextLane);
642 segments.push_back(junctionSegment);
646 const int laneSegmentIndex = (int)((
double)laneSegments.size() * 0.5);
648 laneSegments.at(laneSegmentIndex)->markSegmentLabel();
651 Segment* firstSegment =
new Segment(
this, pathElement, edges.front()->getLaneByAllowedVClass(vClass),
true,
false);
655 segments.push_back(firstSegment);
657 Segment* lastSegment =
new Segment(
this, pathElement, edges.back()->getLaneByAllowedVClass(vClass),
false,
true);
659 segments.push_back(lastSegment);
665 myPaths[pathElement] = segments;
673 std::vector<GNEEdge*> edges;
675 edges.reserve(lanes.size());
677 for (
const auto& lane : lanes) {
678 edges.push_back(lane->getParentEdge());
688 std::vector<GNELane*> lanes;
690 lanes.reserve(edges.size());
692 for (
const auto& edge : edges) {
693 lanes.push_back(edge->getLaneByAllowedVClass(vClass));
705 for (
const auto& segment :
myPaths.at(pathElement)) {
712 if (lanes.size() > 0) {
714 std::vector<Segment*> segments;
716 std::vector<Segment*> laneSegments;
718 segments.reserve(2 * (
int)lanes.size() - 1);
719 laneSegments.reserve(lanes.size());
721 for (
int i = 0; i < (int)lanes.size(); i++) {
723 const bool firstSegment = (i == 0);
724 const bool lastSegment = (i == ((int)lanes.size() - 1));
726 Segment* laneSegment =
new Segment(
this, pathElement, lanes.at(i), firstSegment, lastSegment);
728 segments.push_back(laneSegment);
729 laneSegments.push_back(laneSegment);
733 const GNELane* nextLane = lanes.at(i + 1);
735 Segment* junctionSegment =
new Segment(
this, pathElement, lanes.at(i)->getParentEdge()->getParentJunctions().at(1), lanes.at(i), nextLane);
737 segments.push_back(junctionSegment);
741 const int laneSegmentIndex = (int)((
double)laneSegments.size() * 0.5);
743 laneSegments.at(laneSegmentIndex)->markSegmentLabel();
745 myPaths[pathElement] = segments;
755 for (
const auto& segment :
myPaths.at(pathElement)) {
770 segment->getPathElement()->drawPartialGL(s, lane, segment, 0);
772 if (segment->getPathElement()->isRoute()) {
788 segment->getPathElement()->drawPartialGL(s, segment->getPreviousLane(), segment->getNextLane(), segment, 0);
798 for (
const auto& segment : laneSegment.second) {
799 if (segment->getPathElement() == pathElement) {
800 pathElement->
drawPartialGL(s, laneSegment.first, segment, 0);
810 std::vector<PathElement*> pathElementsToCompute;
815 pathElementsToCompute.push_back(segment->getPathElement());
819 for (
const auto& pathElement : pathElementsToCompute) {
820 pathElement->computePathElement();
828 std::vector<PathElement*> pathElementsToCompute;
833 pathElementsToCompute.push_back(segment->getPathElement());
837 for (
const auto& pathElement : pathElementsToCompute) {
838 pathElement->computePathElement();
849 if (it->first->isDemandElement()) {
851 for (
const auto& segment : it->second) {
904 for (
const auto& path :
myPaths) {
906 for (
const auto& segment : path.second) {
923 std::vector<NBEdge::Connection>::const_iterator con_it = find_if(
924 connections.begin(), connections.end(),
927 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 belongs to GNENet but has influency 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 * > & 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 arent 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 consecutives 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
~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
PathElement()
default constructor
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
bool isAdditionalElement() const
check if pathElement is an additional element
bool isRoute() const
check if pathElement is a route
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
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
std::map< const PathElement *, std::vector< Segment * > > myPaths
map with path element and their asociated 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
GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings
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.
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.
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].