GUROBI:在Python中添加约束时'缺少约束索引'

时间:2018-05-26 10:54:41

标签: python optimization gurobi integer-programming

尝试在Gurobi / Python中添加以下约束: Constraint

代码

N_SERVERS = 5                             #number of servers
C_SERVER = [1]*N_SERVERS
N_NODES = 3                               #number of nodes
C_NODES = [2]*N_NODES    

#create model
m = Model("mip1")

#declare variables
x = m.addVars(len(C_SERVER), vtype=GRB.BINARY, name = "x")
y = m.addVars(len(C_NODES), vtype=GRB.BINARY, name = "y")
m.update()

m.addConstrs(quicksum(x[i]*C_SERVER[i] for i in range(len(x))) + quicksum(y[j]*C_NODES[j] for j in range(len(y))) == quicksum(C_SERVER)

我收到以下错误:KeyError:'缺少约束索引'。是什么原因?

0 个答案:

没有答案