Unsupported operand type for =-: nonetype and float
AnsweredHi,
I am having a problem with the following part of my code. I am using a generator constraint to check if m[i,j,k] is true. If so, another variable dist_var should become the value as indicated, which is taken from a pandas dataframe. However, every time I run this it gives me the following error:
TypeError: unsupported operand type(s) for -=: 'NoneType' and 'float'
for i in SHORT_LOC_list:
for j in SHORT_LOC_list:
for k in SHORT_LOC_list:
if i != j != k:
if dist_data.at[i, k] >= dist_data.at[j, k]:
model_1.addGenConstrIndicator(m3[i, j, k], True, dist_var[i, k] == dist_data.at[j, k])
I have checked the dtypes of the dataframe and it says all types are floats. Although I do not know for sure, I suspect the problem lies in the NoneType. The variable dist_var I have created in the following way:
dist_var = model_1.addVars(SHORT_LOC_list, SHORT_LOC_list, vtype=GRB.CONTINUOUS, name='dist_var')
Any idea what might be going wrong?
Thanks in advance
-
Official comment
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?. -
Hi Matthijs,
The error indicates that it comes from the wrong usage of the '-' operator. Are you sure that the error comes from the general constraints? Could you post the whole error message? Could you also provide a minimum working example which reproduces the error?
Best regards,
Jaromił0 -
Hi Jaromil,
I think I have found the problem myself. It appears that I accidentally set the value of dist_var somewhere in my code beforehand and it did not let me change it again (I mistyped the error in my title, it was a -= error). I have now changed it so that this does not occur.
Thanks for your reply and sorry for your troube,
Matthijs
0
Post is closed for comments.
Comments
3 comments