Example #1
0
 /**
  * Register new Shift from type ShiftType
  * @param WorkingDay $workingDay
  * @param ShiftType $shiftType
  * @param int $amountOfDrivers
  * @param int $status
  * @param bool $manuallyEdited
  * @return Shift
  */
 public static function registerShift(WorkingDay $workingDay, ShiftType $shiftType, $amountOfDrivers = 0, $status = self::OPEN, $manuallyEdited = false)
 {
     $shift = new Shift();
     $shift->setWorkingDay($workingDay);
     $shift->setShiftType($shiftType);
     $shift->setAmountOfDrivers($amountOfDrivers);
     $shift->setStatus($status);
     $shift->setManuallyEdited($manuallyEdited);
     return $shift;
 }
 /**
  * Production code:
  * runs routing algorithm to set optimized missions and orders for a shift
  *
  * @param Shift $shift
  * @param boolean $verbose
  * @return array containing information for user
  */
 public function buildRidePlanForShift(Shift $shift, $verbose = true)
 {
     $day = $shift->getDate();
     $tr = $this->container->get('translator');
     $infos = array();
     if ($verbose) {
         $infos[] = $tr->trans('ride.info.shift') . ' ' . $day->format('d.m.Y') . ', ' . $tr->trans(DateTimeService::getDayOfWeek($day)) . ' ' . $shift->getShiftType()->getName() . '.';
     }
     //set php execution timeout for big calculations
     ini_set('max_execution_time', 300);
     $em = $this->container->get('entity_manager');
     $em->beginTransaction();
     //set STRATEGY for RideOptimization
     $rideStrategy = new RideStrategyAnnealing();
     $rideStrategy->setContainer($this->container);
     //set Shift
     $shift->setManuallyEdited(false);
     // optimization resets manual attribute
     // set DrivingPools
     $drivingPools = $shift->getDrivingPoolsAsArray();
     if (count($drivingPools) < 1) {
         $em->rollback();
         $infos[] = $tr->trans('ride.error.noPools') . ' ' . $shift->getShiftType()->getName() . '.';
         return $infos;
     }
     // set DrivingMissions
     $dispoManagement = $this->container->get('tixi_app.dispomanagement');
     $drivingMissions = $dispoManagement->getDrivingMissionsInShift($shift);
     if (count($drivingMissions) < 1) {
         $em->rollback();
         $infos[] = $tr->trans('ride.error.noMissions') . ' ' . $shift->getShiftType()->getName() . '.';
         return $infos;
     }
     //clean drivingPools for new optimization
     foreach ($drivingPools as $pool) {
         $pool->removeDrivingMissions();
     }
     $configurationBuilder = new ConfigurationBuilder($drivingMissions, $drivingPools, $rideStrategy);
     $this->logger($tr->trans('ride.log.dayAndShift'), array($day->format('d.m.Y'), $shift->getShiftType()->getName()));
     //get all empty Rides
     $emptyRides = $configurationBuilder->buildAllPossibleEmptyRides();
     //get routing information from routing machine and fill node objects
     $s = microtime(true);
     $routeManagement = $this->container->get('tixi_app.routemanagement');
     $emptyRides = $routeManagement->fillRoutesForMultipleRideNodes($emptyRides);
     $e = microtime(true);
     $this->logger($tr->trans('ride.log.routingTime'), array(count($emptyRides), round($e - $s, 3)));
     //create ride configurations with strategy
     $s = microtime(true);
     $rideConfigurations = $configurationBuilder->buildConfigurations();
     if ($rideConfigurations === null) {
         $em->rollback();
         $infos[] = $tr->trans('ride.error.noConfiguration');
         return $infos;
     }
     $e = microtime(true);
     $nodes = count($rideConfigurations);
     $this->logger($tr->trans('ride.log.buildTime'), array($nodes, round($e - $s, 3)));
     // get the best feasible configuration
     $rideConfiguration = $this->getBestConfiguration($rideConfigurations);
     $configurationAnalyzer = new ConfigurationAnalyzer($rideConfiguration);
     $configurationAnalyzer->assignMissionsAndVehiclesToPool();
     $booked = $rideConfiguration->countNodes();
     $overbooked = count($rideConfiguration->getNotFeasibleNodes());
     if ($verbose) {
         $infos[] = $tr->trans('ride.info.nodes') . ' ' . $booked . ', ' . $tr->trans('ride.info.overbooked') . ' ' . $overbooked . '.';
     }
     $this->logger($tr->trans('ride.log.success'), array($nodes, $overbooked));
     // if everything worked, return successfully
     $em->commit();
     $em->flush();
     return $infos;
 }