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
-
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 try Gurobot, our chatbot interface offering instant, expert-level support. -
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
Post is closed for comments.
Comments
5 comments