Commit db6ebc5f authored by 张晓彤's avatar 张晓彤

二次调度触发方式优化

parent 20500a86
......@@ -32,8 +32,7 @@ class Dispatcher:
self.logger = get_logger("zxt.dispatcher")
self.redispatch_active = active
if self.redispatch_active:
self.topo = Topo()
self.topo.generate_topo_graph()
self.topo = graph_construct()
else:
self.topo = None
self.submission = DispatchSubmission(dump, excavator, truck, self.topo)
......@@ -49,8 +48,7 @@ class Dispatcher:
self.truck.truck_para_period_update(self.dump, self.excavator)
self.truck.state_period_update()
if self.redispatch_active:
self.topo = Topo()
self.topo.generate_topo_graph()
self.topo = graph_construct()
else:
self.topo = None
......
......@@ -114,7 +114,7 @@ class CurrentTruck:
def __init__(self, truck_id: str, group_id: str, trip: List[int], task: int, state: int,
lane_locate: str, name: str, combined_excavator: str, combined_dump: str,
combined_load_area: str, combined_unload_area: str):
combined_load_area: str, combined_unload_area: str, redispatch: bool):
self._lane_locate = lane_locate
self._truck_id = truck_id
self._group_id = group_id
......@@ -127,6 +127,7 @@ class CurrentTruck:
self.has_changed = False
self._combined_load_area = combined_load_area
self._combined_unload_area = combined_unload_area
self.redispatch = redispatch
def get_truck_id(self):
return self._truck_id
......@@ -164,6 +165,9 @@ class CurrentTruck:
def get_combined_unload_area(self):
return self._combined_unload_area
def get_redispatch(self):
return self.redispatch
class Group:
"""
......@@ -576,6 +580,7 @@ class GroupDispatcher:
self.logger.info("触发二次调度")
# self.redispatch_to_dump(truck_id, truck_dispatch, truck_locate, truck_trip)
try:
truck_info.redispatch =\
self.redispatcher.redispatch_to_dump(truck_id, truck_dispatch, truck_locate, truck_trip)
except Exception as es:
self.logger.error("二次调度至卸载点失败")
......@@ -608,6 +613,7 @@ class GroupDispatcher:
self.logger.info("触发二次调度")
try:
truck_info.redispatch =\
self.redispatcher.redispatch_to_excavator(truck_id, truck_dispatch, truck_locate,
truck_trip, truck_info)
except Exception as es:
......@@ -791,7 +797,7 @@ class GroupDispatcher:
self.group.truck.get_truck_current_state()[truck_id], truck_lane_locate,
truck_name, combined_excavator=current_truck_goto_excavator_id,
combined_dump=current_truck_goto_dump_id, combined_load_area=current_load_area_id,
combined_unload_area=current_unload_area_id)
combined_unload_area=current_unload_area_id, redispatch=False)
self.group.truck_info_list[truck_id] = truck_info
......@@ -1037,9 +1043,13 @@ class ReDispatcher:
self.logger.info(f'二次调度结果 {truck_id}')
self.logger.info(truck_dispatch[truck_id])
return True
else:
self.logger.info(f'二次调度未变更')
return False
def redispatch_to_dump(self, truck_id: str, truck_dispatch: Mapping[str, List[str]], truck_locate: str,
truck_trip: List[int], truck_info: CurrentTruck):
"""
......@@ -1092,9 +1102,13 @@ class ReDispatcher:
self.logger.info(truck_dispatch[truck_id])
# res = redispatch_request(truck_id, next_excavator_id, next_unload_area_id)
# self.logger.info(res)
return True
else:
self.logger.info(f'二次调度未变更')
return False
def get_best_dump(self, current_dump_id, unload_area_dict):
min_trip_time = 10000000
best_dump_id = current_dump_id
......
......@@ -76,14 +76,14 @@ class DispatchSubmission:
else:
self.logger.info("动态调度模式")
self.dynamic_dispatch_mode(dispatch_seq, group_id, record, truck_info.get_sate(),
truck_info.get_task(), truck_id)
truck_info.get_task(), truck_id, truck_info.get_redispatch())
# except Exception as es:
# self.logger.error("调度结果写入异常")
# self.logger.error(f"调度结果:{dispatch_seq}")
# self.logger.error(es)
def dynamic_dispatch_mode(self, dispatch_seq, group_id, record, state, task, truck_id):
def dynamic_dispatch_mode(self, dispatch_seq, group_id, record, state, task, truck_id, redispatch):
"""
write dispatch plan in dynamic dispatch mode.
:param dispatch_seq:
......@@ -92,6 +92,7 @@ class DispatchSubmission:
:param state:
:param task:
:param truck_id:
:param redispatch:
:return:
"""
if (task in [1, 2]) or (task == 3 and state == 2): # 车辆位于装载区,或车辆重载等待
......@@ -125,12 +126,14 @@ class DispatchSubmission:
# TODO: 判断了两次是否拥堵,需要改善
# # 车辆重载等待,且前方道路阻塞
# if self.topo is not None \
# and task == 3 \
# and truck_id in self.truck.get_truck_lane_locate_dict() \
# and self.truck.get_truck_lane_locate_dict()[truck_id] in self.topo.cross_bf_lanes:
# 车辆重载等待,且前方道路阻塞
if self.topo is not None \
and task == 3 \
and state == 2 \
and truck_id in self.truck.get_truck_lane_locate_dict() \
and self.truck.get_truck_lane_locate_dict()[truck_id] in self.topo.cross_bf_lanes:
if self.topo is not None and redispatch:
# try:
# if truck_id in self.truck.truck_is_temp and not self.truck.truck_is_temp[truck_id]:
self.logger.info("二次调度前往卸载区")
......@@ -189,12 +192,14 @@ class DispatchSubmission:
if self.topo is not None:
# # 车辆重载等待,且前方道路阻塞
# if self.topo is not None \
# and task == 0 \
# and truck_id in self.truck.get_truck_lane_locate_dict() \
# and self.truck.get_truck_lane_locate_dict()[truck_id] in self.topo.cross_bf_lanes:
# 车辆重载等待,且前方道路阻塞
if self.topo is not None \
and task == 0 \
and state == 2 \
and truck_id in self.truck.get_truck_lane_locate_dict() \
and self.truck.get_truck_lane_locate_dict()[truck_id] in self.topo.cross_bf_lanes:
if self.topo is not None and redispatch:
# 车辆停车等待
# try:
# if truck_id in self.truck.truck_is_temp and not self.truck.truck_is_temp[truck_id]:
......
......@@ -310,6 +310,12 @@ class Topo():
self.logger.error(es)
self.logger.error("备停区部分装载拓扑图生成失败")
# 更新交叉点
self.update_cross_nodes()
# 更新交叉点前路段
self.update_cross_bf_lanes()
"""
unload source node for reschedule
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment