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
4cca50a5
Commit
4cca50a5
authored
Sep 15, 2022
by
张晓彤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
二次调度问题修复
parent
7856246e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
391 additions
and
262 deletions
+391
-262
algorithm.py
alg/algorithm.py
+3
-3
dispatcher.py
core/dispatcher.py
+1
-0
group.py
core/group.py
+327
-252
schedule.py
core/schedule.py
+7
-5
util.py
core/util.py
+34
-0
truck.py
equipment/truck.py
+1
-1
topo_graph.py
graph/topo_graph.py
+18
-1
No files found.
alg/algorithm.py
View file @
4cca50a5
...
...
@@ -190,7 +190,7 @@ class ExpectedTime(AlgorithmBase):
# 挖机可用时间
excavator_val_time_global
=
self
.
pre_sch
.
get_excavator_avl_time
()
excavator_val_time
=
np
.
full
(
len
(
self
.
group
.
excavator
),
0
)
excavator_val_time
=
np
.
full
(
len
(
self
.
group
.
excavator
),
0
.0
)
for
excavator_id
,
excavator_index
in
self
.
group
.
excavator_uuid_index_dict
.
items
():
excavator_val_time
[
excavator_index
]
=
excavator_val_time_global
[
excavator_id
]
...
...
@@ -222,7 +222,7 @@ class ExpectedTime(AlgorithmBase):
# self.logger.error(es)
# transport_value = np.zeros(group_dynamic_excavator_num)
if
task
in
[
0
,
1
,
2
]:
if
task
in
[
1
,
2
]:
################################################ 矿卡空载 ###############################################
try
:
...
...
@@ -276,7 +276,7 @@ class ExpectedTime(AlgorithmBase):
self
.
logger
.
error
(
es
)
transport_value
=
np
.
zeros
(
group_dynamic_unload_area_num
)
elif
task
in
[
3
,
4
,
5
]:
elif
task
in
[
4
,
5
]:
################################################ 矿卡重载 ###############################################
try
:
...
...
core/dispatcher.py
View file @
4cca50a5
...
...
@@ -89,6 +89,7 @@ class Dispatcher:
self
.
logger
.
error
(
f
'分组{group.group_id} 调度异常'
)
self
.
logger
.
info
(
f
'调度分组: {group.group_id} {DispatchInfo.group_name[group.group_id]}'
)
self
.
logger
.
info
(
f
'组内车辆 {group.truck_set}'
)
self
.
logger
.
info
(
"组内挖机"
)
self
.
logger
.
info
(
group
.
excavator
)
self
.
logger
.
info
(
"组内卸点"
)
...
...
core/group.py
View file @
4cca50a5
...
...
@@ -8,11 +8,11 @@
from
data.dispatchInfo
import
*
from
bidict
import
bidict
from
alg.algorithm
import
AlgorithmBase
,
DistributionRatio
from
alg.algorithm
import
AlgorithmBase
,
DistributionRatio
import
numpy
as
np
# from settings import get_logger
from
data.para_config
import
get_value
from
core.util
import
POST
from
core.util
import
*
class
CurrentTruck
:
...
...
@@ -129,7 +129,6 @@ class Group:
self
.
logger
.
info
(
f
'group excavator {self.excavator}'
)
self
.
logger
.
info
(
f
'group dump {self.dump}'
)
def
update_group_road_network
(
self
):
"""
update group road network.
...
...
@@ -279,6 +278,13 @@ class Group:
truck_task
=
self
.
truck
.
get_truck_current_task
()[
i
]
truck_info
=
CurrentTruck
(
i
,
self
.
group_id
,
truck_trip
,
truck_task
)
self
.
truck_info_list
[
i
]
=
truck_info
# truck_task = 0
# if i != "f704aa5e-24d9-4822-b634-ae81ca5ff0be":
# self.truck.get_truck_locate_dict()[i] = "8961f641-c134-8be8-f4eb-95e6e2c374b7"
# self.truck.truck_is_temp[i] = False
# self.truck.truck_current_state[i] = 2
except
Exception
as
es
:
self
.
logger
.
error
(
"车辆调度信息读取异常"
)
self
.
logger
.
error
(
es
)
...
...
@@ -289,230 +295,11 @@ class Group:
try
:
# 全智能模式
if
self
.
group_mode
==
1
:
# 车辆停止或者车辆位于装载区内, 调度车辆前往卸载区
if
truck_task
in
[
-
2
,
1
,
2
]:
try
:
if
i
in
self
.
truck
.
truck_excavator_bind
:
next_excavator_id
=
self
.
truck
.
truck_excavator_bind
[
i
]
else
:
next_excavator_value
=
s
.
solve
(
truck_info
)
# next_excavator_value = s.solve(i, truck_task, truck_trip)
# min_index = next_excavator_list.index(min(next_excavator_list))
min_index
=
np
.
argmin
(
next_excavator_value
)
next_excavator_id
=
self
.
excavator_uuid_index_dict
.
inverse
[
min_index
]
if
truck_task
==
-
2
:
next_unload_area_id
=
"Park"
else
:
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
]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
except
Exception
as
es
:
self
.
logger
.
error
(
"重载车辆全智能模式-计算异常"
)
self
.
logger
.
error
(
es
)
# 车辆位于卸载区内, 调度车辆前往装载区
elif
truck_task
in
[
4
,
5
]:
try
:
next_excavator_id
=
get_value
(
"excavator_index_to_uuid_dict"
)[
truck_trip
[
-
1
]]
next_unload_area_value
=
s
.
solve
(
truck_info
)
self
.
logger
.
info
(
f
'车辆 {i}'
)
self
.
logger
.
info
(
f
'group distance {self.to_unload_area_distance}'
)
self
.
logger
.
info
(
f
'walk available {self.group_walk_available}'
)
self
.
logger
.
info
(
self
.
unload_area_uuid_index_dict
)
self
.
logger
.
info
(
self
.
excavator_uuid_index_dict
)
if
i
in
self
.
truck
.
truck_dump_bind
:
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
.
truck
.
truck_dump_bind
[
i
]]
else
:
tmp
=
self
.
group_walk_available
[
self
.
excavator_uuid_index_dict
[
next_excavator_id
],
:]
.
flatten
()
self
.
logger
.
info
(
f
'group_walk_available_pick {tmp}'
)
self
.
logger
.
info
(
f
'next_excavator_id {next_excavator_id}'
)
self
.
logger
.
info
(
next_unload_area_value
)
next_unload_area_value
*=
self
.
group_walk_available
[
self
.
excavator_uuid_index_dict
[
next_excavator_id
],
:]
.
flatten
()
self
.
logger
.
info
(
next_unload_area_value
)
min_index
=
np
.
argmin
(
next_unload_area_value
)
next_unload_area_id
=
self
.
unload_area_uuid_index_dict
.
inverse
[
min_index
]
# next_excavator_id = self.excavator_uuid_index_dict.inverse[truck_trip[-1]]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
except
Exception
as
es
:
self
.
logger
.
error
(
"空载车辆全智能模式-计算异常"
)
self
.
logger
.
error
(
es
.
__traceback__
.
tb_lineno
)
self
.
logger
.
error
(
es
)
truck_dispatch
[
i
]
=
[
None
,
None
]
elif
truck_task
==
0
:
try
:
truck_locate
=
self
.
truck
.
get_truck_locate_dict
()[
i
]
except
Exception
as
es
:
self
.
logger
.
error
(
"车辆位置信息丢失"
)
self
.
logger
.
error
(
es
)
try
:
truck_is_temp
=
self
.
truck
.
truck_is_temp
[
i
]
except
Exception
as
es
:
truck_is_temp
=
False
self
.
logger
.
error
(
es
)
# 车辆当前位于交叉路口前,且排队等待
self
.
logger
.
info
(
f
'车辆位置 {truck_locate}'
)
self
.
logger
.
info
(
f
'车辆状态 {self.truck.truck_current_state[i]}'
)
self
.
logger
.
info
(
f
'车辆临时 {truck_is_temp} {type(truck_is_temp)}'
)
if
(
truck_locate
in
self
.
topo
.
cross_bf_lanes
)
and
(
self
.
truck
.
truck_current_state
[
i
]
==
2
)
and
\
(
not
truck_is_temp
)
and
(
i
in
self
.
truck
.
truck_is_temp
)
and
(
not
self
.
truck
.
truck_is_temp
[
i
]):
self
.
logger
.
info
(
"触发二次调度"
)
# 当前绑定卸载区
# if truck_trip[0] == -1:
next_unload_area_id
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
i
,
isdeleted
=
0
)
.
first
()
.
unload_area_id
# else:
# 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]
# 当前绑定装载区
# if truck_trip[-1] == -1:
item
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
i
,
isdeleted
=
0
)
.
first
()
current_excavator_id
=
item
.
exactor_id
current_load_area_id
=
item
.
load_area_id
self
.
logger
.
info
(
f
'truck_id {i}'
)
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_load_area_id = DispatchInfo.excavator_load_dict[current_excavator_id]
load_area_dict
=
self
.
topo
.
get_load_target_node_real
(
truck_locate
,
current_load_area_id
,
True
)
self
.
logger
.
info
(
load_area_dict
)
# if truck_locate in self.topo.get_cross_nodes() and self.truck.truck_current_state[i] == 0:
# print(self.topo.get_load_target_node_real("6b417083-83b0-4eec-a8bd-2f85f96cb029", "1010cbfe-b134-3ef1-91bb-d746241c975a"))
min_trip_time
=
10000000
best_excavator_id
=
current_excavator_id
for
load_area
,
value
in
load_area_dict
.
items
():
# 车辆不需要掉头
if
value
[
-
1
]
==
1
and
load_area
in
DispatchInfo
.
load_excavator_dict
:
excavator_id
=
DispatchInfo
.
load_excavator_dict
[
load_area
]
traveling_time
=
value
[
0
]
/
self
.
truck
.
empty_speed
[
i
]
now
=
float
(
(
datetime
.
now
()
-
self
.
pre_sch
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
))
reach_time
=
now
+
traveling_time
print
(
self
.
pre_sch
.
excavator_avl_time_dict
)
trip_time
=
max
(
reach_time
,
self
.
pre_sch
.
get_excavator_avl_time
()[
excavator_id
])
-
now
if
min_trip_time
>
trip_time
:
best_excavator_id
=
excavator_id
next_excavator_id
=
best_excavator_id
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
# res = redispatch_request(i, next_excavator_id, next_unload_area_id)
# self.logger.info(res)
self
.
logger
.
info
(
f
'二次调度结果 {i}'
)
self
.
logger
.
info
(
truck_dispatch
[
i
])
elif
truck_task
==
3
:
try
:
truck_locate
=
self
.
truck
.
get_truck_locate_dict
()[
i
]
except
Exception
as
es
:
self
.
logger
.
error
(
"车辆位置信息丢失"
)
self
.
logger
.
error
(
es
)
try
:
truck_is_temp
=
self
.
truck
.
truck_is_temp
[
i
]
except
Exception
as
es
:
truck_is_temp
=
False
self
.
logger
.
error
(
es
)
self
.
logger
.
info
(
f
'车辆位置 {truck_locate}'
)
self
.
logger
.
info
(
f
'车辆状态 {self.truck.truck_current_state[i]}'
)
self
.
logger
.
info
(
f
'车辆临时 {truck_is_temp} {type(truck_is_temp)}'
)
# 车辆当前位于交叉路口前,且排队等待
if
(
truck_locate
in
self
.
topo
.
cross_bf_lanes
)
and
(
self
.
truck
.
truck_current_state
[
i
]
==
0
)
and
\
(
not
truck_is_temp
)
and
(
i
in
self
.
truck
.
truck_is_temp
)
and
(
not
self
.
truck
.
truck_is_temp
[
i
]):
# 当前绑定装载区
if
truck_trip
[
0
]
==
-
1
:
next_excavator_id
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
i
,
isdeleted
=
0
)
.
first
()
.
exactor_id
else
:
next_excavator_id
=
get_value
(
"excavator_index_to_uuid_dict"
)[
truck_trip
[
0
]]
# 当前绑定卸载区
if
truck_trip
[
-
1
]
==
-
1
:
item
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
i
,
isdeleted
=
0
)
.
first
()
current_dump_id
=
item
.
dump_id
current_unload_area_id
=
item
.
unload_area_id
else
:
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
]
unload_area_dict
=
self
.
topo
.
get_unload_target_node_real
(
truck_locate
,
current_unload_area_id
,
True
)
min_trip_time
=
10000000
best_dump_id
=
current_dump_id
for
unload_area
,
value
in
unload_area_dict
.
items
():
# 车辆不需要掉头
if
value
[
-
1
]
==
1
and
unload_area
in
DispatchInfo
.
unload_area_dump_dict
:
dump_id
=
DispatchInfo
.
unload_area_dump_dict
[
unload_area
]
traveling_time
=
value
[
0
]
/
self
.
truck
.
heavy_speed
[
i
]
now
=
float
(
(
datetime
.
now
()
-
self
.
pre_sch
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
))
reach_time
=
now
+
traveling_time
trip_time
=
max
(
reach_time
,
self
.
pre_sch
.
get_dump_avl_time
()[
dump_id
])
-
now
if
min_trip_time
>
trip_time
:
best_dump_id
=
dump_id
next_unload_area_id
=
DispatchInfo
.
dump_unload_area_dict
[
best_dump_id
]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
# res = redispatch_request(i, next_excavator_id, next_unload_area_id)
# self.logger.info(res)
self
.
logger
.
info
(
f
'二次调度结果 {i}'
)
self
.
logger
.
info
(
truck_dispatch
[
i
])
self
.
full_dynamic_mode
(
i
,
s
,
truck_dispatch
,
truck_info
,
truck_task
,
truck_trip
)
# 空车智能模式
elif
self
.
group_mode
==
2
:
if
truck_task
in
[
-
2
,
3
,
4
,
5
]:
try
:
if
i
in
self
.
truck
.
truck_excavator_bind
:
next_excavator_id
=
self
.
truck
.
truck_excavator_bind
[
i
]
else
:
next_excavator_value
=
s
.
solve
(
truck_info
)
# min_index = next_excavator_list.index(min(next_excavator_list))
min_index
=
np
.
argmin
(
next_excavator_value
)
next_excavator_id
=
self
.
excavator_uuid_index_dict
.
inverse
[
min_index
]
if
truck_task
==
-
2
:
next_unload_area_id
=
"Park"
else
:
# next_unload_area_id = self.unload_area_uuid_index_dict.inverse[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
]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
except
Exception
as
es
:
self
.
logger
.
error
(
"重载车辆空车智能模式-计算异常"
)
self
.
logger
.
error
(
es
)
if
truck_task
in
[
0
,
1
,
2
]:
try
:
truck_dispatch
[
i
]
=
DispatchInfo
.
get_truck_match
(
i
)
except
Exception
as
es
:
self
.
logger
.
error
(
"空载车辆空车智能模式-计算异常"
)
self
.
logger
.
error
(
es
)
self
.
semi_dynamic_mode
(
i
,
s
,
truck_dispatch
,
truck_info
,
truck_task
,
truck_trip
)
# 定铲派车
elif
self
.
group_mode
==
3
:
try
:
...
...
@@ -524,55 +311,343 @@ class Group:
# 分流配比模式
elif
self
.
group_mode
==
4
:
next_exactor_id
=
DispatchInfo
.
get_truck_exactor
(
i
)
# 获取该卡车对应的exactor_id
self
.
ratio_mode
(
i
,
truck_dispatch
,
truck_task
)
except
Exception
as
es
:
self
.
logger
.
info
(
es
)
# return dispatch plan
return
truck_dispatch
self
.
logger
.
info
(
f
"分流配比模式,对应的卡车:{i}"
)
def
ratio_mode
(
self
,
i
,
truck_dispatch
,
truck_task
):
next_exactor_id
=
DispatchInfo
.
get_truck_exactor
(
i
)
# 获取该卡车对应的exactor_id
self
.
logger
.
info
(
f
"分流配比模式,对应的卡车:{i}"
)
self
.
logger
.
info
(
f
"矿卡对应的铲车:{next_exactor_id}"
)
next_unload_area_id
=
None
if
truck_task
==
-
2
:
self
.
logger
.
info
(
f
"矿卡对应的铲车:{next_exactor_id}"
)
next_unload_area_id
=
"Park"
next_unload_area_id
=
None
# 空载模式下,计算下一次卸载区的位置,按照分流配比的模式进行计算
if
truck_task
==
-
2
:
elif
truck_task
in
[
0
,
1
,
2
]
:
next_unload_area_id
=
"Park"
try
:
# 空载模式下,计算下一次卸载区的位置,按照分流配比的模式进行计算
if
i
in
self
.
truck
.
truck_dump_bind
:
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
.
truck
.
truck_dump_bind
[
i
]]
else
:
elif
truck_task
in
[
0
,
1
,
2
]:
next_unload_area_id
=
DistributionRatio
(
next_exactor_id
,
self
.
truck
)
.
ratio_main
()
try
:
except
Exception
as
es
:
if
i
in
self
.
truck
.
truck_dump_bind
:
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
.
truck
.
truck_dump_bind
[
i
]]
else
:
self
.
logger
.
error
(
"分流配比模式-->>空载车辆计算异常"
)
next_unload_area_id
=
DistributionRatio
(
next_exactor_id
,
self
.
truck
)
.
ratio_main
(
)
self
.
logger
.
error
(
es
)
except
Exception
as
es
:
# 重载模式下,按照固定派车进行计算
self
.
logger
.
error
(
"分流配比模式-->>空载车辆计算异常"
)
elif
truck_task
in
[
3
,
4
,
5
]:
self
.
logger
.
error
(
es
)
try
:
# 重载模式下,按照固定派车进行计算
next_unload_area_id
=
DispatchInfo
.
get_truck_match
(
i
)[
1
]
elif
truck_task
in
[
3
,
4
,
5
]
:
except
Exception
as
es
:
try
:
self
.
logger
.
error
(
"分流配比模式-->>重载车辆计算异常"
)
next_unload_area_id
=
DispatchInfo
.
get_truck_match
(
i
)[
1
]
self
.
logger
.
error
(
es
)
truck_dispatch
[
i
]
=
[
next_exactor_id
,
next_unload_area_id
]
except
Exception
as
es
:
def
semi_dynamic_mode
(
self
,
i
,
s
,
truck_dispatch
,
truck_info
,
truck_task
,
truck_trip
):
if
truck_task
in
[
-
2
,
3
,
4
,
5
]:
try
:
self
.
logger
.
error
(
"分流配比模式-->>重载车辆计算异常"
)
if
i
in
self
.
truck
.
truck_excavator_bind
:
next_excavator_id
=
self
.
truck
.
truck_excavator_bind
[
i
]
else
:
next_excavator_value
=
s
.
solve
(
truck_info
)
# min_index = next_excavator_list.index(min(next_excavator_list))
min_index
=
np
.
argmin
(
next_excavator_value
)
next_excavator_id
=
self
.
excavator_uuid_index_dict
.
inverse
[
min_index
]
if
truck_task
==
-
2
:
next_unload_area_id
=
"Park"
else
:
# next_unload_area_id = self.unload_area_uuid_index_dict.inverse[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
]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
self
.
logger
.
error
(
es
)
except
Exception
as
es
:
self
.
logger
.
error
(
"重载车辆空车智能模式-计算异常"
)
self
.
logger
.
error
(
es
)
if
truck_task
in
[
0
,
1
,
2
]:
try
:
truck_dispatch
[
i
]
=
DispatchInfo
.
get_truck_match
(
i
)
except
Exception
as
es
:
self
.
logger
.
error
(
"空载车辆空车智能模式-计算异常"
)
self
.
logger
.
error
(
es
)
truck_dispatch
[
i
]
=
[
next_exactor_id
,
next_unload_area_id
]
def
full_dynamic_mode
(
self
,
i
,
s
,
truck_dispatch
,
truck_info
,
truck_task
,
truck_trip
):
# 车辆停止或者车辆位于卸载区内, 调度车辆前往装载区
if
truck_task
in
[
-
2
,
4
,
5
]:
try
:
if
i
in
self
.
truck
.
truck_excavator_bind
:
next_excavator_id
=
self
.
truck
.
truck_excavator_bind
[
i
]
else
:
next_excavator_value
=
s
.
solve
(
truck_info
)
# next_excavator_value = s.solve(i, truck_task, truck_trip)
# min_index = next_excavator_list.index(min(next_excavator_list))
min_index
=
np
.
argmin
(
next_excavator_value
)
next_excavator_id
=
self
.
excavator_uuid_index_dict
.
inverse
[
min_index
]
if
truck_task
==
-
2
:
next_unload_area_id
=
"Park"
else
:
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
]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
except
Exception
as
es
:
self
.
logger
.
info
(
es
)
self
.
logger
.
error
(
"重载车辆全智能模式-计算异常"
)
self
.
logger
.
error
(
es
)
# 车辆位于装载区内, 调度车辆前往卸载区
elif
truck_task
in
[
1
,
2
]:
try
:
next_excavator_id
=
get_value
(
"excavator_index_to_uuid_dict"
)[
truck_trip
[
-
1
]]
next_unload_area_value
=
s
.
solve
(
truck_info
)
self
.
logger
.
info
(
f
'车辆 {i}'
)
self
.
logger
.
info
(
f
'group distance {self.to_unload_area_distance}'
)
self
.
logger
.
info
(
f
'walk available {self.group_walk_available}'
)
self
.
logger
.
info
(
self
.
unload_area_uuid_index_dict
)
self
.
logger
.
info
(
self
.
excavator_uuid_index_dict
)
if
i
in
self
.
truck
.
truck_dump_bind
:
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
.
truck
.
truck_dump_bind
[
i
]]
else
:
tmp
=
self
.
group_walk_available
[
self
.
excavator_uuid_index_dict
[
next_excavator_id
],
:]
.
flatten
()
self
.
logger
.
info
(
f
'group_walk_available_pick {tmp}'
)
self
.
logger
.
info
(
f
'next_excavator_id {next_excavator_id}'
)
self
.
logger
.
info
(
next_unload_area_value
)
next_unload_area_value
*=
self
.
group_walk_available
[
self
.
excavator_uuid_index_dict
[
next_excavator_id
],
:]
.
flatten
()
self
.
logger
.
info
(
next_unload_area_value
)
min_index
=
np
.
argmin
(
next_unload_area_value
)
next_unload_area_id
=
self
.
unload_area_uuid_index_dict
.
inverse
[
min_index
]
# next_excavator_id = self.excavator_uuid_index_dict.inverse[truck_trip[-1]]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
# return dispatch plan
return
truck_dispatch
except
Exception
as
es
:
self
.
logger
.
error
(
"空载车辆全智能模式-计算异常"
)
self
.
logger
.
error
(
es
.
__traceback__
.
tb_lineno
)
self
.
logger
.
error
(
es
)
truck_dispatch
[
i
]
=
[
None
,
None
]
elif
truck_task
==
0
:
try
:
truck_locate
=
self
.
truck
.
get_truck_locate_dict
()[
i
]
except
Exception
as
es
:
self
.
logger
.
error
(
"车辆位置信息丢失"
)
self
.
logger
.
error
(
es
)
self
.
logger
.
info
(
self
.
truck
.
truck_is_temp
)
try
:
truck_is_temp
=
self
.
truck
.
truck_is_temp
[
i
]
except
Exception
as
es
:
truck_is_temp
=
False
self
.
logger
.
error
(
"车辆临时字段异常"
)
self
.
logger
.
error
(
es
)
# 车辆当前位于交叉路口前,且排队等待
self
.
logger
.
info
(
f
'车辆位置 {truck_locate}'
)
self
.
logger
.
info
(
f
'车辆状态 {self.truck.truck_current_state[i]}'
)
self
.
logger
.
info
(
f
'车辆临时 {truck_is_temp} {type(truck_is_temp)}'
)
self
.
logger
.
info
(
self
.
topo
.
cross_bf_lanes
)
self
.
logger
.
info
(
self
.
truck
.
truck_current_state
)
self
.
logger
.
info
(
truck_is_temp
)
if
(
truck_locate
in
self
.
topo
.
cross_bf_lanes
)
and
(
self
.
truck
.
truck_current_state
[
i
]
==
2
)
\
and
(
not
truck_is_temp
):
self
.
logger
.
info
(
"触发二次调度"
)
# 当前绑定卸载区
# if truck_trip[0] == -1:
next_unload_area_id
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
i
,
isdeleted
=
0
)
.
first
()
.
unload_area_id
# else:
# 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]
# 当前绑定装载区
# if truck_trip[-1] == -1:
item
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
i
,
isdeleted
=
0
)
.
first
()
current_excavator_id
=
item
.
exactor_id
current_load_area_id
=
item
.
load_area_id
self
.
logger
.
info
(
f
'truck_id {i}'
)
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_load_area_id = DispatchInfo.excavator_load_dict[current_excavator_id]
load_area_dict
,
load_area_lane_dict
=
self
.
topo
.
get_load_target_node_real
(
truck_locate
,
current_load_area_id
,
True
)
self
.
logger
.
info
(
"所有可达装载区"
)
self
.
logger
.
info
(
load_area_dict
)
# 获取拥堵路段
congestion_lane_dict
=
self
.
get_congestion_lanes
()
# 获取当前交叉口下一路段集合
next_lane_list
=
get_cross_next_lanes
(
truck_locate
)
# 交叉口下一路段可达的装载区
next_lane_load_area_dict
=
get_lane_reach_load_areas
(
load_area_lane_dict
,
next_lane_list
)
# 排除下一个路段阻塞的装载区
delete_congestion_load_area
(
congestion_lane_dict
,
load_area_dict
,
next_lane_load_area_dict
)
self
.
logger
.
info
(
"剔除堵塞装载区"
)
self
.
logger
.
info
(
load_area_dict
)
# 获取最佳挖机
best_excavator_id
=
self
.
get_best_excavator
(
current_excavator_id
,
i
,
load_area_dict
)
next_excavator_id
=
best_excavator_id
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
self
.
logger
.
info
(
f
'二次调度结果 {i}'
)
self
.
logger
.
info
(
truck_dispatch
[
i
])
elif
truck_task
==
3
:
try
:
truck_locate
=
self
.
truck
.
get_truck_locate_dict
()[
i
]
except
Exception
as
es
:
self
.
logger
.
error
(
"车辆位置信息丢失"
)
self
.
logger
.
error
(
es
)
try
:
truck_is_temp
=
self
.
truck
.
truck_is_temp
[
i
]
except
Exception
as
es
:
truck_is_temp
=
False
self
.
logger
.
error
(
"车辆临时字段异常"
)
self
.
logger
.
error
(
es
)
self
.
logger
.
info
(
f
'车辆位置 {truck_locate}'
)
self
.
logger
.
info
(
f
'车辆状态 {self.truck.truck_current_state[i]}'
)
self
.
logger
.
info
(
f
'车辆临时 {truck_is_temp} {type(truck_is_temp)}'
)
# 车辆当前位于交叉路口前,且排队等待
if
(
truck_locate
in
self
.
topo
.
cross_bf_lanes
)
and
(
self
.
truck
.
truck_current_state
[
i
]
==
2
)
\
and
(
not
truck_is_temp
):
# 当前绑定装载区
if
truck_trip
[
0
]
==
-
1
:
next_excavator_id
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
i
,
isdeleted
=
0
)
.
first
()
.
exactor_id
else
:
next_excavator_id
=
get_value
(
"excavator_index_to_uuid_dict"
)[
truck_trip
[
0
]]
# 当前绑定卸载区
if
truck_trip
[
-
1
]
==
-
1
:
item
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
i
,
isdeleted
=
0
)
.
first
()
current_dump_id
=
item
.
dump_id
current_unload_area_id
=
item
.
unload_area_id
else
:
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
]
unload_area_dict
,
unload_area_lane_dict
=
self
.
topo
.
get_unload_target_node_real
(
truck_locate
,
current_unload_area_id
,
True
)
# 获取拥堵路段
congestion_lane_dict
=
self
.
get_congestion_lanes
()
# 获取当前交叉口下一路段集合
next_lane_list
=
get_cross_next_lanes
(
truck_locate
)
# 交叉口下一路段可达的装载区
next_lane_load_area_dict
=
get_lane_reach_load_areas
(
unload_area_lane_dict
,
next_lane_list
)
# 排除下一个路段阻塞的装载区
delete_congestion_load_area
(
congestion_lane_dict
,
unload_area_dict
,
next_lane_load_area_dict
)
min_trip_time
=
10000000
best_dump_id
=
current_dump_id
for
unload_area
,
value
in
unload_area_dict
.
items
():
# 车辆不需要掉头
if
value
[
-
1
]
==
1
and
unload_area
in
DispatchInfo
.
unload_area_dump_dict
:
dump_id
=
DispatchInfo
.
unload_area_dump_dict
[
unload_area
]
traveling_time
=
value
[
0
]
/
self
.
truck
.
heavy_speed
[
i
]
now
=
float
(
(
datetime
.
now
()
-
self
.
pre_sch
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
))
reach_time
=
now
+
traveling_time
trip_time
=
max
(
reach_time
,
self
.
pre_sch
.
get_dump_avl_time
()[
dump_id
])
-
now
if
min_trip_time
>
trip_time
:
best_dump_id
=
dump_id
next_unload_area_id
=
DispatchInfo
.
dump_unload_area_dict
[
best_dump_id
]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
# res = redispatch_request(i, next_excavator_id, next_unload_area_id)
# self.logger.info(res)
self
.
logger
.
info
(
f
'二次调度结果 {i}'
)
self
.
logger
.
info
(
truck_dispatch
[
i
])
def
get_best_excavator
(
self
,
current_excavator_id
,
truck_id
,
load_area_dict
):
"""
get best excavator
:param current_excavator_id: 当前车辆配对挖机
:param truck_id:
:param load_area_dict: 备选装载区
:return:
"""
min_trip_time
=
10000000
best_excavator_id
=
current_excavator_id
for
load_area
,
value
in
load_area_dict
.
items
():
# 车辆不需要掉头
if
value
[
-
1
]
==
1
and
load_area
in
DispatchInfo
.
load_excavator_dict
:
excavator_id
=
DispatchInfo
.
load_excavator_dict
[
load_area
]
traveling_time
=
60
*
(
value
[
0
]
/
1000
)
/
self
.
truck
.
empty_speed
[
truck_id
]
self
.
logger
.
info
(
f
'load_area {load_area}'
)
self
.
logger
.
info
(
f
'traveling_time {traveling_time}'
)
now
=
float
(
(
datetime
.
now
()
-
self
.
pre_sch
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
))
reach_time
=
now
+
traveling_time
self
.
logger
.
info
(
f
'reach_time {reach_time}'
)
trip_time
=
max
(
reach_time
,
self
.
pre_sch
.
get_excavator_avl_time
(
truck_id
=
truck_id
)[
excavator_id
])
-
now
self
.
logger
.
info
(
f
'trip_time {trip_time}'
)
if
min_trip_time
>
trip_time
:
best_excavator_id
=
excavator_id
min_trip_time
=
trip_time
return
best_excavator_id
def
get_congestion_lanes
(
self
):
# 存在车辆拥堵的路段
truck_locate_dict
=
self
.
truck
.
get_truck_locate_dict
()
congestion_lane_list
=
[]
for
key
,
value
in
truck_locate_dict
.
items
():
if
self
.
truck
.
truck_current_state
[
key
]
==
2
:
congestion_lane_list
.
append
(
value
)
return
list
(
set
(
congestion_lane_list
))
core/schedule.py
View file @
4cca50a5
...
...
@@ -50,7 +50,7 @@ class PreSchedule:
self
.
logger
=
get_logger
(
"zxt.pre_schedule"
)
def
update_truck_reach_time
(
self
):
def
update_truck_reach_time
(
self
,
truck_id
=
None
):
"""
更新矿卡预计抵达目的地时间
:return:
...
...
@@ -75,6 +75,8 @@ class PreSchedule:
# self.logger.info("update_truck_reach_time-trucks")
# self.logger.info(trucks)
for
i
in
range
(
trucks
):
if
truck_id
is
not
None
and
i
==
self
.
truck
.
truck_uuid_to_index_dict
[
truck_id
]:
continue
task
=
truck_current_task
[
self
.
truck
.
truck_index_to_uuid_dict
[
i
]]
end_area_index
=
truck_current_trip
[
i
][
1
]
if
end_area_index
==
-
1
:
...
...
@@ -133,8 +135,6 @@ class PreSchedule:
)
for
reach_ls
in
excavator_avl_ls
:
self
.
logger
.
info
(
"update_excavator_avl_time-excavator_avl_ls"
)
self
.
logger
.
info
(
excavator_avl_ls
)
if
len
(
reach_ls
)
!=
0
:
reach_ls
=
np
.
array
(
reach_ls
)
tmp
=
reach_ls
[
np
.
lexsort
(
reach_ls
[:,
::
-
1
]
.
T
)]
...
...
@@ -183,6 +183,8 @@ class PreSchedule:
# self.truck_avl_time[int(tmp[i][1])] = now
# if abs(self.excavator_avl_time[excavator_index] - now) > 60:
# self.excavator_avl_time[excavator_index] = now
self
.
logger
.
info
(
"update_excavator_avl_time-excavator_avl_ls"
)
self
.
logger
.
info
(
excavator_avl_ls
)
except
Exception
as
es
:
self
.
logger
.
error
(
"挖机可用时间计算异常"
)
self
.
logger
.
error
(
es
)
...
...
@@ -279,7 +281,7 @@ class PreSchedule:
dump_avl_time
=
self
.
update_dump_avl_time
(
dump_avl_ls
)
return
dump_avl_time
def
get_excavator_avl_time
(
self
,
excavator_id
=
None
):
def
get_excavator_avl_time
(
self
,
excavator_id
=
None
,
truck_id
=
None
):
"""
获取挖机最早可用时间
:param excavator_id: 挖机编号uuid
...
...
@@ -287,7 +289,7 @@ class PreSchedule:
excavator_avl_time: (array) 各挖机完成所有已分配矿卡装载的时间
"""
self
.
_reset
()
excavator_avl_ls
,
dump_avl_ls
=
self
.
update_truck_reach_time
()
excavator_avl_ls
,
dump_avl_ls
=
self
.
update_truck_reach_time
(
truck_id
=
truck_id
)
if
excavator_id
is
not
None
:
return
self
.
update_excavator_avl_time
(
excavator_avl_ls
)
\
[
self
.
excavator
.
excavator_uuid_to_index_dict
[
excavator_id
]]
...
...
core/util.py
View file @
4cca50a5
...
...
@@ -40,6 +40,40 @@ with open(json_file) as f:
#
# return POST(real_data)
def
get_cross_next_lanes
(
truck_locate
):
next_lane_list
=
[]
startNodeId
=
session_postgre
.
query
(
Lane
)
.
filter_by
(
Id
=
truck_locate
)
.
first
()
.
EndNodeId
for
item
in
session_postgre
.
query
(
Lane
)
.
filter_by
(
StartNodeId
=
startNodeId
)
.
all
():
next_lane_list
.
append
(
str
(
item
.
Id
))
return
next_lane_list
def
delete_congestion_load_area
(
congestion_lane_dict
,
load_area_dict
,
next_lane_load_area_dict
):
"""
:param congestion_lane_dict: 拥堵路段
:param load_area_dict: 拓扑图规划得到的可达装载区
:param next_lane_load_area_dict: 路段可达的装载区
:return:
"""
for
lane_id
in
next_lane_load_area_dict
:
# 下一装载区路段
if
lane_id
in
congestion_lane_dict
:
#
for
load_area
in
next_lane_load_area_dict
[
lane_id
]:
if
load_area
in
load_area_dict
:
del
load_area_dict
[
load_area
]
def
get_lane_reach_load_areas
(
load_area_lane_dict
,
next_lane_list
):
next_lane_load_area_dict
=
{}
for
lane_id
in
next_lane_list
:
for
key
,
value
in
load_area_lane_dict
.
items
():
if
lane_id
in
value
:
if
lane_id
not
in
next_lane_load_area_dict
:
next_lane_load_area_dict
[
lane_id
]
=
[
key
]
else
:
next_lane_load_area_dict
[
lane_id
]
.
append
(
key
)
return
next_lane_load_area_dict
def
POST
(
truck_id
):
"""
...
...
equipment/truck.py
View file @
4cca50a5
...
...
@@ -212,9 +212,9 @@ class TruckInfo(WalkManage):
if
truck_name_to_uuid_dict
[
item
]
in
self
.
dynamic_truck_set
:
try
:
isTemp
=
key_value_dict
[
"isTemp"
]
print
(
isTemp
)
self
.
truck_is_temp
[
truck_name_to_uuid_dict
[
item
]]
=
bool
(
isTemp
)
except
Exception
as
es
:
self
.
logger
.
error
(
item
)
self
.
logger
.
error
(
es
)
self
.
truck_is_temp
[
truck_name_to_uuid_dict
[
item
]]
=
True
...
...
graph/topo_graph.py
View file @
4cca50a5
...
...
@@ -343,6 +343,8 @@ class Topo():
if
not
len
(
target_list
):
self
.
logger
.
error
(
"当前无可去卸载区!"
)
unload_area_lane_dict
=
{}
path_length_map
=
{}
# build the path_length_map from source node
...
...
@@ -350,6 +352,12 @@ class Topo():
try
:
distance
,
path
=
nx
.
single_source_dijkstra
(
self
.
unload_G
,
source
=
source_node
,
target
=
i
,
weight
=
"real_distance"
)
unload_area_id
=
session_postgre
.
query
(
DumpArea
)
.
filter_by
(
Id
=
unload_area_id
)
.
first
(
EntranceNodeId
=
i
)
.
first
()
.
Id
unload_area_lane_dict
[
str
(
unload_area_id
)]
=
[]
for
j
in
range
(
len
(
path
)
-
1
):
unload_area_lane_dict
[
str
(
unload_area_id
)]
+=
self
.
load_G
[
path
[
j
]][
path
[
j
+
1
]][
'lane'
]
path_length_map
[
distance
]
=
path
# print(path)
except
Exception
as
es
:
...
...
@@ -446,6 +454,9 @@ class Topo():
if
not
len
(
target_list
):
self
.
logger
.
error
(
"当前无可去装载区!"
)
load_area_lane_dict
=
{}
# print(target_list)
path_length_map
=
{}
# build the path_length_map from source node
...
...
@@ -453,6 +464,12 @@ class Topo():
try
:
distance
,
path
=
nx
.
single_source_dijkstra
(
self
.
load_G
,
source
=
source_node
,
target
=
i
,
weight
=
"real_distance"
)
load_area_id
=
session_postgre
.
query
(
DiggingWorkArea
)
.
filter_by
(
EntranceNodeId
=
i
)
.
first
()
.
Id
load_area_lane_dict
[
str
(
load_area_id
)]
=
[]
for
j
in
range
(
len
(
path
)
-
1
):
load_area_lane_dict
[
str
(
load_area_id
)]
+=
self
.
load_G
[
path
[
j
]][
path
[
j
+
1
]][
'lane'
]
path_length_map
[
distance
]
=
path
# print(path)
except
Exception
as
es
:
...
...
@@ -470,7 +487,7 @@ class Topo():
else
:
reachable_destinations
[
target_digging_area
]
=
[
k
+
distance_end_node
,
1
]
return
reachable_destinations
return
reachable_destinations
,
load_area_lane_dict
def
update_cross_nodes
(
self
):
"""
...
...
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