/** * Stores Route if none exist and get result * @param \Tixi\CoreDomain\Dispo\Route $route * @return Route */ public function storeRouteIfNotExist(Route $route) { $qb = $this->createQueryBuilder('e')->where('e.startAddress = :startAddressId')->andWhere('e.targetAddress = :targetAddressId')->setParameter('startAddressId', $route->getStartAddress()->getId())->setParameter('targetAddressId', $route->getTargetAddress()->getId()); $result = $qb->getQuery()->getOneOrNullResult(); if ($result) { return $result; } else { $this->store($route); return $route; } }
/** * @param $startAddress * @param $targetAddress * @param int|null $duration * @param int|null $distance * @return Route */ public static function registerRoute($startAddress, $targetAddress, $duration = 0, $distance = 0) { $route = new Route(); $route->setStartAddress($startAddress); $route->setTargetAddress($targetAddress); $route->setDuration($duration); $route->setDistance($distance); return $route; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { $n = $input->getArgument('n'); $routingMachine = $this->getContainer()->get('tixi_app.routingmachine'); $address1 = Address::registerAddress('Rathausstrasse 1', '6340', 'Baar', 'Schweiz', 'Ganztagesschule mit Montessoriprofil', 47.194715, 8.526096000000001); $address2 = Address::registerAddress('Bahnhofstrasse 9', '6410', 'Arth', 'Schweiz', 'CSS', 47.049536, 8.547931); $routes = array(); for ($i = 0; $i < $n; $i++) { array_push($routes, Route::registerRoute($address1, $address2)); } $startTime = microtime(true); $routingMachine->fillRoutingInformationForMultipleRoutes($routes); $endTime = microtime(true); $output->writeln('Exectued ' . $n . ' OSRM requests in: ' . ($endTime - $startTime) . "s\n"); }
public function testGetMultipleRouteInformations() { $address1 = $this->init->createTestAddressBaar(); $address2 = $this->init->createTestAddressGoldau(); $routes = array(); for ($i = 0; $i < 100; $i++) { array_push($routes, Route::registerRoute($address1, $address2, null, null)); array_push($routes, Route::registerRoute($address2, $address1, null, null)); } $s = microtime(true); $this->init->routingMachine->fillRoutingInformationForMultipleRoutes($routes); $e = microtime(true); echo "\n\nFilled " . count($routes) . " routes from RoutingMachine in: " . ($e - $s) . "s\n"; /**@var $route Route */ foreach ($routes as $route) { $this->assertNotEmpty($route->getDurationInMinutes()); } }
/** * @expectedException Doctrine\DBAL\DBALException */ public function testRouteCRUD() { $address = Address::registerAddress('Hauptweg 11', '6333', 'Baar', 'Schweiz', 'Wohnadresse', 47.17546, 8.517752, 'Wohnung'); $address2 = Address::registerAddress('Hauptweg 22', '6333', 'Baar', 'Schweiz', 'Wohnadresse', 47.13546, 8.527752, 'Wohnung'); $this->init->addressRepo->store($address); $this->init->addressRepo->store($address2); $this->init->em->flush(); $route = Route::registerRoute($address, $address2, 8, 1200); $finds = $this->init->routeRepo->findBy(array('startAddress' => $address->getId(), 'targetAddress' => $address2->getId())); $this->assertCount(0, $finds); $this->init->routeRepo->store($route); $this->init->em->flush(); $finds = $this->init->routeRepo->findBy(array('startAddress' => $address->getId(), 'targetAddress' => $address2->getId())); $this->assertCount(1, $finds); //duplicate entry Exception will appear $route2 = Route::registerRoute($address, $address2, 2, 312); $this->init->routeRepo->store($route2); $this->init->em->flush(); }
public function testDrivingOrderCRUD() { $addressFrom = $this->init->createTestAddressBaar(); $addressTo = $this->init->createTestAddressGoldau(); $passenger = Passenger::registerPassenger('m', 'Arthuro', 'Benatone', '+418182930', $addressFrom); $this->init->passengerRepo->store($passenger); $date = $this->init->dateTimeService->convertDateTimeStringToUTCDateTime('20.05.2014 00:00'); $time = $this->init->dateTimeService->convertDateTimeStringToUTCDateTime('20.05.2014 15:05'); $route = Route::registerRoute($addressFrom, $addressTo, 0, 0); $route->setDuration(15); $route->setDistance(6); $this->init->routeRepo->store($route); $drivingOrder = DrivingOrder::registerDrivingOrder($passenger, $date, $time, 2, 'möchte nicht hinten sitzen'); $drivingOrder->assignRoute($route); $passenger->assignDrivingOrder($drivingOrder); $drivingOrder->assignPassenger($passenger); $this->init->drivingOrderRepo->store($drivingOrder); $this->init->em->flush(); $this->assertNotNull($this->init->drivingOrderRepo->find($drivingOrder->getId())); //TimePeriod from start day of month to next start day of month $monthsAgo = 3; $monthDate = new \DateTime('today'); $monthDate->modify('+' . $monthsAgo . ' month'); $monthDate->format('first day of this month'); $workingMonth = WorkingMonth::registerWorkingMonth($monthDate); $workingMonth->createWorkingDaysForThisMonth(); foreach ($workingMonth->getWorkingDays() as $wd) { $this->init->workingDayRepo->store($wd); } $this->init->workingMonthRepo->store($workingMonth); $workingDays = $workingMonth->getWorkingDays(); /**@var $shiftTypes ShiftType[] */ $shiftTypes = $this->init->shiftTypeRepo->findAllActive(); //create workingDays shifts, assign them drivingpools, get amount of needed drivers /** @var $workingDay WorkingDay */ foreach ($workingDays as $workingDay) { /** @var $shiftType ShiftType */ foreach ($shiftTypes as $shiftType) { $shift = Shift::registerShift($workingDay, $shiftType); $shift->setAmountOfDrivers(16); $workingDay->assignShift($shift); for ($i = 1; $i <= $shift->getAmountOfDrivers(); $i++) { $drivingPool = DrivingPool::registerDrivingPool($shift); $shift->assignDrivingPool($drivingPool); $this->init->drivingPoolRepo->store($drivingPool); } $this->init->shiftRepo->store($shift); } $this->init->workingDayRepo->store($workingDay); } $this->init->em->flush(); $this->assertNotNull($this->init->workingMonthRepo->find($workingMonth->getId())); $drivingAssertionPlans = $this->init->repeatedDrivingAssertionPlanRepo->findPlanForDate(new \DateTime()); $this->assertNotNull($drivingAssertionPlans); $drivingPools = array(); foreach ($workingMonth->getWorkingDays() as $wd) { foreach ($wd->getShifts() as $s) { foreach ($s->getDrivingPools() as $dp) { array_push($drivingPools, $dp); } } } foreach ($drivingAssertionPlans as $drivingAssertionPlan) { $assertions = $drivingAssertionPlan->getRepeatedDrivingAssertions(); foreach ($assertions as $assertion) { if ($assertion->matching($shift)) { echo "\nmatches\n"; $drivingPool = DrivingPool::registerDrivingPool($shift); $this->init->drivingPoolRepo->store($drivingPool); } } } $vehicles = $this->init->vehicleRepo->findAll(); /**@var $vehicle Vehicle */ foreach ($vehicles as $vehicle) { foreach ($vehicle->getServicePlans() as $sp) { } } }
/** * Test 21.05.2014: its faster if we get all routes through routingMachine * then checking first if we got a database entry... * * @param RideNode[] $rideNodes * @throws \Exception * @return RideNode[] */ public function fillRoutesForMultipleRideNodes($rideNodes) { /**@var $routingMachine \Tixi\App\Routing\RoutingMachine */ $routingMachine = $this->container->get('tixi_app.routingmachine'); $routesToQuery = array(); /** @var $rideNode \Tixi\App\AppBundle\Ride\RideNode */ foreach ($rideNodes as $hashKey => $rideNode) { $routesToQuery[$hashKey] = Route::registerRoute($rideNode->startAddress, $rideNode->targetAddress); } try { $filledRoutings = $routingMachine->fillRoutingInformationForMultipleRoutes($routesToQuery); foreach ($filledRoutings as $hashKey => $route) { $rideNodes[$hashKey]->duration = $route->getDurationInMinutes(); $rideNodes[$hashKey]->distance = $route->getDistanceInMeters(); } } catch (\Exception $e) { throw $e; } return $rideNodes; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { $output->writeln('building variables...'); $month = $input->getArgument('month'); if (!$month) { $month = 1; } $em = $this->getContainer()->get('entity_manager'); $workingMonthRepo = $this->getContainer()->get('workingmonth_repository'); $workingDayRepo = $this->getContainer()->get('workingday_repository'); $shiftRepo = $this->getContainer()->get('shift_repository'); $shiftTypeRepo = $this->getContainer()->get('shifttype_repository'); $drivingPoolRepo = $this->getContainer()->get('drivingpool_repository'); $passengerRepo = $this->getContainer()->get('passenger_repository'); $driverRepo = $this->getContainer()->get('driver_repository'); $vehicleRepo = $this->getContainer()->get('vehicle_repository'); $addressRepo = $this->getContainer()->get('address_repository'); $poiRepo = $this->getContainer()->get('poi_repository'); $routeRepo = $this->getContainer()->get('route_repository'); $drivingMissionRepo = $this->getContainer()->get('drivingmission_repository'); $drivingOrderRepo = $this->getContainer()->get('drivingorder_repository'); $repeatedDrivingAssertionRepo = $this->getContainer()->get('repeateddrivingassertion_repository'); $repeatedDrivingAssertionPlanRepo = $this->getContainer()->get('repeateddrivingassertionplan_repository'); $repeatedDrivingOrderRepo = $this->getContainer()->get('repeateddrivingorder_repository.doctrine'); $repeatedDrivingOrderPlanRepo = $this->getContainer()->get('repeateddrivingorderplan_repository.doctrine'); $time = $this->getContainer()->get('tixi_api.datetimeservice'); $routingMachine = $this->getContainer()->get('tixi_app.routingmachine'); $routeManagement = $this->getContainer()->get('tixi_app.routemanagement'); $dispoManagement = $this->getContainer()->get('tixi_app.dispomanagement'); $this->zonePlanRepository = $this->getContainer()->get('zoneplan_repository'); $this->zoneRepository = $this->getContainer()->get('zone_repository'); $monthDate = new \DateTime('today'); $monthDate->modify('+' . $month . ' month'); // depreciated: $monthDate->modify('+ 10 year'); $monthDate->modify('first day of this month'); $shiftTypes = $shiftTypeRepo->findAllActive(); $output->writeln('target date is ' . $monthDate->format('d.m.Y')); $output->writeln('building driver assertion plans...'); $drivers = $driverRepo->findAllActive(); foreach ($drivers as $driver) { //no other assertion for zivis if ($driver->getDriverCategory()->getId() == 2) { continue; } $reDrivingAssertionPlan = RepeatedDrivingAssertionPlan::registerRepeatedAssertionPlan('test', new \DateTime('today'), 'weekly', rand(0, 1)); $reDrivingAssertionPlan->assignDriver($driver); $driver->assignRepeatedDrivingAssertionPlan($reDrivingAssertionPlan); $repeatedDrivingAssertionPlanRepo->store($reDrivingAssertionPlan); for ($i = 1; $i <= 7; $i++) { if (rand(0, 3) < 3) { $reDrivingWeeklyAssertion = new RepeatedWeeklyDrivingAssertion(); $reDrivingWeeklyAssertion->addShiftType($shiftTypes[rand(0, count($shiftTypes) - 1)]); $reDrivingWeeklyAssertion->addShiftType($shiftTypes[rand(0, count($shiftTypes) - 1)]); $reDrivingWeeklyAssertion->addShiftType($shiftTypes[rand(0, count($shiftTypes) - 1)]); $reDrivingWeeklyAssertion->setWeekday($i); $reDrivingWeeklyAssertion->setAssertionPlan($reDrivingAssertionPlan); $reDrivingAssertionPlan->assignRepeatedDrivingAssertion($reDrivingWeeklyAssertion); $repeatedDrivingAssertionRepo->store($reDrivingWeeklyAssertion); } } } $em->flush(); $output->writeln('building driving pools...'); $drivingPools = 0; $workingMonth = $workingMonthRepo->findWorkingMonthByDate($monthDate); if ($workingMonth !== null) { $output->writeln("WorkingMonth " . $monthDate->format('m') . " already exists"); } else { $workingMonth = $dispoManagement->openWorkingMonth($monthDate->format('Y'), $monthDate->format('m')); $workingDays = $workingMonth->getWorkingDays(); //create workingDays shifts, assign them drivingpools, get amount of needed drivers /** @var $workingDay WorkingDay */ foreach ($workingDays as $workingDay) { /** @var $shiftType ShiftType */ foreach ($workingDay->getShifts() as $shift) { $shift->setAmountOfDrivers(rand(12, 18)); for ($i = 1; $i <= $shift->getAmountOfDrivers(); $i++) { $drivingPool = DrivingPool::registerDrivingPool($shift); $shift->assignDrivingPool($drivingPool); $drivingPoolRepo->store($drivingPool); $drivingPools++; } } } } $em->flush(); $output->writeln('building unclassified zone...'); $this->unclassifiedZone = $this->getUnclassifiedZone(); if (is_null($this->unclassifiedZone)) { $output->writeln('error: cannot create unclassified zone!'); } $output->writeln('building driving orders...'); /**@var $pois POI[] */ $pois = $poiRepo->findAll(); $countPois = count($pois); $orders = array(); $routes = array(); //create Driving Orders $countOrders = 0; foreach ($shiftTypes as $shiftType) { $approxOrdersPerShift = rand(40, 60); for ($i = 0; $i < $approxOrdersPerShift; $i++) { /**@var $passenger Passenger */ $passenger = $passengerRepo->find(rand(100, 500)); $passenger->setIsInWheelChair(rand(0, 1)); /** WARNING: saving times in UTC on database, but minutesOfDay are from midnight, causing * wrong data if a time is UTC 23:30 but CET 00:30 (= 30 minutesOfDay) */ $stStart = $time->convertToLocalDateTime($shiftType->getStart()); $stEnd = $time->convertToLocalDateTime($shiftType->getEnd()); $stDuration = $stStart->diff($stEnd); $minutes = $stDuration->h * 60 + $stDuration->i; $pickupTime = clone $stStart; $pickupTime->add(new \DateInterval('PT' . rand(1, $minutes) . 'M')); $order = DrivingOrder::registerDrivingOrder($passenger, $monthDate, $pickupTime, rand(0, 1), null, 0, 0, 1); $start = $passenger->getAddress(); $target = $pois[rand(0, $countPois - 1)]->getAddress(); $route = Route::registerRoute($start, $target); $hashKey = hash('crc32', $start->getHashFromBigIntCoordinates() . $target->getHashFromBigIntCoordinates()); $routes[$hashKey] = $route; $route = $routeRepo->storeRouteIfNotExist($route); $order->assignRoute($route); $order->assignPassenger($passenger); $passenger->assignDrivingOrder($order); $drivingOrderRepo->store($order); array_push($orders, $order); } } $output->writeln('building driving missions and routes...'); $routingMachine->fillRoutingInformationForMultipleRoutes($routes); /**@var $order DrivingOrder */ foreach ($orders as $order) { $passenger = $order->getPassenger(); $route = $order->getRoute(); $boardingTime = DispositionVariables::BOARDING_TIME + DispositionVariables::DEBOARDING_TIME; $extraMinutesPassenger = $passenger->getExtraMinutes(); $additionalTimesOnRide = $boardingTime + $extraMinutesPassenger; $serviceMinuteOfDay = $time->getMinutesOfDay($order->getPickUpTime()); $serviceDuration = $route->getDurationInMinutes() + $additionalTimesOnRide; $serviceDistance = $route->getDistanceInMeters(); //DrivingMission <-> DrivingOrder $drivingMission = DrivingMission::registerDrivingMission(rand(0, 1), $serviceMinuteOfDay, $serviceDuration, $serviceDistance); $drivingMission->assignDrivingOrder($order); $order->assignDrivingMission($drivingMission); $drivingMissionRepo->store($drivingMission); // DrivingOrder <-> Zone $cities = array($route->getStartAddress()->getCity(), $route->getTargetAddress()->getCity()); $zone = $this->getZoneWithHighestPriorityForCities($cities); $order->assignZone($zone); $countOrders++; } $em->flush(); $output->writeln("\n--------------------------------------------\n" . "Testdata created for month: " . $monthDate->format('m.Y') . " with:\n" . $drivingPools . " DrivingPools \n" . "And orders for one day: " . $monthDate->format('d.m.Y') . " with:\n" . $countOrders . " DrivingOrders and Routes \n"); }