HTSim/OrderSystem.py

104 lines
5.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import agentpy as ap
import numpy as np
from Order import Order
import pandas as pd
# 输出一个生产状态指令,一个交付情况,一个延期时间计算
class OrderSystem(ap.Agent):
a_lst_order: ap.AgentList[Order]
ev_int_produce_type: int
ev_ary_to_dlv: np.ndarray # 当前order list内所有产品的综合
ev_ary_product_to_produce: np.ndarray # 用于计算 production gap
ev_lst_all_delay_time: list
ev_ave_delay_time: float
xv_plan_excel: np.ndarray
ev_lst_flag: list
ev_changed_product: np.ndarray
# ev_ary_dlv_product: np.ndarray??????
def setup(self):
# Create a list of order
self.a_lst_order = ap.AgentList(self, [])
self.ev_ary_to_dlv = np.zeros((23, 1))
self.ev_int_produce_type = 0
self.ev_ary_product_to_produce = np.zeros((23,))
self.ev_lst_all_delay_time = []
self.ev_ave_delay_time = 0
# self.ev_ary_dlv_product = np.zeros((23,)) ????
self.ev_changed_product = np.zeros((23, ))
self.xv_plan_excel = pd.read_excel("plan.xlsx").to_numpy()
pass
def accept_order(self, new_order):
# Determine whether the order is received and all are currently received
if new_order is not None:
new_order.ev_is_accepted = True
self.a_lst_order.append(new_order)
def rank_order(self):
# Sort order
self.a_lst_order = self.a_lst_order.sort('xv_dlv_t', reverse=False)
def produce_status(self):
# 计算a_lst_order内所有订单包含的产品总量与当期库存的gap排序最大缺口量选定生产状态
self.ev_ary_to_dlv = np.zeros((23,))
for order in self.model.the_firm.the_os.a_lst_order:
self.ev_ary_to_dlv += order.ev_ary_dlv_product # 当前天之前所有的还未满足的需求求和
self.ev_ary_product_to_produce[:, 1] = self.ev_ary_to_dlv - self.model.the_firm.the_is.ev_ary_current_product
# self.ev_ary_product_to_produce = self.model.the_firm.the_is.ev_ary_current_product - self.ev_ary_to_dlv
# self.ev_ary_product_to_produce > 0:
# 选出这些产品按照数值大小进行分类数值最大的产品对应的能带来最大生产率的状态则选定为ev_int_produce_type
# 如果均<=0, 按照产品库存ev_ary_current_material进行排序选择能给库存最低的产品带来最高生产率的状态
sorted_indices = np.argsort(self.ev_ary_product_to_produce[:, 1])[::-1]
sorted_data = self.ev_ary_product_to_produce[sorted_indices]
if sorted_data[0, 1] > 0: # 判断是否存在库存不足
pass
else:
sorted_indices = np.argsort(self.model.the_firm.the_is.ev_ary_current_product[:, 1]) # 对库存进行从小到大排序
sorted_data = self.model.the_firm.the_is.ev_ary_current_product[sorted_indices]
a = self.xv_plan_excel[self.xv_plan_excel[:, 1] == sorted_data[0, 0]] # 检索最大值的产品的四种方案或者最小库存产品的四种方案
sorted_indices = np.argsort(a[:, 3])[::-1]
sorted_data = a[sorted_indices]
# return sorted_data[0, 0]
self.ev_int_produce_type = sorted_data[0, 0]
return self.ev_int_produce_type
def do_shipment(self,ev_ary_current_product):
# Make shipments based on ranked order list
# 交付两次第一次未交付完成的订单要标记交货的时候先便利delay的订单如果能够满足全部剩余量就交货如果不能
# 就继续在列表中存在
# 只有完全交付的订单才计算delay time = order.ev_int_delay_time * 第二次交付的订单内的各类产品之和
# 需要更新 order.ev_ary_dlv_product
# Make shipments based on ranked order list
self.ev_lst_all_delay_time = []
self.ev_ave_delay_time = 0
self.ev_changed_product = ev_ary_current_product # 23x1 ndarray 存储本次库存的改变
for order in self.a_lst_order:
if order.xv_dlv_t == self.model.t: # 第一次交付
# Check and make shipment
order.ev_is_delivered = True
for i in range(len(order.ev_ary_dlv_product)):
if order.ev_ary_dlv_product[i] <= self.ev_changed_product[i]:
order.ev_ary_dlv_product[i] = 0
self.ev_changed_product[i] -= order.ev_ary_dlv_product[i]
else:
order.ev_is_delivered = False
elif order.xv_dlv_t < self.model.t and order.ev_is_delivered == False: # 第二次交付
order.ev_is_delivered = True
for i in range(len(order.ev_ary_dlv_product)):
if order.ev_ary_dlv_product[i] > self.ev_changed_product[i]: # 先判断能不能一次性交付
order.ev_is_delivered = False
if order.ev_is_delivered: # 如果一次性交付
delay_num = np.sum(order.ev_ary_dlv_product)
order.ev_ary_dlv_product = np.zeros((23,))
self.ev_changed_product = self.ev_changed_product - order.ev_ary_dlv_product
order.ev_actual_dlv_t = self.model.t
order.ev_int_delay_time = order.ev_actual_dlv_t - order.xv_dlv_t
self.ev_ave_delay_time += order.ev_int_delay_time * delay_num / 10000
return self.ev_changed_product, self.ev_ave_delay_time