纸浆调度优化问题 - 随时间变化的多个供应输入
Pulp Scheduling Optimization Problem - multiple supply inputs over time
我目前正在用 pulp 构建一个调度计划,但是我很难理解如何表示 pulp 的供应变量以供解析,因为数据包含在多索引数据框中。
问题
我正试图最小化任何增量,以便按工厂、按月的供应与需求相匹配。请注意,并非所有工厂都生产所需的产品
当前供应数据
我知道 pulp 接受变量字典作为输入,即:
LpVariable.dicts("Route",(plant, output)
但是我不确定如何将 supply 表示为:
(月份、工厂、产品,production_output)
非常感谢任何帮助。
我想你想要做的是有决策变量,即每个 月 中每种 产品 的供应量,在每 植物 。换句话说,您有指数:(月份、工厂、产品)。
这当然会创建总共len(months)*len(plants)*len(products)
个变量,在这个例子中是12*5*4 = 240个变量。
我会通过将该工厂的产品产能设置为零来处理无法生产某种产品的工厂。
import pulp
months = range(1,12)
plants = ['A', 'B', 'C', 'D', 'E']
products = ['AFS', 'GDF', 'POD', 'PPI']
supply = pulp.LpVariable.dicts("supply", (months, plants, products))
print(supply)
这将 return 个可以引用的变量,例如:supply[3]['A']['POD']
您可以使用月份、工厂和产品的元组作为变量字典的键,还可以使用它从数据帧中获取生产输出 Mt。
import pulp
months = range(1,12)
plants = ['A', 'B', 'C', 'D', 'E']
products = ['AFS', 'GDF', 'POD', 'PPI']
# set up binary variables for plant-month-product
var_dict = {}
for month in months:
for plant in plants:
for product in product:
combo = (month, plant, product)
var_name = '_'.join([str(c) for c in combo])
var_dict[combo] = LpVariable(var_name, cat=LpBinary)
prob = LpProblem('Schedule', LpMinimize)
# objective function
# assume data in df and has index of month, plant, and product
prob += lpSum([var * df.loc[('at', k), 'Production Output (Mt)']
for k, v in var_dict.items()]
# then add the relevant constraints
# for example, one and only one product per plant per month
# remember that in var_dict the key is a tuple of month, plant, product
# and the value is the binary variable
for month in months:
for plant in plants:
prob += lpSum([v for k, v in var_dict.items()
if k[0] == month and k[1] == plant]) == 1
我目前正在用 pulp 构建一个调度计划,但是我很难理解如何表示 pulp 的供应变量以供解析,因为数据包含在多索引数据框中。
问题 我正试图最小化任何增量,以便按工厂、按月的供应与需求相匹配。请注意,并非所有工厂都生产所需的产品
当前供应数据
我知道 pulp 接受变量字典作为输入,即:
LpVariable.dicts("Route",(plant, output)
但是我不确定如何将 supply 表示为:
(月份、工厂、产品,production_output)
非常感谢任何帮助。
我想你想要做的是有决策变量,即每个 月 中每种 产品 的供应量,在每 植物 。换句话说,您有指数:(月份、工厂、产品)。
这当然会创建总共len(months)*len(plants)*len(products)
个变量,在这个例子中是12*5*4 = 240个变量。
我会通过将该工厂的产品产能设置为零来处理无法生产某种产品的工厂。
import pulp
months = range(1,12)
plants = ['A', 'B', 'C', 'D', 'E']
products = ['AFS', 'GDF', 'POD', 'PPI']
supply = pulp.LpVariable.dicts("supply", (months, plants, products))
print(supply)
这将 return 个可以引用的变量,例如:supply[3]['A']['POD']
您可以使用月份、工厂和产品的元组作为变量字典的键,还可以使用它从数据帧中获取生产输出 Mt。
import pulp
months = range(1,12)
plants = ['A', 'B', 'C', 'D', 'E']
products = ['AFS', 'GDF', 'POD', 'PPI']
# set up binary variables for plant-month-product
var_dict = {}
for month in months:
for plant in plants:
for product in product:
combo = (month, plant, product)
var_name = '_'.join([str(c) for c in combo])
var_dict[combo] = LpVariable(var_name, cat=LpBinary)
prob = LpProblem('Schedule', LpMinimize)
# objective function
# assume data in df and has index of month, plant, and product
prob += lpSum([var * df.loc[('at', k), 'Production Output (Mt)']
for k, v in var_dict.items()]
# then add the relevant constraints
# for example, one and only one product per plant per month
# remember that in var_dict the key is a tuple of month, plant, product
# and the value is the binary variable
for month in months:
for plant in plants:
prob += lpSum([v for k, v in var_dict.items()
if k[0] == month and k[1] == plant]) == 1