Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
integrated-scheduling-v3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张晓彤
integrated-scheduling-v3
Commits
edc1105f
Commit
edc1105f
authored
May 15, 2023
by
张晓彤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化&二次调度
parent
2126a86f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
268 additions
and
211 deletions
+268
-211
group.py
core/group.py
+263
-210
submit.py
core/submit.py
+5
-1
No files found.
core/group.py
View file @
edc1105f
...
@@ -112,12 +112,21 @@ class CurrentTruck:
...
@@ -112,12 +112,21 @@ class CurrentTruck:
"""
"""
def
__init__
(
self
,
truck_id
:
str
,
group_id
:
str
,
trip
:
List
[
int
],
task
:
int
,
state
:
int
):
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
):
self
.
_lane_locate
=
lane_locate
self
.
_truck_id
=
truck_id
self
.
_truck_id
=
truck_id
self
.
_group_id
=
group_id
self
.
_group_id
=
group_id
self
.
_trip
=
trip
self
.
_trip
=
trip
self
.
_task
=
task
self
.
_task
=
task
self
.
_state
=
state
self
.
_state
=
state
self
.
_name
=
name
self
.
_combined_excavator
=
combined_excavator
self
.
_combined_dump
=
combined_dump
self
.
has_changed
=
False
self
.
_combined_load_area
=
combined_load_area
self
.
_combined_unload_area
=
combined_unload_area
def
get_truck_id
(
self
):
def
get_truck_id
(
self
):
return
self
.
_truck_id
return
self
.
_truck_id
...
@@ -134,11 +143,33 @@ class CurrentTruck:
...
@@ -134,11 +143,33 @@ class CurrentTruck:
def
get_sate
(
self
):
def
get_sate
(
self
):
return
self
.
_state
return
self
.
_state
def
get_lane_locate
(
self
):
return
self
.
_lane_locate
def
get_name
(
self
):
return
self
.
_name
def
get_combined_excavator
(
self
):
return
self
.
_combined_excavator
def
get_combined_dump
(
self
):
return
self
.
_combined_dump
def
get_has_changed
(
self
):
return
self
.
has_changed
def
get_combined_load_area
(
self
):
return
self
.
_combined_load_area
def
get_combined_unload_area
(
self
):
return
self
.
_combined_unload_area
class
Group
:
class
Group
:
"""
"""
class for group instance.
class for group instance.
"""
"""
def
__init__
(
self
,
group_id
,
truck
:
TruckInfo
,
pre_sch
:
PreSchedule
,
excavator_info
:
ExcavatorInfo
,
def
__init__
(
self
,
group_id
,
truck
:
TruckInfo
,
pre_sch
:
PreSchedule
,
excavator_info
:
ExcavatorInfo
,
dump_info
:
DumpInfo
,
topo
:
Topo
):
dump_info
:
DumpInfo
,
topo
:
Topo
):
"""
"""
...
@@ -267,7 +298,8 @@ class Group:
...
@@ -267,7 +298,8 @@ class Group:
excavator_index
=
self
.
excavator_uuid_index_dict
[
excavator_id
]
excavator_index
=
self
.
excavator_uuid_index_dict
[
excavator_id
]
dump_index
=
self
.
dump_uuid_index_dict
[
dump_id
]
dump_index
=
self
.
dump_uuid_index_dict
[
dump_id
]
if
self
.
excavator_info
.
excavator_material
[
excavator_id
]
not
in
self
.
dump_info
.
dump_material
[
dump_id
]:
if
self
.
excavator_info
.
excavator_material
[
excavator_id
]
not
in
self
.
dump_info
.
dump_material
[
dump_id
]:
self
.
group_walk_available
[
excavator_index
][
dump_index
]
=
10
self
.
group_walk_available
[
excavator_index
][
dump_index
]
=
10
self
.
logger
.
info
(
"group_walk_available"
)
self
.
logger
.
info
(
"group_walk_available"
)
self
.
logger
.
info
(
self
.
group_walk_available
)
self
.
logger
.
info
(
self
.
group_walk_available
)
...
@@ -323,7 +355,6 @@ class Group:
...
@@ -323,7 +355,6 @@ class Group:
self
.
logger
.
info
(
"group.truck_excavator_exclude"
)
self
.
logger
.
info
(
"group.truck_excavator_exclude"
)
self
.
logger
.
info
(
self
.
truck_excavator_exclude_modify
)
self
.
logger
.
info
(
self
.
truck_excavator_exclude_modify
)
def
info_update
(
self
):
def
info_update
(
self
):
"""
"""
update group info.
update group info.
...
@@ -381,108 +412,21 @@ class GroupDispatcher:
...
@@ -381,108 +412,21 @@ class GroupDispatcher:
for
truck_id
in
list
(
self
.
group
.
group_trucks
):
for
truck_id
in
list
(
self
.
group
.
group_trucks
):
# try:
# construct CurrentTruck obj.
# get truck index from mapping
current_truck
=
self
.
truck_construct
(
truck_id
)
if
truck_id
not
in
self
.
group
.
truck
.
truck_uuid_to_index_dict
:
self
.
logger
.
error
(
f
'truck.truck dict 中不存在 {truck_id}'
)
continue
else
:
truck_idx
=
self
.
group
.
truck
.
truck_uuid_to_index_dict
[
truck_id
]
# get truck trip from truck obj.
truck_trip_info_list
=
self
.
group
.
truck
.
get_truck_current_trip
()
if
truck_idx
>=
len
(
truck_trip_info_list
):
self
.
logger
.
info
(
f
'======================= 开始处理调度车辆 {current_truck.get_name()} ======================='
)
self
.
logger
.
error
(
f
'truck.truck trip 中不存在 {truck_idx} 号矿卡 {truck_id}'
)
continue
else
:
truck_trip
=
self
.
group
.
truck
.
get_truck_current_trip
()[
truck_idx
]
# get truck task from truck obj.
truck_task_list
=
self
.
group
.
truck
.
get_truck_current_task
()
if
truck_id
not
in
truck_task_list
:
self
.
logger
.
error
(
f
'truck.truck task 中不存在矿卡 {truck_id}'
)
continue
else
:
truck_task
=
truck_task_list
[
truck_id
]
# get truck lane_id from truck obj.
truck_lane_locate_dict
=
self
.
group
.
truck
.
get_truck_lane_locate_dict
()
if
truck_id
not
in
truck_lane_locate_dict
:
self
.
logger
.
warning
(
f
'truck.truck lane dict 中不存在矿卡 {truck_id}'
)
# continue
truck_lane_locate
=
None
else
:
truck_lane_locate
=
truck_lane_locate_dict
[
truck_id
]
# get truck name form dict.
truck_uuid_to_name_dict
=
get_value
(
"truck_uuid_to_name_dict"
)
# 获取请调车辆名
if
truck_id
not
in
truck_uuid_to_name_dict
:
# raise CoreException(102, f'truck_uuid_to_name_dict 缺失车辆 {truck_id} 信息')
self
.
logger
.
error
(
f
'truck_uuid_to_name_dict 缺失车辆 {truck_id} 信息'
)
truck_name
=
truck_uuid_to_name_dict
[
truck_id
]
# 获取车辆当前派车计划
if
truck_task
in
[
0
,
1
,
5
]:
excavator_index
=
int
(
truck_trip
[
1
])
dump_index
=
int
(
truck_trip
[
0
])
else
:
dump_index
=
int
(
truck_trip
[
1
])
excavator_index
=
int
(
truck_trip
[
0
])
if
excavator_index
==
-
1
:
current_truck_goto_excavator_id
=
None
current_load_area_id
=
None
else
:
# if excavator_index not in self.group.excavator_info.excavator_index_to_uuid_dict:
# # raise CoreException(111, f'excavator_index_to_uuid_dict 缺失 {excavator_index} 号挖机信息')
# self.logger.error(f'excavator_index_to_uuid_dict 缺失 {excavator_index} 号挖机信息')
current_truck_goto_excavator_id
=
self
.
group
.
excavator_info
.
excavator_index_to_uuid_dict
[
excavator_index
]
current_load_area_id
=
DispatchInfo
.
excavator_load_dict
[
current_truck_goto_excavator_id
]
if
dump_index
==
-
1
:
current_truck_goto_dump_id
=
None
current_unload_area_id
=
None
else
:
# if dump_index not in self.group.dump_info.dump_index_to_uuid_dict:
# # raise CoreException(111, f'dump_index_to_uuid_dict 缺失 {dump_index} 号卸点信息')
# self.logger.error(f'dump_index_to_uuid_dict 缺失 {dump_index} 号卸点信息')
current_truck_goto_dump_id
=
self
.
group
.
dump_info
.
dump_index_to_uuid_dict
[
dump_index
]
current_unload_area_id
=
DispatchInfo
.
dump_unload_area_dict
[
current_truck_goto_dump_id
]
# Construct a truck obj. and add it to group truck dictionary.
truck_info
=
CurrentTruck
(
truck_id
,
self
.
group
.
group_id
,
truck_trip
,
truck_task
,
self
.
group
.
truck
.
get_truck_current_state
()[
truck_id
])
self
.
group
.
truck_info_list
[
truck_id
]
=
truck_info
# Construct a test case for redispatch
# truck_task = 0
# if truck_id != "f704aa5e-24d9-4822-b634-ae81ca5ff0be":
# self.truck.get_truck_locate_dict()[truck_id] = "8961f641-c134-8be8-f4eb-95e6e2c374b7"
# self.truck.truck_is_temp[truck_id] = False
# self.truck.truck_current_state[truck_id] = 2
# except Exception as es:
# self.logger.error("车辆调度信息读取异常")
# self.logger.error(es)
self
.
logger
.
info
(
f
'======================= 开始处理调度车辆 {truck_name} ======================='
)
try
:
try
:
# 全智能模式
# 全智能模式
if
self
.
group
.
group_mode
==
1
:
if
self
.
group
.
group_mode
==
1
:
self
.
logger
.
info
(
"调度模式:全智能模式调度"
)
self
.
logger
.
info
(
"调度模式:全智能模式调度"
)
self
.
full_dynamic_mode
(
truck_id
,
solver
,
truck_dispatch
,
truck_info
,
truck_task
,
truck_trip
)
self
.
full_dynamic_mode
(
truck_id
,
solver
,
truck_dispatch
,
current_truck
)
# 空车智能模式
# 空车智能模式
elif
self
.
group
.
group_mode
==
2
:
elif
self
.
group
.
group_mode
==
2
:
self
.
logger
.
info
(
"调度模式:空车智能模式调度"
)
self
.
logger
.
info
(
"调度模式:空车智能模式调度"
)
self
.
semi_dynamic_mode
(
truck_id
,
solver
,
truck_dispatch
,
truck_info
,
truck_task
,
truck_trip
)
self
.
semi_dynamic_mode
(
truck_id
,
solver
,
truck_dispatch
,
current_truck
)
# 定铲派车
# 定铲派车
elif
self
.
group
.
group_mode
==
3
:
elif
self
.
group
.
group_mode
==
3
:
self
.
logger
.
info
(
"调度模式:固定模式调度"
)
self
.
logger
.
info
(
"调度模式:固定模式调度"
)
...
@@ -495,13 +439,13 @@ class GroupDispatcher:
...
@@ -495,13 +439,13 @@ class GroupDispatcher:
# 分流配比模式
# 分流配比模式
elif
self
.
group
.
group_mode
==
4
:
elif
self
.
group
.
group_mode
==
4
:
self
.
logger
.
info
(
"调度模式:分流配比模式调度"
)
self
.
logger
.
info
(
"调度模式:分流配比模式调度"
)
self
.
ratio_mode
(
truck_id
,
truck_dispatch
,
truck_task
)
self
.
ratio_mode
(
truck_id
,
truck_dispatch
,
current_truck
.
get_task
()
)
except
Exception
as
es
:
except
Exception
as
es
:
self
.
logger
.
error
(
"调度调用异常"
)
self
.
logger
.
error
(
"调度调用异常"
)
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
es
)
self
.
logger
.
info
(
f
'======================= 派车计划计算结束 {
truck_name
} ======================='
)
self
.
logger
.
info
(
f
'======================= 派车计划计算结束 {
current_truck.get_name()
} ======================='
)
return
truck_dispatch
return
truck_dispatch
...
@@ -544,11 +488,16 @@ class GroupDispatcher:
...
@@ -544,11 +488,16 @@ class GroupDispatcher:
self
.
logger
.
error
(
"分流配比模式-->>重载车辆计算异常"
)
self
.
logger
.
error
(
"分流配比模式-->>重载车辆计算异常"
)
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
es
)
truck_dispatch
[
i
]
=
[
next_exactor_id
,
next_unload_area_id
]
truck_dispatch
[
i
]
=
[
next_exactor_id
,
next_unload_area_id
]
def
semi_dynamic_mode
(
self
,
i
,
s
,
truck_dispatch
,
truck_info
,
truck_task
,
truck_trip
):
def
semi_dynamic_mode
(
self
,
i
,
s
,
truck_dispatch
,
truck_info
):
# TODO:和全智能调度很像,是否可以合并合;
# TODO:和全智能调度很像,是否可以合并合;
truck_task
=
truck_info
.
get_task
()
truck_trip
=
truck_info
.
get_trip
()
# 加入二次调度;
# 加入二次调度;
if
truck_task
in
[
-
2
,
3
,
4
,
5
]:
if
truck_task
in
[
-
2
,
3
,
4
,
5
]:
try
:
try
:
...
@@ -579,8 +528,12 @@ class GroupDispatcher:
...
@@ -579,8 +528,12 @@ class GroupDispatcher:
self
.
logger
.
error
(
"空载车辆空车智能模式-计算异常"
)
self
.
logger
.
error
(
"空载车辆空车智能模式-计算异常"
)
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
es
)
def
full_dynamic_mode
(
self
,
i
:
str
,
s
:
AlgorithmBase
,
truck_dispatch
:
Mapping
[
str
,
List
[
str
]],
def
full_dynamic_mode
(
self
,
truck_id
:
str
,
s
:
AlgorithmBase
,
truck_dispatch
:
Mapping
[
str
,
List
[
str
]],
truck_info
:
CurrentTruck
,
truck_task
:
int
,
truck_trip
:
List
[
int
]):
truck_info
:
CurrentTruck
):
truck_trip
=
truck_info
.
get_trip
()
truck_name
=
truck_info
.
get_name
()
# 获取车辆任务信息
# 获取车辆任务信息
try
:
try
:
...
@@ -589,32 +542,32 @@ class GroupDispatcher:
...
@@ -589,32 +542,32 @@ class GroupDispatcher:
raise
Exception
(
"车辆任务信息丢失"
)
raise
Exception
(
"车辆任务信息丢失"
)
except
Exception
as
es
:
except
Exception
as
es
:
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
es
)
truck_dispatch
[
i
]
=
[
None
,
None
]
truck_dispatch
[
truck_id
]
=
[
None
,
None
]
return
return
# 获取车辆位置信息
# 获取车辆位置信息
try
:
try
:
truck_locate
=
self
.
group
.
truck
.
get_truck_lane_locate_dict
()[
i
]
truck_locate
=
self
.
group
.
truck
.
get_truck_lane_locate_dict
()[
truck_id
]
except
Exception
as
es
:
except
Exception
as
es
:
self
.
logger
.
error
(
f
'车辆位置信息丢失 {es}'
)
self
.
logger
.
error
(
f
'车辆位置信息丢失 {es}'
)
truck_locate
=
None
truck_locate
=
None
# 获取车辆临时字段
# 获取车辆临时字段
try
:
try
:
truck_is_temp
=
self
.
group
.
truck
.
truck_is_temp
[
i
]
truck_is_temp
=
self
.
group
.
truck
.
truck_is_temp
[
truck_id
]
except
Exception
as
es
:
except
Exception
as
es
:
truck_is_temp
=
False
truck_is_temp
=
False
self
.
logger
.
error
(
f
'车辆临时字段异常 {es}'
)
self
.
logger
.
error
(
f
'车辆临时字段异常 {es}'
)
# 车辆停止或者车辆位于卸载区内, 调度车辆前往装载区
# 车辆停止或者车辆位于卸载区内, 调度车辆前往装载区
if
truck_task
in
[
-
2
,
3
,
4
,
5
]:
if
truck_task
in
[
-
2
,
3
,
4
,
5
]:
#
if truck_task == 3 and self.group.truck.truck_current_state[i] == 2:
#
if
truck_task
==
3
:
if
truck_task
==
3
:
if
self
.
group
.
topo
is
not
None
and
truck_locate
is
not
None
:
if
self
.
group
.
topo
is
not
None
and
truck_locate
is
not
None
:
self
.
logger
.
info
(
"潜在二次调度车辆状态"
)
self
.
logger
.
info
(
"潜在二次调度车辆状态"
)
self
.
logger
.
info
(
f
'车辆 {truck_name}'
)
self
.
logger
.
info
(
f
'车辆位置 {truck_locate}'
)
self
.
logger
.
info
(
f
'车辆位置 {truck_locate}'
)
self
.
logger
.
info
(
f
'车辆状态 {self.group.truck.truck_current_state[
i
]}'
)
self
.
logger
.
info
(
f
'车辆状态 {self.group.truck.truck_current_state[
truck_id
]}'
)
self
.
logger
.
info
(
f
'车辆任务 {truck_task}'
)
self
.
logger
.
info
(
f
'车辆任务 {truck_task}'
)
self
.
logger
.
info
(
f
'车辆临时 {truck_is_temp}'
)
self
.
logger
.
info
(
f
'车辆临时 {truck_is_temp}'
)
self
.
logger
.
info
(
self
.
group
.
topo
.
cross_bf_lanes
)
self
.
logger
.
info
(
self
.
group
.
topo
.
cross_bf_lanes
)
...
@@ -622,9 +575,9 @@ class GroupDispatcher:
...
@@ -622,9 +575,9 @@ class GroupDispatcher:
# 车辆当前位于交叉路口前,且排队等待
# 车辆当前位于交叉路口前,且排队等待
if
(
truck_locate
in
self
.
group
.
topo
.
cross_bf_lanes
)
and
(
not
truck_is_temp
):
if
(
truck_locate
in
self
.
group
.
topo
.
cross_bf_lanes
)
and
(
not
truck_is_temp
):
self
.
logger
.
info
(
"触发二次调度"
)
self
.
logger
.
info
(
"触发二次调度"
)
# self.redispatch_to_dump(
i
, truck_dispatch, truck_locate, truck_trip)
# self.redispatch_to_dump(
truck_id
, truck_dispatch, truck_locate, truck_trip)
try
:
try
:
self
.
redispatcher
.
redispatch_to_dump
(
i
,
truck_dispatch
,
truck_locate
,
truck_trip
)
self
.
redispatcher
.
redispatch_to_dump
(
truck_id
,
truck_dispatch
,
truck_locate
,
truck_trip
)
except
Exception
as
es
:
except
Exception
as
es
:
self
.
logger
.
error
(
"二次调度至卸载点失败"
)
self
.
logger
.
error
(
"二次调度至卸载点失败"
)
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
es
)
...
@@ -635,21 +588,22 @@ class GroupDispatcher:
...
@@ -635,21 +588,22 @@ class GroupDispatcher:
else
:
else
:
try
:
try
:
if
i
in
self
.
group
.
truck
.
truck_excavator_bind
:
if
truck_id
in
self
.
group
.
truck
.
truck_excavator_bind
:
self
.
logger
.
info
(
"车辆存在绑定关系"
)
self
.
logger
.
info
(
"车辆存在绑定关系"
)
try
:
try
:
if
i
not
in
self
.
group
.
truck
.
truck_excavator_bind
:
if
truck_id
not
in
self
.
group
.
truck
.
truck_excavator_bind
:
raise
CoreException
(
102
,
f
'truck.group_excavators bind 中不存在 {
i
}'
)
raise
CoreException
(
102
,
f
'truck.group_excavators bind 中不存在 {
truck_id
}'
)
except
CoreException
as
es
:
except
CoreException
as
es
:
es
.
with_traceback_info
()
es
.
with_traceback_info
()
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
es
)
return
return
next_excavator_id
=
self
.
group
.
truck
.
truck_excavator_bind
[
i
]
next_excavator_id
=
self
.
group
.
truck
.
truck_excavator_bind
[
truck_id
]
else
:
else
:
self
.
logger
.
info
(
"触发调度算法逻辑"
)
self
.
logger
.
info
(
"触发调度算法逻辑"
)
next_excavator_value
=
s
.
solve
(
truck_info
)
next_excavator_value
=
s
.
solve
(
truck_info
)
self
.
logger
.
info
(
f
'车辆排斥修正 {i}, {self.group.truck_excavator_exclude_modify[i]}'
)
self
.
logger
.
info
(
f
'车辆排斥修正 {truck_id}, {self.group.truck_excavator_exclude_modify[truck_id]}'
)
min_index
=
np
.
argmin
(
next_excavator_value
+
self
.
group
.
truck_excavator_exclude_modify
[
i
])
min_index
=
np
.
argmin
(
next_excavator_value
+
self
.
group
.
truck_excavator_exclude_modify
[
truck_id
])
# min_index = np.argmin(next_excavator_value)
# min_index = np.argmin(next_excavator_value)
next_excavator_id
=
self
.
group
.
excavator_uuid_index_dict
.
inverse
[
min_index
]
next_excavator_id
=
self
.
group
.
excavator_uuid_index_dict
.
inverse
[
min_index
]
...
@@ -660,7 +614,7 @@ class GroupDispatcher:
...
@@ -660,7 +614,7 @@ class GroupDispatcher:
else
:
else
:
dump_id
=
get_value
(
"dump_index_to_uuid_dict"
)[
truck_trip
[
-
1
]]
dump_id
=
get_value
(
"dump_index_to_uuid_dict"
)[
truck_trip
[
-
1
]]
next_unload_area_id
=
get_value
(
"dump_uuid_to_unload_area_uuid_dict"
)[
dump_id
]
next_unload_area_id
=
get_value
(
"dump_uuid_to_unload_area_uuid_dict"
)[
dump_id
]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
truck_dispatch
[
truck_id
]
=
[
next_excavator_id
,
next_unload_area_id
]
self
.
logger
.
info
(
f
'调度结果 next_excavator_id: '
self
.
logger
.
info
(
f
'调度结果 next_excavator_id: '
f
'{next_excavator_id} next_unload_area_id: {next_unload_area_id}'
)
f
'{next_excavator_id} next_unload_area_id: {next_unload_area_id}'
)
...
@@ -676,18 +630,18 @@ class GroupDispatcher:
...
@@ -676,18 +630,18 @@ class GroupDispatcher:
self
.
logger
.
info
(
"潜在二次调度车辆状态"
)
self
.
logger
.
info
(
"潜在二次调度车辆状态"
)
# 车辆当前位于交叉路口前,且排队等待
# 车辆当前位于交叉路口前,且排队等待
self
.
logger
.
info
(
f
'车辆 {
i
}'
)
self
.
logger
.
info
(
f
'车辆 {
truck_name
}'
)
self
.
logger
.
info
(
f
'车辆位置 {truck_locate}'
)
self
.
logger
.
info
(
f
'车辆位置 {truck_locate}'
)
self
.
logger
.
info
(
f
'车辆状态 {self.group.truck.truck_current_state[
i
]}'
)
self
.
logger
.
info
(
f
'车辆状态 {self.group.truck.truck_current_state[
truck_id
]}'
)
self
.
logger
.
info
(
f
'车辆临时 {truck_is_temp}'
)
self
.
logger
.
info
(
f
'车辆临时 {truck_is_temp}'
)
self
.
logger
.
info
(
self
.
group
.
topo
.
cross_bf_lanes
)
self
.
logger
.
info
(
self
.
group
.
topo
.
cross_bf_lanes
)
self
.
logger
.
info
(
self
.
group
.
truck
.
truck_current_state
)
self
.
logger
.
info
(
self
.
group
.
truck
.
truck_current_state
)
if
(
truck_locate
in
self
.
group
.
topo
.
cross_bf_lanes
)
and
(
not
truck_is_temp
):
if
(
truck_locate
in
self
.
group
.
topo
.
cross_bf_lanes
)
and
(
not
truck_is_temp
):
self
.
logger
.
info
(
"触发二次调度"
)
self
.
logger
.
info
(
"触发二次调度"
)
# self.redispatch_to_excavator(i, truck_dispatch, truck_locate)
try
:
try
:
self
.
redispatcher
.
redispatch_to_excavator
(
i
,
truck_dispatch
,
truck_locate
)
self
.
redispatcher
.
redispatch_to_excavator
(
truck_id
,
truck_dispatch
,
truck_locate
,
truck_trip
,
truck_info
)
except
Exception
as
es
:
except
Exception
as
es
:
self
.
logger
.
error
(
"二次调度至装载点失败"
)
self
.
logger
.
error
(
"二次调度至装载点失败"
)
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
es
)
...
@@ -697,7 +651,7 @@ class GroupDispatcher:
...
@@ -697,7 +651,7 @@ class GroupDispatcher:
# 穿越装载区判断
# 穿越装载区判断
if
self
.
gothrough_active
:
if
self
.
gothrough_active
:
self
.
gothroghdispatcher
.
update_lanes_info
()
self
.
gothroghdispatcher
.
update_lanes_info
()
self
.
gothroghdispatcher
.
redispatch_request
(
request_truck_id
=
i
,
truck
=
self
.
group
.
truck
)
self
.
gothroghdispatcher
.
redispatch_request
(
request_truck_id
=
truck_id
,
truck
=
self
.
group
.
truck
)
else
:
else
:
self
.
logger
.
info
(
"正常空载行驶无需调度"
)
self
.
logger
.
info
(
"正常空载行驶无需调度"
)
else
:
else
:
...
@@ -705,10 +659,11 @@ class GroupDispatcher:
...
@@ -705,10 +659,11 @@ class GroupDispatcher:
next_excavator_id
=
get_value
(
"excavator_index_to_uuid_dict"
)[
truck_trip
[
-
1
]]
next_excavator_id
=
get_value
(
"excavator_index_to_uuid_dict"
)[
truck_trip
[
-
1
]]
next_unload_area_value
=
s
.
solve
(
truck_info
)
next_unload_area_value
=
s
.
solve
(
truck_info
)
if
i
in
self
.
group
.
truck
.
truck_dump_bind
:
if
truck_id
in
self
.
group
.
truck
.
truck_dump_bind
:
self
.
logger
.
info
(
"车辆存在绑定关系"
)
self
.
logger
.
info
(
"车辆存在绑定关系"
)
dump_uuid_to_unload_area_uuid_dict
=
get_value
(
"dump_uuid_to_unload_area_uuid_dict"
)
dump_uuid_to_unload_area_uuid_dict
=
get_value
(
"dump_uuid_to_unload_area_uuid_dict"
)
next_unload_area_id
=
dump_uuid_to_unload_area_uuid_dict
[
self
.
group
.
truck
.
truck_dump_bind
[
i
]]
next_unload_area_id
=
dump_uuid_to_unload_area_uuid_dict
[
self
.
group
.
truck
.
truck_dump_bind
[
truck_id
]]
else
:
else
:
self
.
logger
.
info
(
"触发调度算法逻辑"
)
self
.
logger
.
info
(
"触发调度算法逻辑"
)
next_unload_area_value
*=
self
.
group
.
group_walk_available
[
next_unload_area_value
*=
self
.
group
.
group_walk_available
[
...
@@ -720,7 +675,7 @@ class GroupDispatcher:
...
@@ -720,7 +675,7 @@ class GroupDispatcher:
self
.
logger
.
info
(
f
'目标卸点 {min_index} {next_unload_area_id}'
)
self
.
logger
.
info
(
f
'目标卸点 {min_index} {next_unload_area_id}'
)
# next_excavator_id = self.excavator_uuid_index_dict.inverse[truck_trip[-1]]
# next_excavator_id = self.excavator_uuid_index_dict.inverse[truck_trip[-1]]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
truck_dispatch
[
truck_id
]
=
[
next_excavator_id
,
next_unload_area_id
]
self
.
logger
.
info
(
f
'调度结果 next_excavator_id: '
self
.
logger
.
info
(
f
'调度结果 next_excavator_id: '
f
'{next_excavator_id} next_unload_area_id: {next_unload_area_id}'
)
f
'{next_excavator_id} next_unload_area_id: {next_unload_area_id}'
)
...
@@ -729,10 +684,106 @@ class GroupDispatcher:
...
@@ -729,10 +684,106 @@ class GroupDispatcher:
self
.
logger
.
error
(
"空载车辆全智能模式-计算异常"
)
self
.
logger
.
error
(
"空载车辆全智能模式-计算异常"
)
self
.
logger
.
error
(
es
.
__traceback__
.
tb_lineno
)
self
.
logger
.
error
(
es
.
__traceback__
.
tb_lineno
)
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
es
)
truck_dispatch
[
i
]
=
[
None
,
None
]
truck_dispatch
[
truck_id
]
=
[
None
,
None
]
# TODO:车辆在空载状态是否应该如何计算,是计算下一次卸载区还是继续计算当前最优挖机
# TODO:车辆在空载状态是否应该如何计算,是计算下一次卸载区还是继续计算当前最优挖机
def
truck_construct
(
self
,
truck_id
):
"""
Construct truck obj. for each physical mining truck within dispatching info.
and store them in a dictionary.
"""
self
.
logger
.
info
(
f
'调度车辆 {truck_id}'
)
# try:
# get truck index from mapping
if
truck_id
not
in
self
.
group
.
truck
.
truck_uuid_to_index_dict
:
self
.
logger
.
error
(
f
'truck.truck dict 中不存在 {truck_id}'
)
return
None
else
:
truck_idx
=
self
.
group
.
truck
.
truck_uuid_to_index_dict
[
truck_id
]
# get truck trip from truck obj.
truck_trip_info_list
=
self
.
group
.
truck
.
get_truck_current_trip
()
if
truck_idx
>=
len
(
truck_trip_info_list
):
self
.
logger
.
error
(
f
'truck.truck trip 中不存在 {truck_idx} 号矿卡 {truck_id}'
)
return
None
else
:
truck_trip
=
self
.
group
.
truck
.
get_truck_current_trip
()[
truck_idx
]
# get truck task from truck obj.
truck_task_list
=
self
.
group
.
truck
.
get_truck_current_task
()
if
truck_id
not
in
truck_task_list
:
self
.
logger
.
error
(
f
'truck.truck task 中不存在矿卡 {truck_id}'
)
return
None
else
:
truck_task
=
truck_task_list
[
truck_id
]
# get truck lane_id from truck obj.
truck_lane_locate_dict
=
self
.
group
.
truck
.
get_truck_lane_locate_dict
()
if
truck_id
not
in
truck_lane_locate_dict
:
self
.
logger
.
warning
(
f
'truck.truck lane dict 中不存在矿卡 {truck_id}'
)
# continue
truck_lane_locate
=
None
else
:
truck_lane_locate
=
truck_lane_locate_dict
[
truck_id
]
# get truck name form dict.
truck_uuid_to_name_dict
=
get_value
(
"truck_uuid_to_name_dict"
)
# 获取请调车辆名
if
truck_id
not
in
truck_uuid_to_name_dict
:
# raise CoreException(102, f'truck_uuid_to_name_dict 缺失车辆 {truck_id} 信息')
self
.
logger
.
error
(
f
'truck_uuid_to_name_dict 缺失车辆 {truck_id} 信息'
)
truck_name
=
truck_uuid_to_name_dict
[
truck_id
]
# 获取车辆当前派车计划
if
truck_task
in
[
0
,
1
,
5
]:
excavator_index
=
int
(
truck_trip
[
1
])
dump_index
=
int
(
truck_trip
[
0
])
else
:
dump_index
=
int
(
truck_trip
[
1
])
excavator_index
=
int
(
truck_trip
[
0
])
if
excavator_index
==
-
1
:
current_truck_goto_excavator_id
=
None
current_load_area_id
=
None
else
:
# if excavator_index not in self.group.excavator_info.excavator_index_to_uuid_dict:
# # raise CoreException(111, f'excavator_index_to_uuid_dict 缺失 {excavator_index} 号挖机信息')
# self.logger.error(f'excavator_index_to_uuid_dict 缺失 {excavator_index} 号挖机信息')
current_truck_goto_excavator_id
=
self
.
group
.
excavator_info
.
excavator_index_to_uuid_dict
[
excavator_index
]
current_load_area_id
=
DispatchInfo
.
excavator_load_dict
[
current_truck_goto_excavator_id
]
if
dump_index
==
-
1
:
current_truck_goto_dump_id
=
None
current_unload_area_id
=
None
else
:
# if dump_index not in self.group.dump_info.dump_index_to_uuid_dict:
# # raise CoreException(111, f'dump_index_to_uuid_dict 缺失 {dump_index} 号卸点信息')
# self.logger.error(f'dump_index_to_uuid_dict 缺失 {dump_index} 号卸点信息')
current_truck_goto_dump_id
=
self
.
group
.
dump_info
.
dump_index_to_uuid_dict
[
dump_index
]
current_unload_area_id
=
DispatchInfo
.
dump_unload_area_dict
[
current_truck_goto_dump_id
]
# Construct a truck obj. and add it to group truck dictionary.
truck_info
=
CurrentTruck
(
truck_id
,
self
.
group
.
group_id
,
truck_trip
,
truck_task
,
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
)
self
.
group
.
truck_info_list
[
truck_id
]
=
truck_info
return
truck_info
# def redispatch_to_dump(self, truck_id: str, truck_dispatch: Mapping[str, List[str]], truck_locate: str, truck_trip: List[int]):
# def redispatch_to_dump(self, truck_id: str, truck_dispatch: Mapping[str, List[str]], truck_locate: str, truck_trip: List[int]):
# """
# """
# redispatch truck to dumps.
# redispatch truck to dumps.
...
@@ -904,11 +955,13 @@ class ReDispatcher:
...
@@ -904,11 +955,13 @@ class ReDispatcher:
"""
"""
redispatch controller
redispatch controller
"""
"""
def
__init__
(
self
,
group
:
Group
):
def
__init__
(
self
,
group
:
Group
):
self
.
logger
=
get_logger
(
"zxt.ReDispatcher"
)
self
.
logger
=
get_logger
(
"zxt.ReDispatcher"
)
self
.
group
=
group
self
.
group
=
group
def
redispatch_to_excavator
(
self
,
truck_id
:
str
,
truck_dispatch
:
Mapping
[
str
,
List
[
str
]],
truck_locate
:
str
):
def
redispatch_to_excavator
(
self
,
truck_id
:
str
,
truck_dispatch
:
Mapping
[
str
,
List
[
str
]],
truck_locate
:
str
,
truck_trip
:
List
[
int
],
truck_info
:
CurrentTruck
):
"""
"""
redispatch truck to excavators.
redispatch truck to excavators.
:param truck_id:
:param truck_id:
...
@@ -916,23 +969,31 @@ class ReDispatcher:
...
@@ -916,23 +969,31 @@ class ReDispatcher:
:param truck_locate:
:param truck_locate:
:return:
:return:
"""
"""
# 当前绑定卸载区
# 当前绑定卸载区
#
if truck_trip[0] == -1:
if
truck_trip
[
0
]
==
-
1
:
nex
t_unload_area_id
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
truck_id
,
curren
t_unload_area_id
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
truck_id
,
isdeleted
=
0
)
.
first
()
.
unload_area_id
isdeleted
=
0
)
.
first
()
.
unload_area_id
#
else:
else
:
# dump_id = get_value("dump_index_to_uuid_dict")[truck_trip[0]]
# dump_id = get_value("dump_index_to_uuid_dict")[truck_trip[0]]
# next_unload_area_id = get_value("dump_uuid_to_unload_area_uuid_dict")[dump_id]
# current_unload_area_id = get_value("dump_uuid_to_unload_area_uuid_dict")[dump_id]
current_unload_area_id
=
truck_info
.
get_combined_unload_area
()
# 当前绑定装载区
# 当前绑定装载区
#
if truck_trip[-1] == -1:
if
truck_trip
[
-
1
]
==
-
1
:
item
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
truck_id
,
isdeleted
=
0
)
.
first
()
item
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
truck_id
,
isdeleted
=
0
)
.
first
()
current_excavator_id
=
item
.
exactor_id
current_excavator_id
=
item
.
exactor_id
current_load_area_id
=
item
.
load_area_id
current_load_area_id
=
item
.
load_area_id
self
.
logger
.
info
(
f
'truck_id {truck_id}'
)
else
:
self
.
logger
.
info
(
f
'current_load_area_id {current_load_area_id}'
)
# else:
# current_excavator_id = get_value("excavator_index_to_uuid_dict")[truck_trip[-1]]
# current_excavator_id = get_value("excavator_index_to_uuid_dict")[truck_trip[-1]]
# current_load_area_id = DispatchInfo.excavator_load_dict[current_excavator_id]
# current_load_area_id = DispatchInfo.excavator_load_dict[current_excavator_id]
current_excavator_id
=
truck_info
.
get_combined_excavator
()
current_load_area_id
=
truck_info
.
get_combined_load_area
()
self
.
logger
.
info
(
current_load_area_id
)
self
.
logger
.
info
(
f
'truck_id {truck_id}'
)
self
.
logger
.
info
(
f
'current_excavator_id {current_excavator_id}'
)
load_area_dict
,
load_area_lane_dict
=
self
.
group
.
topo
.
get_load_target_node_real
(
truck_locate
,
load_area_dict
,
load_area_lane_dict
=
self
.
group
.
topo
.
get_load_target_node_real
(
truck_locate
,
current_load_area_id
,
True
)
current_load_area_id
,
True
)
# TODO:topo 放到 group 里面不太合理
# TODO:topo 放到 group 里面不太合理
...
@@ -953,11 +1014,18 @@ class ReDispatcher:
...
@@ -953,11 +1014,18 @@ class ReDispatcher:
# 获取最佳挖机
# 获取最佳挖机
best_excavator_id
=
self
.
get_best_excavator
(
current_excavator_id
,
truck_id
,
load_area_dict
)
best_excavator_id
=
self
.
get_best_excavator
(
current_excavator_id
,
truck_id
,
load_area_dict
)
next_excavator_id
=
best_excavator_id
next_excavator_id
=
best_excavator_id
truck_dispatch
[
truck_id
]
=
[
next_excavator_id
,
next_unload_area_id
]
if
next_excavator_id
==
current_excavator_id
:
truck_dispatch
[
truck_id
]
=
[
next_excavator_id
,
current_unload_area_id
]
self
.
logger
.
info
(
f
'二次调度结果 {truck_id}'
)
self
.
logger
.
info
(
f
'二次调度结果 {truck_id}'
)
self
.
logger
.
info
(
truck_dispatch
[
truck_id
])
self
.
logger
.
info
(
truck_dispatch
[
truck_id
])
def
redispatch_to_dump
(
self
,
truck_id
:
str
,
truck_dispatch
:
Mapping
[
str
,
List
[
str
]],
truck_locate
:
str
,
truck_trip
:
List
[
int
]):
else
:
self
.
logger
.
info
(
f
'二次调度未变更'
)
def
redispatch_to_dump
(
self
,
truck_id
:
str
,
truck_dispatch
:
Mapping
[
str
,
List
[
str
]],
truck_locate
:
str
,
truck_trip
:
List
[
int
],
truck_info
:
CurrentTruck
):
"""
"""
redispatch truck to dumps.
redispatch truck to dumps.
:param truck_id:
:param truck_id:
...
@@ -966,20 +1034,24 @@ class ReDispatcher:
...
@@ -966,20 +1034,24 @@ class ReDispatcher:
:param truck_trip:
:param truck_trip:
:return:
:return:
"""
"""
# 当前绑定装载区
# 当前绑定装载区
if
truck_trip
[
0
]
==
-
1
:
if
truck_trip
[
0
]
==
-
1
:
nex
t_excavator_id
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
truck_id
,
curren
t_excavator_id
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
truck_id
,
isdeleted
=
0
)
.
first
()
.
exactor_id
isdeleted
=
0
)
.
first
()
.
exactor_id
else
:
else
:
nex
t_excavator_id
=
get_value
(
"excavator_index_to_uuid_dict"
)[
truck_trip
[
0
]]
curren
t_excavator_id
=
get_value
(
"excavator_index_to_uuid_dict"
)[
truck_trip
[
0
]]
# 当前绑定卸载区
# 当前绑定卸载区
if
truck_trip
[
-
1
]
==
-
1
:
if
truck_trip
[
-
1
]
==
-
1
:
item
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
truck_id
,
isdeleted
=
0
)
.
first
()
item
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
truck_id
,
isdeleted
=
0
)
.
first
()
current_dump_id
=
item
.
dump_id
current_dump_id
=
item
.
dump_id
current_unload_area_id
=
item
.
unload_area_id
current_unload_area_id
=
item
.
unload_area_id
else
:
else
:
current_dump_id
=
get_value
(
"dump_index_to_uuid_dict"
)[
truck_trip
[
-
1
]]
# current_dump_id = get_value("dump_index_to_uuid_dict")[truck_trip[-1]]
current_unload_area_id
=
DispatchInfo
.
dump_unload_area_dict
[
current_dump_id
]
# current_unload_area_id = DispatchInfo.dump_unload_area_dict[current_dump_id]
current_dump_id
=
truck_info
.
get_combined_dump
()
current_unload_area_id
=
truck_info
.
get_combined_unload_area
()
unload_area_dict
,
unload_area_lane_dict
=
self
.
group
.
topo
.
get_unload_target_node_real
(
truck_locate
,
unload_area_dict
,
unload_area_lane_dict
=
self
.
group
.
topo
.
get_unload_target_node_real
(
truck_locate
,
current_unload_area_id
,
current_unload_area_id
,
True
)
True
)
...
@@ -993,10 +1065,27 @@ class ReDispatcher:
...
@@ -993,10 +1065,27 @@ class ReDispatcher:
# 排除下一个路段阻塞的装载区
# 排除下一个路段阻塞的装载区
delete_congestion_load_area
(
congestion_lane_dict
,
unload_area_dict
,
delete_congestion_load_area
(
congestion_lane_dict
,
unload_area_dict
,
next_lane_load_area_dict
)
next_lane_load_area_dict
)
best_dump_id
=
self
.
get_best_dump
(
current_dump_id
,
unload_area_dict
)
next_unload_area_id
=
DispatchInfo
.
dump_unload_area_dict
[
best_dump_id
]
if
next_unload_area_id
==
current_unload_area_id
:
truck_dispatch
[
truck_id
]
=
[
current_excavator_id
,
next_unload_area_id
]
self
.
logger
.
info
(
f
'二次调度结果 {truck_id}'
)
self
.
logger
.
info
(
truck_dispatch
[
truck_id
])
# res = redispatch_request(truck_id, next_excavator_id, next_unload_area_id)
# self.logger.info(res)
else
:
self
.
logger
.
info
(
f
'二次调度未变更'
)
def
get_best_dump
(
self
,
current_dump_id
,
unload_area_dict
):
min_trip_time
=
10000000
min_trip_time
=
10000000
best_dump_id
=
current_dump_id
best_dump_id
=
current_dump_id
try
:
for
unload_area
,
value
in
unload_area_dict
.
items
():
for
unload_area
,
value
in
unload_area_dict
.
items
():
# 车辆不需要掉头
# 车辆不需要掉头
if
unload_area
in
self
.
group
.
group_unload_areas
:
if
value
[
-
1
]
==
1
and
unload_area
in
DispatchInfo
.
unload_area_dump_dict
:
if
value
[
-
1
]
==
1
and
unload_area
in
DispatchInfo
.
unload_area_dump_dict
:
dump_id
=
DispatchInfo
.
unload_area_dump_dict
[
unload_area
]
dump_id
=
DispatchInfo
.
unload_area_dump_dict
[
unload_area
]
...
@@ -1012,12 +1101,15 @@ class ReDispatcher:
...
@@ -1012,12 +1101,15 @@ class ReDispatcher:
if
min_trip_time
>
trip_time
:
if
min_trip_time
>
trip_time
:
best_dump_id
=
dump_id
best_dump_id
=
dump_id
next_unload_area_id
=
DispatchInfo
.
dump_unload_area_dict
[
best_dump_id
]
min_trip_time
=
trip_time
truck_dispatch
[
truck_id
]
=
[
next_excavator_id
,
next_unload_area_id
]
else
:
# res = redispatch_request(truck_id, next_excavator_id, next_unload_area_id)
continue
# self.logger.info(res)
except
Exception
as
es
:
self
.
logger
.
info
(
f
'二次调度结果 {truck_id}'
)
self
.
logger
.
error
(
"寻找最佳卸载区异常"
)
self
.
logger
.
info
(
truck_dispatch
[
truck_id
])
self
.
logger
.
error
(
f
'exception {es}'
)
self
.
logger
.
error
(
f
'in line {es.__traceback__.tb_lineno}'
)
return
best_dump_id
def
get_best_excavator
(
self
,
current_excavator_id
:
str
,
truck_id
:
str
,
load_area_dict
):
def
get_best_excavator
(
self
,
current_excavator_id
:
str
,
truck_id
:
str
,
load_area_dict
):
"""
"""
...
@@ -1031,11 +1123,15 @@ class ReDispatcher:
...
@@ -1031,11 +1123,15 @@ class ReDispatcher:
best_excavator_id
=
current_excavator_id
best_excavator_id
=
current_excavator_id
try
:
try
:
for
load_area
,
value
in
load_area_dict
.
items
():
for
load_area
,
value
in
load_area_dict
.
items
():
# 车辆不需要掉头
# 车辆不需要掉头
if
load_area
in
DispatchInfo
.
load_excavator_dict
:
if
load_area
in
DispatchInfo
.
load_excavator_dict
:
excavator_id
=
DispatchInfo
.
load_excavator_dict
[
load_area
]
excavator_id
=
DispatchInfo
.
load_excavator_dict
[
load_area
]
else
:
else
:
continue
continue
if
excavator_id
in
self
.
group
.
group_excavators
:
if
value
[
-
1
]
==
1
and
excavator_id
in
self
.
group
.
group_excavators
:
if
value
[
-
1
]
==
1
and
excavator_id
in
self
.
group
.
group_excavators
:
traveling_time
=
60
*
(
value
[
0
]
/
1000
)
/
empty_speed
traveling_time
=
60
*
(
value
[
0
]
/
1000
)
/
empty_speed
...
@@ -1049,13 +1145,16 @@ class ReDispatcher:
...
@@ -1049,13 +1145,16 @@ class ReDispatcher:
self
.
logger
.
info
(
f
'reach_time {reach_time}'
)
self
.
logger
.
info
(
f
'reach_time {reach_time}'
)
trip_time
=
max
(
reach_time
,
self
.
group
.
pre_sch
.
get_excavator_avl_time
(
truck_id
=
truck_id
)[
excavator_id
])
-
now
trip_time
=
max
(
reach_time
,
self
.
group
.
pre_sch
.
get_excavator_avl_time
(
truck_id
=
truck_id
)[
excavator_id
])
-
now
self
.
logger
.
info
(
f
'trip_time {trip_time}'
)
self
.
logger
.
info
(
f
'trip_time {trip_time}'
)
if
min_trip_time
>
trip_time
:
if
min_trip_time
>
trip_time
:
best_excavator_id
=
excavator_id
best_excavator_id
=
excavator_id
min_trip_time
=
trip_time
min_trip_time
=
trip_time
else
:
continue
except
Exception
as
es
:
except
Exception
as
es
:
self
.
logger
.
error
(
"寻找最佳装载区异常"
)
self
.
logger
.
error
(
"寻找最佳装载区异常"
)
...
@@ -1080,6 +1179,7 @@ class GoThroughDispatcher:
...
@@ -1080,6 +1179,7 @@ class GoThroughDispatcher:
"""
"""
go through load areas controller
go through load areas controller
"""
"""
def
__init__
(
self
,
group
:
Group
):
def
__init__
(
self
,
group
:
Group
):
self
.
logger
=
get_logger
(
"zxt.GoThroughDispatcher"
)
self
.
logger
=
get_logger
(
"zxt.GoThroughDispatcher"
)
self
.
group
=
group
self
.
group
=
group
...
@@ -1092,10 +1192,12 @@ class GoThroughDispatcher:
...
@@ -1092,10 +1192,12 @@ class GoThroughDispatcher:
gothrough_config
=
load_value
[
"gothrough"
]
gothrough_config
=
load_value
[
"gothrough"
]
self
.
closer_area_name
=
gothrough_config
[
"closer_area_name"
]
self
.
closer_area_name
=
gothrough_config
[
"closer_area_name"
]
self
.
closer_area_id
=
str
(
session_postgre
.
query
(
DiggingWorkArea
)
.
filter_by
(
Name
=
self
.
closer_area_name
)
.
first
()
.
Id
)
self
.
closer_area_id
=
str
(
session_postgre
.
query
(
DiggingWorkArea
)
.
filter_by
(
Name
=
self
.
closer_area_name
)
.
first
()
.
Id
)
self
.
further_area_name
=
gothrough_config
[
"further_area_name"
]
self
.
further_area_name
=
gothrough_config
[
"further_area_name"
]
self
.
further_area_id
=
str
(
session_postgre
.
query
(
DiggingWorkArea
)
.
filter_by
(
Name
=
self
.
further_area_name
)
.
first
()
.
Id
)
self
.
further_area_id
=
str
(
session_postgre
.
query
(
DiggingWorkArea
)
.
filter_by
(
Name
=
self
.
further_area_name
)
.
first
()
.
Id
)
self
.
logger
.
info
(
"近端装载区id"
)
self
.
logger
.
info
(
"近端装载区id"
)
self
.
logger
.
info
(
self
.
closer_area_id
)
self
.
logger
.
info
(
self
.
closer_area_id
)
...
@@ -1110,8 +1212,10 @@ class GoThroughDispatcher:
...
@@ -1110,8 +1212,10 @@ class GoThroughDispatcher:
self
.
logger
.
info
(
self
.
further_area_id
in
DispatchInfo
.
load_excavator_dict
)
self
.
logger
.
info
(
self
.
further_area_id
in
DispatchInfo
.
load_excavator_dict
)
if
(
self
.
closer_area_id
in
DispatchInfo
.
load_excavator_dict
)
and
\
if
(
self
.
closer_area_id
in
DispatchInfo
.
load_excavator_dict
)
and
\
(
self
.
further_area_id
in
DispatchInfo
.
load_excavator_dict
):
(
self
.
further_area_id
in
DispatchInfo
.
load_excavator_dict
):
self
.
closer_excavator_id
,
self
.
further_excavator_id
=
DispatchInfo
.
load_excavator_dict
[
self
.
closer_area_id
],
\
self
.
closer_excavator_id
,
self
.
further_excavator_id
=
DispatchInfo
.
load_excavator_dict
[
DispatchInfo
.
load_excavator_dict
[
self
.
further_area_id
]
self
.
closer_area_id
],
\
DispatchInfo
.
load_excavator_dict
[
self
.
further_area_id
]
else
:
else
:
self
.
logger
.
error
(
"装载点信息错误"
)
self
.
logger
.
error
(
"装载点信息错误"
)
return
return
...
@@ -1183,12 +1287,12 @@ class GoThroughDispatcher:
...
@@ -1183,12 +1287,12 @@ class GoThroughDispatcher:
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
es
)
return
return
self
.
logger
.
info
(
"cross_lane"
)
self
.
logger
.
info
(
"cross_lane"
)
self
.
logger
.
info
(
cross_lane
)
self
.
logger
.
info
(
cross_lane
)
# 截取远端入场点到交叉口的路段
# 截取远端入场点到交叉口的路段
self
.
further_area_backtrack_lanes
=
self
.
further_area_backtrack_lanes
[
0
:
self
.
further_area_backtrack_lanes
.
index
(
cross_lane
)]
self
.
further_area_backtrack_lanes
=
self
.
further_area_backtrack_lanes
[
0
:
self
.
further_area_backtrack_lanes
.
index
(
cross_lane
)]
# 穿越装载区检查路段
# 穿越装载区检查路段
self
.
gothrough_check_lanes
=
[
cross_lane
]
self
.
gothrough_check_lanes
=
[
cross_lane
]
...
@@ -1206,7 +1310,6 @@ class GoThroughDispatcher:
...
@@ -1206,7 +1310,6 @@ class GoThroughDispatcher:
self
.
logger
.
error
(
"穿越装载区交叉口判断异常"
)
self
.
logger
.
error
(
"穿越装载区交叉口判断异常"
)
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
es
)
def
redispatch_request
(
self
,
request_truck_id
:
str
,
truck
:
TruckInfo
):
def
redispatch_request
(
self
,
request_truck_id
:
str
,
truck
:
TruckInfo
):
# 调度开始时间
# 调度开始时间
...
@@ -1250,58 +1353,6 @@ class GoThroughDispatcher:
...
@@ -1250,58 +1353,6 @@ class GoThroughDispatcher:
self
.
logger
.
error
(
"车辆位置信息读取异常"
)
self
.
logger
.
error
(
"车辆位置信息读取异常"
)
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
es
)
# try:
#
# with open(json_file, encoding='UTF-8') as f:
# load_value = json.load(f)
# gothrough_config = load_value["gothrough"]
#
# closer_area_name = gothrough_config["closer_area_name"]
# closer_area_id = str(session_postgre.query(DiggingWorkArea).filter_by(Name=closer_area_name).first().Id)
#
# further_area_name =gothrough_config["further_area_name"]
# further_area_id = str(session_postgre.query(DiggingWorkArea).filter_by(Name=further_area_name).first().Id)
#
# self.logger.info("近端装载区id")
# self.logger.info(closer_area_id)
# self.logger.info("远端装载区id")
# self.logger.info(further_area_id)
#
# self.logger.info("DispatchInfo.load_excavator_dict")
# self.logger.info(DispatchInfo.load_excavator_dict)
#
# # 读取两个挖机id
# self.logger.info(closer_area_id in DispatchInfo.load_excavator_dict)
# self.logger.info(further_area_id in DispatchInfo.load_excavator_dict)
# if (closer_area_id in DispatchInfo.load_excavator_dict) and \
# (further_area_id in DispatchInfo.load_excavator_dict):
# closer_excavator_id, further_excavator_id = DispatchInfo.load_excavator_dict[closer_area_id], \
# DispatchInfo.load_excavator_dict[further_area_id]
# else:
# self.logger.error("装载点信息错误")
# return
#
# # 读取挖机状态
# closer_excavator_state, further_excavator_state = get_excavator_state(closer_excavator_id), \
# get_excavator_state(further_excavator_id)
#
# # 读取两个装载区入场点id
# closer_entrance_node_id = session_postgre.query(DiggingWorkArea).filter_by(
# Id=closer_area_id).first().EntranceNodeId
#
# further_entrance_node_id = session_postgre.query(DiggingWorkArea).filter_by(
# Id=further_area_id).first().EntranceNodeId
#
# self.logger.info("近端装载区入场点")
# self.logger.info(closer_entrance_node_id)
# self.logger.info("远端装载区入场点")
# self.logger.info(further_entrance_node_id)
#
# except Exception as es:
# self.logger.error("读取装载区及车辆信息异常")
# self.logger.error(es)
# return
try
:
try
:
# 读取请调车辆所在路段信息
# 读取请调车辆所在路段信息
request_truck_lane_id
=
truck_locates_dict
[
request_truck_id
]
request_truck_lane_id
=
truck_locates_dict
[
request_truck_id
]
...
@@ -1321,7 +1372,7 @@ class GoThroughDispatcher:
...
@@ -1321,7 +1372,7 @@ class GoThroughDispatcher:
# try:
# try:
# further_area_backtrack_node_id = further_entrance_node_id
# further_area_backtrack_node_id = further_entrance_node_id
# further_area_backtrack_lanes = []
# further_area_backtrack_lanes = []
# for
i
in range(5):
# for
truck_id
in range(5):
# # 查询回溯路段对象
# # 查询回溯路段对象
# item = session_postgre.query(Lane).filter_by(EndNodeId=further_area_backtrack_node_id).first()
# item = session_postgre.query(Lane).filter_by(EndNodeId=further_area_backtrack_node_id).first()
# if item is None:
# if item is None:
...
@@ -1339,7 +1390,7 @@ class GoThroughDispatcher:
...
@@ -1339,7 +1390,7 @@ class GoThroughDispatcher:
# lowest_common_ancestor = None
# lowest_common_ancestor = None
# closer_area_backtrack_node_id = closer_entrance_node_id
# closer_area_backtrack_node_id = closer_entrance_node_id
# closer_area_backtrack_lanes = []
# closer_area_backtrack_lanes = []
# for
i
in range(5):
# for
truck_id
in range(5):
# # 查询回溯路段对象
# # 查询回溯路段对象
# item = session_postgre.query(Lane).filter_by(EndNodeId=closer_area_backtrack_node_id).first()
# item = session_postgre.query(Lane).filter_by(EndNodeId=closer_area_backtrack_node_id).first()
# if item is None:
# if item is None:
...
@@ -1407,8 +1458,10 @@ class GoThroughDispatcher:
...
@@ -1407,8 +1458,10 @@ class GoThroughDispatcher:
target_excavator
=
None
target_excavator
=
None
try
:
try
:
target_excavator
=
area_choose
(
excavators_id
,
self
.
closer_area_id
,
self
.
further_area_id
,
target_excavator
=
area_choose
(
excavators_id
,
self
.
closer_area_id
,
self
.
further_area_id
,
self
.
further_area_backtrack_lanes
,
self
.
closer_area_backtrack_lanes
,
self
.
logger
,
self
.
further_area_backtrack_lanes
,
self
.
closer_area_backtrack_lanes
,
truck
,
truck_locates_dict
,
self
.
closer_excavator_state
,
self
.
further_excavator_state
)
self
.
logger
,
truck
,
truck_locates_dict
,
self
.
closer_excavator_state
,
self
.
further_excavator_state
)
except
Exception
as
es
:
except
Exception
as
es
:
logger
.
error
(
"寻找最优装载区异常"
)
logger
.
error
(
"寻找最优装载区异常"
)
logger
.
error
(
es
)
logger
.
error
(
es
)
...
...
core/submit.py
View file @
edc1105f
...
@@ -135,8 +135,10 @@ class DispatchSubmission:
...
@@ -135,8 +135,10 @@ class DispatchSubmission:
# if truck_id in self.truck.truck_is_temp and not self.truck.truck_is_temp[truck_id]:
# if truck_id in self.truck.truck_is_temp and not self.truck.truck_is_temp[truck_id]:
self
.
logger
.
info
(
"二次调度前往卸载区"
)
self
.
logger
.
info
(
"二次调度前往卸载区"
)
record
[
"isTemp"
]
=
True
# 避免反复修改
record
[
"isTemp"
]
=
True
# 避免反复修改
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
POST
(
truck_id
)
POST
(
truck_id
)
# else:
# else:
# self.logger.info("车辆已完成二次调度-无需更改派车计划")
# self.logger.info("车辆已完成二次调度-无需更改派车计划")
...
@@ -198,9 +200,11 @@ class DispatchSubmission:
...
@@ -198,9 +200,11 @@ class DispatchSubmission:
# if truck_id in self.truck.truck_is_temp and not self.truck.truck_is_temp[truck_id]:
# if truck_id in self.truck.truck_is_temp and not self.truck.truck_is_temp[truck_id]:
self
.
logger
.
info
(
"二次调度前往装载区"
)
self
.
logger
.
info
(
"二次调度前往装载区"
)
record
[
"isTemp"
]
=
True
# 避免反复修改
record
[
"isTemp"
]
=
True
# 避免反复修改
POST
(
truck_id
)
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
POST
(
truck_id
)
# else:
# else:
# self.logger.info("车辆已完成二次调度-无需更改派车计划")
# self.logger.info("车辆已完成二次调度-无需更改派车计划")
# except Exception as es:
# except Exception as es:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment