problem in modeling "keyerror = 0"
回答済みI got troubled with an error stating "KeyError = 0" on the model objective function
from gurobipy import *
# SET
RM = 7
RAW = range(RM) # index r
CE = 3
COMP = range(CE) # index c
# PARAMETER
PMIN_c = [2, 0.4, 1.2]
PMAX_c = [3, 0.6, 1.65]
P_rc = [[2.5, 0, 1.3],
[3, 0, 0.8],
[0, 0.3, 0],
[0, 90, 0],
[0, 96, 4],
[0, 0.4, 1.2],
[0, 0.6, 0]]
AVAIL_r = [400, 300, 600, 500, 200, 300, 250, 500]
COST_r = [200, 250, 150, 220, 240, 200, 165]
DEM = 500
# MODEL
m = Model()
# DECISION VARIABLE
use_r = m.addVars(RAW, COMP, vtype=GRB.CONTINUOUS, name="materials used")
# OBJECTIVE FUNCTION
m.setObjective(quicksum(COST_r[r] * use_r[r] for r in RAW), GRB.MINIMIZE)
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Your variables are defined over 2 lists \(\texttt{RAW}\) and \(\texttt{COMP}\). Thus, you have to access variables \(\texttt{use_r}\) via
m.setObjective(quicksum(COST_r[r] * use_r[r,c] for r in RAW for c in COMP), GRB.MINIMIZE)
Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
2件のコメント