Commit 490c8b21 authored by 张晓彤's avatar 张晓彤

增加配置文件-设备类优化

parent 3fec3e4c
/venv/
/.idea/
/Logs/
/waytous/
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PublishConfigData">
<serverData>
<paths name="root@172.16.0.103:22">
<serverdata>
<mappings>
<mapping local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>
</serverData>
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.7 (waytous)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (waytous)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/integrated-scheduling-v3.iml" filepath="$PROJECT_DIR$/.idea/integrated-scheduling-v3.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
{
"para": {
"log_path": "/usr/local/fleet-log/dispatch",
"empty_speed": 25,
"heavy_speed": 22,
"dump_target_mass": 5000,
"excavator_target_mass": 5000
},
"mysql": {
"host": "192.168.28.111",
"port": "3306",
"user": "root",
"password": "Huituo@123",
"database": "waytous"
},
"postgresql": {
"host": "192.168.28.111",
"port": "5432",
"user": "postgres",
"password": "Huituo@123",
"database": "shenbao_2021520"
},
"redis": {
"host": "192.168.28.111",
"password": "Huituo@123"
}
}
\ No newline at end of file
...@@ -176,6 +176,6 @@ class DumpInfo(WalkManage): ...@@ -176,6 +176,6 @@ class DumpInfo(WalkManage):
# 更新设备优先级 # 更新设备优先级
self.update_dump_priority() self.update_dump_priority()
#
# 卸载目标产量 # # 卸载目标产量
self.dump_target_mass = np.full(self.dynamic_dump_num, dump_target_mass) # self.dump_target_mass = np.full(self.dynamic_dump_num, dump_target_mass)
\ No newline at end of file \ No newline at end of file
...@@ -18,7 +18,7 @@ excavator = ExcavatorInfo() ...@@ -18,7 +18,7 @@ excavator = ExcavatorInfo()
# 矿卡设备类 # 矿卡设备类
class TruckInfo(WalkManage): class TruckInfo(WalkManage):
def __init__(self): def __init__(self, dump, excavator):
# object fileds # object fileds
# self.walker = WalkManage() # self.walker = WalkManage()
# 矿卡数量 # 矿卡数量
...@@ -77,11 +77,14 @@ class TruckInfo(WalkManage): ...@@ -77,11 +77,14 @@ class TruckInfo(WalkManage):
self.period_map_para_load() self.period_map_para_load()
self.period_walk_para_load() self.period_walk_para_load()
# 初始化读取参数 # 初始化读取参数
self.para_period_update() self.para_period_update(dump, excavator)
# # 矿卡所属group # # 矿卡所属group
# self.truck_group = {} # self.truck_group = {}
# 矿卡禁用列表 # 矿卡禁用列表
self.truck_disable_list = [] self.truck_disable_list = []
# 对象域
self.dump = dump
self.excavator = excavator
def get_truck_current_trip(self): def get_truck_current_trip(self):
return self.truck_current_trip return self.truck_current_trip
...@@ -271,8 +274,8 @@ class TruckInfo(WalkManage): ...@@ -271,8 +274,8 @@ class TruckInfo(WalkManage):
item.exactor_id item.exactor_id
] ]
# 结束设备index # # 结束设备index
end_eqp_index = excavator.excavator_uuid_to_index_dict[item.exactor_id] # end_eqp_index = self.excavator_uuid_to_index_dict[item.exactor_id]
end_area_index = load_area_uuid_to_index_dict[end_area_id] end_area_index = load_area_uuid_to_index_dict[end_area_id]
self.truck_current_trip[i] = [ self.truck_current_trip[i] = [
...@@ -284,8 +287,8 @@ class TruckInfo(WalkManage): ...@@ -284,8 +287,8 @@ class TruckInfo(WalkManage):
+ walk_time_to_load_area[start_area_index][end_area_index] + walk_time_to_load_area[start_area_index][end_area_index]
) )
# 目的地矿卡数加一 # # 目的地矿卡数加一
self.excavator_hold_truck_num[end_eqp_index] = self.excavator_hold_truck_num[end_eqp_index] + 1 # self.excavator_hold_truck_num[end_eqp_index] = self.excavator_hold_truck_num[end_eqp_index] + 1
# 若矿卡状态为重载 # 若矿卡状态为重载
elif task in heavy_task_set: elif task in heavy_task_set:
# print("读取重载行程") # print("读取重载行程")
...@@ -304,8 +307,8 @@ class TruckInfo(WalkManage): ...@@ -304,8 +307,8 @@ class TruckInfo(WalkManage):
# 结束区域序号 # 结束区域序号
end_area_index = unload_area_uuid_to_index_dict[end_area_id] end_area_index = unload_area_uuid_to_index_dict[end_area_id]
# 结束设备index # # 结束设备index
end_eqp_index = dump.dump_uuid_to_index_dict[item.dump_id] # end_eqp_index = self.dump_uuid_to_index_dict[item.dump_id]
self.truck_current_trip[i] = [ self.truck_current_trip[i] = [
self.excavator_uuid_to_index_dict[item.exactor_id], self.excavator_uuid_to_index_dict[item.exactor_id],
...@@ -317,7 +320,7 @@ class TruckInfo(WalkManage): ...@@ -317,7 +320,7 @@ class TruckInfo(WalkManage):
) )
# 目的地矿卡数加一 # 目的地矿卡数加一
self.dump_hold_truck_num[end_eqp_index] = self.dump_hold_truck_num[end_eqp_index] + 1 # self.dump_hold_truck_num[end_eqp_index] = self.dump_hold_truck_num[end_eqp_index] + 1
# 其他状态,矿卡状态为-2,equipment_pair表不存在该矿卡 # 其他状态,矿卡状态为-2,equipment_pair表不存在该矿卡
else: else:
# end_eqp_index = excavator.excavator_uuid_to_index_dict[item.exactor_id] # end_eqp_index = excavator.excavator_uuid_to_index_dict[item.exactor_id]
...@@ -327,16 +330,67 @@ class TruckInfo(WalkManage): ...@@ -327,16 +330,67 @@ class TruckInfo(WalkManage):
# logger.error("矿卡行程读取异常") # logger.error("矿卡行程读取异常")
# logger.error(es) # logger.error(es)
# print("self.dump_hold_truck_num")
# print(self.dump_hold_truck_num)
#
# print("self.excavator_hold_truck_num")
# print(self.excavator_hold_truck_num)
self.truck_current_trip.flatten()
# print("当前矿卡行程:")
# print(self.truck_current_trip)
def update_eqp_hold_truck(self):
# 初始化矿卡行程, -1代表备停区
self.truck_current_trip = np.full((self.dynamic_truck_num, 2), -1)
for i in range(self.dynamic_truck_num):
try:
session_mysql.commit()
truck_id = self.truck_index_to_uuid_dict[i]
task = self.truck_current_task[self.truck_index_to_uuid_dict[i]]
item = (
session_mysql.query(EquipmentPair)
.filter_by(truck_id=truck_id, isdeleted=0)
.first()
)
if task in empty_task_set + heavy_task_set and item is None:
raise Exception(f"矿卡 {truck_id} 配对关系异常")
except Exception as es:
logger.error("配对关系异常")
logger.error(es)
continue
# try:
# 若矿卡状态为空运(含装载出场)
if task in [0, 1, 2]:
# 结束设备index
end_eqp_index = self.excavator_uuid_to_index_dict[item.exactor_id]
# 目的地矿卡数加一
self.excavator_hold_truck_num[end_eqp_index] = self.excavator_hold_truck_num[end_eqp_index] + 1
# 若矿卡状态为重载(含卸载出场)
elif task in [3, 4, 5]:
# 结束设备index
end_eqp_index = self.dump_uuid_to_index_dict[item.dump_id]
# 目的地矿卡数加一
self.dump_hold_truck_num[end_eqp_index] = self.dump_hold_truck_num[end_eqp_index] + 1
# 其他状态,矿卡状态为-2,equipment_pair表不存在该矿卡
else:
pass
# except Exception as es:
# logger.error("矿卡行程读取异常")
# logger.error(es)
print("self.dump_hold_truck_num") print("self.dump_hold_truck_num")
print(self.dump_hold_truck_num) print(self.dump_hold_truck_num)
print("self.excavator_hold_truck_num") print("self.excavator_hold_truck_num")
print(self.excavator_hold_truck_num) print(self.excavator_hold_truck_num)
self.truck_current_trip.flatten()
# print("当前矿卡行程:")
# print(self.truck_current_trip)
################################################ long term update ################################################ ################################################ long term update ################################################
# 更新矿卡实际容量 # 更新矿卡实际容量
...@@ -463,7 +517,7 @@ class TruckInfo(WalkManage): ...@@ -463,7 +517,7 @@ class TruckInfo(WalkManage):
if truck_id in self.truck_excavator_bind: if truck_id in self.truck_excavator_bind:
excavator_id = self.truck_excavator_bind[truck_id] excavator_id = self.truck_excavator_bind[truck_id]
# print(self.excavator.excavator_material) # print(self.excavator.excavator_material)
excavator_material_id = excavator.excavator_material[excavator_id] excavator_material_id = self.excavator.excavator_material[excavator_id]
self.truck_material_bind[truck_id] = excavator_material_id self.truck_material_bind[truck_id] = excavator_material_id
for truck_id in self.dynamic_truck_set: for truck_id in self.dynamic_truck_set:
...@@ -475,15 +529,15 @@ class TruckInfo(WalkManage): ...@@ -475,15 +529,15 @@ class TruckInfo(WalkManage):
material = self.truck_material_bind[truck_id] material = self.truck_material_bind[truck_id]
for excavator_id in get_value("dynamic_excavator_set"): for excavator_id in get_value("dynamic_excavator_set"):
excavator_material_id = excavator.excavator_material[excavator_id] excavator_material_id = self.excavator.excavator_material[excavator_id]
excavator_index = excavator.excavator_uuid_to_index_dict[excavator_id] excavator_index = self.excavator_uuid_to_index_dict[excavator_id]
print(truck_index, excavator_index) print(truck_index, excavator_index)
if excavator_material_id != material: if excavator_material_id != material:
self.excavator_material_bind_modify[truck_index][excavator_index] = 1000000 self.excavator_material_bind_modify[truck_index][excavator_index] = 1000000
for dump_id in get_value("dynamic_dump_set"): for dump_id in get_value("dynamic_dump_set"):
dump_material_id = dump.dump_material[dump_id] dump_material_id = self.dump.dump_material[dump_id]
dump_index = dump.dump_uuid_to_index_dict[dump_id] dump_index = self.dump_uuid_to_index_dict[dump_id]
if dump_material_id != material: if dump_material_id != material:
self.dump_material_bind_modify[truck_index][dump_index] = 1000000 self.dump_material_bind_modify[truck_index][dump_index] = 1000000
...@@ -512,7 +566,7 @@ class TruckInfo(WalkManage): ...@@ -512,7 +566,7 @@ class TruckInfo(WalkManage):
self.truck_disable_list.append(item.equipment_id) self.truck_disable_list.append(item.equipment_id)
return self.truck_disable_list return self.truck_disable_list
def reset(self): def truck_reset(self, dump, excavator):
# 更新矿卡数量 # 更新矿卡数量
self.dynamic_truck_num = get_value("dynamic_truck_num") self.dynamic_truck_num = get_value("dynamic_truck_num")
# 更新矿卡集合 # 更新矿卡集合
...@@ -541,14 +595,14 @@ class TruckInfo(WalkManage): ...@@ -541,14 +595,14 @@ class TruckInfo(WalkManage):
self.dump_hold_truck_num = np.zeros(get_value("dynamic_dump_num")) self.dump_hold_truck_num = np.zeros(get_value("dynamic_dump_num"))
# 各装载区矿卡数量 # 各装载区矿卡数量
self.excavator_hold_truck_num = np.zeros(get_value("dynamic_excavator_num")) self.excavator_hold_truck_num = np.zeros(get_value("dynamic_excavator_num"))
# 对象域更新
self.dump = dump
self.excavator = excavator
def para_period_update(self): def para_period_update(self, dump, excavator):
excavator.para_period_update()
dump.para_period_update()
# 初始化参数 # 初始化参数
self.reset() self.truck_reset(dump, excavator)
# 距离成本启动 # 距离成本启动
rule1 = session_mysql.query(DispatchRule).filter_by(id=1).first().disabled rule1 = session_mysql.query(DispatchRule).filter_by(id=1).first().disabled
...@@ -574,15 +628,6 @@ class TruckInfo(WalkManage): ...@@ -574,15 +628,6 @@ class TruckInfo(WalkManage):
self.period_walk_para_update() self.period_walk_para_update()
# # 更新全部矿卡设备集合
# truck_set = set(update_total_truck())
#
# # 更新固定派车矿卡集合
# fixed_truck_set = set(update_fixdisp_truck())
#
# # 更新动态派车矿卡集合
# self.dynamic_truck_set = truck_set.difference(fixed_truck_set)
# 更新有效载重 # 更新有效载重
self.update_truck_payload() self.update_truck_payload()
...@@ -631,5 +676,8 @@ class TruckInfo(WalkManage): ...@@ -631,5 +676,8 @@ class TruckInfo(WalkManage):
# 更新卡车当前行程 # 更新卡车当前行程
self.update_truck_trip() self.update_truck_trip()
# 更新各设备hold矿卡数量
self.update_eqp_hold_truck()
# 矿卡速度更新 # 矿卡速度更新
self.update_truck_speed() self.update_truck_speed()
...@@ -18,21 +18,21 @@ empty_task_set = [0, 1, 5] ...@@ -18,21 +18,21 @@ empty_task_set = [0, 1, 5]
# 重载任务集合 # 重载任务集合
heavy_task_set = [2, 3, 4] heavy_task_set = [2, 3, 4]
# 空载矿卡速度,单位(km/h) # # 空载矿卡速度,单位(km/h)
global empty_speed # global empty_speed
#
empty_speed = 25 # empty_speed = 25
#
# 重载矿卡速度,单位(km/h) # # 重载矿卡速度,单位(km/h)
global heavy_speed # global heavy_speed
#
heavy_speed = 22 # heavy_speed = 22
#
# 卸载设备目标卸载量 # # 卸载设备目标卸载量
dump_target_mass = 5000 # dump_target_mass = 5000
#
# 挖机目标装载量 # # 挖机目标装载量
excavator_target_mass = 5000 # excavator_target_mass = 5000
# 任务集合 # 任务集合
task_set = [-2, 0, 1, 2, 3, 4, 5] task_set = [-2, 0, 1, 2, 3, 4, 5]
......
...@@ -6,25 +6,34 @@ ...@@ -6,25 +6,34 @@
# @File : path_plannner.py # @File : path_plannner.py
# @Software: PyCharm # @Software: PyCharm
from equipment.truck import TruckInfo from equipment.truck import TruckInfo, DumpInfo, ExcavatorInfo
from path_plan.priority_control import weighted_walk_cost, available_walk, update_group_walk_available from path_plan.priority_control import PriorityController
from para_config import * from para_config import *
from tables import * from tables import *
M = 1000000 M = 1000000
truck = TruckInfo()
truck.update_truck_size()
class PathPlanner(WalkManage): class PathPlanner(WalkManage):
def __init__(self): def __init__(self):
# 路段类
self.lane = LaneInfo()
self.lane.lane_speed_generate()
# 设备类
self.dump = DumpInfo()
self.excavator = ExcavatorInfo()
self.truck = TruckInfo(self.dump, self.excavator)
self.truck.update_truck_size()
# 控制类
self.controller = PriorityController(self.dump, self.excavator, self.truck)
# 路线行驶成本 # 路线行驶成本
self.rout_cost = np.array((unload_area_num, load_area_num)) self.rout_cost = np.array((unload_area_num, load_area_num))
# 路段集合 # 路段集合
self.lane_set = {} self.lane_set = {}
# 车辆长度(暂) # 车辆长度(暂)
# self.truck_length = float(sum(truck.get_length().values())) / len(truck.get_length()) self.truck_length = float(sum(self.truck.get_length().values())) / len(self.truck.get_length())
self.truck_length = 3 self.truck_length = 3
# 装载区数量 # 装载区数量
self.num_of_load_area = len(set(update_load_area())) self.num_of_load_area = len(set(update_load_area()))
...@@ -37,9 +46,6 @@ class PathPlanner(WalkManage): ...@@ -37,9 +46,6 @@ class PathPlanner(WalkManage):
self.cost_to_unload_area = np.full((self.num_of_unload_area, self.num_of_load_area), M) self.cost_to_unload_area = np.full((self.num_of_unload_area, self.num_of_load_area), M)
# 路网信息(备停区) # 路网信息(备停区)
self.cost_park_to_load_area = np.full((self.num_of_park_area, self.num_of_load_area), M) self.cost_park_to_load_area = np.full((self.num_of_park_area, self.num_of_load_area), M)
# 路段类
self.lane = LaneInfo()
self.lane.lane_speed_generate()
def path_cost_generate(self, load_area_id, unload_area_id, is_park): def path_cost_generate(self, load_area_id, unload_area_id, is_park):
...@@ -57,7 +63,7 @@ class PathPlanner(WalkManage): ...@@ -57,7 +63,7 @@ class PathPlanner(WalkManage):
# 修正因子 # 修正因子
weight = 60 weight = 60
# 阻塞成本权重 # 阻塞成本权重
alpha = 0 alpha = 1
# 距离成本权重 # 距离成本权重
beta = 1 beta = 1
...@@ -175,12 +181,12 @@ class PathPlanner(WalkManage): ...@@ -175,12 +181,12 @@ class PathPlanner(WalkManage):
# try: # try:
# 路网权重 # 路网权重
walk_weight, park_walk_weight = weighted_walk_cost() walk_weight, park_walk_weight = self.controller.weighted_walk_cost()
# 路网禁用关系 # 路网禁用关系
walk_available = available_walk() walk_available = self.controller.available_walk()
group_walk_available = update_group_walk_available() group_walk_available = self.controller.update_group_walk_available()
logger.info("path_weight") logger.info("path_weight")
logger.info(walk_weight) logger.info(walk_weight)
......
...@@ -11,22 +11,24 @@ from equipment.dump import * ...@@ -11,22 +11,24 @@ from equipment.dump import *
from equipment.excavator import * from equipment.excavator import *
from para_config import * from para_config import *
truck = TruckInfo()
excavator = ExcavatorInfo()
dump = DumpInfo()
class PriorityController():
def weighted_walk_cost(): def __init__(self, dump, excavator, truck):
# 设备类
self.dump = dump
self.excavator = excavator
self.truck = truck
def weighted_walk_cost(self):
dynamic_dump_num = get_value("dynamic_dump_num") dynamic_dump_num = get_value("dynamic_dump_num")
dynamic_excavator_num = get_value("dynamic_excavator_num") dynamic_excavator_num = get_value("dynamic_excavator_num")
dynamic_dump_set = get_value("dynamic_dump_set") dynamic_dump_set = get_value("dynamic_dump_set")
dynamic_excavator_set = get_value("dynamic_excavator_set") dynamic_excavator_set = get_value("dynamic_excavator_set")
excavator.para_period_update()
dump.para_period_update()
walk_weight = np.ones((dynamic_dump_num, dynamic_excavator_num)) walk_weight = np.ones((dynamic_dump_num, dynamic_excavator_num))
excavator_priority = excavator.excavator_priority_coefficient excavator_priority = self.excavator.excavator_priority_coefficient
excavator_material_priority = excavator.excavator_material_priority excavator_material_priority = self.excavator.excavator_material_priority
dump_priority = dump.dump_priority_coefficient dump_priority = self.dump.dump_priority_coefficient
dump_material_priority = np.ones(dynamic_dump_num) dump_material_priority = np.ones(dynamic_dump_num)
park_walk_weight = np.ones((park_num, dynamic_excavator_num)) park_walk_weight = np.ones((park_num, dynamic_excavator_num))
...@@ -35,22 +37,22 @@ def weighted_walk_cost(): ...@@ -35,22 +37,22 @@ def weighted_walk_cost():
if not rule6.disabled: if not rule6.disabled:
for dump_id in dynamic_dump_set: for dump_id in dynamic_dump_set:
for excavator_id in dynamic_excavator_set: for excavator_id in dynamic_excavator_set:
dump_index = dump.dump_uuid_to_index_dict[dump_id] dump_index = self.dump.dump_uuid_to_index_dict[dump_id]
excavator_inedx = excavator.excavator_uuid_to_index_dict[excavator_id] excavator_inedx = self.excavator.excavator_uuid_to_index_dict[excavator_id]
walk_weight[dump_index][excavator_inedx] += dump_priority[dump_index] * \ walk_weight[dump_index][excavator_inedx] += dump_priority[dump_index] * \
excavator_priority[excavator_inedx] excavator_priority[excavator_inedx]
park_walk_weight = park_walk_weight * excavator.excavator_priority_coefficient park_walk_weight = park_walk_weight * self.excavator.excavator_priority_coefficient
rule7 = session_mysql.query(DispatchRule).filter_by(id=7).first() rule7 = session_mysql.query(DispatchRule).filter_by(id=7).first()
if not rule7.disabled: if not rule7.disabled:
for dump_id in dynamic_dump_set: for dump_id in dynamic_dump_set:
for excavator_id in dynamic_excavator_set: for excavator_id in dynamic_excavator_set:
dump_index = dump.dump_uuid_to_index_dict[dump_id] dump_index = self.dump.dump_uuid_to_index_dict[dump_id]
excavator_inedx = excavator.excavator_uuid_to_index_dict[excavator_id] excavator_inedx = self.excavator.excavator_uuid_to_index_dict[excavator_id]
walk_weight[dump_index][excavator_inedx] += dump_material_priority[dump_index] * \ walk_weight[dump_index][excavator_inedx] += dump_material_priority[dump_index] * \
excavator_material_priority[excavator_inedx] excavator_material_priority[excavator_inedx]
park_walk_weight = park_walk_weight * excavator.excavator_material_priority park_walk_weight = park_walk_weight * self.excavator.excavator_material_priority
walk_weight = walk_weight - (walk_weight.min() - 1) walk_weight = walk_weight - (walk_weight.min() - 1)
...@@ -58,35 +60,32 @@ def weighted_walk_cost(): ...@@ -58,35 +60,32 @@ def weighted_walk_cost():
return walk_weight, park_walk_weight return walk_weight, park_walk_weight
def available_walk(self):
def available_walk():
dynamic_dump_num = get_value("dynamic_dump_num") dynamic_dump_num = get_value("dynamic_dump_num")
dynamic_excavator_num = get_value("dynamic_excavator_num") dynamic_excavator_num = get_value("dynamic_excavator_num")
dynamic_dump_set = get_value("dynamic_dump_set") dynamic_dump_set = get_value("dynamic_dump_set")
dynamic_excavator_set = get_value("dynamic_excavator_set") dynamic_excavator_set = get_value("dynamic_excavator_set")
excavator.para_period_update()
dump.para_period_update()
walk_weight = np.zeros((dynamic_dump_num, dynamic_excavator_num)) walk_weight = np.zeros((dynamic_dump_num, dynamic_excavator_num))
for dump_id in dynamic_dump_set: for dump_id in dynamic_dump_set:
for excavator_id in dynamic_excavator_set: for excavator_id in dynamic_excavator_set:
dump_index = dump.dump_uuid_to_index_dict[dump_id] dump_index = self.dump.dump_uuid_to_index_dict[dump_id]
excavator_inedx = excavator.excavator_uuid_to_index_dict[excavator_id] excavator_inedx = self.excavator.excavator_uuid_to_index_dict[excavator_id]
if excavator.excavator_material[excavator_id] != dump.dump_material[dump_id]: if self.excavator.excavator_material[excavator_id] != self.dump.dump_material[dump_id]:
walk_weight[dump_index][excavator_inedx] += 1000000 walk_weight[dump_index][excavator_inedx] += 1000000
return walk_weight return walk_weight
def update_group_walk_available(self):
def update_group_walk_available():
group_walk_available = np.full((get_value("dynamic_dump_num"), get_value("dynamic_excavator_num")), 1000000) group_walk_available = np.full((get_value("dynamic_dump_num"), get_value("dynamic_excavator_num")), 1000000)
for dump_id in get_value("dynamic_dump_set"): for dump_id in get_value("dynamic_dump_set"):
for excavator_id in get_value("dynamic_excavator_set"): for excavator_id in get_value("dynamic_excavator_set"):
item = session_mysql.query(Dispatch).filter_by(dump_id=dump_id, exactor_id=excavator_id, isauto=1, isdeleted=0).first() item = session_mysql.query(Dispatch).filter_by(dump_id=dump_id, exactor_id=excavator_id, isauto=1,
isdeleted=0).first()
if item is not None: if item is not None:
dump_index = dump.dump_uuid_to_index_dict[dump_id] dump_index = self.dump.dump_uuid_to_index_dict[dump_id]
excavator_index = excavator.excavator_uuid_to_index_dict[excavator_id] excavator_index = self.excavator.excavator_uuid_to_index_dict[excavator_id]
group_walk_available[dump_index][excavator_index] = 0 group_walk_available[dump_index][excavator_index] = 0
return group_walk_available return group_walk_available
...@@ -14,10 +14,12 @@ from para_config import * ...@@ -14,10 +14,12 @@ from para_config import *
from equipment.truck import TruckInfo from equipment.truck import TruckInfo
from equipment.excavator import ExcavatorInfo from equipment.excavator import ExcavatorInfo
from equipment.dump import DumpInfo from equipment.dump import DumpInfo
import sched
import time
dump = DumpInfo() dump = DumpInfo()
excavator = ExcavatorInfo() excavator = ExcavatorInfo()
truck = TruckInfo() truck = TruckInfo(dump, excavator)
# 调度类 # 调度类
...@@ -245,6 +247,7 @@ class Dispatcher(WalkManage): ...@@ -245,6 +247,7 @@ class Dispatcher(WalkManage):
end_area_index = truck_current_trip[i][1] end_area_index = truck_current_trip[i][1]
start_area_index = truck_current_trip[i][0] start_area_index = truck_current_trip[i][0]
if task in heavy_task_set: if task in heavy_task_set:
self.goto_dump_truck_num[start_area_index][end_area_index] += 1 self.goto_dump_truck_num[start_area_index][end_area_index] += 1
self.actual_goto_dump_traffic_flow[start_area_index][end_area_index] += float(payload[i]) self.actual_goto_dump_traffic_flow[start_area_index][end_area_index] += float(payload[i])
...@@ -367,7 +370,7 @@ class Dispatcher(WalkManage): ...@@ -367,7 +370,7 @@ class Dispatcher(WalkManage):
excavator.para_period_update() excavator.para_period_update()
# 更新矿卡对象 # 更新矿卡对象
truck.para_period_update() truck.para_period_update(dump, excavator)
def state_period_update(self): def state_period_update(self):
# try: # try:
...@@ -378,7 +381,7 @@ class Dispatcher(WalkManage): ...@@ -378,7 +381,7 @@ class Dispatcher(WalkManage):
self.update_actual_traffic_flow() 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(truck)
# 矿卡抵达时间 # 矿卡抵达时间
excavator_reach_list, dump_reach_list = self.update_truck_reach_time() excavator_reach_list, dump_reach_list = self.update_truck_reach_time()
...@@ -1046,8 +1049,7 @@ class Group(WalkManage): ...@@ -1046,8 +1049,7 @@ class Group(WalkManage):
actual_goto_excavator_traffic_flow, actual_goto_dump_traffic_flow = \ actual_goto_excavator_traffic_flow, actual_goto_dump_traffic_flow = \
dispatcher.actual_goto_excavator_traffic_flow, dispatcher.actual_goto_dump_traffic_flow dispatcher.actual_goto_excavator_traffic_flow, dispatcher.actual_goto_dump_traffic_flow
opt_goto_dump_traffic_flow, opt_goto_excavator_traffic_flow = traffic_flow_plan(truck)
opt_goto_dump_traffic_flow, opt_goto_excavator_traffic_flow = traffic_flow_plan()
# try: # try:
...@@ -1281,7 +1283,7 @@ def state_process(dispatcher): ...@@ -1281,7 +1283,7 @@ def state_process(dispatcher):
# 下面三个函数保证程序定期执行,不用管他 # 下面三个函数保证程序定期执行,不用管他
def process(dispatcher): def process(dispatcher):
# try: try:
# 更新周期参数 # 更新周期参数
period_para_update() period_para_update()
if get_value("dynamic_dump_num") * get_value("dynamic_excavator_num") == 0: if get_value("dynamic_dump_num") * get_value("dynamic_excavator_num") == 0:
...@@ -1294,8 +1296,8 @@ def process(dispatcher): ...@@ -1294,8 +1296,8 @@ def process(dispatcher):
state_process(dispatcher) state_process(dispatcher)
# except Exception as es: except Exception as es:
# logger.error(es) logger.error(es)
scheduler = sched.scheduler(time.time, time.sleep) scheduler = sched.scheduler(time.time, time.sleep)
......
...@@ -18,18 +18,45 @@ import redis ...@@ -18,18 +18,45 @@ import redis
from datetime import datetime, timedelta from datetime import datetime, timedelta
import copy import copy
import json import json
import sched
import time json_file = "config.json"
with open(json_file) as f:
para_config = json.load(f)["para"]
with open(json_file) as f:
mysql_config = json.load(f)["mysql"]
with open(json_file) as f:
postgre_config = json.load(f)["postgresql"]
with open(json_file) as f:
redis_config = json.load(f)["redis"]
# 全局参数
########################################################################################################################
# 空载矿卡速度,单位(km/h)
empty_speed = para_config["empty_speed"]
# 重载矿卡速度,单位(km/h)
heavy_speed = para_config["heavy_speed"]
# 卸载设备目标卸载量
dump_target_mass = para_config["dump_target_mass"]
# 挖机目标装载量
excavator_target_mass = para_config["excavator_target_mass"]
# 创建日志 # 创建日志
######################################################################################################################## ########################################################################################################################
# 日志存储地址 # 日志存储地址
log_path = "/usr/local/fleet-log/dispatch" log_path = para_config["log_path"]
# 创建日志目录 # 创建日志目录
if not os.path.exists(log_path): # if not os.path.exists(log_path):
os.mkdir(log_path) # os.mkdir(log_path)
# logging初始化工作 # logging初始化工作
logging.basicConfig() logging.basicConfig()
...@@ -38,8 +65,8 @@ logger.setLevel(logging.INFO) ...@@ -38,8 +65,8 @@ logger.setLevel(logging.INFO)
# timefilehandler = logging.handlers.TimedRotatingFileHandler(log_path + "/dispatch.log", when='M', interval=1, backupCount=60) # 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(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("./Logs/dispatch.log", maxBytes=3 * 1024 * 1024, backupCount=10)
# 设置后缀名称,跟strftime的格式一样 # 设置后缀名称,跟strftime的格式一样
filehandler.suffix = "%Y-%m-%d_%H-%M.log" filehandler.suffix = "%Y-%m-%d_%H-%M.log"
...@@ -51,12 +78,12 @@ logger.addHandler(filehandler) ...@@ -51,12 +78,12 @@ logger.addHandler(filehandler)
# 连接reids # 连接reids
######################################################################################################################## ########################################################################################################################
# redis 5 存储设备状态 # redis 5 存储设备状态
pool5 = ConnectionPool(host="192.168.28.111", db=5, port=6379, password="Huituo@123") pool5 = ConnectionPool(host=redis_config["host"], db=5, port=6379, password=redis_config["password"])
redis5 = StrictRedis(connection_pool=pool5) redis5 = StrictRedis(connection_pool=pool5)
# redis 2 存储派车计划 # redis 2 存储派车计划
pool2 = ConnectionPool(host="192.168.28.111", db=2, port=6379, password="Huituo@123") pool2 = ConnectionPool(host=redis_config["host"], db=2, port=6379, password=redis_config["password"])
redis2 = StrictRedis(connection_pool=pool2) redis2 = StrictRedis(connection_pool=pool2)
...@@ -67,13 +94,17 @@ Base = declarative_base() ...@@ -67,13 +94,17 @@ Base = declarative_base()
try: try:
engine_mysql = create_engine( engine_mysql = create_engine(
"mysql+mysqlconnector://root:%s@192.168.28.111:3306/waytous" # "mysql+mysqlconnector://root:%s@192.168.28.111:3306/waytous"
% quote("Huituo@123") # % quote("Huituo@123")
"mysql+mysqlconnector://" + mysql_config["user"] + ":" + mysql_config["password"] + "@" + mysql_config[
"host"] + ":" + mysql_config["port"] + "/" + mysql_config["database"]
) )
engine_postgre = create_engine( engine_postgre = create_engine(
"postgresql://postgres:%s@192.168.28.111:5432/shenbao_2021520" # "postgresql://postgres:%s@192.168.28.111:5432/shenbao_2021520"
% quote("Huituo@123") # % quote("Huituo@123")
"postgresql://" + postgre_config["user"] + ":" + postgre_config["password"] + "@" + postgre_config[
"host"] + ":" + postgre_config["port"] + "/" + postgre_config["database"]
) )
# 创建DBsession_mysql类型: # 创建DBsession_mysql类型:
......
...@@ -13,13 +13,9 @@ from equipment.excavator import ExcavatorInfo ...@@ -13,13 +13,9 @@ from equipment.excavator import ExcavatorInfo
from equipment.dump import DumpInfo from equipment.dump import DumpInfo
from equipment.truck import TruckInfo from equipment.truck import TruckInfo
truck = TruckInfo()
excavator = ExcavatorInfo()
dump = DumpInfo()
# 车流规划类 # 车流规划类
class Traffic_para(WalkManage): class Traffic_para(WalkManage):
def __init__(self, num_of_load_area, num_of_unload_area, num_of_excavator, num_of_dump): def __init__(self, num_of_load_area, num_of_unload_area, num_of_excavator, num_of_dump, truck):
self.num_of_dump = num_of_dump self.num_of_dump = num_of_dump
self.num_of_excavator = num_of_excavator self.num_of_excavator = num_of_excavator
self.num_of_load_area = num_of_load_area self.num_of_load_area = num_of_load_area
...@@ -161,11 +157,11 @@ class Traffic_para(WalkManage): ...@@ -161,11 +157,11 @@ class Traffic_para(WalkManage):
# 初始化车流规划类 # 初始化车流规划类
def Traffic_para_init(num_of_load_area, num_of_unload_area, num_of_excavator, num_of_dump): def Traffic_para_init(num_of_load_area, num_of_unload_area, num_of_excavator, num_of_dump, truck):
# try: # try:
tra_para = Traffic_para(num_of_load_area, num_of_unload_area, num_of_excavator, num_of_dump) tra_para = Traffic_para(num_of_load_area, num_of_unload_area, num_of_excavator, num_of_dump, truck)
tra_para.period_map_para_load() tra_para.period_map_para_load()
...@@ -177,10 +173,6 @@ def Traffic_para_init(num_of_load_area, num_of_unload_area, num_of_excavator, nu ...@@ -177,10 +173,6 @@ def Traffic_para_init(num_of_load_area, num_of_unload_area, num_of_excavator, nu
tra_para.extract_walk_time_info() tra_para.extract_walk_time_info()
# 矿卡参数更新
truck.para_period_update()
truck.state_period_update()
truck.update_truck_payload() truck.update_truck_payload()
tra_para.payload = np.mean(truck.get_payload()) tra_para.payload = np.mean(truck.get_payload())
......
...@@ -136,7 +136,7 @@ def transportation_problem_slove(coefficient_goto_dump, coefficient_goto_excavat ...@@ -136,7 +136,7 @@ def transportation_problem_slove(coefficient_goto_dump, coefficient_goto_excavat
'var_y': [[pulp.value(var_y[i][j]) for j in range(row)] for i in range(col)]} 'var_y': [[pulp.value(var_y[i][j]) for j in range(row)] for i in range(col)]}
def traffic_flow_plan(): def traffic_flow_plan(truck):
excavator_list = update_autodisp_excavator() excavator_list = update_autodisp_excavator()
dump_list = update_autodisp_dump() dump_list = update_autodisp_dump()
...@@ -168,7 +168,7 @@ def traffic_flow_plan(): ...@@ -168,7 +168,7 @@ def traffic_flow_plan():
# if (load_area_num * unload_area_num * excavator_num * dump_num == 0): # if (load_area_num * unload_area_num * excavator_num * dump_num == 0):
# raise Exception("无派车计划可用") # raise Exception("无派车计划可用")
# 初始化参量 # 初始化参量
traffic_programme_para = Traffic_para_init(load_area_num, unload_area_num, excavator_num, dump_num) traffic_programme_para = Traffic_para_init(load_area_num, unload_area_num, excavator_num, dump_num, truck)
# traffic_programme_para = traffic_programme_para_init(load_area_num, unload_area_num, excavator_num, dump_num) # traffic_programme_para = traffic_programme_para_init(load_area_num, unload_area_num, excavator_num, dump_num)
# 系统是否以最大化产量为目标 # 系统是否以最大化产量为目标
max_unload_weigh_alg_flag = True max_unload_weigh_alg_flag = True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment