import pulp
# Time Periods
T = range(2) # Example with two periods
# Parameters for M1
d1 = [200, 300] # Demand for M1's products
r1 = 0.1 # Residue generation factor
a1 = 1000 # Selling price per unit of product
br = 50 # Price per unit of residue sold to M2
f1 = 500 # Setup cost
fr = 200 # Treatment setup
p1 = 300 # Production cost per unit
pr = 50 # Treatment cost per unit
c1 = 300 # Production capacity
cr = 100 # Treatment capacity
h1 = 10 # Inventory holding cost per unit
hr = 2 # Inventory holding cost of by-product per unit
cl1 = 20 # Landfilling cost per unit
Imax1 = 400 # Maximum inventory capacity
Imaxr = 200 # Max by-product inventory capacity
tau = 50 # Carbon tax rate
em1 = 0.05 # Carbon emissions per unit of production
emi1 = 0.01 # Carbon emissions per unit of inventory
eml1 = 0.02 # Carbon emissions per unit of landfilling
emr = 0.005 # Carbon emissions per unit treated
emir = 0.008 # Carbon emissions per unit of by-product inventory
# Parameters for M2
d2 = [350, 400] # Demand for M2's products
c2 = 500 # Production capacity for M2
alpha = 0.3 # Proportion of residues in hybrid mode
a2 = 1200 # Selling price for Standard products
ah = 1400 # Selling price for Hybrid products
ae = 1600 # Selling price for Eco-Friendly products
f2 = 600 # Setup cost for Standard mode
p2 = 500 # Production cost for Standard products
h2 = 20 # Inventory holding cost
Imax2 = 500 # Maximum inventory capacity
tau = 50 # Carbon tax rate
em2 = 0.05 # Carbon emissions per unit of production
emi2 = 0.01 # Carbon emissions per unit of inventory
eml2 = 0.02 # Carbon emissions per unit of landfilling
wh = 0.2 # Customer sensitivity to hybrid products
we = 0.1 # Customer sensitivity to eco-friendly products
r2 = 0.05 # Scrap rate for M2
cl2 = 30 # Landfilling cost for M2
# Decision Variables for M1
X1 = [Link]("X1", T, lowBound=0)
I1 = [Link]("I1", T, lowBound=0)
Ir = [Link]("Ir", T, lowBound=0)
R = [Link]("R", T, lowBound=0)
B = [Link]("B", T, lowBound=0)
L = [Link]("L", T, lowBound=0)
y1 = [Link]("y1", T, cat="Binary")
# Decision Variables for M2
X2 = [Link]("X2", T, lowBound=0)
Xh = [Link]("Xh", T, lowBound=0)
Xe = [Link]("Xe", T, lowBound=0)
V = [Link]("V", T, lowBound=0)
I2 = [Link]("I2", T, lowBound=0)
Ih = [Link]("Ih", T, lowBound=0)
Ie = [Link]("Ie", T, lowBound=0)
y2 = [Link]("y2", T, cat="Binary")
yh = [Link]("yh", T, cat="Binary")
ye = [Link]("ye", T, cat="Binary")
# Create the Problem
prob_combined = [Link]("Integrated_Manufacturer_Optimization",
[Link])
# Objective Function
profit1 = [Link]([
a1 * X1[t] - f1 * y1[t] - p1 * X1[t] - h1 * I1[t] - cl1 * L[t] - fr * R[t]
- pr * R[t] - hr * Ir[t] - tau * (em1 * X1[t] + emi1 * I1[t] + emr * R[t] +
emir * Ir[t])
for t in T
])
profit2 = [Link]([
a2 * X2[t] + ah * Xh[t] + ae * Xe[t] - f2 * (y2[t] + yh[t] + ye[t])
- p2 * X2[t] - h2 * (I2[t] + Ih[t] + Ie[t]) - tau * (em2 * (X2[t] + Xh[t] +
Xe[t]))
for t in T
])
prob_combined += profit1 + profit2, "Total_Profit"
# Constraints
for t in T:
# Mode Selection
prob_combined += y2[t] + yh[t] + ye[t] == 1, f"Mode_Selection_{t}"
# Production Capacity
prob_combined += X1[t] <= c1 * y1[t], f"Capacity_M1_{t}"
prob_combined += X2[t] <= c2 * y2[t], f"Capacity_M2_{t}"
prob_combined += Xh[t] <= c2 * yh[t], f"Capacity_Hybrid_{t}"
prob_combined += Xe[t] <= c2 * ye[t], f"Capacity_Eco_{t}"
# Residue and Virgin Material Balances
prob_combined += alpha * B[t] + (1 - alpha) * V[t] == Xh[t],
f"Hybrid_Balance_{t}"
prob_combined += B[t] == Xe[t], f"Eco_Balance_{t}"
# Demand Satisfaction
prob_combined += X1[t] == d1[t] + I1[t], f"Demand_M1_{t}"
prob_combined += X2[t] + Xh[t] + Xe[t] == d2[t] + I2[t], f"Demand_M2_{t}"
# Inventory Limits
prob_combined += I1[t] <= Imax1, f"Inventory_Limit_M1_{t}"
prob_combined += I2[t] + Ih[t] + Ie[t] <= Imax2, f"Inventory_Limit_M2_{t}"
# Solve the Problem
prob_combined.solve()
# Display Results
print(f"Status: {[Link][prob_combined.status]}")
print(f"Objective Value: {[Link](prob_combined.objective)}")
for var in prob_combined.variables():
print(f"{[Link]}: {[Link]}")