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; }
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); } }
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 MSInductLoop::leaveDetectorByLaneChange(MSVehicle& veh) throw() { // Discard entry data 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){ VehicleMap::iterator it = myVehiclesOnDet[mainStripNum].find(&veh); myVehiclesOnDet[mainStripNum].erase(it); myDismissedVehicleNumber++; myCurrentVehicle[mainStripNum] = 0; veh.quitRemindedLeft(this); } }