以下代码引发错误
标记为文件“model.pxi”,第2469行,在gurobipy.Model.addConstr(../../src / python / golobipy.c:77443) TypeError:不支持的操作数类型 - :'bool'和'NoneType'
def get_incenter_and_radius(facets):
n = len(facets[0])
m = Model()
m.setParam('OutputFlag', False)
r = m.addVar(lb = -100.0, ub = 100.0, vtype = GRB.CONTINUOUS)
center = [m.addVar(lb = -1.0, ub = 1.0, vtype = GRB.CONTINUOUS, name = "x" + str(i)) for i in range(n)]
m.update()
for facet in facets:
norm = sqrt(sum(facet[i]**2 for i in nums(facet)))
m.addConstr(r * norm <= get_sp(facet, center))
m.addConstr(r > 0) # ________________ ERROR ___________________
for coord_num in range(n):
m.addConstr(center[coord_num] + r <= 1)
for coord_num in range(n):
m.addConstr(center[coord_num] - r >= -1)
m.setObjective(r, GRB.MAXIMIZE)
m.optimize()
if m.sol_count == 0:
return None, None
center_val = tuple(elt.X for elt in center)
return center_val, r.X
我已经指定了r的类型和范围,那么错误的来源是什么?
答案 0 :(得分:1)
线性规划不允许严格的不等式(&gt;,&lt;)。您应该使用&gt; =或&lt; =运算符。