OrderReallocation-HeavyTruc.../data_structures.py

121 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.

# 数据结构定义:存储订单、企业、供应商数据及算法配置
class OrderData:
"""订单数据类:存储物料需求、交货期、成本等信息"""
def __init__(self):
self.I = 8 # 物料种类数
self.Q = [6000, 12000, 22000, 7500, 13500, 16000, 8000, 14000] # 各物料的需求数量
self.Dd = 40 # 需求交货期(单位:时间)
self.P0 = [45, 30, 30, 50, 40, 45, 30, 30] # 风险企业的单位采购价
self.T0 = [5, 8, 6, 7, 9, 4, 6, 7] # 风险企业的单位运输成本
self.transport_speed = 10 # 运输速度(单位:距离/时间)
class RiskEnterpriseData:
"""风险企业数据类:存储风险企业的产能、距离等信息"""
def __init__(self):
self.I = 8 # 物料种类数(与订单一致)
self.C0_i_min = [50, 100, 150, 80, 100, 150, 80, 100] # 单物料的单位时间最小产能
self.C0_total_max = 18000 # 总产能上限(单位时间)
self.distance = 30 # 与需求点的距离
class SupplierData:
"""供应商数据类:存储各供应商的产能、价格、距离等信息"""
def __init__(self, I=8):
self.I = I # 物料种类数
self.supplier_count = 6 # 供应商数量
self.names = ["S0", "S1", "S2", "S3", "S4", "S5"] # 供应商名称
# 能否生产某物料的矩阵supplier_count × I1=能生产0=不能
self.can_produce = [
[1, 1, 0, 1, 1, 0, 1, 1],
[1, 0, 1, 0, 1, 1, 0, 1],
[0, 1, 0, 1, 0, 0, 1, 0],
[0, 1, 0, 1, 1, 1, 1, 1],
[1, 1, 0, 1, 0, 0, 1, 0],
[0, 0, 1, 0, 1, 0, 1, 1]
]
# 单物料单位时间最小产能supplier_count × I0表示不能生产该物料
self.Cj_i_min = [
[30, 80, 0, 60, 80, 0, 80, 90],
[35, 0, 120, 0, 90, 110, 0, 110],
[0, 70, 0, 70, 0, 0, 85, 0],
[0, 75, 0, 75, 85, 95, 90, 100],
[25, 60, 0, 80, 0, 0, 90, 0],
[0, 0, 150, 0, 100, 0, 100, 95]
]
# 供应商单位时间的最大总产能supplier_count
self.Cj_total_max = [1100, 950, 850, 1350, 750, 1000]
# 最小起订量supplier_count × I
self.MinOrder = [
[300, 800, 0, 600, 800, 0, 800, 900],
[350, 0, 1200, 0, 900, 1100, 0, 1100],
[0, 700, 0, 700, 0, 0, 850, 0],
[0, 750, 0, 750, 850, 950, 900, 1000],
[250, 600, 0, 800, 0, 0, 900, 0],
[0, 0, 1500, 0, 1000, 0, 1000, 950]
]
# 最大供应量supplier_count × I
self.MaxOrder = [
[3000, 8000, 0, 6000, 8000, 0, 8000, 9000],
[3500, 0, 12000, 0, 9000, 11000, 0, 11000],
[0, 7000, 0, 7000, 0, 0, 8500, 0],
[0, 7500, 0, 7500, 8500, 9500, 9000, 7000],
[3000, 6000, 0, 8000, 0, 0, 9000, 0],
[0, 0, 15000, 0, 8000, 0, 6500, 9500]
]
# 单位采购价格supplier_count × I
self.P_ij = [
[50, 32, 0, 60, 42, 0, 32, 33],
[55, 0, 33, 0, 44, 48, 0, 36],
[0, 33, 0, 62, 0, 0, 32, 0],
[0, 36, 0, 59, 46, 40, 34, 40],
[53, 37, 0, 58, 0, 0, 39, 0],
[0, 0, 32, 0, 43, 0, 35, 38]
]
# 单位运输成本supplier_count × I
self.T_ij = [
[8, 8, 0, 5, 15, 0, 8, 11],
[13, 0, 8, 0, 13, 8, 0, 13],
[0, 10, 0, 9, 0, 0, 11, 0],
[0, 6, 0, 8, 11, 7, 9, 10],
[4, 12, 0, 12, 0, 0, 12, 0],
[0, 0, 10, 0, 12, 0, 8, 16]
]
# 供应商与需求点的距离supplier_count
self.distance = [50, 40, 60, 30, 60, 80, 50, 60]
class Config:
"""算法参数配置类存储NSGA-II的各类参数"""
def __init__(self):
# 种群参数
self.pop_size = 200 # 种群大小
self.N1_ratio = 0.2 # 优先成本的种群比例
self.N2_ratio = 0.2 # 优先延期的种群比例
self.N3_ratio = 0.3 # 强制风险企业的种群比例
self.N4_ratio = 0.3 # 随机种群比例
# 遗传操作参数
self.crossover_prob = 0.8 # 交叉概率
self.mutation_prob = 0.3 # 变异概率
self.max_generations = 500 # 最大进化代数
# 惩罚系数
self.delta = 1.3 # 变更惩罚系数
# 早停参数
self.early_stop_patience = 20 # 连续多少代无改进则早停
self.early_stop_threshold = 0.15 # 目标值变化阈值
# 目标函数数量
self.objective_num = 2 # 双目标(成本+延期)
self.duplicate_threshold = 0.01 # 重复解保留数量
self.print_top_n = 10 # 打印前N个最优解
class DataStructures:
"""数据结构工具类:提供评价指标计算等功能"""
@staticmethod
def calculate_evaluation_index(objectives, optimal_cost, optimal_tardiness, max_cost, max_tardiness):
"""
计算评价指标
: objectives: 解的目标值 (成本, 延期)
: optimal_cost: 最优成本值
: optimal_tardiness: 最优延期值
: max_cost: 最大成本值
: max_tardiness: 最大延期值
:return: 评价指标值
"""
cost, tardiness = objectives
cost_ratio = cost/(max_cost - optimal_cost)
tardiness_ratio = tardiness/( max_tardiness - optimal_tardiness)
return cost_ratio + tardiness_ratio