Commit 430230f1 authored by 张晓彤's avatar 张晓彤

二次调度不再绑定启动

parent dcdedf9e
......@@ -20,16 +20,21 @@ class Dispatcher:
"""
class for group dispatch program.
"""
def __init__(self, truck: TruckInfo, dump: DumpInfo, excavator: ExcavatorInfo, pre_sch: PreSchedule, request_mode=False):
def __init__(self, truck: TruckInfo, dump: DumpInfo, excavator: ExcavatorInfo, pre_sch: PreSchedule,
request_mode=False, active=False):
self.group_list = {}
self.truck = truck
self.dump = dump
self.excavator = excavator
self.pre_sch = pre_sch
self.request_mode = request_mode
self.logger = get_logger("zxt.dispatcher")
self.redispatch_active = active
if self.redispatch_active:
self.topo = graph_construct()
else:
self.topo = None
self.submission = DispatchSubmission(dump, excavator, truck, self.topo)
self.logger = get_logger("zxt.dispatcher")
def period_update(self):
"""
......@@ -41,7 +46,10 @@ class Dispatcher:
self.excavator.excavator_para_period_update()
self.truck.truck_para_period_update(self.dump, self.excavator)
self.truck.state_period_update()
if self.redispatch_active:
self.topo = graph_construct()
else:
self.topo = None
def group_generate(self):
"""
......
......@@ -323,6 +323,7 @@ class GroupDispatcher:
"""
self.logger = logging.getLogger("zxt.GroupDispatcher")
self.group = group
if self.group.topo is not None:
self.redispatcher = ReDispatcher(self.group)
def group_dispatch(self, Solver) -> Mapping[str, List[str]]:
......@@ -566,6 +567,7 @@ class GroupDispatcher:
self.logger.error(es)
truck_dispatch[i] = [None, None]
elif truck_task == 0:
if self.group.topo is not None:
if i in self.group.truck.get_truck_locate_dict():
truck_locate = self.group.truck.get_truck_locate_dict()[i]
else:
......@@ -596,8 +598,11 @@ class GroupDispatcher:
# self.redispatch_to_excavator(i, truck_dispatch, truck_locate)
self.redispatcher.redispatch_to_excavator(i, truck_dispatch, truck_locate)
else:
pass
elif truck_task == 3:
if self.group.topo is not None:
try:
truck_locate = self.group.truck.get_truck_locate_dict()[i]
except Exception as es:
......@@ -620,6 +625,8 @@ class GroupDispatcher:
# self.redispatch_to_dump(i, truck_dispatch, truck_locate, truck_trip)
self.redispatcher.redispatch_to_dump(i, truck_dispatch, truck_locate, truck_trip)
else:
pass
# def redispatch_to_dump(self, truck_id: str, truck_dispatch: Mapping[str, List[str]], truck_locate: str, truck_trip: List[int]):
# """
......
......@@ -124,6 +124,8 @@ class DispatchSubmission:
# TODO:
# 判断了两次是否拥堵,需要改善
if self.topo is not None:
# 车辆重载等待,且前方道路阻塞
if task == 3 and state == 2 and truck_id in self.truck.get_truck_locate_dict() and \
self.truck.get_truck_locate_dict()[truck_id] in self.topo.cross_bf_lanes:
......@@ -180,6 +182,8 @@ class DispatchSubmission:
# try:
record = redis_format(truck_id, group_id, str(uuid.uuid1()), item)
if self.topo is not None:
# 车辆重载等待,且前方道路阻塞
if task == 0 and state == 2 and truck_id in self.truck.get_truck_locate_dict() and \
self.truck.get_truck_locate_dict()[truck_id] in self.topo.cross_bf_lanes:
......
......@@ -7,6 +7,7 @@
import numpy as np
from settings import *
from tables import *
import pandas as pd
from tables import DispatchMatch, DispatchEquipment
from bidict import bidict
......
......@@ -8,6 +8,7 @@
from data.static_data_process import *
from settings import *
from tables import *
import numpy as np
# 全局参数设定
......
......@@ -10,6 +10,7 @@
# 静态数据处理(函数名即为注释)
from settings import *
from tables import *
logger = get_logger("zxt.static_data_process")
......
......@@ -8,6 +8,7 @@
from data.para_config import *
from settings import *
from tables import *
# 卸载设备类
......
......@@ -8,6 +8,7 @@
from data.para_config import *
from settings import *
from tables import *
# 挖机设备类
......
# from para_config import *
from settings import *
from tables import *
import numpy as np
import sched
import time
......
......@@ -19,6 +19,7 @@ from core.schedule import PreSchedule
from data.dispatchInfo import DispatchInfo
from util import CoreException
from core.group import direct2redis
import argparse
def process(dispatcher):
......@@ -130,6 +131,16 @@ def main(inc, dispatcher):
if __name__ == "__main__":
# 创建参数解析器
parser = argparse.ArgumentParser(description='argparse some parameters.')
# 添加参数
parser.add_argument('--active', action='store_true', help='active re-dispatch?')
# 参数解析
args = parser.parse_args()
redispatch_active = args.active
# 初始化日志
set_log()
# 获取日志器
......@@ -150,7 +161,7 @@ if __name__ == "__main__":
pre_sch = PreSchedule(truck, excavator, dump)
# 实例化矿卡调度器
dispatcher = Dispatcher(truck, dump, excavator, pre_sch, False)
dispatcher = Dispatcher(truck, dump, excavator, pre_sch, False, redispatch_active)
logger.info(" ")
logger.info("调度系统启动")
......
......@@ -17,6 +17,7 @@ import time
from core.dispatcher import Dispatcher
from core.schedule import PreSchedule
from data.dispatchInfo import DispatchInfo
import argparse
def direct2redis():
......@@ -150,6 +151,18 @@ def main(inc, dispatcher):
if __name__ == "__main__":
# 创建参数解析器
parser = argparse.ArgumentParser(description='argparse some parameters.')
# 添加参数
parser.add_argument('--active', action='store_true', help='active re-dispatch?')
parser.add_argument('--sqlserver', action='store_true', help='use SQLserver?')
# 参数解析
args = parser.parse_args()
redispatch_active = args.active
# 初始化日志
set_log()
# 获取日志器
......@@ -170,7 +183,7 @@ if __name__ == "__main__":
pre_sch = PreSchedule(truck, excavator, dump)
# 实例化矿卡调度器
dispatcher = Dispatcher(truck, dump, excavator, pre_sch, False)
dispatcher = Dispatcher(truck, dump, excavator, pre_sch, False, redispatch_active)
logger.info(" ")
logger.info("调度系统启动")
......
......@@ -19,6 +19,8 @@ from datetime import datetime, timedelta
import copy
import json
global redispatch_active
json_file = "config.json"
with open(json_file) as f:
......
#!/bin/bash
python3 topo_update_server.py
nohup python3 realtime_dispatch.py >/dev/null 2>&1 &
\ No newline at end of file
nohup python3 realtime_dispatch.py --active >/dev/null 2>&1 &
\ No newline at end of file
......@@ -15,6 +15,7 @@ from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base
from urllib.parse import quote
import json, os
from settings import *
relative_path = os.path.dirname(os.path.abspath(__file__)) # 获取当前文件夹的绝对路径
json_file = os.path.join(relative_path, "config.json")
......@@ -83,63 +84,6 @@ session_postgre.expire_on_commit = False
# 定义对象:
# class Excavator(Base):
# __tablename__ = 'excavator_property'
#
# excavator_id = Column(VARCHAR(36), primary_key=True)
# load_area_id = Column(VARCHAR(36))
# average_load_time = Column(Integer)
# target_mass = Column(Float(2))
# actual_mass = Column(Float(2))
# # virtual_mass = Column(Float(2))
# # last_load_time = Column(DateTime)
#
# def __init__(self, excavator_id, load_area_id, average_load_time, target_mass, actual_mass):
# self.excavator_id = excavator_id
# self.load_area_id = load_area_id
# self.average_load_time = average_load_time
# self.target_mass = target_mass
# self.actual_mass = actual_mass
# # self.virtual_mass = virtual_mass
# # self.last_load_time = last_load_time
# class Dump(Base):
# __tablename__ = 'dump_property'
#
# dump_id = Column(VARCHAR(36), primary_key=True)
# unload_area_id = Column(VARCHAR(36))
# average_unload_time = Column(Integer)
# target_mass = Column(Float(2))
# actual_mass = Column(Float(2))
# # virtual_mass = Column(Float(2))
# # last_unload_time = Column(DateTime)
#
# def __init__(self, dump_id, unload_area_id, average_unload_time, target_mass, actual_mass):
# self.dump_id = dump_id
# self.unload_area_id = unload_area_id
# self.average_unload_time = average_unload_time
# self.target_mass = target_mass
# self.actual_mass = actual_mass
# # self.virtual_mass = virtual_mass
# # self.last_unload_time = last_unload_time
# class Walk_time(Base):
# __tablename__ = 'walk_time'
#
# Rid = Column(VARCHAR(36), primary_key=True)
# load_area_id = Column(VARCHAR(36))
# unload_area_id = Column(VARCHAR(36))
# walktime_load = Column(Float(2))
# walktime_unload = Column(Float(2))
#
# def __init__(self, Rid, load_area_id, unload_area_id, walktime_load, walktime_unload):
# self.Rid = Rid
# self.load_area_id = load_area_id
# self.unload_area_id = unload_area_id
# self.walktime_load = walktime_load
# self.walktime_unload = walktime_unload
class WalkTime(Base):
__tablename__ = 'work_area_distance'
......@@ -164,61 +108,6 @@ class WalkTime(Base):
self.to_unload_lanes = to_unload_lanes
self.to_load_lanes = to_load_lanes
# Rid = Column(VARCHAR(36), primary_key=True)
# load_area_id = Column(VARCHAR(36))
# unload_area_id = Column(VARCHAR(36))
# walktime_load = Column(Float(2))
# walktime_unload = Column(Float(2))
#
# def __init__(self, Rid, load_area_id, unload_area_id, walktime_load, walktime_unload):
# self.Rid = Rid
# self.load_area_id = load_area_id
# self.unload_area_id = unload_area_id
# self.walktime_load = walktime_load
# self.walktime_unload = walktime_unload
# class Truck(Base):
# __tablename__ = 'truck_status'
#
# truck_id = Column(VARCHAR(36), primary_key=True)
# # dispatch_id = Column(VARCHAR(36))
# current_task = Column(Integer)
# # reach_time = Column(DateTime)
# last_load_time = Column(DateTime)
# last_unload_time = Column(DateTime)
# payload = Column(Float(2))
#
# def __init__(self, truck_id, current_task, last_load_time, last_unload_time, payload):
# self.truck_id = truck_id
# # self.dispatch_id = dispatch_id
# self.current_task = current_task
# # self.reach_time = reach_time
# self.last_load_time = last_load_time
# self.last_unload_time = last_unload_time
# self.payload = payload
#
# def check_existing(self):
# existing = session_mysql.query(Truck).filter_by(truck_id=self.truck_id).first()
# if not existing:
# truck = Truck(self.truck_id, self.dispatch_id, self.status, self.reach_time, self.last_load_time, self.last_unload_time, self.payload)
# else:
# truck = existing
# session_mysql.close()
# return truck
# class Dispatch(Base):
# __tablename__ = 'dispatch_pair'
#
# dispatch_id = Column(VARCHAR(36), primary_key=True)
# excavator_id = Column(VARCHAR(36))
# dump_id = Column(VARCHAR(36))
#
# def __init__(self, dispatch_id, excavator_id, dump_id):
# self.dispatch_id = dispatch_id
# self.excavator_id = excavator_id
# self.dump_id = dump_id
class EquipmentPair(Base):
__tablename__ = 'sys_equipment_pair'
......@@ -368,13 +257,6 @@ class WalkTimePark(Base):
self.park_load_lanes = park_load_lanes
# class DispatchSetting(Base):
# __tablename__ = 'sys_dispatch_setting_v'
# id = Column(VARCHAR(36), primary_key=True)
#
# def __init__(self, id):
# self.id = id
class Equipment(Base):
__tablename__ = 'sys_equipment'
......
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