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
c5099188
Commit
c5099188
authored
Sep 08, 2022
by
张晓彤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
二次调度调试
parent
4ef1d396
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
349 additions
and
227 deletions
+349
-227
algorithm.py
alg/algorithm.py
+18
-18
dispatcher.py
core/dispatcher.py
+9
-2
group.py
core/group.py
+231
-207
util.py
core/util.py
+91
-0
调度系统部署说明4.1.docx
调度系统部署说明4.1.docx
+0
-0
No files found.
alg/algorithm.py
View file @
c5099188
...
...
@@ -147,33 +147,33 @@ class ExpectedTime(AlgorithmBase):
:return: travel_time_value
"""
#
try:
try
:
# truck_index = self.truck.truck_uuid_to_index_dict[truck_id]
# truck_index = self.truck.truck_uuid_to_index_dict[truck_id]
# trip = self.truck.get_truck_current_trip()[truck_index]
#
# task = self.truck.get_truck_current_task()[truck_id]
# trip = self.truck.get_truck_current_trip()[truck_index]
#
# task = self.truck.get_truck_current_task()[truck_id]
truck_id
=
truck_info
.
get_truck_id
()
truck_id
=
truck_info
.
get_truck_id
()
truck_index
=
self
.
truck
.
truck_uuid_to_index_dict
[
truck_id
]
# task = truck_task
# trip = truck_trip
truck_index
=
self
.
truck
.
truck_uuid_to_index_dict
[
truck_id
]
# task = truck_task
# trip = truck_trip
trip
=
truck_info
.
get_trip
()
trip
=
truck_info
.
get_trip
()
task
=
truck_info
.
get_task
()
task
=
truck_info
.
get_task
()
truck_avl_time
=
self
.
pre_sch
.
get_truck_avl_time
(
truck_id
=
truck_id
)
truck_avl_time
=
self
.
pre_sch
.
get_truck_avl_time
(
truck_id
=
truck_id
)
group_dynamic_excavator_num
=
len
(
self
.
group
.
excavator
)
group_dynamic_excavator_num
=
len
(
self
.
group
.
excavator
)
group_dynamic_unload_area_num
=
len
(
self
.
group
.
unload_area
)
#
#
except Exception as es:
#
self.logger.error("车辆调度信息读取异常")
#
self.logger.error(es)
group_dynamic_unload_area_num
=
len
(
self
.
group
.
unload_area
)
except
Exception
as
es
:
self
.
logger
.
error
(
"车辆调度信息读取异常"
)
self
.
logger
.
error
(
es
)
if
task
==
-
2
:
################################################ 矿卡启动 ###############################################
...
...
core/dispatcher.py
View file @
c5099188
...
...
@@ -137,6 +137,7 @@ class DispatchSubmission:
if
group_mode
==
3
:
try
:
self
.
logger
.
info
(
f
'调度0 {truck_id}'
)
item
=
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
truck_id
=
truck_id
,
isdeleted
=
0
,
)
.
first
()
record
[
"dispatchId"
]
=
item
.
id
record
[
"exactorId"
]
=
item
.
exactor_id
...
...
@@ -159,8 +160,9 @@ class DispatchSubmission:
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
else
:
if
task
in
[
1
,
2
]
or
(
task
==
3
and
state
==
2
):
# 卡车空载或在装载区出场前, 可变更卸载目的地
if
(
task
in
[
1
,
2
])
or
(
task
==
3
and
state
==
2
):
# 卡车空载或在装载区出场前, 可变更卸载目的地
self
.
logger
.
info
(
f
'调度1 {truck_id}'
)
# 查询车辆相关派车计划
try
:
dump_id
=
DispatchInfo
.
unload_area_dump_dict
[
dispatch_seq
[
1
]]
...
...
@@ -191,14 +193,16 @@ class DispatchSubmission:
record
[
"groupName"
]
=
DispatchInfo
.
group_name
[
group_id
]
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
except
Exception
as
es
:
self
.
logger
.
error
(
"调度结果写入异常-矿卡空载"
)
self
.
logger
.
error
(
es
)
finally
:
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
elif
task
in
[
4
,
5
]
or
(
task
==
0
and
state
==
2
):
# 卡车重载或在卸载区出场前, 可变更装载目的地
elif
(
task
in
[
4
,
5
])
or
(
task
==
0
and
state
==
2
):
# 卡车重载或在卸载区出场前, 可变更装载目的地
self
.
logger
.
info
(
f
'调度2 {truck_id}'
)
# 查询车辆相关派车计划
try
:
item
=
(
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
exactor_id
=
dispatch_seq
[
0
],
group_id
=
group_id
,
...
...
@@ -226,12 +230,14 @@ class DispatchSubmission:
record
[
"groupName"
]
=
DispatchInfo
.
group_name
[
group_id
]
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
except
Exception
as
es
:
self
.
logger
.
error
(
"调度结果写入异常-矿卡重载"
)
finally
:
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
elif
task
==
-
2
:
self
.
logger
.
info
(
f
'调度3 {truck_id}'
)
try
:
# 查询车辆相关派车计划
...
...
@@ -263,6 +269,7 @@ class DispatchSubmission:
record
[
"groupName"
]
=
DispatchInfo
.
group_name
[
group_id
]
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
# record["createtime"] = datetime.now().strftime(
# "%b %d, %Y %I:%M:%S %p")
...
...
core/group.py
View file @
c5099188
...
...
@@ -12,6 +12,7 @@ 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
redispatch_request
class
CurrentTruck
:
...
...
@@ -245,7 +246,6 @@ class Group:
"""
pass
def
info_update
(
self
):
"""
update group info.
...
...
@@ -281,254 +281,278 @@ class Group:
# except Exception as es:
# self.logger.error("车辆调度信息读取异常")
# self.logger.error(es)
# 全智能模式
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
)
truck_dispatch
[
i
]
=
[
None
,
None
]
elif
truck_task
==
0
:
truck_locate
=
self
.
truck
.
get_truck_locate_dict
()[
i
]
# 车辆当前位于交叉路口前,且排队等待
self
.
logger
.
info
(
f
'车辆位置 {truck_locate}'
)
self
.
logger
.
info
(
f
'车辆状态 {self.truck.truck_current_state[i]}'
)
if
truck_locate
in
self
.
topo
.
cross_bf_lanes
and
self
.
truck
.
truck_current_state
[
i
]
==
2
:
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
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
)
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
]
self
.
logger
.
info
(
"二次调度结果"
)
self
.
logger
.
info
(
truck_dispatch
[
i
])
elif
truck_task
==
3
:
truck_locate
=
self
.
truck
.
get_truck_locate_dict
()[
i
]
# 车辆当前位于交叉路口前,且排队等待
if
truck_locate
in
self
.
topo
.
cross_bf_lanes
and
self
.
truck
.
truck_current_state
[
i
]
==
0
:
# 当前绑定装载区
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
)
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
]
self
.
logger
.
info
(
"二次调度结果"
)
self
.
logger
.
info
(
truck_dispatch
[
i
])
# 空车智能模式
elif
self
.
group_mode
==
2
:
if
truck_task
in
[
-
2
,
3
,
4
,
5
]:
try
:
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
:
# 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
]:
# 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
(
"es"
)
self
.
logger
.
error
(
es
)
# 车辆当前位于交叉路口前,且排队等待
self
.
logger
.
info
(
f
'车辆位置 {truck_locate}'
)
self
.
logger
.
info
(
f
'车辆状态 {self.truck.truck_current_state[i]}'
)
if
truck_locate
in
self
.
topo
.
cross_bf_lanes
and
self
.
truck
.
truck_current_state
[
i
]
==
2
:
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
)
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
(
"二次调度结果"
)
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
(
"es"
)
self
.
logger
.
error
(
es
)
# 车辆当前位于交叉路口前,且排队等待
if
truck_locate
in
self
.
topo
.
cross_bf_lanes
and
self
.
truck
.
truck_current_state
[
i
]
==
0
:
# 当前绑定装载区
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
)
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
(
"二次调度结果"
)
self
.
logger
.
info
(
truck_dispatch
[
i
])
# 空车智能模式
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
)
# 定铲派车
elif
self
.
group_mode
==
3
:
try
:
truck_dispatch
[
i
]
=
DispatchInfo
.
get_truck_match
(
i
)
except
Exception
as
es
:
self
.
logger
.
error
(
"
空载车辆空车智能模式
-计算异常"
)
self
.
logger
.
error
(
"
固定派车
-计算异常"
)
self
.
logger
.
error
(
es
)
# 定铲派车
elif
self
.
group_mode
==
3
:
try
:
truck_dispatch
[
i
]
=
DispatchInfo
.
get_truck_match
(
i
)
except
Exception
as
es
:
self
.
logger
.
error
(
"固定派车-计算异常"
)
self
.
logger
.
error
(
es
)
# 分流配比模式
elif
self
.
group_mode
==
4
:
# 分流配比模式
elif
self
.
group_mode
==
4
:
next_exactor_id
=
DispatchInfo
.
get_truck_exactor
(
i
)
# 获取该卡车对应的exactor_id
next_exactor_id
=
DispatchInfo
.
get_truck_exactor
(
i
)
# 获取该卡车对应的exactor_id
self
.
logger
.
info
(
f
"分流配比模式,对应的卡车:{i}"
)
self
.
logger
.
info
(
f
"分流配比模式,对应的卡车:{i}"
)
self
.
logger
.
info
(
f
"矿卡对应的铲车:{next_exactor_id}"
)
self
.
logger
.
info
(
f
"矿卡对应的铲车:{next_exactor_id}"
)
next_unload_area_id
=
None
next_unload_area_id
=
None
if
truck_task
==
-
2
:
if
truck_task
==
-
2
:
next_unload_area_id
=
"Park"
next_unload_area_id
=
"Park"
# 空载模式下,计算下一次卸载区的位置,按照分流配比的模式进行计算
# 空载模式下,计算下一次卸载区的位置,按照分流配比的模式进行计算
elif
truck_task
in
[
0
,
1
,
2
]:
elif
truck_task
in
[
0
,
1
,
2
]
:
try
:
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
:
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
:
next_unload_area_id
=
DistributionRatio
(
next_exactor_id
,
self
.
truck
)
.
ratio_main
()
next_unload_area_id
=
DistributionRatio
(
next_exactor_id
,
self
.
truck
)
.
ratio_main
()
except
Exception
as
es
:
except
Exception
as
es
:
self
.
logger
.
error
(
"分流配比模式-->>空载车辆计算异常"
)
self
.
logger
.
error
(
"分流配比模式-->>空载车辆计算异常"
)
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
es
)
# 重载模式下,按照固定派车进行计算
# 重载模式下,按照固定派车进行计算
elif
truck_task
in
[
3
,
4
,
5
]:
elif
truck_task
in
[
3
,
4
,
5
]
:
try
:
try
:
next_unload_area_id
=
DispatchInfo
.
get_truck_match
(
i
)[
1
]
next_unload_area_id
=
DispatchInfo
.
get_truck_match
(
i
)[
1
]
except
Exception
as
es
:
except
Exception
as
es
:
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
]
except
Exception
as
es
:
self
.
logger
.
info
(
es
)
# return dispatch plan
return
truck_dispatch
core/util.py
0 → 100644
View file @
c5099188
#!E:\Pycharm Projects\Waytous
# -*- coding: utf-8 -*-
# @Time : 2022/9/8 9:42
# @Author : Opfer
# @Site :
# @File : util.py
# @Software: PyCharm
import
requests
from
tables
import
*
import
uuid
def
redispatch_request
(
truck_id
,
excavator_id
,
unload_area_id
):
"""
redispatch request.
:param truck_id:
:param excavator_id:
:param unload_area_id:
:return:
"""
exactor_no
=
session_mysql
.
query
(
Equipment
)
.
filter_by
(
id
=
excavator_id
)
.
first
()
.
device_name
unload_area_name
=
session_postgre
.
query
(
DumpArea
)
.
filter_by
(
Id
=
unload_area_id
)
.
first
()
.
Name
truck_name
=
session_mysql
.
query
(
Equipment
)
.
filter_by
(
id
=
truck_id
)
.
first
()
.
device_name
real_data
=
{
"exactorId"
:
excavator_id
,
"exactorNo"
:
exactor_no
,
"id"
:
str
(
uuid
.
uuid4
()),
"unloadAreaId"
:
unload_area_id
,
"unloadAreaName"
:
unload_area_name
,
"truckId"
:
truck_id
,
"truckNo"
:
truck_name
,
"isauto"
:
"true"
,
"tempChange"
:
1
,
"immediateEffect"
:
1
}
return
POST
(
real_data
)
def
POST
(
real_data
):
"""
Post.
:param real_data:
:return:
"""
# real_data = {
# "exactorId": "ddaa65cc-2658-4e35-b6ec-9deb046e0bfb",
# "exactorNo": "WJ001",
# "id": "d83f09cb-8df3-44d5-8e46-10dbaa317e19",
# "unloadAreaId": "10c75b23-4134-3ef1-9097-114bacac1982",
# "unloadAreaName": "卸载区4",
# "truckId": "de4080b3-fb89-460d-b511-c2ecd73c815c",
# "truckNo": "de4080b3-fb89-460d-b511-c2ecd73c815c",
# "isauto": "false",
# "tempChange": 1,
# "immediateEffect": 1
# }
#
# real_data = {
# 'exactorId': 'a3d09975-82d7-4a30-8c54-fe4ed8ff5a29',
# 'exactorNo': 'BI395-02',
# 'id': '76cb19a8-6541-4245-8ef6-40682aca9635',
# 'unloadAreaId': 'd4675d61-2134-8be7-fb36-fb9ef3c97f7c',
# 'unloadAreaName': '哈卸4',
# 'truckId': '7c196882-8850-4344-aff8-846a597f7792',
# 'truckNo': '7c196882-8850-4344-aff8-846a597f7792',
# 'isauto': 'true',
# 'tempChange': 1,
# 'immediateEffect': 1
# }
#
# head = {"Content-Type":"application/json; charset=UTF-8", 'Connection': 'close'}
url_d
=
"http://172.16.0.103:8020/ht/api/dispatch/update"
real_data
=
json
.
dumps
(
real_data
)
print
(
real_data
)
res_d
=
requests
.
post
(
url
=
url_d
,
data
=
real_data
)
return
res_d
.
text
#
# truck_id, excavator_id, unload_area_id = "9ce82957-b1e1-4dee-8dd1-3bbfa2a496b5", \
# "a3d09975-82d7-4a30-8c54-fe4ed8ff5a29", \
# "d4675d61-2134-8be7-fb36-fb9ef3c97f7c"
#
# res = redispatch_request(truck_id, excavator_id, unload_area_id)
#
# print(res)
\ No newline at end of file
调度系统部署说明4.1.docx
View file @
c5099188
No preview for this file type
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