HTSim/ProduceSystem.py

60 lines
3.6 KiB
Python
Raw Normal View History

2023-07-24 15:07:19 +08:00
import agentpy as ap
import numpy as np
import random
class ProduceSystem(ap.Agent):
ev_str_status: str # 0,6,8,10 pp_id
ev_lst_backtrans_material: list # 退回Iss的原材料
ev_ary_produce_number: np.ndarray
def setup(self, dct_status_info):
self.ev_str_status = 0
self.ev_lst_backtrans_material = []
def change_status(self):
self.ev_str_status = self.model.the_firm.the_os.produce_status()
def run_produce(self, ev_lst_material, ev_lst_trans_quan_material, ev_ary_product_to_produce, xv_plan_excel,
xv_ary_bom): # ev_ary_product_to_produce 是 需求和库存的gap 23x2
# 生产状态由Iss确定这个函数需要计算生产数量和原材料消耗量。
# 如果原材料不足就按照production gap(ev_ary_product_to_produce) 大小进行生产如果没有gap的产品了就按照库存水平由少到多进行生产。
# 输出生产结果和原材料消耗结果
produce_plan = xv_plan_excel[xv_plan_excel[:, 0] == self.ev_str_status]
sorted_indices = np.argsort(ev_ary_product_to_produce[:, 1])[::-1]
sorted_data = ev_ary_product_to_produce[sorted_indices] # 对gap进行从大到小排序
sorted_indices_product = np.argsort(self.model.the_firm.the_is.ev_ary_current_product[:, 1]) # 对库存进行从小到大排序
sorted_data_product = self.model.the_firm.the_is.ev_ary_current_product[sorted_indices_product]
self.ev_lst_backtrans_material = ev_lst_trans_quan_material
self.ev_ary_produce_number = []
for product in sorted_data:
if product[1] > 0: # gap存在
product_material = xv_ary_bom[xv_ary_bom[:, 0] == product[0]]
produce_number = produce_plan[produce_plan[:, 1] == product[0]][3]
for material in product_material:
produce_number = min(produce_number, int(
self.ev_lst_backtrans_material[np.where(ev_lst_material == material[1])] / material[
2])) # 取能生产的最小个数
for material in product_material:
self.ev_lst_backtrans_material[np.where(ev_lst_material == material[1])] -= produce_number * material[
2] # 更新原材料消耗情况
self.ev_ary_produce_number.append([product[0], produce_number])
sorted_data_product = sorted_data_product[sorted_data_product[:, 0] != product[0]]
else:
for current_product in sorted_data_product:
product_material = xv_ary_bom[xv_ary_bom[:, 0] == current_product[0]]
produce_number = produce_plan[produce_plan[:, 1] == current_product[0]][3]
for material in product_material:
produce_number = min(produce_number, int(
self.ev_lst_backtrans_material[np.where(ev_lst_material == material[1])] / material[
2])) # 取能生产的最小个数
for material in product_material:
self.ev_lst_backtrans_material[np.where(ev_lst_material == material[1])] -= produce_number * \
material[2] # 更新原材料消耗情况
self.ev_ary_produce_number.append([current_product[0], produce_number])
break
self.ev_ary_produce_number = np.array(self.ev_ary_produce_number)
return self.ev_ary_produce_number, self.ev_lst_backtrans_material