尝试在Gurobi / Python中添加以下约束:
代码
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:'缺少约束索引'。是什么原因?