Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

491 lignes
26 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. $new_order_is_xiecheng=false;//新订单是否是携程 1是0否
  197. $xiecheng_order = $is_xiecheng;//是否是携程的订单 1是0否
  198. $redundantTime_count = $should_be_count;
  199. $go_where = $prodID;//去哪儿
  200. $point_a = $road1;//关键点a
  201. $point_b = $road2;//关键点b
  202. $run_time = ceil(strtotime($time_on_the_way) / 60);//到达关键点时间
  203. $go_time_arr = array();//接客时间数组
  204. $send_time_arr = array();//送客时间数组
  205. $every_one_go_cost_tiem_arr = array();//每位乘客的接客耗时
  206. $every_one_send_cost_tiem_arr = array();//每位乘客的接客耗时
  207. $can_seat_in = true;
  208. $info = "";
  209. $min_route_num = count($min_route_arr);
  210. $order_count = count($order_list);//订单号
  211. $total_cost_time = 0;
  212. if (($order_list[$order_count-1]["startx_y"] == "32.116682,118.784105" && $order_list[$order_count-1]["endx_y"] == "32.011714,120.894448") || ($order_list[$order_count-1]["startx_y"] == "32.011714,120.894448" && $order_list[$order_count-1]["endx_y"] == "32.116682,118.784105")) {
  213. $new_order_is_xiecheng=true;//如果最后一个订单是携程,变为真
  214. }
  215. writeLog("贺奕凯_新订单是否是携程:".json_encode($new_order_is_xiecheng));
  216. for ($i = 0; $i < $min_route_num - 1; $i++) {
  217. //遍历路线数组
  218. if ($i < $order_count - 1) {
  219. $total_cost_time = $total_cost_time + $start_arr[$min_route_arr[$i]][$min_route_arr[$i + 1]];
  220. } elseif ($i == $order_count) {
  221. $total_cost_time = $total_cost_time + $middleTime + $end_arr[$min_route_arr[$i]][$min_route_arr[$i + 1]];
  222. }
  223. if ($i > $order_count) {
  224. $total_cost_time = $total_cost_time + $end_arr[$min_route_arr[$i]][$min_route_arr[$i + 1]];
  225. }
  226. }
  227. if ($total_cost_time > 270) {
  228. if ($xiecheng_order) {
  229. $can_seat_in = true;
  230. $info = "总时间超过270分钟,携程订单为真";
  231. } else {
  232. $can_seat_in = false;
  233. $info = "总时间超过270分钟";
  234. }
  235. }
  236. for ($jj = 0; $jj < $order_count; $jj++) {
  237. $ry_cost_time = 0;
  238. for ($j = $jj; $j < $min_route_num - 1; $j++) {
  239. if ($j < $order_count - 1) {
  240. $ry_cost_time = $ry_cost_time + $start_arr[$min_route_arr[$j]][$min_route_arr[$j + 1]];
  241. } elseif (($j + 1) == $order_count) {
  242. $ry_cost_time = $ry_cost_time + $middleTime;
  243. }
  244. if ($j >= $order_count) {
  245. $ry_cost_time = $ry_cost_time + $end_arr[$min_route_arr[$j]][$min_route_arr[$j + 1]];
  246. }
  247. if ($min_route_arr[$jj] == $min_route_arr[$j + 1]) {
  248. if ($ry_cost_time > 30) {
  249. 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")) {
  250. //这点是携程点
  251. $can_seat_in = true;
  252. // $info = "冗余时间超过30分钟";
  253. // /*break;保证数据完整*/
  254. } else {
  255. //不是携程点
  256. if ($new_order_is_xiecheng) {
  257. //新订单是携程的
  258. $can_seat_in = true;
  259. } else {
  260. //新订单不是携程的
  261. $can_seat_in = false;
  262. }
  263. // $info = "冗余时间超过30分钟";
  264. // /*break;保证数据完整*/
  265. }
  266. // if ($xiecheng_order) {
  267. // $can_seat_in = true;
  268. // $info = "冗余时间超过30分钟";
  269. // /*break;保证数据完整*/
  270. // }else{ $can_seat_in = false;
  271. // $info = "冗余时间超过30分钟";
  272. // /*break;保证数据完整*/
  273. // }
  274. }
  275. }
  276. }
  277. }
  278. if (!$redundantTime_count) {
  279. //特殊情况 不算冗余和时长
  280. $can_seat_in = true;
  281. }
  282. if ($can_seat_in) {
  283. $can_seat_in_orderid_list = array();
  284. for ($i = 0; $i < $min_route_num; $i++) {
  285. $can_seat_in_orderid_list[$i] = $order_list[$min_route_arr[$i] - 1]["order_id"];
  286. }
  287. //$min_route_arr;行车路线
  288. ////$every_one_go_cost_tiem_arr=array();//每位乘客的接客耗时
  289. //$every_one_send_cost_tiem_arr=array();//每位乘客的接客耗时
  290. for ($i = 0; $i < $order_count; $i++) {
  291. //计算每个订单接人的耗时
  292. $every_one_go_cost_tiem_arr[$i] = 0;
  293. for ($ii = $i; $ii < $order_count; $ii++) {
  294. if ($ii == ($order_count - 1)) {
  295. $every_one_go_cost_tiem_arr[$i] = $every_one_go_cost_tiem_arr[$i] + 0;
  296. } else {
  297. $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]];
  298. }
  299. }
  300. }
  301. for ($i = $min_route_num - 1; $i > ($order_count - 1); $i--) {
  302. $every_one_send_cost_tiem_arr[$i - $order_count] = 0;
  303. for ($ii = $i; $ii > ($order_count - 1); $ii--) {
  304. if ($ii == $order_count) {
  305. $every_one_send_cost_tiem_arr[$i - $order_count] = $every_one_send_cost_tiem_arr[$i - $order_count] + 0;
  306. } else {
  307. $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]];
  308. }
  309. }
  310. }
  311. $last_go = $min_route_arr[$order_count - 1];//最后一个接
  312. $frist_send = $min_route_arr[$order_count];//第一个送
  313. $last_go_where = $order_list[$last_go - 1]["startx_y"];
  314. $frist_send_where = $order_list[$frist_send - 1]["endx_y"];
  315. $time1 = commonUtils::baiduShortTime($last_go_where, $point_a["location"]) + commonUtils::baiduShortTime($point_a["location"], $frist_send_where);
  316. $time2 = commonUtils::baiduShortTime($last_go_where, $point_b["location"]) + commonUtils::baiduShortTime($point_b["location"], $frist_send_where);
  317. // $every_one_go_cost_tiem_arr=array();//每位乘客的接客耗时
  318. ////$every_one_send_cost_tiem_arr=array();//每位乘客的接客耗时
  319. if ($xiecheng_order) {
  320. //携程订单
  321. $time_xiecheng = ceil(strtotime($time_on_the_way) / 60);//到携程的时间分钟
  322. //$every_one_go_cost_tiem_arr 接人耗时数组
  323. //$every_one_send_cost_tiem_arr 送人耗时数组
  324. //$min_route_arr 行车队列 1423 1324
  325. //$min_route_num 最短路径数组长度
  326. writeLog("heyikai_到携程时间:".json_encode($time_xiecheng));
  327. writeLog("heyikai_接人耗时:".json_encode($every_one_go_cost_tiem_arr));
  328. writeLog("heyikai_送人耗时:".json_encode($every_one_send_cost_tiem_arr));
  329. $xiecheng_time_array = array();//携程时间数组
  330. $xiecheng_number = 0;//记录第一个携程订单位置
  331. for ($temp_ii = 0; $temp_ii < $order_count; $temp_ii++) {
  332. 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")) {
  333. $xiecheng_number = $temp_ii;//找到第一个携程订单
  334. writeLog("heyikai_第一个携程订单位置:".json_encode($xiecheng_number));
  335. break;
  336. }
  337. }
  338. $xiecheng_time_array[$xiecheng_number] = $time_xiecheng;//固定到携程时间
  339. writeLog("heyikai_已经固定到携程订单时间:".json_encode($xiecheng_time_array[$xiecheng_number]));
  340. for ($temp_f = ($xiecheng_number - 1); $temp_f >= 0; $temp_f--) {
  341. //计算携程前一点和以前的时间
  342. $xiecheng_time_array[$temp_f] = $xiecheng_time_array[($temp_f + 1)] - $start_arr[$min_route_arr[$temp_f]][$min_route_arr[($temp_f + 1)]];
  343. }
  344. for ($temp_e = ($xiecheng_number + 1); $temp_e < $min_route_num; $temp_e++) {
  345. //计算携程后一点和以后的时间
  346. $xiecheng_time_array[$temp_e] = $xiecheng_time_array[($temp_e - 1)] + $start_arr[$min_route_arr[$temp_e - 1]][$min_route_arr[($temp_e)]];
  347. }
  348. //计算中间时间
  349. $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"]);
  350. //确定第一个终点的时间
  351. writeLog("heyikai_中间时间:".json_encode($during_time));
  352. writeLog("heyikai_中间起点:".json_encode($order_list[$min_route_arr[$order_count - 1]-1]["startx_y"]));
  353. writeLog("heyikai_中间终点:".json_encode( $order_list[$min_route_arr[$order_count]-1]["endx_y"]));
  354. $xiecheng_time_array[$order_count] = $xiecheng_time_array[$order_count - 1] + $during_time;
  355. for ($temp_temp_end = ($order_count + 1); $temp_temp_end < $min_route_num; $temp_temp_end++) {
  356. //计算第一个点以后的时间
  357. $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]];
  358. }
  359. $final_xiecheng = array();//携程最终返回
  360. for ($temp_xiecheng_i = 0; $temp_xiecheng_i < $min_route_num; $temp_xiecheng_i++) {
  361. $final_xiecheng[$temp_xiecheng_i]["time"] = date("Y-m-d H:i", $xiecheng_time_array[$temp_xiecheng_i]*60);
  362. $final_xiecheng[$temp_xiecheng_i]["order_id"] = $order_list[$min_route_arr[$temp_xiecheng_i] - 1]["order_id"];
  363. }
  364. writeLog("heyikai:".json_encode($final_xiecheng));
  365. return $final_xiecheng;
  366. } else {
  367. //不是携程订单
  368. if ($go_where == $this->nj_nt_prod_id) {
  369. //南京去南通方向
  370. if ($time1 > $time2) {
  371. //选point_b
  372. $temp_time = $run_time - $point_b["nt"];
  373. $temp_time_go = $temp_time - commonUtils::baiduShortTime($last_go_where, $point_b["location"]);
  374. for ($i = 0; $i < $order_count; $i++) {
  375. $every_one_go_cost_tiem_arr[$i] = $temp_time_go - $every_one_go_cost_tiem_arr[$i];
  376. }
  377. $temp_time_send = $temp_time + commonUtils::baiduShortTime($point_b["location"], $frist_send_where);
  378. for ($i = 0; $i < $order_count; $i++) {
  379. $every_one_send_cost_tiem_arr[$i] = $temp_time_send + $every_one_send_cost_tiem_arr[$i];
  380. }
  381. } else {
  382. //选point_a
  383. $temp_time = $run_time - $point_a["nt"];
  384. $temp_time_go = $temp_time - commonUtils::baiduShortTime($last_go_where, $point_a["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_a["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. }
  393. } elseif ($go_where == $this->nt_nj_prod_id) {
  394. //南通去南京方向
  395. if ($time1 > $time2) {
  396. //选point_b
  397. $temp_time = $run_time - $point_b["nj"];
  398. $temp_time_go = $temp_time - commonUtils::baiduShortTime($last_go_where, $point_b["location"]);
  399. for ($i = 0; $i < $order_count; $i++) {
  400. $every_one_go_cost_tiem_arr[$i] = $temp_time_go - $every_one_go_cost_tiem_arr[$i];
  401. }
  402. $temp_time_send = $temp_time + commonUtils::baiduShortTime($point_b["location"], $frist_send_where);
  403. for ($i = 0; $i < $order_count; $i++) {
  404. $every_one_send_cost_tiem_arr[$i] = $temp_time_send + $every_one_send_cost_tiem_arr[$i];
  405. }
  406. } else {
  407. //选point_a
  408. $temp_time = $run_time - $point_a["nj"];
  409. $temp_time_go = $temp_time - commonUtils::baiduShortTime($last_go_where, $point_a["location"]);
  410. for ($i = 0; $i < $order_count; $i++) {
  411. $every_one_go_cost_tiem_arr[$i] = $temp_time_go - $every_one_go_cost_tiem_arr[$i];
  412. }
  413. $temp_time_send = $temp_time + commonUtils::baiduShortTime($point_a["location"], $frist_send_where);
  414. for ($i = 0; $i < $order_count; $i++) {
  415. $every_one_send_cost_tiem_arr[$i] = $temp_time_send + $every_one_send_cost_tiem_arr[$i];
  416. }
  417. }
  418. } else {
  419. return false;
  420. }
  421. for ($i = 0; $i < $order_count; $i++) {
  422. $every_one_go_cost_tiem_arr[$i] = date("Y-m-d H:i", $every_one_go_cost_tiem_arr[$i] * 60);
  423. }
  424. for ($i = 0; $i < $order_count; $i++) {
  425. $every_one_send_cost_tiem_arr[$i] = date("Y-m-d H:i", $every_one_send_cost_tiem_arr[$i] * 60);
  426. }
  427. $final_result = array();
  428. for ($i = 0; $i < $min_route_num; $i++) {
  429. if ($i < $order_count) {
  430. //接人
  431. $final_result[$i]["order_id"] = $can_seat_in_orderid_list[$i];
  432. $final_result[$i]["time"] = $every_one_go_cost_tiem_arr[$i];
  433. } else {
  434. //送人
  435. $final_result[$i]["order_id"] = $can_seat_in_orderid_list[$i];
  436. $final_result[$i]["time"] = $every_one_send_cost_tiem_arr[$i - $order_count];
  437. }
  438. }
  439. return $final_result;
  440. }
  441. } else {
  442. return false;
  443. }
  444. }
  445. }
  446. /*
  447. * 勿删
  448. * $road1 = array("location" => "32.135283,120.230875,", "nt" => "77", "nj" => "129");//高速路1 广陵枢纽与沪陕高速公路交叉口(地址:江苏省泰州市泰兴市)to:高速路标记点到南通的最短时间 go:高速路标记点到南京的最短时间
  449. $road2 = array("location" => "31.749506,120.140182", "nt" => "89", "nj" => "116");//高速路2 江苏省常州市武进区横林枢纽立交桥
  450. */
  451. //测试
  452. /*$test = new test();
  453. //传入的订单数组
  454. $order_list = array(
  455. 0 => array("order_id" => 10001, "num" => 2, "startx_y" => '32.037596,118.769413', "endx_y" => '31.978861,120.915932'),
  456. 1 => array("order_id" => 10002, "num" => 2, "startx_y" => '32.04072,118.753993', "endx_y" => '32.01604,120.863561'),
  457. 2 => array("order_id" => 10003, "num" => 1, "startx_y" => '32.034166,118.746134', "endx_y" => '31.98495,120.923472')
  458. );
  459. //新加入订单信息
  460. $new_order = array("order_id" => "10004", "num" => "1", "startx_y" => "32.021622,118.728496", "endx_y" => "32.064859,120.815552");
  461. //起点时间矩阵
  462. $array_start = array(
  463. 1 => array(1 => 0, 2 => 7, 3 => 9, 4 => 11),
  464. 2 => array(1 => 6, 2 => 0, 3 => 8, 4 => 2),
  465. 3 => array(1 => 7, 2 => 10, 3 => 0, 4 => 25),
  466. 4 => array(1 => 7, 2 => 14, 3 => 10, 4 => 0)
  467. );
  468. //终点时间矩阵
  469. $array_end = array(
  470. 1 => array(1 => 0, 2 => 5, 3 => 11, 4 => 5),
  471. 2 => array(1 => 3, 2 => 0, 3 => 8, 4 => 20),
  472. 3 => array(1 => 11, 2 => 5, 3 => 0, 4 => 12),
  473. 4 => array(1 => 15, 2 => 8, 3 => 11, 4 => 0)
  474. );
  475. $res = $test->Control($order_list, $new_order, $array_start, $array_end);
  476. var_dump($res);*/