Ejemplo n.º 1
0
bool
MSCalibrator::removePending() {
    if (myToRemove.size() > 0) {
        MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl();
        // it is not save to remove the vehicles inside
        // VehicleRemover::notifyEnter so we do it here
        for (std::set<std::string>::iterator it = myToRemove.begin(); it != myToRemove.end(); ++it) {
            MSVehicle* vehicle = dynamic_cast<MSVehicle*>(vc.getVehicle(*it));
            if (vehicle != nullptr) {
                vehicle->onRemovalFromNet(MSMoveReminder::NOTIFICATION_VAPORIZED);
                vehicle->getLane()->removeVehicle(vehicle, MSMoveReminder::NOTIFICATION_VAPORIZED);
                vc.scheduleVehicleRemoval(vehicle);
            } else {
                WRITE_WARNING("Calibrator '" + getID() + "' could not remove vehicle '" + *it + "'.");
            }
        }
        myToRemove.clear();
        return true;
    }
    return false;
}
Ejemplo n.º 2
0
SUMOTime
MSCalibrator::execute(SUMOTime timestep) throw(ProcessError) {

    if (timestep == 0) {
        return 1;
    }

    if (myNumVehicles == -1) {
        return 1;
    }



    SUMOReal vehPerInterval = myNumVehicles / (myInterval);
    int num_replacements = 0;
    /*
    	OutputDevice *dev = OutputDevice::getOutputDevice(myDebugFilesBaseName + "diff.csv");
    	OutputDevice *dev2 = OutputDevice::getOutputDevice(myDebugFilesBaseName + "replace.csv");
    	OutputDevice *dev3 = OutputDevice::getOutputDevice(myDebugFilesBaseName + "vehicle.xml");
    */

    //positive diff=too many vehicles, negative diff=not enough vehicles
    unsigned veh_cnt = myIL->getNVehContributed();
    SUMOReal diff =  veh_cnt - vehPerInterval + myToCalibrate;
    SUMOReal meanSpeed = myIL->getCurrentSpeed();

    if (diff > 0) {

        unsigned int vehNum = myDestLane->getVehicleNumber();

        //not enough vehicles to delete on the lane?
        if (vehNum < diff) {

            myToCalibrate = diff - vehNum;

            diff = (SUMOReal)vehNum;
        } else {
            myToCalibrate = diff - floor(diff);
        }

        for (int i=1; i <= diff; i++) {

            for (MSLane::VehCont::const_iterator it = myDestLane->getVehiclesSecure().begin();
                    it < myDestLane->getVehiclesSecure().end();
                    it++) {

                MSVehicle * veh = (*it);

                if (veh->getVehicleType().getID() == "BUS") {
                    continue;
                } else {
                    veh->onRemovalFromNet(false);
                    myDestLane->removeVehicle(veh);
                    MSNet::getInstance()->getVehicleControl().scheduleVehicleRemoval(veh);
                    num_replacements++;
                    break;
                }
            }
//			WRITE_WARNING("Removing Vehicle " + veh->getID() + " at Timestep: " + toString(timestep) + "\n");
        }

        //make sure enough cars were deleted, only happens if BUSSES were in the set
        myToCalibrate+diff-num_replacements;
    } else if (diff < 0) {

        myToCalibrate = diff - ceil(diff);
        for (int i=-1; i >= diff; i--) {
//			WRITE_WARNING("Inserting Vehicle at Timestep: " + toString(timestep) + "\n");

            ((MSCalibrator_FileTriggeredChild*) myFileBasedCalibrator)->buildAndScheduleFlowVehicle(meanSpeed);
            childCheckEmit(myFileBasedCalibrator);
            num_replacements--;
        }
    } else if (diff == 0) {
        myToCalibrate = 0;
    }
    /*
    	if (myDebugLevel > 0) {
    		dev->getOStream() << timestep << "\t" << num_replacements << "\t" << diff << "\t" << myToCalibrate << "\t" << veh_cnt << "\t" << meanSpeed << endl;

    		dev2->getOStream() << num_replacements << endl;

    		myIL->writeXMLOutput(*dev3, timestep-1, timestep);
    	}

    //	WRITE_WARNING("execute2(" + toString(timestep) + "): Count: " + toString(myIL->getNVehContributed(myInterval)));
     */

    return 1;
}