How to use fromArray method of Duration class

Best Cucumber Common Library code snippet using Duration.fromArray

RouteExampleTests.php

Source:RouteExampleTests.php Github

copy

Full Screen

...36 }37 Route4Me::setApiKey(Constants::API_KEY);38 //region Prepae Addresses39 $addresses = [];40 $addresses[] = Address::fromArray([41 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258',42 'is_depot' => true,43 'lat' => 30.159341812134,44 'lng' => -81.538619995117,45 'time' => 300,46 'time_window_start' => 28800,47 'time_window_end' => 32400,48 ]);49 $addresses[] = Address::fromArray([50 'address' => '214 Edgewater Branch Drive 32259',51 'lat' => 30.103567123413,52 'lng' => -81.595352172852,53 'time' => 300,54 'time_window_start' => 36000,55 'time_window_end' => 37200,56 ]);57 $addresses[] = Address::fromArray([58 'address' => '756 eagle point dr 32092',59 'lat' => 30.046422958374,60 'lng' => -81.508758544922,61 'time' => 300,62 'time_window_start' => 39600,63 'time_window_end' => 41400,64 ]);65 $addresses[] = Address::fromArray([66 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA',67 'lat' => 30.048496,68 'lng' => -81.558716,69 'time' => 300,70 'time_window_start' => 43200,71 'time_window_end' => 45000,72 ]);73 $addresses[] = Address::fromArray([74 'address' => 'St Johns Florida 32259, USA',75 'lat' => 30.099642,76 'lng' => -81.547201,77 'time' => 300,78 'time_window_start' => 46800,79 'time_window_end' => 48600,80 ]);81 $parameters = RouteParameters::fromArray([82 'device_type' => DeviceType::IPAD,83 'disable_optimization' => false,84 'route_name' => 'phpunit test '.date('Y-m-d H:i'),85 ]);86 //endregion87 $optimizationParameters = new OptimizationProblemParams();88 $optimizationParameters->setAddresses($addresses);89 $optimizationParameters->setParameters($parameters);90 self::$createdProblems[] = OptimizationProblem::optimize($optimizationParameters);91 self::$testRoutes = self::$createdProblems[0]->routes;92 //region Extra Testing Addresses93 $addresses = [];94 $addresses[] = Address::fromArray([95 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258',96 'is_depot' => true,97 'lat' => 30.159341812134,98 'lng' => -81.538619995117,99 'time' => 300,100 'time_window_start' => 28800,101 'time_window_end' => 32400,102 ]);103 $addresses[] = Address::fromArray([104 'address' => '214 Edgewater Branch Drive 32259',105 'lat' => 30.103567123413,106 'lng' => -81.595352172852,107 'time' => 300,108 'time_window_start' => 36000,109 'time_window_end' => 37200,110 ]);111 $addresses[] = Address::fromArray([112 'address' => '756 eagle point dr 32092',113 'lat' => 30.046422958374,114 'lng' => -81.508758544922,115 'time' => 300,116 'time_window_start' => 39600,117 'time_window_end' => 41400,118 ]);119 //endregion120 self::$addresses = $addresses;121 }122 public function testOptimizationWithBundledAddresses()123 {124 $this->markTestSkipped('The test requires special permission to use the address bundling feature.');125 // Huge list of addresses126 $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true);127 $addresses = [];128 foreach ($json as $address) {129 $addresses[] = Address::fromArray($address);130 }131 $bundling = new AddressBundling();132 $bundling->mode = AddressBundlingModes\Mode::ADDRESS;133 $bundling->merge_mode = AddressBundlingModes\FirstItemMode::KEEP_ORIGINAL;134 $bundling->service_time_rules->first_item_mode = AddressBundlingModes\FirstItemMode::KEEP_ORIGINAL;135 $bundling->service_time_rules->additional_items_mode = AddressBundlingModes\AdditionalItemsMode::KEEP_ORIGINAL;136 $parameters = RouteParameters::fromArray([137 'algorithm_type' => Algorithmtype::TSP,138 'route_name' => 'Single Driver Multiple TimeWindows 50 Stops',139 'route_date' => time() + 24 * 60 * 60,140 'route_time' => 5 * 3600 + 30 * 60,141 'distance_unit' => DistanceUnit::MILES,142 'device_type' => DeviceType::WEB,143 'optimize' => OptimizationType::DISTANCE,144 'metric' => Metric::GEODESIC,145 'bundling' => $bundling,146 ]);147 $optimizationParams = new OptimizationProblemParams();148 $optimizationParams->setAddresses($addresses);149 $optimizationParams->setParameters($parameters);150 $problem = OptimizationProblem::optimize($optimizationParams);151 self::$createdProblems[] = $problem;152 $this->assertNotNull($problem);153 $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem);154 $this->assertNotNull($problem->getOptimizationId());155 $this->assertNotNull($problem->getRoutes());156 }157 public function testGetScheduleCalendar()158 {159 $now = new \DateTime();160 $schedCalendarParams = new ScheduleCalendarParameters();161 $schedCalendarParams->date_from_string = $now162 ->add(\DateInterval::createFromDateString('-5 days'))163 ->format('Y-m-d');164 $schedCalendarParams->date_to_string = $now165 ->add(\DateInterval::createFromDateString('5 days'))166 ->format('Y-m-d');167 $schedCalendarParams->orders = true;168 $schedCalendarParams->ab = true;169 $schedCalendarParams->routes_count = true;170 $scheduleCalendar = ScheduleCalendarResponse::fromArray(171 $schedCalendarParams->getScheduleCalendar($schedCalendarParams)172 );173 $this->assertNotNull($scheduleCalendar);174 $this->assertInstanceOf('Route4Me\ScheduleCalendarResponse', $scheduleCalendar);175 }176 public function testMergeRoutes()177 {178 $route = new Route();179 $routeIDs = [self::$testRoutes[0]->route_id];180 $routeDuplicate = $route->duplicateRoute($routeIDs);181 $this->assertTrue(isset($routeDuplicate['status']), "Cannot created duplicate route");182 $this->assertTrue($routeDuplicate['status'], "Cannot created duplicate route");183 $duplicatedRouteId = $routeDuplicate['route_ids'][0];184 self::$removedRouteIDs[] = $duplicatedRouteId;185 $depot = self::$testRoutes[0]->addresses[0];186 // Merge the selected routes187 $params = [188 'route_ids' => $routeIDs[0].','.$duplicatedRouteId,189 'depot_address' => $depot->address,190 'remove_origin' => false,191 'depot_lat' => $depot->lat,192 'depot_lng' => $depot->lng,193 ];194 $result = $route->mergeRoutes($params);195 $this->assertNotNull($result);196 $this->assertTrue(isset($result['status']), "Cannot merge the routes");197 $this->assertTrue($result['status'], "Cannot merge the routes");198 $this->assertTrue(isset($result['optimization_problem_id']), "Cannot merge the routes");199 $this->assertEquals(32,strlen($result['optimization_problem_id']), "Cannot merge the routes");200 self::$removedOptimizationIDs[] = $result['optimization_problem_id'];201 }202 public function testMultipleDepotMultipleDriverFineTuning()203 {204 // Huge list of addresses205 $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true);206 $json = array_slice($json, 0, 19);207 $addresses = [];208 foreach ($json as $address) {209 $addresses[] = Address::fromArray($address);210 }211 //region Optimization With Duration Priority FineTuning212 $parameters = RouteParameters::fromArray([213 'route_name' => 'Optimization With Duration Priority FineTuning. '.date('Y-m-d H:i'),214 'algorithm_type' => AlgorithmType::CVRP_TW_MD,215 'route_time' => 23200,216 'optimize' => OptimizationType::TIME,217 'device_type' => DeviceType::WEB,218 'udu_distance_unit' => 'km',219 'route_max_duration' => 86400,220 'travel_mode' => TravelMode::DRIVING,221 'vehicle_capacity' => 30,222 'vehicle_max_distance_mi' => 10000,223 'rt' => true,224 'target_duration' => 100,225 'target_distance' => 0,226 'target_wait_by_tail_size' => 0227 ]);228 $optimizationParams = new OptimizationProblemParams();229 $optimizationParams->setAddresses($addresses);230 $optimizationParams->setParameters($parameters);231 $problems = OptimizationProblem::optimize($optimizationParams);232 $this->assertTrue(!is_null($problems), "Cannot generate an optimization with duration priority fine-tuning");233 self::$createdProblems[] = $problems;234 $routes=$problems->getRoutes();235 $this->assertTrue(sizeof($routes)==2, "The generated optimization hasn't two routes");236 $totalTripDistanceByDuration = $routes[0]->trip_distance + $routes[1]->trip_distance;237 $totalTripDurationByDuration = $routes[0]->route_duration_sec + $routes[1]->route_duration_sec;238 $totalTripWaitingTimeByDuration = $routes[0]->total_wait_time + $routes[1]->total_wait_time;239 echo "Generated an optimization with the <b>duration</b> priority fine-tuning:<br>";240 echo " Total Trip Distance: $totalTripDistanceByDuration <br>";241 echo " Total Trip Duration: $totalTripDurationByDuration <br>";242 echo " Total Trip Waiting Time: $totalTripWaitingTimeByDuration <br><br><br>";243 //endregion244 //region Optimization With Distance Priority FineTuning245 $parameters = RouteParameters::fromArray([246 'route_name' => 'Optimization With Distance Priority FineTuning. '.date('Y-m-d H:i'),247 'algorithm_type' => AlgorithmType::CVRP_TW_SD,248 'route_time' => 23200,249 'optimize' => OptimizationType::TIME,250 'device_type' => DeviceType::WEB,251 'udu_distance_unit' => 'km',252 'route_max_duration' => 86400,253 'travel_mode' => TravelMode::DRIVING,254 'vehicle_capacity' => 30,255 'vehicle_max_distance_mi' => 10000,256 'rt' => true,257 'target_duration' => 0,258 'target_distance' => 100,259 'target_wait_by_tail_size' => 0260 ]);261 $optimizationParams = new OptimizationProblemParams();262 $optimizationParams->setAddresses($addresses);263 $optimizationParams->setParameters($parameters);264 $problems = OptimizationProblem::optimize($optimizationParams);265 $this->assertTrue(!is_null($problems), "Cannot generate an optimization with the distance priority fine-tuning");266 self::$createdProblems[]=$problems;267 $routes=$problems->getRoutes();268 $this->assertTrue(sizeof($routes)==2, "The generated optimization hasn't two routes");269 $totalTripDistanceByDistance = $routes[0]->trip_distance + $routes[1]->trip_distance;270 $totalTripDurationByDistance = $routes[0]->route_duration_sec + $routes[1]->route_duration_sec;271 $totalTripWaitingTimeByDistance = $routes[0]->total_wait_time + $routes[1]->total_wait_time;272 $this->assertTrue($totalTripDistanceByDistance>0);273 $this->assertTrue($totalTripDurationByDistance>0);274 $this->assertTrue($totalTripWaitingTimeByDistance>0);275 }276 public function testMultipleDepotMultipleDriver()277 {278 // Huge list of addresses279 $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true);280 $addresses = [];281 foreach ($json as $address) {282 $addresses[] = Address::fromArray($address);283 }284 $parameters = RouteParameters::fromArray([285 'algorithm_type' => AlgorithmType::CVRP_TW_MD,286 'distance_unit' => DistanceUnit::MILES,287 'device_type' => DeviceType::WEB,288 'optimize' => OptimizationType::TIME,289 'metric' => Metric::MATRIX,290 'route_max_duration' => 86400 ,291 'travel_mode' => TravelMode::DRIVING,292 'vehicle_capacity' => 50,293 'vehicle_max_distance_mi' => 10000,294 ]);295 $optimizationParams = new OptimizationProblemParams();296 $optimizationParams->setAddresses($addresses);297 $optimizationParams->setParameters($parameters);298 $problem = OptimizationProblem::optimize($optimizationParams);299 self::$createdProblems[] = $problem;300 $this->assertNotNull($problem);301 $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem);302 $this->assertNotNull($problem->getOptimizationId());303 $this->assertNotNull($problem->getRoutes());304 $this->assertTrue(sizeof($problem->getRoutes())>1);305 }306 public function testMultipleDepotMultipleDriverTimeWindow()307 {308 $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true);309 $addresses = [];310 foreach ($json as $address) {311 $addresses[] = Address::fromArray($address);312 }313 $parameters = RouteParameters::fromArray([314 'algorithm_type' => Algorithmtype::CVRP_TW_MD,315 'route_name' => 'Multiple Depot, Multiple Driver, Time Window',316 'route_date' => time() + 24 * 60 * 60,317 'route_time' => 60 * 60 * 7,318 'rt' => true,319 'distance_unit' => DistanceUnit::MILES,320 'device_type' => DeviceType::WEB,321 'optimize' => OptimizationType::TIME,322 'metric' => Metric::GEODESIC,323 'route_max_duration' => 86400 * 3,324 'travel_mode' => TravelMode::DRIVING,325 'vehicle_capacity' => 99,326 'vehicle_max_distance_mi' => 99999,327 ]);328 $optimizationParams = new OptimizationProblemParams();329 $optimizationParams->setAddresses($addresses);330 $optimizationParams->setParameters($parameters);331 $problem = OptimizationProblem::optimize($optimizationParams);332 self::$createdProblems[] = $problem;333 $this->assertNotNull($problem);334 $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem);335 $this->assertNotNull($problem->getOptimizationId());336 $this->assertNotNull($problem->getRoutes());337 }338 public function testMultipleDepotMultipleDriverWith24StopsTimeWindow()339 {340 // Huge list of addresses341 $json = json_decode(file_get_contents(dirname(__FILE__).'/data/mdp_mdr_24stops_tw.json'), true);342 $addresses = [];343 foreach ($json as $address) {344 $addresses[] = Address::fromArray($address);345 }346 $addresses[7]->is_depot = true;347 $parameters = RouteParameters::fromArray([348 'algorithm_type' => Algorithmtype::CVRP_TW_MD,349 'route_name' => 'Multiple Depot, Multiple Driver with 24 Stops, Time Window',350 'route_date' => time() + 24 * 60 * 60,351 'route_time' => 60 * 60 * 7,352 'distance_unit' => DistanceUnit::MILES,353 'device_type' => DeviceType::WEB,354 'optimize' => OptimizationType::TIME,355 'metric' => Metric::MATRIX,356 'route_max_duration' => 86400,357 'travel_mode' => TravelMode::DRIVING,358 'vehicle_capacity' => 5,359 'vehicle_max_distance_mi' => 10000,360 ]);361 $optimizationParams = new OptimizationProblemParams();362 $optimizationParams->setAddresses($addresses);363 $optimizationParams->setParameters($parameters);364 $problem = OptimizationProblem::optimize($optimizationParams);365 self::$createdProblems[] = $problem;366 $this->assertNotNull($problem);367 $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem);368 $this->assertNotNull($problem->getOptimizationId());369 $this->assertNotNull($problem->getRoutes());370 $this->assertTrue(sizeof($problem->getRoutes())>1);371 }372 public function testMultipleSeparateDepostMultipleDriver()373 {374 // List of addresses375 $jsonAddresses = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_only.json'), true);376 $addresses = [];377 foreach ($jsonAddresses as $address) {378 $addresses[] = Address::fromArray($address);379 }380 $jsonDepots = json_decode(file_get_contents(dirname(__FILE__).'/data/depots.json'), true);381 // List of depots382 $depots = [];383 foreach ($jsonDepots as $depot) {384 $depots[] = Address::fromArray($depot);385 }386 $parameters = RouteParameters::fromArray([387 'route_name' => 'Multiple Depots Seprate Section '.date('Y-m-d H:i'),388 'algorithm_type' => AlgorithmType::CVRP_TW_MD,389 'distance_unit' => DistanceUnit::MILES,390 'device_type' => DeviceType::WEB,391 'optimize' => OptimizationType::TIME,392 'metric' => Metric::GEODESIC,393 'route_max_duration' => 86400 * 2,394 'travel_mode' => TravelMode::DRIVING,395 'vehicle_capacity' => 50,396 'vehicle_max_distance_mi' => 10000,397 'parts' => 50,398 ]);399 $optimizationParams = new OptimizationProblemParams();400 $optimizationParams->setAddresses($addresses);401 $optimizationParams->setDepots($depots);402 $optimizationParams->setParameters($parameters);403 $problem = OptimizationProblem::optimize($optimizationParams);404 self::$createdProblems[] = $problem;405 $this->assertNotNull($problem);406 $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem);407 $this->assertNotNull($problem->getOptimizationId());408 $this->assertNotNull($problem->getRoutes());409 }410 public function testOptimizationSingleDriverRoute10Stops()411 {412 // Huge list of addresses413 $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true);414 $json = array_slice($json, 0, 10);415 $addresses = [];416 foreach ($json as $address) {417 $addresses[] = Address::fromArray($address);418 }419 $parameters = RouteParameters::fromArray([420 'algorithm_type' => AlgorithmType::TSP,421 'distance_unit' => DistanceUnit::MILES,422 'device_type' => DeviceType::WEB,423 'optimize' => OptimizationType::DISTANCE,424 'travel_mode' => TravelMode::DRIVING,425 'route_max_duration' => 86400,426 'vehicle_capacity' => 1,427 'vehicle_max_distance_mi' => 10000,428 ]);429 $optimizationParams = new OptimizationProblemParams();430 $optimizationParams->setAddresses($addresses);431 $optimizationParams->setParameters($parameters);432 $problem = OptimizationProblem::optimize($optimizationParams);433 self::$createdProblems[] = $problem;434 $this->assertNotNull($problem);435 $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem);436 $this->assertNotNull($problem->getOptimizationId());437 $this->assertNotNull($problem->getRoutes());438 }439 public function testRouteSlowDown()440 {441 // Huge list of addresses442 $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true);443 $json = array_slice($json, 0, 10);444 $addresses = [];445 foreach ($json as $address) {446 $addresses[] = Address::fromArray($address);447 }448 $parameters = RouteParameters::fromArray([449 'algorithm_type' => AlgorithmType::TSP,450 'distance_unit' => DistanceUnit::MILES,451 'device_type' => DeviceType::WEB,452 'optimize' => OptimizationType::DISTANCE,453 'travel_mode' => TravelMode::DRIVING,454 'route_name' => 'SD 10 stops slowdown route '.date('Y-m-d H:i'),455 'route_max_duration' => 86400,456 'vehicle_capacity' => 1,457 'vehicle_max_distance_mi' => 10000,458 'slowdowns' => [459 'service_time' => 15,460 'travel_time' => 20461 ],462 ]);463 $optimizationParams = new OptimizationProblemParams();464 $optimizationParams->setAddresses($addresses);465 $optimizationParams->setParameters($parameters);466 $problem = OptimizationProblem::optimize($optimizationParams);467 self::$createdProblems[] = $problem;468 $this->assertNotNull($problem);469 $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem);470 $this->assertNotNull($problem->getOptimizationId());471 $this->assertNotNull($problem->parameters);472 $this->assertNotNull($problem->parameters->route_time_multiplier);473 $this->assertNotNull($problem->parameters->route_service_time_multiplier);474 $this->assertEquals(15, $problem->parameters->route_service_time_multiplier);475 $this->assertEquals(20, $problem->parameters->route_time_multiplier);476 }477 public function testSingleDriverRoundTrip()478 {479 // Huge list of addresses480 $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true);481 $json = array_slice($json, 0, 16);482 $addresses = [];483 foreach ($json as $address) {484 $addresses[] = Address::fromArray($address);485 }486 $parameters = RouteParameters::fromArray([487 'algorithm_type' => AlgorithmType::TSP,488 'distance_unit' => DistanceUnit::MILES,489 'device_type' => DeviceType::WEB,490 'optimize' => OptimizationType::DISTANCE,491 'travel_mode' => TravelMode::DRIVING,492 'route_max_duration' => 86400,493 'vehicle_capacity' => 1,494 'vehicle_max_distance_mi' => 10000,495 'rt' => true,496 ]);497 $optimizationParams = new OptimizationProblemParams();498 $optimizationParams->setAddresses($addresses);499 $optimizationParams->setParameters($parameters);500 $problem = OptimizationProblem::optimize($optimizationParams);501 self::$createdProblems[] = $problem;502 $this->assertNotNull($problem);503 $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem);504 $this->assertNotNull($problem->getOptimizationId());505 $this->assertNotNull($problem->getRoutes());506 $this->assertNotNull($problem->addresses);507 $firstAddress = $problem->routes[0]->addresses[0];508 $lastAddress = $problem->routes[0]->addresses[sizeof($problem->routes[0]->addresses)-1];509 $this->assertEquals($firstAddress->route_destination_id, $lastAddress->route_destination_id);510 }511 public function testSingleDepotMultipleDriverNoTimeWindow()512 {513 // Huge list of addresses514 $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true);515 $addresses = [];516 foreach ($json as $address) {517 $addresses[] = Address::fromArray($address);518 }519 $parameters = RouteParameters::fromArray([520 'algorithm_type' => Algorithmtype::CVRP_TW_SD,521 'route_name' => 'Single Depot, Multiple Driver, No Time Window',522 'route_date' => time() + 24 * 60 * 60,523 'route_time' => 60 * 60 * 7,524 'rt' => true,525 'distance_unit' => DistanceUnit::MILES,526 'device_type' => DeviceType::WEB,527 'optimize' => OptimizationType::TIME,528 'metric' => Metric::GEODESIC,529 'route_max_duration' => 86400,530 'travel_mode' => TravelMode::DRIVING,531 'vehicle_capacity' => 20,532 'vehicle_max_distance_mi' => 99999,533 'parts' => 4,534 ]);535 $optimizationParams = new OptimizationProblemParams();536 $optimizationParams->setAddresses($addresses);537 $optimizationParams->setParameters($parameters);538 $problem = OptimizationProblem::optimize($optimizationParams);539 self::$createdProblems[] = $problem;540 $this->assertNotNull($problem);541 $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem);542 $this->assertNotNull($problem->getOptimizationId());543 $this->assertNotNull($problem->getRoutes());544 $this->assertNotNull(sizeof($problem->routes)>1);545 }546 public function testSingleDriverMultipleTimeWindows()547 {548 // Huge list of addresses549 $json = json_decode(file_get_contents(dirname(__FILE__).'/data/mdp_mdr_24stops_tw.json'), true);550 $json = array_slice($json, 0, 20);551 $addresses = [];552 foreach ($json as $address) {553 $addresses[] = Address::fromArray($address);554 }555 $parameters = RouteParameters::fromArray([556 'algorithm_type' => Algorithmtype::TSP,557 'route_name' => 'Single Driver Multiple TimeWindows 20 Stops '.date('Y-m-d H:i'),558 'route_date' => time() + 24 * 60 * 60,559 'route_time' => 5 * 3600 + 30 * 60,560 'distance_unit' => DistanceUnit::MILES,561 'device_type' => DeviceType::WEB,562 'optimize' => OptimizationType::TIME,563 'metric' => Metric::MATRIX,564 ]);565 $optimizationParams = new OptimizationProblemParams();566 $optimizationParams->setAddresses($addresses);567 $optimizationParams->setParameters($parameters);568 $problem = OptimizationProblem::optimize($optimizationParams);569 self::$createdProblems[] = $problem;570 $this->assertNotNull($problem);571 $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem);572 $this->assertNotNull($problem->getOptimizationId());573 $this->assertNotNull($problem->getRoutes());574 $this->assertNotNull(sizeof($problem->routes)>1);575 }576 public function testTruckingSingleDriverMultipleTimeWindows()577 {578 #region Create Medium Truck579 $vehicle = new Vehicle();580 $vehicleParameters = Vehicle::fromArray([581 'vehicle_name' => 'GMC TopKick C5500 Medium',582 'vehicle_alias' => 'GMC TopKick C5500 Medium',583 'vehicle_vin' => 'SAJXA01A06FN08012',584 'vehicle_license_plate' => 'CVH4561',585 'vehicle_model' => 'TopKick C5500',586 'vehicle_model_year' => 1995,587 'vehicle_year_acquired' => 2008,588 'vehicle_reg_country_id' => '223',589 'vehicle_make' => 'GMC',590 'vehicle_type_id' => 'pickup_truck',591 'vehicle_axle_count' => 2,592 'mpg_city' => 7,593 'mpg_highway' => 14,594 'fuel_type' => 'diesel',595 'height_inches' => 97,596 'height_metric' => 243,597 'weight_lb' => 19000,598 'maxWeightPerAxleGroupInPounds' => 9500,599 'max_weight_per_axle_group_metric' => 4300,600 'widthInInches' => 96,601 'width_metric' => 240,602 'lengthInInches' => 244,603 'length_metric' => 610,604 'Use53FootTrailerRouting' => 'YES',605 'UseTruckRestrictions' => 'YES',606 'DividedHighwayAvoidPreference' => 'NEUTRAL',607 'FreewayAvoidPreference' => 'NEUTRAL',608 'truck_config' => 'FULLSIZEVAN',609 ]);610 $result = $vehicle->createVehicle($vehicleParameters);611 $this->assertNotNull($result);612 $this->assertTrue(isset($result['status']));613 $this->assertTrue($result['status']);614 $this->assertTrue(isset($result['vehicle_guid']));615 $vehicleId = $result['vehicle_guid'];616 self::$removedVehicle = $vehicleId;617 #endregion618 // Huge list of addresses619 $json = json_decode(file_get_contents(dirname(__FILE__).'/data/mdp_mdr_24stops_tw.json'), true);620 $json = array_slice($json, 0, 18);621 $addresses = [];622 foreach ($json as $address) {623 $addresses[] = Address::fromArray($address);624 }625 $parameters = RouteParameters::fromArray([626 'algorithm_type' => Algorithmtype::CVRP_TW_SD,627 'route_name' => 'Trucking SD Multiple TW 18 Stops '.date('Y-m-d H:i'),628 'route_date' => time() + 24 * 60 * 60,629 'route_time' => 5 * 3600 + 30 * 60,630 'distance_unit' => DistanceUnit::MILES,631 'device_type' => DeviceType::WEB,632 'optimize' => OptimizationType::TIME_WITH_TRAFFIC,633 'metric' => Metric::MATRIX,634 'route_max_duration' => 8 * 3600 + 30 * 60,635 'vehicle_id' => $vehicleId,636 'travel_mode' => TravelMode::DRIVING,637 'vehicle_max_cargo_weight' => 30,638 'vehicle_capacity' => 10,639 'vehicle_max_distance_mi' => 10000,640 'trailer_weight_t' => 10,641 'weight_per_axle_t' => 10,642 'limited_weight_t' => 20,643 'rt' => true644 ]);645 $optimizationParams = new OptimizationProblemParams();646 $optimizationParams->setAddresses($addresses);647 $optimizationParams->setParameters($parameters);648 $problem = OptimizationProblem::optimize($optimizationParams);649 self::$createdProblems[] = $problem;650 $this->assertNotNull($problem);651 $this->assertInstanceOf('Route4Me\OptimizationProblem', $problem);652 $this->assertNotNull($problem->getOptimizationId());653 $this->assertNotNull($problem->getRoutes());654 $this->assertNotNull(sizeof($problem->routes)>1);655 }656 public static function tearDownAfterClass()657 {658 if (sizeof(self::$createdProblems)>0) {659 $optimizationProblemIDs = [];660 foreach (self::$createdProblems as $problem) {661 $optimizationProblemId = $problem->optimization_problem_id;662 $optimizationProblemIDs[] = $optimizationProblemId;663 }664 if (sizeof(self::$removedOptimizationIDs)>0) {665 $optimizationProblemIDs = array_merge($optimizationProblemIDs,self::$removedOptimizationIDs);666 }667 $params = [668 'optimization_problem_ids' => $optimizationProblemIDs,669 'redirect' => 0,670 ];671 $problem = new OptimizationProblem();672 $result = $problem->removeOptimization($params);673 if ($result!=null && $result['status']==true) {674 echo "The test optimizations were removed <br>";675 } else {676 echo "Cannot remove the test optimizations <br>";677 }678 }679 if (sizeof(self::$removedRouteIDs)>0) {680 $route = new Route();681 $route_ids = join(',', self::$removedRouteIDs);682 $result = $route->deleteRoutes($route_ids);683 if ($result!=null && $result['deleted']==true) {684 echo "The test routes were removed <br>";685 } else {686 echo "Cannot remove the test routes <br>";687 }688 }689 if (!is_null(self::$removedVehicle!=null) && strlen(self::$removedVehicle)==32) {690 $vehicle = new Vehicle();691 $vehicleParameters = Vehicle::fromArray([692 'vehicle_id' => self::$removedVehicle,693 ]);694 $result = $vehicle->removeVehicle($vehicleParameters);695 if (!is_null($result)) {696 echo "The vehicle ".$result['vehicle_id']." removed <br>";697 } else {698 echo "Cannot remove the vehicle ".$vehicle['vehicle_id']."<br>";699 }700 }701 }702}...

Full Screen

Full Screen

InputMessageAnimation.php

Source:InputMessageAnimation.php Github

copy

Full Screen

...55 $this->width = $width;56 $this->height = $height;57 $this->caption = $caption;58 }59 public static function fromArray(array $array): InputMessageAnimation60 {61 return new static(62 TdSchemaRegistry::fromArray($array['animation']),63 TdSchemaRegistry::fromArray($array['thumbnail']),64 $array['duration'],65 $array['width'],66 $array['height'],67 TdSchemaRegistry::fromArray($array['caption']),68 );69 }70 public function typeSerialize(): array71 {72 return [73 '@type' => static::TYPE_NAME,74 'animation' => $this->animation->typeSerialize(),75 'thumbnail' => $this->thumbnail->typeSerialize(),76 'duration' => $this->duration,77 'width' => $this->width,78 'height' => $this->height,79 'caption' => $this->caption->typeSerialize(),80 ];81 }...

Full Screen

Full Screen

VideoNote.php

Source:VideoNote.php Github

copy

Full Screen

...47 $this->minithumbnail = $minithumbnail;48 $this->thumbnail = $thumbnail;49 $this->video = $video;50 }51 public static function fromArray(array $array): VideoNote52 {53 return new static(54 $array['duration'],55 $array['length'],56 (isset($array['minithumbnail']) ? TdSchemaRegistry::fromArray($array['minithumbnail']) : null),57 (isset($array['thumbnail']) ? TdSchemaRegistry::fromArray($array['thumbnail']) : null),58 TdSchemaRegistry::fromArray($array['video']),59 );60 }61 public function typeSerialize(): array62 {63 return [64 '@type' => static::TYPE_NAME,65 'duration' => $this->duration,66 'length' => $this->length,67 'minithumbnail' => (isset($this->minithumbnail) ? $this->minithumbnail : null),68 'thumbnail' => (isset($this->thumbnail) ? $this->thumbnail : null),69 'video' => $this->video->typeSerialize(),70 ];71 }72 public function getDuration(): int...

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$duration = new Duration();2$duration->fromArray(array('years' => 1, 'months' => 2, 'days' => 3, 'hours' => 4, 'minutes' => 5, 'seconds' => 6));3echo $duration->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');4$duration = new Duration();5$duration->fromString('P1Y2M3DT4H5M6S');6echo $duration->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');7$duration = new Duration();8$duration->fromString('P1Y2M3DT4H5M6S');9echo $duration->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');10$duration = new Duration();11$duration->fromString('P1Y2M3DT4H5M6S');12echo $duration->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');13$duration = new Duration();14$duration->fromString('P1Y2M3DT4H5M6S');15echo $duration->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$duration = new Duration();2$duration->fromArray(array(3));4print_r($duration);5$duration = new Duration();6$duration->fromArray(array(7));8print_r($duration->toArray());9$duration = new Duration();10$duration->fromArray(array(11));12print_r($duration->toDateTimeInterval());13$duration = new Duration();14$duration->fromArray(array(15));16print_r($duration->toISO8601());

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$duration = new Duration();2$duration->fromArray(array('days' => 1, 'hours' => 2, 'minutes' => 3, 'seconds' => 4));3echo $duration->format('%d days, %h hours, %i minutes, %s seconds');4$duration = new Duration();5$duration->fromArray(array('days' => 1, 'hours' => 2, 'minutes' => 3, 'seconds' => 4));6echo $duration->format('%d days, %h hours, %i minutes, %s seconds');7$duration = new Duration();8$duration->fromArray(array('days' => 1, 'hours' => 2, 'minutes' => 3, 'seconds' => 4));9echo $duration->format('%d days, %h hours, %i minutes, %s seconds');10$duration = new Duration();11$duration->fromArray(array('days' => 1, 'hours' => 2, 'minutes' => 3, 'seconds' => 4));12echo $duration->format('%d days, %h hours, %i minutes, %s seconds');13$duration = new Duration();14$duration->fromArray(array('days' => 1, 'hours' => 2, 'minutes' => 3, 'seconds' => 4));15echo $duration->format('%d days, %h hours, %i minutes, %s seconds');16$duration = new Duration();

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$duration = new Duration();2$duration->fromArray(array(3));4echo $duration->getDuration();5$duration = new Duration();6$duration->fromArray(array(7 'start' => new DateTime('2016-01-01 10:00:00'),8 'end' => new DateTime('2016-01-01 12:00:00')9));10echo $duration->getDuration();11$duration = new Duration();12$duration->fromArray(array(13 'start' => new DateTimeImmutable('2016-01-01 10:00:00'),14 'end' => new DateTimeImmutable('2016-01-01 12:00:00')15));16echo $duration->getDuration();17$duration = new Duration();18$duration->fromArray(array(19));20echo $duration->getDuration();21$duration = new Duration();22$duration->fromArray(array(23 'start' => new DateTime('2016-01-01 10:00:00'),24 'end' => new DateTime('2016-01-01 12:00:00')25));26echo $duration->getDuration();27$duration = new Duration();28$duration->fromArray(array(29 'start' => new DateTimeImmutable('2016-01-01 10:00:00'),30 'end' => new DateTimeImmutable('2016-01-01 12:00:00')31));32echo $duration->getDuration();33$duration = new Duration();

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$duration = new Duration();2$duration->fromArray(array("hours" => 1, "minutes" => 30));3$duration = new Duration();4$duration->fromArray(array("hours" => 1, "minutes" => 30, "seconds" => 45));5$duration = new Duration();6$duration->fromArray(array("hours" => 1, "minutes" => 30, "seconds" => 45, "milliseconds" => 500));7$duration = new Duration();8$duration->fromArray(array("hours" => 1, "minutes" => 30, "seconds" => 45, "milliseconds" => 500, "microseconds" => 100));9$duration = new Duration();10$duration->fromArray(array("hours" => 1, "minutes" => 30, "seconds" => 45, "milliseconds" => 500, "microseconds" => 100, "nanoseconds" => 200));

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$duration = new Duration();2$duration->fromArray(array('days'=>1, 'hours'=>2, 'minutes'=>3, 'seconds'=>4));3echo $duration->format('%d %h %i %s');4$duration = new Duration();5$duration->fromString('P1DT2H3M4S');6echo $duration->format('%d %h %i %s');7$duration = new Duration();8$duration->fromTimestamp(3600 * 24 + 3600 * 2 + 60 * 3 + 4);9echo $duration->format('%d %h %i %s');10$duration = new Duration();11$duration->fromDateTime(new DateTime('2012-01-01 00:00:00'), new DateTime('2012-01-02 02:03:04'));12echo $duration->format('%d %h %i %s');13$duration = new Duration();14$duration->fromDateTime(new DateTime('2012-01-01 00:00:00'), new DateTime('2012-01-02 02:03:04'));15echo $duration->format('%d %h %i %s');16$duration = new Duration();17$duration->fromDateTime(new DateTime('2012-01-01 00:00:00'), new DateTime('2012-01-02 02:03:04'));18echo $duration->format('%d %h %i %s');19$duration = new Duration();20$duration->fromDateTime(new DateTime('2012-01-01 00:00:00'), new DateTime('2012-01-02 02:03:04'));21echo $duration->format('%d %h %i %s');22$duration = new Duration();23$duration->fromDateTime(new DateTime('

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$duration = new Duration();2$duration->fromArray(array('days' => 5, 'hours' => 10, 'minutes' => 20));3echo $duration->getDays() . " days " . $duration->getHours() . " hours " . $duration->getMinutes() . " minutes";4$duration = new Duration();5$duration->fromString('5 days 10 hours 20 minutes');6echo $duration->getDays() . " days " . $duration->getHours() . " hours " . $duration->getMinutes() . " minutes";7$duration = new Duration();8$duration->fromString('5 days 10 hours 20 minutes');9echo $duration->toString();10$duration = new Duration();11$duration->fromString('5 days 10 hours 20 minutes');12$duration->add(new Duration('1 days 2 hours 30 minutes'));13echo $duration->toString();14$duration = new Duration();15$duration->fromString('5 days 10 hours 20 minutes');16$duration->sub(new Duration('1 days 2 hours 30 minutes'));17echo $duration->toString();18$duration = new Duration();19$duration->fromString('5 days 10 hours 20 minutes');20$duration->multiply(2);21echo $duration->toString();22$duration = new Duration();23$duration->fromString('5 days 10 hours 20 minutes');24$duration->divide(2);25echo $duration->toString();

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$duration = new Duration();2$duration->fromArray(array('hours' => 5, 'minutes' => 45));3echo $duration->toString();4$duration = new Duration();5$duration->fromArray(array('days' => 2, 'hours' => 5, 'minutes' => 45));6echo $duration->toString();7$duration = new Duration();8$duration->fromArray(array('weeks' => 2, 'days' => 2, 'hours' => 5, 'minutes' => 45));9echo $duration->toString();10$duration = new Duration();11$duration->fromArray(array('months' => 2, 'weeks' => 2, 'days' => 2, 'hours' => 5, 'minutes' => 45));12echo $duration->toString();13$duration = new Duration();14$duration->fromArray(array('years' => 2, 'months' => 2, 'weeks' => 2, 'days' => 2, 'hours' => 5, 'minutes' => 45));15echo $duration->toString();16$duration = new Duration();17$duration->fromArray(array('years' => 2, 'months' => 2, 'weeks' => 2, 'days' => 2, 'hours' => 5, 'minutes' => 45, 'seconds' => 15));18echo $duration->toString();

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1$duration = new Duration();2$duration->fromArray(array('year' => 1, 'month' => 2, 'day' => 3));3$duration = new Duration();4$duration->fromArray(array('year' => 1, 'month' => 2, 'day' => 3, 'hour' => 4, 'minute' => 5, 'second' => 6));5$duration = new Duration();6$duration->fromArray(array('year' => 1, 'month' => 2, 'day' => 3, 'hour' => 4, 'minute' => 5, 'second' => 6, 'millisecond' => 7));7$duration = new Duration();8$duration->fromArray(array('year' => 1, 'month' => 2, 'day' => 3, 'hour' => 4, 'minute' => 5, 'second' => 6, 'millisecond' => 7, 'microsecond' => 8));9$duration = new Duration();10$duration->fromArray(array('year' => 1, 'month' => 2, 'day' => 3, 'hour' => 4, 'minute' => 5, 'second' => 6, 'millisecond' => 7, 'microsecond' => 8, 'nanosecond' => 9));

Full Screen

Full Screen

fromArray

Using AI Code Generation

copy

Full Screen

1require_once('Duration.php');2$duration = new Duration();3$duration->fromArray(array('hours' => 1, 'minutes' => 30));4require_once('Duration.php');5$duration = new Duration();6$duration->fromArray(array('hours' => 1, 'minutes' => 30));7require_once('Duration.php');8$duration = new Duration();9$duration->fromArray(array('hours' => 1, 'minutes' => 30));10require_once('Duration.php');11$duration = new Duration();12$duration->fromArray(array('hours' => 1, 'minutes' => 30));13require_once('Duration.php');14$duration = new Duration();15$duration->fromArray(array('hours' => 1, 'minutes' => 30));16require_once('Duration.php');17$duration = new Duration();18$duration->fromArray(array('hours' => 1, 'minutes' => 30));19require_once('

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cucumber Common Library automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Duration

Trigger fromArray code on LambdaTest Cloud Grid

Execute automation tests with fromArray on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful