foodcheri / routific-bundle
Routific PHP SDK 包
v1.0.0
2016-06-14 19:09 UTC
Requires
- mashape/unirest-php: 3.*
This package is not auto-updated.
Last update: 2024-09-17 10:29:44 UTC
README
SDK Routific
安装
通过在 composer.json 中添加以下行来安装包
"require": {
...
"foodcheri/routific-bundle": "dev-master"
},
"repositories": [{
"type": "vcs",
"url": "https://github.com/foodcheri/RoutificBundle.git"
}],
更新您的供应商
composer update
在 config.yml 中添加配置
...
routific:
api_url: ~ #default: https://api.routific.com/v1
token_key: routific_token
使用方法
实例化 Routific 客户端
$clientRoutific = $this->get('foodcheri_sdk_routific.client');
为了解决车辆路径问题,实例化一个 VehicleRoutingProblem EndPoint 对象
$problem = new VehicleRoutingProblem();
向问题端点添加访问
$problem->addVisit("order_1", array(
"location" => array(
"name" => "Visit1 name",
"lat" => 49.227607,
"lng" => -123.1363085
),
"start" => "19:00",
"end" => "19:30",
"duration" => 5,
"load" => 1,
"type" => "A",
"priority" => "high"
)
);
向问题端点添加车辆
$problem->addVehicle("vehicle_1", array(
"start_location" => array(
"id" => "hub id"
"name" => "hub name",
"lat" => 49.227607,
"lng" => -123.1363085
),
"end_location" => array(
"id" => "hub id",
"name" => "hub name",
"lat" => 49.227607,
"lng" => -123.1363085
),
"shift_start" => "18:00",
"shift_end" => "22:30",
"min_visits" => 10,
"capacity" => 20,
"type" => ["A", "B"],
"speed" => "bike",
"strict_start" => true,
"break_start" => "12:00",
"break_end" => "13:30",
"break_duration" => 30
)
);
向问题端点添加选项
"options": {
"traffic": "slow",
"min_visits_per_vehicle": 5,
"balance": true,
"min_vehicles": true,
"shortest_distance": true
}
$problem->addOption(array("traffic" => "slow"));
最后为端点问题执行路线计算
$clientRoutific->route($problem);
响应
{
"status": "success",
"total_travel_time": 31.983334,
"total_idle_time": 0,
"num_unserved": 0,
"unserved": null,
"solution": {
"vehicle_1": [
{
"location_id": "depot",
"location_name": "800 Kingsway",
"arrival_time": "08:00"
},
{
"location_id": "order_3",
"location_name": "800 Robson",
"arrival_time": "08:10",
"finish_time": "08:20"
},
{
"location_id": "order_2",
"location_name": "3780 Arbutus",
"arrival_time": "08:29",
"finish_time": "09:10"
},
{
"location_id": "order_1",
"location_name": "6800 Cambie",
"arrival_time": "09:19",
"finish_time": "09:29"
},
{
"location_id": "depot",
"location_name": "800 Kingsway",
"arrival_time": "09:39"
}
]
}
}