Browse Source

2021 0301, wangkang parkspace

wk 4 năm trước cách đây
mục cha
commit
4efdfff07e

+ 159 - 73
parkspace_allocation/parkspace_manager.cpp

@@ -238,11 +238,12 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 	 * P=i%6
 	 * S=15*d-(j%15)*(2*d-1)+[6*d-(i%6)(2*d-1)]*W    W>1
 	 */
-	int time_min=0;
+	float time_min=0;
 	int parkingspace_index_id=-1;
 	//判断是否是左半库
-	if ( terminal_id<=3 && terminal_id>=0)
+	if ( terminal_id<=3 && terminal_id>=0 )
 	{
+		LOG(INFO) << " 左半库 车牌号:"<<car_info.license()<<"  车高:"<<car_info.car_height()<< this;
 		//如果是小车 (低于1.55米属于小车)
 		if ( car_info.car_height() <= MIN_CAR_HIGH )
 		{
@@ -273,8 +274,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 					}
 					else
 					{
-						time_min = time < time_min ? time : time_min;
-						parkingspace_index_id = i;
+						if ( time < time_min )
+						{
+							time_min = time;
+							parkingspace_index_id = i;
+						}
 					}
 				}
 				++i;
@@ -285,6 +289,10 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 				parkspace_info.CopyFrom(all_min_parkspace_data.parkspace_info(parkingspace_index_id));
 				return Error_code::SUCCESS;
 			}
+			else
+			{
+				LOG(INFO) << " 小车车位未找到合适车位 "<< this;
+			}
 		}
 		if ( car_info.car_height() <= MID_CAR_HIGH )
 		{
@@ -306,7 +314,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 				{
 				    //只需计算端口到车位的距离
 					// 三楼中型用时=| 目标车位到电梯的距离 - 终端到电梯的距离 | / 中跑车速度
-					int t_min=abs( i%15*all_mid_parkspace_data.parkspace_info(i).parkingspace_width()-terminal_id%6*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
+					float t_min=abs( room_id%15*all_mid_parkspace_data.parkspace_info(i).parkingspace_width()-(terminal_id%6+2)*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
 					if ( time_min == 0 )
 					{
 						time_min=t_min;
@@ -314,8 +322,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 					}
 					else
 					{
-						time_min=t_min<time_min?t_min:time_min;
-						parkingspace_index_id=i;
+						if ( t_min<time_min )
+						{
+							time_min=t_min;
+							parkingspace_index_id=i;
+						}
 					}
 				}
 				//如果是六楼的中型车位
@@ -323,7 +334,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 					&& all_mid_parkspace_data.parkspace_info(i).parkingspace_status() == message::Parkspace_status::eParkspace_empty )
 				{
 					//用时=目标终端到电梯口的距离/中跑车速度+(目标车位楼层-2)*楼层高度/电梯速度+电梯口到目标车位的距离/中跑车速度
-					float time=terminal_id%6*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
+					float time=(terminal_id%6+2)*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
 								(all_mid_parkspace_data.parkspace_info(i).parkingspace_floor_id()-2)*all_mid_parkspace_data.parkspace_info(i).parkingspace_height()/THE_ELEVATOR_SPEED + ELEVATOR_MOVEMENT_TIME +
 								all_mid_parkspace_data.parkspace_info(i).parkingspace_index_id()%15*all_mid_parkspace_data.parkspace_info(i).parkingspace_width()/MEDIUM_CAR_SPEED + UPSTAIRS_SPORTS_TIME;
 					if ( time_min == 0 )
@@ -334,8 +345,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 					}
 					else
 					{
-						time_min=time<time_min?time:time_min;
-						parkingspace_index_id=i;
+						if ( time<time_min )
+						{
+							time_min=time;
+							parkingspace_index_id=i;
+						}
 					}
 				}
 				++i;
@@ -346,6 +360,10 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 				parkspace_info.CopyFrom(all_mid_parkspace_data.parkspace_info(parkingspace_index_id));
 				return Error_code::SUCCESS;
 			}
+			else
+			{
+				LOG(INFO) << " 中车车位未找到合适车位 "<< this;
+			}
 		}
 		if ( car_info.car_height() <= BIG_CAR_HIGH )
 		{
@@ -357,6 +375,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 			{
 				return t_error;
 			}
+			std::cout << " all_big_parkspace_data.parkspace_info_size() = " << all_big_parkspace_data.parkspace_info_size() << std::endl;
 			int i=0;
 			while(i<all_big_parkspace_data.parkspace_info_size())
 			{
@@ -369,7 +388,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 					if ( all_big_parkspace_data.parkspace_info(i).parkingspace_floor_id() == 2 )
 					{
 						// 二楼用时=| 目标车位到电梯的距离 - 终端到电梯的距离 | / 中跑车速度
-						int t_min=abs( i%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width()-terminal_id%6*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
+						float t_min=abs( room_id%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width() - (terminal_id%6+2)*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
 						if ( time_min == 0 )
 						{
 							time_min=t_min;
@@ -377,14 +396,17 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 						}
 						else
 						{
-							time_min=t_min<time_min?t_min:time_min;
-							parkingspace_index_id=i;
+							if ( t_min<time_min )
+							{
+								time_min=t_min;
+								parkingspace_index_id=i;
+							}
 						}
 					}
 					else
 					{
 						//用时=目标终端到电梯口的距离/中跑车速度+(目标车位楼层-2)*楼层高度/电梯速度+电梯口到目标车位的距离/中跑车速度
-						float time=terminal_id%6*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
+						float time=(terminal_id%6+2)*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
 								   (all_big_parkspace_data.parkspace_info(i).parkingspace_floor_id()-2)*all_big_parkspace_data.parkspace_info(i).parkingspace_height()/THE_ELEVATOR_SPEED + ELEVATOR_MOVEMENT_TIME +
 								   all_big_parkspace_data.parkspace_info(i).parkingspace_index_id()%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width()/MEDIUM_CAR_SPEED + UPSTAIRS_SPORTS_TIME;
 						if ( time_min == 0 )
@@ -395,8 +417,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 						}
 						else
 						{
-							time_min=time<time_min?time:time_min;
-							parkingspace_index_id=i;
+							if ( time<time_min )
+							{
+								time_min=time;
+								parkingspace_index_id=i;
+							}
 						}
 					}
 				}
@@ -449,8 +474,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 					}
 					else
 					{
-						time_min = time < time_min ? time : time_min;
-						parkingspace_index_id = i;
+						if ( time < time_min )
+						{
+							time_min = time;
+							parkingspace_index_id = i;
+						}
 					}
 				}
 				++i;
@@ -482,7 +510,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 				{
 					//只需计算端口到车位的距离
 					// 三楼中型车位用时=| 目标车位到电梯的距离 - 终端到电梯的距离 | / 中跑车速度
-					int t_min=abs( i%15*all_mid_parkspace_data.parkspace_info(i).parkingspace_width()-terminal_id%6*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
+					float t_min=abs( room_id%15*all_mid_parkspace_data.parkspace_info(i).parkingspace_width()-(terminal_id%6+2)*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
 					if ( time_min == 0 )
 					{
 						time_min=t_min;
@@ -490,15 +518,18 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 					}
 					else
 					{
-						time_min=t_min<time_min?t_min:time_min;
-						parkingspace_index_id=i;
+						if ( t_min<time_min )
+						{
+							time_min=t_min;
+							parkingspace_index_id=i;
+						}
 					}
 				}
 				if ( room_id <= 75 && room_id >= 69
 					 && all_mid_parkspace_data.parkspace_info(i).parkingspace_status() == message::Parkspace_status::eParkspace_empty )
 				{
 					//用时=目标终端到电梯口的距离/中跑车速度+(目标车位楼层-2)*楼层高度/电梯速度+电梯口到目标车位的距离/中跑车速度
-					float time=terminal_id%6*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
+					float time=(terminal_id%6+2)*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
 							   (all_mid_parkspace_data.parkspace_info(i).parkingspace_floor_id()-2)*all_mid_parkspace_data.parkspace_info(i).parkingspace_height()/THE_ELEVATOR_SPEED + ELEVATOR_MOVEMENT_TIME +
 							   all_mid_parkspace_data.parkspace_info(i).parkingspace_index_id()%15*all_mid_parkspace_data.parkspace_info(i).parkingspace_width()/MEDIUM_CAR_SPEED + UPSTAIRS_SPORTS_TIME;
 					if ( time_min == 0 )
@@ -509,8 +540,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 					}
 					else
 					{
-						time_min=time<time_min?time:time_min;
-						parkingspace_index_id=i;
+						if ( time<time_min )
+						{
+							time_min=time;
+							parkingspace_index_id=i;
+						}
 					}
 				}
 				++i;
@@ -545,7 +579,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 					if ( all_big_parkspace_data.parkspace_info(i).parkingspace_floor_id() == 2 )
 					{
 						// 二楼用时=| 目标车位到电梯的距离 - 终端到电梯的距离 | / 中跑车速度
-						int t_min=abs( i%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width()-terminal_id%6*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
+						float t_min=abs( room_id%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width()-(terminal_id%6+2)*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
 						if ( time_min == 0 )
 						{
 							time_min=t_min;
@@ -553,14 +587,17 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 						}
 						else
 						{
-							time_min=t_min<time_min?t_min:time_min;
-							parkingspace_index_id=i;
+							if ( t_min<time_min )
+							{
+								time_min=t_min;
+								parkingspace_index_id=i;
+							}
 						}
 					}
 					else
 					{
 						//用时=目标终端到电梯口的距离/中跑车速度+(目标车位楼层-2)*楼层高度/电梯速度+电梯口到目标车位的距离/中跑车速度
-						float time=terminal_id%6*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
+						float time=(terminal_id%6+2)*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
 								   (all_big_parkspace_data.parkspace_info(i).parkingspace_floor_id()-2)*all_big_parkspace_data.parkspace_info(i).parkingspace_height()/THE_ELEVATOR_SPEED + ELEVATOR_MOVEMENT_TIME +
 								   all_big_parkspace_data.parkspace_info(i).parkingspace_index_id()%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width()/MEDIUM_CAR_SPEED + UPSTAIRS_SPORTS_TIME;
 						if ( time_min == 0 )
@@ -570,8 +607,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverA(message::Pa
 						}
 						else
 						{
-							time_min=time<time_min?time:time_min;
-							parkingspace_index_id=i;
+							if ( time<time_min )
+							{
+								time_min=time;
+								parkingspace_index_id=i;
+							}
 						}
 					}
 				}
@@ -606,7 +646,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB1(message::P
 	 * P=i%6
 	 * S=15*d-(j%15)*(2*d-1)+[6*d-(i%6)(2*d-1)]*W    W>1
 	 */
-	int time_min=0;
+	float time_min=0;
 	int parkingspace_index_id=-1;
 	//找左侧车位
 	//如果是小车 (低于1.55米属于小车)
@@ -639,8 +679,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB1(message::P
 				}
 				else
 				{
-					time_min = time < time_min ? time : time_min;
-					parkingspace_index_id = i;
+					if ( time<time_min )
+					{
+						time_min=time;
+						parkingspace_index_id=i;
+					}
 				}
 			}
 			++i;
@@ -674,8 +717,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB1(message::P
 					}
 					else
 					{
-						time_min = time < time_min ? time : time_min;
-						parkingspace_index_id = i;
+						if ( time < time_min )
+						{
+							time_min = time;
+							parkingspace_index_id = i;
+						}
 					}
 				}
 				++i;
@@ -708,7 +754,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB1(message::P
 				 && all_mid_parkspace_data.parkspace_info(i).parkingspace_status() == message::Parkspace_status::eParkspace_empty )
 			{
 				//用时=目标终端到电梯口的距离/中跑车速度+(目标车位楼层-2)*楼层高度/电梯速度+电梯口到目标车位的距离/中跑车速度
-				float time=terminal_id%6*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
+				float time=(terminal_id%6+2)*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
 						   (all_mid_parkspace_data.parkspace_info(i).parkingspace_floor_id()-2)*all_mid_parkspace_data.parkspace_info(i).parkingspace_height()/THE_ELEVATOR_SPEED + ELEVATOR_MOVEMENT_TIME +
 						   all_mid_parkspace_data.parkspace_info(i).parkingspace_index_id()%15*all_mid_parkspace_data.parkspace_info(i).parkingspace_width()/MEDIUM_CAR_SPEED + UPSTAIRS_SPORTS_TIME;
 				if ( time_min == 0 )
@@ -719,8 +765,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB1(message::P
 				}
 				else
 				{
-					time_min=time<time_min?time:time_min;
-					parkingspace_index_id=i;
+					if ( time<time_min )
+					{
+						time_min=time;
+						parkingspace_index_id=i;
+					}
 				}
 			}
 			++i;
@@ -744,7 +793,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB1(message::P
 					 && all_mid_parkspace_data.parkspace_info(i).parkingspace_status() == message::Parkspace_status::eParkspace_empty )
 				{
 					//用时=目标终端到电梯口的距离/中跑车速度+(目标车位楼层-2)*楼层高度/电梯速度+电梯口到目标车位的距离/中跑车速度
-					float time=terminal_id%6*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
+					float time=(terminal_id%6+2)*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
 							   (all_mid_parkspace_data.parkspace_info(i).parkingspace_floor_id()-2)*all_mid_parkspace_data.parkspace_info(i).parkingspace_height()/THE_ELEVATOR_SPEED + ELEVATOR_MOVEMENT_TIME +
 							   all_mid_parkspace_data.parkspace_info(i).parkingspace_index_id()%15*all_mid_parkspace_data.parkspace_info(i).parkingspace_width()/MEDIUM_CAR_SPEED + UPSTAIRS_SPORTS_TIME;
 					if ( time_min == 0 )
@@ -755,8 +804,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB1(message::P
 					}
 					else
 					{
-						time_min=time<time_min?time:time_min;
-						parkingspace_index_id=i;
+						if ( time<time_min )
+						{
+							time_min=time;
+							parkingspace_index_id=i;
+						}
 					}
 				}
 				++i;
@@ -792,7 +844,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB1(message::P
 				if ( all_big_parkspace_data.parkspace_info(i).parkingspace_floor_id() == 2 )
 				{
 					// 二楼用时=| 目标车位到电梯的距离 - 终端到电梯的距离 | / 中跑车速度
-					int t_min=abs( i%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width()-terminal_id%6*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
+					float t_min=abs( room_id%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width()-(terminal_id%6+2)*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
 					if ( time_min == 0 )
 					{
 						time_min=t_min;
@@ -800,14 +852,17 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB1(message::P
 					}
 					else
 					{
-						time_min=t_min<time_min?t_min:time_min;
-						parkingspace_index_id=i;
+						if ( t_min<time_min )
+						{
+							time_min=t_min;
+							parkingspace_index_id=i;
+						}
 					}
 				}
 				else
 				{
 					//用时=目标终端到电梯口的距离/中跑车速度+(目标车位楼层-2)*楼层高度/电梯速度+电梯口到目标车位的距离/中跑车速度
-					float time=terminal_id%6*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
+					float time=(terminal_id%6+2)*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
 							   (all_big_parkspace_data.parkspace_info(i).parkingspace_floor_id()-2)*all_big_parkspace_data.parkspace_info(i).parkingspace_height()/THE_ELEVATOR_SPEED + ELEVATOR_MOVEMENT_TIME +
 							   all_big_parkspace_data.parkspace_info(i).parkingspace_index_id()%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width()/MEDIUM_CAR_SPEED + UPSTAIRS_SPORTS_TIME;
 					if ( time_min == 0 )
@@ -818,8 +873,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB1(message::P
 					}
 					else
 					{
-						time_min=time<time_min?time:time_min;
-						parkingspace_index_id=i;
+						if ( time<time_min )
+						{
+							time_min=time;
+							parkingspace_index_id=i;
+						}
 					}
 				}
 			}
@@ -852,7 +910,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB2(message::P
 	 * P=i%6
 	 * S=15*d-(j%15)*(2*d-1)+[6*d-(i%6)(2*d-1)]*W    W>1
 	 */
-	int time_min=0;
+	float time_min=0;
 	int parkingspace_index_id=-1;
 	//找右侧车位
 	//如果是小车 (低于1.55米属于小车)
@@ -885,8 +943,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB2(message::P
 				}
 				else
 				{
-					time_min = time < time_min ? time : time_min;
-					parkingspace_index_id = i;
+					if ( time<time_min )
+					{
+						time_min=time;
+						parkingspace_index_id=i;
+					}
 				}
 			}
 			++i;
@@ -920,8 +981,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB2(message::P
 					}
 					else
 					{
-						time_min = time < time_min ? time : time_min;
-						parkingspace_index_id = i;
+						if ( time < time_min )
+						{
+							time_min = time;
+							parkingspace_index_id = i;
+						}
 					}
 				}
 				++i;
@@ -954,7 +1018,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB2(message::P
 				 && all_mid_parkspace_data.parkspace_info(i).parkingspace_status() == message::Parkspace_status::eParkspace_empty )
 			{
 				//用时=目标终端到电梯口的距离/中跑车速度+(目标车位楼层-2)*楼层高度/电梯速度+电梯口到目标车位的距离/中跑车速度
-				float time=terminal_id%6*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
+				float time=(terminal_id%6+2)*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
 						   (all_mid_parkspace_data.parkspace_info(i).parkingspace_floor_id()-2)*all_mid_parkspace_data.parkspace_info(i).parkingspace_height()/THE_ELEVATOR_SPEED + ELEVATOR_MOVEMENT_TIME +
 						   all_mid_parkspace_data.parkspace_info(i).parkingspace_index_id()%15*all_mid_parkspace_data.parkspace_info(i).parkingspace_width()/MEDIUM_CAR_SPEED + UPSTAIRS_SPORTS_TIME;
 				if ( time_min == 0 )
@@ -965,8 +1029,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB2(message::P
 				}
 				else
 				{
-					time_min=time<time_min?time:time_min;
-					parkingspace_index_id=i;
+					if ( time<time_min )
+					{
+						time_min=time;
+						parkingspace_index_id=i;
+					}
 				}
 			}
 			++i;
@@ -990,7 +1057,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB2(message::P
 					 && all_mid_parkspace_data.parkspace_info(i).parkingspace_status() == message::Parkspace_status::eParkspace_empty )
 				{
 					//用时=目标终端到电梯口的距离/中跑车速度+(目标车位楼层-2)*楼层高度/电梯速度+电梯口到目标车位的距离/中跑车速度
-					float time=terminal_id%6*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
+					float time=(terminal_id%6+2)*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
 							   (all_mid_parkspace_data.parkspace_info(i).parkingspace_floor_id()-2)*all_mid_parkspace_data.parkspace_info(i).parkingspace_height()/THE_ELEVATOR_SPEED + ELEVATOR_MOVEMENT_TIME +
 							   all_mid_parkspace_data.parkspace_info(i).parkingspace_index_id()%15*all_mid_parkspace_data.parkspace_info(i).parkingspace_width()/MEDIUM_CAR_SPEED + UPSTAIRS_SPORTS_TIME;
 					if ( time_min == 0 )
@@ -1001,8 +1068,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB2(message::P
 					}
 					else
 					{
-						time_min=time<time_min?time:time_min;
-						parkingspace_index_id=i;
+						if ( time<time_min )
+						{
+							time_min=time;
+							parkingspace_index_id=i;
+						}
 					}
 				}
 				++i;
@@ -1038,7 +1108,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB2(message::P
 				if ( all_big_parkspace_data.parkspace_info(i).parkingspace_floor_id() == 2 )
 				{
 					// 二楼用时=| 目标车位到电梯的距离 - 终端到电梯的距离 | / 中跑车速度
-					int t_min=abs( i%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width()-terminal_id%6*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
+					float t_min=abs( room_id%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width()-(terminal_id%6+2)*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
 					if ( time_min == 0 )
 					{
 						time_min=t_min;
@@ -1046,14 +1116,17 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB2(message::P
 					}
 					else
 					{
-						time_min=t_min<time_min?t_min:time_min;
-						parkingspace_index_id=i;
+						if ( t_min<time_min )
+						{
+							time_min=t_min;
+							parkingspace_index_id=i;
+						}
 					}
 				}
 				else
 				{
 					//用时=目标终端到电梯口的距离/中跑车速度+(目标车位楼层-2)*楼层高度/电梯速度+电梯口到目标车位的距离/中跑车速度
-					float time=terminal_id%6*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
+					float time=(terminal_id%6+2)*TERMINAL_SPACING/MEDIUM_CAR_SPEED  + DOWNSTAIRS_SPORTS_TIME +
 							   (all_big_parkspace_data.parkspace_info(i).parkingspace_floor_id()-2)*all_big_parkspace_data.parkspace_info(i).parkingspace_height()/THE_ELEVATOR_SPEED + ELEVATOR_MOVEMENT_TIME +
 							   all_big_parkspace_data.parkspace_info(i).parkingspace_index_id()%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width()/MEDIUM_CAR_SPEED + UPSTAIRS_SPORTS_TIME;
 					if ( time_min == 0 )
@@ -1064,8 +1137,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB2(message::P
 					}
 					else
 					{
-						time_min=time<time_min?time:time_min;
-						parkingspace_index_id=i;
+						if ( time<time_min )
+						{
+							time_min=time;
+							parkingspace_index_id=i;
+						}
 					}
 				}
 			}
@@ -1097,7 +1173,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB3(message::P
 	 * P=i%6
 	 * S=15*d-(j%15)*(2*d-1)+[6*d-(i%6)(2*d-1)]*W    W>1
 	 */
-	int time_min=0;
+	float time_min=0;
 	int parkingspace_index_id=-1;
 	//找缓存区车位 缓冲区只有中型车位和大型车位
 	if ( car_info.car_height() <= MID_CAR_HIGH )
@@ -1118,7 +1194,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB3(message::P
 			{
 				//只需计算端口到车位的距离
 				// 三楼中型用时=| 目标车位到电梯的距离 - 终端到电梯的距离 | / 中跑车速度
-				int t_min=abs( i%15*all_mid_parkspace_data.parkspace_info(i).parkingspace_width()-terminal_id%6*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
+				float t_min=abs( room_id%15*all_mid_parkspace_data.parkspace_info(i).parkingspace_width()-(terminal_id%6+2)*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
 				if ( time_min == 0 )
 				{
 					time_min=t_min;
@@ -1126,8 +1202,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB3(message::P
 				}
 				else
 				{
-					time_min=t_min<time_min?t_min:time_min;
-					parkingspace_index_id=i;
+					if ( t_min<time_min )
+					{
+						time_min=t_min;
+						parkingspace_index_id=i;
+					}
 				}
 			}
 		}
@@ -1156,7 +1235,7 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB3(message::P
 			{
 				//只需计算端口到车位的距离
 				// 二楼中型用时=| 目标车位到电梯的距离 - 终端到电梯的距离 | / 中跑车速度
-				int t_min=abs( i%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width()-terminal_id%6*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
+				float t_min=abs( room_id%15*all_big_parkspace_data.parkspace_info(i).parkingspace_width()-(terminal_id%6+2)*TERMINAL_SPACING )/MEDIUM_CAR_SPEED+DOWNSTAIRS_SPORTS_TIME;
 				if ( time_min == 0 )
 				{
 					time_min=t_min;
@@ -1164,8 +1243,11 @@ Error_manager Parkspace_manager::query_the_optimal_parkspace_serverB3(message::P
 				}
 				else
 				{
-					time_min=t_min<time_min?t_min:time_min;
-					parkingspace_index_id=i;
+					if ( t_min<time_min )
+					{
+						time_min=t_min;
+						parkingspace_index_id=i;
+					}
 				}
 			}
 		}
@@ -1214,10 +1296,11 @@ void Parkspace_manager::execute_for_allocate(message::Car_info car_info, int ter
 	{
 		m_parkspace_lock.lock();
 		//如果车辆不存在 则找到一个最优车位
-//		error=query_the_optimal_parkspace(t_allocated_space,car_info,terminal_id);
+		error=query_the_optimal_parkspace_serverA(t_allocated_space,car_info,terminal_id);
 //		query_the_optimal_parkspace_serverA(t_allocated_space,car_info,terminal_id);
 		//如果车辆不存在则获取一个空车位
-		error=m_parkspace_operating_function.query_one_empty_parkspace(t_allocated_space);
+//		error=m_parkspace_operating_function.query_one_empty_parkspace(t_allocated_space);
+
 		if ( error != Error_code::SUCCESS )
 		{
 			t_error.set_error_code(error.get_error_code());
@@ -1227,6 +1310,9 @@ void Parkspace_manager::execute_for_allocate(message::Car_info car_info, int ter
 		}
 		else
 		{
+			LOG(INFO) <<"分配的车位ID为:"<<t_allocated_space.parkingspace_index_id();
+
+			return ;
 			//修改车为状态为锁定
 			t_allocated_space.set_parkingspace_status(message::Parkspace_status::eParkspace_locked);
 			t_allocated_space.mutable_car_info()->CopyFrom(car_info);

+ 5 - 5
parkspace_allocation/parkspace_manager.h

@@ -36,19 +36,19 @@ public:
 //中型车高判断标准 (暂时未定)   手写1.75
 #define MID_CAR_HIGH			1.75
 //大型车高判断标准 (暂时未定)   手写1.65
-#define BIG_CAR_HIGH			1.95
+#define BIG_CAR_HIGH			2
 //中跑车速度 米每秒
 #define MEDIUM_CAR_SPEED		0.8
 //电梯速度  米每秒
 #define THE_ELEVATOR_SPEED		1.3
 //终端间距
-#define TERMINAL_SPACING		2
+#define TERMINAL_SPACING		2.5
 //中跑车楼下运动时间
-#define DOWNSTAIRS_SPORTS_TIME	0
+#define DOWNSTAIRS_SPORTS_TIME	1
 //中跑车楼上运动时间
-#define UPSTAIRS_SPORTS_TIME	0
+#define UPSTAIRS_SPORTS_TIME	1
 //电梯运动时间
-#define ELEVATOR_MOVEMENT_TIME	0
+#define ELEVATOR_MOVEMENT_TIME	1
 private:
     // 父类的构造函数必须保护,子类的构造函数必须私有。
     Parkspace_manager();

+ 1 - 1
parkspace_allocation/parkspace_operating_function.cpp

@@ -99,7 +99,7 @@ Error_manager Parkspace_operating_function::get_specify_the_type_parkspace_info(
 	//执行sql操作
 	char all_specify_the_type_sql[1024];
 	memset(all_specify_the_type_sql, 0, 1024);
-	sprintf(all_specify_the_type_sql,"select * from parkingspace where parkingspace_type= %d",3);
+	sprintf(all_specify_the_type_sql,"select * from parkingspace where parkingspace_type= %d",parkspace_type);
 	boost::shared_ptr<sql::ResultSet>  tp_result = nullptr;
 	Error_manager ec = Database_controller::get_instance_pointer()->sql_query(all_specify_the_type_sql, tp_result);
 	if(ec == SUCCESS)

+ 1 - 0
parkspace_allocation/parkspace_operating_function.h

@@ -29,6 +29,7 @@ public:
     Error_manager get_all_parkspace_info(message::Parkspace_allocation_data_msg &all_parkspace_info);
     // 获取置顶类型车位信息,用于车位分配
 	Error_manager get_specify_the_type_parkspace_info(message::Parkspace_allocation_data_msg &all_specify_the_type_parkspace_info,int parkspace_type);
+
     // 清除数据库中所有车位号牌,状态全修改为空闲
     Error_manager clear_all_parkspace_info();
     // 更新数据库中车位状态--根据车位ID修改车位状态

+ 27 - 27
test/parkspace_client.cpp

@@ -31,8 +31,8 @@ std::string send_allocation_request(int n)
     base_info.set_sender(message::eMain);
     base_info.set_receiver(message::eParkspace);
     base_info.set_timeout_ms(2000);
-    car_info.set_car_height(1.0);
-    car_info.set_car_width(1.0);
+    car_info.set_car_height(1.94);
+    car_info.set_car_width(1.94);
     car_info.set_license(CAR_LICENSE);
 
     request.mutable_base_info()->CopyFrom(base_info);
@@ -84,13 +84,13 @@ std::string send_release_request(int n)
     car_info.set_car_height(1.5);
     car_info.set_car_width(1.85);
     car_info.set_license(CAR_LICENSE);
-    space_info.set_parkspace_id(1);
-    space_info.set_index(1);
-    space_info.set_direction(message::Direction::eForward);
-    space_info.set_floor(33);
-    space_info.set_width(1.5);
-    space_info.set_height(1.5);
-    space_info.set_parkspace_status(message::Parkspace_status::eParkspace_occupied);
+    space_info.set_parkingspace_index_id(1);
+    space_info.set_parkingspace_room_id(1);
+    space_info.set_parkingspace_direction(message::Direction::eForward);
+    space_info.set_parkingspace_floor_id(3);
+    space_info.set_parkingspace_height(1.5);
+    space_info.set_parkingspace_width(1.5);
+    space_info.set_parkingspace_status(message::Parkspace_status::eParkspace_occupied);
     space_info.mutable_car_info()->CopyFrom(car_info);
 
     request.mutable_base_info()->CopyFrom(base_info);
@@ -103,7 +103,7 @@ std::string send_release_request(int n)
 
 std::string send_confirm_request(int n)
 {
-    // 发送车位释放请求
+    // 发送车位确认请求
     message::Error_manager error_code;
     message::Base_info base_info;
     message::Car_info car_info;
@@ -117,13 +117,13 @@ std::string send_confirm_request(int n)
     car_info.set_car_height(1.5);
     car_info.set_car_width(1.85);
     car_info.set_license(CAR_LICENSE);
-    space_info.set_parkspace_id(1);
-    space_info.set_index(1);
-    space_info.set_direction(message::Direction::eForward);
-    space_info.set_floor(33);
-    space_info.set_width(1.5);
-    space_info.set_height(1.5);
-    space_info.set_parkspace_status(message::Parkspace_status::eParkspace_occupied);
+    space_info.set_parkingspace_index_id(1);
+    space_info.set_parkingspace_room_id(1);
+    space_info.set_parkingspace_direction(message::Direction::eForward);
+    space_info.set_parkingspace_floor_id(33);
+    space_info.set_parkingspace_width(1.5);
+    space_info.set_parkingspace_height(1.5);
+    space_info.set_parkingspace_status(message::Parkspace_status::eParkspace_occupied);
     space_info.mutable_car_info()->CopyFrom(car_info);
 
     request.mutable_base_info()->CopyFrom(base_info);
@@ -139,7 +139,7 @@ int main()
     nnxx::socket socket{nnxx::SP, nnxx::BUS};
     socket.bind("tcp://127.0.0.1:7000");
 //    socket.connect("tcp://192.168.2.113:30008");
-    
+
 //	socket.connect("tcp://127.0.0.1:30005");
 
 //	socket.connect("tcp://192.168.2.127:30005");
@@ -153,17 +153,17 @@ int main()
     socket.send(alloc_req);
     usleep(1000 * 500);
 
-    std::string confirm_req = send_confirm_request(1);
-    socket.send(confirm_req);
-    usleep(1000 * 500);
+//    std::string confirm_req = send_confirm_request(1);
+//    socket.send(confirm_req);
+//    usleep(1000 * 500);
 //
-    std::string search_req = send_search_requests(1);
-    socket.send(search_req);
-    usleep(1000 * 500);
+//    std::string search_req = send_search_requests(1);
+//    socket.send(search_req);
+//    usleep(1000 * 500);
 //
-    std::string release_req = send_release_request(1);
-    socket.send(release_req);
-    usleep(1000 * 500);
+//    std::string release_req = send_release_request(1);
+//    socket.send(release_req);
+//    usleep(1000 * 500);
 
     // usleep(1000*200);
     // search_req = send_search_requests(3);