Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
integrated-scheduling-v3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张晓彤
integrated-scheduling-v3
Commits
0619e46c
Commit
0619e46c
authored
Sep 09, 2022
by
张晓彤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
二次调度修复及加入请求机制
parent
c5099188
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
423 additions
and
314 deletions
+423
-314
CHANGELOG.txt
CHANGELOG.txt
+11
-0
dispatcher.py
core/dispatcher.py
+214
-141
group.py
core/group.py
+97
-77
ruler.py
core/ruler.py
+0
-8
util.py
core/util.py
+37
-74
dispatchInfo.py
data/dispatchInfo.py
+4
-4
excavator.py
equipment/excavator.py
+1
-1
truck.py
equipment/truck.py
+42
-0
topo_graph.py
graph/topo_graph.py
+14
-6
topo_update_server.py
topo_update_server.py
+3
-3
调度系统部署说明4.1.docx
调度系统部署说明4.1.docx
+0
-0
No files found.
CHANGELOG.txt
View file @
0619e46c
...
...
@@ -50,4 +50,14 @@ Changelog for package Dispatch
[fix ]:
[TODO ]:
[info ]: author: zxt ; time: 2022-04-07 17:33:00 ; email: ; tel: ;
--------------------
--------------------
[version]: 3.4.0
[message]: 新增拓扑路网功能,新增部分依赖库,启动方式发生改变,部署前注意查阅部署文档;
[feather]:
[fix ]:
[TODO ]:
[info ]: author: zxt ; time: 2022-09-09 14:00:00 ; email: ; tel: ;
--------------------
\ No newline at end of file
core/dispatcher.py
View file @
0619e46c
...
...
@@ -18,6 +18,7 @@ import json
import
uuid
from
tables
import
session_mysql
,
session_postgre
from
graph.graph_load
import
graph_construct
from
core.util
import
POST
class
Dispatcher
:
...
...
@@ -31,9 +32,10 @@ class Dispatcher:
self
.
excavator
=
excavator
self
.
pre_sch
=
pre_sch
self
.
request_mode
=
request_mode
self
.
submission
=
DispatchSubmission
(
dump
,
excavator
,
truck
)
self
.
logger
=
get_logger
(
"zxt.dispatcher"
)
self
.
topo
=
graph_construct
()
self
.
submission
=
DispatchSubmission
(
dump
,
excavator
,
truck
,
self
.
topo
)
self
.
logger
=
get_logger
(
"zxt.dispatcher"
)
def
period_update
(
self
):
"""
...
...
@@ -78,13 +80,13 @@ class Dispatcher:
aa
=
self
.
group_list
for
group
in
self
.
group_list
.
values
():
#
try:
try
:
truck_dispatch_plan_dict
=
group
.
group_dispatch
(
ExpectedTime
)
truck_dispatch_plan_dict
=
group
.
group_dispatch
(
ExpectedTime
)
#
except Exception as es:
#
self.logger.error(es)
#
self.logger.error(f'分组{group.group_id} 调度异常')
except
Exception
as
es
:
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
f
'分组{group.group_id} 调度异常'
)
self
.
logger
.
info
(
f
'调度分组: {group.group_id} {DispatchInfo.group_name[group.group_id]}'
)
self
.
logger
.
info
(
"组内挖机"
)
...
...
@@ -102,11 +104,12 @@ class DispatchSubmission:
Attribute:
"""
def
__init__
(
self
,
dump
,
excavator
,
truck
):
def
__init__
(
self
,
dump
,
excavator
,
truck
,
topo
):
self
.
logger
=
get_logger
(
"zxt.submission"
)
self
.
dump
=
dump
self
.
excavator
=
excavator
self
.
truck
=
truck
self
.
topo
=
topo
def
truck_dispatch_to_redis
(
self
,
truck_id
,
dispatch_seq
):
"""
...
...
@@ -136,159 +139,229 @@ class DispatchSubmission:
group_mode
=
3
if
group_mode
==
3
:
self
.
logger
.
info
(
"固定调度"
)
self
.
fixed_dispatch_mode
(
group_id
,
record
,
truck_id
)
else
:
self
.
logger
.
info
(
"动态调度"
)
self
.
dynamic_dispatch_mode
(
dispatch_seq
,
group_id
,
record
,
state
,
task
,
truck_id
)
except
Exception
as
es
:
self
.
logger
.
error
(
"调度结果写入异常"
)
self
.
logger
.
error
(
f
"调度结果:{dispatch_seq}"
)
self
.
logger
.
error
(
es
)
def
dynamic_dispatch_mode
(
self
,
dispatch_seq
,
group_id
,
record
,
state
,
task
,
truck_id
):
"""
write dispatch plan in dynamic dispatch mode.
:param dispatch_seq:
:param group_id:
:param record:
:param state:
:param task:
:param truck_id:
:return:
"""
if
(
task
in
[
1
,
2
])
or
(
task
==
3
and
state
==
2
):
# 卡车空载或在装载区出场前, 可变更卸载目的地
self
.
logger
.
info
(
f
'调度1 {truck_id}'
)
# 查询车辆相关派车计划
try
:
dump_id
=
DispatchInfo
.
unload_area_dump_dict
[
dispatch_seq
[
1
]]
item
=
(
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
dump_id
=
dump_id
,
group_id
=
group_id
,
isdeleted
=
0
,
)
.
first
())
if
item
is
None
:
raise
Exception
(
"调度计划配置异常"
)
if
dispatch_seq
[
0
]
is
None
:
raise
Exception
(
"调度计划表与实时监控不匹配"
)
except
Exception
as
es
:
item
=
(
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
group_id
=
group_id
,
isdeleted
=
0
,
)
.
first
())
self
.
logger
.
error
(
es
)
# 其余调度信息写入
try
:
# record["dispatchId"] = item.id
record
[
"dispatchId"
]
=
str
(
uuid
.
uuid1
())
record
[
"exactorId"
]
=
item
.
exactor_id
record
[
"loadAreaId"
]
=
item
.
load_area_id
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"unloadAreaId"
]
=
item
.
unload_area_id
record
[
"groupId"
]
=
group_id
record
[
"isdeleted"
]
=
False
# record["isTemp"] = False
record
[
"haulFlag"
]
=
-
1
record
[
"groupName"
]
=
DispatchInfo
.
group_name
[
group_id
]
if
task
==
3
and
state
==
2
and
self
.
truck
.
get_truck_locate_dict
()[
truck_id
]
in
self
.
topo
.
cross_bf_lanes
:
# try:
if
truck_id
in
self
.
truck
.
truck_is_temp
and
not
self
.
truck
.
truck_is_temp
[
truck_id
]:
self
.
logger
.
info
(
"二次调度前往卸载区"
)
record
[
"isTemp"
]
=
True
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
POST
(
truck_id
)
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
else
:
self
.
logger
.
info
(
"车辆已完成二次调度-无需更改派车计划"
)
# except Exception as es:
# self.logger.error(es)
# self.logger.error("二次调度失败")
# record["isTemp"] = False
# redis5.set(truck_id, str(json.dumps(record)))
else
:
self
.
logger
.
info
(
"调度前往卸载区"
)
record
[
"isTemp"
]
=
False
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
# redis5.set(truck_id, str(json.dumps(record)))
except
Exception
as
es
:
self
.
logger
.
error
(
"调度结果写入异常-矿卡空载"
)
self
.
logger
.
error
(
es
)
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
# redis5.set(truck_id, str(json.dumps(record)))
# finally:
# redis5.set(truck_id, str(json.dumps(record)))
elif
(
task
in
[
4
,
5
])
or
(
task
==
0
and
state
==
2
):
# 卡车重载或在卸载区出场前, 可变更装载目的地
self
.
logger
.
info
(
f
'调度2 {truck_id}'
)
# 查询车辆相关派车计划
try
:
item
=
(
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
exactor_id
=
dispatch_seq
[
0
],
group_id
=
group_id
,
isdeleted
=
0
,
)
.
first
())
if
item
is
None
:
raise
Exception
(
"调度计划配置异常"
)
if
dispatch_seq
[
0
]
is
None
:
raise
Exception
(
"调度计划表与实时监控不匹配"
)
except
Exception
as
es
:
item
=
(
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
group_id
=
group_id
,
isdeleted
=
0
,
)
.
first
())
self
.
logger
.
error
(
es
)
# 调度信息写入
try
:
# record["dispatchId"] = item.id
record
[
"dispatchId"
]
=
str
(
uuid
.
uuid1
())
record
[
"exactorId"
]
=
item
.
exactor_id
record
[
"loadAreaId"
]
=
item
.
load_area_id
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"unloadAreaId"
]
=
item
.
unload_area_id
record
[
"groupId"
]
=
group_id
record
[
"isdeleted"
]
=
False
# record["isTemp"] = False
record
[
"haulFlag"
]
=
-
1
record
[
"groupName"
]
=
DispatchInfo
.
group_name
[
group_id
]
if
task
==
0
and
state
==
2
and
self
.
truck
.
get_truck_locate_dict
()[
truck_id
]
in
self
.
topo
.
cross_bf_lanes
:
# 车辆停车等待
# try:
if
truck_id
in
self
.
truck
.
truck_is_temp
and
not
self
.
truck
.
truck_is_temp
[
truck_id
]:
self
.
logger
.
info
(
"二次调度前往装载区"
)
record
[
"isTemp"
]
=
True
# 若尚未二次调度
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
POST
(
truck_id
)
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
else
:
self
.
logger
.
info
(
"车辆已完成二次调度-无需更改派车计划"
)
# except Exception as es:
# self.logger.error(es)
# self.logger.error("二次调度失败")
# record["isTemp"] = False
# redis5.set(truck_id, str(json.dumps(record)))
else
:
self
.
logger
.
info
(
"调度前往装载区"
)
record
[
"isTemp"
]
=
False
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
# redis5.set(truck_id, str(json.dumps(record)))
except
Exception
as
es
:
self
.
logger
.
error
(
"调度结果写入异常-矿卡重载"
)
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
# finally:
# redis5.set(truck_id, str(json.dumps(record)))
elif
task
==
-
2
:
self
.
logger
.
info
(
f
'调度3 {truck_id}'
)
try
:
# 查询车辆相关派车计划
try
:
item
=
(
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
exactor_id
=
dispatch_seq
[
0
],
group_id
=
group_id
,
isdeleted
=
0
)
.
first
())
if
item
is
None
:
raise
Exception
(
"调度计划配置异常"
)
if
dispatch_seq
[
0
]
is
None
:
raise
Exception
(
"调度计划表与实时监控不匹配"
)
except
Exception
as
es
:
item
=
(
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
group_id
=
group_id
,
isdeleted
=
0
,
)
.
first
())
self
.
logger
.
error
(
es
)
# 调度信息写入
try
:
self
.
logger
.
info
(
f
'调度0 {truck_id}'
)
item
=
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
truck_id
=
truck_id
,
isdeleted
=
0
,
)
.
first
()
record
[
"dispatchId"
]
=
item
.
id
# record["dispatchId"] = item.id
record
[
"dispatchId"
]
=
str
(
uuid
.
uuid1
())
record
[
"exactorId"
]
=
item
.
exactor_id
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"loadAreaId"
]
=
item
.
load_area_id
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"unloadAreaId"
]
=
item
.
unload_area_id
record
[
"groupId"
]
=
item
.
group_id
record
[
"groupId"
]
=
group_id
record
[
"isdeleted"
]
=
False
record
[
"isTemp"
]
=
False
record
[
"haulFlag"
]
=
-
1
record
[
"groupName"
]
=
DispatchInfo
.
group_name
[
group_id
]
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
except
Exception
as
es
:
self
.
logger
.
error
(
"调度结果写入异常-矿卡故障或备停区-redis写入异常"
)
self
.
logger
.
error
(
es
)
session_postgre
.
rollback
()
session_mysql
.
rollback
()
finally
:
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
else
:
if
(
task
in
[
1
,
2
])
or
(
task
==
3
and
state
==
2
):
# 卡车空载或在装载区出场前, 可变更卸载目的地
self
.
logger
.
info
(
f
'调度1 {truck_id}'
)
# 查询车辆相关派车计划
try
:
dump_id
=
DispatchInfo
.
unload_area_dump_dict
[
dispatch_seq
[
1
]]
item
=
(
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
dump_id
=
dump_id
,
group_id
=
group_id
,
isdeleted
=
0
,
)
.
first
())
if
item
is
None
:
raise
Exception
(
"调度计划配置异常"
)
if
dispatch_seq
[
0
]
is
None
:
raise
Exception
(
"调度计划表与实时监控不匹配"
)
except
Exception
as
es
:
item
=
(
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
group_id
=
group_id
,
isdeleted
=
0
,
)
.
first
())
self
.
logger
.
error
(
es
)
# 其余调度信息写入
try
:
# record["dispatchId"] = item.id
record
[
"dispatchId"
]
=
str
(
uuid
.
uuid1
())
record
[
"exactorId"
]
=
item
.
exactor_id
record
[
"loadAreaId"
]
=
item
.
load_area_id
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"unloadAreaId"
]
=
item
.
unload_area_id
record
[
"groupId"
]
=
group_id
record
[
"isdeleted"
]
=
False
record
[
"isTemp"
]
=
False
record
[
"haulFlag"
]
=
-
1
record
[
"groupName"
]
=
DispatchInfo
.
group_name
[
group_id
]
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
except
Exception
as
es
:
self
.
logger
.
error
(
"调度结果写入异常-矿卡空载"
)
self
.
logger
.
error
(
es
)
finally
:
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
elif
(
task
in
[
4
,
5
])
or
(
task
==
0
and
state
==
2
):
# 卡车重载或在卸载区出场前, 可变更装载目的地
self
.
logger
.
info
(
f
'调度2 {truck_id}'
)
# 查询车辆相关派车计划
try
:
item
=
(
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
exactor_id
=
dispatch_seq
[
0
],
group_id
=
group_id
,
isdeleted
=
0
,
)
.
first
())
if
item
is
None
:
raise
Exception
(
"调度计划配置异常"
)
if
dispatch_seq
[
0
]
is
None
:
raise
Exception
(
"调度计划表与实时监控不匹配"
)
except
Exception
as
es
:
item
=
(
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
group_id
=
group_id
,
isdeleted
=
0
,
)
.
first
())
self
.
logger
.
error
(
es
)
# 调度信息写入
try
:
# record["dispatchId"] = item.id
record
[
"dispatchId"
]
=
str
(
uuid
.
uuid1
())
record
[
"exactorId"
]
=
item
.
exactor_id
record
[
"loadAreaId"
]
=
item
.
load_area_id
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"unloadAreaId"
]
=
item
.
unload_area_id
record
[
"groupId"
]
=
group_id
record
[
"isdeleted"
]
=
False
record
[
"isTemp"
]
=
False
record
[
"haulFlag"
]
=
-
1
record
[
"groupName"
]
=
DispatchInfo
.
group_name
[
group_id
]
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
except
Exception
as
es
:
self
.
logger
.
error
(
"调度结果写入异常-矿卡重载"
)
finally
:
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
except
Exception
as
es
:
self
.
logger
.
error
(
"调度结果写入异常-矿卡故障或备停区"
)
self
.
logger
.
error
(
es
)
else
:
pass
elif
task
==
-
2
:
self
.
logger
.
info
(
f
'调度3 {truck_id}'
)
try
:
# 查询车辆相关派车计划
try
:
item
=
(
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
exactor_id
=
dispatch_seq
[
0
],
group_id
=
group_id
,
isdeleted
=
0
)
.
first
())
if
item
is
None
:
raise
Exception
(
"调度计划配置异常"
)
if
dispatch_seq
[
0
]
is
None
:
raise
Exception
(
"调度计划表与实时监控不匹配"
)
except
Exception
as
es
:
item
=
(
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
group_id
=
group_id
,
isdeleted
=
0
,
)
.
first
())
self
.
logger
.
error
(
es
)
# 调度信息写入
try
:
# record["dispatchId"] = item.id
record
[
"dispatchId"
]
=
str
(
uuid
.
uuid1
())
record
[
"exactorId"
]
=
item
.
exactor_id
record
[
"loadAreaId"
]
=
item
.
load_area_id
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"unloadAreaId"
]
=
item
.
unload_area_id
record
[
"groupId"
]
=
group_id
record
[
"isdeleted"
]
=
False
record
[
"isTemp"
]
=
False
record
[
"haulFlag"
]
=
-
1
record
[
"groupName"
]
=
DispatchInfo
.
group_name
[
group_id
]
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
# record["createtime"] = datetime.now().strftime(
# "%b %d, %Y %I:%M:%S %p")
except
Exception
as
es
:
self
.
logger
.
error
(
"调度结果写入异常-矿卡故障或备停区-redis写入异常"
)
self
.
logger
.
error
(
es
)
finally
:
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
except
Exception
as
es
:
self
.
logger
.
error
(
"调度结果写入异常-矿卡故障或备停区"
)
self
.
logger
.
error
(
es
)
else
:
pass
def
fixed_dispatch_mode
(
self
,
group_id
,
record
,
truck_id
):
"""
write dispatch plan in fixed dispatch method.
:param group_id:
:param record:
:param truck_id:
:return:
"""
try
:
self
.
logger
.
info
(
f
'调度0 {truck_id}'
)
item
=
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
truck_id
=
truck_id
,
isdeleted
=
0
,
)
.
first
()
record
[
"dispatchId"
]
=
item
.
id
record
[
"exactorId"
]
=
item
.
exactor_id
record
[
"dumpId"
]
=
item
.
dump_id
record
[
"loadAreaId"
]
=
item
.
load_area_id
record
[
"unloadAreaId"
]
=
item
.
unload_area_id
record
[
"groupId"
]
=
item
.
group_id
record
[
"isdeleted"
]
=
False
record
[
"isTemp"
]
=
False
record
[
"haulFlag"
]
=
-
1
record
[
"groupName"
]
=
DispatchInfo
.
group_name
[
group_id
]
self
.
logger
.
info
(
f
'redis 注入 {record}'
)
except
Exception
as
es
:
self
.
logger
.
error
(
"调度结果写入异常"
)
self
.
logger
.
error
(
f
"调度结果:{dispatch_seq}"
)
self
.
logger
.
error
(
es
)
session_postgre
.
rollback
()
session_mysql
.
rollback
()
finally
:
redis5
.
set
(
truck_id
,
str
(
json
.
dumps
(
record
)))
def
group_dispatch_to_redis
(
self
,
group
:
Group
,
dispatch_plan_dict
):
"""
...
...
core/group.py
View file @
0619e46c
...
...
@@ -12,7 +12,7 @@ from alg.algorithm import AlgorithmBase,DistributionRatio
import
numpy
as
np
# from settings import get_logger
from
data.para_config
import
get_value
from
core.util
import
redispatch_request
from
core.util
import
POST
class
CurrentTruck
:
...
...
@@ -167,13 +167,13 @@ class Group:
for
i
in
range
(
len
(
self
.
truck_set
)):
self
.
truck_uuid_index_dict
[
list
(
self
.
truck_set
)[
i
]]
=
i
self
.
excavator_uuid_index_dict
=
bidict
(
DispatchInfo
.
excavator_uuid_to_index_dict
[
self
.
group_id
])
self
.
unload_area_uuid_index_dict
=
bidict
(
DispatchInfo
.
unload_area_uuid_to_index_dict
[
self
.
group_id
])
self
.
dump_uuid_index_dict
=
bidict
(
DispatchInfo
.
dump_uuid_to_index_dict
[
self
.
group_id
])
#
self.excavator_uuid_index_dict = bidict(DispatchInfo.excavator_uuid_to_index_dict[self.group_id])
#
self.unload_area_uuid_index_dict = bidict(DispatchInfo.unload_area_uuid_to_index_dict[self.group_id])
#
self.dump_uuid_index_dict = bidict(DispatchInfo.dump_uuid_to_index_dict[self.group_id])
#
self.excavator_uuid_index_dict = bidict(self.excavator_uuid_index_dict)
#
self.unload_area_uuid_index_dict = bidict(self.unload_area_uuid_index_dict)
#
self.truck_uuid_index_dict = bidict(self.truck_uuid_index_dict)
self
.
excavator_uuid_index_dict
=
bidict
(
self
.
excavator_uuid_index_dict
)
self
.
unload_area_uuid_index_dict
=
bidict
(
self
.
unload_area_uuid_index_dict
)
self
.
truck_uuid_index_dict
=
bidict
(
self
.
truck_uuid_index_dict
)
self
.
dump_uuid_index_dict
=
bidict
(
self
.
dump_uuid_index_dict
)
# group_excavator_dict = {group_1: {excavator_1: load_area_1}, group_2: {excavator_2: load_area_2}}
...
...
@@ -187,36 +187,37 @@ class Group:
# material control
self
.
group_walk_available
=
np
.
ones_like
(
self
.
to_unload_area_distance
)
# try:
self
.
logger
.
info
(
"物料兼容性"
)
self
.
logger
.
info
(
DispatchInfo
.
group_name
[
self
.
group_id
])
for
dump_id
in
self
.
dump
:
for
excavator_id
in
self
.
excavator
:
# load_area_id = DispatchInfo.excavator_load_dict[excavator_id]
# unload_area_id = DispatchInfo.dump_unload_area_dict[dump_id]
excavator_index
=
self
.
excavator_uuid_index_dict
[
excavator_id
]
dump_index
=
self
.
dump_uuid_index_dict
[
dump_id
]
# load_area_index = get_value("load_area_uuid_to_index_dict")[load_area_id]
# unload_area_index = get_value("unload_area_uuid_to_index_dict")[unload_area_id]
# 两设备处理物料不同, 相关路网不可通行
# self.logger.info(excavator_id)
# self.logger.info(self.excavator_info.excavator_material)
self
.
logger
.
info
(
self
.
excavator_info
.
excavator_material
[
excavator_id
])
# self.logger.info(dump_id)
# self.logger.info(self.dump_info.dump_material)
self
.
logger
.
info
(
self
.
dump_info
.
dump_material
[
dump_id
])
if
self
.
excavator_info
.
excavator_material
[
excavator_id
]
not
in
self
.
dump_info
.
dump_material
[
dump_id
]:
self
.
group_walk_available
[
excavator_index
][
dump_index
]
=
10
self
.
logger
.
info
(
"group_walk_available"
)
self
.
logger
.
info
(
self
.
group_walk_available
)
# except Exception as es:
# self.logger.info(es)
# self.logger.info("error-12")
try
:
self
.
logger
.
info
(
"物料兼容性"
)
self
.
logger
.
info
(
DispatchInfo
.
group_name
[
self
.
group_id
])
for
dump_id
in
self
.
dump
:
for
excavator_id
in
self
.
excavator
:
# load_area_id = DispatchInfo.excavator_load_dict[excavator_id]
# unload_area_id = DispatchInfo.dump_unload_area_dict[dump_id]
excavator_index
=
self
.
excavator_uuid_index_dict
[
excavator_id
]
dump_index
=
self
.
dump_uuid_index_dict
[
dump_id
]
# load_area_index = get_value("load_area_uuid_to_index_dict")[load_area_id]
# unload_area_index = get_value("unload_area_uuid_to_index_dict")[unload_area_id]
# 两设备处理物料不同, 相关路网不可通行
# self.logger.info(excavator_id)
# self.logger.info(self.excavator_info.excavator_material)
self
.
logger
.
info
(
self
.
excavator_info
.
excavator_material
[
excavator_id
])
# self.logger.info(dump_id)
# self.logger.info(self.dump_info.dump_material)
self
.
logger
.
info
(
self
.
dump_info
.
dump_material
[
dump_id
])
if
self
.
excavator_info
.
excavator_material
[
excavator_id
]
not
in
self
.
dump_info
.
dump_material
[
dump_id
]:
self
.
group_walk_available
[
excavator_index
][
dump_index
]
=
10
self
.
logger
.
info
(
"group_walk_available"
)
self
.
logger
.
info
(
self
.
group_walk_available
)
except
Exception
as
es
:
self
.
logger
.
error
(
es
)
self
.
logger
.
error
(
es
.
__traceback__
.
tb_lineno
)
self
.
logger
.
error
(
"设备物料读取异常"
)
def
update_device_bind
(
self
):
"""
...
...
@@ -273,40 +274,43 @@ class Group:
for
i
in
list
(
self
.
truck_set
):
self
.
logger
.
info
(
"车辆调度程序"
)
# try:
truck_trip
=
self
.
truck
.
get_truck_current_trip
()[
self
.
truck
.
truck_uuid_to_index_dict
[
i
]]
truck_task
=
self
.
truck
.
get_truck_current_task
()[
i
]
truck_info
=
CurrentTruck
(
i
,
self
.
group_id
,
truck_trip
,
truck_task
)
self
.
truck_info_list
[
i
]
=
truck_info
# except Exception as es:
# self.logger.error("车辆调度信息读取异常")
# self.logger.error(es)
try
:
truck_trip
=
self
.
truck
.
get_truck_current_trip
()[
self
.
truck
.
truck_uuid_to_index_dict
[
i
]]
truck_task
=
self
.
truck
.
get_truck_current_task
()[
i
]
truck_info
=
CurrentTruck
(
i
,
self
.
group_id
,
truck_trip
,
truck_task
)
self
.
truck_info_list
[
i
]
=
truck_info
except
Exception
as
es
:
self
.
logger
.
error
(
"车辆调度信息读取异常"
)
self
.
logger
.
error
(
es
)
self
.
logger
.
info
(
"self.excavator_uuid_index_dict"
)
self
.
logger
.
info
(
self
.
excavator_uuid_index_dict
)
try
:
# 全智能模式
if
self
.
group_mode
==
1
:
# 车辆停止或者车辆位于装载区内, 调度车辆前往卸载区
if
truck_task
in
[
-
2
,
1
,
2
]:
#
try:
if
i
in
self
.
truck
.
truck_excavator_bind
:
next_excavator_id
=
self
.
truck
.
truck_excavator_bind
[
i
]
else
:
next_excavator_value
=
s
.
solve
(
truck_info
)
# next_excavator_value = s.solve(i, truck_task, truck_trip)
# min_index = next_excavator_list.index(min(next_excavator_list))
min_index
=
np
.
argmin
(
next_excavator_value
)
next_excavator_id
=
self
.
excavator_uuid_index_dict
.
inverse
[
min_index
]
if
truck_task
==
-
2
:
next_unload_area_id
=
"Park"
else
:
dump_id
=
get_value
(
"dump_index_to_uuid_dict"
)[
truck_trip
[
-
1
]]
next_unload_area_id
=
get_value
(
"dump_uuid_to_unload_area_uuid_dict"
)[
dump_id
]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
#
except Exception as es:
#
self.logger.error("重载车辆全智能模式-计算异常")
#
self.logger.error(es)
try
:
if
i
in
self
.
truck
.
truck_excavator_bind
:
next_excavator_id
=
self
.
truck
.
truck_excavator_bind
[
i
]
else
:
next_excavator_value
=
s
.
solve
(
truck_info
)
# next_excavator_value = s.solve(i, truck_task, truck_trip)
# min_index = next_excavator_list.index(min(next_excavator_list))
min_index
=
np
.
argmin
(
next_excavator_value
)
next_excavator_id
=
self
.
excavator_uuid_index_dict
.
inverse
[
min_index
]
if
truck_task
==
-
2
:
next_unload_area_id
=
"Park"
else
:
dump_id
=
get_value
(
"dump_index_to_uuid_dict"
)[
truck_trip
[
-
1
]]
next_unload_area_id
=
get_value
(
"dump_uuid_to_unload_area_uuid_dict"
)[
dump_id
]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
except
Exception
as
es
:
self
.
logger
.
error
(
"重载车辆全智能模式-计算异常"
)
self
.
logger
.
error
(
es
)
# 车辆位于卸载区内, 调度车辆前往装载区
elif
truck_task
in
[
4
,
5
]:
try
:
...
...
@@ -347,12 +351,19 @@ class Group:
try
:
truck_locate
=
self
.
truck
.
get_truck_locate_dict
()[
i
]
except
Exception
as
es
:
self
.
logger
.
error
(
"es"
)
self
.
logger
.
error
(
"车辆位置信息丢失"
)
self
.
logger
.
error
(
es
)
try
:
truck_is_temp
=
self
.
truck
.
truck_is_temp
[
i
]
except
Exception
as
es
:
truck_is_temp
=
False
self
.
logger
.
error
(
es
)
# 车辆当前位于交叉路口前,且排队等待
self
.
logger
.
info
(
f
'车辆位置 {truck_locate}'
)
self
.
logger
.
info
(
f
'车辆状态 {self.truck.truck_current_state[i]}'
)
if
truck_locate
in
self
.
topo
.
cross_bf_lanes
and
self
.
truck
.
truck_current_state
[
i
]
==
2
:
self
.
logger
.
info
(
f
'车辆临时 {truck_is_temp} {type(truck_is_temp)}'
)
if
(
truck_locate
in
self
.
topo
.
cross_bf_lanes
)
and
(
self
.
truck
.
truck_current_state
[
i
]
==
2
)
and
\
(
not
truck_is_temp
)
and
(
i
in
self
.
truck
.
truck_is_temp
)
and
(
not
self
.
truck
.
truck_is_temp
[
i
]):
self
.
logger
.
info
(
"触发二次调度"
)
# 当前绑定卸载区
# if truck_trip[0] == -1:
...
...
@@ -371,7 +382,7 @@ class Group:
# else:
# current_excavator_id = get_value("excavator_index_to_uuid_dict")[truck_trip[-1]]
# current_load_area_id = DispatchInfo.excavator_load_dict[current_excavator_id]
load_area_dict
=
self
.
topo
.
get_load_target_node_real
(
truck_locate
,
current_load_area_id
)
load_area_dict
=
self
.
topo
.
get_load_target_node_real
(
truck_locate
,
current_load_area_id
,
True
)
self
.
logger
.
info
(
load_area_dict
)
...
...
@@ -403,20 +414,29 @@ class Group:
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
res
=
redispatch_request
(
i
,
next_excavator_id
,
next_unload_area_id
)
#
res = redispatch_request(i, next_excavator_id, next_unload_area_id)
self
.
logger
.
info
(
res
)
self
.
logger
.
info
(
"二次调度结果"
)
#
self.logger.info(res)
self
.
logger
.
info
(
f
'二次调度结果 {i}'
)
self
.
logger
.
info
(
truck_dispatch
[
i
])
elif
truck_task
==
3
:
try
:
truck_locate
=
self
.
truck
.
get_truck_locate_dict
()[
i
]
except
Exception
as
es
:
self
.
logger
.
error
(
"
es
"
)
self
.
logger
.
error
(
"
车辆位置信息丢失
"
)
self
.
logger
.
error
(
es
)
try
:
truck_is_temp
=
self
.
truck
.
truck_is_temp
[
i
]
except
Exception
as
es
:
truck_is_temp
=
False
self
.
logger
.
error
(
es
)
self
.
logger
.
info
(
f
'车辆位置 {truck_locate}'
)
self
.
logger
.
info
(
f
'车辆状态 {self.truck.truck_current_state[i]}'
)
self
.
logger
.
info
(
f
'车辆临时 {truck_is_temp} {type(truck_is_temp)}'
)
# 车辆当前位于交叉路口前,且排队等待
if
truck_locate
in
self
.
topo
.
cross_bf_lanes
and
self
.
truck
.
truck_current_state
[
i
]
==
0
:
if
(
truck_locate
in
self
.
topo
.
cross_bf_lanes
)
and
(
self
.
truck
.
truck_current_state
[
i
]
==
0
)
and
\
(
not
truck_is_temp
)
and
(
i
in
self
.
truck
.
truck_is_temp
)
and
(
not
self
.
truck
.
truck_is_temp
[
i
]):
# 当前绑定装载区
if
truck_trip
[
0
]
==
-
1
:
next_excavator_id
=
session_mysql
.
query
(
EquipmentPair
)
.
filter_by
(
truck_id
=
i
,
isdeleted
=
0
)
.
first
()
.
exactor_id
...
...
@@ -430,7 +450,7 @@ class Group:
else
:
current_dump_id
=
get_value
(
"dump_index_to_uuid_dict"
)[
truck_trip
[
-
1
]]
current_unload_area_id
=
DispatchInfo
.
dump_unload_area_dict
[
current_dump_id
]
unload_area_dict
=
self
.
topo
.
get_unload_target_node_real
(
truck_locate
,
current_unload_area_id
)
unload_area_dict
=
self
.
topo
.
get_unload_target_node_real
(
truck_locate
,
current_unload_area_id
,
True
)
min_trip_time
=
10000000
best_dump_id
=
current_dump_id
...
...
@@ -457,10 +477,10 @@ class Group:
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
res
=
redispatch_request
(
i
,
next_excavator_id
,
next_unload_area_id
)
#
res = redispatch_request(i, next_excavator_id, next_unload_area_id)
self
.
logger
.
info
(
res
)
self
.
logger
.
info
(
"二次调度结果"
)
#
self.logger.info(res)
self
.
logger
.
info
(
f
'二次调度结果 {i}'
)
self
.
logger
.
info
(
truck_dispatch
[
i
])
# 空车智能模式
...
...
core/ruler.py
deleted
100644 → 0
View file @
c5099188
#!E:\Pycharm Projects\Waytous
# -*- coding: utf-8 -*-
# @Time : 2022/8/18 13:53
# @Author : Opfer
# @Site :
# @File : ruler.py
# @Software: PyCharm
\ No newline at end of file
core/util.py
View file @
0619e46c
...
...
@@ -8,83 +8,46 @@
import
requests
from
tables
import
*
import
uuid
def
redispatch_request
(
truck_id
,
excavator_id
,
unload_area_id
):
"""
redispatch request.
:param truck_id:
:param excavator_id:
:param unload_area_id:
:return:
"""
exactor_no
=
session_mysql
.
query
(
Equipment
)
.
filter_by
(
id
=
excavator_id
)
.
first
()
.
device_name
unload_area_name
=
session_postgre
.
query
(
DumpArea
)
.
filter_by
(
Id
=
unload_area_id
)
.
first
()
.
Name
truck_name
=
session_mysql
.
query
(
Equipment
)
.
filter_by
(
id
=
truck_id
)
.
first
()
.
device_name
real_data
=
{
"exactorId"
:
excavator_id
,
"exactorNo"
:
exactor_no
,
"id"
:
str
(
uuid
.
uuid4
()),
"unloadAreaId"
:
unload_area_id
,
"unloadAreaName"
:
unload_area_name
,
"truckId"
:
truck_id
,
"truckNo"
:
truck_name
,
"isauto"
:
"true"
,
"tempChange"
:
1
,
"immediateEffect"
:
1
}
with
open
(
json_file
)
as
f
:
mysql_config
=
json
.
load
(
f
)[
"mysql"
]
# def redispatch_request(truck_id, excavator_id, unload_area_id):
# """
# redispatch request.
# :param truck_id:
# :param excavator_id:
# :param unload_area_id:
# :return:
# """
#
# exactor_no = session_mysql.query(Equipment).filter_by(id=excavator_id).first().device_name
# unload_area_name = session_postgre.query(DumpArea).filter_by(Id=unload_area_id).first().Name
# truck_name = session_mysql.query(Equipment).filter_by(id=truck_id).first().device_name
#
# real_data = {
# "exactorId": excavator_id,
# "exactorNo": exactor_no,
# "id": str(uuid.uuid4()),
# "unloadAreaId": unload_area_id,
# "unloadAreaName": unload_area_name,
# "truckId": truck_id,
# "truckNo": truck_name,
# "isauto": "true",
# "tempChange": 1,
# "immediateEffect": 1
# }
#
# return POST(real_data)
return
POST
(
real_data
)
def
POST
(
real_data
):
def
POST
(
truck_id
):
"""
Post.
:param real_data:
:return:
"""
# real_data = {
# "exactorId": "ddaa65cc-2658-4e35-b6ec-9deb046e0bfb",
# "exactorNo": "WJ001",
# "id": "d83f09cb-8df3-44d5-8e46-10dbaa317e19",
# "unloadAreaId": "10c75b23-4134-3ef1-9097-114bacac1982",
# "unloadAreaName": "卸载区4",
# "truckId": "de4080b3-fb89-460d-b511-c2ecd73c815c",
# "truckNo": "de4080b3-fb89-460d-b511-c2ecd73c815c",
# "isauto": "false",
# "tempChange": 1,
# "immediateEffect": 1
# }
#
# real_data = {
# 'exactorId': 'a3d09975-82d7-4a30-8c54-fe4ed8ff5a29',
# 'exactorNo': 'BI395-02',
# 'id': '76cb19a8-6541-4245-8ef6-40682aca9635',
# 'unloadAreaId': 'd4675d61-2134-8be7-fb36-fb9ef3c97f7c',
# 'unloadAreaName': '哈卸4',
# 'truckId': '7c196882-8850-4344-aff8-846a597f7792',
# 'truckNo': '7c196882-8850-4344-aff8-846a597f7792',
# 'isauto': 'true',
# 'tempChange': 1,
# 'immediateEffect': 1
# }
#
# head = {"Content-Type":"application/json; charset=UTF-8", 'Connection': 'close'}
url_d
=
"http://172.16.0.103:8020/ht/api/dispatch/update"
real_data
=
json
.
dumps
(
real_data
)
print
(
real_data
)
res_d
=
requests
.
post
(
url
=
url_d
,
data
=
real_data
)
return
res_d
.
text
#
# truck_id, excavator_id, unload_area_id = "9ce82957-b1e1-4dee-8dd1-3bbfa2a496b5", \
# "a3d09975-82d7-4a30-8c54-fe4ed8ff5a29", \
# "d4675d61-2134-8be7-fb36-fb9ef3c97f7c"
#
# res = redispatch_request(truck_id, excavator_id, unload_area_id)
#
# print(res)
\ No newline at end of file
url_d
=
"http://"
+
mysql_config
[
"host"
]
+
":8020/ht/api/dispatch/updateTemp?truckId="
+
truck_id
res_d
=
requests
.
get
(
url_d
)
print
(
res_d
.
text
)
return
res_d
.
text
\ No newline at end of file
data/dispatchInfo.py
View file @
0619e46c
...
...
@@ -401,9 +401,9 @@ class DispatchInfo:
cls
.
load_distance
[
item
]
=
unload_load_distance
except
Exception
as
es
:
logger
.
error
(
f
'{item} 分组装载路网异常'
)
logger
.
warning
(
f
'{item} 分组装载路网异常'
)
cls
.
load_distance
[
item
]
=
np
.
full
((
len
(
unload_areas
),
len
(
load_areas
)),
10000
)
logger
.
error
(
es
)
logger
.
warning
(
es
)
session_postgre
.
rollback
()
session_mysql
.
rollback
()
...
...
@@ -418,9 +418,9 @@ class DispatchInfo:
cls
.
unload_distance
[
item
]
=
load_unload_distance
except
Exception
as
es
:
logger
.
error
(
f
'{item} 分组卸载路网异常'
)
logger
.
warning
(
f
'{item} 分组卸载路网异常'
)
cls
.
unload_distance
[
item
]
=
np
.
full
((
len
(
load_areas
),
len
(
unload_areas
)),
10000
)
logger
.
error
(
es
)
logger
.
warning
(
es
)
session_postgre
.
rollback
()
session_mysql
.
rollback
()
...
...
equipment/excavator.py
View file @
0619e46c
...
...
@@ -82,7 +82,7 @@ class ExcavatorInfo(WalkManage):
self
.
logger
.
info
(
self
.
loading_time
)
self
.
logger
.
info
(
"excavator_uuid_to_index_dict"
)
self
.
logger
.
info
(
self
.
excavator_uuid_to_index_dict
)
self
.
loading_time
[
self
.
excavator_uuid_to_index_dict
[
excavator_id
]]
=
10
.00
self
.
loading_time
[
self
.
excavator_uuid_to_index_dict
[
excavator_id
]]
=
2
.00
# 更新挖机设备出入时间
def
update_excavator_entrance_exit_time
(
self
):
...
...
equipment/truck.py
View file @
0619e46c
...
...
@@ -86,6 +86,8 @@ class TruckInfo(WalkManage):
self
.
_excavator
=
excavator
# 车辆位置信息
self
.
truck_locate_dict
=
{}
# 车辆临时调度
self
.
truck_is_temp
=
{}
def
get_truck_current_trip
(
self
):
return
self
.
truck_current_trip
...
...
@@ -137,6 +139,7 @@ class TruckInfo(WalkManage):
# 更新矿卡当前任务
def
update_truck_current_task
(
self
):
self
.
truck_current_task
=
{}
self
.
truck_current_state
=
{}
device_name_set
=
redis2
.
keys
()
truck_name_to_uuid_dict
=
get_value
(
"truck_name_to_uuid_dict"
)
...
...
@@ -186,6 +189,43 @@ class TruckInfo(WalkManage):
# logger.info("矿卡当前任务:")
# logger.info(self.truck_current_task)
def
update_truck_is_temp
(
self
):
"""
:return:
"""
self
.
truck_is_temp
=
{}
device_name_set
=
redis2
.
keys
()
truck_name_to_uuid_dict
=
get_value
(
"truck_name_to_uuid_dict"
)
for
item
in
device_name_set
:
try
:
item
=
item
.
decode
(
encoding
=
"utf-8"
)
if
item
not
in
truck_name_to_uuid_dict
:
continue
key_value_dict
=
byte_to_str
(
redis5
.
get
(
truck_name_to_uuid_dict
[
item
]))
# reids str可以自动转为bytes
print
(
key_value_dict
)
key_value_dict
=
json
.
loads
(
key_value_dict
)
if
truck_name_to_uuid_dict
[
item
]
in
self
.
dynamic_truck_set
:
try
:
isTemp
=
key_value_dict
[
"isTemp"
]
print
(
isTemp
)
self
.
truck_is_temp
[
truck_name_to_uuid_dict
[
item
]]
=
bool
(
isTemp
)
except
Exception
as
es
:
self
.
logger
.
error
(
es
)
self
.
truck_is_temp
[
truck_name_to_uuid_dict
[
item
]]
=
True
print
(
f
'here3 {item} {bool(isTemp)}'
)
except
Exception
as
es
:
self
.
logger
.
warning
(
"读取矿卡任务异常-reids读取异常"
)
self
.
logger
.
warning
(
es
)
self
.
logger
.
info
(
"isTemp"
)
self
.
logger
.
info
(
self
.
truck_is_temp
)
# 更新矿卡最后装载/卸载时间
def
update_truck_last_leave_time
(
self
):
self
.
last_load_time
=
{}
...
...
@@ -885,6 +925,8 @@ class TruckInfo(WalkManage):
# 更新卡车当前任务
self
.
update_truck_current_task
()
self
.
update_truck_is_temp
()
# 更新卡车最后一次装载/卸载时间
self
.
update_truck_last_leave_time
()
...
...
graph/topo_graph.py
View file @
0619e46c
...
...
@@ -326,15 +326,19 @@ class Topo():
unload_G target
"""
def
get_unload_target_node_real
(
self
,
truck_location_lane
,
pre_target
):
def
get_unload_target_node_real
(
self
,
truck_location_lane
,
pre_target
,
allow
):
source_node
=
self
.
get_unload_edge_node
(
truck_location_lane
)
target_list
=
[]
for
(
u
,
wt
)
in
self
.
unload_G
.
nodes
.
data
(
'name'
):
# select next reachable target
if
wt
==
'dump'
and
u
!=
pre_target
:
target_list
.
append
(
u
)
if
wt
==
'dump'
:
if
allow
:
target_list
.
append
(
u
)
else
:
if
u
!=
pre_target
:
target_list
.
append
(
u
)
if
not
len
(
target_list
):
self
.
logger
.
error
(
"当前无可去卸载区!"
)
...
...
@@ -420,7 +424,7 @@ class Topo():
load_G target
"""
def
get_load_target_node_real
(
self
,
truck_location_lane
,
pre_target
):
def
get_load_target_node_real
(
self
,
truck_location_lane
,
pre_target
,
allow
):
# source_node = self.get_load_edge_node(truck_location_lane)
source_node
,
end_node
=
self
.
get_load_edge_node
(
truck_location_lane
)
...
...
@@ -432,8 +436,12 @@ class Topo():
target_list
=
[]
for
(
node
,
att
)
in
self
.
load_G
.
nodes
.
data
(
'name'
):
# select next reachable target
if
att
==
'digging'
and
node
!=
pre_destination_node
:
target_list
.
append
(
node
)
if
att
==
'digging'
:
if
allow
:
target_list
.
append
(
node
)
else
:
if
node
!=
pre_destination_node
:
target_list
.
append
(
node
)
if
not
len
(
target_list
):
self
.
logger
.
error
(
"当前无可去装载区!"
)
...
...
topo_update_server.py
View file @
0619e46c
...
...
@@ -9,6 +9,6 @@
from
graph.topo_update
import
topo_graph_update
from
graph.graph_load
import
graph_construct
#
topo_graph_update()
topo_graph_update
()
graph_construct
()
\ No newline at end of file
# graph_construct()
\ No newline at end of file
调度系统部署说明4.1.docx
View file @
0619e46c
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment