【发布时间】:2020-03-20 18:33:43
【问题描述】:
第一次使用纸浆,我正在尝试对我正在处理的生产问题设置条件约束。不幸的是,我在文档中也找不到有关如何执行此操作的任何示例。
目标函数是通过根据每个产品的预测价格减去成本来告知工厂每月生产哪种产品来最大化收入(当然这里省略了许多其他约束,否则会简单得多)。
对于以下数据,我需要设置以下约束:
- 尽管有能力生产多种产品,但工厂每个月只能生产一种产品。
这限制了工厂在一个月内只生产一种产品。我对纸浆很陌生,但尽管查阅了文档和 S.O.我找不到示例实现。
生产数据:
到目前为止我的代码
# omitted data etl logic - it is formatted as per the above images
# Get production info
plants = LpVariable.dicts('plants',
((month, plant, product) for month, plant, product in wp_df.index if month >= 4),
lowBound = 0,
cat='Integer')
# Get forecast price info by product
forecast_prices = LpVariable.dicts('price_by_prod',
((month, contract) for month, contract in fcst_diffs.index if month >= 4),
lowBound = 0,
cat='Integer')
# Prod costs for each month, plant.
costs = LpVariable.dicts(
'prod costs',
((month, plant) for month, plant in prod_costs_df.index),
lowBound=0,
cat='Integer')
# Define problem
model = LpProblem('Revenue Maximising Production Optimisation',
LpMaximize)
# Define objective function
model += lpSum(
[plants[m,w,g] * wp_df.loc[(m,w,g), 'production_output'] for m, w, g in wp_df.index]
+ [costs[m, w] * costs_df.loc[(m,w), 'prod_costs_usd'] for m, w in prod_costs_df.index]
)
我现在省略约束,因为我有很多要设置的。
感谢您的帮助,谢谢。
【问题讨论】:
标签: python linear-programming pulp