Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create examples for advanced constraints #11

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 14 additions & 27 deletions UnitTestFiles/Test/OrderTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ public static function setUpBeforeClass()
'EXT_FIELD_email' => '[email protected]',
'EXT_FIELD_phone' => '380380380380',
'EXT_FIELD_custom_data' => [
0 => [
'order_id' => '10',
'name' => 'Bill Soul',
],
'order_id' => '10',
'name' => 'Bill Soul'
],
]);

Expand Down Expand Up @@ -106,10 +104,8 @@ public function testFromArray()
'EXT_FIELD_email' => '[email protected]',
'EXT_FIELD_phone' => '380380380380',
'EXT_FIELD_custom_data' => [
0 => [
'order_id' => '10',
'name' => 'Bill Soul',
],
'order_id' => '10',
'name' => 'Bill Soul'
],
]);

Expand All @@ -124,11 +120,10 @@ public function testFromArray()
$this->assertEquals('[email protected]', $orderParameters->EXT_FIELD_email);
$this->assertEquals('380380380380', $orderParameters->EXT_FIELD_phone);
$this->assertEquals([
0 => [
'order_id' => '10',
'name' => 'Bill Soul',
],
], $orderParameters->EXT_FIELD_custom_data);
'order_id' => '10',
'name' => 'Bill Soul'
],
$orderParameters->EXT_FIELD_custom_data);
}

public function testToArray()
Expand All @@ -145,10 +140,8 @@ public function testToArray()
'EXT_FIELD_email' => '[email protected]',
'EXT_FIELD_phone' => '380380380380',
'EXT_FIELD_custom_data' => [
0 => [
'order_id' => '10',
'name' => 'Bill Soul',
],
'order_id' => '10',
'name' => 'Bill Soul'
],
]);

Expand All @@ -165,10 +158,8 @@ public function testToArray()
'EXT_FIELD_email' => '[email protected]',
'EXT_FIELD_phone' => '380380380380',
'EXT_FIELD_custom_data' => [
0 => [
'order_id' => '10',
'name' => 'Bill Soul',
],
'order_id' => '10',
'name' => 'Bill Soul'
],
]
);
Expand Down Expand Up @@ -473,9 +464,7 @@ public function testUpdateOrder()
self::$createdOrders[0]['address_2'] = 'Lviv';
self::$createdOrders[0]['EXT_FIELD_phone'] = '032268593';
self::$createdOrders[0]['EXT_FIELD_custom_data'] = [
0 => [
'customer_no' => '11',
],
'customer_no' => '11'
];

$response = $order->updateOrder(self::$createdOrders[0]);
Expand All @@ -485,9 +474,7 @@ public function testUpdateOrder()
$this->assertEquals('Lviv', $response['address_2']);
$this->assertEquals('032268593', $response['EXT_FIELD_phone']);
$this->assertEquals(
[
0 => [ 'customer_no' => '11' ],
],
[ 'customer_no' => '11' ],
$response['EXT_FIELD_custom_data']
);
}
Expand Down
6 changes: 2 additions & 4 deletions UnitTestFiles/Test/V5/data/update_order_data.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"order_id": "7205711",
"address_2": "Lviv",
"EXT_FIELD_custom_data" : [
{
"EXT_FIELD_custom_data" : {
"customer_no" : 11
}
],
},
"EXT_FIELD_phone": "032268593"
}
6 changes: 2 additions & 4 deletions UnitTestFiles/Test/data/update_order_data.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"order_id": "7205711",
"address_2": "Lviv",
"EXT_FIELD_custom_data" : [
{
"EXT_FIELD_custom_data" : {
"customer_no" : 11
}
],
},
"EXT_FIELD_phone": "032268593"
}
76 changes: 76 additions & 0 deletions examples/OptimizationWithAdvancedConstraints.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Route4Me;

$root = realpath(dirname(__FILE__).'/../');
require $root.'/vendor/autoload.php';

use Route4Me\Enum\OptimizationType;
use Route4Me\Enum\AlgorithmType;
use Route4Me\Enum\DistanceUnit;
use Route4Me\Enum\DeviceType;
use Route4Me\Enum\Metric;

// The example requires an API key with the enterprise subscription.

// Set the api key in the Route4me class
Route4Me::setApiKey(Constants::API_KEY);

// Huge list of addresses
$json = json_decode(file_get_contents('./addresses_adv_constr.json'), true);

$addresses = [];
foreach ($json as $address) {
$addresses[] = Address::fromArray($address);
}

$depots = [
Address::fromArray([
'alias' => 'Start Depot',
'address' => '1 MIAD Terminal J 2nd Floor, Miami,FL, (305) 876-0980',
'lat' => 25.774254,
'lng' => -80.190211
])
];

$parameters = RouteParameters::fromArray([
'algorithm_type' => Algorithmtype::ADVANCED_CVRP_TW,
'route_name' => 'Optimization With Same Last Location '.date('Y-m-d H:i:s', time()),
'route_date' => time() + 24 * 60 * 60,
'route_time' => 6 * 3600,
'distance_unit' => DistanceUnit::MILES,
'device_type' => DeviceType::WEB,
'optimize' => OptimizationType::DISTANCE,
'advanced_constraints' => [
[
'location_sequence_pattern' => [
'',
[
'alias' => 'End Depot',
'address' => '9681 SW 72nd St, Miami,FL, (305) 598-4933',
'lng' => -80.34972,
'lat' => 25.70185
]
]
]
],

]);

$optimizationParams = new OptimizationProblemParams();
$optimizationParams->setAddresses($addresses);
$optimizationParams->setDepots($depots);
$optimizationParams->setParameters($parameters);

$problem = OptimizationProblem::optimize($optimizationParams);
echo "<pre>";
foreach ((array) $problem as $key => $value) {
if (is_string($value)) {
echo $key.' --> '.$value.'<br>';
} else {
echo "************ $key ************* <br>";
Route4Me::simplePrint((array) $value, true);
echo '******************************* <br>';
}
}
echo "</pre>";
87 changes: 87 additions & 0 deletions examples/OptimizationWithAdvancedConstraintsMemberCount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace Route4Me;

$root = realpath(dirname(__FILE__).'/../');
require $root.'/vendor/autoload.php';

use Route4Me\Enum\OptimizationType;
use Route4Me\Enum\AlgorithmType;
use Route4Me\Enum\DistanceUnit;
use Route4Me\Enum\DeviceType;
use Route4Me\Enum\Metric;
use Route4Me\Enum\TravelMode;

// The example requires an API key with the enterprise subscription.

// Set the api key in the Route4me class
Route4Me::setApiKey(Constants::API_KEY);

// Huge list of addresses
$json = json_decode(file_get_contents('./addresses_adv_constr2.json'), true);

$addresses = [];
foreach ($json as $address) {
$addresses[] = Address::fromArray($address);
}

$depots = [
Address::fromArray([
'alias' => 'Start Depot',
'is_depot' => true,
'address' => '1 Fritz Sonnenberg Rd, Green Point, Cape Town, 8051, South Africa',
'lat' => -33.90410680000001,
'lng' => 18.4010964
])
];

$parameters = RouteParameters::fromArray([
'rt' => 0,
'algorithm_type' => Algorithmtype::ADVANCED_CVRP_TW,
'route_name' => 'Optimization With Same Last Location and Member Count '.date('Y-m-d H:i:s', time()),
'route_date' => time() + 24 * 60 * 60,
'route_time' => 6 * 3600,
'distance_unit' => DistanceUnit::MILES,
'device_type' => DeviceType::WEB,
'optimize' => OptimizationType::DISTANCE,
'travel_mode' => TravelMode::DRIVING,
'route_max_duration' => 7200,
'store_route' => true,
'parts' => 2,
'parts_min' => 2,
'advanced_constraints' => [
[
'members_count' => 2,
'location_sequence_pattern' => [
'',
[
'lat' => -33.92136,
'lng' => 18.4181938,
'is_depot' => false,
'address' => '105 Bree St, Cape Town City Centre, Cape Town, 8001, South Africa',
'order_id' => 50,
'route_destination_id' => 736611941,
]
]
]
],

]);

$optimizationParams = new OptimizationProblemParams();
$optimizationParams->setAddresses($addresses);
$optimizationParams->setDepots($depots);
$optimizationParams->setParameters($parameters);

$problem = OptimizationProblem::optimize($optimizationParams);
echo "<pre>";
foreach ((array) $problem as $key => $value) {
if (is_string($value)) {
echo $key.' --> '.$value.'<br>';
} else {
echo "************ $key ************* <br>";
Route4Me::simplePrint((array) $value, true);
echo '******************************* <br>';
}
}
echo "</pre>";
6 changes: 2 additions & 4 deletions examples/Order/NewOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
'EXT_FIELD_email' => '[email protected]',
'EXT_FIELD_phone' => '380380380380',
'EXT_FIELD_custom_data' => [
0 => [
'order_id' => '10',
'name' => 'Bill Soul',
],
],
'name' => 'Bill Soul'
]
]);

$order = new Order();
Expand Down
4 changes: 1 addition & 3 deletions examples/Order/UpdateOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
$randomOrder['address_2'] = 'Lviv';
$randomOrder['EXT_FIELD_phone'] = '032268593';
$randomOrder['EXT_FIELD_custom_data'] = [
0 => [
'customer_no' => '11',
],
'customer_no' => '11'
];

$response = $order->updateOrder($randomOrder);
Expand Down
6 changes: 2 additions & 4 deletions examples/Order/update_order_data.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"order_id": "7205711",
"address_2": "Lviv",
"EXT_FIELD_custom_data" : [
{
"EXT_FIELD_custom_data" : {
"customer_no" : 11
}
],
},
"EXT_FIELD_phone": "032268593"
}
Loading