继续编写相关逻辑

This commit is contained in:
Saturneric 2021-04-19 17:37:36 +08:00
parent 4a045d650b
commit 845aa0e48f
4 changed files with 100 additions and 14 deletions

View File

@ -53,7 +53,7 @@ def import_process(res, products: Dict[str, model.Product]) -> Dict[str, model.P
process: model.Process = model.Process(record[0], record[1], products[record[2]], record[9]) process: model.Process = model.Process(record[0], record[1], products[record[2]], record[9])
process.set_mode_quantity(record[5], record[6], record[7]) process.set_mode_quantity(record[5], record[6], record[7])
process.set_product_time(record[8]) process.set_product_time(record[8])
products[record[2]].set_process(process) products[record[2]].add_process(process)
processes[process.pcs_id] = process processes[process.pcs_id] = process
for record in res: for record in res:

View File

@ -34,7 +34,7 @@ class Product:
self.product_id: str = product_id self.product_id: str = product_id
self.product_name: str = product_name self.product_name: str = product_name
self.semi_products: List[Dict[str, any]] = [] self.semi_products: List[Dict[str, any]] = []
self.process: Optional[Process] = None self.processes: List[Process] = []
def add_semi_product(self, semi_product: Product, amount): def add_semi_product(self, semi_product: Product, amount):
if semi_product.product_id != self.product_id: if semi_product.product_id != self.product_id:
@ -43,8 +43,8 @@ class Product:
"amount": amount "amount": amount
}) })
def set_process(self, process): def add_process(self, process):
self.process = process self.processes.append(process)
@auto_str @auto_str
@ -104,7 +104,7 @@ class Process:
@auto_repr @auto_repr
class Resource: class Resource:
def __init__(self, rsc_id: str, rsc_name: str, rsc_type: str, workspace: Workspace): def __init__(self, rsc_id: str, rsc_name: str, rsc_type: str, workspace: str):
self.rsc_id: str = rsc_id self.rsc_id: str = rsc_id
self.rsc_name: str = rsc_name self.rsc_name: str = rsc_name
self.rsc_type: str = rsc_type self.rsc_type: str = rsc_type
@ -112,7 +112,7 @@ class Resource:
self.basic_attr: Optional[str] = None self.basic_attr: Optional[str] = None
self.attrs: Set = set() self.attrs: Set = set()
self.workspace: Workspace = workspace self.workspace: str = workspace
def set_amount(self, amount: int): def set_amount(self, amount: int):
self.amount: int = amount self.amount: int = amount

View File

@ -1,6 +1,6 @@
import model import model
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import List, Dict from typing import List, Dict, Optional
class RuntimeProduct: class RuntimeProduct:
@ -8,6 +8,7 @@ class RuntimeProduct:
def __init__(self, product, amount): def __init__(self, product, amount):
self.ddl: datetime = datetime.today() self.ddl: datetime = datetime.today()
self.start: datetime = datetime.today() self.start: datetime = datetime.today()
self.delay = datetime.today()
self.product: model.Product = product self.product: model.Product = product
self.amount: int = amount self.amount: int = amount
@ -15,6 +16,9 @@ class RuntimeProduct:
self.ddl = ddl self.ddl = ddl
self.start = start self.start = start
def set_delay(self, processes_pdt_times):
self.delay = self.ddl - timedelta(minutes=processes_pdt_times)
class ProductLine: class ProductLine:
@ -74,3 +78,73 @@ class RuntimeProcess:
self.process = process self.process = process
self.ddl = runtime_product.ddl self.ddl = runtime_product.ddl
self.delay = self.runtime_product.ddl - timedelta(minutes=process.pdt_time) self.delay = self.runtime_product.ddl - timedelta(minutes=process.pdt_time)
class RuntimeResourceNeed:
def __int__(self,
process: model.Process,
resource_attr: str,
workspace: str,
start: datetime, end: datetime):
if start < end:
raise RuntimeError("the start time must before the end time")
self.process: model.Process = process
self.resource_attr: str = resource_attr
self.workspace: str = workspace
self.start: datetime = start
self.end: datetime = end
class RuntimeResource:
def __init__(self, resource: model.Resource):
self.resource: model.Resource = resource
self.workspace: str = self.resource.workspace
self.basic_attr = self.resource.basic_attr
self.resource_attrs = self.resource.attrs
self.schedules: List[RuntimeResourceNeed] = []
def add_schedule(self, schedule: RuntimeResourceNeed) -> bool:
pre_need: Optional[RuntimeResourceNeed] = None
back_need: Optional[RuntimeResourceNeed] = None
for resource_need in self.schedules:
if resource_need.end > schedule.start:
pre_need = resource_need
if back_need is not None \
and resource_need.start < resource_need.end:
back_need = resource_need
if pre_need is not None or back_need is not None:
return False
else:
self.schedules.append(schedule)
self.schedules = sorted(self.schedules, key=lambda need: need.start)
return True
class RuntimeResourcePool:
def __init__(self, resources: List[model.Resource]):
self.pool: List[RuntimeResource] = []
for resource in resources:
runtime_resource = RuntimeResource(resource)
self.pool.append(runtime_resource)
def alloc_resource(self, resource_need: RuntimeResourceNeed) -> bool:
# 精确搜索
for runtime_resource in self.pool:
if runtime_resource.basic_attr == resource_need.resource_attr:
if runtime_resource.add_schedule(resource_need) is True:
return True
# 放宽条件搜索
for runtime_resource in self.pool:
if resource_need.resource_attr in runtime_resource.resource_attrs:
if runtime_resource.add_schedule(resource_need) is True:
return True
return False

View File

@ -52,18 +52,30 @@ def search_semi_products(floor, produce_tree, produce_list, runtime_product):
def products_processor(runtime_products: List[runtime.RuntimeProduct]): def products_processor(runtime_products: List[runtime.RuntimeProduct]):
processes_list: List[runtime.RuntimeProcess] = []
runtime_products_processes_list: List[Dict[str, any]] = []
for runtime_product in runtime_products: for runtime_product in runtime_products:
runtime_process: runtime.RuntimeProcess = \ processes_list: List[runtime.RuntimeProcess] = []
runtime.RuntimeProcess(runtime_product, runtime_product.product.process) production_times: int = 0
for process in runtime_product.product.processes:
runtime_process: runtime.RuntimeProcess = \
runtime.RuntimeProcess(runtime_product, process)
production_times += runtime_process.process.pdt_time
processes_list.append(runtime_process)
processes_list.append(runtime_process) runtime_product.set_delay(production_times)
runtime_products_processes_list.append({"runtimeProduct": runtime_product, "runtimeProcess": processes_list})
processes_list = sorted(processes_list, key=lambda rt_pcs: (rt_pcs.ddl, rt_pcs.delay)) runtime_products_processes_list = \
sorted(runtime_products_processes_list,
key=lambda dict_item:
(dict_item["runtimeProduct"].ddl, dict_item["runtimeProduct"].delay))
for runtime_process in processes_list: for item in runtime_products_processes_list:
print(runtime_process.process.pcs_id, runtime_process.delay) for runtime_process in item["runtimeProcess"]:
runtime_product: runtime.RuntimeProduct = item["runtimeProduct"]
print(runtime_product.product.product_id, runtime_product.delay, runtime_process.process.pcs_id)
if __name__ == "__main__": if __name__ == "__main__":