HTSim/Firm.py

62 lines
3.5 KiB
Python
Raw Normal View History

2023-07-24 15:07:19 +08:00
import numpy as np
import json
from InventorySystem import InventorySystem
from OrderSystem import OrderSystem
from ProduceSystem import ProduceSystem
2023-07-25 21:32:08 +08:00
2023-07-24 15:07:19 +08:00
# Create Company Instance
class Firm:
the_os: OrderSystem
the_is: InventorySystem
the_ps: ProduceSystem
def __init__(self, env, dct_all_para):
self.env = env
# get the parameters here
2023-07-25 21:32:08 +08:00
self.xv_ary_initial_product_num = np.asarray(dct_all_para['xv_ary_initial_product_num']) # 初始产成品库存
self.xv_ary_initial_material_num = np.asarray(dct_all_para['xv_ary_initial_material_num']) # 初始原材料库存
self.xv_product_num = int(dct_all_para['xv_product_num']) # 产成品个数
self.xv_material_num = int(dct_all_para['xv_material_num']) # 原材料个数
2023-07-25 23:17:57 +08:00
self.xv_ary_plan = np.asarray(dct_all_para['xv_ary_plan'])
2023-07-25 21:32:08 +08:00
self.xv_ary_bom = np.asarray(dct_all_para['xv_ary_bom'])
self.xv_ary_product_id = np.asarray(dct_all_para['xv_ary_product_id'])
self.xv_ary_material_id = np.asarray(dct_all_para['xv_ary_material_id'])
self.xv_ary_s = np.asarray(dct_all_para['xv_ary_s'])
self.xv_ary_S = np.asarray(dct_all_para['xv_ary_S'])
# self.dct_status_info = json.loads(dct_all_para['dct_status_info']) # 生产状态表
# self.xv_ary_lead_time = np.array([dct_all_para['xv_int_lead_time_a'], dct_all_para['xv_int_lead_time_b']])
2023-07-24 15:07:19 +08:00
# create agents here
2023-07-25 23:17:57 +08:00
self.the_os = OrderSystem(env, xv_product_num=self.xv_product_num, xv_ary_plan=self.xv_ary_plan,
2023-07-25 21:32:08 +08:00
xv_ary_product_id=self.xv_ary_product_id) # 实例Oss
2023-07-24 15:07:19 +08:00
self.the_is = InventorySystem(env, xv_ary_initial_material_num=self.xv_ary_initial_material_num,
xv_ary_initial_product_num=self.xv_ary_initial_product_num,
2023-07-25 21:32:08 +08:00
xv_product_num=self.xv_product_num,
xv_material_num=self.xv_material_num,
2023-07-25 23:17:57 +08:00
xv_ary_bom=self.xv_ary_bom, xv_ary_plan=self.xv_ary_plan,
2023-07-25 21:32:08 +08:00
xv_ary_material_id=self.xv_ary_material_id) # 实例Iss
self.the_ps = ProduceSystem(env, xv_ary_bom=self.xv_ary_bom, xv_ary_plan=self.xv_ary_plan,
xv_product_num=self.xv_product_num,
xv_ary_product_id=self.xv_ary_product_id,
xv_ary_material_id=self.xv_ary_material_id) # 实例Pss
2023-07-24 15:07:19 +08:00
# self.the_fs = FinancialSystem(env, xv_flt_initial_cash=self.xv_flt_initial_cash)
2023-07-25 21:32:08 +08:00
def operating(self): # 按步骤进行
2023-07-24 15:07:19 +08:00
self.the_os.rank_order()
2023-07-25 21:32:08 +08:00
self.the_os.produce_status()
self.the_is.material_state_to_use()
self.the_is.material_check()
2023-07-24 15:07:19 +08:00
self.the_ps.change_status()
2023-07-25 21:32:08 +08:00
self.the_ps.run_produce(ev_lst_trans_quan_material=self.the_is.ev_lst_trans_quan_material,
ev_ary_product_to_produce=self.the_os.ev_ary_product_to_produce)
self.the_is.consume_and_store(ev_ary_produced_num=self.the_ps.ev_ary_produce_number,
ev_changed_product=self.the_os.ev_changed_product,
ev_lst_backtrans_material=self.the_ps.ev_lst_backtrans_material)
2023-07-25 23:17:57 +08:00
self.the_is.material_replenishment(xv_ary_s=self.xv_ary_s, xv_ary_S=self.xv_ary_S)
2023-07-25 21:32:08 +08:00
self.the_os.do_shipment(ev_ary_current_product=self.the_is.ev_ary_current_product)
2023-07-24 15:07:19 +08:00
# self.the_is.inventory_cost()
# self.the_fs.financial_calculating()