Having problems modelling a objective function
Answered
#I am trying to code a production model, however my objective function gives me a "key error 1".
#Please help me understand where am i getting it wrong ?
import gurobipy as gp
from gurobipy import GRB
# Create a new Gurobi model
model = gp.Model("production_planning")
# Define the sizes of the sets
i = 6
j = 4
m = 2
# Create sets I, J, and M
I = range(1, i + 1) # Parts set from 1 to i_n
J = range(1, j + 1) # Jobs set from 1 to j_n
M = range(1, m + 1) # Machines set from 1 to m_n
# Define the parameters for each part
h = {'1': 25.10, '2': 37.25, '3': 39.24, '4': 4.27, '5': 13.56, '6': 2.18} # Height of each part
a = {'1': 569.53, '2': 464.89, '3': 779.96, '4': 122.62, '5': 390.39, '6': 178.34} # Production area of each part
V = {'1': 2867.59, '2': 2378.05, '3': 16420.91, '4': 102.83, '5': 3640.48, '6': 214.79} # Material volume of each part
# Define the parameters for each machine
MC = 2 # Cost per unit volume of material
TC = {'1': 60, '2': 80} # Operation cost per unit time for each machine
VT = 0.030864 # Time for forming per unit volume of material for each machine
HT = {'1': 1.4, '2': 0.7} # Accumulated interval time per unit height for each machine
HC = 20 # Cost of human work per unit time
ST = {'1': 2, '2': 1} # Setup time needed for each machine
H = {'1': 32.5, '2': 40} # Maximum height of part that each machine can process
A = {'1': 625, '2': 1600} # Maximum production area of part that each machine can process
#Decision variables
X = model.addVar(j, i, vtype=GRB.BINARY, name="X")
Y = model.addVar(m, j, vtype=GRB.BINARY, name="Y")
Z = model.addVar(j, vtype=GRB.BINARY, name="Z")
model.update()
JPC = gp.LinExpr()
for m in M:
for i in I:
JPC += TC[m] * VT[m] + MC * gp.quicksum(V[i] for i in I)
JPC += TC[m] * HT[m] * max(h[i] for i in range(I))
JPC += ST[m] * HC
0

Hi Muhammad,
Please see Tutorial: Preparing a Minimal Reproducible Example where we walk through debugging a key error.
 Riley
0
Please sign in to leave a comment.
Comments
1 comment