Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 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 : /****************************************************************************/
14 : /// @file MSEdge.cpp
15 : /// @author Christian Roessel
16 : /// @author Jakob Erdmann
17 : /// @author Christoph Sommer
18 : /// @author Daniel Krajzewicz
19 : /// @author Laura Bieker
20 : /// @author Michael Behrisch
21 : /// @author Sascha Krieg
22 : /// @date Tue, 06 Mar 2001
23 : ///
24 : // A road/street connecting two junctions
25 : /****************************************************************************/
26 : #include <config.h>
27 :
28 : #include <algorithm>
29 : #include <iostream>
30 : #include <cassert>
31 : #ifdef HAVE_FOX
32 : #include <utils/common/ScopedLocker.h>
33 : #endif
34 : #include <utils/common/StringTokenizer.h>
35 : #include <utils/options/OptionsCont.h>
36 : #include <microsim/devices/MSRoutingEngine.h>
37 : #include <mesosim/MELoop.h>
38 : #include <mesosim/MESegment.h>
39 : #include <mesosim/MEVehicle.h>
40 : #include "MSInsertionControl.h"
41 : #include "MSJunction.h"
42 : #include "MSLane.h"
43 : #include "MSLaneChanger.h"
44 : #include "MSLaneChangerSublane.h"
45 : #include "MSLink.h"
46 : #include "MSGlobals.h"
47 : #include "MSNet.h"
48 : #include "MSVehicle.h"
49 : #include "MSLeaderInfo.h"
50 : #include <microsim/transportables/MSTransportable.h>
51 : #include "MSEdgeWeightsStorage.h"
52 : #include "MSEdge.h"
53 :
54 : #define BEST_LANE_LOOKAHEAD 3000.0
55 :
56 : // ===========================================================================
57 : // static member definitions
58 : // ===========================================================================
59 : MSEdge::DictType MSEdge::myDict;
60 : MSEdgeVector MSEdge::myEdges;
61 : SVCPermissions MSEdge::myMesoIgnoredVClasses(0);
62 :
63 :
64 : // ===========================================================================
65 : // member method definitions
66 : // ===========================================================================
67 2062871 : MSEdge::MSEdge(const std::string& id, int numericalID,
68 : const SumoXMLEdgeFunc function,
69 : const std::string& streetName,
70 : const std::string& edgeType,
71 : int priority,
72 2062871 : double distance) :
73 2062871 : Named(id), myNumericalID(numericalID), myLanes(nullptr),
74 2062871 : myLaneChanger(nullptr), myFunction(function), myVaporizationRequests(0),
75 2062871 : myLastFailedInsertionTime(-1),
76 2062871 : myFromJunction(nullptr), myToJunction(nullptr),
77 2062871 : myHaveTransientPermissions(false),
78 2062871 : myOtherTazConnector(nullptr),
79 2062871 : myStreetName(streetName),
80 2062871 : myEdgeType(edgeType),
81 2062871 : myPriority(priority),
82 2062871 : myDistance(distance),
83 2062871 : myWidth(0.),
84 2062871 : myLength(0.),
85 2062871 : myEmptyTraveltime(0.),
86 2062871 : myTimePenalty(0.),
87 2062871 : myAmDelayed(false),
88 2062871 : myAmRoundabout(false),
89 2062871 : myAmFringe(true),
90 4125742 : myBidiEdge(nullptr)
91 2062871 : { }
92 :
93 :
94 3442109 : MSEdge::~MSEdge() {
95 1937438 : delete myLaneChanger;
96 1937438 : delete myReversedRoutingEdge;
97 1937438 : delete myRailwayRoutingEdge;
98 11191861 : }
99 :
100 :
101 : void
102 1932811 : MSEdge::initialize(const std::vector<MSLane*>* lanes) {
103 : assert(lanes != 0);
104 1932811 : myLanes = std::shared_ptr<const std::vector<MSLane*> >(lanes);
105 1932811 : if (myFunction == SumoXMLEdgeFunc::CONNECTOR) {
106 199980 : myCombinedPermissions = SVCAll;
107 : }
108 4086153 : for (MSLane* const lane : *lanes) {
109 2153342 : lane->setRightSideOnEdge(myWidth, (int)mySublaneSides.size());
110 2153342 : MSLeaderInfo ahead(lane->getWidth());
111 4935261 : for (int j = 0; j < ahead.numSublanes(); ++j) {
112 2781919 : mySublaneSides.push_back(myWidth + j * MSGlobals::gLateralResolution);
113 : }
114 2153342 : myWidth += lane->getWidth();
115 2153342 : }
116 1932811 : }
117 :
118 :
119 1811323 : void MSEdge::recalcCache() {
120 1811323 : if (myLanes->empty()) {
121 : return;
122 : }
123 1811323 : myLength = myLanes->front()->getLength();
124 3622646 : myEmptyTraveltime = myLength / MAX2(getSpeedLimit(), NUMERICAL_EPS);
125 1811323 : if (isNormal() && (MSGlobals::gUseMesoSim || MSGlobals::gTLSPenalty > 0)) {
126 : SUMOTime minorPenalty = 0;
127 159442 : bool haveTLSPenalty = MSGlobals::gTLSPenalty > 0;
128 159442 : if (MSGlobals::gUseMesoSim) {
129 159327 : const MESegment::MesoEdgeType& edgeType = MSNet::getInstance()->getMesoType(getEdgeType());
130 159327 : minorPenalty = edgeType.minorPenalty;
131 159327 : haveTLSPenalty = edgeType.tlsPenalty > 0;
132 : }
133 159442 : if (haveTLSPenalty || minorPenalty > 0) {
134 : // add tls penalties to the minimum travel time
135 : SUMOTime minPenalty = -1;
136 1931 : for (const MSLane* const l : *myLanes) {
137 3025 : for (const MSLink* const link : l->getLinkCont()) {
138 1721 : if (link->getLane()->isWalkingArea() && link->getLaneBefore()->isNormal()) {
139 60 : continue;
140 : }
141 1661 : SUMOTime linkPenalty = link->isTLSControlled() ? link->getMesoTLSPenalty() : (link->havePriority() ? 0 : minorPenalty);
142 1661 : if (minPenalty == -1) {
143 : minPenalty = linkPenalty;
144 : } else {
145 : minPenalty = MIN2(minPenalty, linkPenalty);
146 : }
147 : }
148 : }
149 627 : if (minPenalty > 0) {
150 197 : myEmptyTraveltime += STEPS2TIME(minPenalty);
151 197 : myTimePenalty = STEPS2TIME(minPenalty);
152 : }
153 : }
154 1651881 : } else if (isCrossing() && MSGlobals::gTLSPenalty > 0) {
155 : // penalties are recorded for the entering link
156 80 : for (const auto& ili : myLanes->front()->getIncomingLanes()) {
157 40 : double penalty = STEPS2TIME(ili.viaLink->getMesoTLSPenalty());
158 40 : if (!ili.viaLink->haveOffPriority()) {
159 0 : penalty = MAX2(penalty, MSGlobals::gMinorPenalty);
160 : }
161 40 : if (penalty > 0) {
162 20 : myEmptyTraveltime += penalty;
163 20 : myTimePenalty = penalty;
164 : }
165 : }
166 1651841 : } else if (isInternal() && MSGlobals::gUsingInternalLanes) {
167 808103 : const MSLink* link = myLanes->front()->getIncomingLanes()[0].viaLink;
168 808103 : if (!link->isTLSControlled() && !link->havePriority()) {
169 407707 : if (link->isTurnaround()) {
170 139561 : myEmptyTraveltime += MSGlobals::gTurnaroundPenalty;
171 139561 : myTimePenalty = MSGlobals::gTurnaroundPenalty;
172 : } else {
173 268146 : myEmptyTraveltime += MSGlobals::gMinorPenalty;
174 268146 : myTimePenalty = MSGlobals::gMinorPenalty;
175 : }
176 : }
177 : }
178 : }
179 :
180 :
181 : void
182 28 : MSEdge::resetTAZ(MSJunction* junction) {
183 : mySuccessors.clear();
184 : myPredecessors.clear();
185 700 : for (const MSEdge* edge : junction->getIncoming()) {
186 672 : if (!edge->isInternal()) {
187 112 : MSEdgeVector& succ = const_cast<MSEdgeVector&>(edge->mySuccessors);
188 : MSConstEdgePairVector& succVia = const_cast<MSConstEdgePairVector&>(edge->myViaSuccessors);
189 112 : MSEdgeVector& pred = const_cast<MSEdgeVector&>(edge->myPredecessors);
190 112 : auto it = std::find(succ.begin(), succ.end(), this);
191 112 : auto it2 = std::find(succVia.begin(), succVia.end(), std::make_pair(const_cast<const MSEdge*>(this), (const MSEdge*)nullptr));
192 112 : auto it3 = std::find(pred.begin(), pred.end(), this);
193 112 : if (it != succ.end()) {
194 : succ.erase(it);
195 : succVia.erase(it2);
196 : }
197 112 : if (it3 != pred.end()) {
198 : pred.erase(it3);
199 : }
200 : }
201 : }
202 28 : }
203 :
204 : void
205 1730207 : MSEdge::closeBuilding() {
206 3880474 : for (MSLane* const lane : *myLanes) {
207 4895848 : for (MSLink* const link : lane->getLinkCont()) {
208 2745581 : link->initParallelLinks();
209 : MSLane* const toL = link->getLane();
210 : MSLane* const viaL = link->getViaLane();
211 2745581 : if (toL != nullptr) {
212 : MSEdge& to = toL->getEdge();
213 2745581 : if (std::find(mySuccessors.begin(), mySuccessors.end(), &to) == mySuccessors.end()) {
214 2486688 : mySuccessors.push_back(&to);
215 4973376 : myViaSuccessors.push_back(std::make_pair(&to, (viaL == nullptr ? nullptr : &viaL->getEdge())));
216 : }
217 2745581 : if (std::find(to.myPredecessors.begin(), to.myPredecessors.end(), this) == to.myPredecessors.end()) {
218 2486688 : to.myPredecessors.push_back(this);
219 : }
220 2745581 : if (link->getDirection() != LinkDirection::TURN) {
221 2170241 : myAmFringe = false;
222 : }
223 : }
224 2745581 : if (viaL != nullptr) {
225 : MSEdge& to = viaL->getEdge();
226 917389 : if (std::find(to.myPredecessors.begin(), to.myPredecessors.end(), this) == to.myPredecessors.end()) {
227 807920 : to.myPredecessors.push_back(this);
228 : }
229 : }
230 : }
231 2150267 : lane->checkBufferType();
232 : }
233 1730207 : std::sort(mySuccessors.begin(), mySuccessors.end(), by_id_sorter());
234 1730207 : rebuildAllowedLanes(true);
235 1730207 : recalcCache();
236 :
237 : // extend lookup table for sublane model after all edges are read
238 1730207 : if (myLanes->back()->getOpposite() != nullptr) {
239 7354 : MSLane* opposite = myLanes->back()->getOpposite();
240 7354 : MSLeaderInfo ahead(opposite->getWidth());
241 20810 : for (int j = 0; j < ahead.numSublanes(); ++j) {
242 13456 : mySublaneSides.push_back(myWidth + j * MSGlobals::gLateralResolution);
243 : }
244 7354 : }
245 1730207 : }
246 :
247 :
248 : void
249 160 : MSEdge::updateMesoType() {
250 : assert(MSGlobals::gUseMesoSim);
251 160 : if (!myLanes->empty()) {
252 160 : MSGlobals::gMesoNet->updateSegmentsForEdge(*this);
253 : }
254 160 : }
255 :
256 :
257 : void
258 1730207 : MSEdge::buildLaneChanger() {
259 1730207 : if (!myLanes->empty()) {
260 1730207 : const bool allowChanging = allowsLaneChanging();
261 1730207 : if (MSGlobals::gLateralResolution > 0) {
262 : // may always initiate sublane-change
263 159271 : if (!isInternal() || MSGlobals::gUsingInternalLanes) {
264 159095 : myLaneChanger = new MSLaneChangerSublane(myLanes.get(), allowChanging);
265 : }
266 : } else {
267 1570936 : if (MSGlobals::gLaneChangeDuration > 0) {
268 3717 : myLaneChanger = new MSLaneChanger(myLanes.get(), allowChanging);
269 1567219 : } else if (myLanes->size() > 1 || canChangeToOpposite()) {
270 281008 : myLaneChanger = new MSLaneChanger(myLanes.get(), allowChanging);
271 : }
272 : }
273 : }
274 1730207 : }
275 :
276 :
277 : bool
278 1730207 : MSEdge::allowsLaneChanging() const {
279 1730207 : if (isInternal() && MSGlobals::gUsingInternalLanes) {
280 : // allow changing only if all links leading to this internal lane have priority
281 : // or they are controlled by a traffic light
282 1314822 : for (const MSLane* const lane : *myLanes) {
283 914777 : const MSLink* const link = lane->getLogicalPredecessorLane()->getLinkTo(lane);
284 : assert(link != nullptr);
285 : const LinkState state = link->getState();
286 398502 : if ((state == LINKSTATE_MINOR && lane->getBidiLane() == nullptr)
287 516481 : || state == LINKSTATE_EQUAL
288 516481 : || state == LINKSTATE_STOP
289 : || state == LINKSTATE_ALLWAY_STOP
290 914777 : || state == LINKSTATE_DEADEND) {
291 : return false;
292 : }
293 : }
294 : }
295 : return true;
296 : }
297 :
298 :
299 : void
300 17798609 : MSEdge::addToAllowed(const SVCPermissions permissions, std::shared_ptr<const std::vector<MSLane*> > allowedLanes, AllowedLanesCont& laneCont) const {
301 17798609 : if (!allowedLanes->empty()) {
302 : // recheck whether we had this list to save memory
303 17932528 : for (auto& allowed : laneCont) {
304 17020553 : if (*allowed.second == *allowedLanes) {
305 13590155 : allowed.first |= permissions;
306 : return;
307 : }
308 : }
309 911975 : laneCont.push_back(std::make_pair(permissions, allowedLanes));
310 : }
311 : }
312 :
313 :
314 : SVCPermissions
315 2807713 : MSEdge::getMesoPermissions(SVCPermissions p, SVCPermissions ignoreIgnored) {
316 2807713 : SVCPermissions ignored = myMesoIgnoredVClasses & ~ignoreIgnored;
317 2807713 : return (p | ignored) == ignored ? 0 : p;
318 : }
319 :
320 :
321 : void
322 1731081 : MSEdge::rebuildAllowedLanes(const bool onInit) {
323 : // rebuild myMinimumPermissions and myCombinedPermissions
324 1731081 : myMinimumPermissions = SVCAll;
325 1731081 : myCombinedPermissions = 0;
326 : bool lanesChangedPermission = false;
327 3882655 : for (MSLane* const lane : *myLanes) {
328 : // same dedicated lanes are ignored in meso to avoid capacity errors.
329 : // Here we have to make sure that vehicles which are set to depart on
330 : // such lanes trigger an error.
331 2151574 : SVCPermissions allow = getMesoPermissions(lane->getPermissions(), SVC_PEDESTRIAN);
332 2151574 : myMinimumPermissions &= allow;
333 2151574 : myCombinedPermissions |= allow;
334 2151574 : lanesChangedPermission |= lane->hadPermissionChanges();
335 : }
336 1731081 : if (!onInit && !myHaveTransientPermissions && lanesChangedPermission) {
337 503 : myHaveTransientPermissions = true;
338 : // backup original structures when first needed
339 503 : myOrigAllowed = myAllowed;
340 : myOrigAllowedTargets = myAllowedTargets;
341 : myOrigClassesViaSuccessorMap = myClassesViaSuccessorMap;
342 : }
343 : // rebuild myAllowed
344 : myAllowed.clear();
345 1731081 : if (myCombinedPermissions != myMinimumPermissions) {
346 133994 : myAllowed.push_back(std::make_pair(SVC_IGNORING, myLanes));
347 4555796 : for (SVCPermissions vclass = SVC_PRIVATE; vclass <= SUMOVehicleClass_MAX; vclass *= 2) {
348 4421802 : if ((myCombinedPermissions & vclass) == vclass) {
349 : std::shared_ptr<std::vector<MSLane*> > allowedLanes = std::make_shared<std::vector<MSLane*> >();
350 9383329 : for (MSLane* const lane : *myLanes) {
351 6375353 : if (lane->allowsVehicleClass((SUMOVehicleClass)vclass)) {
352 3212991 : allowedLanes->push_back(lane);
353 : }
354 : }
355 6015952 : addToAllowed(vclass, allowedLanes, myAllowed);
356 : }
357 : }
358 : }
359 1731081 : if (onInit) {
360 1730207 : myOriginalMinimumPermissions = myMinimumPermissions;
361 1730207 : myOriginalCombinedPermissions = myCombinedPermissions;
362 : } else {
363 874 : rebuildAllowedTargets(false);
364 2309 : for (MSEdge* pred : myPredecessors) {
365 1435 : if (myHaveTransientPermissions && !pred->myHaveTransientPermissions) {
366 727 : pred->myOrigAllowed = pred->myAllowed;
367 : pred->myOrigAllowedTargets = pred->myAllowedTargets;
368 : pred->myOrigClassesViaSuccessorMap = pred->myClassesViaSuccessorMap;
369 727 : pred->myHaveTransientPermissions = true;
370 : }
371 1435 : pred->rebuildAllowedTargets(false);
372 : }
373 874 : if (MSGlobals::gUseMesoSim) {
374 1354 : for (MESegment* s = MSGlobals::gMesoNet->getSegmentForEdge(*this); s != nullptr; s = s->getNextSegment()) {
375 1128 : s->updatePermissions();
376 : }
377 : }
378 : }
379 1731081 : }
380 :
381 :
382 : void
383 1733057 : MSEdge::rebuildAllowedTargets(const bool updateVehicles) {
384 : myAllowedTargets.clear();
385 4223804 : for (const MSEdge* target : mySuccessors) {
386 : bool universalMap = true; // whether the mapping for SVC_IGNORING is also valid for all vehicle classes
387 : std::shared_ptr<std::vector<MSLane*> > allLanes = std::make_shared<std::vector<MSLane*> >();
388 : // compute the mapping for SVC_IGNORING
389 5854106 : for (MSLane* const lane : *myLanes) {
390 : SVCPermissions combinedTargetPermissions = 0;
391 9425711 : for (const MSLink* const link : lane->getLinkCont()) {
392 6062352 : if (&link->getLane()->getEdge() == target) {
393 2750466 : allLanes->push_back(lane);
394 2750466 : combinedTargetPermissions |= link->getLane()->getPermissions();
395 2750466 : if (link->getViaLane() != nullptr &&
396 918710 : ((lane->getPermissions() & link->getLane()->getPermissions()) != link->getViaLane()->getPermissions())) {
397 : // custom connection permissions
398 : universalMap = false;
399 : }
400 : }
401 : }
402 3363359 : if (combinedTargetPermissions == 0 || (lane->getPermissions() & combinedTargetPermissions) != lane->getPermissions()) {
403 : universalMap = false;
404 : }
405 : }
406 2490747 : if (universalMap) {
407 1996012 : if (myAllowed.empty()) {
408 : // we have no lane specific permissions
409 3938910 : myAllowedTargets[target].push_back(std::make_pair(myMinimumPermissions, myLanes));
410 : } else {
411 104547 : for (const auto& i : myAllowed) {
412 233970 : addToAllowed(i.first, i.second, myAllowedTargets[target]);
413 : }
414 : }
415 : } else {
416 989470 : addToAllowed(SVC_IGNORING, allLanes, myAllowedTargets[target]);
417 : // compute the vclass specific mapping
418 16820990 : for (SVCPermissions vclass = SVC_PRIVATE; vclass <= SUMOVehicleClass_MAX; vclass *= 2) {
419 16326255 : if ((myCombinedPermissions & vclass) == vclass) {
420 : std::shared_ptr<std::vector<MSLane*> > allowedLanes = std::make_shared<std::vector<MSLane*> >();
421 47184658 : for (MSLane* const lane : *myLanes) {
422 32966750 : if (lane->allowsVehicleClass((SUMOVehicleClass)vclass)) {
423 67104779 : for (const MSLink* const link : lane->getLinkCont()) {
424 41913935 : if (link->getLane()->allowsVehicleClass((SUMOVehicleClass)vclass) && &link->getLane()->getEdge() == target && (link->getViaLane() == nullptr || link->getViaLane()->allowsVehicleClass((SUMOVehicleClass)vclass))) {
425 11250697 : allowedLanes->push_back(lane);
426 : }
427 : }
428 : }
429 : }
430 42653724 : addToAllowed(vclass, allowedLanes, myAllowedTargets[target]);
431 : }
432 : }
433 : }
434 : }
435 1733057 : if (updateVehicles) {
436 1303 : for (const MSLane* const lane : *myLanes) {
437 762 : const MSLane::VehCont& vehs = lane->getVehiclesSecure();
438 2171 : for (MSVehicle* veh : vehs) {
439 1409 : veh->updateBestLanes(true);
440 : }
441 762 : lane->releaseVehicles();
442 : }
443 : }
444 : myClassesSuccessorMap.clear();
445 1733057 : }
446 :
447 :
448 : // ------------ Access to the edge's lanes
449 : MSLane*
450 870 : MSEdge::leftLane(const MSLane* const lane) const {
451 870 : return parallelLane(lane, 1);
452 : }
453 :
454 :
455 : MSLane*
456 448 : MSEdge::rightLane(const MSLane* const lane) const {
457 448 : return parallelLane(lane, -1);
458 : }
459 :
460 :
461 : MSLane*
462 64649615 : MSEdge::parallelLane(const MSLane* const lane, int offset, bool includeOpposite) const {
463 64649615 : const int resultIndex = lane->getIndex() + offset;
464 64649615 : if (resultIndex >= getNumLanes() && includeOpposite) {
465 16236936 : const MSEdge* opposite = getOppositeEdge();
466 16236936 : if (opposite != nullptr && resultIndex < getNumLanes() + opposite->getNumLanes()) {
467 1379091 : return opposite->getLanes()[opposite->getNumLanes() + getNumLanes() - resultIndex - 1];
468 : }
469 : return nullptr;
470 48412679 : } else if (resultIndex >= (int)myLanes->size() || resultIndex < 0) {
471 : return nullptr;
472 : } else {
473 28052523 : return (*myLanes)[resultIndex];
474 : }
475 : }
476 :
477 :
478 : const std::vector<MSLane*>*
479 72124207 : MSEdge::allowedLanes(const MSEdge& destination, SUMOVehicleClass vclass, bool ignoreTransientPermissions) const {
480 72124207 : const auto& targets = ignoreTransientPermissions && myHaveTransientPermissions ? myOrigAllowedTargets : myAllowedTargets;
481 : AllowedLanesByTarget::const_iterator i = targets.find(&destination);
482 72124207 : if (i != targets.end()) {
483 72129627 : for (const auto& allowed : i->second) {
484 72035565 : if ((allowed.first & vclass) == vclass) {
485 : return allowed.second.get();
486 : }
487 : }
488 : }
489 : return nullptr;
490 : }
491 :
492 :
493 : const std::vector<MSLane*>*
494 2363049705 : MSEdge::allowedLanes(SUMOVehicleClass vclass) const {
495 2363049705 : if ((myMinimumPermissions & vclass) == vclass) {
496 632957430 : return myLanes.get();
497 : } else {
498 1730092275 : if ((myCombinedPermissions & vclass) == vclass) {
499 3465902444 : for (const auto& allowed : myAllowed) {
500 3465902444 : if ((allowed.first & vclass) == vclass) {
501 : return allowed.second.get();
502 : }
503 : }
504 : }
505 2004 : return nullptr;
506 : }
507 : }
508 :
509 :
510 : // ------------
511 : SUMOTime
512 409 : MSEdge::incVaporization(SUMOTime) {
513 409 : ++myVaporizationRequests;
514 409 : return 0;
515 : }
516 :
517 :
518 : SUMOTime
519 43 : MSEdge::decVaporization(SUMOTime) {
520 43 : --myVaporizationRequests;
521 43 : return 0;
522 : }
523 :
524 :
525 : MSLane*
526 102933189 : MSEdge::getFreeLane(const std::vector<MSLane*>* allowed, const SUMOVehicleClass vclass, double departPos) const {
527 102933189 : if (allowed == nullptr) {
528 69534678 : allowed = allowedLanes(vclass);
529 : }
530 : MSLane* res = nullptr;
531 69534678 : if (allowed != nullptr) {
532 : double largestGap = 0;
533 : MSLane* resByGap = nullptr;
534 : double leastOccupancy = std::numeric_limits<double>::max();
535 227708276 : for (std::vector<MSLane*>::const_iterator i = allowed->begin(); i != allowed->end(); ++i) {
536 124777010 : const double occupancy = (*i)->getBruttoOccupancy();
537 124777010 : if (occupancy < leastOccupancy) {
538 111094799 : res = (*i);
539 : leastOccupancy = occupancy;
540 : }
541 124777010 : const MSVehicle* last = (*i)->getLastFullVehicle();
542 124777010 : const double lastGap = (last != nullptr ? last->getPositionOnLane() : myLength) - departPos;
543 124777010 : if (lastGap > largestGap) {
544 : largestGap = lastGap;
545 55182155 : resByGap = (*i);
546 : }
547 : }
548 102931266 : if (resByGap != nullptr) {
549 : //if (res != resByGap) std::cout << SIMTIME << " edge=" << getID() << " departPos=" << departPos << " res=" << Named::getIDSecure(res) << " resByGap=" << Named::getIDSecure(resByGap) << " largestGap=" << largestGap << "\n";
550 : res = resByGap;
551 : }
552 : }
553 102933189 : return res;
554 : }
555 :
556 :
557 : double
558 102889141 : MSEdge::getDepartPosBound(const MSVehicle& veh, bool upper) const {
559 102889141 : const SUMOVehicleParameter& pars = veh.getParameter();
560 : double pos = getLength();
561 : // determine the position
562 102889141 : switch (pars.departPosProcedure) {
563 3077245 : case DepartPosDefinition::GIVEN:
564 3077245 : pos = pars.departPos;
565 3077245 : if (pos < 0.) {
566 2981267 : pos += myLength;
567 : }
568 : break;
569 : case DepartPosDefinition::RANDOM:
570 : // could be any position on the edge
571 : break;
572 : case DepartPosDefinition::RANDOM_FREE:
573 : // could be any position on the edge due to multiple random attempts
574 : break;
575 : case DepartPosDefinition::FREE:
576 : // many candidate positions, upper bound could be computed exactly
577 : // with much effort
578 : break;
579 310948 : case DepartPosDefinition::LAST:
580 310948 : if (upper) {
581 463174 : for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) {
582 314178 : MSVehicle* last = (*i)->getLastFullVehicle();
583 314178 : if (last != nullptr) {
584 273594 : pos = MIN2(pos, last->getPositionOnLane());
585 : }
586 : }
587 : } else {
588 : pos = 0;
589 : }
590 : break;
591 45467108 : case DepartPosDefinition::BASE:
592 : case DepartPosDefinition::DEFAULT:
593 45467108 : if (!upper) {
594 : pos = 0;
595 : }
596 : break;
597 8 : default:
598 8 : pos = MIN2(pos, veh.getVehicleType().getLength());
599 : break;
600 : }
601 102889141 : return pos;
602 : }
603 :
604 : MSLane*
605 39 : MSEdge::getDepartLaneMeso(SUMOVehicle& veh) const {
606 39 : if (veh.getParameter().departLaneProcedure == DepartLaneDefinition::GIVEN) {
607 2 : if ((int) myLanes->size() <= veh.getParameter().departLane || !(*myLanes)[veh.getParameter().departLane]->allowsVehicleClass(veh.getVehicleType().getVehicleClass())) {
608 0 : return nullptr;
609 : }
610 2 : return (*myLanes)[veh.getParameter().departLane];
611 : }
612 37 : return (*myLanes)[0];
613 : }
614 :
615 : MSLane*
616 2236774609 : MSEdge::getDepartLane(MSVehicle& veh) const {
617 2236774609 : switch (veh.getParameter().departLaneProcedure) {
618 100199618 : case DepartLaneDefinition::GIVEN:
619 100199618 : if ((int) myLanes->size() <= veh.getParameter().departLane || !(*myLanes)[veh.getParameter().departLane]->allowsVehicleClass(veh.getVehicleType().getVehicleClass())) {
620 62 : return nullptr;
621 : }
622 100199556 : return (*myLanes)[veh.getParameter().departLane];
623 77409424 : case DepartLaneDefinition::RANDOM:
624 154818848 : return RandHelper::getRandomFrom(*allowedLanes(veh.getVehicleType().getVehicleClass()));
625 69437063 : case DepartLaneDefinition::FREE:
626 69437063 : return getFreeLane(nullptr, veh.getVehicleType().getVehicleClass(), getDepartPosBound(veh, false));
627 5489916 : case DepartLaneDefinition::ALLOWED_FREE:
628 5489916 : if (veh.getRoute().size() == 1) {
629 5906 : return getFreeLane(nullptr, veh.getVehicleType().getVehicleClass(), getDepartPosBound(veh, false));
630 : } else {
631 5484010 : return getFreeLane(allowedLanes(**(veh.getRoute().begin() + 1), veh.getVehicleType().getVehicleClass()), veh.getVehicleType().getVehicleClass(), getDepartPosBound(veh, false));
632 : }
633 27599985 : case DepartLaneDefinition::BEST_FREE: {
634 27599985 : veh.updateBestLanes(false, myLanes->front());
635 27599985 : const std::vector<MSVehicle::LaneQ>& bl = veh.getBestLanes();
636 : double bestLength = -1;
637 86138119 : for (std::vector<MSVehicle::LaneQ>::const_iterator i = bl.begin(); i != bl.end(); ++i) {
638 58538134 : if ((*i).length > bestLength) {
639 : bestLength = (*i).length;
640 : }
641 : }
642 : // beyond a certain length, all lanes are suitable
643 : // however, we still need to check departPos to avoid unsuitable insertion
644 : // (this is only possible in some cases)
645 : double departPos = 0;
646 27599985 : if (bestLength > BEST_LANE_LOOKAHEAD) {
647 362177 : departPos = getDepartPosBound(veh);
648 362177 : bestLength = MIN2(bestLength - departPos, BEST_LANE_LOOKAHEAD);
649 : }
650 27599985 : std::vector<MSLane*>* bestLanes = new std::vector<MSLane*>();
651 86138119 : for (std::vector<MSVehicle::LaneQ>::const_iterator i = bl.begin(); i != bl.end(); ++i) {
652 58538134 : if (((*i).length - departPos) >= bestLength) {
653 30515130 : bestLanes->push_back((*i).lane);
654 : }
655 : }
656 27599985 : MSLane* ret = getFreeLane(bestLanes, veh.getVehicleType().getVehicleClass(), getDepartPosBound(veh, false));
657 27599985 : delete bestLanes;
658 27599985 : return ret;
659 : }
660 1956638603 : case DepartLaneDefinition::DEFAULT:
661 : case DepartLaneDefinition::FIRST_ALLOWED:
662 1956638603 : return getFirstAllowed(veh.getVehicleType().getVehicleClass());
663 : default:
664 : break;
665 : }
666 0 : if (!(*myLanes)[0]->allowsVehicleClass(veh.getVehicleType().getVehicleClass())) {
667 : return nullptr;
668 : }
669 0 : return (*myLanes)[0];
670 : }
671 :
672 :
673 : MSLane*
674 1957326815 : MSEdge::getFirstAllowed(SUMOVehicleClass vClass, bool defaultFirst) const {
675 3408235580 : for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) {
676 3408235580 : if ((*i)->allowsVehicleClass(vClass)) {
677 : return *i;
678 : }
679 : }
680 0 : return defaultFirst && !myLanes->empty() ? myLanes->front() : nullptr;
681 : }
682 :
683 :
684 : bool
685 2771046674 : MSEdge::validateDepartSpeed(SUMOVehicle& v) const {
686 2771046674 : const SUMOVehicleParameter& pars = v.getParameter();
687 2771046674 : const MSVehicleType& type = v.getVehicleType();
688 2771046674 : if (pars.departSpeedProcedure == DepartSpeedDefinition::GIVEN) {
689 : // departSpeed could have been rounded down in the output
690 120842769 : double vMax = getVehicleMaxSpeed(&v) + SPEED_EPS;
691 120842769 : if (pars.departSpeed > vMax) {
692 : // check departLane (getVehicleMaxSpeed checks lane 0)
693 22578 : MSLane* departLane = MSGlobals::gMesoNet ? getDepartLaneMeso(v) : getDepartLane(dynamic_cast<MSVehicle&>(v));
694 22578 : if (departLane != nullptr) {
695 22578 : vMax = departLane->getVehicleMaxSpeed(&v);
696 22578 : if (pars.wasSet(VEHPARS_SPEEDFACTOR_SET)) {
697 : // speedFactor could have been rounded down in the output
698 7 : vMax *= (1 + SPEED_EPS);
699 : }
700 : // additive term must come after multiplication!
701 22578 : vMax += SPEED_EPS;
702 22578 : if (pars.departSpeed > vMax) {
703 22564 : const std::vector<double>& speedFactorParams = type.getSpeedFactor().getParameter();
704 22564 : if (speedFactorParams[1] > 0.) {
705 45090 : v.setChosenSpeedFactor(type.computeChosenSpeedDeviation(nullptr, pars.departSpeed / MIN2(getSpeedLimit(), type.getDesiredMaxSpeed() - SPEED_EPS)));
706 22545 : if (v.getChosenSpeedFactor() > speedFactorParams[0] + 2 * speedFactorParams[1]) {
707 : // only warn for significant deviation
708 37140 : WRITE_WARNINGF(TL("Choosing new speed factor % for vehicle '%' to match departure speed % (max %)."),
709 : toString(v.getChosenSpeedFactor()), pars.id, pars.departSpeed, vMax);
710 : }
711 : } else {
712 : return false;
713 : }
714 : }
715 : }
716 : }
717 : }
718 : return true;
719 : }
720 :
721 :
722 : bool
723 2771608567 : MSEdge::insertVehicle(SUMOVehicle& v, SUMOTime time, const bool checkOnly, const bool forceCheck) const {
724 : // when vaporizing, no vehicles are inserted, but checking needs to be successful to trigger removal
725 2771589505 : if (isVaporizing() || isTazConnector()
726 5542632597 : || v.getRouteValidity(true, checkOnly) != MSBaseVehicle::ROUTE_VALID) {
727 584604 : return checkOnly;
728 : }
729 2771023788 : const SUMOVehicleParameter& pars = v.getParameter();
730 2771023788 : if (!validateDepartSpeed(v)) {
731 14 : const std::string errorMsg = "Departure speed for vehicle '" + pars.id + "' is too high for the departure edge '" + getID() + "'.";
732 14 : if (MSGlobals::gCheckRoutes) {
733 14 : throw ProcessError(errorMsg);
734 : } else {
735 28 : WRITE_WARNING(errorMsg);
736 : }
737 : }
738 2771023781 : if (MSGlobals::gUseMesoSim) {
739 506319647 : if (!forceCheck && myLastFailedInsertionTime == time) {
740 : return false;
741 : }
742 27400196 : double pos = 0.0;
743 27400196 : switch (pars.departPosProcedure) {
744 571407 : case DepartPosDefinition::GIVEN:
745 571407 : if (pars.departPos >= 0.) {
746 565765 : pos = pars.departPos;
747 : } else {
748 5642 : pos = pars.departPos + getLength();
749 : }
750 571407 : if (pos < 0 || pos > getLength()) {
751 6 : WRITE_WARNING("Invalid departPos " + toString(pos) + " given for vehicle '" +
752 : v.getID() + "'. Inserting at lane end instead.");
753 2 : pos = getLength();
754 : }
755 : break;
756 : case DepartPosDefinition::RANDOM:
757 : case DepartPosDefinition::RANDOM_FREE:
758 6812 : pos = RandHelper::rand(getLength());
759 6812 : break;
760 : default:
761 : break;
762 : }
763 : bool result = false;
764 27400196 : MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this, pos);
765 : MEVehicle* veh = static_cast<MEVehicle*>(&v);
766 : int qIdx;
767 27400196 : if (pars.departPosProcedure == DepartPosDefinition::FREE) {
768 486320 : while (segment != nullptr && !result) {
769 447862 : if (checkOnly) {
770 6 : result = segment->hasSpaceFor(veh, time, qIdx, true) == time;
771 : } else {
772 447856 : result = segment->initialise(veh, time);
773 : }
774 : segment = segment->getNextSegment();
775 : }
776 : } else {
777 27361738 : if (checkOnly) {
778 25860819 : result = segment->hasSpaceFor(veh, time, qIdx, true) == time;
779 : } else {
780 1500919 : result = segment->initialise(veh, time);
781 : }
782 : }
783 27400194 : return result;
784 : }
785 2264704134 : if (checkOnly) {
786 692472006 : switch (v.getParameter().departLaneProcedure) {
787 614408504 : case DepartLaneDefinition::GIVEN:
788 : case DepartLaneDefinition::DEFAULT:
789 : case DepartLaneDefinition::FIRST_ALLOWED: {
790 614408504 : MSLane* insertionLane = getDepartLane(static_cast<MSVehicle&>(v));
791 614408504 : if (insertionLane == nullptr) {
792 0 : WRITE_WARNING("could not insert vehicle '" + v.getID() + "' on any lane of edge '" + getID() + "', time=" + time2string(MSNet::getInstance()->getCurrentTimeStep()));
793 0 : return false;
794 : }
795 614408504 : const double occupancy = insertionLane->getBruttoOccupancy();
796 614408504 : return (occupancy == 0 || occupancy * myLength + v.getVehicleType().getLengthWithGap() <= myLength ||
797 12217279 : v.getParameter().departProcedure == DepartDefinition::SPLIT);
798 : }
799 78063502 : default:
800 86238078 : for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) {
801 82390999 : const double occupancy = (*i)->getBruttoOccupancy();
802 82390999 : if (occupancy == 0 || occupancy * myLength + v.getVehicleType().getLengthWithGap() <= myLength ||
803 8174576 : v.getParameter().departProcedure == DepartDefinition::SPLIT) {
804 : return true;
805 : }
806 : }
807 : }
808 : return false;
809 : }
810 1572232128 : MSLane* insertionLane = getDepartLane(static_cast<MSVehicle&>(v));
811 1572232128 : if (insertionLane == nullptr) {
812 : return false;
813 : }
814 :
815 1572232128 : if (!forceCheck) {
816 1572231951 : if (myLastFailedInsertionTime == time) {
817 : if (myFailedInsertionMemory.count(insertionLane->getIndex())) {
818 : // A vehicle was already rejected for the proposed insertionLane in this timestep
819 : return false;
820 : }
821 : } else {
822 : // last rejection occurred in a previous timestep, clear cache
823 : myFailedInsertionMemory.clear();
824 : }
825 : }
826 :
827 9637254 : bool success = insertionLane->insertVehicle(static_cast<MSVehicle&>(v));
828 :
829 9637253 : if (!success) {
830 : // constraints may enforce explicit re-ordering so we need to try other vehicles after failure
831 13997628 : if (!insertionLane->hasParameter("insertionOrder" + v.getID())) {
832 6998667 : myFailedInsertionMemory.insert(insertionLane->getIndex());
833 : }
834 : }
835 : return success;
836 : }
837 :
838 :
839 : void
840 34873442 : MSEdge::changeLanes(SUMOTime t) const {
841 34873442 : if (myLaneChanger != nullptr) {
842 34873442 : myLaneChanger->laneChange(t);
843 : }
844 34873442 : }
845 :
846 :
847 : const MSEdge*
848 2179783 : MSEdge::getInternalFollowingEdge(const MSEdge* followerAfterInternal, SUMOVehicleClass vClass) const {
849 : //@todo to be optimized
850 2617484 : for (const MSLane* const l : *myLanes) {
851 3144995 : for (const MSLink* const link : l->getLinkCont()) {
852 2707294 : if (&link->getLane()->getEdge() == followerAfterInternal) {
853 1894868 : if (link->getViaLane() != nullptr) {
854 991507 : if (link->getViaLane()->allowsVehicleClass(vClass)) {
855 989089 : return &link->getViaLane()->getEdge();
856 : } else {
857 2418 : continue;
858 : }
859 : } else {
860 : return nullptr; // network without internal links
861 : }
862 : }
863 : }
864 : }
865 : return nullptr;
866 : }
867 :
868 :
869 : double
870 1112573 : MSEdge::getInternalFollowingLengthTo(const MSEdge* followerAfterInternal, SUMOVehicleClass vClass) const {
871 : assert(followerAfterInternal != 0);
872 : assert(!followerAfterInternal->isInternal());
873 : double dist = 0.;
874 1112573 : const MSEdge* edge = getInternalFollowingEdge(followerAfterInternal, vClass);
875 : // Take into account non-internal lengths until next non-internal edge
876 2039825 : while (edge != nullptr && edge->isInternal()) {
877 927252 : dist += edge->getLength();
878 927252 : edge = edge->getInternalFollowingEdge(followerAfterInternal, vClass);
879 : }
880 1112573 : return dist;
881 : }
882 :
883 :
884 : const MSEdge*
885 134515 : MSEdge::getNormalBefore() const {
886 : const MSEdge* result = this;
887 142464 : while (result->isInternal() && MSGlobals::gUsingInternalLanes) {
888 : assert(result->getPredecessors().size() == 1);
889 7949 : result = result->getPredecessors().front();
890 : }
891 134515 : return result;
892 : }
893 :
894 : const MSEdge*
895 4782005 : MSEdge::getNormalSuccessor() const {
896 : const MSEdge* result = this;
897 8934534 : while (result->isInternal()) {
898 : assert(result->getSuccessors().size() == 1);
899 4152529 : result = result->getSuccessors().front();
900 : }
901 4782005 : return result;
902 : }
903 :
904 : double
905 123001899 : MSEdge::getMeanSpeed() const {
906 : double v = 0;
907 : double totalNumVehs = 0;
908 123001899 : if (MSGlobals::gUseMesoSim) {
909 144552452 : for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != nullptr; segment = segment->getNextSegment()) {
910 : const int numVehs = segment->getCarNumber();
911 125490916 : if (numVehs > 0) {
912 23308328 : v += numVehs * segment->getMeanSpeed();
913 23308328 : totalNumVehs += numVehs;
914 : }
915 : }
916 19061536 : if (totalNumVehs == 0) {
917 11617428 : return getLength() / myEmptyTraveltime; // may include tls-penalty
918 : }
919 : } else {
920 249579510 : for (const MSLane* const lane : *myLanes) {
921 : int numVehs = lane->getVehicleNumber();
922 145639147 : if (numVehs == 0) {
923 : // take speed limit but with lowest possible weight
924 : numVehs = 1;
925 : }
926 145639147 : v += numVehs * lane->getMeanSpeed();
927 145639147 : totalNumVehs += numVehs;
928 : }
929 103940363 : if (myBidiEdge != nullptr) {
930 8069028 : for (const MSLane* const lane : myBidiEdge->getLanes()) {
931 4148390 : if (lane->getVehicleNumber() > 0) {
932 : // do not route across edges which are already occupied in reverse direction
933 : return 0;
934 : }
935 : }
936 : }
937 103712755 : if (totalNumVehs == 0) {
938 0 : return getSpeedLimit();
939 : }
940 : }
941 111156863 : return v / totalNumVehs;
942 : }
943 :
944 :
945 : double
946 0 : MSEdge::getMeanFriction() const {
947 : double f = 0.;
948 0 : for (const MSLane* const lane : *myLanes) {
949 0 : f += lane->getFrictionCoefficient();
950 : }
951 0 : if (!myLanes->empty()) {
952 0 : return f / (double)myLanes->size();
953 : }
954 : return 1.;
955 : }
956 :
957 :
958 : double
959 1090 : MSEdge::getMeanSpeedBike() const {
960 1090 : if (MSGlobals::gUseMesoSim) {
961 : // no separate bicycle speeds in meso
962 362 : return getMeanSpeed();
963 : }
964 : double v = 0;
965 : double totalNumVehs = 0;
966 2404 : for (const MSLane* const lane : *myLanes) {
967 : const int numVehs = lane->getVehicleNumber();
968 1676 : v += numVehs * lane->getMeanSpeedBike();
969 1676 : totalNumVehs += numVehs;
970 : }
971 728 : if (totalNumVehs == 0) {
972 364 : return getSpeedLimit();
973 : }
974 364 : return v / totalNumVehs;
975 : }
976 :
977 :
978 : double
979 64004 : MSEdge::getCurrentTravelTime(double minSpeed) const {
980 : assert(minSpeed > 0);
981 64004 : if (!myAmDelayed) {
982 34496 : return myEmptyTraveltime;
983 : }
984 59016 : return getLength() / MAX2(minSpeed, getMeanSpeed());
985 : }
986 :
987 :
988 : double
989 0 : MSEdge::getRoutingSpeed() const {
990 0 : return MSRoutingEngine::getAssumedSpeed(this, nullptr);
991 : }
992 :
993 :
994 : bool
995 1932837 : MSEdge::dictionary(const std::string& id, MSEdge* ptr) {
996 : const DictType::iterator it = myDict.lower_bound(id);
997 1932837 : if (it == myDict.end() || it->first != id) {
998 : // id not in myDict
999 1932809 : myDict.emplace_hint(it, id, ptr);
1000 3865654 : while (ptr->getNumericalID() >= (int)myEdges.size()) {
1001 1932845 : myEdges.push_back(nullptr);
1002 : }
1003 1932809 : myEdges[ptr->getNumericalID()] = ptr;
1004 1932809 : return true;
1005 : }
1006 : return false;
1007 : }
1008 :
1009 :
1010 : MSEdge*
1011 8323250 : MSEdge::dictionary(const std::string& id) {
1012 : const DictType::iterator it = myDict.find(id);
1013 8323250 : if (it == myDict.end()) {
1014 : return nullptr;
1015 : }
1016 6435596 : return it->second;
1017 : }
1018 :
1019 :
1020 : MSEdge*
1021 2752167 : MSEdge::dictionaryHint(const std::string& id, const int startIdx) {
1022 : // this method is mainly useful when parsing connections from the net.xml which are sorted by "from" id
1023 2752167 : if (myEdges[startIdx] != nullptr && myEdges[startIdx]->getID() == id) {
1024 : return myEdges[startIdx];
1025 : }
1026 1631791 : if (startIdx + 1 < (int)myEdges.size() && myEdges[startIdx + 1] != nullptr && myEdges[startIdx + 1]->getID() == id) {
1027 : return myEdges[startIdx + 1];
1028 : }
1029 484806 : return dictionary(id);
1030 : }
1031 :
1032 :
1033 : const MSEdgeVector&
1034 818452 : MSEdge::getAllEdges() {
1035 818452 : return myEdges;
1036 : }
1037 :
1038 :
1039 : void
1040 40096 : MSEdge::clear() {
1041 1847606 : for (DictType::iterator i = myDict.begin(); i != myDict.end(); ++i) {
1042 1807510 : delete (*i).second;
1043 : }
1044 : myDict.clear();
1045 : myEdges.clear();
1046 40096 : }
1047 :
1048 :
1049 : void
1050 269 : MSEdge::insertIDs(std::vector<std::string>& into) {
1051 15600 : for (DictType::iterator i = myDict.begin(); i != myDict.end(); ++i) {
1052 15331 : into.push_back((*i).first);
1053 : }
1054 269 : }
1055 :
1056 :
1057 : void
1058 370747 : MSEdge::parseEdgesList(const std::string& desc, ConstMSEdgeVector& into,
1059 : const std::string& rid) {
1060 370747 : StringTokenizer st(desc);
1061 370747 : parseEdgesList(st.getVector(), into, rid);
1062 370747 : }
1063 :
1064 :
1065 : void
1066 371014 : MSEdge::parseEdgesList(const std::vector<std::string>& desc, ConstMSEdgeVector& into,
1067 : const std::string& rid) {
1068 1490126 : for (std::vector<std::string>::const_iterator i = desc.begin(); i != desc.end(); ++i) {
1069 1119179 : const MSEdge* edge = MSEdge::dictionary(*i);
1070 : // check whether the edge exists
1071 1119179 : if (edge == nullptr) {
1072 67 : throw ProcessError("The edge '" + *i + "' within the route " + rid + " is not known."
1073 134 : + "\n The route can not be build.");
1074 : }
1075 1119112 : into.push_back(edge);
1076 : }
1077 370947 : }
1078 :
1079 :
1080 : double
1081 1307063 : MSEdge::getDistanceTo(const MSEdge* other, const bool doBoundaryEstimate) const {
1082 : assert(this != other);
1083 1307063 : if (doBoundaryEstimate) {
1084 17973 : return myBoundary.distanceTo2D(other->myBoundary);
1085 : }
1086 1289090 : if (isTazConnector()) {
1087 433 : if (other->isTazConnector()) {
1088 423 : return myBoundary.distanceTo2D(other->myBoundary);
1089 : }
1090 10 : return myBoundary.distanceTo2D(other->getLanes()[0]->getShape()[0]);
1091 : }
1092 1288657 : if (other->isTazConnector()) {
1093 5221 : return other->myBoundary.distanceTo2D(getLanes()[0]->getShape()[-1]);
1094 : }
1095 1283436 : return getLanes()[0]->getShape()[-1].distanceTo2D(other->getLanes()[0]->getShape()[0]);
1096 : }
1097 :
1098 :
1099 : const Position
1100 1519 : MSEdge::getStopPosition(const SUMOVehicleParameter::Stop& stop) {
1101 1519 : return MSLane::dictionary(stop.lane)->geometryPositionAtOffset((stop.endPos + stop.startPos) / 2.);
1102 : }
1103 :
1104 :
1105 : double
1106 88507829 : MSEdge::getSpeedLimit() const {
1107 : // @note lanes might have different maximum speeds in theory
1108 88507829 : return myLanes->empty() ? 1 : getLanes()[0]->getSpeedLimit();
1109 : }
1110 :
1111 :
1112 : double
1113 1852527 : MSEdge::getLengthGeometryFactor() const {
1114 1852527 : return myLanes->empty() ? 1 : getLanes()[0]->getLengthGeometryFactor();
1115 : }
1116 :
1117 : double
1118 240269282 : MSEdge::getVehicleMaxSpeed(const SUMOTrafficObject* const veh) const {
1119 : // @note lanes might have different maximum speeds in theory
1120 240269282 : return myLanes->empty() ? 1 : getLanes()[0]->getVehicleMaxSpeed(veh);
1121 : }
1122 :
1123 :
1124 : void
1125 189 : MSEdge::setMaxSpeed(double val, double jamThreshold) {
1126 : assert(val >= 0);
1127 189 : if (myLanes != nullptr) {
1128 532 : for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) {
1129 343 : (*i)->setMaxSpeed(val, false, false, jamThreshold);
1130 : }
1131 : }
1132 189 : }
1133 :
1134 :
1135 : void
1136 1223799 : MSEdge::addTransportable(MSTransportable* t) const {
1137 1223799 : if (t->isPerson()) {
1138 : myPersons.insert(t);
1139 : } else {
1140 : myContainers.insert(t);
1141 : }
1142 1223799 : }
1143 :
1144 : void
1145 2138310 : MSEdge::removeTransportable(MSTransportable* t) const {
1146 2138310 : std::set<MSTransportable*, ComparatorNumericalIdLess>& tc = t->isPerson() ? myPersons : myContainers;
1147 : auto it = tc.find(t);
1148 2138310 : if (it != tc.end()) {
1149 : tc.erase(it);
1150 : }
1151 2138310 : }
1152 :
1153 : std::vector<MSTransportable*>
1154 7181201 : MSEdge::getSortedPersons(SUMOTime timestep, bool includeRiding) const {
1155 7181201 : std::vector<MSTransportable*> result(myPersons.begin(), myPersons.end());
1156 7181201 : if (includeRiding) {
1157 2347915 : for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) {
1158 1656344 : const MSLane::VehCont& vehs = (*i)->getVehiclesSecure();
1159 2879978 : for (MSLane::VehCont::const_iterator j = vehs.begin(); j != vehs.end(); ++j) {
1160 1223634 : const std::vector<MSTransportable*>& persons = (*j)->getPersons();
1161 1223634 : result.insert(result.end(), persons.begin(), persons.end());
1162 : }
1163 1656344 : (*i)->releaseVehicles();
1164 : }
1165 : }
1166 7181201 : sort(result.begin(), result.end(), transportable_by_position_sorter(timestep));
1167 7181201 : return result;
1168 0 : }
1169 :
1170 :
1171 : std::vector<MSTransportable*>
1172 4232524 : MSEdge::getSortedContainers(SUMOTime timestep, bool /* includeRiding */) const {
1173 4232524 : std::vector<MSTransportable*> result(myContainers.begin(), myContainers.end());
1174 4232524 : sort(result.begin(), result.end(), transportable_by_position_sorter(timestep));
1175 4232524 : return result;
1176 0 : }
1177 :
1178 :
1179 : int
1180 5073950 : MSEdge::transportable_by_position_sorter::operator()(const MSTransportable* const c1, const MSTransportable* const c2) const {
1181 5073950 : const double pos1 = c1->getCurrentStage()->getEdgePos(myTime);
1182 5073950 : const double pos2 = c2->getCurrentStage()->getEdgePos(myTime);
1183 5073950 : if (pos1 != pos2) {
1184 4918366 : return pos1 < pos2;
1185 : }
1186 155584 : return c1->getID() < c2->getID();
1187 : }
1188 :
1189 :
1190 : void
1191 424885 : MSEdge::addSuccessor(MSEdge* edge, const MSEdge* via) {
1192 424885 : mySuccessors.push_back(edge);
1193 424885 : myViaSuccessors.push_back(std::make_pair(edge, via));
1194 424885 : if (isTazConnector() && edge->getFromJunction() != nullptr) {
1195 212439 : myBoundary.add(edge->getFromJunction()->getPosition());
1196 : }
1197 :
1198 424885 : edge->myPredecessors.push_back(this);
1199 424885 : if (edge->isTazConnector() && getToJunction() != nullptr) {
1200 212446 : edge->myBoundary.add(getToJunction()->getPosition());
1201 : }
1202 424885 : }
1203 :
1204 :
1205 : const MSEdgeVector&
1206 7045970 : MSEdge::getSuccessors(SUMOVehicleClass vClass) const {
1207 7045970 : if (vClass == SVC_IGNORING || !MSNet::getInstance()->hasPermissions() || myFunction == SumoXMLEdgeFunc::CONNECTOR) {
1208 7040006 : return mySuccessors;
1209 : }
1210 : #ifdef HAVE_FOX
1211 5964 : ScopedLocker<> lock(mySuccessorMutex, MSGlobals::gNumThreads > 1);
1212 : #endif
1213 : std::map<SUMOVehicleClass, MSEdgeVector>::iterator i = myClassesSuccessorMap.find(vClass);
1214 5964 : if (i == myClassesSuccessorMap.end()) {
1215 : // instantiate vector
1216 1320 : myClassesSuccessorMap[vClass];
1217 : i = myClassesSuccessorMap.find(vClass);
1218 : // this vClass is requested for the first time. rebuild all successors
1219 6371 : for (MSEdgeVector::const_iterator it = mySuccessors.begin(); it != mySuccessors.end(); ++it) {
1220 5051 : if ((*it)->isTazConnector()) {
1221 239 : i->second.push_back(*it);
1222 : } else {
1223 4812 : const std::vector<MSLane*>* allowed = allowedLanes(**it, vClass);
1224 4812 : if (allowed != nullptr && allowed->size() > 0) {
1225 3998 : i->second.push_back(*it);
1226 : }
1227 : }
1228 : }
1229 : }
1230 : // can use cached value
1231 5964 : return i->second;
1232 : }
1233 :
1234 :
1235 : const MSConstEdgePairVector&
1236 100227967 : MSEdge::getViaSuccessors(SUMOVehicleClass vClass, bool ignoreTransientPermissions) const {
1237 100227967 : if (vClass == SVC_IGNORING || !MSNet::getInstance()->hasPermissions() || myFunction == SumoXMLEdgeFunc::CONNECTOR) {
1238 94967887 : return myViaSuccessors;
1239 : }
1240 : #ifdef HAVE_FOX
1241 5260080 : ScopedLocker<> lock(mySuccessorMutex, MSGlobals::gNumThreads > 1);
1242 : #endif
1243 5260080 : auto& viaMap = ignoreTransientPermissions && myHaveTransientPermissions ? myOrigClassesViaSuccessorMap : myClassesViaSuccessorMap;
1244 : auto i = viaMap.find(vClass);
1245 5260080 : if (i != viaMap.end()) {
1246 : // can use cached value
1247 5216172 : return i->second;
1248 : }
1249 : // instantiate vector
1250 43908 : MSConstEdgePairVector& result = viaMap[vClass];
1251 : // this vClass is requested for the first time. rebuild all successors
1252 182806 : for (const auto& viaPair : myViaSuccessors) {
1253 138898 : if (viaPair.first->isTazConnector()) {
1254 10162 : result.push_back(viaPair);
1255 : } else {
1256 128736 : const std::vector<MSLane*>* allowed = allowedLanes(*viaPair.first, vClass, ignoreTransientPermissions);
1257 128736 : if (allowed != nullptr && allowed->size() > 0) {
1258 101850 : result.push_back(viaPair);
1259 : }
1260 : }
1261 : }
1262 : return result;
1263 : }
1264 :
1265 :
1266 : void
1267 1732620 : MSEdge::setJunctions(MSJunction* from, MSJunction* to) {
1268 1732620 : myFromJunction = from;
1269 1732620 : myToJunction = to;
1270 1732620 : if (!isTazConnector()) {
1271 1732620 : myBoundary.add(from->getPosition());
1272 1732620 : myBoundary.add(to->getPosition());
1273 : }
1274 1732620 : }
1275 :
1276 :
1277 : bool
1278 2766059 : MSEdge::canChangeToOpposite() const {
1279 2766059 : return (!myLanes->empty() && myLanes->back()->getOpposite() != nullptr &&
1280 : // do not change on curved internal lanes
1281 : (!isInternal()
1282 5473 : || (MSGlobals::gUsingInternalLanes
1283 5469 : && myLanes->back()->getIncomingLanes()[0].viaLink->getDirection() == LinkDirection::STRAIGHT)));
1284 : }
1285 :
1286 :
1287 : const MSEdge*
1288 17985727 : MSEdge::getOppositeEdge() const {
1289 17985727 : if (!myLanes->empty() && myLanes->back()->getOpposite() != nullptr) {
1290 2991554 : return &(myLanes->back()->getOpposite()->getEdge());
1291 : } else {
1292 14994173 : return nullptr;
1293 : }
1294 : }
1295 :
1296 :
1297 : bool
1298 178 : MSEdge::hasMinorLink() const {
1299 370 : for (const MSLane* const l : *myLanes) {
1300 290 : for (const MSLink* const link : l->getLinkCont()) {
1301 98 : if (!link->havePriority()) {
1302 : return true;
1303 : }
1304 : }
1305 : }
1306 : return false;
1307 : }
1308 :
1309 : bool
1310 1040834 : MSEdge::hasChangeProhibitions(SUMOVehicleClass svc, int index) const {
1311 1040834 : if (myLanes->size() == 1) {
1312 : return false;
1313 : }
1314 2392778 : for (const MSLane* const l : *myLanes) {
1315 1601732 : if (l->getIndex() <= index && !l->allowsChangingRight(svc) && l->getIndex() > 0) {
1316 : return true;
1317 1601644 : } else if (l->getIndex() >= index && !l->allowsChangingLeft(svc) && l->getIndex() < (int)(myLanes->size() - 1)) {
1318 : return true;
1319 : }
1320 : }
1321 : return false;
1322 : }
1323 :
1324 : void
1325 1073907 : MSEdge::checkAndRegisterBiDirEdge(const std::string& bidiID) {
1326 1073907 : if (bidiID != "") {
1327 24844 : myBidiEdge = dictionary(bidiID);
1328 24844 : if (myBidiEdge == nullptr) {
1329 0 : WRITE_ERRORF(TL("Bidi-edge '%' does not exist"), bidiID);
1330 : }
1331 24844 : setBidiLanes();
1332 638003 : return;
1333 : }
1334 1049063 : if (getFunction() != SumoXMLEdgeFunc::NORMAL) {
1335 : return;
1336 : }
1337 : // legacy networks (no bidi attribute)
1338 435904 : ConstMSEdgeVector candidates = myToJunction->getOutgoing();
1339 3579606 : for (ConstMSEdgeVector::const_iterator it = candidates.begin(); it != candidates.end(); it++) {
1340 3143702 : if ((*it)->getToJunction() == myFromJunction) { //reverse edge
1341 291548 : if (myBidiEdge != nullptr && isSuperposable(*it)) {
1342 0 : WRITE_WARNINGF(TL("Ambiguous superposable edges between junction '%' and '%'."), myToJunction->getID(), myFromJunction->getID());
1343 0 : break;
1344 : }
1345 291548 : if (isSuperposable(*it)) {
1346 26 : myBidiEdge = *it;
1347 26 : setBidiLanes();
1348 : }
1349 : }
1350 : }
1351 435904 : }
1352 :
1353 :
1354 : void
1355 24870 : MSEdge::setBidiLanes() {
1356 : assert(myBidiEdge != nullptr);
1357 24870 : if (getNumLanes() == 1 && myBidiEdge->getNumLanes() == 1) {
1358 : // the other way round is set when this method runs for the bidiEdge
1359 24332 : getLanes()[0]->setBidiLane(myBidiEdge->getLanes()[0]);
1360 : } else {
1361 : // find lanes with matching reversed shapes
1362 : int numBidiLanes = 0;
1363 1680 : for (MSLane* l1 : *myLanes) {
1364 3630 : for (MSLane* l2 : *myBidiEdge->myLanes) {
1365 2488 : if (l1->getShape().reverse().almostSame(l2->getShape(), POSITION_EPS * 2)) {
1366 592 : l1->setBidiLane(l2);
1367 592 : numBidiLanes++;
1368 : }
1369 : }
1370 : }
1371 : // warn only once for each pair
1372 538 : if (numBidiLanes == 0 && getNumericalID() < myBidiEdge->getNumericalID()) {
1373 15 : WRITE_WARNINGF(TL("Edge '%s' and bidi edge '%s' have no matching bidi lanes"), getID(), myBidiEdge->getID());
1374 : }
1375 : }
1376 24870 : }
1377 :
1378 :
1379 : bool
1380 291548 : MSEdge::isSuperposable(const MSEdge* other) {
1381 291548 : if (other == nullptr || other->getLanes().size() != myLanes->size()) {
1382 : return false;
1383 : }
1384 : std::vector<MSLane*>::const_iterator it1 = myLanes->begin();
1385 : std::vector<MSLane*>::const_reverse_iterator it2 = other->getLanes().rbegin();
1386 : do {
1387 287514 : if ((*it1)->getShape().reverse() != (*it2)->getShape()) {
1388 : return false;
1389 : }
1390 : it1++;
1391 : it2++;
1392 26 : } while (it1 != myLanes->end());
1393 :
1394 : return true;
1395 : }
1396 :
1397 :
1398 : void
1399 64892 : MSEdge::addWaiting(SUMOVehicle* vehicle) const {
1400 : #ifdef HAVE_FOX
1401 64892 : ScopedLocker<> lock(myWaitingMutex, MSGlobals::gNumSimThreads > 1);
1402 : #endif
1403 64892 : myWaiting.push_back(vehicle);
1404 64892 : }
1405 :
1406 :
1407 : void
1408 57295 : MSEdge::removeWaiting(const SUMOVehicle* vehicle) const {
1409 : #ifdef HAVE_FOX
1410 57295 : ScopedLocker<> lock(myWaitingMutex, MSGlobals::gNumSimThreads > 1);
1411 : #endif
1412 57295 : std::vector<SUMOVehicle*>::iterator it = std::find(myWaiting.begin(), myWaiting.end(), vehicle);
1413 57295 : if (it != myWaiting.end()) {
1414 56878 : myWaiting.erase(it);
1415 : }
1416 57295 : }
1417 :
1418 :
1419 : SUMOVehicle*
1420 75821 : MSEdge::getWaitingVehicle(MSTransportable* transportable, const double position) const {
1421 : #ifdef HAVE_FOX
1422 75821 : ScopedLocker<> lock(myWaitingMutex, MSGlobals::gNumSimThreads > 1);
1423 : #endif
1424 76134 : for (SUMOVehicle* const vehicle : myWaiting) {
1425 5084 : if (transportable->isWaitingFor(vehicle)) {
1426 7171 : if (vehicle->isStoppedInRange(position, MSGlobals::gStopTolerance) ||
1427 2198 : (!vehicle->hasDeparted() &&
1428 2000 : (vehicle->getParameter().departProcedure == DepartDefinition::TRIGGERED ||
1429 83 : vehicle->getParameter().departProcedure == DepartDefinition::CONTAINER_TRIGGERED))) {
1430 : return vehicle;
1431 : }
1432 202 : if (!vehicle->isLineStop(position) && vehicle->allowsBoarding(transportable)) {
1433 228 : WRITE_WARNING((transportable->isPerson() ? "Person '" : "Container '")
1434 : + transportable->getID() + "' at edge '" + getID() + "' position " + toString(position) + " cannot use waiting vehicle '"
1435 : + vehicle->getID() + "' at position " + toString(vehicle->getPositionOnLane()) + " because it is too far away.");
1436 : }
1437 : }
1438 : }
1439 : return nullptr;
1440 : }
1441 :
1442 : std::vector<const SUMOVehicle*>
1443 107752 : MSEdge::getVehicles() const {
1444 : std::vector<const SUMOVehicle*> result;
1445 107752 : if (MSGlobals::gUseMesoSim) {
1446 140 : for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != nullptr; segment = segment->getNextSegment()) {
1447 80 : std::vector<const MEVehicle*> segmentVehs = segment->getVehicles();
1448 80 : result.insert(result.end(), segmentVehs.begin(), segmentVehs.end());
1449 80 : }
1450 : } else {
1451 290011 : for (MSLane* lane : getLanes()) {
1452 670542 : for (auto veh : lane->getVehiclesSecure()) {
1453 488253 : result.push_back(veh);
1454 : }
1455 182289 : lane->releaseVehicles();
1456 : }
1457 : }
1458 107752 : return result;
1459 0 : }
1460 :
1461 : int
1462 453951 : MSEdge::getNumDrivingLanes() const {
1463 : int result = 0;
1464 453951 : SVCPermissions filter = SVCAll;
1465 453951 : if ((myCombinedPermissions & ~(SVC_PEDESTRIAN | SVC_WHEELCHAIR)) != 0) {
1466 : filter = ~(SVC_PEDESTRIAN | SVC_WHEELCHAIR);
1467 96 : } else if ((myCombinedPermissions & (SVC_PEDESTRIAN | SVC_WHEELCHAIR)) != 0) {
1468 : // filter out green verge
1469 : filter = (SVC_PEDESTRIAN | SVC_WHEELCHAIR);
1470 : }
1471 958186 : for (const MSLane* const l : *myLanes) {
1472 504235 : if ((l->getPermissions() & filter) != 0) {
1473 502624 : result++;
1474 : }
1475 : }
1476 453951 : return result;
1477 : }
1478 :
1479 : int
1480 653 : MSEdge::getVehicleNumber() const {
1481 653 : return (int)getVehicles().size();
1482 : }
1483 :
1484 :
1485 : bool
1486 0 : MSEdge::isEmpty() const {
1487 : /// more efficient than retrieving vehicle number
1488 0 : if (MSGlobals::gUseMesoSim) {
1489 0 : for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != nullptr; segment = segment->getNextSegment()) {
1490 0 : if (segment->getCarNumber() > 0) {
1491 : return false;
1492 : }
1493 : }
1494 : } else {
1495 0 : for (MSLane* lane : getLanes()) {
1496 0 : if (lane->getVehicleNumber() > 0) {
1497 : return false;
1498 : }
1499 : }
1500 : }
1501 : return true;
1502 : }
1503 :
1504 :
1505 : double
1506 6 : MSEdge::getWaitingSeconds() const {
1507 : double wtime = 0;
1508 6 : if (MSGlobals::gUseMesoSim) {
1509 4 : for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != nullptr; segment = segment->getNextSegment()) {
1510 3 : wtime += segment->getWaitingSeconds();
1511 : }
1512 : } else {
1513 10 : for (MSLane* lane : getLanes()) {
1514 5 : wtime += lane->getWaitingSeconds();
1515 : }
1516 : }
1517 6 : return wtime;
1518 : }
1519 :
1520 :
1521 : double
1522 14 : MSEdge::getOccupancy() const {
1523 14 : if (myLanes->size() == 0) {
1524 : return 0;
1525 : }
1526 14 : if (MSGlobals::gUseMesoSim) {
1527 : /// @note MESegment only tracks brutto occupancy so we compute this from sratch
1528 : double sum = 0;
1529 4 : for (const SUMOVehicle* veh : getVehicles()) {
1530 2 : sum += dynamic_cast<const MEVehicle*>(veh)->getVehicleType().getLength();
1531 2 : }
1532 2 : return sum / (myLength * (double)myLanes->size());
1533 : } else {
1534 : double sum = 0;
1535 24 : for (auto lane : getLanes()) {
1536 12 : sum += lane->getNettoOccupancy();
1537 : }
1538 12 : return sum / (double)myLanes->size();
1539 : }
1540 : }
1541 :
1542 :
1543 : double
1544 0 : MSEdge::getFlow() const {
1545 0 : if (myLanes->size() == 0) {
1546 : return 0;
1547 : }
1548 : double flow = 0;
1549 0 : for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != nullptr; segment = segment->getNextSegment()) {
1550 0 : flow += (double) segment->getCarNumber() * segment->getMeanSpeed();
1551 : }
1552 0 : return 3600 * flow / (*myLanes)[0]->getLength();
1553 : }
1554 :
1555 :
1556 : double
1557 0 : MSEdge::getBruttoOccupancy() const {
1558 0 : if (myLanes->size() == 0) {
1559 : return 0;
1560 : }
1561 : double occ = 0;
1562 0 : for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != nullptr; segment = segment->getNextSegment()) {
1563 0 : occ += segment->getBruttoOccupancy();
1564 : }
1565 0 : return occ / (*myLanes)[0]->getLength() / (double)(myLanes->size());
1566 : }
1567 :
1568 : double
1569 4240 : MSEdge::getTravelTimeAggregated(const MSEdge* const edge, const SUMOVehicle* const veh, double /*time*/) {
1570 4240 : return edge->getLength() / MIN2(MSRoutingEngine::getAssumedSpeed(edge, veh), veh->getMaxSpeed());
1571 : }
1572 :
1573 :
1574 : void
1575 2098 : MSEdge::inferEdgeType() {
1576 : // @note must be called after closeBuilding() to ensure successors and
1577 : // predecessors are set
1578 2098 : if (isInternal() && myEdgeType == "") {
1579 1274 : const std::string typeBefore = getNormalBefore()->getEdgeType();
1580 1274 : if (typeBefore != "") {
1581 622 : const std::string typeAfter = getNormalSuccessor()->getEdgeType();
1582 622 : if (typeBefore == typeAfter) {
1583 : myEdgeType = typeBefore;
1584 244 : } else if (typeAfter != "") {
1585 60 : MSNet* net = MSNet::getInstance();
1586 60 : auto resBefore = net->getRestrictions(typeBefore);
1587 60 : auto resAfter = net->getRestrictions(typeAfter);
1588 60 : if (resBefore != nullptr && resAfter != nullptr) {
1589 : // create new restrictions for this type-combination
1590 80 : myEdgeType = typeBefore + "|" + typeAfter;
1591 40 : if (net->getRestrictions(myEdgeType) == nullptr) {
1592 40 : for (const auto& item : *resBefore) {
1593 20 : const SUMOVehicleClass svc = item.first;
1594 20 : const double speed = item.second;
1595 : const auto it = (*resAfter).find(svc);
1596 20 : if (it != (*resAfter).end()) {
1597 20 : const double speed2 = it->second;
1598 20 : const double newSpeed = (MSNet::getInstance()->hasJunctionHigherSpeeds()
1599 20 : ? MAX2(speed, speed2) : (speed + speed2) / 2);
1600 20 : net->addRestriction(myEdgeType, svc, newSpeed);
1601 : }
1602 : }
1603 : }
1604 : }
1605 : }
1606 : }
1607 : }
1608 2098 : }
1609 :
1610 :
1611 : double
1612 2134 : MSEdge::getDistanceAt(double pos) const {
1613 : // negative values of myDistances indicate descending kilometrage
1614 2134 : return fabs(myDistance + pos);
1615 : }
1616 :
1617 :
1618 : bool
1619 99 : MSEdge::hasTransientPermissions() const {
1620 99 : return myHaveTransientPermissions;
1621 : }
1622 :
1623 :
1624 : void
1625 8184 : MSEdge::clearState() {
1626 : myPersons.clear();
1627 : myContainers.clear();
1628 : myWaiting.clear();
1629 8184 : }
1630 :
1631 : /****************************************************************************/
|