Error: ufunc 'subtract' cannot use operands with types dtype('<M8[ns]') and dtype('O')
AnsweredI encountered this error while trying to solve a VRP. I am not very sure how to convert the date time and gurobi var such that they can subtract each other
-
variable t is tupledict while arrivaltime is timedate64. that is why subtraction not possible. any idea how to convert
0 -
Could you please generate a minimal reproducible example showing the issue? Currently, it is not possible to execute your code, because all data is missing.
Other than that, it does not seem to be a Gurobi issue but rather a data type issue. You should try to track down which subtraction exactly is responsible for the error.
Best regards,
Jaromił0 -
This variable gives a datatype of datetime64[ns]arrival=np.array(data["Vessel Arrival Time"])This variable gives a datatype of gurobi.vart=model.addVars(vessel_number,vtype=GRB.CONTINUOUS ,name="t")I get this when I check the first index of tt[0]<gurobi.Var *Awaiting Model Update*><gurobi.Var *Awaiting Model Update*>The subtraction that caused the error isconstraint5=model.addConstrs(w[i]>=arrival[i]-t[i]for i in range(vessel_number) )0
-
The error occurs because it is not possible to subtract/add Gurobi optimization variables from/to a datetime64[ns] object. You have to somehow convert your arrival values to numerical values. This stackoverflow thread should be helpful.
Best regards,
Jaromił0
Please sign in to leave a comment.
Comments
4 comments