void MSInductLoop::notifyLeave(MSVehicle& veh, bool isArrival, bool isLaneChange) throw() { if (veh.getPositionOnLane() > myPosition && veh.getPositionOnLane() - veh.getVehicleType().getLength() <= myPosition) { // vehicle is on detector during lane change leaveDetectorByLaneChange(veh); } }
void MSInductLoop::enterDetectorByMove(MSVehicle& veh, SUMOReal entryTimestep) throw() { unsigned int mainStripNum = 0; int flag = 0; for( MSLane::StripContIter it = myLane->myStrips.begin(); it!=myLane->myStrips.end(); it ++){ if(veh.isMainStrip(**it)){ myVehiclesOnDet[mainStripNum].insert(std::make_pair(&veh, entryTimestep)); flag = 1; break; } mainStripNum++; } if(mainStripNum < myStripCount) veh.quitRemindedEntered(this); /*if (myCurrentVehicle[mainStripNum]!=0 && myCurrentVehicle[mainStripNum]!=&veh) { // in fact, this is an error - a second vehicle is on the detector // before the first one leaves... (collision) // Still, this seems to happen, but should not be handled herein. // we will inform the user, etc., but continue as nothing had happened MsgHandler::getWarningInstance()->inform("Collision on e1-detector '" + getID() + "'.\n Vehicle '" + myCurrentVehicle[mainStripNum]->getID() + "' was aready at detector as '" + veh.getID() + "' entered."); leaveDetectorByMove(*(myCurrentVehicle[mainStripNum]), entryTimestep); }*/ //disabled by pulakesh_segmentation fault myCurrentVehicle[mainStripNum] = &veh; }
SUMOVehicle* MSVehicleControl::getWaitingVehicle(const MSEdge* const edge, const std::set<std::string>& lines, const SUMOReal position, const std::string ridingID) { if (myWaiting.find(edge) != myWaiting.end()) { // for every vehicle waiting vehicle at this edge std::vector<SUMOVehicle*> waitingTooFarAway; for (std::vector<SUMOVehicle*>::const_iterator it = myWaiting[edge].begin(); it != myWaiting[edge].end(); ++it) { const std::string& line = (*it)->getParameter().line == "" ? (*it)->getParameter().id : (*it)->getParameter().line; SUMOReal vehiclePosition = (*it)->getPositionOnLane(); // if the line of the vehicle is contained in the set of given lines and the vehicle is stopped and is positioned // in the interval [position - t, position + t] for a tolerance t=10 if (lines.count(line)) { if ((position - 10 <= vehiclePosition) && (vehiclePosition <= position + 10)) { return (*it); } else if ((*it)->isStoppedTriggered() || (*it)->getParameter().departProcedure == DEPART_TRIGGERED) { // maybe we are within the range of the stop MSVehicle* veh = static_cast<MSVehicle*>(*it); if (veh->isStoppedInRange(position)) { return (*it); } else { waitingTooFarAway.push_back(*it); } } } } for (std::vector<SUMOVehicle*>::iterator it = waitingTooFarAway.begin(); it != waitingTooFarAway.end(); ++it) { WRITE_WARNING(ridingID + " at edge '" + edge->getID() + "' position " + toString(position) + " cannot use waiting vehicle '" + (*it)->getID() + "' at position " + toString((*it)->getPositionOnLane()) + " because it is too far away."); } } return 0; }
bool MSCalibrator::VehicleRemover::notifyEnter(SUMOTrafficObject& veh, Notification /* reason */, const MSLane* /* enteredLane */) { if (myParent == nullptr) { return false; } if (myParent->isActive()) { myParent->updateMeanData(); const bool calibrateFlow = myParent->myCurrentStateInterval->q >= 0; const int totalWishedNum = myParent->totalWished(); int adaptedNum = myParent->passed() + myParent->myClearedInJam; MSVehicle* vehicle = dynamic_cast<MSVehicle*>(&veh); if (calibrateFlow && adaptedNum > totalWishedNum) { #ifdef MSCalibrator_DEBUG std::cout << time2string(MSNet::getInstance()->getCurrentTimeStep()) << " " << myParent->getID() << " vaporizing " << vehicle->getID() << " to reduce flow\n"; #endif if (myParent->scheduleRemoval(vehicle)) { myParent->myRemoved++; } } else if (myParent->invalidJam(myLaneIndex)) { #ifdef MSCalibrator_DEBUG std::cout << time2string(MSNet::getInstance()->getCurrentTimeStep()) << " " << myParent->getID() << " vaporizing " << vehicle->getID() << " to clear jam\n"; #endif if (!myParent->myHaveWarnedAboutClearingJam) { WRITE_WARNING("Clearing jam at calibrator '" + myParent->myID + "' at time " + time2string(MSNet::getInstance()->getCurrentTimeStep())); myParent->myHaveWarnedAboutClearingJam = true; } if (myParent->scheduleRemoval(vehicle)) { myParent->myClearedInJam++; } } } return true; }
std::pair<MSVehicle* const, SUMOReal> MSLaneChanger::getRealLeader(const ChangerIt& target) const { // get the leading vehicle on the lane to change to MSVehicle* neighLead = target->lead; // check whether the hopped vehicle got the leader if (target->hoppedVeh != 0) { SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane(); if (hoppedPos > veh(myCandi)->getPositionOnLane() && (neighLead == 0 || neighLead->getPositionOnLane() > hoppedPos)) { neighLead = target->hoppedVeh; } } if (neighLead == 0) { MSLane* targetLane = target->lane; MSVehicle* predP = targetLane->getPartialOccupator(); if (predP != 0) { return std::pair<MSVehicle*, SUMOReal>(predP, targetLane->getPartialOccupatorEnd() - veh(myCandi)->getPositionOnLane() - veh(myCandi)->getVehicleType().getMinGap()); } const std::vector<MSLane*>& bestLaneConts = veh(myCandi)->getBestLanesContinuation(myCandi->lane); SUMOReal seen = myCandi->lane->getLength() - veh(myCandi)->getPositionOnLane(); SUMOReal speed = veh(myCandi)->getSpeed(); SUMOReal dist = veh(myCandi)->getCarFollowModel().brakeGap(speed) + veh(myCandi)->getVehicleType().getMinGap(); if (seen > dist) { return std::pair<MSVehicle* const, SUMOReal>(static_cast<MSVehicle*>(0), -1); } return target->lane->getLeaderOnConsecutive(dist, seen, speed, *veh(myCandi), bestLaneConts); } else { MSVehicle* candi = veh(myCandi); return std::pair<MSVehicle* const, SUMOReal>(neighLead, neighLead->getPositionOnLane() - neighLead->getVehicleType().getLength() - candi->getPositionOnLane() - candi->getVehicleType().getMinGap()); } }
bool MSMsgInductLoop::isStillActive(MSVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed) throw() { if (newPos < myPosition) { // detector not reached yet return true; } if (myVehiclesOnDet.find(&veh) == myVehiclesOnDet.end()) { // entered the detector by move SUMOReal entryTimestep = (SUMOReal) ((SUMOReal) MSNet::getInstance()->getCurrentTimeStep() + ((myPosition - oldPos) / newSpeed)); if (newPos - veh.getVehicleType().getLength() > myPosition) { // entered and passed detector in a single timestep SUMOReal leaveTimestep = (SUMOReal) ((SUMOReal) MSNet::getInstance()->getCurrentTimeStep() + ((myPosition - oldPos + veh.getVehicleType().getLength()) / newSpeed)); enterDetectorByMove(veh, entryTimestep); leaveDetectorByMove(veh, leaveTimestep); return false; } // entered detector, but not passed enterDetectorByMove(veh, entryTimestep); return true; } else { // vehicle has been on the detector the previous timestep if (newPos - veh.getVehicleType().getLength() >= myPosition) { // vehicle passed the detector SUMOReal leaveTimestep = (SUMOReal) ((SUMOReal) MSNet::getInstance()->getCurrentTimeStep() + ((myPosition - oldPos + veh.getVehicleType().getLength()) / newSpeed)); leaveDetectorByMove(veh, leaveTimestep); return false; } // vehicle stays on the detector return true; } }
void MSLCM_DK2004::informBlocker(MSAbstractLaneChangeModel::MSLCMessager& msgPass, int& blocked, int dir, const std::pair<MSVehicle*, SUMOReal>& neighLead, const std::pair<MSVehicle*, SUMOReal>& neighFollow) { if ((blocked & LCA_BLOCKED_BY_FOLLOWER) != 0) { assert(neighFollow.first != 0); MSVehicle* nv = neighFollow.first; SUMOReal decelGap = neighFollow.second + SPEED2DIST(myVehicle.getSpeed()) * (SUMOReal) 2.0 - MAX2(nv->getSpeed() - (SUMOReal) ACCEL2DIST(nv->getCarFollowModel().getMaxDecel()) * (SUMOReal) 2.0, (SUMOReal) 0); if (neighFollow.second > 0 && decelGap > 0 && decelGap >= nv->getCarFollowModel().getSecureGap(nv->getSpeed(), myVehicle.getSpeed(), myVehicle.getCarFollowModel().getMaxDecel())) { SUMOReal vsafe = myCarFollowModel.followSpeed(&myVehicle, myVehicle.getSpeed(), neighFollow.second, neighFollow.first->getSpeed(), neighFollow.first->getCarFollowModel().getMaxDecel()); msgPass.informNeighFollower(new Info(vsafe, dir | LCA_AMBLOCKINGFOLLOWER), &myVehicle); } else { SUMOReal vsafe = neighFollow.second <= 0 ? 0 : myCarFollowModel.followSpeed(&myVehicle, myVehicle.getSpeed(), neighFollow.second, neighFollow.first->getSpeed(), neighFollow.first->getCarFollowModel().getMaxDecel()); msgPass.informNeighFollower(new Info(vsafe, dir | LCA_AMBLOCKINGFOLLOWER_DONTBRAKE), &myVehicle); } } if ((blocked & LCA_BLOCKED_BY_LEADER) != 0) { if (neighLead.first != 0 && neighLead.second > 0) { msgPass.informNeighLeader(new Info(0, dir | LCA_AMBLOCKINGLEADER), &myVehicle); } } }
void MSInductLoop::leaveDetectorByMove(MSVehicle& veh, SUMOReal leaveTimestep) throw() { int mainStripNum = 0;int flag = 0; for( MSLane::StripContIter it = myLane->myStrips.begin(); it!=myLane->myStrips.end(); it ++){ if(veh.isMainStrip(**it)){ flag = 1; break; } mainStripNum++; } VehicleMap::iterator it = myVehiclesOnDet[mainStripNum].find(&veh); //uncommnet following for extra check // assert(it != myVehiclesOnDet[mainStripNum].end()); if(it!= myVehiclesOnDet[mainStripNum].end()){ SUMOReal entryTimestep = it->second; myVehiclesOnDet[mainStripNum].erase(it); myCurrentVehicle[mainStripNum] = 0; //uncomment following for extra check //assert(entryTimestep < leaveTimestep); myVehicleDataCont[mainStripNum].push_back(VehicleData(veh.getID(), veh.getVehicleType().getLength(), entryTimestep, leaveTimestep)); myLastOccupancy[mainStripNum] = 0; veh.quitRemindedLeft(this); } else { //exit(0); } }
std::pair<MSVehicle * const, SUMOReal> MSLane::getLeaderOnConsecutive(SUMOReal dist, SUMOReal seen, SUMOReal speed, const MSVehicle &veh, const std::vector<MSLane*> &bestLaneConts) const { if (seen>dist) { return std::pair<MSVehicle * const, SUMOReal>(0, -1); } unsigned int view = 1; // loop over following lanes const MSLane * targetLane = this; MSVehicle *leader = targetLane->getPartialOccupator(); if (leader!=0) { return std::pair<MSVehicle * const, SUMOReal>(leader, seen-targetLane->getPartialOccupatorEnd()); } const MSLane * nextLane = targetLane; while (true) { // get the next link used MSLinkCont::const_iterator link = targetLane->succLinkSec(veh, view, *nextLane, bestLaneConts); if (nextLane->isLinkEnd(link) || !(*link)->havePriority() || (*link)->getState()==MSLink::LINKSTATE_TL_RED) { return std::pair<MSVehicle * const, SUMOReal>(0, -1); } #ifdef HAVE_INTERNAL_LANES bool nextInternal = false; nextLane = (*link)->getViaLane(); if (nextLane==0) { nextLane = (*link)->getLane(); } else { nextInternal = true; } #else nextLane = (*link)->getLane(); #endif if (nextLane==0) { return std::pair<MSVehicle * const, SUMOReal>(0, -1); } MSVehicle * leader = nextLane->getLastVehicle(veh.getStrips()); if (leader!=0) { return std::pair<MSVehicle * const, SUMOReal>(leader, seen+leader->getPositionOnLane()-leader->getVehicleType().getLength()); } else { leader = nextLane->getPartialOccupator(); if (leader!=0) { return std::pair<MSVehicle * const, SUMOReal>(leader, seen+nextLane->getPartialOccupatorEnd()); } } if (nextLane->getMaxSpeed()<speed) { dist = veh.getCarFollowModel().brakeGap(nextLane->getMaxSpeed()); } seen += nextLane->getLength(); if (seen>dist) { return std::pair<MSVehicle * const, SUMOReal>(0, -1); } #ifdef HAVE_INTERNAL_LANES if (!nextInternal) { view++; } #else view++; #endif } }
MSVehicle * MSLane::removeFirstVehicle() { MSVehicle *veh = *(myVehicles.end()-1); veh->leaveLaneAtMove(0); myVehicles.erase(myVehicles.end()-1); myVehicleLengthSum -= veh->getVehicleType().getLength(); return veh; }
bool MSMsgInductLoop::notifyEnter(MSVehicle& veh, bool, bool) throw() { if (veh.getPositionOnLane() - veh.getVehicleType().getLength() > myPosition) { // vehicle-front is beyond detector. Ignore return false; } // vehicle is in front of detector return true; }
//TODO: refactor out? only called by setCritical for getting the leader (last veh of lane) MSVehicle* MSLane::pop(SUMOTime) { assert(! myVehicles.empty()); MSVehicle* first = myVehicles.back(); first->leaveLaneAtMove(SPEED2DIST(first->getSpeed())/* - first->pos()*/); myVehicles.pop_back(); myVehicleLengthSum -= first->getVehicleType().getLength(); return first; }
SUMOVehicle* MSVehicleControl::buildVehicle(SUMOVehicleParameter* defs, const MSRoute* route, MSVehicleType* type, const bool ignoreStopErrors, const bool fromRouteFile) { myLoadedVehNo++; MSVehicle* built = new MSVehicle(defs, route, type, type->computeChosenSpeedDeviation(fromRouteFile ? MSRouteHandler::getParsingRNG() : nullptr)); built->addStops(ignoreStopErrors); MSNet::getInstance()->informVehicleStateListener(built, MSNet::VEHICLE_STATE_BUILT); return built; }
std::vector<std::string> MSE2Collector::getCurrentVehicleIDs() const { std::vector<std::string> ret; for (std::list<SUMOVehicle*>::const_iterator i = myKnownVehicles.begin(); i != myKnownVehicles.end(); ++i) { MSVehicle* veh = static_cast<MSVehicle*>(*i); ret.push_back(veh->getID()); } std::sort(ret.begin(), ret.end()); return ret; }
std::pair<MSVehicle* const, SUMOReal> MSLaneChanger::getRealFollower(const ChangerIt& target) const { MSVehicle* neighFollow = veh(target); // check whether the hopped vehicle got the follower if (target->hoppedVeh != 0) { SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane(); if (hoppedPos <= veh(myCandi)->getPositionOnLane() && (neighFollow == 0 || neighFollow->getPositionOnLane() > hoppedPos)) { neighFollow = target->hoppedVeh; } } if (neighFollow == 0) { SUMOReal speed = target->lane->getSpeedLimit(); // in order to look back, we'd need the minimum braking ability of vehicles in the net... // we'll assume it to be 4m/s^2 // !!!revisit SUMOReal dist = speed * speed / (2.*4.) + SPEED2DIST(speed); dist = MIN2(dist, (SUMOReal) 500.); MSVehicle* candi = veh(myCandi); SUMOReal seen = candi->getPositionOnLane() - candi->getVehicleType().getLength(); return target->lane->getFollowerOnConsecutive(dist, seen, candi->getSpeed(), candi->getPositionOnLane() - candi->getVehicleType().getLength(), 4.5);//!!! recheck } else { MSVehicle* candi = veh(myCandi); return std::pair<MSVehicle* const, SUMOReal>(neighFollow, candi->getPositionOnLane() - candi->getVehicleType().getLength() - neighFollow->getPositionOnLane() - neighFollow->getVehicleType().getMinGap()); } }
SUMOReal MSPerson::MSPersonStage_Driving::getAngle(SUMOTime /* now */) const { if (myVehicle != 0) { MSVehicle* veh = dynamic_cast<MSVehicle*>(myVehicle); if (veh != 0) { return veh->getAngle() + 90; } else { return 0; } } return getEdgeAngle(myWaitingEdge, myWaitingPos); }
bool MSInductLoop::isStillActive(MSVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed) throw() { if (newPos < myPosition) { // detector not reached yet return true; } int mainStripNum = 0;int flag =0; for( MSLane::StripContIter it = myLane->myStrips.begin(); it!=myLane->myStrips.end(); it ++){ if(veh.isMainStrip(**it)){ flag=1; break; } mainStripNum++; } if (flag == 1 && myVehiclesOnDet[mainStripNum].find(&veh) == myVehiclesOnDet[mainStripNum].end()) { // entered the detector by move SUMOReal entryTime = STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()); if (newSpeed!=0) { entryTime += (myPosition - oldPos) / newSpeed; } if (newPos - veh.getVehicleType().getLength() > myPosition) { // entered and passed detector in a single timestep SUMOReal leaveTime = STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()); leaveTime += (myPosition - oldPos + veh.getVehicleType().getLength()) / newSpeed; enterDetectorByMove(veh, entryTime); leaveDetectorByMove(veh, leaveTime); return false; } // entered detector, but not passed enterDetectorByMove(veh, entryTime); return true; } else if(flag==1){ // vehicle has been on the detector the previous timestep if (newPos - veh.getVehicleType().getLength() >= myPosition) { // vehicle passed the detector SUMOReal leaveTime = STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()); leaveTime += (myPosition - oldPos + veh.getVehicleType().getLength()) / newSpeed; leaveDetectorByMove(veh, leaveTime); return false; } // vehicle stays on the detector return true; } else {std::cerr<<"Main strip not found\n";} }
void MSVehicleTransfer::loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset, MSVehicleControl& vc) { MSVehicle* veh = dynamic_cast<MSVehicle*>(vc.getVehicle(attrs.getString(SUMO_ATTR_ID))); assert(veh != 0); SUMOTime proceedTime = (SUMOTime)attrs.getLong(SUMO_ATTR_DEPART); MSLane* parkingLane = attrs.hasAttribute(SUMO_ATTR_PARKING) ? MSLane::dictionary(attrs.getString(SUMO_ATTR_PARKING)): 0; myVehicles.push_back(VehicleInformation(veh, proceedTime + offset, parkingLane != 0)); if (parkingLane != 0) { myParkingVehicles[parkingLane].insert(veh); veh->setTentativeLaneAndPosition(parkingLane, veh->getPositionOnLane()); veh->processNextStop(veh->getSpeed()); } MSNet::getInstance()->getInsertionControl().alreadyDeparted(veh); }
void MSDevice_Routing::buildVehicleDevices(MSVehicle &v, std::vector<MSDevice*> &into) throw() { OptionsCont &oc = OptionsCont::getOptions(); if (oc.getFloat("device.routing.probability")==0&&!oc.isSet("device.routing.knownveh")) { // no route computation is modelled return; } // route computation is enabled bool haveByNumber = false; if (oc.getBool("device.routing.deterministic")) { haveByNumber = ((myVehicleIndex%1000) < (int)(oc.getFloat("device.routing.probability")*1000.)); } else { haveByNumber = RandHelper::rand()<=oc.getFloat("device.routing.probability"); } bool haveByName = oc.isSet("device.routing.knownveh") && OptionsCont::getOptions().isInStringVector("device.routing.knownveh", v.getID()); if (haveByNumber||haveByName) { // build the device MSDevice_Routing* device = new MSDevice_Routing(v, "routing_" + v.getID(), string2time(oc.getString("device.routing.period")), string2time(oc.getString("device.routing.pre-period"))); into.push_back(device); // initialise edge efforts if not done before if (myEdgeEfforts.size()==0) { const std::vector<MSEdge*> &edges = MSNet::getInstance()->getEdgeControl().getEdges(); for (std::vector<MSEdge*>::const_iterator i=edges.begin(); i!=edges.end(); ++i) { myEdgeEfforts[*i] = (*i)->getCurrentTravelTime(); } } // make the weights be updated if (myEdgeWeightSettingCommand==0) { myEdgeWeightSettingCommand = new StaticCommand< MSDevice_Routing >(&MSDevice_Routing::adaptEdgeEfforts); MSNet::getInstance()->getEndOfTimestepEvents().addEvent( myEdgeWeightSettingCommand, 0, MSEventControl::ADAPT_AFTER_EXECUTION); myAdaptationWeight = oc.getFloat("device.routing.adaptation-weight"); myAdaptationInterval = string2time(oc.getString("device.routing.adaptation-interval")); } myWithTaz = oc.getBool("device.routing.with-taz"); if (myWithTaz) { if (MSEdge::dictionary(v.getParameter().fromTaz+"-source") == 0) { WRITE_ERROR("Source district '" + v.getParameter().fromTaz + "' not known when rerouting '" + v.getID() + "'!"); return; } if (MSEdge::dictionary(v.getParameter().toTaz+"-sink") == 0) { WRITE_ERROR("Destination district '" + v.getParameter().toTaz + "' not known when rerouting '" + v.getID() + "'!"); return; } } } myVehicleIndex++; }
void MSPerson::MSPersonStage_Driving::proceed(MSNet* net, MSPerson* person, SUMOTime now, const MSEdge &previousEdge) { MSVehicle *v = MSNet::getInstance()->getVehicleControl().getWaitingVehicle(&previousEdge, myLines); if (v != 0) { v->addPerson(person); if (v->getDesiredDepart() == -1) { MSNet::getInstance()->getEmitControl().add(v); MSNet::getInstance()->getVehicleControl().removeWaiting(&previousEdge, v); } } else { net->getPersonControl().addWaiting(&previousEdge, person); } }
void MSMsgInductLoop::leaveDetectorByMove(MSVehicle& veh, SUMOReal leaveTimestep) throw() { VehicleMap::iterator it = myVehiclesOnDet.find(&veh); assert(it != myVehiclesOnDet.end()); SUMOReal entryTimestep = it->second; myVehiclesOnDet.erase(it); assert(entryTimestep < leaveTimestep); myVehicleDataCont.push_back(VehicleData(veh.getVehicleType().getLength(), entryTimestep, leaveTimestep)); myLastOccupancy = leaveTimestep - entryTimestep; myLastLeaveTime = leaveTimestep; myCurrentID = myCurrentVehicle->getID(); myCurrentVehicle = 0; veh.quitRemindedLeft(this); }
void MSMsgInductLoop::enterDetectorByMove(MSVehicle& veh, SUMOReal entryTimestep) throw() { myVehiclesOnDet.insert(std::make_pair(&veh, entryTimestep)); veh.quitRemindedEntered(this); myCurrentVehicle = &veh; }
std::pair<MSVehicle * const, SUMOReal> MSLane::getFollowerOnConsecutive(SUMOReal dist, SUMOReal seen, SUMOReal leaderSpeed, SUMOReal backOffset) const { // ok, a vehicle has not noticed the lane about itself; // iterate as long as necessary to search for an approaching one std::set<MSLane*> visited; std::vector<std::pair<MSVehicle *, SUMOReal> > possible; std::vector<MSLane::IncomingLaneInfo> newFound; std::vector<MSLane::IncomingLaneInfo> toExamine = myIncomingLanes; while (toExamine.size()!=0) { for (std::vector<MSLane::IncomingLaneInfo>::iterator i=toExamine.begin(); i!=toExamine.end(); ++i) { /* if ((*i).viaLink->getState()==MSLink::LINKSTATE_TL_RED) { continue; } */ MSLane *next = (*i).lane; if (next->getFirstVehicle()!=0) { MSVehicle * v = (MSVehicle*) next->getFirstVehicle(); SUMOReal agap = (*i).length - v->getPositionOnLane() + backOffset; if (!v->getCarFollowModel().hasSafeGap(v->getCarFollowModel().maxNextSpeed(v->getSpeed()), agap, leaderSpeed, v->getLane().getMaxSpeed())) { possible.push_back(std::make_pair(v, (*i).length-v->getPositionOnLane()+seen)); } } else { if ((*i).length+seen<dist) { const std::vector<MSLane::IncomingLaneInfo> &followers = next->getIncomingLanes(); for (std::vector<MSLane::IncomingLaneInfo>::const_iterator j=followers.begin(); j!=followers.end(); ++j) { if (visited.find((*j).lane)==visited.end()) { visited.insert((*j).lane); MSLane::IncomingLaneInfo ili; ili.lane = (*j).lane; ili.length = (*j).length + (*i).length; ili.viaLink = (*j).viaLink; newFound.push_back(ili); } } } } } toExamine.clear(); swap(newFound, toExamine); } if (possible.size()==0) { return std::pair<MSVehicle * const, SUMOReal>(0, -1); } sort(possible.begin(), possible.end(), by_second_sorter()); return *(possible.begin()); }
SUMOReal getMaxSpeedRegardingNextLanes(MSVehicle& veh, SUMOReal speed, SUMOReal pos) { MSRouteIterator next = veh.getRoute().begin(); const MSCFModel &cfModel = veh.getCarFollowModel(); MSLane *currentLane = (*next)->getLanes()[0]; SUMOReal seen = currentLane->getLength() - pos; SUMOReal dist = SPEED2DIST(speed) + cfModel.brakeGap(speed); SUMOReal tspeed = speed; while (seen<dist&&next!=veh.getRoute().end()-1) { ++next; MSLane *nextLane = (*next)->getLanes()[0]; tspeed = MIN2(cfModel.ffeV(&veh, tspeed, seen, nextLane->getMaxSpeed()), nextLane->getMaxSpeed()); dist = SPEED2DIST(tspeed) + cfModel.brakeGap(tspeed); seen += nextLane->getMaxSpeed(); } return tspeed; }
const MSVehicle * const MSLane::getFirstVehicle() const { //XXX: partial occupators don't count? StripCont::const_iterator it = myStrips.begin(); const MSVehicle *first = (*it)->getFirstVehicle(); for (; it != myStrips.end(); ++it) { MSVehicle *curr = (*it)->getLastVehicle(); if (curr == 0) continue; else if (first == 0 && curr != 0) first = curr; if (first->getPositionOnLane() < curr->getPositionOnLane()) first = curr; } return first; }
void MSMsgInductLoop::leaveDetectorByLaneChange(MSVehicle& veh) throw() { // Discard entry data myVehiclesOnDet.erase(&veh); myDismissedVehicleNumber++; myCurrentID = myCurrentVehicle->getID(); myCurrentVehicle = 0; veh.quitRemindedLeft(this); }
void MSLaneChangerSublane::updateChanger(bool vehHasChanged) { MSLaneChanger::updateChanger(vehHasChanged); if (!vehHasChanged) { MSVehicle* lead = myCandi->lead; //std::cout << SIMTIME << " updateChanger lane=" << myCandi->lane->getID() << " lead=" << Named::getIDSecure(lead) << "\n"; myCandi->ahead.addLeader(lead, false, 0); MSLane* shadowLane = lead->getLaneChangeModel().getShadowLane(); if (shadowLane != 0) { const SUMOReal latOffset = lead->getLane()->getRightSideOnEdge() - shadowLane->getRightSideOnEdge(); //std::cout << SIMTIME << " updateChanger shadowLane=" << shadowLane->getID() << " lead=" << Named::getIDSecure(lead) << "\n"; (myChanger.begin() + shadowLane->getIndex())->ahead.addLeader(lead, false, latOffset); } } //std::cout << SIMTIME << " updateChanger: lane=" << myCandi->lane->getID() << " lead=" << Named::getIDSecure(myCandi->lead) << " ahead=" << myCandi->ahead.toString() << " vehHasChanged=" << vehHasChanged << "\n"; //for (ChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) { // std::cout << " lane=" << ce->lane->getID() << " vehicles=" << toString(ce->lane->myVehicles) << "\n"; //} }
bool MSLink::maybeOccupied(MSLane* lane) { MSVehicle* veh = lane->getLastVehicle(); SUMOReal distLeft = 0; if (veh == 0) { veh = lane->getPartialOccupator(); distLeft = lane->getLength() - lane->getPartialOccupatorEnd(); } else { distLeft = lane->getLength() - veh->getPositionOnLane() + veh->getVehicleType().getLength(); } if (veh == 0) { return false; } else { assert(distLeft > 0); // can we be sure that the vehicle leaves this lane in the next step? bool result = distLeft > (veh->getSpeed() - veh->getCarFollowModel().getMaxDecel()); return result; } }
size_t MSLane::getEmptyStartStripID(size_t vehWidth) const { StripCont::const_iterator strip = myStrips.begin(); std::vector<SUMOReal> vehPositions(myStrips.size(), getLength()); std::vector<SUMOReal>::iterator it, start, end; size_t startPos = 0; it = vehPositions.begin(); // vehPositions contains position of end of last vehicle of every strip // or length of lane if there is no last vehicle int i=0; for (i=0; strip != myStrips.end(); ++strip, ++i) { MSVehicle *veh = (*strip)->getLastVehicle(); if (veh != 0) vehPositions[i] = veh->getPositionOnLane() - veh->getVehicleType().getLength(); } assert(i==myStrips.size()); // for each possible position of vehicle, find the vehicle closest to current one // (in all strips current vehicle occupies) std::map<size_t, SUMOReal> possiblePosn; std::map<size_t, SUMOReal>::iterator pos; for (size_t myStart = 0; myStart <= myStrips.size() - vehWidth; ++myStart) { // find min dist among all strips that vehicle may occupy start = vehPositions.begin() + myStart; end = start + vehWidth; it = std::min_element(start, end); possiblePosn[myStart] = *it; } // now find the maximum among the possible start positions pos = possiblePosn.begin(); SUMOReal currMaxPos = pos->second; startPos = pos->first; for (; pos != possiblePosn.end(); ++pos) { if (currMaxPos < pos->second) { currMaxPos = pos->second; startPos = pos->first; } } //std::cerr << getID() << "::getEmptyStartStrip(" << vehWidth << ") = " << startPos << std::endl; return startPos; }
MSAbstractLaneChangeModel::MSAbstractLaneChangeModel(MSVehicle& v) : myVehicle(v), myOwnState(0), myLastLaneChangeOffset(0), myLaneChangeCompletion(1.0), myLaneChangeDirection(0), myLaneChangeMidpointPassed(false), myAlreadyMoved(false), myShadowLane(0), myHaveShadow(false), myCarFollowModel(v.getCarFollowModel()) { }