/** ------------------------------------------------------------------------ * Assign Vehicles for the new WorkingMonth to empty DrivingPools RANDOMLY. * * Prerequisite: * + DrivingAssertions for WorkingDay already exist. * * Constraints: * + Vehicle which are not available on the working day are not assigned. * + Drivers with >1 shift in the working day must not need to change vehicles. * + Drivers who supervise one or more vehicles shall drive one of these. * + Driver preferences for a vehicle type shall be honored. * * Notes: * + Some drivers may not be assigned due to overbooking, previous assignments, * or the driver preferences or a combination of all this. * + The planner then needs to fix this manually. * * @param WorkingDay $workingDay with all (hydrated) child objects * @return array|null */ public function assignVehiclesToPools(WorkingDay $workingDay) { $shifts = $workingDay->getShiftsAsArray(); $vehicles = $this->getAvailableVehiclesForDay($workingDay->getDate()); $vehicleManager = new DispositionManageVehicles($vehicles, $shifts); $vehicleManager->setContainer($this->container); $dtos = $vehicleManager->getAvailableDrivers(); /** @var DispositionResourcesDTO $dto */ foreach ($dtos as $dto) { if ($dto->countShifts() >= 2) { $vehicleManager->assignVehicleToDriverAndDrivingPools($dto, $shifts); /* first priority: multiple shifts */ } } reset($dtos); /** @var DispositionResourcesDTO $dto */ foreach ($dtos as $dto) { if ($dto->countShifts() == 1 and $dto->getDriver()->hasSupervisedVehicles()) { $vehicleManager->assignVehicleToDriverAndDrivingPools($dto, $shifts); /* second priority: supervisors */ } } reset($dtos); /** @var DispositionResourcesDTO $dto */ foreach ($dtos as $dto) { if ($dto->countShifts() == 1 and !$dto->getDriver()->hasSupervisedVehicles()) { $vehicleManager->assignVehicleToDriverAndDrivingPools($dto, $shifts); /* third priority: all others */ } } $vehicleManager->assignVehicleToEmptyDrivingPools($shifts); return array(); }