bool MSLane::emit(MSVehicle& veh) throw(ProcessError) { SUMOReal pos = 0; SUMOReal speed = 0; bool patchSpeed = true; // whether the speed shall be adapted to infrastructure/traffic in front // determine the speed const SUMOVehicleParameter &pars = veh.getParameter(); size_t stripId = getEmptyStartStripID(veh.getWidth()); switch (pars.departSpeedProcedure) { case DEPART_SPEED_GIVEN: speed = pars.departSpeed; patchSpeed = false; break; case DEPART_SPEED_RANDOM: speed = RandHelper::rand(MIN2(veh.getMaxSpeed(), getMaxSpeed())); patchSpeed = true; // !!!(?) break; case DEPART_SPEED_MAX: speed = MIN2(veh.getMaxSpeed(), getMaxSpeed()); patchSpeed = true; // !!!(?) break; case DEPART_SPEED_DEFAULT: default: // speed = 0 was set before patchSpeed = false; // !!!(?) break; } // determine the position switch (pars.departPosProcedure) { case DEPART_POS_GIVEN: if (pars.departPos >= 0.) { pos = pars.departPos; } else { pos = pars.departPos + getLength(); } break; case DEPART_POS_RANDOM: pos = RandHelper::rand(getLength()); break; case DEPART_POS_RANDOM_FREE: { for (unsigned int i=0; i < 10; i++) { // we will try some random positions ... pos = RandHelper::rand(getLength()); if (isEmissionSuccess(&veh, speed, pos, patchSpeed, stripId)) { return true; } } // ... and if that doesn't work, we put the vehicle to the free position return freeEmit(veh, speed); } break; case DEPART_POS_FREE: return freeEmit(veh, speed); case DEPART_POS_DEFAULT: default: // pos = 0 was set before break; } // try to emit return isEmissionSuccess(&veh, speed, pos, patchSpeed, stripId); }
// ------ Vehicle emission ------ bool MSLane::freeEmit(MSVehicle& veh, SUMOReal mspeed) throw() { size_t stripId = getEmptyStartStripID(veh.getWidth()); bool adaptableSpeed = true; if (getVehicleNumber()==0) { if (isEmissionSuccess(&veh, mspeed, 0, adaptableSpeed,stripId)) { return true; } } else { // check whether the vehicle can be put behind the last one if there is such MSVehicle *leader = getLastVehicle(veh.getStrips()); if (leader != 0) { SUMOReal leaderPos = leader->getPositionOnLane() - leader->getVehicleType().getLength(); SUMOReal speed = mspeed; if (adaptableSpeed) { speed = leader->getSpeed(); } SUMOReal frontGapNeeded = veh.getCarFollowModel().getSecureGap(speed, leader->getCarFollowModel().getSpeedAfterMaxDecel(leader->getSpeed())); if (leaderPos-frontGapNeeded>=0) { SUMOReal tspeed = MIN2(veh.getCarFollowModel().ffeV(&veh, mspeed, frontGapNeeded, leader->getSpeed()), mspeed); // check whether we can emit in behind the last vehicle on the lane if (isEmissionSuccess(&veh, tspeed, 0, adaptableSpeed, stripId)) { return true; } else std::cerr << "not successful emission 1" ; } } else { if (isEmissionSuccess(&veh, mspeed, 0, adaptableSpeed, stripId)) { return true; } else std::cerr << "not successful emission 2" ; } } /* ashu StripCont strips =getMyStrips(); for (StripContConstIter it=strips.begin(); it != strips.end(); ++it) {if ((*it)->freeEmitCheck(veh, mspeed)) return true;} //TODO: Uncomment and fix // go through the lane, look for free positions (starting after the last vehicle) MSLane::VehCont::iterator predIt = myVehicles.begin(); while (predIt!=myVehicles.end()) { // get leader (may be zero) and follower const MSVehicle *leader = predIt!=myVehicles.end()-1 ? *(predIt+1) : getPartialOccupator(); const MSVehicle *follower = *predIt; // patch speed if allowed SUMOReal speed = mspeed; if (adaptableSpeed&&leader!=0) { speed = MIN2(leader->getSpeed(), mspeed); } // compute the space needed to not collide with leader SUMOReal frontMax = getLength(); if (leader!=0) { SUMOReal leaderRearPos = leader->getPositionOnLane() - leader->getVehicleType().getLength(); if (leader == getPartialOccupator()) { leaderRearPos = getPartialOccupatorEnd(); } frontMax = leaderRearPos - veh.getCarFollowModel().getSecureGap(speed, leader->getCarFollowModel().getSpeedAfterMaxDecel(leader->getSpeed())); } // compute the space needed to not let the follower collide const SUMOReal followPos = follower->getPositionOnLane(); const SUMOReal backGapNeeded = follower->getCarFollowModel().getSecureGap(follower->getSpeed(), veh.getCarFollowModel().getSpeedAfterMaxDecel(speed)); const SUMOReal backMin = followPos + backGapNeeded + veh.getVehicleType().getLength(); // check whether there is enough room (given some extra space for rounding errors) if (frontMax>0 && backMin+POSITION_EPS<frontMax) { // try emit vehicle (should be always ok) if (isEmissionSuccess(&veh, speed, backMin+POSITION_EPS, adaptableSpeed)) { std::cerr << "FIX working" ; return true; } } ++predIt; } */ //TODO: Recheck01 ___AB oct 2011 StripCont strips =getMyStrips(); for (StripContConstIter it=strips.begin(); it != strips.end(); ++it) { // go through the lane, look for free positions (starting after the last vehicle) MSLane::VehCont::iterator predIt = (*it)->myVehicles.begin(); while (predIt!=(*it)->myVehicles.end()) { // get leader (may be zero) and follower const MSVehicle *leader = predIt!=(*it)->myVehicles.end()-1 ? *(predIt+1) : (*it)->getPartialOccupator(); const MSVehicle *follower = *predIt; // patch speed if allowed SUMOReal speed = mspeed; if (adaptableSpeed&&leader!=0) { speed = MIN2(leader->getSpeed(), mspeed); } // compute the space needed to not collide with leader SUMOReal frontMax = getLength(); if (leader!=0) { SUMOReal leaderRearPos = leader->getPositionOnLane() - leader->getVehicleType().getLength(); if (leader == (*it)->getPartialOccupator()) { leaderRearPos = (*it)->getPartialOccupatorEnd(); } frontMax = leaderRearPos - veh.getCarFollowModel().getSecureGap(speed, leader->getCarFollowModel().getSpeedAfterMaxDecel(leader->getSpeed())); } // compute the space needed to not let the follower collide const SUMOReal followPos = follower->getPositionOnLane(); const SUMOReal backGapNeeded = follower->getCarFollowModel().getSecureGap(follower->getSpeed(), veh.getCarFollowModel().getSpeedAfterMaxDecel(speed)); const SUMOReal backMin = followPos + backGapNeeded + veh.getVehicleType().getLength(); // check whether there is enough room (given some extra space for rounding errors) if (frontMax>0 && backMin+POSITION_EPS<frontMax) { // try emit vehicle (should be always ok) if (isEmissionSuccess(&veh, speed, backMin+POSITION_EPS, adaptableSpeed, stripId)) { std::cerr << "FIX working" ; return true; } } ++predIt; } }//for // first check at lane's begin std::cerr << "not successful emission last" ; return false; }