Commit 72b40647 authored by 张晓彤's avatar 张晓彤

实时调度优化

parent 93d0a611
...@@ -5,8 +5,17 @@ from equipment.truck import TruckInfo ...@@ -5,8 +5,17 @@ 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
from dispatcher import Dispatcher, PreSchedule, DispatchSubmission from dispatcher import Dispatcher, PreSchedule, DispatchSubmission
from flask_caching import Cache
config = {
"DEBUG": True, # some Flask specific configs
"CACHE_TYPE": "SimpleCache", # Flask-Caching related configs
"CACHE_DEFAULT_TIMEOUT": 300
}
app = Flask(__name__) app = Flask(__name__)
app.config.from_mapping(config)
cache = Cache(app)
@app.route("/dispatch", methods=["POST"]) @app.route("/dispatch", methods=["POST"])
...@@ -26,38 +35,52 @@ def dispatch_request(): ...@@ -26,38 +35,52 @@ def dispatch_request():
# 获取日志器 # 获取日志器
logger = get_logger("zxt.request") logger = get_logger("zxt.request")
# 清空数据库缓存 try:
session_mysql.commit()
session_mysql.flush() # 清空数据库缓存
session_mysql.commit()
session_mysql.flush()
# 清空数据库缓存
session_postgre.commit()
session_postgre.flush()
except Exception as es:
logger.error("数据库访问异常")
logger.error(es)
return jsonify(msg="未知异常, 请联系管理员", code=506)
# 清空数据库缓存 try:
session_postgre.commit()
session_postgre.flush()
# 全局参数更新 # 全局参数更新
global_period_para_update() global_period_para_update()
# get_global_para_from_cache(cache)
# 实例化设备对象 # 实例化设备对象
dump = DumpInfo() dump = DumpInfo()
excavator = ExcavatorInfo() excavator = ExcavatorInfo()
truck = TruckInfo(dump, excavator) truck = TruckInfo(dump, excavator)
# 实例化调度预测器 # 实例化调度预测器
pre_sch = PreSchedule(truck, excavator, dump) pre_sch = PreSchedule(truck, excavator, dump)
# 实例化矿卡调度器 # 实例化矿卡调度器
dispatcher = Dispatcher(dump, excavator, truck, pre_sch, True) dispatcher = Dispatcher(dump, excavator, truck, pre_sch, True)
# 周期更新 # 周期更新
dispatcher.dispatcher_period_update() dispatcher.dispatcher_period_update()
except Exception as es:
logger.error("参数更新异常")
logger.error(es)
session_mysql.rollback()
session_postgre.rollback()
return jsonify(msg="未知异常, 请联系管理员", code=505)
request_trucks = [] request_trucks = []
try: try:
request_trucks = dispatcher.group.group_dispatch_truck[group_id] request_trucks = dispatcher.group.group_dispatch_truck[group_id]
except Exception as es: except Exception as es:
logger.error(es) logger.error(es)
return jsonify(msg="派车计划生成失败", detail="调度分组异常", code=1005) return jsonify(msg="未知异常, 请联系管理员", code=504)
try: try:
# 更新周期参数 # 更新周期参数
...@@ -65,10 +88,10 @@ def dispatch_request(): ...@@ -65,10 +88,10 @@ def dispatch_request():
if get_value("dynamic_dump_num") * get_value("dynamic_excavator_num") == 0: if get_value("dynamic_dump_num") * get_value("dynamic_excavator_num") == 0:
# raise Exception("无动态派车计划可用") # raise Exception("无动态派车计划可用")
return jsonify(msg="派车计划生成失败", detail="无动态派车计划可用", code=1003) return jsonify(msg="未知异常, 请联系管理员", code=503)
if get_value("dynamic_truck_num") == 0: if get_value("dynamic_truck_num") == 0:
# raise Exception("无动态派车可用矿卡") # raise Exception("无动态派车可用矿卡")
return jsonify(msg="派车计划生成失败", detail="无动态派车可用矿卡", code=1004) return jsonify(msg="未知异常, 请联系管理员", code=502)
# 更新请调矿卡派车计划 # 更新请调矿卡派车计划
for truck_id in request_trucks: for truck_id in request_trucks:
...@@ -80,11 +103,17 @@ def dispatch_request(): ...@@ -80,11 +103,17 @@ def dispatch_request():
except Exception as es: except Exception as es:
logger.error("最外层异常捕获") logger.error("最外层异常捕获")
logger.error(es) logger.error(es)
return jsonify(msg="派车计划生成失败", detail="未知异常", code=1002) return jsonify(msg="未知异常, 请联系管理员", code=501)
# DBsession_postgre.close_all()
# DBsession_mysql.close_all()
session_mysql.close()
session_postgre.close()
# 调度结束时间 # 调度结束时间
rtd_end_time = datetime.now() rtd_end_time = datetime.now()
print(f'调度时耗 {rtd_end_time - rtd_start_time}') print(f'调度时耗 {rtd_end_time - rtd_start_time}')
return jsonify(msg="派车计划生成成功", code=1001) return jsonify(msg="success", code=0)
\ No newline at end of file \ No newline at end of file
...@@ -131,9 +131,17 @@ class Dispatcher(WalkManage): ...@@ -131,9 +131,17 @@ class Dispatcher(WalkManage):
""" """
# 规则读取 # 规则读取
rule3 = session_mysql.query(DispatchRule).filter_by(id=3).first().disabled try:
rule3 = session_mysql.query(DispatchRule).filter_by(id=3).first().disabled
rule4 = session_mysql.query(DispatchRule).filter_by(id=4).first().disabled
rule4 = session_mysql.query(DispatchRule).filter_by(id=4).first().disabled except Exception as es:
self.logger.error(es)
self.logger.error("调度规则读取异常")
session_postgre.rollback()
session_postgre.rollback()
try: try:
...@@ -673,7 +681,7 @@ class DispatchSubmission: ...@@ -673,7 +681,7 @@ class DispatchSubmission:
self.logger.error(f"调度结果:{Seq}") self.logger.error(f"调度结果:{Seq}")
self.logger.error(es) self.logger.error(es)
for i in range(dynamic_truck_num): for i in range(get_value("dynamic_truck_num")):
print("dispatch_setting:") print("dispatch_setting:")
print(redis5.get(self.truck.truck_index_to_uuid_dict[i])) print(redis5.get(self.truck.truck_index_to_uuid_dict[i]))
# except Exception as es: # except Exception as es:
......
...@@ -124,8 +124,11 @@ class DumpInfo(WalkManage): ...@@ -124,8 +124,11 @@ class DumpInfo(WalkManage):
except Exception as es: except Exception as es:
self.logger.error("卸点物料更新异常") self.logger.error("卸点物料更新异常")
self.logger.error(es) self.logger.error(es)
session_mysql.rollback()
session_postgre.rollback()
def update_dump_priority(self): def update_dump_priority(self):
unload_area_index_to_uuid_dict = get_value("unload_area_index_to_uuid_dict")
self.dump_priority_coefficient = np.ones(self.dynamic_dump_num) self.dump_priority_coefficient = np.ones(self.dynamic_dump_num)
for dump_id in self.dynamic_dump_set: for dump_id in self.dynamic_dump_set:
try: try:
...@@ -140,15 +143,27 @@ class DumpInfo(WalkManage): ...@@ -140,15 +143,27 @@ class DumpInfo(WalkManage):
except Exception as es: except Exception as es:
self.logger.error("卸点优先级更新异常") self.logger.error("卸点优先级更新异常")
self.logger.error(es) self.logger.error(es)
session_postgre.rollback()
def update_unload_ability(self): def update_unload_ability(self):
unload_area_index_to_uuid_dict = get_value("unload_area_index_to_uuid_dict")
try: try:
rule3 = session_mysql.query(DispatchRule).filter_by(id=3).first() try:
rule3 = session_mysql.query(DispatchRule).filter_by(id=3).first()
except Exception as es:
self.logger.error(es)
session_mysql.rollback()
session_postgre.rollback()
if not rule3.disabled: if not rule3.disabled:
for dump_index in range(self.dynamic_dump_num): for dump_index in range(self.dynamic_dump_num):
unload_area_id = unload_area_index_to_uuid_dict[self.dump_index_to_unload_area_index_dict[dump_index]] unload_area_id = unload_area_index_to_uuid_dict[self.dump_index_to_unload_area_index_dict[dump_index]]
unload_ability = session_postgre.query(DumpArea).filter_by(Id=unload_area_id).first().UnloadAbililty try:
unload_ability = session_postgre.query(DumpArea).filter_by(Id=unload_area_id).first().UnloadAbililty
except Exception as es:
self.logger.error(es)
session_mysql.rollback()
session_postgre.rollback()
self.dump_strength[dump_index] = unload_ability # 卸载设备最大卸载能力,单位吨/小时 self.dump_strength[dump_index] = unload_ability # 卸载设备最大卸载能力,单位吨/小时
if unload_ability < 200: if unload_ability < 200:
......
...@@ -136,6 +136,8 @@ class ExcavatorInfo(WalkManage): ...@@ -136,6 +136,8 @@ class ExcavatorInfo(WalkManage):
self.excavator_material[excavator_id] = excavator_material_id self.excavator_material[excavator_id] = excavator_material_id
except Exception as es: except Exception as es:
self.logger.warning(es) self.logger.warning(es)
session_postgre.rollback()
session_postgre.rollback()
def update_excavator_priority(self): def update_excavator_priority(self):
...@@ -143,38 +145,51 @@ class ExcavatorInfo(WalkManage): ...@@ -143,38 +145,51 @@ class ExcavatorInfo(WalkManage):
self.logger.info(self.dynamic_excavator_set) self.logger.info(self.dynamic_excavator_set)
for excavator_id in get_value("dynamic_excavator_set"): for excavator_id in get_value("dynamic_excavator_set"):
item = session_mysql.query(Equipment).filter_by(id=excavator_id).first() try:
self.logger.info("excavator_priority_coefficient") item = session_mysql.query(Equipment).filter_by(id=excavator_id).first()
self.logger.info(self.excavator_priority_coefficient) self.logger.info("excavator_priority_coefficient")
self.excavator_priority_coefficient[self.excavator_uuid_to_index_dict[excavator_id]] = item.priority + 1 self.logger.info(self.excavator_priority_coefficient)
self.excavator_priority_coefficient[self.excavator_uuid_to_index_dict[excavator_id]] = item.priority + 1
# 物料优先级控制
rule = 2 # 物料优先级控制
rule7 = session_mysql.query(DispatchRule).filter_by(id=7).first() rule = 2
rule7 = session_mysql.query(DispatchRule).filter_by(id=7).first()
material_priority_use = rule7.disabled
if material_priority_use == 0: material_priority_use = rule7.disabled
rule = rule7.rule_weight if material_priority_use == 0:
rule = rule7.rule_weight
if rule == 3:
if self.excavator_material[excavator_id] == 'e56eb559-a746-4cc4-8ada-ebf9819fbe27': if rule == 3:
self.excavator_material_priority[self.excavator_uuid_to_index_dict[excavator_id]] = 5 if self.excavator_material[excavator_id] == 'e56eb559-a746-4cc4-8ada-ebf9819fbe27':
elif rule == 1: self.excavator_material_priority[self.excavator_uuid_to_index_dict[excavator_id]] = 5
if self.excavator_material[excavator_id] == '81bb175d-50fe-4be3-937e-6791ac4d6fec': elif rule == 1:
self.excavator_material_priority[self.excavator_uuid_to_index_dict[excavator_id]] = 5 if self.excavator_material[excavator_id] == '81bb175d-50fe-4be3-937e-6791ac4d6fec':
self.excavator_material_priority[self.excavator_uuid_to_index_dict[excavator_id]] = 5
except Exception as es:
self.logger.error("物料更新异常")
self.logger.error(es)
session_postgre.rollback()
session_postgre.rollback()
def update_mining_ability(self): def update_mining_ability(self):
try: try:
rule4 = session_mysql.query(DispatchRule).filter_by(id=4).first() try:
rule4 = session_mysql.query(DispatchRule).filter_by(id=4).first()
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
if not rule4.disabled: if not rule4.disabled:
for excavator_index in range(len(self.excavator_index_to_uuid_dict)): for excavator_index in range(len(self.excavator_index_to_uuid_dict)):
load_ability = session_mysql.query(EquipmentSpec.mining_abililty).\ try:
join(Equipment, Equipment.equipment_spec == EquipmentSpec.id).\ load_ability = session_mysql.query(EquipmentSpec.mining_abililty).\
filter(Equipment.id == self.excavator_index_to_uuid_dict[excavator_index]).first() join(Equipment, Equipment.equipment_spec == EquipmentSpec.id).\
self.excavator_strength[excavator_index] = load_ability.mining_abililty filter(Equipment.id == self.excavator_index_to_uuid_dict[excavator_index]).first()
self.excavator_strength[excavator_index] = load_ability.mining_abililty
# if load_ability.mining_abililty < 200:
# raise Exception("挖机装载能力异常") # if load_ability.mining_abililty < 200:
# raise Exception("挖机装载能力异常")
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
else: else:
self.excavator_strength = np.full(self.dynamic_excavator_num, 5000) self.excavator_strength = np.full(self.dynamic_excavator_num, 5000)
...@@ -209,7 +224,11 @@ class ExcavatorInfo(WalkManage): ...@@ -209,7 +224,11 @@ class ExcavatorInfo(WalkManage):
self.logger.info("Excavator update!") self.logger.info("Excavator update!")
rule7 = session_mysql.query(DispatchRule).filter_by(id=7).first().disabled try:
rule7 = session_mysql.query(DispatchRule).filter_by(id=7).first().disabled
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
self.logger.info("物料优先级规则") self.logger.info("物料优先级规则")
self.logger.info(rule7) self.logger.info(rule7)
......
This diff is collapsed.
...@@ -70,7 +70,12 @@ class Group(WalkManage): ...@@ -70,7 +70,12 @@ class Group(WalkManage):
# 动态派车数量没变,但是此时某条派车计划被删除,dispatch_truck_group 就会缺失矿卡 # 动态派车数量没变,但是此时某条派车计划被删除,dispatch_truck_group 就会缺失矿卡
for truck_id in dynamic_truck_set: for truck_id in dynamic_truck_set:
item = session_mysql.query(Dispatch).filter_by(truck_id=truck_id, isauto=1, isdeleted=0).first() try:
item = session_mysql.query(Dispatch).filter_by(truck_id=truck_id, isauto=1, isdeleted=0).first()
except Exception as es:
self.logger.error(es)
session_postgre.rollback()
session_postgre.rollback()
if item is None: if item is None:
print(truck_id) print(truck_id)
continue continue
...@@ -90,9 +95,13 @@ class Group(WalkManage): ...@@ -90,9 +95,13 @@ class Group(WalkManage):
""" """
# 更新调度组 # 更新调度组
self.group_set = set() self.group_set = set()
for item in session_mysql.query(Dispatch).filter_by(isauto=1, isdeleted=0).all(): try:
if item.group_id is not None: for item in session_mysql.query(Dispatch).filter_by(isauto=1, isdeleted=0).all():
self.group_set.add(item.group_id) if item.group_id is not None:
self.group_set.add(item.group_id)
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
self.group_num = len(self.group_set) self.group_num = len(self.group_set)
def update_device_group(self): def update_device_group(self):
...@@ -106,9 +115,13 @@ class Group(WalkManage): ...@@ -106,9 +115,13 @@ class Group(WalkManage):
self.device_group[group_id] = [set(), set()] self.device_group[group_id] = [set(), set()]
else: else:
continue continue
for item in session_mysql.query(Dispatch).filter_by(group_id=group_id, isauto=1, isdeleted=0).all(): try:
self.device_group[group_id][0].add(item.dump_id) for item in session_mysql.query(Dispatch).filter_by(group_id=group_id, isauto=1, isdeleted=0).all():
self.device_group[group_id][1].add(item.exactor_id) self.device_group[group_id][0].add(item.dump_id)
self.device_group[group_id][1].add(item.exactor_id)
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
def update_actual_traffic_flow(self): def update_actual_traffic_flow(self):
""" """
...@@ -232,6 +245,7 @@ class Group(WalkManage): ...@@ -232,6 +245,7 @@ class Group(WalkManage):
""" """
walk_to_excavator_cost, walk_to_dump_cost, park_to_excavator_cost = self.path.walk_cost_cal() walk_to_excavator_cost, walk_to_dump_cost, park_to_excavator_cost = self.path.walk_cost_cal()
park_num = get_value("park_num")
try: try:
......
This diff is collapsed.
...@@ -200,6 +200,9 @@ class PathPlanner(WalkManage): ...@@ -200,6 +200,9 @@ class PathPlanner(WalkManage):
self.lane.lane_speed_generate() self.lane.lane_speed_generate()
try: try:
unload_area_uuid_to_index_dict = get_value("unload_area_uuid_to_index_dict")
load_area_uuid_to_index_dict = get_value("load_area_uuid_to_index_dict")
park_uuid_to_index_dict = get_value(" park_uuid_to_index_dict")
# 读取路网成本 # 读取路网成本
for walk_time in session_postgre.query(WalkTime).all(): for walk_time in session_postgre.query(WalkTime).all():
load_area_id, unload_area_id = str(walk_time.load_area_id), str(walk_time.unload_area_id) load_area_id, unload_area_id = str(walk_time.load_area_id), str(walk_time.unload_area_id)
......
...@@ -32,7 +32,7 @@ class PathPlanner(WalkManage): ...@@ -32,7 +32,7 @@ class PathPlanner(WalkManage):
self.controller = PriorityController(self.dump, self.excavator, self.truck) 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((get_value("unload_area_num"), get_value("load_area_num")))
# 路段集合 # 路段集合
self.lane_set = {} self.lane_set = {}
# 车辆长度(暂) # 车辆长度(暂)
...@@ -87,9 +87,12 @@ class PathPlanner(WalkManage): ...@@ -87,9 +87,12 @@ class PathPlanner(WalkManage):
# 备停区处理 # 备停区处理
if is_park: if is_park:
# 提取指定道路记录 # 提取指定道路记录
path = session_postgre.query(WalkTimePark).filter_by(park_area_id=unload_area_id, try:
path = session_postgre.query(WalkTimePark).filter_by(park_area_id=unload_area_id,
load_area_id=load_area_id).first() load_area_id=load_area_id).first()
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
# 读取道路路段信息 # 读取道路路段信息
for lane_id in path.park_load_lanes: for lane_id in path.park_load_lanes:
if lane_id in self.lane.used_lane_set: if lane_id in self.lane.used_lane_set:
...@@ -104,9 +107,12 @@ class PathPlanner(WalkManage): ...@@ -104,9 +107,12 @@ class PathPlanner(WalkManage):
to_load_cost = alpha * cost_to_load_blockage + beta * path.park_load_distance to_load_cost = alpha * cost_to_load_blockage + beta * path.park_load_distance
else: else:
path = session_postgre.query(WalkTime).filter_by(load_area_id=load_area_id, try:
unload_area_id=unload_area_id).first() path = session_postgre.query(WalkTime).filter_by(load_area_id=load_area_id,
unload_area_id=unload_area_id).first()
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
for lane_id in path.to_unload_lanes: for lane_id in path.to_unload_lanes:
if lane_id in self.lane.used_lane_set: if lane_id in self.lane.used_lane_set:
if lane_id in lane_cost_memory: if lane_id in lane_cost_memory:
...@@ -146,7 +152,11 @@ class PathPlanner(WalkManage): ...@@ -146,7 +152,11 @@ class PathPlanner(WalkManage):
lane_blockage = 0 # 路段拥堵度默认为0 lane_blockage = 0 # 路段拥堵度默认为0
try: try:
lane_rec = session_postgre.query(Lane).filter_by(Id=lane_id).first() # 读取路段记录 try:
lane_rec = session_postgre.query(Lane).filter_by(Id=lane_id).first() # 读取路段记录
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
lane_length = lane_rec.Length # 道路长度 lane_length = lane_rec.Length # 道路长度
...@@ -180,37 +190,56 @@ class PathPlanner(WalkManage): ...@@ -180,37 +190,56 @@ class PathPlanner(WalkManage):
lane_cost_memory = {} # 路段拥堵度列表, 记忆化搜索 lane_cost_memory = {} # 路段拥堵度列表, 记忆化搜索
# 距离成本启用 # 距离成本启用
rule1 = session_mysql.query(DispatchRule).filter_by(id=1).first() try:
rule1 = session_mysql.query(DispatchRule).filter_by(id=1).first()
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
if rule1.disabled == 0: if rule1.disabled == 0:
beta = rule1.rule_weight beta = rule1.rule_weight
# 拥堵成本启用 # 拥堵成本启用
rule2 = session_mysql.query(DispatchRule).filter_by(id=2).first() try:
rule2 = session_mysql.query(DispatchRule).filter_by(id=2).first()
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
if rule2.disabled == 0: if rule2.disabled == 0:
alpha = rule2.rule_weight alpha = rule2.rule_weight
try: try:
unload_area_uuid_to_index_dict = get_value("unload_area_uuid_to_index_dict")
load_area_uuid_to_index_dict = get_value("load_area_uuid_to_index_dict")
park_uuid_to_index_dict = get_value("park_uuid_to_index_dict")
# 读取路网成本 # 读取路网成本
for walk_time in session_postgre.query(WalkTime).all(): try:
load_area_id, unload_area_id = str(walk_time.load_area_id), str(walk_time.unload_area_id) for walk_time in session_postgre.query(WalkTime).all():
unload_area_index = unload_area_uuid_to_index_dict[unload_area_id] load_area_id, unload_area_id = str(walk_time.load_area_id), str(walk_time.unload_area_id)
load_area_index = load_area_uuid_to_index_dict[load_area_id] unload_area_index = unload_area_uuid_to_index_dict[unload_area_id]
self.cost_to_load_area[unload_area_index][load_area_index], \ load_area_index = load_area_uuid_to_index_dict[load_area_id]
self.cost_to_unload_area[unload_area_index][load_area_index] = \ self.cost_to_load_area[unload_area_index][load_area_index], \
self.path_cost_generate(load_area_id, unload_area_id, False, lane_cost_memory, alpha, beta) self.cost_to_unload_area[unload_area_index][load_area_index] = \
# self.cost_to_load_area[unload_area_index][load_area_index] = \ self.path_cost_generate(load_area_id, unload_area_id, False, lane_cost_memory, alpha, beta)
# WalkManage.distance_to_load_area[unload_area_index][load_area_index] # self.cost_to_load_area[unload_area_index][load_area_index] = \
# self.cost_to_unload_area[unload_area_index][load_area_index] = \ # WalkManage.distance_to_load_area[unload_area_index][load_area_index]
# WalkManage.distance_to_unload_area[unload_area_index][load_area_index] # self.cost_to_unload_area[unload_area_index][load_area_index] = \
# WalkManage.distance_to_unload_area[unload_area_index][load_area_index]
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
# 读取备停区路网成本 # 读取备停区路网成本
for walk_time_park in session_postgre.query(WalkTimePark).all(): try:
park_area_index = park_uuid_to_index_dict[str(walk_time_park.park_area_id)] for walk_time_park in session_postgre.query(WalkTimePark).all():
load_area_index = load_area_uuid_to_index_dict[str(walk_time_park.load_area_id)] park_area_index = park_uuid_to_index_dict[str(walk_time_park.park_area_id)]
self.cost_park_to_load_area[park_area_index][load_area_index], _ = \ load_area_index = load_area_uuid_to_index_dict[str(walk_time_park.load_area_id)]
self.path_cost_generate(str(walk_time_park.load_area_id), str(walk_time_park.park_area_id), True, lane_cost_memory, alpha, beta) self.cost_park_to_load_area[park_area_index][load_area_index], _ = \
# self.cost_park_to_load_area[park_area_index][load_area_index] = \ self.path_cost_generate(str(walk_time_park.load_area_id), str(walk_time_park.park_area_id), True, lane_cost_memory, alpha, beta)
# WalkManage.distance_park_to_load_area[park_area_index][load_area_index] # self.cost_park_to_load_area[park_area_index][load_area_index] = \
# WalkManage.distance_park_to_load_area[park_area_index][load_area_index]
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
logger.info(self.cost_park_to_load_area) logger.info(self.cost_park_to_load_area)
logger.info(self.distance_park_to_excavator) logger.info(self.distance_park_to_excavator)
...@@ -297,6 +326,7 @@ class LaneInfo: ...@@ -297,6 +326,7 @@ class LaneInfo:
truck_speed_dict = {} truck_speed_dict = {}
try: try:
truck_name_to_uuid_dict = get_value("truck_name_to_uuid_dict")
device_name_set = redis2.keys() device_name_set = redis2.keys()
for item in device_name_set: for item in device_name_set:
item = item.decode(encoding='utf-8') item = item.decode(encoding='utf-8')
...@@ -317,6 +347,8 @@ class LaneInfo: ...@@ -317,6 +347,8 @@ class LaneInfo:
:return: :return:
truck_locate_dict: (Dict{key:truck_id, value:lane_id}) 矿卡所在路段表 truck_locate_dict: (Dict{key:truck_id, value:lane_id}) 矿卡所在路段表
""" """
truck_name_to_uuid_dict = get_value("truck_name_to_uuid_dict")
self.used_lane_set = [] self.used_lane_set = []
# try: # try:
truck_locate_dict = {} truck_locate_dict = {}
......
...@@ -31,6 +31,7 @@ class PriorityController: ...@@ -31,6 +31,7 @@ class PriorityController:
walk_weight: 卸载-装载区 路网权重 walk_weight: 卸载-装载区 路网权重
park_walk_weight: 备停区-装载区 路网权重 park_walk_weight: 备停区-装载区 路网权重
""" """
park_num = get_value("park_num")
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")
...@@ -43,7 +44,11 @@ class PriorityController: ...@@ -43,7 +44,11 @@ class PriorityController:
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))
rule6 = session_mysql.query(DispatchRule).filter_by(id=6).first() try:
rule6 = session_mysql.query(DispatchRule).filter_by(id=6).first()
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
if not rule6.disabled: if not rule6.disabled:
for dump_id in dynamic_dump_set: for dump_id in dynamic_dump_set:
...@@ -54,7 +59,11 @@ class PriorityController: ...@@ -54,7 +59,11 @@ class PriorityController:
walk_to_dump_weight[excavator_inedx][dump_index] += dump_priority[dump_index] walk_to_dump_weight[excavator_inedx][dump_index] += dump_priority[dump_index]
park_walk_weight = park_walk_weight * self.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() try:
rule7 = session_mysql.query(DispatchRule).filter_by(id=7).first()
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
if not rule7.disabled: if not rule7.disabled:
for dump_id in dynamic_dump_set: for dump_id in dynamic_dump_set:
...@@ -102,8 +111,12 @@ class PriorityController: ...@@ -102,8 +111,12 @@ class PriorityController:
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, try:
item = session_mysql.query(Dispatch).filter_by(dump_id=dump_id, exactor_id=excavator_id, isauto=1,
isdeleted=0).first() isdeleted=0).first()
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
if item is not None: if item is not None:
dump_index = self.dump.dump_uuid_to_index_dict[dump_id] dump_index = self.dump.dump_uuid_to_index_dict[dump_id]
excavator_index = self.excavator.excavator_uuid_to_index_dict[excavator_id] excavator_index = self.excavator.excavator_uuid_to_index_dict[excavator_id]
......
...@@ -67,8 +67,8 @@ def set_log(): ...@@ -67,8 +67,8 @@ def set_log():
# 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, encoding="utf-8")
# 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, encoding="utf-8")
# 设置后缀名称,跟strftime的格式一样 # 设置后缀名称,跟strftime的格式一样
filehandler.suffix = "%Y-%m-%d_%H-%M.log" filehandler.suffix = "%Y-%m-%d_%H-%M.log"
......
...@@ -43,6 +43,8 @@ def build_work_area_uuid_index_map(): ...@@ -43,6 +43,8 @@ def build_work_area_uuid_index_map():
except Exception as es: except Exception as es:
logger.error("路网读取") logger.error("路网读取")
logger.error(es) logger.error(es)
session_postgre.rollback()
session_postgre.rollback()
return ( return (
load_area_uuid_to_index_dict, load_area_uuid_to_index_dict,
unload_area_uuid_to_index_dict, unload_area_uuid_to_index_dict,
...@@ -70,6 +72,8 @@ def build_park_uuid_index_map(): ...@@ -70,6 +72,8 @@ def build_park_uuid_index_map():
except Exception as es: except Exception as es:
logger.info("备停区路网读取") logger.info("备停区路网读取")
logger.error(es) logger.error(es)
session_postgre.rollback()
session_postgre.rollback()
return park_uuid_to_index_dict, park_index_to_uuid_dict return park_uuid_to_index_dict, park_index_to_uuid_dict
...@@ -90,6 +94,8 @@ def build_truck_uuid_name_map(): ...@@ -90,6 +94,8 @@ def build_truck_uuid_name_map():
raise Exception("无矿卡设备可用-矿卡设备映射异常") raise Exception("无矿卡设备可用-矿卡设备映射异常")
except Exception as es: except Exception as es:
logger.warning(es) logger.warning(es)
session_postgre.rollback()
session_postgre.rollback()
return truck_uuid_to_name_dict, truck_name_to_uuid_dict return truck_uuid_to_name_dict, truck_name_to_uuid_dict
...@@ -109,6 +115,8 @@ def build_equipment_uuid_name_map(): ...@@ -109,6 +115,8 @@ def build_equipment_uuid_name_map():
raise Exception("无挖机设备可用") raise Exception("无挖机设备可用")
except Exception as es: except Exception as es:
logger.warning(es) logger.warning(es)
session_postgre.rollback()
session_postgre.rollback()
try: try:
...@@ -121,6 +129,8 @@ def build_equipment_uuid_name_map(): ...@@ -121,6 +129,8 @@ def build_equipment_uuid_name_map():
raise Exception("无卸载设备可用") raise Exception("无卸载设备可用")
except Exception as es: except Exception as es:
logger.warning(es) logger.warning(es)
session_postgre.rollback()
session_postgre.rollback()
return excavator_uuid_to_name_dict, dump_uuid_to_name_dict return excavator_uuid_to_name_dict, dump_uuid_to_name_dict
...@@ -175,6 +185,8 @@ def update_deveices_map(unload_area_uuid_to_index_dict, load_area_uuid_to_index_ ...@@ -175,6 +185,8 @@ def update_deveices_map(unload_area_uuid_to_index_dict, load_area_uuid_to_index_
except Exception as es: except Exception as es:
logger.error("卸载区信息异常") logger.error("卸载区信息异常")
logger.error(es) logger.error(es)
session_postgre.rollback()
session_postgre.rollback()
logger.info("excavator_index_to_load_area_index_dict") logger.info("excavator_index_to_load_area_index_dict")
logger.info(excavator_index_to_load_area_index_dict) logger.info(excavator_index_to_load_area_index_dict)
...@@ -241,6 +253,8 @@ def update_total_truck(): ...@@ -241,6 +253,8 @@ def update_total_truck():
except Exception as es: except Exception as es:
logger.info("矿卡读取") logger.info("矿卡读取")
logger.error(es) logger.error(es)
session_postgre.rollback()
session_postgre.rollback()
return truck_list return truck_list
...@@ -260,6 +274,8 @@ def update_dynamic_truck(): ...@@ -260,6 +274,8 @@ def update_dynamic_truck():
except Exception as es: except Exception as es:
logger.error(es) logger.error(es)
logger.error("动态调度矿卡读取异常") logger.error("动态调度矿卡读取异常")
session_postgre.rollback()
session_postgre.rollback()
return set(dynamic_truck_list) return set(dynamic_truck_list)
...@@ -279,11 +295,15 @@ def update_fixdisp_truck(): ...@@ -279,11 +295,15 @@ def update_fixdisp_truck():
rule5 = session_mysql.query(DispatchRule).filter_by(id=5).first().disabled rule5 = session_mysql.query(DispatchRule).filter_by(id=5).first().disabled
if not rule5: if not rule5:
query = np.array( try:
session_mysql.query(Equipment) query = np.array(
.filter_by(device_type=1, isdeleted=0, disabled=1) session_mysql.query(Equipment)
.all() .filter_by(device_type=1, isdeleted=0, disabled=1)
) .all()
)
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
for item in query: for item in query:
fixed_truck_list.append(item.id) fixed_truck_list.append(item.id)
...@@ -293,6 +313,8 @@ def update_fixdisp_truck(): ...@@ -293,6 +313,8 @@ def update_fixdisp_truck():
except Exception as es: except Exception as es:
logger.info("派车计划读取") logger.info("派车计划读取")
logger.error(es) logger.error(es)
session_postgre.rollback()
session_postgre.rollback()
return set(fixed_truck_list) return set(fixed_truck_list)
...@@ -308,6 +330,8 @@ def update_autodisp_excavator(): ...@@ -308,6 +330,8 @@ def update_autodisp_excavator():
raise Exception("无动态派车计划可用-动态派车挖机/卸载设备集合读取异常") raise Exception("无动态派车计划可用-动态派车挖机/卸载设备集合读取异常")
except Exception as es: except Exception as es:
logger.warning(es) logger.warning(es)
session_postgre.rollback()
session_postgre.rollback()
return set(dynamic_excavator_list) return set(dynamic_excavator_list)
...@@ -324,29 +348,43 @@ def update_autodisp_dump(): ...@@ -324,29 +348,43 @@ def update_autodisp_dump():
raise Exception("无动态派车计划可用-动态派车挖机/卸载设备集合读取异常") raise Exception("无动态派车计划可用-动态派车挖机/卸载设备集合读取异常")
except Exception as es: except Exception as es:
logger.warning(es) logger.warning(es)
session_postgre.rollback()
session_postgre.rollback()
return set(dynamic_dump_list) return set(dynamic_dump_list)
def update_load_area(): def update_load_area():
load_area_list = [] load_area_list = []
for walk_time in session_postgre.query(WalkTime).all(): try:
load_area_list.append(walk_time.load_area_id) for walk_time in session_postgre.query(WalkTime).all():
load_area_list.append(walk_time.load_area_id)
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
return load_area_list return load_area_list
def update_unload_area(): def update_unload_area():
unload_area_list = [] unload_area_list = []
for walk_time in session_postgre.query(WalkTime).all(): try:
unload_area_list.append(walk_time.unload_area_id) for walk_time in session_postgre.query(WalkTime).all():
unload_area_list.append(walk_time.unload_area_id)
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
return unload_area_list return unload_area_list
def update_park_area(): def update_park_area():
park_area_list = [] park_area_list = []
for walk_time_park in session_postgre.query(WalkTimePark).all(): try:
park_area_list.append(walk_time_park.park_area_id) for walk_time_park in session_postgre.query(WalkTimePark).all():
park_area_list.append(walk_time_park.park_area_id)
except Exception as es:
session_postgre.rollback()
session_postgre.rollback()
return park_area_list return park_area_list
# def build_work_area_uuid_index_map(): # def build_work_area_uuid_index_map():
......
...@@ -192,6 +192,9 @@ class Traffic_para(WalkManage): ...@@ -192,6 +192,9 @@ class Traffic_para(WalkManage):
# 设置卸载点信息 # 设置卸载点信息
def extract_dump_info(self): def extract_dump_info(self):
unload_area_index_to_uuid_dict = get_value("unload_area_index_to_uuid_dict")
dynamic_dump_num = get_value("dynamic_dump_num") dynamic_dump_num = get_value("dynamic_dump_num")
try: try:
rule3 = session_mysql.query(DispatchRule).filter_by(id=3).first() rule3 = session_mysql.query(DispatchRule).filter_by(id=3).first()
......
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