Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
integrated-scheduling
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
0
Merge Requests
0
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
Commits
f3862cae
Commit
f3862cae
authored
Sep 13, 2021
by
Allvey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Light Schedule
parent
2c77ecd3
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
235 additions
and
1818 deletions
+235
-1818
integrated-scheduling.iml
.idea/integrated-scheduling.iml
+0
-1
dump.py
equipment/dump.py
+9
-49
excavator.py
equipment/excavator.py
+9
-65
truck.py
equipment/truck.py
+6
-82
path_plannner.py
path_plan/path_plannner.py
+50
-41
priority_control.py
path_plan/priority_control.py
+11
-7
realtime_dispatch.py
realtime_dispatch.py
+133
-432
settings.py
settings.py
+4
-4
tables.py
tables.py
+4
-2
traffic_flow_info.py
traffic_flow/traffic_flow_info.py
+5
-6
traffic_flow_planner.py
traffic_flow/traffic_flow_planner.py
+4
-8
wato_dispatch.py
wato_dispatch.py
+0
-1121
No files found.
.idea/integrated-scheduling.iml
View file @
f3862cae
<?xml version="1.0" encoding="UTF-8"?>
<module
type=
"PYTHON_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
>
<content
url=
"file://$MODULE_DIR$/../WatoDisp-master"
/>
<content
url=
"file://$MODULE_DIR$"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 3.7 (waytous)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
...
...
equipment/dump.py
View file @
f3862cae
...
...
@@ -6,30 +6,14 @@
# @File : dump.py
# @Software: PyCharm
from
traffic_flow.traffic_flow_planner
import
*
from
static_data_process
import
*
from
para_config
import
*
from
settings
import
*
# 卸载设备类
class
DumpInfo
(
WalkManage
):
def
__init__
(
self
):
# # 卸载设备集合
# self.dynamic_dump_set = set(update_autodisp_dump())
# 卸载设备数量
self
.
dynamic_dump_num
=
len
(
dynamic_dump_set
)
# 目标产量
self
.
dump_target_mass
=
np
.
zeros
(
self
.
dynamic_dump_num
)
# 实际真实产量
self
.
cur_dump_real_mass
=
np
.
zeros
(
self
.
dynamic_dump_num
)
# # 预计产量(包含正在驶往目的地的矿卡载重)
# self.pre_dump_real_mass = copy.deepcopy(self.cur_dump_real_mass)
# # 模拟实际产量(防止调度修改真实产量)
# self.sim_dump_real_mass = np.zeros(self.dynamic_dump_num)
# # 真实设备可用时间
# self.cur_dump_ava_time = np.zeros(self.dynamic_dump_num)
# # 模拟各设备可用时间(防止调度修改真实产量)
# self.sim_dump_ava_time = np.zeros(self.dynamic_dump_num)
# 用于动态调度的卸载设备集合
self
.
dynamic_dump_set
=
[]
# 开始时间
...
...
@@ -58,12 +42,6 @@ class DumpInfo(WalkManage):
def
get_dump_num
(
self
):
return
self
.
dynamic_dump_num
def
get_dump_target_mass
(
self
):
return
self
.
dump_target_mass
def
get_dump_actual_mass
(
self
):
return
self
.
cur_dump_real_mass
def
get_dynamic_dump_set
(
self
):
return
self
.
dynamic_dump_set
...
...
@@ -132,37 +110,22 @@ class DumpInfo(WalkManage):
logger
.
error
(
f
"卸载设备 {dump_id} 出入场时间信息缺失, 已设为默认值(1min)"
)
logger
.
error
(
es
)
self
.
entrance_time
[
self
.
dump_uuid_to_index_dict
[
dump_id
]]
=
0.50
self
.
exit_time
[
self
.
dump_uuid_to_index_dict
[
dump_id
]]
=
0.50
# 更新卸载设备实际卸载量
def
update_actual_unload_thoughout
(
self
):
self
.
cur_dump_real_mass
=
np
.
zeros
(
self
.
dynamic_dump_num
)
now
=
datetime
.
now
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
for
dump_id
in
self
.
dump_uuid_to_index_dict
.
keys
():
for
query
in
(
session_mysql
.
query
(
LoadInfo
)
.
join
(
Equipment
,
LoadInfo
.
dump_id
==
Equipment
.
equipment_id
)
.
filter
(
Equipment
.
id
==
dump_id
,
LoadInfo
.
time
>
now
)
.
order_by
(
LoadInfo
.
time
.
desc
())
.
all
()
):
# print("time:", query.time)
# print("load_weight:", )
self
.
cur_dump_real_mass
[
self
.
dump_uuid_to_index_dict
[
dump_id
]]
=
(
self
.
cur_dump_real_mass
[
self
.
dump_uuid_to_index_dict
[
dump_id
]]
+
query
.
load_weight
)
self
.
exit_time
[
self
.
dump_uuid_to_index_dict
[
dump_id
]]
=
0.50
def
update_dump_material
(
self
):
self
.
dump_material
=
{}
for
dump_id
in
dynamic_dump_set
:
unload_area_id
=
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
dump_id
=
dump_id
)
.
first
()
.
unload_area_id
unload_area_id
=
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
dump_id
=
dump_id
,
isauto
=
1
,
isdeleted
=
0
)
.
first
()
.
unload_area_id
dump_material_id
=
session_postgre
.
query
(
DumpArea
)
.
filter_by
(
Id
=
unload_area_id
)
.
first
()
.
Material
self
.
dump_material
[
dump_id
]
=
dump_material_id
\
self
.
dump_material
[
dump_id
]
=
dump_material_id
def
update_dump_priority
(
self
):
self
.
dump_priority_coefficient
=
np
.
ones
(
self
.
dynamic_dump_num
)
for
dump_id
in
dynamic_dump_set
:
item
=
session_mysql
.
query
(
Equipment
)
.
filter_by
(
id
=
dump_id
)
.
first
()
self
.
dump_priority_coefficient
[
self
.
dump_uuid_to_index_dict
[
dump_id
]]
+=
item
.
priority
unload_area_index
=
self
.
dump_index_to_unload_area_index_dict
[
self
.
dump_uuid_to_index_dict
[
dump_id
]]
unload_area_id
=
unload_area_index_to_uuid_dict
[
unload_area_index
]
item
=
session_postgre
.
query
(
DumpArea
)
.
filter_by
(
Id
=
unload_area_id
)
.
first
()
self
.
dump_priority_coefficient
[
self
.
dump_uuid_to_index_dict
[
dump_id
]]
+=
item
.
Priority
def
para_period_update
(
self
):
...
...
@@ -186,9 +149,6 @@ class DumpInfo(WalkManage):
# 计算平均进出场时间
self
.
update_dump_entrance_exit_time
()
# 计算实时卸载量
self
.
update_actual_unload_thoughout
()
# 更新卸点物料
self
.
update_dump_material
()
...
...
equipment/excavator.py
View file @
f3862cae
...
...
@@ -6,8 +6,6 @@
# @File : excavator.py
# @Software: PyCharm
from
traffic_flow.traffic_flow_planner
import
*
from
static_data_process
import
*
from
para_config
import
*
from
settings
import
*
...
...
@@ -18,18 +16,6 @@ class ExcavatorInfo(WalkManage):
# self.dynamic_excavator_set = set(update_autodisp_excavator())
# 装载设备数量
self
.
dynamic_excavator_num
=
len
(
dynamic_excavator_set
)
# 目标产量
self
.
excavator_target_mass
=
np
.
zeros
(
self
.
dynamic_excavator_num
)
# 真实实际产量
self
.
cur_excavator_real_mass
=
np
.
zeros
(
self
.
dynamic_excavator_num
)
# # 预计产量(包含正在驶往目的地的矿卡载重)
# self.pre_excavator_real_mass = copy.deepcopy(self.cur_excavator_real_mass)
# # 模拟实际产量(防止调度修改真实产量)
# self.sim_excavator_real_mass = np.zeros(self.dynamic_excavator_num)
# # 真实设备可用时间
# self.cur_excavator_ava_time = np.zeros(self.dynamic_excavator_num)
# # 模拟各设备可用时间(防止调度修改真实产量)
# self.sim_excavator_ava_time = np.zeros(self.dynamic_excavator_num)
# 用于动态调度的卸载设备集合
self
.
dynamic_excavator_set
=
[]
# 开始时间
...
...
@@ -60,17 +46,12 @@ class ExcavatorInfo(WalkManage):
def
get_excavator_num
(
self
):
return
self
.
dynamic_excavator_num
def
get_excavator_target_mass
(
self
):
return
self
.
excavator_target_mass
def
get_excavator_actual_mass
(
self
):
return
self
.
cur_excavator_real_mass
def
get_dynamic_excavator_set
(
self
):
return
self
.
dynamic_excavator_set
# 更新挖机装载时间
def
update_excavator_loadtime
(
self
):
self
.
loading_time
=
np
.
zeros
(
self
.
dynamic_excavator_num
)
for
excavator_id
in
self
.
excavator_uuid_to_index_dict
.
keys
():
...
...
@@ -95,9 +76,7 @@ class ExcavatorInfo(WalkManage):
except
Exception
as
es
:
logger
.
error
(
f
"挖机 {excavator_id} 装载时间信息缺失, 已设为默认值(1min)"
)
logger
.
error
(
es
)
self
.
loading_time
[
self
.
excavator_uuid_to_index_dict
[
excavator_id
]
]
=
5.00
self
.
loading_time
[
self
.
excavator_uuid_to_index_dict
[
excavator_id
]]
=
5.00
# 更新挖机设备出入时间
def
update_excavator_entrance_exit_time
(
self
):
...
...
@@ -141,37 +120,16 @@ class ExcavatorInfo(WalkManage):
return
loading_task_time
# 更新挖机实际装载量
def
update_actual_load_throughout
(
self
):
self
.
cur_excavator_real_mass
=
np
.
zeros
(
self
.
dynamic_excavator_num
)
now
=
datetime
.
now
()
.
strftime
(
"
%
Y-
%
m-
%
d"
)
for
excavator_id
in
self
.
excavator_uuid_to_index_dict
.
keys
():
# print(excavator_id)
for
query
in
(
session_mysql
.
query
(
LoadInfo
)
.
join
(
Equipment
,
LoadInfo
.
dump_id
==
Equipment
.
equipment_id
)
.
filter
(
Equipment
.
id
==
excavator_id
,
LoadInfo
.
time
>
now
)
.
order_by
(
LoadInfo
.
time
.
desc
())
.
all
()
):
# print("time:", query.time)
# print("load_weight:", )
self
.
cur_excavator_real_mass
[
self
.
excavator_uuid_to_index_dict
[
excavator_id
]
]
=
(
self
.
cur_excavator_real_mass
[
self
.
excavator_uuid_to_index_dict
[
excavator_id
]
]
+
query
.
load_weight
)
def
update_excavator_material
(
self
):
for
excavator_id
in
dynamic_excavator_set
:
load_area_id
=
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
exactor_id
=
excavator_id
)
.
first
()
.
load_area_id
load_area_id
=
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
exactor_id
=
excavator_id
,
isdeleted
=
0
,
isauto
=
1
)
.
first
()
.
load_area_id
excavator_material_id
=
session_postgre
.
query
(
DiggingWorkArea
)
.
filter_by
(
Id
=
load_area_id
)
.
first
()
.
Material
self
.
excavator_material
[
excavator_id
]
=
excavator_material_id
def
update_excavator_priority
(
self
):
self
.
excavator_material_priority
=
np
.
ones
(
dynamic_excavator_num
)
for
excavator_id
in
dynamic_excavator_set
:
item
=
session_mysql
.
query
(
Equipment
)
.
filter_by
(
id
=
excavator_id
)
.
first
()
self
.
excavator_priority_coefficient
[
self
.
excavator_uuid_to_index_dict
[
excavator_id
]]
=
item
.
priority
+
1
...
...
@@ -184,17 +142,15 @@ class ExcavatorInfo(WalkManage):
rule
=
rule7
.
rule_weight
if
rule
==
3
:
if
se
ssion_mysql
.
query
(
Material
)
.
filter_by
(
id
=
self
.
excavator_material
[
excavator_id
])
.
first
()
.
name
==
'土
'
:
if
se
lf
.
excavator_material
[
excavator_id
]
==
'c8092d59-7597-44d7-a731-5a568b46060e
'
:
self
.
excavator_material_priority
[
self
.
excavator_uuid_to_index_dict
[
excavator_id
]]
=
5
elif
rule
==
1
:
if
se
ssion_mysql
.
query
(
Material
)
.
filter_by
(
id
=
self
.
excavator_material
[
excavator_id
])
.
first
()
.
name
==
'煤
'
:
if
se
lf
.
excavator_material
[
excavator_id
]
==
'c481794b-6ced-45b9-a9c4-c4a388f44418
'
:
self
.
excavator_material_priority
[
self
.
excavator_uuid_to_index_dict
[
excavator_id
]]
=
5
def
para_period_update
(
self
):
# print("Excavator update!")
logger
.
info
(
"Excavator update!"
)
# 装载周期参数
...
...
@@ -202,11 +158,6 @@ class ExcavatorInfo(WalkManage):
self
.
period_walk_para_load
()
# # 初始化挖机可用时间
# self.cur_excavator_ava_time = np.full(self.dynamic_excavator_num,
# (datetime.now() - self.start_time) / timedelta(hours=0, minutes=1,
# seconds=0))
# 用于动态调度的挖机设备
self
.
dynamic_excavator_set
=
set
(
update_autodisp_excavator
())
...
...
@@ -215,15 +166,8 @@ class ExcavatorInfo(WalkManage):
# 计算平均装载时间
self
.
update_excavator_loadtime
()
# 计算实时装载量
self
.
update_actual_load_throughout
()
# 更新挖机物料
self
.
update_excavator_material
()
# 更新挖机优先级
# 挖机目标产量
self
.
excavator_target_mass
=
np
.
full
(
self
.
dynamic_excavator_num
,
excavator_target_mass
)
self
.
update_excavator_priority
()
equipment/truck.py
View file @
f3862cae
...
...
@@ -6,8 +6,6 @@
# @File : truck.py
# @Software: PyCharm
from
traffic_flow.traffic_flow_planner
import
*
from
static_data_process
import
*
from
para_config
import
*
from
settings
import
*
from
equipment.dump
import
DumpInfo
...
...
@@ -37,9 +35,6 @@ class TruckInfo(WalkManage):
self
.
truck_current_task
=
{}
# 调度开始时间
self
.
start_time
=
datetime
.
now
()
# # 卡车完成装载及卸载时间
# self.cur_truck_ava_time = np.zeros(self.dynamic_truck_num)
# self.sim_truck_ava_time = np.zeros(self.dynamic_truck_num)
# 矿卡有效载重
self
.
payload
=
np
.
zeros
(
self
.
dynamic_truck_num
)
# 矿卡时速
...
...
@@ -61,14 +56,14 @@ class TruckInfo(WalkManage):
# 矿卡卸点排斥关系
self
.
truck_dump_exclude
=
{}
# 排斥关系modify
self
.
excavator_exclude_modify
=
np
.
zeros
(
self
.
dynamic_truck_num
)
self
.
excavator_exclude_modify
=
np
.
full
((
dynamic_truck_num
,
dynamic_excavator_num
),
0
)
# 矿卡优先级
self
.
truck_priority
=
np
.
ones
(
self
.
dynamic_truck_num
)
# 矿卡绑定物料
self
.
truck_material_bind
=
{}
# 矿卡绑定物料modify
self
.
dump_material_bind_modify
=
np
.
zeros
(
self
.
dynamic_truck_num
)
self
.
excavator_material_bind_modify
=
np
.
zeros
(
self
.
dynamic_truck_num
)
self
.
dump_material_bind_modify
=
np
.
full
((
self
.
dynamic_truck_num
,
dynamic_excavator_num
),
0
)
self
.
excavator_material_bind_modify
=
np
.
zeros
(
self
.
dynamic_truck_num
)
# 引入对象
self
.
dump
=
DumpInfo
()
self
.
excavator
=
ExcavatorInfo
()
...
...
@@ -100,7 +95,7 @@ class TruckInfo(WalkManage):
return
self
.
relative_last_load_time
def
get_realative_last_unload_time
(
self
):
return
self
.
relative_
unlast_
load_time
return
self
.
relative_
last_un
load_time
def
get_payload
(
self
):
return
self
.
payload
...
...
@@ -250,10 +245,6 @@ class TruckInfo(WalkManage):
self
.
dump_uuid_to_index_dict
[
item
.
dump_id
],
self
.
excavator_uuid_to_index_dict
[
item
.
exactor_id
],
]
# if truck_uuid_to_name_dict[self.truck_index_to_uuid_dict[i]] in tmp_set:
# self.cur_truck_reach_excavator[i] = last_unload_time + 10 * self.walk_time_to_load_area[start_area_index][
# end_area_index]
# else:
self
.
cur_truck_reach_excavator
[
i
]
=
(
last_unload_time
+
walk_time_to_load_area
[
start_area_index
][
end_area_index
]
...
...
@@ -336,9 +327,6 @@ class TruckInfo(WalkManage):
elif
item
.
priority
==
3
:
self
.
truck_priority
[
truck_index
]
=
10
logger
.
info
(
"矿卡优先级:"
)
logger
.
info
(
self
.
truck_priority
)
def
update_truck_dump_area_bind
(
self
):
try
:
rule5
=
session_mysql
.
query
(
DispatchRule
)
.
filter_by
(
id
=
5
)
.
first
()
...
...
@@ -354,10 +342,6 @@ class TruckInfo(WalkManage):
logger
.
error
(
"矿卡-卸载区域绑定关系读取异常"
)
logger
.
error
(
es
)
logger
.
info
(
"矿卡-卸载点绑定关系"
)
logger
.
info
(
self
.
truck_dump_bind
)
def
update_truck_excavator_bind
(
self
):
try
:
rule5
=
session_mysql
.
query
(
DispatchRule
)
.
filter_by
(
id
=
5
)
.
first
()
...
...
@@ -374,9 +358,6 @@ class TruckInfo(WalkManage):
logger
.
error
(
"矿卡-挖机绑定关系读取异常"
)
logger
.
error
(
es
)
logger
.
info
(
"矿卡-挖机绑定关系"
)
logger
.
info
(
self
.
truck_excavator_bind
)
def
update_truck_excavator_exclude
(
self
):
self
.
truck_excavator_exclude
=
{}
...
...
@@ -407,10 +388,6 @@ class TruckInfo(WalkManage):
logger
.
error
(
"矿卡-挖机禁止关系读取异常"
)
logger
.
error
(
es
)
logger
.
info
(
"矿卡-挖机禁止关系"
)
logger
.
info
(
self
.
truck_excavator_exclude
)
logger
.
info
(
self
.
excavator_exclude_modify
)
def
update_truck_dump_exclude
(
self
):
pass
...
...
@@ -437,9 +414,11 @@ class TruckInfo(WalkManage):
if
truck_id
in
self
.
truck_excavator_bind
:
excavator_id
=
self
.
truck_excavator_bind
[
truck_id
]
# print(self.excavator.excavator_material)
excavator_material_id
=
self
.
excavator
.
excavator_material
[
excavator_id
]
self
.
truck_material_bind
[
truck_id
]
=
excavator_material_id
for
truck_id
in
dynamic_truck_set
:
truck_index
=
self
.
truck_uuid_to_index_dict
[
truck_id
]
...
...
@@ -460,9 +439,6 @@ class TruckInfo(WalkManage):
if
dump_material_id
!=
material
:
self
.
dump_material_bind_modify
[
truck_index
][
dump_index
]
=
1000000
logger
.
info
(
"矿卡-物料类型"
)
logger
.
info
(
self
.
truck_material_bind
)
def
update_truck_spec
(
self
):
for
truck_id
in
dynamic_truck_set
:
self
.
size
[
truck_id
]
=
session_mysql
.
query
(
Equipment
)
.
filter_by
(
id
=
truck_id
)
.
first
()
.
equipment_spec
...
...
@@ -485,8 +461,6 @@ class TruckInfo(WalkManage):
def
para_period_update
(
self
):
# print("Para truck update!")
# 设备优先级启用
rule6
=
session_mysql
.
query
(
DispatchRule
)
.
filter_by
(
id
=
6
)
.
first
()
.
disabled
...
...
@@ -546,53 +520,3 @@ class TruckInfo(WalkManage):
# 矿卡速度更新
self
.
update_truck_speed
()
# def period_update(self):
#
# print("Truck update!")
#
# # # 更新行走队形
# # self.walker.update_walk_time()
#
# # 装载周期参数
# self.period_map_para_load()
#
# self.period_walk_para_load()
#
# # 更新全部矿卡设备集合
# truck_set = set(update_total_truck())
#
# # 更新固定派车矿卡集合
# fixed_truck_set = set(update_fixdisp_truck())
#
# # 更新动态派车矿卡集合
# self.dynamic_truck_set = truck_set.difference(fixed_truck_set)
#
# # 更新矿卡数量
# self.dynamic_truck_num = len(self.dynamic_truck_set)
#
# # 更新卡车当前任务
# self.update_truck_current_task()
#
# # 更新有效载重
# self.update_truck_payload()
#
# # 更新卡车最后一次装载/卸载时间
# self.update_truck_last_leave_time()
#
# # 更新卡车当前行程
# self.update_truck_trip()
#
# # 更新绑定关系
# self.update_truck_dump_area_bind()
#
# self.update_truck_excavator_bind()
#
# # 更新禁止关系
# self.update_truck_excavator_exclude()
#
# # 更新矿卡调度优先级
# self.update_truck_priority()
#
# # 更新矿卡物料类型
# self.update_truck_material()
path_plan/path_plannner.py
View file @
f3862cae
...
...
@@ -13,7 +13,6 @@ from tables import *
M
=
1000000
class
PathPlanner
(
WalkManage
):
def
__init__
(
self
):
# 路线行驶成本
...
...
@@ -53,21 +52,28 @@ class PathPlanner(WalkManage):
weighted_distance
=
weighted_walk_cost
()
# 修正因子
weight
=
100
00
weight
=
100
# 阻塞成本权重
alpha
=
1
*
weight
alpha
=
0
# 距离成本权重
beta
=
1
session_mysql
.
commit
()
# 距离成本启用
rule1
=
session_mysql
.
query
(
DispatchRule
)
.
filter_by
(
id
=
1
)
.
first
()
if
rule1
.
disabled
==
0
:
alpha
=
alpha
*
rule1
.
rule_weight
beta
=
rule1
.
rule_weight
# 拥堵成本启用
rule2
=
session_mysql
.
query
(
DispatchRule
)
.
filter_by
(
id
=
2
)
.
first
()
if
rule2
.
disabled
==
0
:
beta
=
beta
*
rule2
.
rule_weight
alpha
=
rule2
.
rule_weight
beta
/=
beta
alpha
=
alpha
/
beta
*
weight
try
:
# 备停区处理
...
...
@@ -130,40 +136,39 @@ class PathPlanner(WalkManage):
self
.
period_map_para_load
()
# try:
# 读取路网成本
for
walk_time
in
session_postgre
.
query
(
WalkTime
)
.
all
():
# print(str(walk_time.load_area_id),str(walk_time.unload_area_id))
# print(walk_time.load_area_name, walk_time.unload_area_name)
load_area_id
,
unload_area_id
=
str
(
walk_time
.
load_area_id
),
str
(
walk_time
.
unload_area_id
)
unload_area_index
=
unload_area_uuid_to_index_dict
[
unload_area_id
]
load_area_index
=
load_area_uuid_to_index_dict
[
load_area_id
]
self
.
cost_to_load_area
[
unload_area_index
][
load_area_index
],
\
self
.
cost_to_unload_area
[
unload_area_index
][
load_area_index
]
=
\
self
.
path_cost_generate
(
load_area_id
,
unload_area_id
,
False
)
# 读取备停区路网成本
for
walk_time_park
in
session_postgre
.
query
(
WalkTimePark
)
.
all
():
park_area_index
=
park_uuid_to_index_dict
[
str
(
walk_time_park
.
park_area_id
)]
load_area_index
=
load_area_uuid_to_index_dict
[
str
(
walk_time_park
.
load_area_id
)]
_
,
self
.
cost_park_to_load_area
[
park_area_index
][
load_area_index
]
=
\
self
.
path_cost_generate
(
str
(
walk_time_park
.
load_area_id
),
str
(
walk_time_park
.
park_area_id
),
True
)
# except Exception as es:
# logger.error('路网信息计成本计算异常')
# logger.error(es)
try
:
# 读取路网成本
for
walk_time
in
session_postgre
.
query
(
WalkTime
)
.
all
():
load_area_id
,
unload_area_id
=
str
(
walk_time
.
load_area_id
),
str
(
walk_time
.
unload_area_id
)
unload_area_index
=
unload_area_uuid_to_index_dict
[
unload_area_id
]
load_area_index
=
load_area_uuid_to_index_dict
[
load_area_id
]
self
.
cost_to_load_area
[
unload_area_index
][
load_area_index
],
\
self
.
cost_to_unload_area
[
unload_area_index
][
load_area_index
]
=
\
self
.
path_cost_generate
(
load_area_id
,
unload_area_id
,
False
)
# 读取备停区路网成本
for
walk_time_park
in
session_postgre
.
query
(
WalkTimePark
)
.
all
():
park_area_index
=
park_uuid_to_index_dict
[
str
(
walk_time_park
.
park_area_id
)]
load_area_index
=
load_area_uuid_to_index_dict
[
str
(
walk_time_park
.
load_area_id
)]
self
.
cost_park_to_load_area
[
park_area_index
][
load_area_index
],
_
=
\
self
.
path_cost_generate
(
str
(
walk_time_park
.
load_area_id
),
str
(
walk_time_park
.
park_area_id
),
True
)
except
Exception
as
es
:
logger
.
error
(
'路网信息计成本计算异常'
)
logger
.
error
(
es
)
cost_to_excavator
=
np
.
zeros_like
(
self
.
distance_to_excavator
)
cost_to_dump
=
np
.
zeros_like
(
self
.
distance_to_dump
)
cost_park_to_excavator
=
np
.
zeros_like
(
self
.
distance_park_to_excavator
)
# 路网优先级
walk_weight
=
weighted_walk_cost
()
walk_weight
=
walk_weight
/
walk_weight
.
min
()
# 路网权重
walk_weight
,
park_walk_weight
=
weighted_walk_cost
()
# 路网禁用关系
walk_available
=
available_walk
()
logger
.
info
(
"walk_weight"
,
walk_weight
)
print
(
"path_weight"
,
walk_weight
)
print
(
"walk_avail"
,
walk_available
)
for
i
in
range
(
dynamic_dump_num
):
for
j
in
range
(
dynamic_excavator_num
):
...
...
@@ -172,19 +177,29 @@ class PathPlanner(WalkManage):
cost_to_excavator
[
i
][
j
]
=
self
.
cost_to_load_area
[
unload_area_index
][
load_area_index
]
/
walk_weight
[
i
][
j
]
cost_to_dump
[
i
][
j
]
=
self
.
cost_to_unload_area
[
unload_area_index
][
load_area_index
]
/
walk_weight
[
i
][
j
]
*
walk_available
[
i
][
j
]
for
j
in
range
(
dynamic_excavator_num
):
load_area_index
=
self
.
excavator_index_to_load_area_index_dict
[
j
]
cost_park_to_excavator
[
0
][
j
]
=
self
.
cost_park_to_load_area
[
0
][
load_area_index
]
/
park_walk_weight
[
0
][
j
]
logger
.
info
(
"真实路网距离-驶往挖机:"
)
logger
.
info
(
self
.
distance_to_excavator
)
logger
.
info
(
"真实路网距离-驶往卸点:"
)
logger
.
info
(
self
.
distance_to_dump
)
logger
.
info
(
"加权-阻塞路网距离-驶往挖机:"
)
logger
.
info
(
"真实备停区路网距离-驶往挖机:"
)
logger
.
info
(
self
.
distance_park_to_excavator
)
logger
.
info
(
"阻塞路网距离-驶往挖机:"
)
logger
.
info
(
cost_to_excavator
)
logger
.
info
(
"
加权-
阻塞路网距离-驶往卸点:"
)
logger
.
info
(
"阻塞路网距离-驶往卸点:"
)
logger
.
info
(
cost_to_dump
)
return
cost_to_excavator
,
cost_to_dump
,
walk_weight
,
walk_available
logger
.
info
(
"阻塞备停区路网距离-驶往挖机:"
)
logger
.
info
(
cost_park_to_excavator
)
return
cost_to_excavator
,
cost_to_dump
,
cost_park_to_excavator
class
LaneInfo
:
...
...
@@ -232,18 +247,12 @@ class LaneInfo:
# truck -> lane
truck_locate_dict
=
self
.
update_truck_loacate
()
# print("truck -> lane")
# print(truck_locate_dict)
logger
.
info
(
"矿卡位于路段:"
)
logger
.
info
(
truck_locate_dict
)
# truck -> speed
truck_speed_dict
=
self
.
update_truck_speed
()
# print("truck -> speed")
# print(truck_speed_dict)
logger
.
info
(
"矿卡当前速度:"
)
logger
.
info
(
truck_speed_dict
)
...
...
path_plan/priority_control.py
View file @
f3862cae
...
...
@@ -3,7 +3,7 @@
# @Time : 2021/9/3 14:44
# @Author : Opfer
# @Site :
# @File : priority_control.py
# @File : priority_control.py
# @Software: PyCharm
from
equipment.truck
import
*
...
...
@@ -15,6 +15,7 @@ truck = TruckInfo()
excavator
=
ExcavatorInfo
()
dump
=
DumpInfo
()
def
weighted_walk_cost
():
excavator
.
update_excavator_priority
()
dump
.
update_dump_priority
()
...
...
@@ -23,8 +24,10 @@ def weighted_walk_cost():
excavator_material_priority
=
excavator
.
excavator_material_priority
dump_priority
=
dump
.
dump_priority_coefficient
dump_material_priority
=
np
.
ones
(
dynamic_dump_num
)
park_walk_weight
=
np
.
ones
((
park_num
,
dynamic_excavator_num
))
rule6
=
session_mysql
.
query
(
DispatchRule
)
.
filter_by
(
id
=
6
)
.
first
()
if
not
rule6
.
disabled
:
for
dump_id
in
dynamic_dump_set
:
for
excavator_id
in
dynamic_excavator_set
:
...
...
@@ -32,8 +35,10 @@ def weighted_walk_cost():
excavator_inedx
=
excavator
.
excavator_uuid_to_index_dict
[
excavator_id
]
walk_weight
[
dump_index
][
excavator_inedx
]
+=
dump_priority
[
dump_index
]
*
\
excavator_priority
[
excavator_inedx
]
park_walk_weight
=
park_walk_weight
*
excavator
.
excavator_priority_coefficient
rule7
=
session_mysql
.
query
(
DispatchRule
)
.
filter_by
(
id
=
7
)
.
first
()
if
not
rule7
.
disabled
:
for
dump_id
in
dynamic_dump_set
:
for
excavator_id
in
dynamic_excavator_set
:
...
...
@@ -41,11 +46,13 @@ def weighted_walk_cost():
excavator_inedx
=
excavator
.
excavator_uuid_to_index_dict
[
excavator_id
]
walk_weight
[
dump_index
][
excavator_inedx
]
+=
dump_material_priority
[
dump_index
]
*
\
excavator_material_priority
[
excavator_inedx
]
park_walk_weight
=
park_walk_weight
*
excavator
.
excavator_material_priority
logger
.
info
(
"路网优先级"
)
logger
.
info
(
walk_weight
)
walk_weight
=
walk_weight
-
(
walk_weight
.
min
()
-
1
)
return
walk_weight
park_walk_weight
=
park_walk_weight
-
(
park_walk_weight
.
min
()
-
1
)
return
walk_weight
,
park_walk_weight
def
available_walk
():
...
...
@@ -60,8 +67,5 @@ def available_walk():
if
excavator
.
excavator_material
[
excavator_id
]
!=
dump
.
dump_material
[
dump_id
]:
walk_weight
[
dump_index
][
excavator_inedx
]
+=
1000
logger
.
info
(
"路网禁用关系"
)
logger
.
info
(
walk_weight
)
return
walk_weight
realtime_dispatch.py
View file @
f3862cae
...
...
@@ -77,6 +77,8 @@ class Dispatcher(WalkManage):
(
self
.
dump
.
get_dump_num
(),
self
.
excavator
.
get_excavator_num
())
)
self
.
path
=
PathPlanner
()
# 更新矿卡预计抵达目的地时间
def
update_truck_reach_time
(
self
):
try
:
...
...
@@ -354,109 +356,9 @@ class Dispatcher(WalkManage):
logger
.
info
(
"驶往挖机实际车流"
)
logger
.
info
(
self
.
actual_goto_excavator_traffic_flow
)
# 更新卸载设备预计产量
def
update_pre_unload_throughout
(
self
):
truck_current_task
=
self
.
truck
.
get_truck_current_task
()
payload
=
self
.
truck
.
get_payload
()
try
:
self
.
pre_dump_real_mass
=
copy
.
deepcopy
(
self
.
dump
.
get_dump_actual_mass
())
for
i
in
range
(
self
.
truck
.
get_truck_num
()):
# task = self.truck_current_stage[i][0]
task
=
truck_current_task
[
self
.
truck_index_to_uuid_dict
[
i
]]
end_area_index
=
self
.
truck
.
get_truck_current_trip
()[
i
][
1
]
# 若矿卡正常行驶,需要将该部分载重计入实时产量
if
task
in
heavy_task_set
:
self
.
pre_dump_real_mass
[
end_area_index
]
=
(
self
.
pre_dump_real_mass
[
end_area_index
]
+
payload
[
i
]
)
else
:
pass
except
Exception
as
es
:
logger
.
error
(
"卸载设备预计装载量计算异常"
)
logger
.
error
(
es
)
# 更新挖机预计产量
def
update_pre_load_throughout
(
self
):
truck_current_task
=
self
.
truck
.
get_truck_current_task
()
payload
=
self
.
truck
.
get_payload
()
try
:
self
.
pre_excavator_real_mass
=
copy
.
deepcopy
(
self
.
excavator
.
get_excavator_actual_mass
()
)
for
i
in
range
(
self
.
truck
.
get_truck_num
()):
# task = self.truck_current_stage[i][0]
task
=
truck_current_task
[
self
.
truck_index_to_uuid_dict
[
i
]]
end_area_index
=
self
.
truck
.
get_truck_current_trip
()[
i
][
1
]
# 若矿卡正常行驶,需要将该部分载重计入实时产量
if
task
in
empty_task_set
:
self
.
pre_excavator_real_mass
[
end_area_index
]
=
(
self
.
pre_excavator_real_mass
[
end_area_index
]
+
payload
[
i
]
)
else
:
pass
except
Exception
as
es
:
logger
.
error
(
"挖机/卸载设备预计装载量计算异常"
)
logger
.
error
(
es
)
# def period_update(self):
#
# logger.info(
# "#####################################周期更新开始#####################################"
# )
#
# # 装载周期参数
# self.period_map_para_load()
#
# self.period_walk_para_load()
#
# # 更新卸载设备对象
# self.dump.period_update()
#
# # 更新挖机对象
# self.excavator.period_update()
#
# # 更新矿卡对象
# self.truck.period_update()
#
# # # 更新距离参量
# # self.walker.update_walk_time()
#
# # # 更新设备距离(不同于工作区距离)
# # self.update_walk_time()
#
# # 更新实时车流
# self.update_actual_traffic_flow()
#
# # 计算理想车流
# (
# self.opt_goto_dump_traffic_flow,
# self.opt_goto_excavator_traffic_flow,
# ) = traffic_flow_plan()
#
# # 矿卡抵达时间
# excavator_reach_list, dump_reach_list = self.update_truck_reach_time()
#
# # 挖机可用时间
# self.update_excavator_ava_time(excavator_reach_list)
#
# # 卸载设备可用时间
# self.update_dump_ava_time(dump_reach_list)
#
# # 挖机预计装载量
# self.update_pre_load_throughout()
#
# # 卸载设备预计卸载量
# self.update_pre_unload_throughout()
def
para_period_update
(
self
):
logger
.
info
(
"#####################################周期更新开始#####################################"
)
logger
.
info
(
"#####################################周期更新开始#####################################"
)
# 装载映射参数及
self
.
period_map_para_load
()
...
...
@@ -480,10 +382,7 @@ class Dispatcher(WalkManage):
self
.
update_actual_traffic_flow
()
# 计算理想车流
(
self
.
opt_goto_dump_traffic_flow
,
self
.
opt_goto_excavator_traffic_flow
,
)
=
traffic_flow_plan
()
(
self
.
opt_goto_dump_traffic_flow
,
self
.
opt_goto_excavator_traffic_flow
,)
=
traffic_flow_plan
()
# 矿卡抵达时间
excavator_reach_list
,
dump_reach_list
=
self
.
update_truck_reach_time
()
...
...
@@ -494,12 +393,6 @@ class Dispatcher(WalkManage):
# 卸载设备可用时间
self
.
update_dump_ava_time
(
dump_reach_list
)
# 挖机预计装载量
self
.
update_pre_load_throughout
()
# 卸载设备预计卸载量
self
.
update_pre_unload_throughout
()
def
sim_para_reset
(
self
):
...
...
@@ -508,175 +401,126 @@ class Dispatcher(WalkManage):
self
.
sim_excavator_ava_time
=
copy
.
deepcopy
(
self
.
cur_excavator_ava_time
)
self
.
sim_dump_ava_time
=
copy
.
deepcopy
(
self
.
cur_dump_ava_time
)
# 挖机\卸载设备产量重置
self
.
sim_dump_real_mass
=
copy
.
deepcopy
(
self
.
pre_dump_real_mass
)
self
.
sim_excavator_real_mass
=
copy
.
deepcopy
(
self
.
pre_excavator_real_mass
)
def
truck_schedule
(
self
,
truck_id
):
rule3
=
session_mysql
.
query
(
DispatchRule
)
.
filter_by
(
id
=
3
)
.
first
()
.
disabled
rule4
=
session_mysql
.
query
(
DispatchRule
)
.
filter_by
(
id
=
4
)
.
first
()
.
disabled
path
=
PathPlanner
()
cost_to_excavator
,
cost_to_dump
,
cost_park_to_excavator
=
self
.
path
.
walk_cost
()
cost_to_excavator
,
cost_to_dump
,
walk_weight
,
walk_available
=
path
.
walk_cost
()
excavator_priority_coefficient
=
self
.
excavator
.
excavator_priority_coefficient
excavator_material_priority
=
self
.
excavator
.
excavator_material_priority
# 矿卡对应序号
truck_index
=
self
.
truck_uuid_to_index_dict
[
truck_id
]
# 矿卡行程
trip
=
self
.
truck
.
get_truck_current_trip
()[
truck_index
]
# 矿卡当前任务
task
=
self
.
truck
.
get_truck_current_task
()[
self
.
truck_index_to_uuid_dict
[
truck_index
]
]
# 挖机目标产量
excavator_target_mass
=
self
.
excavator
.
get_excavator_target_mass
()
task
=
self
.
truck
.
get_truck_current_task
()[
self
.
truck_index_to_uuid_dict
[
truck_index
]]
# 挖机装载时间
loading_time
=
self
.
excavator
.
get_loading_time
()
# 卸载设备目标产量
dump_target_mass
=
self
.
dump
.
get_dump_target_mass
()
# 卸载设备卸载时间
unloading_time
=
self
.
dump
.
get_unloading_time
()
# 路网信息
walk_time_park_to_excavator
=
walk_manage
.
get_walk_time_park_to_excavator
()
\
*
(
empty_speed
/
float
(
self
.
truck
.
empty_speed
[
truck_id
]))
walk_time_to_dump
=
walk_manage
.
get_walk_time_to_dump
()
*
\
(
heavy_speed
/
self
.
truck
.
heavy_speed
[
truck_id
])
walk_time_to_excavator
=
walk_manage
.
get_walk_time_to_excavator
()
*
\
(
empty_speed
/
float
(
self
.
truck
.
empty_speed
[
truck_id
]))
# 出入场时间
loading_task_time
=
self
.
excavator
.
get_loading_task_time
()
unloading_task_time
=
self
.
dump
.
get_unloading_task_time
()
dynamic_dump_num
=
self
.
dump
.
get_dump_num
()
dynamic_excavator_num
=
self
.
excavator
.
get_excavator_num
()
now
=
float
(
(
datetime
.
now
()
-
self
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
)
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
))
# print()
# print("调度矿卡:", truck_id, truck_uuid_to_name_dict[truck_id])
logger
.
info
(
" "
)
logger
.
info
(
f
"调度矿卡 {truck_id} {truck_uuid_to_name_dict[truck_id]}"
)
logger
.
info
(
"=========================================================="
)
logger
.
info
(
f
"调度矿卡 {truck_id} {truck_index} {truck_uuid_to_name_dict[truck_id]}"
)
target
=
0
logger
.
info
(
"矿卡-挖机锁定"
)
logger
.
info
(
self
.
truck
.
excavator_material_bind_modify
[
truck_index
])
logger
.
info
(
"矿卡排斥关系"
)
logger
.
info
(
self
.
truck
.
excavator_exclude_modify
[
truck_index
])
if
task
==
-
2
:
try
:
logger
.
info
(
"矿卡状态:矿卡启动或故障恢复"
)
logger
.
info
(
"矿卡行程:无"
)
logger
.
info
(
f
"涉及挖机:{list(self.excavator_uuid_to_index_dict.keys())}"
)
logger
.
info
(
f
"挖机饱和度:{(1 - self.sim_excavator_real_mass / excavator_target_mass)}"
)
logger
.
info
(
f
"行程时间:{(np.maximum(self.sim_excavator_ava_time, now + walk_time_park_to_excavator[0, :]) + loading_time - now)}"
)
f
"行程时间:{(np.maximum(self.sim_excavator_ava_time, now + walk_time_park_to_excavator[0, :]) + loading_time - now)}"
)
logger
.
info
(
f
"行驶时间:{walk_time_park_to_excavator[0, :] + loading_time}"
)
logger
.
info
(
"物料类型"
)
if
truck_id
in
self
.
truck
.
truck_material_bind
:
logger
.
info
(
self
.
truck
.
truck_material_bind
[
truck_id
])
logger
.
info
(
"挖机物料优先级"
)
logger
.
info
(
excavator_material_priority
)
logger
.
info
(
"挖机设备优先级"
)
logger
.
info
(
excavator_priority_coefficient
)
except
Exception
as
es
:
logger
.
error
(
f
"矿卡{truck_id}状态不匹配"
)
logger
.
error
(
es
)
if
truck_id
in
self
.
truck
.
truck_excavator_bind
:
target
=
self
.
excavator_uuid_to_index_dict
[
self
.
truck
.
truck_excavator_bind
[
truck_id
]
]
target
=
self
.
excavator_uuid_to_index_dict
[
self
.
truck
.
truck_excavator_bind
[
truck_id
]]
else
:
transport_value
=
\
(
10
*
(
1
-
self
.
sim_excavator_real_mass
/
excavator_target_mass
)
/
(
np
.
maximum
(
self
.
sim_excavator_ava_time
,
now
+
walk_time_park_to_excavator
[
0
,
:],
)
+
loading_task_time
-
now
)
)
target
=
np
.
argmax
(
transport_value
=
cost_park_to_excavator
logger
.
info
(
"transport_value"
)
logger
.
info
(
transport_value
)
target
=
np
.
argmin
(
transport_value
-
self
.
truck
.
excavator_exclude_modify
[
truck_index
]
-
self
.
truck
.
excavator_material_bind_modify
[
truck_index
]
)
# target = np.argmin((walk_time_park_to_excavator[0, :] + loading_time))
-
self
.
truck
.
excavator_material_bind_modify
[
truck_index
])
logger
.
info
(
f
"目的地:{self.excavator_index_to_uuid_dict[target]}"
)
# print("目的地: ", self.excavator_index_to_uuid_dict[target])
if
task
in
[
0
,
1
,
2
]:
try
:
logger
.
info
(
"矿卡状态:矿卡空载"
)
# logger.info(f'矿卡行程:{self.dump_index_to_uuid_dict[trip[0]]}-{self.excavator_index_to_uuid_dict[trip[1]]}')
logger
.
info
(
f
"涉及卸载设备:{list(self.dump_uuid_to_index_dict.keys())}"
)
# logger.info(f'卸载设备饱和度:{(1 - self.sim_dump_real_mass / dump_target_mass)}')
# logger.info(
# f'行程时间:{(np.maximum(self.sim_dump_ava_time, self.sim_truck_ava_time[truck_index] + walk_time_to_dump[:, trip[1]]) + unloading_time - self.sim_truck_ava_time[truck_index])}')
# logger.info(f'行驶时间:{walk_time_to_dump[:, trip[1]] + unloading_time}')
except
Exception
as
es
:
logger
.
error
(
f
"矿卡{truck_id}状态不匹配"
)
logger
.
error
(
es
)
# # 卡车空载,计算下一次卸载设备
# target = np.argmax(10 * (1 - self.sim_dump_real_mass / dump_target_mass) /
# (np.maximum(self.sim_dump_ava_time,
# # self.sim_truck_reach_excavator[truck_index] + self.loading_time[trip[1]]
# self.sim_truck_ava_time[truck_index]
# + walk_time_to_dump[:, trip[1]]) + unloading_time
# - self.sim_truck_ava_time[truck_index]))
try
:
assert
np
.
array
(
self
.
actual_goto_dump_traffic_flow
)
.
shape
==
(
dynamic_excavator_num
,
dynamic_dump_num
,
)
dynamic_dump_num
,)
assert
np
.
array
(
self
.
opt_goto_dump_traffic_flow
)
.
shape
==
(
dynamic_excavator_num
,
dynamic_dump_num
,
)
dynamic_dump_num
,)
except
Exception
as
es
:
logger
.
warning
(
es
)
self
.
actual_goto_dump_traffic_flow
=
np
.
array
(
self
.
actual_goto_dump_traffic_flow
)
.
reshape
((
dynamic_excavator_num
,
dynamic_dump_num
))
self
.
actual_goto_dump_traffic_flow
)
.
reshape
((
dynamic_excavator_num
,
dynamic_dump_num
))
self
.
opt_goto_dump_traffic_flow
=
np
.
array
(
self
.
opt_goto_dump_traffic_flow
)
.
reshape
((
dynamic_excavator_num
,
dynamic_dump_num
))
self
.
opt_goto_dump_traffic_flow
)
.
reshape
((
dynamic_excavator_num
,
dynamic_dump_num
))
self
.
actual_goto_dump_traffic_flow
=
np
.
array
(
self
.
actual_goto_dump_traffic_flow
)
self
.
actual_goto_dump_traffic_flow
=
np
.
array
(
self
.
actual_goto_dump_traffic_flow
)
self
.
opt_goto_dump_traffic_flow
=
np
.
array
(
self
.
opt_goto_dump_traffic_flow
)
logger
.
info
(
"挖机id:"
)
logger
.
info
(
self
.
excavator_uuid_to_index_dict
)
logger
.
info
(
"卸点id:"
)
logger
.
info
(
self
.
dump_uuid_to_index_dict
)
logger
.
info
(
f
"卸载点实际车流:"
)
logger
.
info
(
self
.
actual_goto_dump_traffic_flow
)
logger
.
info
(
f
"卸载点理想车流:"
)
logger
.
info
(
self
.
opt_goto_dump_traffic_flow
)
logger
.
info
(
"卸载点实际车流"
)
logger
.
info
(
self
.
actual_goto_dump_traffic_flow
[
int
(
trip
[
1
]),
:])
logger
.
info
(
"卸载点理想车流"
)
logger
.
info
(
self
.
opt_goto_dump_traffic_flow
[
int
(
trip
[
1
]),
:])
logger
.
info
(
"物料类型"
)
if
truck_id
in
self
.
truck
.
truck_material_bind
:
logger
.
info
(
self
.
truck
.
truck_material_bind
[
truck_id
])
try
:
logger
.
info
(
"挖机id:"
)
logger
.
info
(
self
.
excavator_uuid_to_index_dict
)
logger
.
info
(
"卸点id:"
)
logger
.
info
(
self
.
dump_uuid_to_index_dict
)
logger
.
info
(
f
"卸载点实际车流:"
)
logger
.
info
(
self
.
actual_goto_dump_traffic_flow
)
logger
.
info
(
f
"卸载点理想车流:"
)
logger
.
info
(
self
.
opt_goto_dump_traffic_flow
)
logger
.
info
(
"卸载点实际车流"
)
logger
.
info
(
self
.
actual_goto_dump_traffic_flow
[
int
(
trip
[
1
]),
:])
logger
.
info
(
"卸载点理想车流"
)
logger
.
info
(
self
.
opt_goto_dump_traffic_flow
[
int
(
trip
[
1
]),
:])
logger
.
info
(
"物料类型"
)
if
truck_id
in
self
.
truck
.
truck_material_bind
:
logger
.
info
(
self
.
truck
.
truck_material_bind
[
truck_id
])
logger
.
info
(
"驶往卸点的运输成本"
)
logger
.
info
(
cost_to_dump
)
logger
.
info
(
"卸点物料修正"
)
logger
.
info
(
self
.
truck
.
dump_material_bind_modify
)
except
Exception
as
es
:
logger
.
info
(
"车流及修正因子"
)
logger
.
info
(
es
)
if
truck_id
in
self
.
truck
.
truck_dump_bind
:
bind_unload_area_id
=
self
.
truck
.
truck_dump_bind
[
truck_id
]
...
...
@@ -686,118 +530,99 @@ class Dispatcher(WalkManage):
break
else
:
if
rule3
and
rule4
:
transport_value
=
(
cost_to_excavator
/
walk_weight
*
walk_available
)[:,
int
(
trip
[
1
])]
logger
.
info
(
"不含车流规划:"
)
logger
.
info
(
transport_value
)
transport_value
=
cost_to_dump
[:,
int
(
trip
[
1
])]
else
:
transport_value
=
\
(
self
.
actual_goto_dump_traffic_flow
[
int
(
trip
[
1
]),
:]
+
0.001
)
\
/
(
self
.
opt_goto_dump_traffic_flow
[
int
(
trip
[
1
]),
:]
+
0.001
)
transport_value
=
(
self
.
actual_goto_dump_traffic_flow
[
int
(
trip
[
1
]),
:]
+
0.001
)
\
/
(
self
.
opt_goto_dump_traffic_flow
[
int
(
trip
[
1
]),
:]
+
0.001
)
logger
.
info
(
"transport_value"
)
logger
.
info
(
transport_value
)
target
=
np
.
argmin
(
transport_value
+
self
.
truck
.
excavator_exclude_modify
[
truck_index
]
+
self
.
truck
.
excavator_material_bind_modify
[
truck_index
]
)
+
self
.
truck
.
dump_material_bind_modify
[
truck_index
])
logger
.
info
(
"车流比:"
)
logger
.
info
(
(
self
.
actual_goto_dump_traffic_flow
[
int
(
trip
[
1
]),
:]
+
0.001
)
/
(
self
.
opt_goto_dump_traffic_flow
[
int
(
trip
[
1
]),
:]
+
0.001
)
)
logger
.
info
((
self
.
actual_goto_dump_traffic_flow
[
int
(
trip
[
1
]),
:]
+
0.001
)
\
/
(
self
.
opt_goto_dump_traffic_flow
[
int
(
trip
[
1
]),
:]
+
0.001
))
logger
.
info
(
f
"目的地:{self.dump_index_to_uuid_dict[target]}"
)
elif
task
in
[
3
,
4
,
5
]:
try
:
logger
.
info
(
"矿卡状态:矿卡重载"
)
# logger.info(f'矿卡行程:{self.excavator_index_to_uuid_dict[trip[0]]}-{self.dump_index_to_uuid_dict[trip[1]]}')
logger
.
info
(
f
"涉及挖机设备:{list(self.excavator_uuid_to_index_dict.keys())}"
)
# logger.info(f'卸载设备饱和度:{(1 - self.sim_excavator_real_mass / excavator_target_mass)}')
# logger.info(
# f'行程时间:{(np.maximum(self.sim_excavator_ava_time, self.sim_truck_ava_time[truck_index] + walk_time_to_excavator[trip[1], :]) + loading_time - self.sim_truck_ava_time[truck_index])}')
# logger.info(f'行驶时间:{walk_time_to_excavator[trip[1], :] + loading_time}')
except
Exception
as
es
:
logger
.
error
(
f
"矿卡{truck_id}状态不匹配"
)
logger
.
error
(
es
)
# # 卡车重载,计算下一次装载点
# target = np.argmax(10 * (1 - self.sim_excavator_real_mass / excavator_target_mass) /
# (np.maximum(self.sim_excavator_ava_time,
# self.sim_truck_ava_time[truck_index]
# + walk_time_to_excavator[trip[1], :]) + loading_time
# - self.sim_truck_ava_time[truck_index]))
try
:
assert
np
.
array
(
self
.
actual_goto_excavator_traffic_flow
)
.
shape
==
(
dynamic_excavator_num
,
dynamic_dump_num
,
)
dynamic_dump_num
,)
assert
np
.
array
(
self
.
opt_goto_excavator_traffic_flow
)
.
shape
==
(
dynamic_excavator_num
,
dynamic_dump_num
,
)
dynamic_dump_num
,)
except
Exception
as
es
:
logger
.
warning
(
es
)
self
.
actual_goto_excavator_traffic_flow
=
np
.
array
(
self
.
actual_goto_excavator_traffic_flow
)
.
reshape
((
dynamic_dump_num
,
dynamic_excavator_num
))
self
.
actual_goto_excavator_traffic_flow
)
.
reshape
((
dynamic_dump_num
,
dynamic_excavator_num
))
self
.
opt_goto_excavator_traffic_flow
=
np
.
array
(
self
.
opt_goto_excavator_traffic_flow
)
.
reshape
((
dynamic_dump_num
,
dynamic_excavator_num
))
self
.
opt_goto_excavator_traffic_flow
)
.
reshape
((
dynamic_dump_num
,
dynamic_excavator_num
))
# 不知道为什么,偶尔变成了list
self
.
actual_goto_excavator_traffic_flow
=
np
.
array
(
self
.
actual_goto_excavator_traffic_flow
)
self
.
opt_goto_excavator_traffic_flow
=
np
.
array
(
self
.
opt_goto_excavator_traffic_flow
)
logger
.
info
(
"挖机id:"
)
logger
.
info
(
self
.
excavator_uuid_to_index_dict
)
logger
.
info
(
"卸点id:"
)
logger
.
info
(
self
.
dump_uuid_to_index_dict
)
logger
.
info
(
f
"挖机实际车流:"
)
logger
.
info
(
self
.
actual_goto_excavator_traffic_flow
)
logger
.
info
(
f
"挖机理想车流:"
)
logger
.
info
(
self
.
opt_goto_excavator_traffic_flow
)
logger
.
info
(
"挖机实际车流"
)
logger
.
info
(
self
.
actual_goto_excavator_traffic_flow
[
trip
[
1
],
:])
logger
.
info
(
"挖机理想车流"
)
logger
.
info
(
self
.
opt_goto_excavator_traffic_flow
[
trip
[
1
],
:])
logger
.
info
(
"物料类型"
)
if
truck_id
in
self
.
truck
.
truck_material_bind
:
logger
.
info
(
self
.
truck
.
truck_material_bind
[
truck_id
])
self
.
actual_goto_excavator_traffic_flow
=
np
.
array
(
self
.
actual_goto_excavator_traffic_flow
)
self
.
opt_goto_excavator_traffic_flow
=
np
.
array
(
self
.
opt_goto_excavator_traffic_flow
)
try
:
logger
.
info
(
"挖机id:"
)
logger
.
info
(
self
.
excavator_uuid_to_index_dict
)
logger
.
info
(
"卸点id:"
)
logger
.
info
(
self
.
dump_uuid_to_index_dict
)
logger
.
info
(
f
"挖机实际车流:"
)
logger
.
info
(
self
.
actual_goto_excavator_traffic_flow
)
logger
.
info
(
f
"挖机理想车流:"
)
logger
.
info
(
self
.
opt_goto_excavator_traffic_flow
)
logger
.
info
(
"挖机实际车流"
)
logger
.
info
(
self
.
actual_goto_excavator_traffic_flow
[
trip
[
1
],
:])
logger
.
info
(
"挖机理想车流"
)
logger
.
info
(
self
.
opt_goto_excavator_traffic_flow
[
trip
[
1
],
:])
logger
.
info
(
"物料类型"
)
if
truck_id
in
self
.
truck
.
truck_material_bind
:
logger
.
info
(
self
.
truck
.
truck_material_bind
[
truck_id
])
logger
.
info
(
"驶往挖机的运输成本"
)
logger
.
info
(
cost_to_excavator
)
logger
.
info
(
"挖机物料修正"
)
logger
.
info
(
self
.
truck
.
excavator_material_bind_modify
)
logger
.
info
(
"挖机优先级修正"
)
logger
.
info
(
self
.
excavator
.
excavator_priority_coefficient
)
except
Exception
as
es
:
logger
.
info
(
"车流及修正因子"
)
logger
.
info
(
es
)
if
truck_id
in
self
.
truck
.
truck_excavator_bind
:
target
=
self
.
excavator_uuid_to_index_dict
[
self
.
truck
.
truck_excavator_bind
[
truck_id
]
]
target
=
self
.
excavator_uuid_to_index_dict
[
self
.
truck
.
truck_excavator_bind
[
truck_id
]]
else
:
if
rule3
and
rule4
:
transport_value
=
(
cost_to_excavator
/
walk_weight
*
walk_available
)
[
int
(
trip
[
1
]),
:]
transport_value
=
cost_to_excavator
[
int
(
trip
[
1
]),
:]
else
:
transport_value
=
\
(
self
.
actual_goto_excavator_traffic_flow
[
trip
[
1
],
:]
+
0.001
)
\
/
(
self
.
opt_goto_excavator_traffic_flow
[
trip
[
1
],
:]
+
0.001
)
transport_value
=
(
self
.
actual_goto_excavator_traffic_flow
[
trip
[
1
],
:]
+
0.001
)
\
/
(
self
.
opt_goto_excavator_traffic_flow
[
trip
[
1
],
:]
+
0.001
)
logger
.
info
(
"transport_value"
)
logger
.
info
(
transport_value
)
target
=
np
.
argmin
(
transport_value
target
=
np
.
argmin
(
transport_value
+
self
.
truck
.
excavator_exclude_modify
[
truck_index
]
+
self
.
truck
.
excavator_material_bind_modify
[
truck_index
]
)
+
self
.
truck
.
excavator_material_bind_modify
[
truck_index
])
logger
.
info
(
"车流比:"
)
logger
.
info
(
(
self
.
actual_goto_excavator_traffic_flow
[
trip
[
1
],
:]
+
0.001
)
/
(
self
.
opt_goto_excavator_traffic_flow
[
trip
[
1
],
:]
+
0.001
)
)
/
(
self
.
opt_goto_excavator_traffic_flow
[
trip
[
1
],
:]
+
0.001
))
logger
.
info
(
f
"目的地:{self.excavator_index_to_uuid_dict[target]}"
)
logger
.
info
(
"=========================================================="
)
return
target
def
schedule_construct
(
self
):
...
...
@@ -842,15 +667,14 @@ class Dispatcher(WalkManage):
if
len
(
Seq
[
truck
])
>
0
:
# try:
task
=
truck_current_task
[
self
.
truck_index_to_uuid_dict
[
truck
]]
# 矿卡结束当前派车计划后的目的地
end_eq_index
=
truck_current_trip
[
truck
][
1
]
# 调用调度函数,得到最优目的地序号
target_eq_index
=
self
.
truck_schedule
(
self
.
truck_index_to_uuid_dict
[
truck
]
)
target_eq_index
=
self
.
truck_schedule
(
self
.
truck_index_to_uuid_dict
[
truck
])
# 写入Seq序列
Seq
[
truck
][
1
]
=
target_eq_index
...
...
@@ -862,77 +686,45 @@ class Dispatcher(WalkManage):
try
:
if
task
in
empty_task_set
:
target_area_index
=
self
.
dump_index_to_unload_area_index_dict
[
target_eq_index
]
end_area_index
=
self
.
excavator_index_to_load_area_index_dict
[
end_eq_index
]
target_area_index
=
self
.
dump_index_to_unload_area_index_dict
[
target_eq_index
]
end_area_index
=
self
.
excavator_index_to_load_area_index_dict
[
end_eq_index
]
# 更新变量,预计产量更新
self
.
sim_dump_real_mass
[
target_eq_index
]
=
(
self
.
sim_dump_real_mass
[
target_eq_index
]
+
payload
[
truck
]
)
self
.
sim_dump_real_mass
[
target_eq_index
]
=
\
(
self
.
sim_dump_real_mass
[
target_eq_index
]
+
payload
[
truck
])
# 预计卸载设备可用时间更新
self
.
sim_dump_ava_time
[
target_eq_index
]
=
(
max
(
self
.
sim_dump_ava_time
[
target_eq_index
],
self
.
sim_truck_ava_time
[
truck
]
+
walk_time_to_unload_area
[
target_area_index
][
end_area_index
],
)
self
.
sim_truck_ava_time
[
truck
]
+
\
walk_time_to_unload_area
[
target_area_index
][
end_area_index
],)
+
unloading_task_time
[
target_eq_index
]
)
elif
task
in
heavy_task_set
:
target_area_index
=
(
self
.
excavator_index_to_load_area_index_dict
[
target_eq_index
]
)
end_area_index
=
self
.
dump_index_to_unload_area_index_dict
[
end_eq_index
]
target_area_index
=
(
self
.
excavator_index_to_load_area_index_dict
[
target_eq_index
])
end_area_index
=
self
.
dump_index_to_unload_area_index_dict
[
end_eq_index
]
# 更新变量,预计产量更新
self
.
sim_excavator_real_mass
[
target_eq_index
]
=
(
self
.
sim_excavator_real_mass
[
target_eq_index
]
+
payload
[
truck
]
)
self
.
sim_excavator_real_mass
[
target_eq_index
]
=
(
self
.
sim_excavator_real_mass
[
target_eq_index
]
+
payload
[
truck
])
# 预计装载点可用时间更新
self
.
sim_excavator_ava_time
[
target_eq_index
]
=
(
max
(
self
.
sim_excavator_ava_time
[
target_eq_index
],
self
.
sim_truck_ava_time
[
truck
]
+
walk_time_to_unload_area
[
end_area_index
][
target_area_index
],
)
+
loading_task_time
[
target_eq_index
]
)
max
(
self
.
sim_excavator_ava_time
[
target_eq_index
],
self
.
sim_truck_ava_time
[
truck
]
+
walk_time_to_unload_area
[
end_area_index
][
target_area_index
],)
\
+
loading_task_time
[
target_eq_index
])
else
:
pass
except
Exception
as
es
:
logger
.
error
(
f
"矿卡 {truck_uuid_to_name_dict[self.truck_index_to_uuid_dict[truck]]} 调度状态更新异常"
)
logger
.
error
(
f
"矿卡 {truck_uuid_to_name_dict[self.truck_index_to_uuid_dict[truck]]} 调度状态更新异常"
)
logger
.
error
(
es
)
for
i
in
range
(
len
(
Seq
)):
try
:
record
=
{
"truckId"
:
self
.
truck_index_to_uuid_dict
[
i
]}
task
=
self
.
truck
.
get_truck_current_task
()[
self
.
truck_index_to_uuid_dict
[
i
]
]
task
=
self
.
truck
.
get_truck_current_task
()[
self
.
truck_index_to_uuid_dict
[
i
]]
if
task
in
empty_task_set
:
item
=
(
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
dump_id
=
self
.
dump_index_to_uuid_dict
[
Seq
[
i
][
1
]],
isauto
=
1
,
isdeleted
=
0
,
)
.
first
()
)
.
filter_by
(
dump_id
=
self
.
dump_index_to_uuid_dict
[
Seq
[
i
][
1
]],
isauto
=
1
,
isdeleted
=
0
,)
.
first
())
record
[
"exactorId"
]
=
item
.
exactor_id
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"loadAreaId"
]
=
item
.
load_area_id
...
...
@@ -941,18 +733,11 @@ class Dispatcher(WalkManage):
record
[
"isdeleted"
]
=
False
record
[
"creator"
]
=
item
.
creator
record
[
"createtime"
]
=
item
.
createtime
.
strftime
(
"
%
b
%
d,
%
Y
%#
I:
%#
M:
%#
S
%
p"
)
"
%
b
%
d,
%
Y
%#
I:
%#
M:
%#
S
%
p"
)
elif
task
in
heavy_task_set
:
item
=
(
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
exactor_id
=
self
.
excavator_index_to_uuid_dict
[
Seq
[
i
][
1
]],
isauto
=
1
,
isdeleted
=
0
,
)
.
first
()
)
.
filter_by
(
exactor_id
=
self
.
excavator_index_to_uuid_dict
[
Seq
[
i
][
1
]],
isauto
=
1
,
isdeleted
=
0
,)
.
first
())
record
[
"exactorId"
]
=
self
.
excavator_index_to_uuid_dict
[
Seq
[
i
][
1
]]
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"loadAreaId"
]
=
item
.
load_area_id
...
...
@@ -961,18 +746,11 @@ class Dispatcher(WalkManage):
record
[
"isdeleted"
]
=
False
record
[
"creator"
]
=
item
.
creator
record
[
"createtime"
]
=
item
.
createtime
.
strftime
(
"
%
b
%
d,
%
Y
%#
I:
%#
M:
%#
S
%
p"
)
"
%
b
%
d,
%
Y
%#
I:
%#
M:
%#
S
%
p"
)
elif
task
==
-
2
:
item
=
(
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
exactor_id
=
self
.
excavator_index_to_uuid_dict
[
Seq
[
i
][
1
]],
isauto
=
1
,
isdeleted
=
0
,
)
.
first
()
)
.
filter_by
(
exactor_id
=
self
.
excavator_index_to_uuid_dict
[
Seq
[
i
][
1
]],
isauto
=
1
,
isdeleted
=
0
,)
.
first
())
record
[
"exactorId"
]
=
item
.
exactor_id
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"loadAreaId"
]
=
item
.
load_area_id
...
...
@@ -981,8 +759,7 @@ class Dispatcher(WalkManage):
record
[
"isdeleted"
]
=
False
record
[
"creator"
]
=
item
.
creator
record
[
"createtime"
]
=
item
.
createtime
.
strftime
(
"
%
b
%
d,
%
Y
%#
I:
%#
M:
%#
S
%
p"
)
"
%
b
%
d,
%
Y
%#
I:
%#
M:
%#
S
%
p"
)
else
:
pass
...
...
@@ -999,9 +776,7 @@ class Dispatcher(WalkManage):
# logger.error("更新不及时")
# logger.error(es)
logger
.
info
(
"#####################################周期更新结束#####################################"
)
logger
.
info
(
"#####################################周期更新结束#####################################"
)
return
Seq
...
...
@@ -1021,14 +796,6 @@ def para_process(dispatcher):
# 更新周期参数
period_para_update
()
# # 清空数据库缓存
# session_mysql.commit()
# session_mysql.flush()
#
# # 清空数据库缓存
# session_postgre.commit()
# session_postgre.flush()
# 周期更新
dispatcher
.
para_period_update
()
...
...
@@ -1044,7 +811,6 @@ def para_process(dispatcher):
# logger.error("更新不及时")
# logger.error(es)
def
state_process
(
dispatcher
):
# print("state_process!")
...
...
@@ -1072,10 +838,6 @@ def state_process(dispatcher):
# logger.error("更新不及时")
# logger.error(es)
# 下面三个函数保证程序定期执行,不用管他
def
process
(
dispatcher
):
...
...
@@ -1103,65 +865,4 @@ if __name__ == "__main__":
dispatcher
=
Dispatcher
()
main
(
10
,
dispatcher
)
# # 下面三个函数保证程序定期执行,不用管他
# def process(dispatcher):
#
# # 更新周期参数
# period_para_update()
#
# # 清空数据库缓存
# session_mysql.commit()
# session_mysql.flush()
#
# # 清空数据库缓存
# session_postgre.commit()
# session_postgre.flush()
#
# # 周期更新
# dispatcher.period_update()
#
# # 参数重置
# dispatcher.sim_para_reset()
#
# # try:
#
# # 调度计算
# dispatcher.schedule_construct()
#
# # except Exception as es:
# # logger.error("更新不及时")
# # logger.error(es)
#
#
# dispatcher = Dispatcher()
#
# para_process(dispatcher)
#
# state_process(dispatcher)
#
#
# jobstores = {'default': MemoryJobStore()}
#
# executors = {'default': ThreadPoolExecutor(10)}
#
# job_defaults = {'coalesce': False, 'max_instances': 10}
#
# scheduler = BlockingScheduler(jobstores=jobstores, executors=executors, job_defaults=job_defaults)
#
# # scheduler = BlockingScheduler()
#
# scheduler.add_job(para_process, args=[dispatcher], id='ins1', trigger='interval', seconds=60)
#
# scheduler.add_job(state_process, args=[dispatcher], id='ins2', trigger='interval', seconds=10)
#
# if __name__ == '__main__':
# try:
# scheduler.start()
# except SystemExit:
# print('exit')
# exit()
\ No newline at end of file
main
(
10
,
dispatcher
)
\ No newline at end of file
settings.py
View file @
f3862cae
...
...
@@ -28,8 +28,8 @@ import time
log_path
=
"/usr/local/fleet-log/dispatch"
# 创建日志目录
if
not
os
.
path
.
exists
(
log_path
):
os
.
mkdir
(
log_path
)
#
if not os.path.exists(log_path):
#
os.mkdir(log_path)
# logging初始化工作
logging
.
basicConfig
()
...
...
@@ -39,8 +39,8 @@ logger.setLevel(logging.INFO)
# timefilehandler = logging.handlers.TimedRotatingFileHandler(log_path + "/dispatch.log", when='M', interval=1, backupCount=60)
filehandler
=
logging
.
handlers
.
RotatingFileHandler
(
log_path
+
"/dispatch.log"
,
maxBytes
=
3
*
1024
*
1024
,
backupCount
=
10
)
#
filehandler = logging.handlers.RotatingFileHandler("./Logs/dispatch.log", maxBytes=3 * 1024 * 1024, backupCount=10)
#
filehandler = logging.handlers.RotatingFileHandler(log_path + "/dispatch.log", maxBytes=3*1024*1024, backupCount=10)
filehandler
=
logging
.
handlers
.
RotatingFileHandler
(
"./Logs/dispatch.log"
,
maxBytes
=
3
*
1024
*
1024
,
backupCount
=
10
)
# 设置后缀名称,跟strftime的格式一样
filehandler
.
suffix
=
"
%
Y-
%
m-
%
d_
%
H-
%
M.log"
...
...
tables.py
View file @
f3862cae
...
...
@@ -390,13 +390,15 @@ class DumpArea(Base):
UnloadAbililty
=
Column
(
Float
)
Disabled
=
Column
(
Integer
)
Material
=
Column
(
VARCHAR
(
36
))
Priority
=
Column
(
Integer
)
def
__init__
(
self
,
Id
,
BindList
,
UnloadAbililty
,
Disabled
,
Material
):
def
__init__
(
self
,
Id
,
BindList
,
UnloadAbililty
,
Disabled
,
Material
,
Priority
):
self
.
Id
=
Id
self
.
BindList
=
BindList
self
.
UnloadAbililty
=
UnloadAbililty
self
.
Disabled
=
Disabled
self
.
Material
=
Material
self
.
Priority
=
Priority
class
DiggingWorkArea
(
Base
):
...
...
@@ -424,7 +426,7 @@ class DispatchRule(Base):
class
Material
(
Base
):
__tablename__
=
'resource_m
ate
rials'
__tablename__
=
'resource_m
eta
rials'
id
=
Column
(
VARCHAR
(
40
),
primary_key
=
True
)
name
=
Column
(
VARCHAR
(
40
))
...
...
traffic_flow/traffic_flow_info.py
View file @
f3862cae
...
...
@@ -7,9 +7,8 @@
# @Software: PyCharm
# import
from
path_plan.path_plannner
import
*
from
traffic_flow.traffic_flow_planner
import
*
from
path_plan.path_plannner
import
*
from
para_config
import
*
from
equipment.excavator
import
ExcavatorInfo
from
equipment.dump
import
DumpInfo
...
...
@@ -194,6 +193,7 @@ class Traffic_para(WalkManage):
#
# if rule == 0:
# if self.excavator.excavator_material[excavator_id] == 'c8092d59-7597-44d7-a731-5a568b46060e':
# print("here111")
# self.excavator_material_priority[self.excavator_uuid_to_index_dict[excavator_id]] = 5
# elif rule == 2:
# if self.excavator.excavator_material[excavator_id] == 'c481794b-6ced-45b9-a9c4-c4a388f44418':
...
...
@@ -338,6 +338,7 @@ def Traffic_para_init(num_of_load_area, num_of_unload_area, num_of_excavator, nu
# # 设备优先级
# if not device_priority_use:
# print("here1")
# # 每条卸载道路的优先级,等于电铲的优先级乘以卸载点的优先级
# tra_para.priority_coefficient_goto_dump[i][j] = tra_para.excavator_priority_coefficient[i] \
# * tra_para.dump_priority_coefficient[j]
...
...
@@ -347,6 +348,7 @@ def Traffic_para_init(num_of_load_area, num_of_unload_area, num_of_excavator, nu
# * tra_para.dump_priority_coefficient[j]
# # 物料优先级
# if not material_priority_use:
# print("here2")
# # # 每条卸载道路的优先级,等于电铲的优先级乘以卸载点的优先级
# # tra_para.priority_coefficient_goto_dump[i][j] += tra_para.excavator_material_priority[i] \
# # * tra_para.dump_material_priority[j]
...
...
@@ -364,10 +366,7 @@ def Traffic_para_init(num_of_load_area, num_of_unload_area, num_of_excavator, nu
# tra_para.walk_time_to_dump[i][j] = \
# tra_para.walk_time_to_unload_area[load_area_index][unload_area_index]
logger
.
info
(
"priority_coefficient_goto_dump"
)
logger
.
info
(
tra_para
.
priority_coefficient_goto_dump
)
logger
.
info
(
"priority_coefficient_goto_excavator"
)
logger
.
info
(
tra_para
.
priority_coefficient_goto_excavator
)
print
(
"cout"
,
tra_para
.
priority_coefficient_goto_dump
,
tra_para
.
priority_coefficient_goto_excavator
)
# except Exception as es:
# logger.error(es)
...
...
traffic_flow/traffic_flow_planner.py
View file @
f3862cae
...
...
@@ -39,7 +39,7 @@ def transportation_problem_slove(coefficient_goto_dump, coefficient_goto_excavat
if
max_unload_weigh_alg_flag
==
True
:
prob
=
pulp
.
LpProblem
(
'Transportation Problem'
,
sense
=
pulp
.
LpMaximize
)
# 得到目标函数,目标函数是使得系统的运输量最大
prob
+=
(
pulp
.
lpDot
(
flatten
(
var_
y
),
coefficient_goto_excavator
.
flatten
()))
prob
+=
(
pulp
.
lpDot
(
flatten
(
var_
x
),
coefficient_goto_dump
.
flatten
()))
else
:
prob
=
pulp
.
LpProblem
(
'Transportation Problem'
,
sense
=
pulp
.
LpMinimize
)
goto_excavator_cost
=
var_x
*
walk_time_to_excavator
...
...
@@ -168,7 +168,7 @@ def traffic_flow_plan():
walk_time_to_dump
=
traffic_programme_para
.
walk_time_to_dump
truck_total_num
=
traffic_programme_para
.
truck_total_num
#
print(w_ij, s_ij, b_excavator, b_dump)
print
(
w_ij
,
s_ij
,
b_excavator
,
b_dump
)
res
=
transportation_problem_slove
(
coefficient_goto_dump
,
coefficient_goto_excavator
,
w_ij
,
s_ij
,
b_excavator
,
b_dump
,
grade_loading_array
,
max_unload_weigh_alg_flag
,
truck_total_num
,
...
...
@@ -184,16 +184,12 @@ def traffic_flow_plan():
print
(
'各变量的取值为:'
)
logger
.
info
(
'各变量取值:'
)
logger
.
info
(
dynamic_excavator_set
)
logger
.
info
(
dynamic_dump_set
)
print
(
dynamic_excavator_set
)
print
(
dynamic_dump_set
)
print
(
dynamic_excavator_set
)
print
(
np
.
array
(
res
[
'var_x'
])
.
round
(
3
))
logger
.
info
(
f
'重运车流:{res["var_x"]} 单位: 吨/时'
)
logger
.
info
(
dynamic_dump_set
)
logger
.
info
(
dynamic_excavator_set
)
print
(
dynamic_dump_set
)
print
(
dynamic_excavator_set
)
print
(
dynamic_dump_set
)
print
(
np
.
array
(
res
[
'var_y'
])
.
round
(
3
))
logger
.
info
(
f
'空运车流:{res["var_y"]} 单位: 吨/时'
)
...
...
wato_dispatch.py
deleted
100644 → 0
View file @
2c77ecd3
#!E:\Pycharm Projects\Waytous
# -*- coding: utf-8 -*-
# @Time : 2021/6/15 10:35
# @Author : Opfer
# @Site :
# @File : wato_dispatch.py
# @Software: PyCharm
# 独立的调度系统
from
sqlalchemy
import
Column
,
create_engine
from
sqlalchemy
import
VARCHAR
,
DateTime
,
Float
,
Integer
,
BOOLEAN
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.ext.declarative
import
declarative_base
import
numpy
as
np
from
redis
import
StrictRedis
,
ConnectionPool
import
redis
from
datetime
import
datetime
,
timedelta
import
copy
import
json
import
sched
import
time
from
tables
import
*
from
urllib.parse
import
quote
import
logging
import
logging.handlers
# 全局参数设定
########################################################################################################################
empty_task_set
=
[
0
,
1
,
5
]
heavy_task_set
=
[
2
,
3
,
4
]
# 空载矿卡速度,单位(km/h)
empty_speed
=
25
# 重载矿卡速度,单位(km/h)
heavy_speed
=
22
# 卸点目标卸载量
dump_target_mass
=
5000
# 挖机目标装载量
shovel_target_mass
=
5000
task_set
=
[
-
2
,
0
,
1
,
2
,
3
,
4
,
5
]
M
=
100000000
# 连接reids
########################################################################################################################
pool5
=
ConnectionPool
(
host
=
'192.168.28.111'
,
db
=
5
,
port
=
6379
,
password
=
'Huituo@123'
)
redis5
=
StrictRedis
(
connection_pool
=
pool5
)
pool2
=
ConnectionPool
(
host
=
'192.168.28.111'
,
db
=
2
,
port
=
6379
,
password
=
'Huituo@123'
)
redis2
=
StrictRedis
(
connection_pool
=
pool2
)
# 创建对象的基类:
Base
=
declarative_base
()
# 初始化数据库连接:
engine_mysql
=
create_engine
(
'mysql+mysqlconnector://root:
%
s@192.168.28.111:3306/waytous'
%
quote
(
'Huituo@123'
))
engine_postgre
=
create_engine
(
'postgresql://postgres:
%
s@192.168.28.111:5432/shenbao_2021520'
%
quote
(
'Huituo@123'
))
# 创建DBsession_mysql类型:
DBsession_mysql
=
sessionmaker
(
bind
=
engine_mysql
)
DBsession_postgre
=
sessionmaker
(
bind
=
engine_postgre
)
# 创建session_mysql对象:
session_mysql
=
DBsession_mysql
()
session_postgre
=
DBsession_postgre
()
# 创建日志
########################################################################################################################
# logging初始化工作
logging
.
basicConfig
()
logger
=
logging
.
getLogger
(
__name__
)
logger
.
setLevel
(
logging
.
INFO
)
timefilehandler
=
logging
.
handlers
.
TimedRotatingFileHandler
(
"RDlogs/dispatch.log"
,
when
=
'M'
,
interval
=
1
,
backupCount
=
60
)
# 设置后缀名称,跟strftime的格式一样
timefilehandler
.
suffix
=
"
%
Y-
%
m-
%
d_
%
H-
%
M.log"
formatter
=
logging
.
Formatter
(
'
%(asctime)
s|
%(name)-12
s:
%(levelname)-8
s
%(message)
s'
)
timefilehandler
.
setFormatter
(
formatter
)
logger
.
addHandler
(
timefilehandler
)
########################################################################################################################
# load_area_id <-> load_area_index
# unload_area_id <-> unload_area_index
load_area_uuid_to_index_dict
=
{}
unload_area_uuid_to_index_dict
=
{}
load_area_index_to_uuid_dict
=
{}
unload_area_index_to_uuid_dict
=
{}
unload_area_num
=
0
load_area_num
=
0
for
item
in
session_postgre
.
query
(
WalkTime
)
.
all
():
load_area
=
str
(
item
.
load_area_id
)
unload_area
=
str
(
item
.
unload_area_id
)
if
load_area
not
in
load_area_uuid_to_index_dict
:
load_area_uuid_to_index_dict
[
load_area
]
=
load_area_num
load_area_index_to_uuid_dict
[
load_area_num
]
=
load_area
load_area_num
=
load_area_num
+
1
if
unload_area
not
in
unload_area_uuid_to_index_dict
:
unload_area_uuid_to_index_dict
[
unload_area
]
=
unload_area_num
unload_area_index_to_uuid_dict
[
unload_area_num
]
=
unload_area
unload_area_num
=
unload_area_num
+
1
########################################################################################################################
# park_id <-> park_index
park_uuid_to_index_dict
=
{}
park_index_to_uuid_dict
=
{}
park_num
=
0
for
item
in
session_postgre
.
query
(
WalkTimePark
)
.
all
():
park
=
str
(
item
.
park_area_id
)
if
park
not
in
park_uuid_to_index_dict
:
park_uuid_to_index_dict
[
park
]
=
park_num
park_index_to_uuid_dict
[
park_num
]
=
park
park_num
=
park_num
+
1
########################################################################################################################
# truck_id <-> truck_name
truck_uuid_to_name_dict
=
{}
truck_name_to_uuid_dict
=
{}
for
item
in
session_mysql
.
query
(
Equipment
)
.
filter_by
(
device_type
=
1
)
.
all
():
truck_id
=
item
.
id
truck_name
=
item
.
equipment_id
truck_name_to_uuid_dict
[
truck_name
]
=
truck_id
truck_uuid_to_name_dict
[
truck_id
]
=
truck_name
########################################################################################################################
# 矿卡集合
truck_set
=
[]
query
=
np
.
array
(
session_mysql
.
query
(
Equipment
)
.
filter_by
(
device_type
=
1
,
isdeleted
=
0
)
.
all
())
for
item
in
query
:
truck_set
.
append
(
item
.
id
)
truck_set
=
set
(
truck_set
)
# 固定派车矿卡集合
fixed_truck_set
=
[]
query
=
np
.
array
(
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
isauto
=
0
,
isdeleted
=
0
)
.
all
())
for
item
in
query
:
fixed_truck_set
.
append
(
item
.
truck_id
)
fixed_truck_set
=
set
(
fixed_truck_set
)
# 动态派车矿卡集合
dynamic_truck_set
=
truck_set
.
difference
(
fixed_truck_set
)
# print("可用于动态派车的矿卡:")
# print(dynamic_truck_set)
logger
.
info
(
"可用于动态派车的矿卡:"
)
logger
.
info
(
dynamic_truck_set
)
########################################################################################################################
# 用于动态派车的挖机集合
dynamic_excavator_set
=
[]
# 用于动态调度的卸载点集合
dynamic_dump_set
=
[]
for
item
in
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
isdeleted
=
0
,
isauto
=
1
)
.
all
():
dynamic_excavator_set
.
append
(
item
.
exactor_id
)
dynamic_dump_set
.
append
(
item
.
dump_id
)
# 用于动态调度的挖机及卸载设备数量
dynamic_excavator_set
=
set
(
dynamic_excavator_set
)
dynamic_dump_set
=
set
(
dynamic_dump_set
)
# for item in dynamic_truck_set:
# now = datetime.now()
# truck = Truck(truck_id=item, current_task=-1, last_load_time=now, last_unload_time=now, payload=220.0)
#
# truck = truck.check_existing()
# session_mysql.add(truck)
#
# session_mysql.commit()
def
seq_is_empty
(
sequence
):
# 判断sequence是否为空
for
i
in
range
(
len
(
sequence
)):
if
len
(
sequence
[
i
])
!=
0
:
return
False
return
True
def
sequence_meet
(
sequence
):
# 判断构造解是否达标
meet
=
True
for
i
in
range
(
len
(
sequence
)):
meet
=
meet
and
len
(
sequence
[
i
])
>
2
return
meet
class
Dispatcher
:
def
__init__
(
self
):
# 设备数量
self
.
dumps
=
len
(
dynamic_dump_set
)
self
.
shovels
=
len
(
dynamic_excavator_set
)
self
.
trucks
=
len
(
dynamic_truck_set
)
self
.
dis
=
np
.
full
((
self
.
dumps
,
self
.
shovels
),
M
)
# 目标产量
self
.
dump_target_mass
=
np
.
zeros
(
self
.
dumps
)
self
.
shovel_target_mass
=
np
.
zeros
(
self
.
shovels
)
# 真实实际产量
self
.
cur_dump_real_mass
=
np
.
zeros
(
self
.
dumps
)
self
.
cur_shovel_real_mass
=
np
.
zeros
(
self
.
shovels
)
# 预计产量
self
.
pre_dump_real_mass
=
copy
.
deepcopy
(
self
.
cur_dump_real_mass
)
self
.
pre_shovel_real_mass
=
copy
.
deepcopy
(
self
.
cur_shovel_real_mass
)
# 模拟实际产量(防止修改真实产量)
self
.
sim_dump_real_mass
=
np
.
zeros
(
self
.
dumps
)
self
.
sim_shovel_real_mass
=
np
.
zeros
(
self
.
shovels
)
# 真实设备可用时间
self
.
cur_truck_reach_dump
=
np
.
zeros
(
self
.
trucks
)
self
.
cur_truck_reach_shovel
=
np
.
zeros
(
self
.
trucks
)
self
.
cur_shovel_ava_time
=
np
.
zeros
(
self
.
shovels
)
self
.
cur_dump_ava_time
=
np
.
zeros
(
self
.
dumps
)
# 模拟各设备可用时间
self
.
sim_truck_reach_dump
=
np
.
zeros
(
self
.
trucks
)
self
.
sim_truck_reach_shovel
=
np
.
zeros
(
self
.
trucks
)
self
.
sim_shovel_ava_time
=
np
.
zeros
(
self
.
shovels
)
self
.
sim_dump_ava_time
=
np
.
zeros
(
self
.
dumps
)
# 矿卡阶段
self
.
truck_current_task
=
{}
# 维护一个矿卡调度表
self
.
Seq
=
[[]
for
_
in
range
(
self
.
trucks
)]
# 调度开始时间
self
.
start_time
=
datetime
.
now
()
# self.relative_now_time = datetime.now() - self.start_time
# 行走时间
self
.
com_time_area
=
np
.
full
((
unload_area_num
,
load_area_num
),
M
)
self
.
go_time_area
=
np
.
full
((
unload_area_num
,
load_area_num
),
M
)
self
.
com_time_eq
=
np
.
full
((
self
.
dumps
,
self
.
shovels
),
M
)
self
.
go_time_eq
=
np
.
full
((
self
.
dumps
,
self
.
shovels
),
M
)
self
.
park_to_load_area
=
np
.
full
((
park_num
,
load_area_num
),
M
)
self
.
park_to_load_eq
=
np
.
full
((
park_num
,
self
.
shovels
),
M
)
# 卡车完成装载及卸载时间
self
.
cur_truck_ava_time
=
np
.
zeros
(
self
.
trucks
)
self
.
sim_truck_ava_time
=
np
.
zeros
(
self
.
trucks
)
# 处理距离
for
item
in
session_postgre
.
query
(
WalkTime
)
.
all
():
load_area
=
str
(
item
.
load_area_id
)
unload_area
=
str
(
item
.
unload_area_id
)
load_area_index
=
load_area_uuid_to_index_dict
[
load_area
]
unload_area_index
=
unload_area_uuid_to_index_dict
[
unload_area
]
self
.
com_time_area
[
unload_area_index
][
load_area_index
]
=
60
/
1000
*
item
.
to_load_distance
/
empty_speed
self
.
go_time_area
[
unload_area_index
][
load_area_index
]
=
60
/
1000
*
item
.
to_unload_distance
/
heavy_speed
def
update
(
self
):
print
(
"#####################################周期更新#####################################"
)
logger
.
info
(
"周期更新开始"
)
# 初始化挖机可用时间
self
.
cur_shovel_ava_time
=
np
.
full
(
self
.
shovels
,
(
datetime
.
now
()
-
self
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
))
################################################################################################################
# 矿卡集合
################################################################################################################
# 读取矿卡集合
truck_set
=
[]
query
=
np
.
array
(
session_mysql
.
query
(
Equipment
)
.
filter_by
(
device_type
=
1
,
isdeleted
=
0
)
.
all
())
for
item
in
query
:
truck_set
.
append
(
item
.
id
)
truck_set
=
set
(
truck_set
)
# 固定派车矿卡集合
fixed_truck_set
=
[]
query
=
np
.
array
(
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
isauto
=
0
,
isdeleted
=
0
)
.
all
())
for
item
in
query
:
fixed_truck_set
.
append
(
item
.
truck_id
)
fixed_truck_set
=
set
(
fixed_truck_set
)
# 动态派车矿卡集合
self
.
dynamic_truck_set
=
truck_set
.
difference
(
fixed_truck_set
)
# 更新矿卡数量
self
.
trucks
=
len
(
self
.
dynamic_truck_set
)
################################################################################################################
# 更新矿卡参数
################################################################################################################
# 卡车完成装载及卸载时间
self
.
cur_truck_ava_time
=
np
.
zeros
(
self
.
trucks
)
self
.
sim_truck_ava_time
=
np
.
zeros
(
self
.
trucks
)
# 真实设备可用时间
self
.
cur_truck_reach_dump
=
np
.
zeros
(
self
.
trucks
)
self
.
cur_truck_reach_shovel
=
np
.
zeros
(
self
.
trucks
)
# 模拟各设备可用时间
self
.
sim_truck_reach_dump
=
np
.
zeros
(
self
.
trucks
)
self
.
sim_truck_reach_shovel
=
np
.
zeros
(
self
.
trucks
)
################################################################################################################
# 动态派车挖机、卸载设备集合
################################################################################################################
# 用于动态派车的挖机集合
self
.
dynamic_excavator_set
=
[]
# 用于动态调度的卸载点集合
self
.
dynamic_dump_set
=
[]
for
item
in
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
isdeleted
=
0
,
isauto
=
1
)
.
all
():
self
.
dynamic_excavator_set
.
append
(
item
.
exactor_id
)
self
.
dynamic_dump_set
.
append
(
item
.
dump_id
)
# 用于动态调度的挖机及卸载设备数量
self
.
dynamic_excavator_set
=
set
(
self
.
dynamic_excavator_set
)
self
.
dynamic_dump_set
=
set
(
self
.
dynamic_dump_set
)
# 更新挖机和卸载设备数量
self
.
dumps
=
len
(
self
.
dynamic_dump_set
)
self
.
shovels
=
len
(
self
.
dynamic_excavator_set
)
# print("检测到挖机数量:", self.shovels)
# print(self.dynamic_excavator_set)
# print("检测到卸点数量:", self.dumps)
# 初始化挖机可用时间
self
.
cur_shovel_ava_time
=
np
.
full
(
self
.
shovels
,
(
datetime
.
now
()
-
self
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
))
################################################################################################################
# 挖机卸载点映射
################################################################################################################
self
.
excavator_uuid_to_index_dict
=
{}
# 用于将Excavator表中的area_id映射到index
self
.
dump_uuid_to_index_dict
=
{}
# 用于将Dump表中的area_id映射到index
self
.
excavator_index_to_uuid_dict
=
{}
# 用于将index映射到Excavator表中的area_id
self
.
dump_index_to_uuid_dict
=
{}
# 用于将index映射到Dump表中的area_id
self
.
dump_uuid_to_unload_area_uuid_dict
=
{}
self
.
excavator_uuid_to_load_area_uuid_dict
=
{}
self
.
excavator_index_to_load_area_index_dict
=
{}
self
.
dump_index_to_unload_area_index_dict
=
{}
excavator_num
=
0
dump_num
=
0
for
item
in
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
isdeleted
=
0
,
isauto
=
1
)
.
all
():
# excavator_id <-> excavator_index
# dump_id <-> dump_index
# excavator_id <-> load_area_id
# dump_id <-> unload_area_id
# excavator_index <-> load_area_index
# dump_index <-> unload_area_index
excavator_id
=
item
.
exactor_id
load_area_id
=
item
.
load_area_id
unload_area_id
=
item
.
unload_area_id
dump_id
=
item
.
dump_id
if
dump_id
not
in
self
.
dump_uuid_to_unload_area_uuid_dict
:
self
.
dump_uuid_to_index_dict
[
dump_id
]
=
dump_num
self
.
dump_index_to_uuid_dict
[
dump_num
]
=
dump_id
self
.
dump_uuid_to_unload_area_uuid_dict
[
dump_id
]
=
unload_area_id
self
.
dump_index_to_unload_area_index_dict
[
self
.
dump_uuid_to_index_dict
[
dump_id
]]
=
\
unload_area_uuid_to_index_dict
[
unload_area_id
]
dump_num
=
dump_num
+
1
if
excavator_id
not
in
self
.
excavator_uuid_to_index_dict
:
self
.
excavator_uuid_to_index_dict
[
excavator_id
]
=
excavator_num
self
.
excavator_index_to_uuid_dict
[
excavator_num
]
=
excavator_id
self
.
excavator_uuid_to_load_area_uuid_dict
[
excavator_id
]
=
load_area_id
self
.
excavator_index_to_load_area_index_dict
[
self
.
excavator_uuid_to_index_dict
[
excavator_id
]]
=
\
load_area_uuid_to_index_dict
[
load_area_id
]
excavator_num
=
excavator_num
+
1
# print(self.excavator_index_to_load_area_index_dict)
################################################################################################################
# 设备距离
################################################################################################################
for
i
in
range
(
self
.
dumps
):
for
j
in
range
(
self
.
shovels
):
self
.
com_time_eq
[
i
][
j
]
=
self
.
com_time_area
[
self
.
dump_index_to_unload_area_index_dict
[
i
]]
\
[
self
.
excavator_index_to_load_area_index_dict
[
j
]]
self
.
go_time_eq
[
i
][
j
]
=
self
.
go_time_area
[
self
.
dump_index_to_unload_area_index_dict
[
i
]]
\
[
self
.
excavator_index_to_load_area_index_dict
[
j
]]
for
item
in
session_postgre
.
query
(
WalkTimePort
)
.
all
():
load_area
=
str
(
item
.
load_area_id
)
park_area
=
str
(
item
.
park_area_id
)
load_area_index
=
load_area_uuid_to_index_dict
[
load_area
]
park_index
=
park_uuid_to_index_dict
[
park
]
self
.
park_to_load_area
[
park_index
][
load_area_index
]
=
60
/
1000
*
item
.
park_load_distance
/
empty_speed
for
i
in
range
(
park_num
):
for
j
in
range
(
self
.
shovels
):
self
.
park_to_load_eq
[
i
][
j
]
=
self
.
park_to_load_area
[
i
][
self
.
excavator_index_to_load_area_index_dict
[
j
]]
################################################################################################################
# 矿卡映射
################################################################################################################
self
.
truck_uuid_to_index_dict
=
{}
self
.
truck_index_to_uuid_dict
=
{}
# truck_id <-> truck_index
truck_num
=
0
for
truck_id
in
self
.
dynamic_truck_set
:
self
.
truck_uuid_to_index_dict
[
truck_id
]
=
truck_num
self
.
truck_index_to_uuid_dict
[
truck_num
]
=
truck_id
truck_num
=
truck_num
+
1
################################################################################################################
# 卡车当前任务
################################################################################################################
# self.truck_current_stage = np.array(session_mysql.query(Truck.status).all())
self
.
truck_current_task
=
{}
device_name_set
=
redis2
.
keys
()
for
item
in
device_name_set
:
item
=
item
.
decode
(
encoding
=
'utf-8'
)
json_value
=
json
.
loads
(
redis2
.
get
(
item
))
device_type
=
json_value
.
get
(
'type'
)
if
device_type
==
1
:
if
truck_name_to_uuid_dict
[
item
]
in
self
.
dynamic_truck_set
:
currentTask
=
json_value
.
get
(
'currentTask'
)
self
.
truck_current_task
[
truck_name_to_uuid_dict
[
item
]]
=
currentTask
try
:
if
currentTask
not
in
task_set
:
raise
Exception
(
f
'车辆{item}出现未知状态{currentTask}'
)
except
Exception
as
es
:
logger
.
warning
(
es
)
print
(
es
)
# print("矿卡当前任务:")
# print(self.truck_current_task)
logger
.
info
(
"矿卡当前任务:"
)
logger
.
info
(
self
.
truck_current_task
)
################################################################################################################
# 卡车当前状态
################################################################################################################
self
.
truck_current_state
=
{}
device_name_set
=
redis2
.
keys
()
for
item
in
device_name_set
:
item
=
item
.
decode
(
encoding
=
'utf-8'
)
json_value
=
json
.
loads
(
redis2
.
get
(
item
))
device_type
=
json_value
.
get
(
'type'
)
if
device_type
==
1
:
if
truck_name_to_uuid_dict
[
item
]
in
self
.
dynamic_truck_set
:
self
.
truck_current_state
[
truck_name_to_uuid_dict
[
item
]]
=
json_value
.
get
(
'state'
)
# print("矿卡当前状态:")
# print(self.truck_current_state)
################################################################################################################
# 有效载重
################################################################################################################
# self.payload = np.array(session_mysql.query(Truck.payload).all())
self
.
payload
=
np
.
zeros
(
self
.
trucks
)
for
truck_id
in
self
.
dynamic_truck_set
:
trcuk_index
=
self
.
truck_uuid_to_index_dict
[
truck_id
]
truck_spec
=
session_mysql
.
query
(
Equipment
)
.
filter_by
(
id
=
truck_id
)
.
first
()
.
equipment_spec
# truck_spec = query.equipment_spec
self
.
payload
[
trcuk_index
]
=
session_mysql
.
query
(
EquipmentSpec
)
.
filter_by
(
id
=
truck_spec
)
.
first
()
.
capacity
################################################################################################################
# 卡车最后一次装载/卸载时间
################################################################################################################
self
.
last_load_time
=
{}
self
.
last_unload_time
=
{}
self
.
relative_last_load_time
=
{}
self
.
relative_last_unload_time
=
{}
# for x in redis2.keys():
# print(redis2.get(x))
for
item
in
self
.
dynamic_truck_set
:
json_value
=
json
.
loads
(
redis2
.
get
(
truck_uuid_to_name_dict
[
item
]))
device_type
=
json_value
.
get
(
'type'
)
# 判断是否为矿卡
if
device_type
==
1
:
task
=
self
.
truck_current_task
[
item
]
state
=
self
.
truck_current_state
[
item
]
if
task
in
heavy_task_set
:
last_load_time_tmp
=
json_value
.
get
(
'lastLoadTime'
)
if
last_load_time_tmp
is
not
None
:
self
.
last_load_time
[
item
]
=
datetime
.
strptime
(
last_load_time_tmp
,
\
"
%
b
%
d,
%
Y
%
I:
%
M:
%
S
%
p"
)
else
:
self
.
last_load_time
[
item
]
=
datetime
.
now
()
self
.
relative_last_load_time
[
item
]
=
((
self
.
last_load_time
[
item
]
-
self
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
))
# print("相对last_load_time", self.relative_last_load_time[item])
logger
.
info
(
"相对last_load_time"
)
logger
.
info
(
self
.
relative_last_load_time
[
item
])
if
task
in
empty_task_set
:
last_unload_time_tmp
=
json_value
.
get
(
'lastUnloadTime'
)
if
last_unload_time_tmp
is
not
None
:
self
.
last_unload_time
[
item
]
=
datetime
.
strptime
(
last_unload_time_tmp
,
\
"
%
b
%
d,
%
Y
%
I:
%
M:
%
S
%
p"
)
else
:
self
.
last_unload_time
[
item
]
=
datetime
.
now
()
self
.
relative_last_unload_time
[
item
]
=
((
self
.
last_unload_time
[
item
]
-
self
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
))
# print("相对last_unload_time", self.relative_last_unload_time[item])
logger
.
info
(
"相对last_unload_time"
)
logger
.
info
(
self
.
relative_last_unload_time
[
item
])
################################################################################################################
# 计算平均装载时间
################################################################################################################
self
.
loading_time
=
np
.
zeros
(
self
.
shovels
)
for
excavator_id
in
self
.
excavator_uuid_to_index_dict
.
keys
():
ave_load_time
=
0
for
query
in
session_mysql
.
query
(
JobRecord
.
start_time
,
JobRecord
.
end_time
)
.
\
join
(
Equipment
,
JobRecord
.
equipment_id
==
Equipment
.
equipment_id
)
.
\
filter
(
Equipment
.
id
==
excavator_id
,
JobRecord
.
end_time
!=
None
)
.
\
order_by
(
JobRecord
.
start_time
.
desc
())
.
limit
(
10
):
ave_load_time
=
ave_load_time
+
int
(
(
query
.
end_time
-
query
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
))
self
.
loading_time
[
self
.
excavator_uuid_to_index_dict
[
excavator_id
]]
=
ave_load_time
/
10
################################################################################################################
# 计算平均卸载时间
################################################################################################################
self
.
unloading_time
=
np
.
zeros
(
dump_num
)
for
dump_id
in
self
.
dump_uuid_to_index_dict
.
keys
():
ave_unload_time
=
0
for
query
in
session_mysql
.
query
(
JobRecord
.
start_time
,
JobRecord
.
end_time
)
.
\
join
(
Equipment
,
JobRecord
.
equipment_id
==
Equipment
.
equipment_id
)
.
\
filter
(
Equipment
.
id
==
dump_id
,
JobRecord
.
end_time
!=
None
)
.
\
order_by
(
JobRecord
.
start_time
.
desc
())
.
limit
(
10
):
ave_unload_time
=
ave_unload_time
+
int
(
(
query
.
end_time
-
query
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
))
self
.
unloading_time
[
self
.
dump_uuid_to_index_dict
[
dump_id
]]
=
ave_unload_time
/
10
# print("average_unload_time: ", self.unloading_time[self.dump_uuid_to_index_dict[dump_id]])
################################################################################################################
# 读取实时装载卸载量
################################################################################################################
self
.
cur_shovel_real_mass
=
np
.
zeros
(
self
.
shovels
)
self
.
cur_dump_real_mass
=
np
.
zeros
(
self
.
dumps
)
now
=
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d'
)
for
excavator_id
in
self
.
excavator_uuid_to_index_dict
.
keys
():
# print(excavator_id)
for
query
in
session_mysql
.
query
(
LoadInfo
)
.
\
join
(
Equipment
,
LoadInfo
.
dump_id
==
Equipment
.
equipment_id
)
.
\
filter
(
Equipment
.
id
==
excavator_id
,
LoadInfo
.
time
>
now
)
.
\
order_by
(
LoadInfo
.
time
.
desc
())
.
all
():
# print("time:", query.time)
# print("load_weight:", )
self
.
cur_shovel_real_mass
[
self
.
excavator_uuid_to_index_dict
[
excavator_id
]]
=
\
self
.
cur_shovel_real_mass
[
self
.
excavator_uuid_to_index_dict
[
excavator_id
]]
+
query
.
load_weight
for
dump_id
in
self
.
dump_uuid_to_index_dict
.
keys
():
# print(excavator_id)
for
query
in
session_mysql
.
query
(
LoadInfo
)
.
\
join
(
Equipment
,
LoadInfo
.
dump_id
==
Equipment
.
equipment_id
)
.
\
filter
(
Equipment
.
id
==
dump_id
,
LoadInfo
.
time
>
now
)
.
\
order_by
(
LoadInfo
.
time
.
desc
())
.
all
():
# print("time:", query.time)
# print("load_weight:", )
self
.
cur_dump_real_mass
[
self
.
dump_uuid_to_index_dict
[
dump_id
]]
=
\
self
.
cur_dump_real_mass
[
self
.
dump_uuid_to_index_dict
[
dump_id
]]
+
query
.
load_weight
################################################################################################################
# 读取卡车当前行程
################################################################################################################
self
.
truck_current_trip
=
np
.
full
((
self
.
trucks
,
2
),
-
1
)
for
i
in
range
(
self
.
trucks
):
session_mysql
.
commit
()
truck_id
=
self
.
truck_index_to_uuid_dict
[
i
]
task
=
self
.
truck_current_task
[
self
.
truck_index_to_uuid_dict
[
i
]]
# print("truck_task:", truck_id, task)
item
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
truck_id
,
isdeleted
=
0
)
.
first
()
# if task in heavy_task_set:
# print(item.id, item.truck_id, item.exactor_id, item.dump_id, item.isdeleted)
try
:
if
task
in
empty_task_set
+
heavy_task_set
:
if
item
is
None
:
raise
Exception
(
"矿卡配对关系不存在"
)
except
Exception
as
es
:
print
(
es
)
logger
.
warning
(
es
)
return
state
=
self
.
truck_current_state
[
self
.
truck_index_to_uuid_dict
[
i
]]
# 若矿卡状态为空运
if
task
in
empty_task_set
:
# print("读取空载行程")
# print(item.exactor_id, item.dump_id)
# 若矿卡从低停车场空运出发????????
# if task == 0:
# last_unload_time = self.relative_last_unload_time[self.truck_index_to_uuid_dict[i]]
# # 开始区域id
# # 开始区域序号
# start_area_index = -1
# # 结束区域id
# end_area_id = self.excavator_uuid_to_load_area_uuid_dict[item.exactor_id]
# # 结束区域序号
# end_area_index = load_area_uuid_to_index_dict[end_area_id]
# self.truck_current_trip[i] = [-1, self.excavator_uuid_to_index_dict[item.exactor_id]]
# self.cur_truck_reach_shovel[i] = last_unload_time + self.com_time_area[start_area_index][
# end_area_index]
# else:
last_unload_time
=
self
.
relative_last_unload_time
[
self
.
truck_index_to_uuid_dict
[
i
]]
# 开始区域id
start_area_id
=
self
.
dump_uuid_to_unload_area_uuid_dict
[
item
.
dump_id
]
# 开始区域序号
start_area_index
=
unload_area_uuid_to_index_dict
[
start_area_id
]
end_area_id
=
self
.
excavator_uuid_to_load_area_uuid_dict
[
item
.
exactor_id
]
end_area_index
=
load_area_uuid_to_index_dict
[
end_area_id
]
self
.
truck_current_trip
[
i
]
=
[
self
.
dump_uuid_to_index_dict
[
item
.
dump_id
],
self
.
excavator_uuid_to_index_dict
[
item
.
exactor_id
]]
# if truck_uuid_to_name_dict[self.truck_index_to_uuid_dict[i]] in tmp_set:
# self.cur_truck_reach_shovel[i] = last_unload_time + 10 * self.com_time_area[start_area_index][
# end_area_index]
# else:
self
.
cur_truck_reach_shovel
[
i
]
=
last_unload_time
+
self
.
com_time_area
[
start_area_index
][
end_area_index
]
# 若矿卡状态为重载
elif
task
in
heavy_task_set
:
# print("读取重载行程")
# print(item.exactor_id, item.dump_id)
last_load_time
=
self
.
relative_last_load_time
[
self
.
truck_index_to_uuid_dict
[
i
]]
# 开始区域id
start_area_id
=
self
.
excavator_uuid_to_load_area_uuid_dict
[
item
.
exactor_id
]
# 开始区域序号
start_area_index
=
load_area_uuid_to_index_dict
[
start_area_id
]
# 结束区域id
end_area_id
=
self
.
dump_uuid_to_unload_area_uuid_dict
[
item
.
dump_id
]
# 结束区域序号
end_area_index
=
unload_area_uuid_to_index_dict
[
end_area_id
]
self
.
truck_current_trip
[
i
]
=
[
self
.
excavator_uuid_to_index_dict
[
item
.
exactor_id
],
self
.
dump_uuid_to_index_dict
[
item
.
dump_id
]]
self
.
cur_truck_reach_dump
[
i
]
=
last_load_time
+
self
.
go_time_area
[
end_area_index
][
start_area_index
]
# 其他状态,矿卡状态为-2,equipment_pair表不存在该矿卡
else
:
pass
self
.
truck_current_trip
.
flatten
()
# print("当前矿卡行程:")
# print(self.truck_current_trip)
################################################################################################################
# 读取卸点产量
################################################################################################################
# 卸载目标产量
# self.dump_target_mass = (np.array(session_mysql.query(Dump.target_mass).all())).flatten()
self
.
dump_target_mass
=
np
.
full
(
self
.
dumps
,
dump_target_mass
)
################################################################################################################
# 读取挖机产量
################################################################################################################
# 电铲目标产量
# self.shovel_target_mass = (np.array(session_mysql.query(Excavator.target_mass).all())).flatten()
self
.
shovel_target_mass
=
np
.
full
(
self
.
shovels
,
shovel_target_mass
)
################################################################################################################
# 计算挖机与卸载点预估产量
################################################################################################################
self
.
pre_dump_real_mass
=
copy
.
deepcopy
(
self
.
cur_dump_real_mass
)
self
.
pre_shovel_real_mass
=
copy
.
deepcopy
(
self
.
cur_shovel_real_mass
)
for
i
in
range
(
self
.
trucks
):
# task = self.truck_current_stage[i][0]
task
=
self
.
truck_current_task
[
self
.
truck_index_to_uuid_dict
[
i
]]
end_area_index
=
self
.
truck_current_trip
[
i
][
1
]
# 若矿卡正常行驶,需要将该部分载重计入实时产量
if
task
in
empty_task_set
or
(
task
==
-
1
and
state
==
4
):
self
.
pre_shovel_real_mass
[
end_area_index
]
=
self
.
pre_shovel_real_mass
[
end_area_index
]
+
self
.
payload
[
i
]
elif
task
in
heavy_task_set
or
(
task
==
-
1
and
state
==
5
):
self
.
pre_dump_real_mass
[
end_area_index
]
=
self
.
pre_dump_real_mass
[
end_area_index
]
+
self
.
payload
[
i
]
else
:
pass
################################################################################################################
# 矿卡抵达时间
################################################################################################################
now
=
(
datetime
.
now
()
-
self
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
)
shovel_ava_ls
=
[[]
for
_
in
range
(
self
.
shovels
)]
dump_ava_ls
=
[[]
for
_
in
range
(
self
.
dumps
)]
for
i
in
range
(
self
.
trucks
):
task
=
self
.
truck_current_task
[
self
.
truck_index_to_uuid_dict
[
i
]]
end_area_index
=
self
.
truck_current_trip
[
i
][
1
]
if
task
in
empty_task_set
:
reach_time
=
self
.
cur_truck_reach_shovel
[
i
]
shovel_ava_ls
[
end_area_index
]
.
append
([
reach_time
,
i
,
end_area_index
])
elif
task
in
heavy_task_set
:
reach_time
=
self
.
cur_truck_reach_dump
[
i
]
dump_ava_ls
[
end_area_index
]
.
append
([
reach_time
,
i
,
end_area_index
])
elif
task
==
-
2
:
self
.
cur_truck_ava_time
[
i
]
=
(
datetime
.
now
()
-
self
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
)
################################################################################################################
# 挖机可用时间
################################################################################################################
for
reach_ls
in
shovel_ava_ls
:
if
len
(
reach_ls
)
!=
0
:
reach_ls
=
np
.
array
(
reach_ls
)
tmp
=
reach_ls
[
np
.
lexsort
(
reach_ls
[:,
::
-
1
]
.
T
)]
for
i
in
range
(
len
(
tmp
)):
shovel_index
=
int
(
tmp
[
i
][
2
])
self
.
cur_shovel_ava_time
[
shovel_index
]
=
max
(
tmp
[
i
][
0
],
self
.
cur_shovel_ava_time
[
shovel_index
])
+
\
self
.
loading_time
[
shovel_index
]
self
.
cur_truck_ava_time
[
int
(
tmp
[
i
][
1
])]
=
self
.
cur_shovel_ava_time
[
shovel_index
]
# 若挖机可用时间严重偏离,进行修正
if
abs
(
self
.
cur_shovel_ava_time
[
shovel_index
]
-
now
)
>
60
:
self
.
cur_truck_ava_time
[
int
(
tmp
[
i
][
1
])]
=
now
if
abs
(
self
.
cur_shovel_ava_time
[
shovel_index
]
-
now
)
>
60
:
self
.
cur_shovel_ava_time
[
shovel_index
]
=
now
################################################################################################################
# 卸点可用时间
################################################################################################################
# dump_index = 0
for
reach_ls
in
dump_ava_ls
:
if
len
(
reach_ls
)
!=
0
:
reach_ls
=
np
.
array
(
reach_ls
)
tmp
=
reach_ls
[
np
.
lexsort
(
reach_ls
[:,
::
-
1
]
.
T
)]
for
i
in
range
(
len
(
tmp
)):
dump_index
=
int
(
tmp
[
i
][
2
])
self
.
cur_dump_ava_time
[
dump_index
]
=
max
(
tmp
[
i
][
0
],
self
.
cur_dump_ava_time
[
dump_index
])
+
\
self
.
unloading_time
[
dump_index
]
self
.
cur_truck_ava_time
[
int
(
tmp
[
i
][
1
])]
=
self
.
cur_dump_ava_time
[
dump_index
]
# 若卸点可用时间严重偏离,进行修正
if
abs
(
self
.
cur_dump_ava_time
[
dump_index
]
-
now
)
>
60
:
self
.
cur_dump_ava_time
[
dump_index
]
=
now
if
abs
(
self
.
cur_truck_ava_time
[
int
(
tmp
[
i
][
1
])]
-
now
)
>
60
:
self
.
cur_truck_ava_time
[
int
(
tmp
[
i
][
1
])]
=
now
# dump_index = dump_index + 1
logger
.
info
(
'f{周期更新结束}'
)
def
reset
(
self
):
# 卡车抵达时间重置
self
.
sim_truck_reach_dump
=
copy
.
deepcopy
(
self
.
cur_truck_reach_dump
)
self
.
sim_truck_reach_shovel
=
copy
.
deepcopy
(
self
.
cur_truck_reach_shovel
)
# 设备可用时间重置
self
.
sim_truck_ava_time
=
copy
.
deepcopy
(
self
.
cur_truck_ava_time
)
self
.
sim_shovel_ava_time
=
copy
.
deepcopy
(
self
.
cur_shovel_ava_time
)
self
.
sim_dump_ava_time
=
copy
.
deepcopy
(
self
.
cur_dump_ava_time
)
# 电铲\卸载点产量重置
self
.
sim_dump_real_mass
=
copy
.
deepcopy
(
self
.
pre_dump_real_mass
)
self
.
sim_shovel_real_mass
=
copy
.
deepcopy
(
self
.
pre_shovel_real_mass
)
def
truck_schedule_send_post
(
self
,
truck_id
):
truck_index
=
self
.
truck_uuid_to_index_dict
[
truck_id
]
trip
=
self
.
truck_current_trip
[
truck_index
]
task
=
self
.
truck_current_task
[
self
.
truck_index_to_uuid_dict
[
truck_index
]]
# state = self.truck_current_state[self.truck_index_to_uuid_dict[truck_index]]
now
=
(
datetime
.
now
()
-
self
.
start_time
)
/
timedelta
(
hours
=
0
,
minutes
=
1
,
seconds
=
0
)
logger
.
info
(
" "
)
logger
.
info
(
f
'调度矿卡{truck_id} {truck_uuid_to_name_dict[truck_id]}'
)
#
# print(f'矿卡可用时间:{truck_uuid_to_name_dict[truck_id]}')
# print(self.sim_truck_ava_time[self.truck_uuid_to_index_dict[truck_id]])
#
# print(f'挖机可用时间:')
# print(self.sim_shovel_ava_time)
#
# print(f'卸点可用时间:')
# print(self.sim_dump_ava_time)
target
=
0
if
task
==
-
2
:
# print("矿卡状态:矿卡启动或故障恢复")
# print("矿卡行程:无")
# print("涉及电铲:")
# print(list(self.excavator_uuid_to_index_dict.keys()))
# print("电铲饱和度:")
# print(10 * (1 - self.sim_shovel_real_mass / self.shovel_target_mass))
# print("行程时间:")
# print((np.maximum(self.sim_shovel_ava_time,
# now + self.park_to_load_eq[0, :]) + self.loading_time
# - now))
# print("行驶时间:")
# print(self.park_to_load_eq[0, :] + self.loading_time)
logger
.
info
(
"矿卡状态:矿卡启动或故障恢复"
)
logger
.
info
(
"矿卡行程:无"
)
logger
.
info
(
f
'涉及电铲:{list(self.excavator_uuid_to_index_dict.keys())}'
)
logger
.
info
(
f
'电铲饱和度:{(1 - self.sim_shovel_real_mass / self.shovel_target_mass)}'
)
logger
.
info
(
f
'行程时间:{(np.maximum(self.sim_shovel_ava_time, now + self.park_to_load_eq[0, :]) + self.loading_time - now)}'
)
logger
.
info
(
f
'行驶时间:{self.park_to_load_eq[0, :] + self.loading_time}'
)
target
=
np
.
argmax
(
10
*
(
1
-
self
.
sim_shovel_real_mass
/
self
.
shovel_target_mass
)
/
(
np
.
maximum
(
self
.
sim_shovel_ava_time
,
now
+
self
.
park_to_load_eq
[
0
,
:])
+
self
.
loading_time
-
now
))
# print("目的地: ", self.excavator_index_to_uuid_dict[target])
logger
.
info
(
f
'目的地:{self.excavator_index_to_uuid_dict[target]}'
)
if
task
in
empty_task_set
:
# print("矿卡状态:矿卡空载")
# print("矿卡行程:", self.dump_index_to_uuid_dict[trip[0]], self.excavator_index_to_uuid_dict[trip[1]])
# print("涉及卸点:")
# print(list(self.dump_uuid_to_index_dict.keys()))
# print("卸点饱和度:")
# print(10 * (1 - self.sim_dump_real_mass / self.dump_target_mass))
# print("行程时间:")
# print((np.maximum(self.sim_dump_ava_time,
# # self.sim_truck_reach_shovel[truck_index] + self.loading_time[trip[1]]
# self.sim_truck_ava_time[truck_index]
# + self.go_time_eq[:, trip[1]]) + self.unloading_time
# - self.sim_truck_ava_time[truck_index]))
# # print("卸载时间:")
# # print(self.unloading_time)
# print("行驶时间:")
# print(self.go_time_eq[:, trip[1]] + self.unloading_time)
logger
.
info
(
"矿卡状态:矿卡空载"
)
logger
.
info
(
f
'矿卡行程:{self.dump_index_to_uuid_dict[trip[0]]}-{self.excavator_index_to_uuid_dict[trip[1]]}'
)
logger
.
info
(
f
'涉及卸点:{list(self.dump_uuid_to_index_dict.keys())}'
)
logger
.
info
(
f
'卸点饱和度:{(1 - self.sim_dump_real_mass / self.dump_target_mass)}'
)
logger
.
info
(
f
'行程时间:{(np.maximum(self.sim_dump_ava_time,self.sim_truck_ava_time[truck_index] + self.go_time_eq[:, trip[1]]) + self.unloading_time - self.sim_truck_ava_time[truck_index])}'
)
logger
.
info
(
f
'行驶时间:{self.go_time_eq[:, trip[1]] + self.unloading_time}'
)
# 卡车空载,计算下一次卸载点
# start_area_index = self.excavator_index_to_load_area_index_dict[trip[1]]
target
=
np
.
argmax
(
10
*
(
1
-
self
.
sim_dump_real_mass
/
self
.
dump_target_mass
)
/
(
np
.
maximum
(
self
.
sim_dump_ava_time
,
# self.sim_truck_reach_shovel[truck_index] + self.loading_time[trip[1]]
self
.
sim_truck_ava_time
[
truck_index
]
+
self
.
go_time_eq
[:,
trip
[
1
]])
+
self
.
unloading_time
-
self
.
sim_truck_ava_time
[
truck_index
]))
# print("目的地: ", self.dump_index_to_uuid_dict[target])
logger
.
info
(
f
'目的地:{self.dump_index_to_uuid_dict[target]}'
)
elif
task
in
heavy_task_set
:
# print("矿卡状态:矿卡重载")
# print("矿卡行程:", self.excavator_index_to_uuid_dict[trip[0]], self.dump_index_to_uuid_dict[trip[1]])
# print("涉及电铲:")
# print(list(self.excavator_uuid_to_index_dict.keys()))
# print("电铲饱和度:")
# print(10 * (1 - self.sim_shovel_real_mass / self.shovel_target_mass))
# print("装载时间:")
# print(self.loading_time)
# print("行程时间:")
# print((np.maximum(self.sim_shovel_ava_time,
# self.sim_truck_ava_time[truck_index]
# + self.com_time_eq[trip[1], :]) + self.loading_time
# - self.sim_truck_ava_time[truck_index]))
# print("行驶时间:")
# print(self.com_time_eq[trip[1], :])
logger
.
info
(
"矿卡状态:矿卡重载"
)
logger
.
info
(
f
'矿卡行程:{self.excavator_index_to_uuid_dict[trip[0]]}-{self.dump_index_to_uuid_dict[trip[1]]}'
)
logger
.
info
(
f
'涉及卸点:{list(self.excavator_uuid_to_index_dict.keys())}'
)
logger
.
info
(
f
'卸点饱和度:{(1 - self.sim_shovel_real_mass / self.shovel_target_mass)}'
)
logger
.
info
(
f
'行程时间:{(np.maximum(self.sim_shovel_ava_time,self.sim_truck_ava_time[truck_index] + self.com_time_eq[trip[1], :]) + self.loading_time - self.sim_truck_ava_time[truck_index])}'
)
logger
.
info
(
f
'行驶时间:{self.com_time_eq[trip[1], :] + self.loading_time}'
)
# 卡车重载,计算下一次装载点
# start_area_index = self.dump_index_to_unload_area_index_dict[trip[1]]
target
=
np
.
argmax
(
10
*
(
1
-
self
.
sim_shovel_real_mass
/
self
.
shovel_target_mass
)
/
(
np
.
maximum
(
self
.
sim_shovel_ava_time
,
self
.
sim_truck_ava_time
[
truck_index
]
+
self
.
com_time_eq
[
trip
[
1
],
:])
+
self
.
loading_time
-
self
.
sim_truck_ava_time
[
truck_index
]))
# print("目的地: ", self.excavator_index_to_uuid_dict[target])
logger
.
info
(
f
'目的地:{self.excavator_index_to_uuid_dict[target]}'
)
return
target
def
solution_construct
(
self
):
# Seq初始化
Seq
=
[[
self
.
truck_current_trip
[
i
][
1
],
-
1
]
for
i
in
range
(
self
.
trucks
)]
# 根据矿卡最早可用时间顺序进行规划
temp
=
copy
.
deepcopy
(
self
.
cur_truck_ava_time
)
for
i
in
range
(
self
.
trucks
):
task
=
self
.
truck_current_task
[
self
.
truck_index_to_uuid_dict
[
i
]]
if
task
==
-
2
:
temp
[
i
]
=
temp
[
i
]
+
M
index
=
np
.
argsort
(
temp
.
reshape
(
1
,
-
1
))
index
=
index
.
flatten
()
for
truck
in
index
:
if
len
(
Seq
[
truck
])
>
0
:
task
=
self
.
truck_current_task
[
self
.
truck_index_to_uuid_dict
[
truck
]]
state
=
self
.
truck_current_state
[
self
.
truck_index_to_uuid_dict
[
truck
]]
end_eq_index
=
self
.
truck_current_trip
[
truck
][
1
]
target_eq_index
=
self
.
truck_schedule_send_post
(
self
.
truck_index_to_uuid_dict
[
truck
])
Seq
[
truck
][
1
]
=
target_eq_index
if
task
in
empty_task_set
:
target_area_index
=
self
.
dump_index_to_unload_area_index_dict
[
target_eq_index
]
end_area_index
=
self
.
excavator_index_to_load_area_index_dict
[
end_eq_index
]
# 更新变量,预计产量更新
self
.
sim_dump_real_mass
[
target_eq_index
]
=
self
.
sim_dump_real_mass
[
target_eq_index
]
+
self
.
payload
[
truck
]
# 预计卸点可用时间更新
self
.
sim_dump_ava_time
[
target_eq_index
]
=
(
max
(
self
.
sim_dump_ava_time
[
target_eq_index
],
self
.
sim_truck_ava_time
[
truck
]
+
self
.
go_time_area
[
target_area_index
][
end_area_index
],
)
+
self
.
unloading_time
[
target_eq_index
]
)
elif
task
in
heavy_task_set
or
(
task
==
-
1
and
state
==
5
):
target_area_index
=
self
.
excavator_index_to_load_area_index_dict
[
target_eq_index
]
end_area_index
=
self
.
dump_index_to_unload_area_index_dict
[
end_eq_index
]
# 更新变量,预计产量更新
self
.
sim_shovel_real_mass
[
target_eq_index
]
=
self
.
sim_shovel_real_mass
[
target_eq_index
]
+
\
self
.
payload
[
truck
]
# 预计装载点可用时间更新
self
.
sim_shovel_ava_time
[
target_eq_index
]
=
(
max
(
self
.
sim_shovel_ava_time
[
target_eq_index
],
self
.
sim_truck_ava_time
[
truck
]
+
self
.
go_time_area
[
end_area_index
][
target_area_index
],
)
+
self
.
loading_time
[
target_eq_index
]
)
# elif task == -2 or state == 7:
# target_area_index = self.excavator_index_to_load_area_index_dict[target_eq_index]
# # 更新变量,预计产量更新
# self.sim_shovel_real_mass[target_eq_index] = self.sim_shovel_real_mass[target_eq_index] + \
# self.payload[
# truck]
# # 预计装载点可用时间更新
# self.sim_shovel_ava_time[target_eq_index] = (
# max(
# self.sim_shovel_ava_time[target_eq_index],
# self.sim_truck_ava_time[truck]
# + self.park_to_load_area[0][target_area_index],
# )
# + self.loading_time[target_eq_index]
# )
else
:
pass
for
i
in
range
(
len
(
Seq
)):
record
=
{
"truckId"
:
self
.
truck_index_to_uuid_dict
[
i
]}
task
=
self
.
truck_current_task
[
self
.
truck_index_to_uuid_dict
[
i
]]
state
=
self
.
truck_current_state
[
self
.
truck_index_to_uuid_dict
[
i
]]
if
task
in
empty_task_set
:
item
=
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
dump_id
=
self
.
dump_index_to_uuid_dict
[
Seq
[
i
][
1
]],
isauto
=
1
,
isdeleted
=
0
)
.
first
()
record
[
"exactorId"
]
=
item
.
exactor_id
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"loadAreaId"
]
=
item
.
load_area_id
record
[
"unloadAreaId"
]
=
item
.
unload_area_id
record
[
"dispatchId"
]
=
item
.
id
record
[
"isdeleted"
]
=
False
record
[
"creator"
]
=
item
.
creator
record
[
"createtime"
]
=
item
.
createtime
.
strftime
(
'
%
b
%
d,
%
Y
%#
I:
%#
M:
%#
S
%
p'
)
elif
task
in
heavy_task_set
:
item
=
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
exactor_id
=
self
.
excavator_index_to_uuid_dict
[
Seq
[
i
][
1
]],
isauto
=
1
,
isdeleted
=
0
)
.
first
()
record
[
"exactorId"
]
=
self
.
excavator_index_to_uuid_dict
[
Seq
[
i
][
1
]]
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"loadAreaId"
]
=
item
.
load_area_id
record
[
"unloadAreaId"
]
=
item
.
unload_area_id
record
[
"dispatchId"
]
=
item
.
id
record
[
"isdeleted"
]
=
False
record
[
"creator"
]
=
item
.
creator
record
[
"createtime"
]
=
item
.
createtime
.
strftime
(
'
%
b
%
d,
%
Y
%#
I:
%#
M:
%#
S
%
p'
)
elif
task
==
-
2
:
item
=
session_mysql
.
query
(
Dispatch
)
.
filter_by
(
exactor_id
=
self
.
excavator_index_to_uuid_dict
[
Seq
[
i
][
1
]],
isauto
=
1
,
isdeleted
=
0
)
.
first
()
record
[
"exactorId"
]
=
item
.
exactor_id
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"loadAreaId"
]
=
item
.
load_area_id
record
[
"unloadAreaId"
]
=
item
.
unload_area_id
record
[
"dispatchId"
]
=
item
.
id
record
[
"isdeleted"
]
=
False
record
[
"creator"
]
=
item
.
creator
record
[
"createtime"
]
=
item
.
createtime
.
strftime
(
'
%
b
%
d,
%
Y
%#
I:
%#
M:
%#
S
%
p'
)
else
:
pass
# json_value = json.loads(redis5.get(self.truck_index_to_uuid_dict[i]))
#
# if json_value is not None:
#
# record["exactorId"] = json_value.get('exactorId')
# record["dumpId"] = json_value.get('dumpId')
# record["loadAreaId"] = json_value.get('loadAreaId')
# record["unloadAreaId"] = json_value.get('unloadAreaId')
# record["dispatchId"] = json_value.get('dispatchId')
# record["isdeleted"] = json_value.get('isdeleted')
# record["creator"] = json_value.get('creator')
# record["createtime"] = json_value.get('createtime')
# else:
# item = session_mysql.query(Dispatch).filter_by(
# exactor_id=self.excavator_index_to_uuid_dict[Seq[i][1]], isauto=1, isdeleted=0).first()
# record["exactorId"] = item.exactor_id
# record["dumpId"] = item.dump_id
# record["loadAreaId"] = item.load_area_id
# record["unloadAreaId"] = item.unload_area_id
# record["dispatchId"] = item.id
# record["isdeleted"] = False
# record["creator"] = item.creator
# record["createtime"] = item.createtime.strftime('%b %d, %Y %#I:%#M:%#S %p')
redis5
.
set
(
self
.
truck_index_to_uuid_dict
[
i
],
str
(
json
.
dumps
(
record
)))
for
i
in
range
(
self
.
trucks
):
print
(
"dispatch_setting:"
)
print
(
redis5
.
get
(
self
.
truck_index_to_uuid_dict
[
i
]))
return
Seq
def
process
(
obj
):
session_mysql
.
commit
()
session_mysql
.
flush
()
obj
.
update
()
obj
.
reset
()
obj
.
solution_construct
()
scheduler
=
sched
.
scheduler
(
time
.
time
,
time
.
sleep
)
def
perform
(
inc
,
obj
):
scheduler
.
enter
(
inc
,
0
,
perform
,
(
inc
,
obj
))
process
(
obj
)
def
main
(
inc
,
obj
):
scheduler
.
enter
(
0
,
0
,
perform
,
(
inc
,
obj
))
scheduler
.
run
()
if
__name__
==
"__main__"
:
logger
.
info
(
" "
)
logger
.
info
(
"调度系统启动"
)
obj
=
Dispatcher
()
main
(
60
,
obj
)
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