defgen_chrom(num_order, num_seru, data_seru): sequence = np.random.permutation(list(range(1,num_order+1))) process_able_matrix = np.zeros([num_seru,data_seru.shape[1]-1]) for i inrange(num_seru): for j inrange(data_seru.shape[1]-1): if np.isnan(data_seru.iloc[i][j+1][0]): pass else: process_able_matrix[i,j] = j+1 process_able_list = [[int(value) for value in row if value != 0] for row in process_able_matrix] # 找出所有的产品类型 product_types = set() for machine in process_able_list: product_types.update(machine)
# 创建一个包含每个产品类型可以在哪个机器加工的列表 product_to_machine = {product: [] for product in product_types} for machine_index, machine inenumerate(process_able_list): for product in machine: product_to_machine[product].append(machine_index+1)
# 按产品类型排序并转换为列表 result = [product_to_machine[product] for product insorted(product_to_machine)] sequence = np.random.permutation(list(range(1,num_order+1))) sequence_type = [data_order.iloc[i-1]['product type'] for i in sequence] assign = [np.random.choice(result[sequence_type[i]-1]) for i inrange(num_order)] x = np.concatenate([sequence, assign],axis=0) return x