68 #ifdef CHECK_MEMORY_LEAKS
70 #endif // CHECK_MEMORY_LEAKS
86 myShape(shape), myNumericalID(numericalID),
87 myVehicles(), myLength(length), myWidth(width), myEdge(edge), myMaxSpeed(maxSpeed),
88 myPermissions(permissions),
89 myLogicalPredecessorLane(0),
90 myVehicleLengthSum(0), myInlappingVehicleEnd(10000), myInlappingVehicle(0) {
95 for (MSLinkCont::iterator i =
myLinks.begin(); i !=
myLinks.end(); ++i) {
119 (*veh)->addReminder(rem);
157 if (leader.first != 0) {
159 vIn = leader.first->getSpeed();
160 leaderDecel = leader.first->getCarFollowModel().getMaxDecel();
166 const SUMOReal vHlp = 0.5 * (vIn + mspeed);
170 for (
int i = 0; i <= 10; i++) {
181 }
else if (x > maxPos) {
201 if (leader.first != 0) {
203 vIn = leader.first->getSpeed();
209 const SUMOReal vHlp = 0.5 * (mspeed + vIn);
213 }
else if (xIn > maxPos) {
227 MSLane::VehCont::iterator predIt =
myVehicles.begin();
230 MSLane::VehCont::iterator maxIt =
myVehicles.begin();
249 const SUMOReal lhs = nettoGap/tau + tauDecel - fSpeed - fSpeed*fSpeed/(2*tauDecel) + leaderSpeed*leaderSpeed/(2*tauDecel);
250 if (lhs >= sqrt(tauDecel * tauDecel + leaderSpeed * leaderSpeed)) {
252 const SUMOReal currentMaxSpeed = lhs - tauDecel;
253 if (
MIN2(currentMaxSpeed, mspeed) > maxSpeed) {
254 maxSpeed = currentMaxSpeed;
255 maxPos = leaderRearPos + frontGap;
273 bool adaptableSpeed =
true;
283 if (adaptableSpeed) {
287 if (leaderPos - frontGapNeeded >= 0) {
296 MSLane::VehCont::iterator predIt =
myVehicles.begin();
304 if (adaptableSpeed && leader != 0) {
316 frontMax = leaderRearPos - frontGapNeeded;
324 if (frontMax > 0 && backMin +
POSITION_EPS < frontMax) {
341 bool patchSpeed =
true;
377 for (
unsigned int i = 0; i < 10; i++) {
414 aVehicle->
getID() +
"'. Inserting at lane end instead.");
420 std::vector<MSLane*>::const_iterator ri = bestLaneConts.begin();
425 MSLane* currentLane =
this;
428 while (seen < dist && ri != bestLaneConts.end()) {
430 MSLinkCont::const_iterator link = currentLane->
succLinkSec(*aVehicle, 1, *currentLane, bestLaneConts);
433 #ifdef HAVE_INTERNAL_LANES
434 bool nextInternal =
false;
435 nextLane = (*link)->getViaLane();
437 nextLane = (*link)->getLane();
442 nextLane = (*link)->getLane();
466 if (nspeed < speed) {
468 speed =
MIN2(nspeed, speed);
478 if (nspeed < speed) {
481 speed =
MIN2(cfModel.
freeSpeed(aVehicle, speed, seen, nspeed), speed);
490 #ifdef HAVE_INTERNAL_LANES
491 const SUMOTime leaveTime = (*link)->getViaLane() == 0 ? arrivalTime +
TIME2STEPS((*link)->getLength() * speed) : arrivalTime +
TIME2STEPS((*link)->getViaLane()->getLength() * speed);
495 if ((*link)->hasApproachingFoe(arrivalTime, leaveTime)) {
497 if (nspeed < speed) {
499 speed =
MIN2(nspeed, speed);
509 if (nspeed < speed) {
511 speed =
MIN2(nspeed, speed);
522 currentLane = nextLane;
527 if (nspeed < speed) {
529 speed =
MIN2(nspeed, speed);
533 WRITE_ERROR(
"Vehicle '" + aVehicle->
getID() +
"' will not be able to depart using given velocity!");
547 if (gap < frontGapNeeded) {
559 if (gap < backGapNeeded) {
571 if (approaching.first != 0) {
572 const MSVehicle*
const follower = approaching.first;
575 if (gap < backGapNeeded) {
585 if (gap <= frontGapNeeded) {
630 std::pair<MSVehicle*, SUMOReal>
636 return std::make_pair(last, pos);
642 return std::make_pair<MSVehicle*, SUMOReal>(0, 0);
651 std::vector<MSVehicle*> collisions;
652 VehCont::iterator lastBeforeEnd =
myVehicles.end() - 1;
653 VehCont::iterator veh;
655 for (veh =
myVehicles.begin(); veh != lastBeforeEnd;) {
657 VehCont::const_iterator pred(veh + 1);
658 if ((*veh)->moveRegardingCritical(t,
this, *pred, 0,
myLeftVehLength)) {
659 collisions.push_back(*veh);
665 collisions.push_back(*veh);
667 assert((*veh)->getPositionOnLane() <=
myLength);
668 assert((*veh)->getLane() ==
this);
670 for (std::vector<MSVehicle*>::iterator i = collisions.begin(); i != collisions.end(); ++i) {
686 VehCont::iterator lastVeh =
myVehicles.end() - 1;
687 for (VehCont::iterator veh =
myVehicles.begin(); veh != lastVeh;) {
688 VehCont::iterator pred = veh + 1;
689 SUMOReal gap = (*pred)->getPositionOnLane() - (*pred)->getVehicleType().getLength() - (*veh)->getPositionOnLane() - (*veh)->getVehicleType().getMinGap();
711 MSLane* currentLane = (*next)->getLanes()[0];
715 while (seen < dist && next != veh.
getRoute().
end() - 1) {
717 MSLane* nextLane = (*next)->getLanes()[0];
738 }
else if (target != 0 && moved) {
749 into.push_back(target);
783 DictType::iterator it =
myDict.find(
id);
786 myDict.insert(DictType::value_type(
id, ptr));
795 DictType::iterator it =
myDict.find(
id);
806 for (DictType::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
815 for (DictType::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
816 into.push_back((*i).first);
827 return (link !=
myLinks.end());
875 MSLinkCont::const_iterator
877 const MSLane& succLinkSource,
const std::vector<MSLane*> &conts)
const {
880 if (nRouteEdge == 0) {
882 return succLinkSource.
myLinks.end();
891 MSLinkCont::const_iterator link;
892 if (nRouteSuccs > 0 && conts.size() >= nRouteSuccs && nRouteSuccs > 0) {
894 for (link = succLinkSource.
myLinks.begin(); link != succLinkSource.
myLinks.end() ; ++link) {
895 if ((*link)->getLane() != 0 && (*link)->getLane()->myEdge == nRouteEdge && (*link)->getLane()->allowsVehicleClass(veh.
getVehicleType().
getVehicleClass())) {
897 if ((*link)->getLane() == conts[nRouteSuccs - 1]) {
907 std::vector<MSLinkCont::const_iterator> valid;
908 for (link = succLinkSource.
myLinks.begin(); link != succLinkSource.
myLinks.end() ; ++link) {
909 if ((*link)->getLane() != 0 && (*link)->getLane()->myEdge == nRouteEdge && (*link)->getLane()->allowsVehicleClass(veh.
getVehicleType().
getVehicleClass())) {
910 valid.push_back(link);
914 if (valid.size() == 0) {
916 return succLinkSource.
myLinks.end();
919 if (valid.size() == 1) {
920 return *(valid.begin());
926 if (nRouteEdge2 == 0 || next_allowed == 0) {
927 return *(valid.begin());
931 for (std::vector<MSLinkCont::const_iterator>::iterator i = valid.begin(); i != valid.end(); ++i) {
932 if (find(next_allowed->begin(), next_allowed->end(), (**i)->getLane()) != next_allowed->end()) {
936 return *(valid.begin());
958 throw "Only within the gui-version";
965 if (remVehicle->
getID() == (*it)->getID()) {
1016 std::map<MSEdge*, std::vector<MSLane*> >::const_iterator i =
myApproachingLanes.find(edge);
1020 const std::vector<MSLane*> &lanes = (*i).second;
1021 return find(lanes.begin(), lanes.end(), lane) != lanes.end();
1027 inline int operator()(
const std::pair<const MSVehicle* , SUMOReal> &p1,
const std::pair<const MSVehicle* , SUMOReal> &p2)
const {
1028 return p1.second < p2.second;
1032 std::pair<MSVehicle* const, SUMOReal>
1037 std::set<MSLane*> visited;
1038 std::vector<std::pair<MSVehicle*, SUMOReal> > possible;
1039 std::vector<MSLane::IncomingLaneInfo> newFound;
1041 while (toExamine.size() != 0) {
1042 for (std::vector<MSLane::IncomingLaneInfo>::iterator i = toExamine.begin(); i != toExamine.end(); ++i) {
1048 MSLane* next = (*i).lane;
1056 if ((*i).length + seen < dist) {
1057 const std::vector<MSLane::IncomingLaneInfo> &followers = next->
getIncomingLanes();
1058 for (std::vector<MSLane::IncomingLaneInfo>::const_iterator j = followers.begin(); j != followers.end(); ++j) {
1059 if (visited.find((*j).lane) == visited.end()) {
1060 visited.insert((*j).lane);
1062 ili.
lane = (*j).lane;
1063 ili.
length = (*j).length + (*i).length;
1065 newFound.push_back(ili);
1072 swap(newFound, toExamine);
1074 if (possible.size() == 0) {
1075 return std::pair<MSVehicle * const, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
1078 return *(possible.begin());
1082 std::pair<MSVehicle* const, SUMOReal>
1084 const std::vector<MSLane*> &bestLaneConts)
const {
1086 return std::pair<MSVehicle * const, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
1088 unsigned int view = 1;
1090 const MSLane* targetLane =
this;
1095 const MSLane* nextLane = targetLane;
1099 MSLinkCont::const_iterator link = targetLane->
succLinkSec(veh, view, *nextLane, bestLaneConts);
1101 return std::pair<MSVehicle * const, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
1103 #ifdef HAVE_INTERNAL_LANES
1104 bool nextInternal =
false;
1105 nextLane = (*link)->getViaLane();
1106 if (nextLane == 0) {
1107 nextLane = (*link)->getLane();
1109 nextInternal =
true;
1112 nextLane = (*link)->getLane();
1114 if (nextLane == 0) {
1115 return std::pair<MSVehicle * const, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
1120 return std::pair<MSVehicle * const, SUMOReal>(leader, seen + leader->getPositionOnLane() - leader->getVehicleType().getLength());
1132 return std::pair<MSVehicle * const, SUMOReal>(
static_cast<MSVehicle*
>(0), -1);
1134 #ifdef HAVE_INTERNAL_LANES
1135 if (!nextInternal) {
1153 for (std::vector<MSEdge*>::iterator i = pred.begin(); i != pred.end();) {
1162 if (pred.size() != 0) {
1164 MSEdge* best = *pred.begin();
1205 for (VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1206 v += (*i)->getSpeed();
1218 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1219 ret += (*i)->getHBEFA_CO2Emissions();
1230 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1231 ret += (*i)->getHBEFA_COEmissions();
1242 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1243 ret += (*i)->getHBEFA_PMxEmissions();
1254 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1255 ret += (*i)->getHBEFA_NOxEmissions();
1266 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1267 ret += (*i)->getHBEFA_HCEmissions();
1278 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1279 ret += (*i)->getHBEFA_FuelConsumption();
1290 if (vehs.size() == 0) {
1294 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1295 SUMOReal sv = (*i)->getHarmonoise_NoiseEmissions();
1296 ret += (
SUMOReal) pow(10., (sv / 10.));
1316 myLaneDir(e->getLanes()[0]->
getShape().getBegLine().atan2PositiveAngle())
1325 if (ae1 != 0 && ae1->size() != 0) {
1329 if (ae2 != 0 && ae2->size() != 0) {