GurobiError: Unsupported type (<class 'str'>) for LinExpr addition argument
ユーザーの入力を待っています。I have got this error, and I do not know what should I do.
# constants
numHub = len(C)
numCensustracts =len(df['D'])
#Set of hubs
H=np.arange(0,numHub)
# Set of census tracts
CT=np.arange(0,numCensustracts)
# first constraint
for j in CT:
m.addConstr(sum(x[i,j] for i in H)+ r[j]== df.D[j])
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Can you please post a full working code example that reproduces this issue? I.e., one that includes the definitions of \( \texttt{r} \), \( \texttt{df} \), \( \texttt{H} \), etc.
The error message states you are trying to add a \( \texttt{str} \) object to a linear expression object. I suspect that for some (or all) \( \texttt{j} \) in \( \texttt{CT} \), \( \texttt{r[j]} \) or \( \texttt{df.D[j]} \) is a \( \texttt{str} \) instead of a number. Here is an easy way to double-check the types of the elements in \( \texttt{r} \) and \( \texttt{df.D} \):
for j in CT:
print(f'r[{j}] = {r[j]}, {type(r[j])}')
print(f'df.D[{j}] = {df.D[j]}, {type(df.D[j])}')0
投稿コメントは受け付けていません。
コメント
2件のコメント