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.
 
 
 
 
 
 

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