Eclipse SUMO - Simulation of Urban MObility
GNEPathManager.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // Manager for paths in NETEDIT (routes, trips, flows...)
19 /****************************************************************************/
20 
21 #include <netbuild/NBEdgeCont.h>
22 #include <netbuild/NBNetBuilder.h>
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEViewNet.h>
27 
28 #include "GNEPathManager.h"
29 
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
35 // ---------------------------------------------------------------------------
36 // GNEPathManager::Segment - methods
37 // ---------------------------------------------------------------------------
38 
40  const bool firstSegment, const bool lastSegment) :
41  myPathManager(pathManager),
42  myPathElement(element),
43  myFirstSegment(firstSegment),
44  myLastSegment(lastSegment),
45  myLane(lane),
46  myPreviousLane(nullptr),
47  myNextLane(nullptr),
48  myJunction(nullptr),
49  myNextSegment(nullptr),
50  myPreviousSegment(nullptr),
51  myLabelSegment(false) {
52  // add segment in laneSegments
54 }
55 
56 
58  const GNELane* previousLane, const GNELane* nextLane) :
59  myPathManager(pathManager),
60  myPathElement(element),
61  myFirstSegment(false),
62  myLastSegment(false),
63  myLane(nullptr),
64  myPreviousLane(previousLane),
65  myNextLane(nextLane),
66  myJunction(junction),
67  myNextSegment(nullptr),
68  myPreviousSegment(nullptr),
69  myLabelSegment(false) {
70  // add segment in junctionSegments
72 }
73 
74 
76  // clear segment from LaneSegments
77  myPathManager->clearSegmentFromJunctionAndLaneSegments(this);
78 }
79 
80 
81 bool
83  if (myLane) {
84  return myFirstSegment;
85  } else {
86  throw ProcessError("Invalid call: Only allowed in lane segments");
87  }
88 }
89 
90 
91 bool
93  if (myLane) {
94  return myLastSegment;
95  } else {
96  throw ProcessError("Invalid call: Only allowed in lane segments");
97  }
98 }
99 
100 
103  return myPathElement;
104 }
105 
106 
107 const GNELane*
109  return myLane;
110 }
111 
112 
113 const GNELane*
115  if (myJunction) {
116  return myPreviousLane;
117  } else {
118  throw ProcessError("Invalid call: Only allowed in junction segments");
119  }
120 }
121 
122 
123 const GNELane*
125  if (myJunction) {
126  return myNextLane;
127  } else {
128  throw ProcessError("Invalid call: Only allowed in junction segments");
129  }
130 }
131 
132 
133 const GNEJunction*
135  return myJunction;
136 }
137 
138 
141  return myNextSegment;
142 }
143 
144 
145 void
147  myNextSegment = nextSegment;
148 }
149 
150 
153  return myPreviousSegment;
154 }
155 
156 
157 void
159  myPreviousSegment = previousSegment;
160 }
161 
162 
163 bool
165  return myLabelSegment;
166 }
167 
168 
169 void
171  myLabelSegment = true;
172 }
173 
174 
176  myPathManager(nullptr),
177  myPathElement(nullptr),
178  myFirstSegment(false),
179  myLastSegment(false),
180  myLane(nullptr),
181  myPreviousLane(nullptr),
182  myNextLane(nullptr),
183  myJunction(nullptr),
184  myNextSegment(nullptr),
185  myPreviousSegment(nullptr) {
186 }
187 
188 // ---------------------------------------------------------------------------
189 // GNEPathManager::PathElement - methods
190 // ---------------------------------------------------------------------------
191 
193  myOption(options) {
194 }
195 
196 
198 
199 
200 bool
202  return (myOption & PathElement::Options::NETWORK_ELEMENT) != 0;
203 }
204 
205 
206 bool
208  return (myOption & PathElement::Options::ADDITIONAL_ELEMENT) != 0;
209 }
210 
211 
212 bool
214  return (myOption & PathElement::Options::DEMAND_ELEMENT) != 0;
215 }
216 
217 
218 bool
220  return (myOption & PathElement::Options::DATA_ELEMENT) != 0;
221 }
222 
223 
224 bool
226  return (myOption & PathElement::Options::ROUTE) != 0;
227 }
228 
229 
231  myOption(PathElement::Options::NETWORK_ELEMENT) {
232 }
233 
234 // ---------------------------------------------------------------------------
235 // GNEPathManager::PathCalculator - methods
236 // ---------------------------------------------------------------------------
237 
239  myNet(net),
240  myPathCalculatorUpdated(false),
241  myDijkstraRouter(nullptr) {
242  // create myDijkstraRouter
245  true, &NBRouterEdge::getTravelTimeStatic, nullptr, true);
246 }
247 
248 
250  delete myDijkstraRouter;
251 }
252 
253 
254 void
256  // simply delete and create myDijkstraRouter again
257  if (myDijkstraRouter) {
258  delete myDijkstraRouter;
259  }
260  myDijkstraRouter = new DijkstraRouter<NBRouterEdge, NBVehicle>(
261  myNet->getNetBuilder()->getEdgeCont().getAllRouterEdges(),
262  true, &NBRouterEdge::getTravelTimeStatic, nullptr, true);
263  // update flag
264  myPathCalculatorUpdated = true;
265 }
266 
267 
268 std::vector<GNEEdge*>
269 GNEPathManager::PathCalculator::calculateDijkstraPath(const SUMOVehicleClass vClass, const std::vector<GNEEdge*>& partialEdges) const {
270  // declare a solution vector
271  std::vector<GNEEdge*> solution;
272  // calculate route depending of number of partial myEdges
273  if (partialEdges.size() == 0) {
274  // partial edges empty, then return a empty vector
275  return solution;
276  }
277  // check if path calculator is updated
278  if (!myPathCalculatorUpdated) {
279  // use partialEdges as solution
280  solution = partialEdges;
281  return solution;
282  }
283  if (partialEdges.size() == 1) {
284  // if there is only one partialEdges, route has only one edge
285  solution.push_back(partialEdges.front());
286  return solution;
287  } else {
288  // declare temporal vehicle
289  NBVehicle tmpVehicle("temporalNBVehicle", vClass);
290  // obtain pointer to GNENet
291  GNENet* net = partialEdges.front()->getNet();
292  // iterate over every selected myEdges
293  for (int i = 1; i < (int)partialEdges.size(); i++) {
294  // declare a temporal route in which save route between two last myEdges
295  std::vector<const NBRouterEdge*> partialRoute;
296  myDijkstraRouter->compute(partialEdges.at(i - 1)->getNBEdge(), partialEdges.at(i)->getNBEdge(), &tmpVehicle, 10, partialRoute);
297  // save partial route in solution
298  for (const auto& edgeID : partialRoute) {
299  solution.push_back(net->getAttributeCarriers()->retrieveEdge(edgeID->getID()));
300  }
301  }
302  }
303  // filter solution
304  auto solutionIt = solution.begin();
305  // iterate over solution
306  while (solutionIt != solution.end()) {
307  if ((solutionIt + 1) != solution.end()) {
308  // if next edge is the same of current edge, remove it
309  if (*solutionIt == *(solutionIt + 1)) {
310  solutionIt = solution.erase(solutionIt);
311  } else {
312  solutionIt++;
313  }
314  } else {
315  solutionIt++;
316  }
317  }
318  return solution;
319 }
320 
321 
322 std::vector<GNEEdge*>
323 GNEPathManager::PathCalculator::calculateDijkstraPath(const SUMOVehicleClass /*vClass*/, const GNEJunction* /*fromJunction*/, const GNEJunction* /*toJunction*/) const {
324  // implement path between junction here
325  return std::vector<GNEEdge*> ();
326 }
327 
328 
329 
330 void
332  // first reset reachability of all lanes
333  for (const auto& edge : originEdge->getNet()->getAttributeCarriers()->getEdges()) {
334  for (const auto& lane : edge.second->getLanes()) {
335  lane->resetReachability();
336  }
337  }
338  // get max speed
339  const double defaultMaxSpeed = SUMOVTypeParameter::VClassDefaultValues(vClass).maxSpeed;
340  // declare map for reachable edges
341  std::map<GNEEdge*, double> reachableEdges;
342  // init first edge
343  reachableEdges[originEdge] = 0;
344  // declare a vector for checked edges
345  std::vector<GNEEdge*> check;
346  // add first edge
347  check.push_back(originEdge);
348  // continue while there is edges to check
349  while (check.size() > 0) {
350  GNEEdge* edge = check.front();
351  check.erase(check.begin());
352  double traveltime = reachableEdges[edge];
353  for (const auto& lane : edge->getLanes()) {
354  if ((edge->getNBEdge()->getLaneStruct(lane->getIndex()).permissions & vClass) == vClass) {
355  lane->setReachability(traveltime);
356  }
357  }
358  // update traveltime
359  traveltime += edge->getNBEdge()->getLength() / MIN2(edge->getNBEdge()->getSpeed(), defaultMaxSpeed);
360  std::vector<GNEEdge*> sucessors;
361  // get sucessor edges
362  for (const auto& sucessorEdge : edge->getToJunction()->getGNEOutgoingEdges()) {
363  // check if edge is connected with sucessor edge
364  if (consecutiveEdgesConnected(vClass, edge, sucessorEdge)) {
365  sucessors.push_back(sucessorEdge);
366  }
367  }
368  // add sucessors to check vector
369  for (const auto& nextEdge : sucessors) {
370  // revisit edge via faster path
371  if ((reachableEdges.count(nextEdge) == 0) || (reachableEdges[nextEdge] > traveltime)) {
372  reachableEdges[nextEdge] = traveltime;
373  check.push_back(nextEdge);
374  }
375  }
376  }
377 }
378 
379 
380 bool
382  // check conditions
383  if ((from == nullptr) || (to == nullptr)) {
384  // myEdges cannot be null
385  return false;
386  } else if (from == to) {
387  // the same edge cannot be consecutive of itself
388  return false;
389  } else if (vClass == SVC_PEDESTRIAN) {
390  // for pedestrians consecutive myEdges are always connected
391  return true;
392  } else {
393  // iterate over connections of from edge
394  for (const auto& fromLane : from->getLanes()) {
395  for (const auto& fromConnection : from->getGNEConnections()) {
396  // within from loop, iterate ove to lanes
397  for (const auto& toLane : to->getLanes()) {
398  if (fromConnection->getLaneTo() == toLane) {
399  // get lane structs for both lanes
400  const NBEdge::Lane NBFromLane = from->getNBEdge()->getLaneStruct(fromLane->getIndex());
401  const NBEdge::Lane NBToLane = to->getNBEdge()->getLaneStruct(toLane->getIndex());
402  // check vClass
403  if (((NBFromLane.permissions & vClass) == vClass) &&
404  ((NBToLane.permissions & vClass) == vClass)) {
405  return true;
406  }
407  }
408  }
409  }
410  }
411  return false;
412  }
413 }
414 
415 
416 bool
418  if (busStop->getTagProperty().getTag() != SUMO_TAG_BUS_STOP) {
419  return false;
420  }
421  // check if busstop is placed over a pedestrian lane
422  if ((busStop->getParentLanes().front()->getParentEdge() == edge) &&
423  (edge->getNBEdge()->getLaneStruct(busStop->getParentLanes().front()->getIndex()).permissions & SVC_PEDESTRIAN) != 0) {
424  // busStop is placed over an lane that supports pedestrians, then return true
425  return true;
426  }
427  // obtain a list with all edge lanes that supports pedestrians
428  std::vector<GNELane*> pedestrianLanes;
429  for (int laneIndex = 0; laneIndex < (int)edge->getLanes().size(); laneIndex++) {
430  if ((edge->getNBEdge()->getLaneStruct(laneIndex).permissions & SVC_PEDESTRIAN) != 0) {
431  pedestrianLanes.push_back(edge->getLanes().at(laneIndex));
432  }
433  }
434  // check if exist an access between busStop and pedestrian lanes
435  for (const auto& access : busStop->getChildAdditionals()) {
436  // check that child is an access
437  if (access->getTagProperty().getTag() == SUMO_TAG_ACCESS) {
438  for (const auto& lane : pedestrianLanes) {
439  if (access->getParentLanes().front() == lane) {
440  // found, then return true
441  return true;
442  }
443  }
444  }
445  }
446  // There isn't a valid access, then return false
447  return false;
448 }
449 
450 
451 bool
453  return myPathCalculatorUpdated;
454 }
455 
456 
457 void
459  myPathCalculatorUpdated = false;
460 }
461 
462 // ---------------------------------------------------------------------------
463 // GNEPathManager::PathDraw - methods
464 // ---------------------------------------------------------------------------
465 
467 
468 
470 
471 
472 void
474  // just clear myDrawedElements
475  myLaneDrawedElements.clear();
476  myLane2laneDrawedElements.clear();
477 }
478 
479 
480 bool
481 GNEPathManager::PathDraw::drawPathGeometry(const bool dottedElement, const GNELane* lane, SumoXMLTag tag) {
482  // check conditions
483  if (dottedElement) {
484  return true;
487  return true;
488  } else if (myLaneDrawedElements.count(lane) > 0) {
489  // check tag
490  if (myLaneDrawedElements.at(lane).count(tag) > 0) {
491  // element type was already inserted, then don't draw geometry
492  return false;
493  } else {
494  // insert tag for the given lane
495  myLaneDrawedElements.at(lane).insert(tag);
496  // draw geometry
497  return true;
498  }
499  } else {
500  // insert lane and tag
501  myLaneDrawedElements[lane].insert(tag);
502  // draw geometry
503  return true;
504  }
505 }
506 
507 
508 bool
509 GNEPathManager::PathDraw::drawPathGeometry(const bool dottedElement, const GNELane* fromLane, const GNELane* toLane, SumoXMLTag tag) {
510  // check conditions
511  if (dottedElement) {
512  return true;
515  return true;
516  } else {
517  // declare lane2lane
518  const std::pair<const GNELane*, const GNELane*> lane2lane(fromLane, toLane);
519  // check lane2lane
520  if (myLane2laneDrawedElements.count(lane2lane) > 0) {
521  // check tag
522  if (myLane2laneDrawedElements.at(lane2lane).count(tag) > 0) {
523  // element type was already inserted, then don't draw geometry
524  return false;
525  } else {
526  // insert tag for the given lane2lane
527  myLane2laneDrawedElements.at(lane2lane).insert(tag);
528  // draw geometry
529  return true;
530  }
531  } else {
532  // insert lane2lane and tag
533  myLane2laneDrawedElements[lane2lane].insert(tag);
534  // draw geometry
535  return true;
536  }
537  }
538 }
539 
540 // ---------------------------------------------------------------------------
541 // GNEPathManager - methods
542 // ---------------------------------------------------------------------------
543 
546  myPathDraw(new PathDraw()) {
547 }
548 
549 
551  // clear paths
552  clearSegments();
553  // delete route calculator Instance
554  delete myPathCalculator;
555  // delete path draw
556  delete myPathDraw;
557 }
558 
559 
562  return myPathCalculator;
563 }
564 
565 
568  return myPathDraw;
569 }
570 
571 
572 bool
573 GNEPathManager::isPathValid(const PathElement* pathElement) const {
574  // first check if path element exist
575  if (myPaths.count(pathElement) > 0) {
576  // check if path hat more than one element
577  if (myPaths.at(pathElement).size() > 0) {
578  // if there is a next segment, then is invalid
579  return (myPaths.at(pathElement).front()->getNextSegment() == nullptr);
580  } else {
581  return false;
582  }
583  } else {
584  return false;
585  }
586 }
587 
588 
589 const GNELane*
590 GNEPathManager::getFirstLane(const PathElement* pathElement) const {
591  if ((myPaths.count(pathElement) > 0) && (myPaths.at(pathElement).size() > 0)) {
592  return myPaths.at(pathElement).front()->getLane();
593  } else {
594  return nullptr;
595  }
596 }
597 
598 
599 void
600 GNEPathManager::calculatePathEdges(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*> edges) {
601  // check if path element exist already in myPaths
602  if (myPaths.find(pathElement) != myPaths.end()) {
603  // delete segments
604  for (const auto& segment : myPaths.at(pathElement)) {
605  delete segment;
606  }
607  // remove path element from myPaths
608  myPaths.erase(pathElement);
609  }
610  // continue depending of number of edges
611  if (edges.size() > 0) {
612  // declare segment vector
613  std::vector<Segment*> segments;
614  // declare lane segments
615  std::vector<Segment*> laneSegments;
616  // calculate Dijkstra path
617  const std::vector<GNEEdge*> path = myPathCalculator->calculateDijkstraPath(vClass, edges);
618  // continue if path isn't empty
619  if (path.size() > 0) {
620  // reserve
621  segments.reserve(2 * (int)path.size() - 1);
622  laneSegments.reserve(path.size());
623  // iterate over path
624  for (int i = 0; i < (int)path.size(); i++) {
625  // get first and last segment flags
626  const bool firstSegment = (i == 0);
627  const bool lastSegment = (i == ((int)path.size() - 1));
628  // get first allowed lane
629  const GNELane* lane = path.at(i)->getLaneByAllowedVClass(vClass);
630  // create segments
631  Segment* laneSegment = new Segment(this, pathElement, lane, firstSegment, lastSegment);
632  // add it into segment and laneSegment vectors
633  segments.push_back(laneSegment);
634  laneSegments.push_back(laneSegment);
635  // continue if this isn't the last edge
636  if (!lastSegment) {
637  // obtain next lane
638  const GNELane* nextLane = path.at(i + 1)->getLaneByAllowedVClass(vClass);
639  // create junction segments
640  Segment* junctionSegment = new Segment(this, pathElement, path.at(i)->getParentJunctions().at(1), lane, nextLane);
641  // add it into segment vector
642  segments.push_back(junctionSegment);
643  }
644  }
645  // get lane segment index
646  const int laneSegmentIndex = (int)((double)laneSegments.size() * 0.5);
647  // mark middle label as label segment
648  laneSegments.at(laneSegmentIndex)->markSegmentLabel();
649  } else {
650  // create first segment
651  Segment* firstSegment = new Segment(this, pathElement, edges.front()->getLaneByAllowedVClass(vClass), true, false);
652  // mark segment as label segment
653  firstSegment->markSegmentLabel();
654  // add to segments
655  segments.push_back(firstSegment);
656  // create last segment
657  Segment* lastSegment = new Segment(this, pathElement, edges.back()->getLaneByAllowedVClass(vClass), false, true);
658  // add to segments
659  segments.push_back(lastSegment);
660  // set previous and next segment for vinculating first and last segment with a red line
661  firstSegment->setNextSegment(lastSegment);
662  lastSegment->setPreviousSegment(firstSegment);
663  }
664  // add segment in path
665  myPaths[pathElement] = segments;
666  }
667 }
668 
669 
670 void
671 GNEPathManager::calculatePathLanes(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNELane*> lanes) {
672  // declare edges
673  std::vector<GNEEdge*> edges;
674  // reserve edges
675  edges.reserve(lanes.size());
676  // get parent of every lane
677  for (const auto& lane : lanes) {
678  edges.push_back(lane->getParentEdge());
679  }
680  // calculate path edges
681  calculatePathEdges(pathElement, vClass, edges);
682 }
683 
684 
685 void
686 GNEPathManager::calculateConsecutivePathEdges(PathElement* pathElement, SUMOVehicleClass vClass, const std::vector<GNEEdge*> edges) {
687  // declare lane vector
688  std::vector<GNELane*> lanes;
689  // reserve lanes
690  lanes.reserve(edges.size());
691  // get first allowed lane of every edge
692  for (const auto& edge : edges) {
693  lanes.push_back(edge->getLaneByAllowedVClass(vClass));
694  }
695  // calculate consecutive path lanes
696  calculateConsecutivePathLanes(pathElement, lanes);
697 }
698 
699 
700 void
701 GNEPathManager::calculateConsecutivePathLanes(PathElement* pathElement, const std::vector<GNELane*> lanes) {
702  // check if path element exist already in myPaths
703  if (myPaths.find(pathElement) != myPaths.end()) {
704  // delete segments
705  for (const auto& segment : myPaths.at(pathElement)) {
706  delete segment;
707  }
708  // remove path element from myPaths
709  myPaths.erase(pathElement);
710  }
711  // continue depending of number of lanes
712  if (lanes.size() > 0) {
713  // declare segment vector
714  std::vector<Segment*> segments;
715  // declare lane segments
716  std::vector<Segment*> laneSegments;
717  // reserve
718  segments.reserve(2 * (int)lanes.size() - 1);
719  laneSegments.reserve(lanes.size());
720  // iterate over lanes
721  for (int i = 0; i < (int)lanes.size(); i++) {
722  // get first and last segment flags
723  const bool firstSegment = (i == 0);
724  const bool lastSegment = (i == ((int)lanes.size() - 1));
725  // create segments
726  Segment* laneSegment = new Segment(this, pathElement, lanes.at(i), firstSegment, lastSegment);
727  // add it into segment vector
728  segments.push_back(laneSegment);
729  laneSegments.push_back(laneSegment);
730  // continue if this isn't the last lane
731  if (!lastSegment) {
732  // obtain next lane
733  const GNELane* nextLane = lanes.at(i + 1);
734  // create junction segments
735  Segment* junctionSegment = new Segment(this, pathElement, lanes.at(i)->getParentEdge()->getParentJunctions().at(1), lanes.at(i), nextLane);
736  // add it into segment vector
737  segments.push_back(junctionSegment);
738  }
739  }
740  // get lane segment index
741  const int laneSegmentIndex = (int)((double)laneSegments.size() * 0.5);
742  // mark middle label as label segment
743  laneSegments.at(laneSegmentIndex)->markSegmentLabel();
744  // add segment in path
745  myPaths[pathElement] = segments;
746  }
747 }
748 
749 
750 void
752  // check if path element exist already in myPaths
753  if (myPaths.find(pathElement) != myPaths.end()) {
754  // delete segments
755  for (const auto& segment : myPaths.at(pathElement)) {
756  delete segment;
757  }
758  // remove path element from myPaths
759  myPaths.erase(pathElement);
760  }
761 }
762 
763 
764 void
766  if (myLaneSegments.count(lane) > 0) {
767  int numRoutes = 0;
768  for (const auto& segment : myLaneSegments.at(lane)) {
769  // draw segment
770  segment->getPathElement()->drawPartialGL(s, lane, segment, 0);
771  // check if path element is a route
772  if (segment->getPathElement()->isRoute()) {
773  numRoutes++;
774  }
775  }
776  // check if draw overlapped routes
777  if ((numRoutes > 1) && lane->getNet()->getViewNet()->getDemandViewOptions().showOverlappedRoutes()) {
778  lane->drawOverlappedRoutes(numRoutes);
779  }
780  }
781 }
782 
783 
784 void
786  if (myJunctionSegments.count(junction) > 0) {
787  for (const auto& segment : myJunctionSegments.at(junction)) {
788  segment->getPathElement()->drawPartialGL(s, segment->getPreviousLane(), segment->getNextLane(), segment, 0);
789  }
790  }
791 }
792 
793 
794 void
796  // draw all lane segments
797  for (const auto& laneSegment : myLaneSegments) {
798  for (const auto& segment : laneSegment.second) {
799  if (segment->getPathElement() == pathElement) {
800  pathElement->drawPartialGL(s, laneSegment.first, segment, 0);
801  }
802  }
803  }
804 }
805 
806 
807 void
809  // declare vector for path elements to compute
810  std::vector<PathElement*> pathElementsToCompute;
811  // check lane in laneSegments
812  if (myLaneSegments.count(lane) > 0) {
813  // obtain affected path elements
814  for (const auto& segment : myLaneSegments.at(lane)) {
815  pathElementsToCompute.push_back(segment->getPathElement());
816  }
817  }
818  // compute path elements
819  for (const auto& pathElement : pathElementsToCompute) {
820  pathElement->computePathElement();
821  }
822 }
823 
824 
825 void
827  // declare vector for path elements to compute
828  std::vector<PathElement*> pathElementsToCompute;
829  // check junction in junctionSegments
830  if (myJunctionSegments.count(junction) > 0) {
831  // obtain affected path elements
832  for (const auto& segment : myJunctionSegments.at(junction)) {
833  pathElementsToCompute.push_back(segment->getPathElement());
834  }
835  }
836  // compute path elements
837  for (const auto& pathElement : pathElementsToCompute) {
838  pathElement->computePathElement();
839  }
840 }
841 
842 
843 void
845  // declare iterator
846  auto it = myPaths.begin();
847  // iterate over paths
848  while (it != myPaths.end()) {
849  if (it->first->isDemandElement()) {
850  // delete all segments
851  for (const auto& segment : it->second) {
852  delete segment;
853  }
854  // remove path
855  it = myPaths.erase(it);
856  } else {
857  it++;
858  }
859  }
860 }
861 
862 
863 void
865  myLaneSegments[lane].insert(segment);
866 }
867 
868 
869 void
871  myJunctionSegments[junction].insert(segment);
872 }
873 
874 
875 void
877  // check if segment has a lane
878  if (segment->getLane()) {
879  // remove segment from segments associated with lane
880  if (myLaneSegments.at(segment->getLane()).find(segment) != myLaneSegments.at(segment->getLane()).end()) {
881  myLaneSegments.at(segment->getLane()).erase(segment);
882  }
883  // clear lane if doesn't have more segments
884  if (myLaneSegments.at(segment->getLane()).empty()) {
885  myLaneSegments.erase(segment->getLane());
886  }
887  }
888  if (segment->getJunction()) {
889  // remove segment from segments associated with junction
890  if (myJunctionSegments.at(segment->getJunction()).find(segment) != myJunctionSegments.at(segment->getJunction()).end()) {
891  myJunctionSegments.at(segment->getJunction()).erase(segment);
892  }
893  // clear junction if doesn't have more segments
894  if (myJunctionSegments.at(segment->getJunction()).empty()) {
895  myJunctionSegments.erase(segment->getJunction());
896  }
897  }
898 }
899 
900 
901 void
903  // first iterate over paths
904  for (const auto& path : myPaths) {
905  // delete all segments
906  for (const auto& segment : path.second) {
907  delete segment;
908  }
909  }
910  // clear paths
911  myPaths.clear();
912 }
913 
914 
915 bool
916 GNEPathManager::connectedLanes(const GNELane* fromLane, const GNELane* toLane) const {
917  // get from and to NBEdges
918  NBEdge* fromNBEdge = fromLane->getParentEdge()->getNBEdge();
919  NBEdge* toNBEdge = toLane->getParentEdge()->getNBEdge();
920  // get connections vinculated with from Lane
921  const std::vector<NBEdge::Connection> connections = fromNBEdge->getConnectionsFromLane(fromLane->getIndex());
922  // find connection
923  std::vector<NBEdge::Connection>::const_iterator con_it = find_if(
924  connections.begin(), connections.end(),
925  NBEdge::connections_finder(fromLane->getIndex(), toNBEdge, toLane->getIndex()));
926  // check if connection was found
927  return (con_it != connections.end());
928 }
929 
930 /****************************************************************************/
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.
T MIN2(T a, T b)
Definition: StdDefs.h:74
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.
Definition: GNEAdditional.h:48
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)
Definition: GNEEdge.h:53
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition: GNEEdge.cpp:435
GNEJunction * getToJunction() const
get from Junction (only used to increase readability)
Definition: GNEEdge.h:82
const std::vector< GNELane * > & getLanes() const
returns a reference to the lane vector
Definition: GNEEdge.cpp:782
const std::vector< GNEConnection * > & getGNEConnections() const
returns a reference to the GNEConnection vector
Definition: GNEEdge.cpp:788
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.
Definition: GNELane.h:46
int getIndex() const
returns the index of the lane
Definition: GNELane.cpp:797
void drawOverlappedRoutes(const int numRoutes) const
draw overlapped routes
Definition: GNELane.cpp:1398
GNEEdge * getParentEdge() const
get arent edge
Definition: GNELane.cpp:113
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.
Definition: GNENet.h:42
NBNetBuilder * getNetBuilder() const
get net builder
Definition: GNENet.cpp:1359
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:125
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
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(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
Definition: GNEViewNet.cpp:531
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.
Definition: NBEdge.h:91
double getLength() const
Returns the computed length of the edge.
Definition: NBEdge.h:588
double getSpeed() const
Returns the speed allowed on this edge.
Definition: NBEdge.h:614
std::vector< Connection > getConnectionsFromLane(int lane, NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
Definition: NBEdge.cpp:1206
Lane & getLaneStruct(int lane)
Definition: NBEdge.h:1368
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:148
static double getTravelTimeStatic(const NBRouterEdge *const edge, const NBVehicle *const, double)
Definition: NBEdge.h:81
A vehicle as used by router.
Definition: NBVehicle.h:42
bool showOverlappedRoutes() const
show overlapped routes
An (internal) definition of a single lane of an edge.
Definition: NBEdge.h:142
SVCPermissions permissions
List of vehicle types that are allowed on this lane.
Definition: NBEdge.h:153
struct for default values that depend of VClass
double maxSpeed
The vehicle type's maximum speed [m/s].