继续编写相关逻辑
This commit is contained in:
parent
4a045d650b
commit
845aa0e48f
@ -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.set_mode_quantity(record[5], record[6], record[7])
|
||||
process.set_product_time(record[8])
|
||||
products[record[2]].set_process(process)
|
||||
products[record[2]].add_process(process)
|
||||
processes[process.pcs_id] = process
|
||||
|
||||
for record in res:
|
||||
|
10
model.py
10
model.py
@ -34,7 +34,7 @@ class Product:
|
||||
self.product_id: str = product_id
|
||||
self.product_name: str = product_name
|
||||
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):
|
||||
if semi_product.product_id != self.product_id:
|
||||
@ -43,8 +43,8 @@ class Product:
|
||||
"amount": amount
|
||||
})
|
||||
|
||||
def set_process(self, process):
|
||||
self.process = process
|
||||
def add_process(self, process):
|
||||
self.processes.append(process)
|
||||
|
||||
|
||||
@auto_str
|
||||
@ -104,7 +104,7 @@ class Process:
|
||||
@auto_repr
|
||||
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_name: str = rsc_name
|
||||
self.rsc_type: str = rsc_type
|
||||
@ -112,7 +112,7 @@ class Resource:
|
||||
|
||||
self.basic_attr: Optional[str] = None
|
||||
self.attrs: Set = set()
|
||||
self.workspace: Workspace = workspace
|
||||
self.workspace: str = workspace
|
||||
|
||||
def set_amount(self, amount: int):
|
||||
self.amount: int = amount
|
||||
|
76
runtime.py
76
runtime.py
@ -1,6 +1,6 @@
|
||||
import model
|
||||
from datetime import datetime, timedelta
|
||||
from typing import List, Dict
|
||||
from typing import List, Dict, Optional
|
||||
|
||||
|
||||
class RuntimeProduct:
|
||||
@ -8,6 +8,7 @@ class RuntimeProduct:
|
||||
def __init__(self, product, amount):
|
||||
self.ddl: datetime = datetime.today()
|
||||
self.start: datetime = datetime.today()
|
||||
self.delay = datetime.today()
|
||||
self.product: model.Product = product
|
||||
self.amount: int = amount
|
||||
|
||||
@ -15,6 +16,9 @@ class RuntimeProduct:
|
||||
self.ddl = ddl
|
||||
self.start = start
|
||||
|
||||
def set_delay(self, processes_pdt_times):
|
||||
self.delay = self.ddl - timedelta(minutes=processes_pdt_times)
|
||||
|
||||
|
||||
class ProductLine:
|
||||
|
||||
@ -74,3 +78,73 @@ class RuntimeProcess:
|
||||
self.process = process
|
||||
self.ddl = runtime_product.ddl
|
||||
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
|
||||
|
@ -52,18 +52,30 @@ def search_semi_products(floor, produce_tree, produce_list, runtime_product):
|
||||
|
||||
|
||||
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:
|
||||
processes_list: List[runtime.RuntimeProcess] = []
|
||||
production_times: int = 0
|
||||
for process in runtime_product.product.processes:
|
||||
runtime_process: runtime.RuntimeProcess = \
|
||||
runtime.RuntimeProcess(runtime_product, runtime_product.product.process)
|
||||
|
||||
runtime.RuntimeProcess(runtime_product, process)
|
||||
production_times += runtime_process.process.pdt_time
|
||||
processes_list.append(runtime_process)
|
||||
|
||||
processes_list = sorted(processes_list, key=lambda rt_pcs: (rt_pcs.ddl, rt_pcs.delay))
|
||||
runtime_product.set_delay(production_times)
|
||||
runtime_products_processes_list.append({"runtimeProduct": runtime_product, "runtimeProcess": processes_list})
|
||||
|
||||
for runtime_process in processes_list:
|
||||
print(runtime_process.process.pcs_id, runtime_process.delay)
|
||||
runtime_products_processes_list = \
|
||||
sorted(runtime_products_processes_list,
|
||||
key=lambda dict_item:
|
||||
(dict_item["runtimeProduct"].ddl, dict_item["runtimeProduct"].delay))
|
||||
|
||||
for item in runtime_products_processes_list:
|
||||
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__":
|
||||
|
Loading…
Reference in New Issue
Block a user