Commit 3e2448fe authored by 张晓彤's avatar 张晓彤

Initial commit

parents
^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package Dispatch
^^^^^^^^^^^^^^^^^^^^^^^^^^
--------------------
[version]: 1.0.1
[message]: add
[feather]:
[fix ]:
[TODO ]:
[info ]: author: zxt ; time: 2021-07-07 15:46:00 ; email: ; tel: ;
--------------------
--------------------
[version]: 1.1.1
[message]: refactor real-time dispatch function
[feather]:
[fix ]:
[TODO ]:
[info ]: author: zxt ; time: 2021-07-23 16:59:00 ; email: ; tel: ;
--------------------
--------------------
[version]: 1.2.1
[message]: add traffic flow planning
[feather]:
[fix ]:
[TODO ]:
[info ]: author: zxt ; time: 2021-07-23 16:59:00 ; email: ; tel: ;
--------------------
\ No newline at end of file
#!E:\Pycharm Projects\Waytous
# -*- coding: utf-8 -*-
# @Time : 2021/8/24 11:31
# @Author : Opfer
# @Site :
# @File : __init__.py
# @Software: PyCharm
\ No newline at end of file
#!E:\Pycharm Projects\Waytous
# -*- coding: utf-8 -*-
# @Time : 2021/8/24 11:28
# @Author : Opfer
# @Site :
# @File : dump.py
# @Software: PyCharm
from para_config import *
from settings import *
# 卸载设备类
class DumpInfo(WalkManage):
def __init__(self):
# 卸载设备数量
self.dynamic_dump_num = get_value("dynamic_dump_num")
# 用于动态调度的卸载设备集合
self.dynamic_dump_set = get_value("dynamic_dump_set")
# 开始时间
self.start_time = datetime.now()
# 卸载时间
self.unloading_time = np.zeros(self.dynamic_dump_num)
# 入场时间
self.entrance_time = np.zeros(self.dynamic_dump_num)
# 出场时间
self.exit_time = np.zeros(self.dynamic_dump_num)
# 卸载点物料类型
self.dump_material = {}
# 卸点优先级
self.dump_priority_coefficient = np.ones(self.dynamic_dump_num)
# 初始化读取映射及路网
self.period_map_para_load()
self.period_walk_para_load()
# 参数初始化
self.para_period_update()
def get_unloading_time(self):
return self.unloading_time
def get_dump_num(self):
return self.dynamic_dump_num
def get_dynamic_dump_set(self):
return self.dynamic_dump_set
def get_unloading_task_time(self):
unloading_time = self.unloading_time
dump_entrance_time = self.entrance_time
dump_exit_time = self.exit_time
unloading_task_time = unloading_time + dump_entrance_time + dump_exit_time
return unloading_task_time
# 更新卸载设备卸载时间
def update_dump_unloadtime(self):
self.unloading_time = np.zeros(self.dynamic_dump_num)
for dump_id in self.dump_uuid_to_index_dict.keys():
ave_unload_time = 0
unload_count = 0
# try:
# for query in (
# session_mysql.query(JobRecord.start_time, JobRecord.end_time)
# .join(Equipment, JobRecord.equipment_id == Equipment.equipment_id)
# .filter(Equipment.id == dump_id, JobRecord.end_time != None)
# .order_by(JobRecord.start_time.desc())
# .limit(10)
# ):
# ave_unload_time = ave_unload_time + float(
# (query.end_time - query.start_time)
# / timedelta(hours=0, minutes=1, seconds=0)
# )
# unload_count = unload_count + 1
# self.unloading_time[self.dump_uuid_to_index_dict[dump_id]] = (
# ave_unload_time / unload_count
# )
# except Exception as es:
# logger.error(f"卸载设备 {dump_id} 卸载时间信息缺失, 已设为默认值(1min)")
# logger.error(es)
self.unloading_time[self.dump_uuid_to_index_dict[dump_id]] = 5.00
# print("average_unload_time: ", self.unloading_time[self.dump_uuid_to_index_dict[dump_id]])
# 更新卸载设备出入时间
def update_dump_entrance_exit_time(self):
self.entrance_time = np.zeros(self.dynamic_dump_num)
self.exit_time = np.zeros(self.dynamic_dump_num)
now = datetime.now().strftime("%Y-%m-%d")
for dump_id in self.dump_uuid_to_index_dict.keys():
# try:
# for query in (
# session_mysql.query(WorkRecord)
# .filter(
# WorkRecord.equipment_id == dump_id, WorkRecord.work_day >= now
# )
# .first()
# ):
# self.entrance_time[self.dump_uuid_to_index_dict[dump_id]] = float(
# query.load_entrance_time / query.load_entrance_count
# )
# self.exit_time[self.dump_uuid_to_index_dict[dump_id]] = float(
# query.exit_entrance_time / query.exit_entrance_count
# )
# except Exception as es:
# logger.error(f"卸载设备 {dump_id} 出入场时间信息缺失, 已设为默认值(1min)")
# logger.error(es)
self.entrance_time[self.dump_uuid_to_index_dict[dump_id]] = 0.50
self.exit_time[self.dump_uuid_to_index_dict[dump_id]] = 0.50
def update_dump_material(self):
self.dump_material = {}
for dump_id in get_value("dynamic_dump_set"):
try:
unload_area_id = session_mysql.query(Dispatch).filter_by(dump_id=dump_id, isauto=1, isdeleted=0).first().unload_area_id
dump_material_id = session_postgre.query(DumpArea).filter_by(Id=unload_area_id).first().Material
self.dump_material[dump_id] = dump_material_id
except Exception as es:
logger.error("无动态派车计划可用")
logger.error(es)
def update_dump_priority(self):
self.dump_priority_coefficient = np.ones(self.dynamic_dump_num)
for dump_id in self.dynamic_dump_set:
try:
unload_area_index = self.dump_index_to_unload_area_index_dict[self.dump_uuid_to_index_dict[dump_id]]
unload_area_id = unload_area_index_to_uuid_dict[unload_area_index]
item = session_postgre.query(DumpArea).filter_by(Id=unload_area_id).first()
self.dump_priority_coefficient[self.dump_uuid_to_index_dict[dump_id]] += item.Priority
except Exception as es:
logger.error("无动态派车计划可用")
logger.error(es)
def reset(self):
# 卸载设备数量
self.dynamic_dump_num = get_value("dynamic_dump_num")
# 用于动态调度的卸载设备集合
self.dynamic_dump_set = get_value("dynamic_dump_set")
# 卸载时间
self.unloading_time = np.zeros(self.dynamic_dump_num)
# 入场时间
self.entrance_time = np.zeros(self.dynamic_dump_num)
# 出场时间
self.exit_time = np.zeros(self.dynamic_dump_num)
# 卸载点物料类型
self.dump_material = {}
# 卸点优先级
self.dump_priority_coefficient = np.ones(self.dynamic_dump_num)
def para_period_update(self):
self.reset()
# print("Dump update!")
logger.info("Dump update!")
# 装载周期参数
self.period_map_para_load()
self.period_walk_para_load()
# 计算平均卸载时间
self.update_dump_unloadtime()
# 计算平均进出场时间
self.update_dump_entrance_exit_time()
# 更新卸点物料
self.update_dump_material()
# 更新设备优先级
self.update_dump_priority()
# 卸载目标产量
self.dump_target_mass = np.full(self.dynamic_dump_num, dump_target_mass)
\ No newline at end of file
#!E:\Pycharm Projects\Waytous
# -*- coding: utf-8 -*-
# @Time : 2021/8/24 11:28
# @Author : Opfer
# @Site :
# @File : excavator.py
# @Software: PyCharm
from para_config import *
from settings import *
# 挖机设备类
class ExcavatorInfo(WalkManage):
def __init__(self):
# # 挖机集合
# self.dynamic_excavator_set = set(update_autodisp_excavator())
# 装载设备数量
self.dynamic_excavator_num = len(dynamic_excavator_set)
# 用于动态调度的卸载设备集合
self.dynamic_excavator_set = []
# 开始时间
self.start_time = datetime.now()
# 装载时间
self.loading_time = np.zeros(self.dynamic_excavator_num)
# 入场时间
self.entrance_time = np.zeros(self.dynamic_excavator_num)
# 出场时间
self.exit_time = np.zeros(self.dynamic_excavator_num)
# 挖机对应物料类型
self.excavator_material = {}
# 挖机设备优先级
self.excavator_priority_coefficient = np.ones(self.dynamic_excavator_num)
# 挖机物料优先级
self.excavator_material_priority = np.ones(self.dynamic_excavator_num)
# 初始化读取映射及路网
self.period_map_para_load()
self.period_walk_para_load()
# 参数初始化
self.para_period_update()
def get_loading_time(self):
return self.loading_time
def get_excavator_num(self):
return self.dynamic_excavator_num
def get_dynamic_excavator_set(self):
return self.dynamic_excavator_set
# 更新挖机装载时间
def update_excavator_loadtime(self):
self.loading_time = np.zeros(self.dynamic_excavator_num)
for excavator_id in self.excavator_uuid_to_index_dict.keys():
ave_load_time = 0
load_count = 0
# try:
# for query in (
# session_mysql.query(JobRecord.start_time, JobRecord.end_time)
# .join(Equipment, JobRecord.equipment_id == Equipment.equipment_id)
# .filter(Equipment.id == excavator_id, JobRecord.end_time != None)
# .order_by(JobRecord.start_time.desc())
# .limit(10)
# ):
# ave_load_time = ave_load_time + float(
# (query.end_time - query.start_time)
# / timedelta(hours=0, minutes=1, seconds=0)
# )
# load_count = load_count + 1
# self.loading_time[self.excavator_uuid_to_index_dict[excavator_id]] = (
# ave_load_time / load_count
# )
# except Exception as es:
# logger.error(f"挖机 {excavator_id} 装载时间信息缺失, 已设为默认值(1min)")
# logger.error(es)
logger.info("loading_time")
logger.info(self.loading_time)
logger.info("excavator_uuid_to_index_dict")
logger.info(self.excavator_uuid_to_index_dict)
self.loading_time[self.excavator_uuid_to_index_dict[excavator_id]] = 5.00
# 更新挖机设备出入时间
def update_excavator_entrance_exit_time(self):
self.entrance_time = np.zeros(self.dynamic_excavator_num)
self.exit_time = np.zeros(self.dynamic_excavator_num)
now = datetime.now().strftime("%Y-%m-%d")
for excavator_id in self.excavator_uuid_to_index_dict.keys():
# try:
# for query in (
# session_mysql.query(WorkRecord)
# .filter(
# WorkRecord.equipment_id == excavator_id,
# WorkRecord.work_day >= now,
# )
# .first()
# ):
# self.entrance_time[
# self.excavator_uuid_to_index_dict[excavator_id]
# ] = float(query.load_entrance_time / query.load_entrance_count)
# self.exit_time[
# self.excavator_uuid_to_index_dict[excavator_id]
# ] = float(query.exit_entrance_time / query.exit_entrance_count)
# except Exception as es:
# logger.error(f"挖机设备 {excavator_id} 出入场时间信息缺失, 已设为默认值(1min)")
# logger.error(es)
self.entrance_time[
self.excavator_uuid_to_index_dict[excavator_id]
] = 0.50
self.exit_time[self.excavator_uuid_to_index_dict[excavator_id]] = 0.50
# 读取出入场时间
def get_loading_task_time(self):
loading_time = self.loading_time
excavator_entrance_time = self.entrance_time
excavator_exit_time = self.exit_time
loading_task_time = loading_time + excavator_entrance_time + excavator_exit_time
return loading_task_time
def update_excavator_material(self):
logger.info("self.dynamic_excavator_set")
logger.info(self.dynamic_excavator_set)
for excavator_id in self.dynamic_excavator_set:
try:
load_area_id = session_mysql.query(Dispatch).filter_by(exactor_id=excavator_id, isdeleted=0, isauto=1).first().load_area_id
excavator_material_id = session_postgre.query(DiggingWorkArea).filter_by(Id=load_area_id).first().Material
self.excavator_material[excavator_id] = excavator_material_id
except Exception as es:
logger.warning(es)
def update_excavator_priority(self):
logger.info("dynamic_excavator_set")
logger.info(self.dynamic_excavator_set)
for excavator_id in self.dynamic_excavator_set:
item = session_mysql.query(Equipment).filter_by(id=excavator_id).first()
logger.info("excavator_priority_coefficient")
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()
material_priority_use = rule7.disabled
if material_priority_use == 0:
rule = rule7.rule_weight
if rule == 3:
if self.excavator_material[excavator_id] == 'e56eb559-a746-4cc4-8ada-ebf9819fbe27':
self.excavator_material_priority[self.excavator_uuid_to_index_dict[excavator_id]] = 5
elif rule == 1:
if self.excavator_material[excavator_id] == '81bb175d-50fe-4be3-937e-6791ac4d6fec':
self.excavator_material_priority[self.excavator_uuid_to_index_dict[excavator_id]] = 5
def reset(self):
# 装载设备数量
self.dynamic_excavator_num = get_value("dynamic_excavator_num")
# 用于动态调度的卸载设备集合
self.dynamic_excavator_set = get_value("dynamic_excavator_set")
# 装载时间
self.loading_time = np.zeros(self.dynamic_excavator_num)
# 入场时间
self.entrance_time = np.zeros(self.dynamic_excavator_num)
# 出场时间
self.exit_time = np.zeros(self.dynamic_excavator_num)
# 挖机对应物料类型
self.excavator_material = {}
# 挖机设备优先级
self.excavator_priority_coefficient = np.ones(self.dynamic_excavator_num)
# 挖机物料优先级
self.excavator_material_priority = np.ones(self.dynamic_excavator_num)
def para_period_update(self):
self.reset()
logger.info("Excavator update!")
rule7 = session_mysql.query(DispatchRule).filter_by(id=7).first().disabled
logger.info("物料优先级规则")
logger.info(rule7)
# 装载周期参数
self.period_map_para_update()
self.period_walk_para_update()
# 用于动态调度的挖机设备
self.dynamic_excavator_set = set(update_autodisp_excavator())
self.dynamic_excavator_num = len(self.dynamic_excavator_set)
# 计算平均装载时间
self.update_excavator_loadtime()
# 更新挖机物料
self.update_excavator_material()
# 更新挖机优先级
self.update_excavator_priority()
This diff is collapsed.
This diff is collapsed.
#!E:\Pycharm Projects\Waytous
# -*- coding: utf-8 -*-
# @Time : 2021/8/3 10:51
# @Author : Opfer
# @Site :
# @File : __init__.py.py
# @Software: PyCharm
\ No newline at end of file
This diff is collapsed.
#!E:\Pycharm Projects\Waytous
# -*- coding: utf-8 -*-
# @Time : 2021/9/3 14:44
# @Author : Opfer
# @Site :
# @File : priority_control.py
# @Software: PyCharm
from equipment.truck import *
from equipment.dump import *
from equipment.excavator import *
from para_config import *
truck = TruckInfo()
excavator = ExcavatorInfo()
dump = DumpInfo()
def weighted_walk_cost():
dynamic_dump_num = get_value("dynamic_dump_num")
dynamic_excavator_num = get_value("dynamic_excavator_num")
dynamic_dump_set = get_value("dynamic_dump_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))
excavator_priority = excavator.excavator_priority_coefficient
excavator_material_priority = excavator.excavator_material_priority
dump_priority = dump.dump_priority_coefficient
dump_material_priority = np.ones(dynamic_dump_num)
park_walk_weight = np.ones((park_num, dynamic_excavator_num))
rule6 = session_mysql.query(DispatchRule).filter_by(id=6).first()
if not rule6.disabled:
for dump_id in dynamic_dump_set:
for excavator_id in dynamic_excavator_set:
dump_index = dump.dump_uuid_to_index_dict[dump_id]
excavator_inedx = excavator.excavator_uuid_to_index_dict[excavator_id]
walk_weight[dump_index][excavator_inedx] += dump_priority[dump_index] * \
excavator_priority[excavator_inedx]
park_walk_weight = park_walk_weight * excavator.excavator_priority_coefficient
rule7 = session_mysql.query(DispatchRule).filter_by(id=7).first()
if not rule7.disabled:
for dump_id in dynamic_dump_set:
for excavator_id in dynamic_excavator_set:
dump_index = dump.dump_uuid_to_index_dict[dump_id]
excavator_inedx = excavator.excavator_uuid_to_index_dict[excavator_id]
walk_weight[dump_index][excavator_inedx] += dump_material_priority[dump_index] * \
excavator_material_priority[excavator_inedx]
park_walk_weight = park_walk_weight * excavator.excavator_material_priority
walk_weight = walk_weight - (walk_weight.min() - 1)
park_walk_weight = park_walk_weight - (park_walk_weight.min() - 1)
return walk_weight, park_walk_weight
def available_walk():
dynamic_dump_num = get_value("dynamic_dump_num")
dynamic_excavator_num = get_value("dynamic_excavator_num")
dynamic_dump_set = get_value("dynamic_dump_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))
for dump_id in dynamic_dump_set:
for excavator_id in dynamic_excavator_set:
dump_index = dump.dump_uuid_to_index_dict[dump_id]
excavator_inedx = excavator.excavator_uuid_to_index_dict[excavator_id]
if excavator.excavator_material[excavator_id] != dump.dump_material[dump_id]:
walk_weight[dump_index][excavator_inedx] += 1000000
return walk_weight
def update_group_walk_available():
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 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()
if item is not None:
dump_index = dump.dump_uuid_to_index_dict[dump_id]
excavator_index = excavator.excavator_uuid_to_index_dict[excavator_id]
group_walk_available[dump_index][excavator_index] = 0
return group_walk_available
#还没想好写什么
\ No newline at end of file
This diff is collapsed.
#!E:\Pycharm Projects\Waytous
# -*- coding: utf-8 -*-
# @Time : 2021/7/23 11:25
# @Author : Opfer
# @Site :
# @File : settings.py
# @Software: PyCharm
# 数据库设备, redis设置, 日志设置
from tables import *
from urllib.parse import quote
import logging.handlers
import numpy as np
import os
from redis import StrictRedis, ConnectionPool
import redis
from datetime import datetime, timedelta
import copy
import json
import sched
import time
# 创建日志
########################################################################################################################
# 日志存储地址
log_path = "/usr/local/fleet-log/dispatch"
# 创建日志目录
# if not os.path.exists(log_path):
# os.mkdir(log_path)
# logging初始化工作
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# 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("./Logs/dispatch.log", maxBytes=3 * 1024 * 1024, backupCount=10)
# 设置后缀名称,跟strftime的格式一样
filehandler.suffix = "%Y-%m-%d_%H-%M.log"
formatter = logging.Formatter("%(asctime)s - %(name)s: %(levelname)s %(filename)s %(message)s")
filehandler.setFormatter(formatter)
logger.addHandler(filehandler)
# 连接reids
########################################################################################################################
# redis 5 存储设备状态
pool5 = ConnectionPool(host="192.168.28.111", db=5, port=6379, password="Huituo@123")
redis5 = StrictRedis(connection_pool=pool5)
# redis 2 存储派车计划
pool2 = ConnectionPool(host="192.168.28.111", db=2, port=6379, password="Huituo@123")
redis2 = StrictRedis(connection_pool=pool2)
# 数据库连接设置
########################################################################################################################
# 创建对象的基类:
Base = declarative_base()
try:
engine_mysql = create_engine(
"mysql+mysqlconnector://root:%s@192.168.28.111:3306/waytous"
% quote("Huituo@123")
)
engine_postgre = create_engine(
"postgresql://postgres:%s@192.168.28.111:5432/shenbao_2021520"
% quote("Huituo@123")
)
# 创建DBsession_mysql类型:
DBsession_mysql = sessionmaker(bind=engine_mysql)
DBsession_mysql = scoped_session(DBsession_mysql)
DBsession_postgre = sessionmaker(bind=engine_postgre)
DBsession_postgre = scoped_session(DBsession_postgre)
# 创建session_mysql对象:
session_mysql = DBsession_mysql()
session_mysql.expire_on_commit = False
session_postgre = DBsession_postgre()
session_postgre.expire_on_commit = False
except Exception as es:
logger.error("数据库连接失败")
logger.error(es)
def str_to_byte(item):
return bytes(item, encoding='utf8')
def byte_to_str(item):
return str(item, encoding='utf-8')
This diff is collapsed.
This diff is collapsed.
#!E:\Pycharm Projects\Waytous
# -*- coding: utf-8 -*-
# @Time : 2021/8/31 15:17
# @Author : Opfer
# @Site :
# @File : __init__.py
# @Software: PyCharm
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
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