First time using pulp and I am trying to set a conditional constraint on a production problem I am working on. Unfortunately I cannot find any examples in the documentation as to how to do so either.
The objective function is to maximise revenue by informing monthly plant production on which product to produce based on the forecast price per product minus costs (Naturally there are lots of other constraints omitted here, otherwise it would be far simpler).
For the below data I need to set the following constraints:
- A plant can only produce a single product each month, despite having the capability to produce multiple products.
that limits a plant to producing only ONE product in a month. I am quite new to pulp but despite trawling the documentation and S.O. I cannot find an example implementation.
Production data:
My code so far
# 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]
)
I am omitting constraints for now as I have quite a few to set.
Appreciate the help, thank you.