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
efc064b5
Commit
efc064b5
authored
Oct 08, 2022
by
张晓彤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化
parent
ea6385f4
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
100 deletions
+115
-100
dispatcher.py
core/dispatcher.py
+3
-7
group.py
core/group.py
+60
-49
realtime_dispatch.py
realtime_dispatch.py
+18
-44
__init__.py
util/__init__.py
+10
-0
core_exception.py
util/core_exception.py
+24
-0
No files found.
core/dispatcher.py
View file @
efc064b5
...
...
@@ -19,6 +19,7 @@ import uuid
from
tables
import
session_mysql
,
session_postgre
from
graph.graph_load
import
graph_construct
from
core.util
import
POST
from
graph.topo_graph
import
Topo
class
Dispatcher
:
...
...
@@ -36,15 +37,12 @@ class Dispatcher:
self
.
submission
=
DispatchSubmission
(
dump
,
excavator
,
truck
,
self
.
topo
)
self
.
logger
=
get_logger
(
"zxt.dispatcher"
)
def
period_update
(
self
):
"""
Update
global parameter and
equipment information.
Update equipment information.
:return: None
"""
# global_period_para_update()
self
.
dump
.
dump_para_period_update
()
self
.
excavator
.
excavator_para_period_update
()
self
.
truck
.
truck_para_period_update
(
self
.
dump
,
self
.
excavator
)
...
...
@@ -76,8 +74,6 @@ class Dispatcher:
Group dispatching logic.
:return:
"""
a
=
len
(
self
.
group_list
)
aa
=
self
.
group_list
for
group
in
self
.
group_list
.
values
():
try
:
...
...
@@ -105,7 +101,7 @@ class DispatchSubmission:
Attribute:
"""
def
__init__
(
self
,
dump
,
excavator
,
truck
,
t
opo
):
def
__init__
(
self
,
dump
:
DumpInfo
,
excavator
:
ExcavatorInfo
,
truck
:
TruckInfo
,
topo
:
T
opo
):
self
.
logger
=
get_logger
(
"zxt.submission"
)
self
.
dump
=
dump
self
.
excavator
=
excavator
...
...
core/group.py
View file @
efc064b5
...
...
@@ -13,6 +13,8 @@ import numpy as np
# from settings import get_logger
from
data.para_config
import
get_value
from
core.util
import
*
from
typing
import
Mapping
,
List
from
util
import
CoreException
class
CurrentTruck
:
...
...
@@ -155,29 +157,6 @@ class Group:
# self.truck_uuid_index_dict = DispatchInfo.get_group_truck_dict(self.group_id)
self
.
dump_uuid_index_dict
=
DispatchInfo
.
get_group_dump_dict
(
self
.
group_id
)
# for i in range(len(self.excavator)):
# self.excavator_uuid_index_dict[list(self.excavator)[i]] = i
#
# for i in range(len(self.unload_area)):
# self.unload_area_uuid_index_dict[list(self.unload_area)[i]] = i
#
# for i in range(len(self.dump)):
# self.dump_uuid_index_dict[list(self.dump)[i]] = i
#
# 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(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}}
def
update_device_material
(
self
):
"""
update group device material.
...
...
@@ -258,56 +237,89 @@ class Group:
self
.
update_group_road_network
()
self
.
update_device_material
()
def
group_dispatch
(
self
,
solver
:
object
)
:
def
group_dispatch
(
self
,
Solver
)
->
Mapping
[
str
,
List
[
str
,
str
]]
:
"""
Receive a
a
lg obj. and output dispatch plan for trucks in this group.
:param
s
olver:
Receive a
A
lg obj. and output dispatch plan for trucks in this group.
:param
S
olver:
:return:
dispatch plan: Dict({truck_id: match_id})
"""
truck_dispatch
=
{}
self
.
truck_info_list
=
{}
assert
issubclass
(
s
olver
,
AlgorithmBase
)
s
=
solver
(
self
,
self
.
truck
,
self
.
pre_sch
)
#
algorithm init
assert
issubclass
(
S
olver
,
AlgorithmBase
)
s
olver
=
Solver
(
self
,
self
.
truck
,
self
.
pre_sch
)
# solver
algorithm init
self
.
logger
.
info
(
f
'分组 {self.group_name} 调度计算
调度模式 {self.group_mode}'
)
self
.
logger
.
info
(
f
'分组 {self.group_name} 调度计算
-
调度模式 {self.group_mode}'
)
for
i
in
list
(
self
.
truck_set
):
for
truck_id
in
list
(
self
.
truck_set
):
self
.
logger
.
info
(
f
'调度车辆 {
i
}'
)
self
.
logger
.
info
(
f
'调度车辆 {
truck_id
}'
)
# try:
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
if
truck_id
not
in
self
.
truck
.
truck_uuid_to_index_dict
:
raise
CoreException
(
102
,
f
'truck.truck dict 中不存在 {truck_id}'
)
# truck_task = 0
# if i != "f704aa5e-24d9-4822-b634-ae81ca5ff0be":
# self.truck.get_truck_locate_dict()[i] = "8961f641-c134-8be8-f4eb-95e6e2c374b7"
# self.truck.truck_is_temp[i] = False
# self.truck.truck_current_state[i] = 2
truck_idx
=
self
.
truck
.
truck_uuid_to_index_dict
[
truck_id
]
except
CoreException
as
es
:
self
.
logger
.
error
(
es
)
continue
except
Exception
as
es
:
self
.
logger
.
error
(
"车辆调度信息读取异常"
)
try
:
truck_trip_info_list
=
self
.
truck
.
get_truck_current_trip
()
if
truck_idx
>=
len
(
truck_trip_info_list
):
raise
CoreException
(
103
,
f
'truck.truck trip 中不存在 {truck_idx} 号矿卡 {truck_id}'
)
truck_trip
=
self
.
truck
.
get_truck_current_trip
()[
truck_idx
]
except
CoreException
as
es
:
self
.
logger
.
error
(
es
)
continue
# TODO: 怎么知道异常行数
try
:
truck_task_list
=
self
.
truck
.
get_truck_current_task
()
if
truck_id
not
in
truck_task_list
:
raise
CoreException
(
102
,
f
'truck.truck task 中不存在矿卡 {truck_id}'
)
truck_task
=
truck_task_list
[
truck_id
]
except
CoreException
as
ce
:
self
.
logger
.
error
(
ce
)
continue
# Construct a truck obj.
truck_info
=
CurrentTruck
(
truck_id
,
self
.
group_id
,
truck_trip
,
truck_task
)
self
.
truck_info_list
[
truck_id
]
=
truck_info
# Construct a test case for redispatch
# truck_task = 0
# if truck_id != "f704aa5e-24d9-4822-b634-ae81ca5ff0be":
# self.truck.get_truck_locate_dict()[truck_id] = "8961f641-c134-8be8-f4eb-95e6e2c374b7"
# self.truck.truck_is_temp[truck_id] = False
# self.truck.truck_current_state[truck_id] = 2
# except Exception as es:
# self.logger.error("车辆调度信息读取异常")
# self.logger.error(es)
try
:
# 全智能模式
if
self
.
group_mode
==
1
:
self
.
logger
.
info
(
"全智能模式调度"
)
self
.
full_dynamic_mode
(
i
,
s
,
truck_dispatch
,
truck_info
,
truck_task
,
truck_trip
)
self
.
full_dynamic_mode
(
truck_id
,
solver
,
truck_dispatch
,
truck_info
,
truck_task
,
truck_trip
)
# 空车智能模式
elif
self
.
group_mode
==
2
:
self
.
logger
.
info
(
"空车智能模式调度"
)
self
.
semi_dynamic_mode
(
i
,
s
,
truck_dispatch
,
truck_info
,
truck_task
,
truck_trip
)
self
.
semi_dynamic_mode
(
truck_id
,
solver
,
truck_dispatch
,
truck_info
,
truck_task
,
truck_trip
)
# 定铲派车
elif
self
.
group_mode
==
3
:
self
.
logger
.
info
(
"固定模式调度"
)
try
:
truck_dispatch
[
i
]
=
DispatchInfo
.
get_truck_match
(
i
)
truck_dispatch
[
truck_id
]
=
DispatchInfo
.
get_truck_match
(
truck_id
)
except
Exception
as
es
:
self
.
logger
.
error
(
"固定派车-计算异常"
)
self
.
logger
.
error
(
es
)
...
...
@@ -315,7 +327,7 @@ class Group:
# 分流配比模式
elif
self
.
group_mode
==
4
:
self
.
logger
.
info
(
"分流配比模式调度"
)
self
.
ratio_mode
(
i
,
truck_dispatch
,
truck_task
)
self
.
ratio_mode
(
truck_id
,
truck_dispatch
,
truck_task
)
except
Exception
as
es
:
self
.
logger
.
error
(
es
)
...
...
@@ -395,7 +407,8 @@ class Group:
self
.
logger
.
error
(
"空载车辆空车智能模式-计算异常"
)
self
.
logger
.
error
(
es
)
def
full_dynamic_mode
(
self
,
i
,
s
,
truck_dispatch
,
truck_info
,
truck_task
,
truck_trip
):
def
full_dynamic_mode
(
self
,
i
:
str
,
s
:
AlgorithmBase
,
truck_dispatch
:
Mapping
[
str
,
List
[
str
,
str
]],
truck_info
:
CurrentTruck
,
truck_task
:
int
,
truck_trip
:
List
[
int
,
int
]):
# 车辆停止或者车辆位于卸载区内, 调度车辆前往装载区
if
truck_task
in
[
-
2
,
4
,
5
]:
try
:
...
...
@@ -403,8 +416,6 @@ class Group:
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
]
...
...
realtime_dispatch.py
View file @
efc064b5
...
...
@@ -17,6 +17,7 @@ import time
from
core.dispatcher
import
Dispatcher
from
core.schedule
import
PreSchedule
from
data.dispatchInfo
import
DispatchInfo
from
util
import
CoreException
def
direct2redis
():
...
...
@@ -36,25 +37,20 @@ def direct2redis():
truck_disp
=
{}
for
item
in
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
isdeleted
=
0
,
)
.
all
():
if
item
is
None
:
raise
CoreException
(
101
,
"无可用派车计划"
)
if
item
.
truck_id
not
in
truck_disp
:
record
=
{
"truckId"
:
item
.
truck_id
}
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
[
item
.
group_id
]
logger
.
info
(
"调度结果"
)
logger
.
info
(
record
)
record
=
{
"truckId"
:
item
.
truck_id
,
"dispatchId"
:
item
.
id
,
"exactorId"
:
item
.
exactor_id
,
"dumpId"
:
item
.
dump_id
,
"loadAreaId"
:
item
.
load_area_id
,
"unloadAreaId"
:
item
.
unload_area_id
,
"groupId"
:
item
.
group_id
,
"isdeleted"
:
False
,
"isTemp"
:
False
,
"haulFlag"
:
-
1
,
"groupName"
:
DispatchInfo
.
group_name
[
item
.
group_id
]}
logger
.
info
(
f
'写入redis调度结果: {record}'
)
# 写入redis
redis5
.
set
(
item
.
truck_id
,
str
(
json
.
dumps
(
record
)))
except
Exception
as
es
:
logger
.
error
(
es
)
except
CoreException
as
ce
:
logger
.
error
(
ce
)
session_postgre
.
rollback
()
session_mysql
.
rollback
()
...
...
@@ -75,12 +71,12 @@ def process(dispatcher):
global_period_para_update
()
#
if get_value("dynamic_dump_num") * get_value("dynamic_excavator_num") == 0:
# raise Exception("无动态派车计划可用
")
# return
#
if get_value("dynamic_truck_num") == 0:
# raise Exception("无动态派车可用矿卡
")
# return
if
get_value
(
"dynamic_dump_num"
)
*
get_value
(
"dynamic_excavator_num"
)
==
0
:
raise
CoreException
(
101
,
"无可用派车计划
"
)
if
get_value
(
"dynamic_truck_num"
)
==
0
:
raise
CoreException
(
101
,
"无可用调度车辆
"
)
# 清空数据库缓存
session_mysql
.
commit
()
...
...
@@ -103,28 +99,6 @@ def process(dispatcher):
DispatchInfo
.
update_group_name
()
# logger.info
# group_set = set()
#
# # device group structure
# load_excavator_dict = {} # 装载区id-->>电铲编号的映射
# excavator_load_dict = {} # 电铲编号->>装载区id的映射
#
# group_excavator_dict = {} # team_id -> dict {[excavator_id, excavator_id], ...}
# excavator_group_dict = {} # excavator_id -> team_id 问题:多个key值对应一个value值
#
# group_dump_dict = {} # team_id -> dict {unload_area_id, unload_area_id, ...}
# dump_group_dict = {} # unload_area_id -> team_id
#
# group_truck_dict = {} # team_id -> dict # {group_id:[truck_id,truck_id],...}
# truck_group_dict = {} # truck_id -> team_id
#
# # group feature
# group_mode = {} # 数据格式: {team_id:mode_code}
#
# # route_distance(路网距离)
# load_distance = {}
# unload_distance = {}
logger
.
info
(
"Dispatchinfo,更新后信息"
)
logger
.
info
(
"group_set"
)
logger
.
info
(
DispatchInfo
.
group_set
)
...
...
util/__init__.py
0 → 100644
View file @
efc064b5
#!E:\Pycharm Projects\Waytous
# -*- coding: utf-8 -*-
# @Time : 2022/10/8 11:32
# @Author : Opfer
# @Site :
# @File : __init__.py
# @Software: PyCharm
from
util.core_exception
import
CoreException
\ No newline at end of file
util/core_exception.py
0 → 100644
View file @
efc064b5
#!E:\Pycharm Projects\Waytous
# -*- coding: utf-8 -*-
# @Time : 2022/10/8 11:33
# @Author : Opfer
# @Site :
# @File : core_exception.py
# @Software: PyCharm
code_msg
=
{
101
:
"调度失败"
,
102
:
"车辆不存在或信息缺失"
,
103
:
"数组越界异常"
}
class
CoreException
(
Exception
):
""" class for my exception."""
def
__init__
(
self
,
Code
=
None
,
ErrorInfo
=
None
):
super
()
.
__init__
(
self
,
ErrorInfo
)
self
.
error_info
=
ErrorInfo
self
.
code
=
Code
def
__str__
(
self
):
return
'{0:}-{1:}'
.
format
(
code_msg
[
self
.
code
],
self
.
error_info
)
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