在python外壳上输入代码进行优化问题期间,由于未知原因GurobiError: Variable has not yet been added to the model
,我收到了此错误,这是代码的一部分:
from gurobipy import *
>>> m=Model("scanning")
>>> from sympy import *
>>> v=zeros(3,1)
>>> ub=zeros(3,1)
>>> lb=zeros(3,1)
>>> x=m.addVar(lb=0,ub=3,vtype='I',name='x')
>>> m.addConstr(Array([[1,2,3],[2,1,0],[2,3,1]])*x>=0,"c0")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/midow/anaconda3/lib/python3.6/site-packages/sympy/tensor/array/ndim_array.py", line 346, in __mul__
other = sympify(other)
File "/Users/midow/anaconda3/lib/python3.6/site-packages/sympy/core/sympify.py", line 266, in sympify
if a in sympy_classes:
File "var.pxi", line 39, in gurobipy.Var.__hash__
gurobipy.GurobiError: Variable has not yet been added to the model
我不知道我为什么会收到这个错误,尽管我猜语法正确,但我不知道是否缺少什么。
我在macOS High Sierra上使用Python 3.6.8
。