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
aed9900d
Commit
aed9900d
authored
Jun 23, 2022
by
张晓彤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化623
parent
db860cc7
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
93 additions
and
103 deletions
+93
-103
algorithm.py
alg/algorithm.py
+12
-4
config.json
config.json
+1
-1
group.py
core/group.py
+53
-76
dispatchInfo.py
data/dispatchInfo.py
+22
-17
realtime_dispatch.py
realtime_dispatch.py
+1
-1
settings.py
settings.py
+4
-4
No files found.
alg/algorithm.py
View file @
aed9900d
...
...
@@ -140,20 +140,28 @@ class ExpectedTime(AlgorithmBase):
self
.
pre_sch
=
pre_sch
self
.
logger
=
get_logger
(
"zxt.algorithm.expected"
)
def
solve
(
self
,
truck_i
d
):
def
solve
(
self
,
truck_i
nfo
):
"""
Receive a truck_id and calculate the associated route travelling time.
:param truck_i
d: (uuid
)
:param truck_i
nfo: (current truck obj
)
:return: travel_time_value
"""
try
:
# truck_index = self.truck.truck_uuid_to_index_dict[truck_id]
# trip = self.truck.get_truck_current_trip()[truck_index]
#
# task = self.truck.get_truck_current_task()[truck_id]
truck_id
=
truck_info
.
get_truck_id
()
truck_index
=
self
.
truck
.
truck_uuid_to_index_dict
[
truck_id
]
trip
=
self
.
truck
.
get_truck_current_trip
()[
truck_index
]
trip
=
truck_info
.
get_trip
()
task
=
self
.
truck
.
get_truck_current_task
()[
truck_id
]
task
=
truck_info
.
get_task
()
truck_avl_time
=
self
.
pre_sch
.
get_truck_avl_time
(
truck_id
=
truck_id
)
...
...
config.json
View file @
aed9900d
{
"para"
:
{
"log_path"
:
"/
Users/guoao/Desktop/work_log/wek46/code_1/integrated-scheduling-v4/Logs
"
,
"log_path"
:
"/
usr/local/fleet-log/dispatch
"
,
"empty_speed"
:
17
,
"heavy_speed"
:
17
,
"dump_target_mass"
:
5000
,
...
...
core/group.py
View file @
aed9900d
...
...
@@ -20,6 +20,38 @@ from bidict import bidict
from
alg.algorithm
import
AlgorithmBase
import
numpy
as
np
class
CurrentTruck
:
""" class for the information of current dispatching truck.
Description:
当前请求调度卡车信息
Attribute:
truck_id(uuid)
group_id(uuid)
trip(list)
task(int)
"""
def
__init__
(
self
,
truck_id
,
group_id
,
trip
,
task
):
self
.
_truck_id
=
truck_id
self
.
_group_id
=
group_id
self
.
_trip
=
trip
self
.
_task
=
task
def
get_truck_id
(
self
):
return
self
.
_truck_id
def
get_trip
(
self
):
return
self
.
_trip
def
get_task
(
self
):
return
self
.
_task
def
get_group_id
(
self
):
return
self
.
_group_id
class
Group
:
"""
...
...
@@ -29,18 +61,17 @@ class Group:
""" Generate a group obj.
:param group_id: (uuid) group_id
"""
self
.
to_unload_area_congestion
=
None
# basic info.
self
.
group_id
=
group_id
self
.
group_mode
=
1
self
.
truck
=
truck
self
.
pre_sch
=
pre_sch
# group devices
self
.
excavator
=
{}
# excavator_id -> unload_area_id
self
.
unload_area
=
{}
# unload_area_id -> load_area_id
self
.
excavator
s
=
{}
# excavator_id -> unload_area_id
self
.
unload_area
s
=
{}
# unload_area_id -> load_area_id
self
.
truck_set
=
set
()
# truck_id
# road network info.
self
.
to_excavator_distance
=
None
self
.
to_unload_area_distance
=
None
...
...
@@ -71,8 +102,8 @@ class Group:
"""
# update group devices
# DispatchInfo.update_device_group_structure()
self
.
excavator
=
DispatchInfo
.
get_excavator
(
self
.
group_id
)
self
.
unload_area
=
DispatchInfo
.
get_unload_area
(
self
.
group_id
)
self
.
excavator
s
=
DispatchInfo
.
get_excavator
(
self
.
group_id
)
self
.
unload_area
s
=
DispatchInfo
.
get_unload_area
(
self
.
group_id
)
self
.
truck_set
=
DispatchInfo
.
get_truck_set
(
self
.
group_id
)
def
update_group_road_network
(
self
):
...
...
@@ -80,7 +111,6 @@ class Group:
update group road network.
:return:
"""
# update group road network
# DispatchInfo.update_route_distance()
self
.
to_excavator_distance
=
DispatchInfo
.
get_to_excavator_distance
(
self
.
group_id
)
self
.
to_unload_area_distance
=
DispatchInfo
.
get_to_unload_area_distance
(
self
.
group_id
)
...
...
@@ -91,13 +121,12 @@ class Group:
update group device map.
:return:
"""
# update device map
# excavator_index = 0
for
i
in
range
(
len
(
self
.
excavator
)):
self
.
excavator_uuid_index_dict
[
list
(
self
.
excavator
)[
i
]]
=
i
for
i
in
range
(
len
(
self
.
excavator
s
)):
self
.
excavator_uuid_index_dict
[
list
(
self
.
excavator
s
)[
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
.
unload_area
s
)):
self
.
unload_area_uuid_index_dict
[
list
(
self
.
unload_area
s
)[
i
]]
=
i
for
i
in
range
(
len
(
self
.
truck_set
)):
self
.
truck_uuid_index_dict
[
list
(
self
.
truck_set
)[
i
]]
=
i
...
...
@@ -127,6 +156,7 @@ class Group:
"""
truck_dispatch
=
{}
# 全智能模式
if
self
.
group_mode
==
1
:
assert
issubclass
(
solver
,
AlgorithmBase
)
s
=
solver
(
self
,
self
.
truck
,
self
.
pre_sch
)
# algorithm init
...
...
@@ -134,8 +164,9 @@ class Group:
for
i
in
list
(
self
.
truck_set
):
truck_trip
=
self
.
truck
.
get_truck_current_trip
()[
self
.
truck_uuid_index_dict
[
i
]]
truck_task
=
self
.
truck
.
get_truck_current_task
()[
i
]
truck_info
=
CurrentTruck
(
i
,
self
.
group_id
,
truck_trip
,
truck_task
)
if
truck_task
in
[
-
2
,
3
,
4
]:
next_excavator_value
=
s
.
solve
(
i
)
next_excavator_value
=
s
.
solve
(
i
,
truck_info
)
# min_index = next_excavator_list.index(min(next_excavator_list))
min_index
=
np
.
argmin
(
next_excavator_value
)
next_excavator_id
=
self
.
excavator_uuid_index_dict
.
inverse
[
min_index
]
...
...
@@ -152,15 +183,16 @@ class Group:
next_excavator_id
=
self
.
excavator_uuid_index_dict
.
inverse
[
truck_trip
[
-
1
]]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
# 空车智能模式
if
self
.
group_mode
==
2
:
el
if
self
.
group_mode
==
2
:
assert
issubclass
(
solver
,
AlgorithmBase
)
s
=
solver
(
self
,
self
.
truck
,
self
.
pre_sch
)
# algorithm init
for
i
in
list
(
self
.
truck_set
):
truck_trip
=
self
.
truck
.
get_truck_current_trip
()[
self
.
truck_uuid_index_dict
[
i
]]
truck_task
=
self
.
truck
.
get_truck_current_task
()[
i
]
truck_info
=
CurrentTruck
(
i
,
self
.
group_id
,
truck_trip
,
truck_task
)
if
truck_task
in
[
-
2
,
3
,
4
]:
next_excavator_value
=
s
.
solve
(
i
)
next_excavator_value
=
s
.
solve
(
i
,
truck_info
)
# min_index = next_excavator_list.index(min(next_excavator_list))
min_index
=
np
.
argmin
(
next_excavator_value
)
next_excavator_id
=
self
.
excavator_uuid_index_dict
.
inverse
[
min_index
]
...
...
@@ -170,70 +202,14 @@ class Group:
next_unload_area_id
=
self
.
unload_area_uuid_index_dict
.
inverse
[
truck_trip
[
-
1
]]
truck_dispatch
[
i
]
=
[
next_excavator_id
,
next_unload_area_id
]
if
truck_task
in
[
0
,
1
]:
truck_dispatch
[
i
]
=
DispatchInfo
.
get_truck_
team_trip
(
i
)
if
self
.
group_mode
==
3
:
truck_dispatch
[
i
]
=
DispatchInfo
.
get_truck_
match
(
i
)
# 定铲派车
el
if
self
.
group_mode
==
3
:
for
i
in
list
(
self
.
truck_set
):
truck_dispatch
[
i
]
=
DispatchInfo
.
get_truck_
team_trip
(
i
)
truck_dispatch
[
i
]
=
DispatchInfo
.
get_truck_
match
(
i
)
if
self
.
group_mode
==
4
:
el
if
self
.
group_mode
==
4
:
pass
# return dispatch plan
return
truck_dispatch
\ No newline at end of file
# from data.dispatchInfo import DispatchInfo
# from bidict import bidict
# from alg.algorithm import AlgorithmBase
#
#
# class Group_0:
# """
# class for group instance.
# """
# def __init__(self, group_id):
# """ Generate a group obj.
# :param group_id: (uuid) group_id
# """
#
# self.group_id = group_id
#
# # group devices
# self.excavator_dict = {} # excavator_id -> unload_area_id
# self.unload_area = {} # unload_area_id -> load_area_id
# self.truck_set = set() # truck_id
#
# # road network info.
# self.to_excavator_distance = None
# self.to_unload_area_distance = None
# self.park_to_excavator_distance = None
#
# self.to_excavator_congestion = None
# self.to_unload_area_congestion = None
# self.park_to_excavator_congestion = None
#
# # device map
# self.truck_uuid_index_dict = bidict()
# self.excavator_uuid_index_dict = bidict()
# self.unload_area_uuid_index_dict = bidict()
#
# def update_xx_(self):
# """
# update above parameters.
# :return:
# """
# pass
#
# def group_dispatch(self, solver):
# """
# Receive a alg obj. and output dispatch plan for trucks in this group.
# :param solver:
# :return:
# dispatch plan: Dict({truck_id: match_id})
# """
# assert isinstance(solver, AlgorithmBase)
# s = solver(self) # algorithm init
# return s.solve() # algorithm solve
data/dispatchInfo.py
View file @
aed9900d
...
...
@@ -24,16 +24,19 @@ class DispatchInfo:
load_excavator_dict
=
{}
# 装载区id-->>电铲编号的映射
excavator_load_dict
=
{}
# 电铲编号->>装载区id的映射
# excavator <-> team_id
group_excavator_dict
=
{}
# team_id -> dict {[excavator_id, excavator_id], ...}
excavator_group_dict
=
{}
# excavator_id -> team_id 问题:多个key值对应一个value值
# unload_area <-> team_id
group_unload_area_dict
=
{}
# team_id -> dict {unload_area_id, unload_area_id, ...}
unload_area_group_dict
=
{}
# unload_area_id -> team_id
# truck_id <-> team_id
group_truck_dict
=
{}
# team_id -> dict # {group_id:[truck_id,truck_id],...}
truck_group_dict
=
{}
# truck_id -> team_id
# group
featur
e
# group
mod
e
group_mode
=
{}
# 数据格式: {team_id:mode_code}
# route_distance(路网距离)
...
...
@@ -43,10 +46,11 @@ class DispatchInfo:
# group_name <-> group_id
group_name
=
{}
truck_team_trip_dict
=
{}
# truck -> match(excavator_id, unload_area_id)
truck_match_dict
=
{}
@classmethod
def
re
new_
set
(
cls
):
def
reset
(
cls
):
"""
@date:2022/6/2 19:50
@author:maqc
...
...
@@ -71,7 +75,7 @@ class DispatchInfo:
cls
.
load_distance
=
{}
cls
.
unload_distance
=
{}
cls
.
truck_
team_trip
_dict
=
{}
cls
.
truck_
match
_dict
=
{}
# cls.group_unload_area_dict = {} # cls.group_unload_area_dict.keys() 相当于所有的team_id
# cls.unload_area_group_dict = {} # cls.unload_area_group_dict.keys() 相当于所有的卸载区 unload_area_id
...
...
@@ -93,7 +97,7 @@ class DispatchInfo:
@desc:分组与卸载区、挖机、矿卡的映射和反映射
"""
logger
=
get_logger
(
"mqc.update_device_group_structure"
)
#
build excavator group map
#
update excavator_id <-> load_area_id
try
:
for
item
in
session_mysql
.
query
(
DispatchSetting
)
.
all
():
...
...
@@ -104,7 +108,7 @@ class DispatchInfo:
logger
.
error
(
"挖机和装载区映射更新异常"
)
logger
.
error
(
es
)
# update excavator
<->group and unload_area<->group map
# update excavator
_id <-> group_id && unload_area_id <-> group_id && truck_id <-> group_id
try
:
for
item
in
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
group_type
=
1
)
.
all
():
...
...
@@ -142,13 +146,13 @@ class DispatchInfo:
except
Exception
as
es
:
logger
.
error
(
es
)
# update truck
->team id dict
# update truck
_id <-> match_id(excavator_id, unload_area_id)
try
:
trucks
=
cls
.
truck_group_dict
.
keys
()
for
i
in
trucks
:
trip
_excavator
=
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
truck_id
=
i
)
.
first
()
.
exactor_id
trip
_unload_area
=
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
truck_id
=
i
)
.
first
()
.
unload_area_id
cls
.
truck_
team_trip_dict
[
i
]
=
[
trip_excavator
,
trip
_unload_area
]
match
_excavator
=
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
truck_id
=
i
)
.
first
()
.
exactor_id
match
_unload_area
=
session_mysql
.
query
(
DispatchSetting
)
.
filter_by
(
truck_id
=
i
)
.
first
()
.
unload_area_id
cls
.
truck_
match_dict
[
i
]
=
[
match_excavator
,
match
_unload_area
]
except
Exception
as
es
:
logger
.
error
(
es
)
...
...
@@ -179,7 +183,7 @@ class DispatchInfo:
@author:zxtc
@desc:处理 group name
"""
# update group_id->mode_
cod
e
# update group_id->mode_
nam
e
logger
=
get_logger
(
"zxt.update_group_name"
)
cls
.
group_name
=
{}
try
:
...
...
@@ -202,16 +206,17 @@ class DispatchInfo:
try
:
groups
=
cls
.
group_excavator_dict
.
keys
()
for
item
in
groups
:
# 每个组的 excavator_id
# 每个组的 excavator_id 及对应 load_area_id
excavator_ids
=
cls
.
group_excavator_dict
[
item
]
# 每个组的load_areas
load_areas
=
[]
for
excavator_id
in
excavator_ids
:
load_areas
.
append
(
cls
.
excavator_load_dict
[
excavator_id
])
# 每个组的unload_areas
unload_areas
=
cls
.
group_unload_area_dict
[
item
]
# unload->load
路网
# unload->load
distance
unload_load_distance
=
np
.
zeros
((
len
(
unload_areas
),
len
(
load_areas
)))
for
i
in
range
(
len
(
unload_areas
)):
for
j
in
range
(
len
(
load_areas
)):
...
...
@@ -219,7 +224,7 @@ class DispatchInfo:
unload_load_distance
[
i
][
j
]
=
distance
cls
.
load_distance
[
item
]
=
unload_load_distance
# load->unload
路网
# load->unload
distance
load_unload_distance
=
np
.
zeros
((
len
(
load_areas
),
len
(
unload_areas
)))
for
i
in
range
(
len
(
load_areas
)):
for
j
in
range
(
len
(
unload_areas
)):
...
...
@@ -261,8 +266,8 @@ class DispatchInfo:
return
cls
.
unload_distance
[
group_id
]
@classmethod
def
get_truck_
team_trip
(
cls
,
truck_id
):
return
cls
.
truck_
team_trip
_dict
[
truck_id
]
def
get_truck_
match
(
cls
,
truck_id
):
return
cls
.
truck_
match
_dict
[
truck_id
]
@classmethod
...
...
realtime_dispatch.py
View file @
aed9900d
...
...
@@ -86,7 +86,7 @@ def process(dispatcher):
global_period_para_update
()
# 更新调度信息
DispatchInfo
.
re
new_
set
()
DispatchInfo
.
reset
()
DispatchInfo
.
update_device_group_structure
()
...
...
settings.py
View file @
aed9900d
...
...
@@ -60,15 +60,15 @@ def set_log():
# 创建日志目录
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
()
# 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
,
encoding
=
"utf-8"
)
#
filehandler = logging.handlers.RotatingFileHandler("./Logs/dispatch.log", maxBytes=3 * 1024 * 1024, backupCount=10, encoding="utf-8")
#
filehandler = logging.handlers.RotatingFileHandler(log_path + "/dispatch.log", maxBytes=3*1024*1024, backupCount=10, encoding="utf-8")
filehandler
=
logging
.
handlers
.
RotatingFileHandler
(
"./Logs/dispatch.log"
,
maxBytes
=
3
*
1024
*
1024
,
backupCount
=
10
,
encoding
=
"utf-8"
)
# 设置后缀名称,跟strftime的格式一样
filehandler
.
suffix
=
"
%
Y-
%
m-
%
d_
%
H-
%
M.log"
...
...
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