Python Gurobi

时间:2017-03-04 22:41:56

标签: python gurobi

Attached is the DEA notes

以下是我目前的代码。当我运行它时,我收到了这个错误 第33行,在     m.addConstr(quicksum([L [i] Xi [i] [j],j为范围(n1),如果i <= j]) - (θ X0 [k] [j]对于范围内的j(len(Xi)))&lt; = 0,&#39; Xi%d&#39;%(i))

文件&#34; linexpr.pxi&#34;,第429行,在gurobipy.LinExpr。 sub (../../src/python/gurobipy.c:32250)

TypeError:*:&#39; int&#39;不支持的操作数类型和&#39;生成器&#39;

from gurobipy import *

X0 =[[5,14],\
    [8,15],\
    [7,12]]

Xi = list(map(list, zip(*X0)))

Y0 =[[9,4,16],\
    [5,7,10],\
    [4,9,13]]

Yi = list(map(list, zip(*Y0)))    

n1= len(X0)
n2= len(Yi)

m = Model("DEA")

#set up variables
theta = m.addVar(obj=1)#,vtype=GRB.SEMIINT,name='theta')

L = {}
for i in range(n1):
    L[i] = m.addVar(obj=0,vtype=GRB.SEMIINT, lb=0,name='L%d' % i)

m.update() 

#set up constraints
k = 0
for i in range(n1):
    m.addConstr(quicksum([L[i]*Xi[i][j] for j in range(n1) if i <= j])-(theta*X0[k][j] for j in range(len(Xi))) <= 0,'Xi%d' % (i))

for i in range(n2):
    m.addConstr(quicksum([L[i]*Yi[i][j] for j in range(n1) if i <= j]) >= Y0[k][i], 'Yi%d' % (i))

m.optimize()

m.write('DEA.lp')

# Print solution
if m.status == GRB.status.OPTIMAL:
    print ('\nOptimal flows:')
    for v in m.getVars():
        if v.X > 0:
            print( '%6s = %4.1f' % (v.VarName, v.X))
    print()
    print( 'Objective Value:', m.ObjVal)

else:
    print ('Bummer ',m.status)

0 个答案:

没有答案