0
votes

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:

  1. 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:

production data

product forecast price 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.

1

1 Answers

0
votes

Introduce a set of binary variables which are indexed by {plant, product, month}, which determine whether plant i is being used to make product j during month k. Variable will be 1 when this is true, and 0 otherwise.

You'll then need to add constraints so that the amount of product j being produced in plant i during month k is limited. Typically this could be done with a constraint constraining this amount variable to be <= b*C where b is the binary variable, and C is the capacity of that plant to make that product.

Finally you need to constraint each plant to only make a single product during each month. For each month, and for each plant, the sum of these binary variables across all the products is limited to be <= 0.

Good luck!