You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

476 lines
25 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Miracle
  5. * Date: 2016/9/5
  6. * Time: 10:51
  7. * 调度算法
  8. */
  9. require_once __DIR__ . '/common.php';
  10. class dispatch_algorithm extends virtifyUsers
  11. {
  12. private $nj_nt_prod_id = "449860";
  13. private $nt_nj_prod_id = "449865";
  14. /**
  15. * //全排列方法
  16. * @param string $first
  17. * @param $arr
  18. * @param array $results
  19. * Array ( [0] => 1-2-3 [1] => 1-3-2 [2] => 2-1-3 [3] => 2-3-1 [4] => 3-1-2 [5] => 3-2-1 ) 结果格式
  20. */
  21. function Permutate($first = '', $arr, &$results = array())
  22. {
  23. $len = count($arr);
  24. if ($len == 1) {
  25. $results[] = $first . '-' . $arr[0];
  26. } else {
  27. for ($i = 0; $i < $len; $i++) {
  28. $tmp = $arr[0];
  29. $arr[0] = $arr[$i];
  30. $arr[$i] = $tmp;
  31. if ($first != '') {
  32. $this->Permutate($first . '-' . $arr[0], array_slice($arr, 1), $results);
  33. } else {
  34. $this->Permutate($first . $arr[0], array_slice($arr, 1), $results);
  35. }
  36. }
  37. }
  38. }
  39. /**
  40. * //调度方法
  41. * @param $order_list
  42. * @param $new_order
  43. * @param $array_start
  44. * @param $array_end
  45. * @return string|void
  46. */
  47. function dispatch($prodID, $order_list, $new_order, $array_start, $array_end, $run_date, $should_be_count)
  48. {
  49. $is_xiecheng = false;//判断是否是携程的订单
  50. $order_num = count($order_list) + 1;//将会有多少订单上车
  51. $order_list[$order_num - 1]["order_id"] = $new_order["order_id"];
  52. $order_list[$order_num - 1]["num"] = $new_order["num"];
  53. $order_list[$order_num - 1]["startx_y"] = $new_order["startx_y"];
  54. $order_list[$order_num - 1]["endx_y"] = $new_order["endx_y"];
  55. for ($temp_xiecheng_i = 0; $temp_xiecheng_i < $order_num; $temp_xiecheng_i++) {
  56. if (($order_list[$temp_xiecheng_i]["startx_y"] == "32.116682,118.784105" && $order_list[$temp_xiecheng_i]["endx_y"] == "32.011714,120.894448") || ($order_list[$temp_xiecheng_i]["startx_y"] == "32.011714,120.894448" && $order_list[$temp_xiecheng_i]["endx_y"] == "32.116682,118.784105")) {
  57. $is_xiecheng = true;//是携程的订单
  58. }
  59. }
  60. $arr = range(1, $order_num);//1-3的全排列
  61. //默认相同地点或很近地点时间为0
  62. for ($start_i = 1; $start_i <= $order_num; $start_i++) {
  63. for ($start_ii = 1; $start_ii <= $order_num; $start_ii++) {
  64. if ($array_start[$start_i][$start_ii] <= 2) {
  65. $array_start[$start_i][$start_ii] = 0;//默认相同地点或很近地点时间为0
  66. }
  67. }
  68. }
  69. for ($end_i = 1; $end_i <= $order_num; $end_i++) {
  70. for ($end_ii = 1; $end_ii <= $order_num; $end_ii++) {
  71. if ($array_end[$end_i][$end_ii] <= 2) {
  72. $array_end[$end_i][$end_ii] = 0;//默认相同地点或很近地点时间为0
  73. }
  74. }
  75. }
  76. $Permutate_results = array();
  77. $this->Permutate($first = '', $arr, $Permutate_results);
  78. $totol = count($Permutate_results);
  79. $Permutate_array = array();
  80. for ($ii = 0; $ii < $totol; $ii++) {
  81. $Permutate_array[$ii] = explode('-', $Permutate_results[$ii]);//切分字符串变成数组
  82. }
  83. $min_start_cost_time = 9999;//起始地最小耗时
  84. $min_start_arr_num = 0;//记录起始最小耗时的排列位置
  85. for ($i = 0; $i < $totol; $i++) {
  86. //遍历每一种全排列计算冗余时间
  87. $totol_start_cost = 0;//每种组合实际消耗时间
  88. for ($j = 0; $j < $order_num - 1; $j++) {
  89. //计算每一个点
  90. $totol_start_cost = $totol_start_cost + $array_start[$Permutate_array[$i][$j]][$Permutate_array[$i][$j + 1]];
  91. }
  92. if ($totol_start_cost < $min_start_cost_time) {
  93. $min_start_arr_num = $i;//记录接人最小耗时组合
  94. $min_start_cost_time = $totol_start_cost;//记录接人最小耗时时间值
  95. }
  96. }
  97. $arr_start_rev = array();
  98. $temp_j = $order_num - 1;
  99. $arr_start_rev_cost = 0;//翻转接人耗时
  100. for ($temp_i = 0; $temp_i < $order_num; $temp_i++) {
  101. $arr_start_rev[$temp_i] = $Permutate_array[$min_start_arr_num][$temp_j];
  102. $temp_j--;//翻转接人数组
  103. }
  104. for ($j = 0; $j < $order_num - 1; $j++) {
  105. $arr_start_rev_cost = $arr_start_rev_cost + $array_start[$arr_start_rev[$j]][$arr_start_rev[$j + 1]];
  106. }
  107. $min_end_cost_time = 9999;//起始地最小耗时
  108. $min_end_arr_num = 0;//记录起始最小耗时的排列位置
  109. for ($i = 0; $i < $totol; $i++) {
  110. //遍历每一种全排列计算冗余时间
  111. $totol_end_cost = 0;//每种组合实际消耗时间
  112. for ($j = 0; $j < $order_num - 1; $j++) {
  113. //计算每一个点
  114. $totol_end_cost = $array_end[$Permutate_array[$i][$j]][$Permutate_array[$i][$j + 1]] + $totol_end_cost;
  115. }
  116. if ($totol_end_cost < $min_end_cost_time) {
  117. $min_end_arr_num = $i;//记录送人最小耗时组合
  118. $min_end_cost_time = $totol_end_cost;//记录送人最小耗时时间值
  119. }
  120. }
  121. $arr_end_rev = array();
  122. $temp_j = $order_num - 1;
  123. $arr_end_rev_cost = 0;//翻转送人耗时
  124. for ($temp_i = 0; $temp_i < $order_num; $temp_i++) {
  125. $arr_end_rev[$temp_i] = $Permutate_array[$min_end_arr_num][$temp_j];
  126. $temp_j--;//翻转送人数组
  127. }
  128. for ($j = 0; $j < $order_num - 1; $j++) {
  129. $arr_end_rev_cost = $arr_end_rev_cost + $array_end[$arr_end_rev[$j]][$arr_end_rev[$j + 1]];
  130. }
  131. $start = array(
  132. "$min_start_cost_time" . '-' . $order_list[$Permutate_array[$min_start_arr_num][$order_num - 1] - 1]["startx_y"] => $Permutate_array[$min_start_arr_num],
  133. "$arr_start_rev_cost" . '-' . $order_list[$Permutate_array[$min_start_arr_num][0] - 1]["startx_y"] => $arr_start_rev
  134. );
  135. $end = array(
  136. "$min_end_cost_time" . '-' . $order_list[$Permutate_array[$min_end_arr_num][0] - 1]["startx_y"] => $Permutate_array[$min_end_arr_num],
  137. "$arr_end_rev_cost" . '-' . $order_list[$Permutate_array[$min_end_arr_num][$order_num - 1] - 1]["startx_y"] => $arr_end_rev
  138. );
  139. #region 求出四种组合方式中用时最短的线路
  140. $min_time_list = array();
  141. foreach ($start as $k => $v) {
  142. foreach ($end as $key => $value) {
  143. $begin_lat_lon = explode('-', $k);
  144. $end_lat_lon = explode('-', $key);
  145. $time = commonUtils::baiduShortTime($begin_lat_lon[1], $end_lat_lon[1]);
  146. $current_route = $v;
  147. $total_route = array_merge($current_route, $value);
  148. $total_time = array("min_time" => $begin_lat_lon[0] + ceil($time / 60) + $end_lat_lon[0], "route" => $total_route, "middle_time" => ceil($time / 60));
  149. array_push($min_time_list, $total_time);
  150. }
  151. }
  152. $max_time = 999999;
  153. $min_route_arr = array();
  154. $middleTime = 0;
  155. $min_time_list_count = count($min_time_list);
  156. for ($i = 0; $i < $min_time_list_count; $i++) {
  157. if ($min_time_list[$i]["min_time"] < $max_time) {
  158. $max_time = $min_time_list[$i]["min_time"];
  159. $middleTime = $min_time_list[$i]["middle_time"]; //接人的最后一个点到送人的第一个点的最短时间
  160. $min_route_arr = $min_time_list[$i]["route"];
  161. }
  162. }
  163. $road1 = array("location" => "32.135283,120.230875", "nt" => "77", "nj" => "129");//高速路1 广陵枢纽与沪陕高速公路交叉口(地址:江苏省泰州市泰兴市)to:高速路标记点到南通的最短时间 go:高速路标记点到南京的最短时间
  164. $road2 = array("location" => "31.749506,120.140182", "nt" => "89", "nj" => "116");//高速路2 江苏省常州市武进区横林枢纽立交桥
  165. if ($is_xiecheng) {
  166. //携程的订单
  167. $temp_time_on_the_way = strtotime($run_date);
  168. $time_on_the_way = date("Y-m-d H:i", $temp_time_on_the_way); //到携程的时间
  169. } else {
  170. //不是携程的订单
  171. $temp_time_on_the_way = strtotime($run_date) + 210 * 60;
  172. $time_on_the_way = date("Y-m-d H:i", $temp_time_on_the_way); //到南通的时间
  173. }
  174. #endregion
  175. //调用处理冗余时间逻辑方法
  176. $res = $this->redundantTime($order_list, $middleTime, $min_route_arr, $array_start, $array_end, $road1, $road2, $prodID, $time_on_the_way, $should_be_count, $is_xiecheng);
  177. if ($res) {
  178. return $res;
  179. } else {
  180. return false;
  181. }
  182. }
  183. /**
  184. * 处理冗余时间逻辑
  185. * @param $order_list
  186. * @param $middleTime
  187. * @param $min_route_arr
  188. * @param $start_arr
  189. * @param $end_arr
  190. * @return array|bool
  191. */
  192. function redundantTime($order_list, $middleTime, $min_route_arr, $start_arr, $end_arr, $road1, $road2, $prodID, $time_on_the_way, $should_be_count, $is_xiecheng)
  193. {
  194. writeLog("heyikai_startarr:".json_encode($start_arr));
  195. writeLog("heyikai_endarr:".json_encode($end_arr));
  196. $xiecheng_order = $is_xiecheng;//是否是携程的订单 1是0否
  197. $redundantTime_count = $should_be_count;
  198. $go_where = $prodID;//去哪儿
  199. $point_a = $road1;//关键点a
  200. $point_b = $road2;//关键点b
  201. $run_time = ceil(strtotime($time_on_the_way) / 60);//到达关键点时间
  202. $go_time_arr = array();//接客时间数组
  203. $send_time_arr = array();//送客时间数组
  204. $every_one_go_cost_tiem_arr = array();//每位乘客的接客耗时
  205. $every_one_send_cost_tiem_arr = array();//每位乘客的接客耗时
  206. $can_seat_in = true;
  207. $info = "";
  208. $min_route_num = count($min_route_arr);
  209. $order_count = count($order_list);//订单号
  210. $total_cost_time = 0;
  211. for ($i = 0; $i < $min_route_num - 1; $i++) {
  212. //遍历路线数组
  213. if ($i < $order_count - 1) {
  214. $total_cost_time = $total_cost_time + $start_arr[$min_route_arr[$i]][$min_route_arr[$i + 1]];
  215. } elseif ($i == $order_count) {
  216. $total_cost_time = $total_cost_time + $middleTime + $end_arr[$min_route_arr[$i]][$min_route_arr[$i + 1]];
  217. }
  218. if ($i > $order_count) {
  219. $total_cost_time = $total_cost_time + $end_arr[$min_route_arr[$i]][$min_route_arr[$i + 1]];
  220. }
  221. }
  222. if ($total_cost_time > 270) {
  223. if ($xiecheng_order) {
  224. $can_seat_in = true;
  225. $info = "总时间超过270分钟,携程订单为真";
  226. } else {
  227. $can_seat_in = false;
  228. $info = "总时间超过270分钟";
  229. }
  230. }
  231. for ($jj = 0; $jj < $order_count; $jj++) {
  232. $ry_cost_time = 0;
  233. for ($j = $jj; $j < $min_route_num - 1; $j++) {
  234. if ($j < $order_count - 1) {
  235. $ry_cost_time = $ry_cost_time + $start_arr[$min_route_arr[$j]][$min_route_arr[$j + 1]];
  236. } elseif (($j + 1) == $order_count) {
  237. $ry_cost_time = $ry_cost_time + $middleTime;
  238. }
  239. if ($j >= $order_count) {
  240. $ry_cost_time = $ry_cost_time + $end_arr[$min_route_arr[$j]][$min_route_arr[$j + 1]];
  241. }
  242. if ($min_route_arr[$jj] == $min_route_arr[$j + 1]) {
  243. if ($ry_cost_time > 30) {
  244. if (($order_list[$jj]["startx_y"] == "32.116682,118.784105" && $order_list[$jj]["endx_y"] == "32.011714,120.894448") || ($order_list[$jj]["startx_y"] == "32.011714,120.894448" && $order_list[$jj]["endx_y"] == "32.116682,118.784105")) {
  245. //这点是携程点
  246. $can_seat_in = true;
  247. // $info = "冗余时间超过30分钟";
  248. // /*break;保证数据完整*/
  249. } else {
  250. //不是携程点
  251. $can_seat_in = false;
  252. // $info = "冗余时间超过30分钟";
  253. // /*break;保证数据完整*/
  254. }
  255. // if ($xiecheng_order) {
  256. // $can_seat_in = true;
  257. // $info = "冗余时间超过30分钟";
  258. // /*break;保证数据完整*/
  259. // }else{ $can_seat_in = false;
  260. // $info = "冗余时间超过30分钟";
  261. // /*break;保证数据完整*/
  262. // }
  263. }
  264. }
  265. }
  266. }
  267. if (!$redundantTime_count) {
  268. //特殊情况 不算冗余和时长
  269. $can_seat_in = true;
  270. }
  271. if ($can_seat_in) {
  272. $can_seat_in_orderid_list = array();
  273. for ($i = 0; $i < $min_route_num; $i++) {
  274. $can_seat_in_orderid_list[$i] = $order_list[$min_route_arr[$i] - 1]["order_id"];
  275. }
  276. //$min_route_arr;行车路线
  277. ////$every_one_go_cost_tiem_arr=array();//每位乘客的接客耗时
  278. //$every_one_send_cost_tiem_arr=array();//每位乘客的接客耗时
  279. for ($i = 0; $i < $order_count; $i++) {
  280. //计算每个订单接人的耗时
  281. $every_one_go_cost_tiem_arr[$i] = 0;
  282. for ($ii = $i; $ii < $order_count; $ii++) {
  283. if ($ii == ($order_count - 1)) {
  284. $every_one_go_cost_tiem_arr[$i] = $every_one_go_cost_tiem_arr[$i] + 0;
  285. } else {
  286. $every_one_go_cost_tiem_arr[$i] = $every_one_go_cost_tiem_arr[$i] + $start_arr[$min_route_arr[$ii]][$min_route_arr[$ii + 1]];
  287. }
  288. }
  289. }
  290. for ($i = $min_route_num - 1; $i > ($order_count - 1); $i--) {
  291. $every_one_send_cost_tiem_arr[$i - $order_count] = 0;
  292. for ($ii = $i; $ii > ($order_count - 1); $ii--) {
  293. if ($ii == $order_count) {
  294. $every_one_send_cost_tiem_arr[$i - $order_count] = $every_one_send_cost_tiem_arr[$i - $order_count] + 0;
  295. } else {
  296. $every_one_send_cost_tiem_arr[$i - $order_count] = $every_one_send_cost_tiem_arr[$i - $order_count] + $end_arr[$min_route_arr[$ii - 1]][$min_route_arr[$ii]];
  297. }
  298. }
  299. }
  300. $last_go = $min_route_arr[$order_count - 1];//最后一个接
  301. $frist_send = $min_route_arr[$order_count];//第一个送
  302. $last_go_where = $order_list[$last_go - 1]["startx_y"];
  303. $frist_send_where = $order_list[$frist_send - 1]["endx_y"];
  304. $time1 = commonUtils::baiduShortTime($last_go_where, $point_a["location"]) + commonUtils::baiduShortTime($point_a["location"], $frist_send_where);
  305. $time2 = commonUtils::baiduShortTime($last_go_where, $point_b["location"]) + commonUtils::baiduShortTime($point_b["location"], $frist_send_where);
  306. // $every_one_go_cost_tiem_arr=array();//每位乘客的接客耗时
  307. ////$every_one_send_cost_tiem_arr=array();//每位乘客的接客耗时
  308. if ($xiecheng_order) {
  309. //携程订单
  310. $time_xiecheng = ceil(strtotime($time_on_the_way) / 60);//到携程的时间分钟
  311. //$every_one_go_cost_tiem_arr 接人耗时数组
  312. //$every_one_send_cost_tiem_arr 送人耗时数组
  313. //$min_route_arr 行车队列 1423 1324
  314. //$min_route_num 最短路径数组长度
  315. writeLog("heyikai_到携程时间:".json_encode($time_xiecheng));
  316. writeLog("heyikai_接人耗时:".json_encode($every_one_go_cost_tiem_arr));
  317. writeLog("heyikai_送人耗时:".json_encode($every_one_send_cost_tiem_arr));
  318. $xiecheng_time_array = array();//携程时间数组
  319. $xiecheng_number = 0;//记录第一个携程订单位置
  320. for ($temp_ii = 0; $temp_ii < $order_count; $temp_ii++) {
  321. if (($order_list[$temp_ii]["startx_y"] == "32.116682,118.784105" && $order_list[$temp_ii]["endx_y"] == "32.011714,120.894448") || ($order_list[$temp_ii]["startx_y"] == "32.011714,120.894448" && $order_list[$temp_ii]["endx_y"] == "32.116682,118.784105")) {
  322. $xiecheng_number = $temp_ii;//找到第一个携程订单
  323. }
  324. }
  325. $xiecheng_time_array[$xiecheng_number] = $time_xiecheng;//固定到携程时间
  326. for ($temp_f = ($xiecheng_number - 1); $temp_f >= 0; $temp_f--) {
  327. //计算携程前一点和以前的时间
  328. $xiecheng_time_array[$temp_f] = $xiecheng_time_array[($temp_f + 1)] - $start_arr[$min_route_arr[$temp_f]][$min_route_arr[($temp_f + 1)]];
  329. }
  330. for ($temp_e = ($xiecheng_number + 1); $temp_e < $min_route_num; $temp_e++) {
  331. //计算携程后一点和以后的时间
  332. $xiecheng_time_array[$temp_e] = $xiecheng_time_array[($temp_e - 1)] + $start_arr[$min_route_arr[$temp_e - 1]][$min_route_arr[($temp_e)]];
  333. }
  334. //计算中间时间
  335. $during_time = commonUtils::baiduShortTime($order_list[$min_route_arr[$order_count - 1]-1]["startx_y"], $order_list[$min_route_arr[$order_count]-1]["endx_y"]);
  336. //确定第一个终点的时间
  337. writeLog("heyikai_中间时间:".json_encode($during_time));
  338. writeLog("heyikai_中间起点:".json_encode($order_list[$min_route_arr[$order_count - 1]-1]["startx_y"]));
  339. writeLog("heyikai_中间终点:".json_encode( $order_list[$min_route_arr[$order_count]-1]["endx_y"]));
  340. $xiecheng_time_array[$order_count] = $xiecheng_time_array[$order_count - 1] + $during_time;
  341. for ($temp_temp_end = ($order_count + 1); $temp_temp_end < $min_route_num; $temp_temp_end++) {
  342. //计算第一个点以后的时间
  343. $xiecheng_time_array[$temp_temp_end] = $xiecheng_time_array[($temp_temp_end - 1)] + $end_arr[$min_route_arr[($temp_temp_end - 1)]][$min_route_arr[$temp_temp_end]];
  344. }
  345. $final_xiecheng = array();//携程最终返回
  346. for ($temp_xiecheng_i = 0; $temp_xiecheng_i < $min_route_num; $temp_xiecheng_i++) {
  347. $final_xiecheng[$temp_xiecheng_i]["time"] = date("Y-m-d H:i", $xiecheng_time_array[$temp_xiecheng_i]*60);
  348. $final_xiecheng[$temp_xiecheng_i]["order_id"] = $order_list[$min_route_arr[$temp_xiecheng_i] - 1]["order_id"];
  349. }
  350. writeLog("heyikai:".json_encode($final_xiecheng));
  351. return $final_xiecheng;
  352. } else {
  353. //不是携程订单
  354. if ($go_where == $this->nj_nt_prod_id) {
  355. //南京去南通方向
  356. if ($time1 > $time2) {
  357. //选point_b
  358. $temp_time = $run_time - $point_b["nt"];
  359. $temp_time_go = $temp_time - commonUtils::baiduShortTime($last_go_where, $point_b["location"]);
  360. for ($i = 0; $i < $order_count; $i++) {
  361. $every_one_go_cost_tiem_arr[$i] = $temp_time_go - $every_one_go_cost_tiem_arr[$i];
  362. }
  363. $temp_time_send = $temp_time + commonUtils::baiduShortTime($point_b["location"], $frist_send_where);
  364. for ($i = 0; $i < $order_count; $i++) {
  365. $every_one_send_cost_tiem_arr[$i] = $temp_time_send + $every_one_send_cost_tiem_arr[$i];
  366. }
  367. } else {
  368. //选point_a
  369. $temp_time = $run_time - $point_a["nt"];
  370. $temp_time_go = $temp_time - commonUtils::baiduShortTime($last_go_where, $point_a["location"]);
  371. for ($i = 0; $i < $order_count; $i++) {
  372. $every_one_go_cost_tiem_arr[$i] = $temp_time_go - $every_one_go_cost_tiem_arr[$i];
  373. }
  374. $temp_time_send = $temp_time + commonUtils::baiduShortTime($point_a["location"], $frist_send_where);
  375. for ($i = 0; $i < $order_count; $i++) {
  376. $every_one_send_cost_tiem_arr[$i] = $temp_time_send + $every_one_send_cost_tiem_arr[$i];
  377. }
  378. }
  379. } elseif ($go_where == $this->nt_nj_prod_id) {
  380. //南通去南京方向
  381. if ($time1 > $time2) {
  382. //选point_b
  383. $temp_time = $run_time - $point_b["nj"];
  384. $temp_time_go = $temp_time - commonUtils::baiduShortTime($last_go_where, $point_b["location"]);
  385. for ($i = 0; $i < $order_count; $i++) {
  386. $every_one_go_cost_tiem_arr[$i] = $temp_time_go - $every_one_go_cost_tiem_arr[$i];
  387. }
  388. $temp_time_send = $temp_time + commonUtils::baiduShortTime($point_b["location"], $frist_send_where);
  389. for ($i = 0; $i < $order_count; $i++) {
  390. $every_one_send_cost_tiem_arr[$i] = $temp_time_send + $every_one_send_cost_tiem_arr[$i];
  391. }
  392. } else {
  393. //选point_a
  394. $temp_time = $run_time - $point_a["nj"];
  395. $temp_time_go = $temp_time - commonUtils::baiduShortTime($last_go_where, $point_a["location"]);
  396. for ($i = 0; $i < $order_count; $i++) {
  397. $every_one_go_cost_tiem_arr[$i] = $temp_time_go - $every_one_go_cost_tiem_arr[$i];
  398. }
  399. $temp_time_send = $temp_time + commonUtils::baiduShortTime($point_a["location"], $frist_send_where);
  400. for ($i = 0; $i < $order_count; $i++) {
  401. $every_one_send_cost_tiem_arr[$i] = $temp_time_send + $every_one_send_cost_tiem_arr[$i];
  402. }
  403. }
  404. } else {
  405. return false;
  406. }
  407. for ($i = 0; $i < $order_count; $i++) {
  408. $every_one_go_cost_tiem_arr[$i] = date("Y-m-d H:i", $every_one_go_cost_tiem_arr[$i] * 60);
  409. }
  410. for ($i = 0; $i < $order_count; $i++) {
  411. $every_one_send_cost_tiem_arr[$i] = date("Y-m-d H:i", $every_one_send_cost_tiem_arr[$i] * 60);
  412. }
  413. $final_result = array();
  414. for ($i = 0; $i < $min_route_num; $i++) {
  415. if ($i < $order_count) {
  416. //接人
  417. $final_result[$i]["order_id"] = $can_seat_in_orderid_list[$i];
  418. $final_result[$i]["time"] = $every_one_go_cost_tiem_arr[$i];
  419. } else {
  420. //送人
  421. $final_result[$i]["order_id"] = $can_seat_in_orderid_list[$i];
  422. $final_result[$i]["time"] = $every_one_send_cost_tiem_arr[$i - $order_count];
  423. }
  424. }
  425. return $final_result;
  426. }
  427. } else {
  428. return false;
  429. }
  430. }
  431. }
  432. /*
  433. * 勿删
  434. * $road1 = array("location" => "32.135283,120.230875,", "nt" => "77", "nj" => "129");//高速路1 广陵枢纽与沪陕高速公路交叉口(地址:江苏省泰州市泰兴市)to:高速路标记点到南通的最短时间 go:高速路标记点到南京的最短时间
  435. $road2 = array("location" => "31.749506,120.140182", "nt" => "89", "nj" => "116");//高速路2 江苏省常州市武进区横林枢纽立交桥
  436. */
  437. //测试
  438. /*$test = new test();
  439. //传入的订单数组
  440. $order_list = array(
  441. 0 => array("order_id" => 10001, "num" => 2, "startx_y" => '32.037596,118.769413', "endx_y" => '31.978861,120.915932'),
  442. 1 => array("order_id" => 10002, "num" => 2, "startx_y" => '32.04072,118.753993', "endx_y" => '32.01604,120.863561'),
  443. 2 => array("order_id" => 10003, "num" => 1, "startx_y" => '32.034166,118.746134', "endx_y" => '31.98495,120.923472')
  444. );
  445. //新加入订单信息
  446. $new_order = array("order_id" => "10004", "num" => "1", "startx_y" => "32.021622,118.728496", "endx_y" => "32.064859,120.815552");
  447. //起点时间矩阵
  448. $array_start = array(
  449. 1 => array(1 => 0, 2 => 7, 3 => 9, 4 => 11),
  450. 2 => array(1 => 6, 2 => 0, 3 => 8, 4 => 2),
  451. 3 => array(1 => 7, 2 => 10, 3 => 0, 4 => 25),
  452. 4 => array(1 => 7, 2 => 14, 3 => 10, 4 => 0)
  453. );
  454. //终点时间矩阵
  455. $array_end = array(
  456. 1 => array(1 => 0, 2 => 5, 3 => 11, 4 => 5),
  457. 2 => array(1 => 3, 2 => 0, 3 => 8, 4 => 20),
  458. 3 => array(1 => 11, 2 => 5, 3 => 0, 4 => 12),
  459. 4 => array(1 => 15, 2 => 8, 3 => 11, 4 => 0)
  460. );
  461. $res = $test->Control($order_list, $new_order, $array_start, $array_end);
  462. var_dump($res);*/