/** * @param Shift $shift * @return bool */ public function matching(Shift $shift) { $startDate = $this->getAssertionPlan()->getAnchorDate(); $endDate = $this->getAssertionPlan()->getEndingDate(); /**@var $shiftDate \DateTime */ $shiftDate = $shift->getDate(); $wd = $shiftDate->format('N'); if ($shiftDate >= $startDate && $shiftDate <= $endDate) { if ($wd == $this->getWeekday()) { if ($this->matchShiftType($shift->getShiftType())) { return true; } } } return false; }
/** * @param Shift $shift * @return bool */ public function matching(Shift $shift) { $startDate = $this->getAssertionPlan()->getAnchorDate(); $endDate = $this->getAssertionPlan()->getEndingDate(); /**@var $shiftDate \DateTime */ $shiftDate = $shift->getDate(); $checkDate = clone $shiftDate; $checkDate->modify($this->getRelativeWeekAsText() . ' ' . $this->getWeekdayAsText() . ' of this month'); if ($shiftDate >= $startDate && $shiftDate <= $endDate) { if ($shiftDate->format('Ymd') === $checkDate->format('Ymd')) { if ($this->matchShiftType($shift->getShiftType())) { return true; } } } return false; }
/** * Get all driving missions in shift, where the start time of the driving * mission is between the start and end of the shift. * * @param Shift $shift * @return array|\Tixi\CoreDomain\Dispo\DrivingMission[] */ public function getDrivingMissionsInShift(Shift $shift) { $timeService = $this->container->get('tixi_api.datetimeservice'); $startTime = $timeService->convertToLocalDateTime($shift->getStartDate()); $shiftMinutesStart = $timeService->getMinutesOfDay($startTime); $endTime = $timeService->convertToLocalDateTime($shift->getEndDate()); $shiftMinutesEnd = $timeService->getMinutesOfDay($endTime); $matchingDrivingMissions = array(); $drivingMissionRepo = $this->container->get('drivingmission_repository'); $drivingMissions = $drivingMissionRepo->findDrivingMissionsForDay($shift->getDate()); foreach ($drivingMissions as $drivingMission) { /**@var $drivingMission \Tixi\CoreDomain\Dispo\DrivingMission */ $startMinute = $drivingMission->getServiceMinuteOfDay(); if ($startMinute >= $shiftMinutesStart && $startMinute <= $shiftMinutesEnd) { array_push($matchingDrivingMissions, $drivingMission); } } return $matchingDrivingMissions; }
/** * @param Shift $shift */ public function matching(Shift $shift) { foreach ($this->getServicePlans() as $servicePlan) { if ($servicePlan->matchDate($shift->getDate())) { // todo code incomplete... } } }
/** * @param Shift $shift */ public function assignShift(Shift $shift) { $this->shift = $shift; $shift->assignDrivingAssertion($this); /* * set sortOrder to shifts working day + start time * this is redundant, but needed for sorting in DataGrid */ $localDate = clone $shift->getDate(); // date in timezone Europe/Paris $utcStart = clone $shift->getStart(); // time in timezone UTC $utcStart->setTimezone($localDate->getTimezone()); $localDate->setTime($utcStart->format('H'), $utcStart->format('i')); $localDate->setTimezone(new \DateTimeZone('UTC')); $this->sortOrder = $localDate; }
/** * 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; }