i am trying to implement an optimization model (mixed integer linear program) using Python-MIP. I am using Pandas DataFrame which contains all necessary information. It's a dynamic scenario, which means at each iteration the DataFrame will go through the optimizer and then update it's information. The model was working fine with simple scenario (when all the data are passing directly to the optimization model without using other functions). However, when i try to pass some column values to other functions and get the updated DataFrame and then feed to the optimization model it keeps showing me the following error. Any suggestion?
def opt_cal(df):
p=pd.Series(np.repeat(2, len(df)))
print("price is\n",p)
w = (df['priority'])
print("value of w \n",w)
I= range(len(df))
print("value of I is",I)
m=(df['mode'])
print("value of m is \n",m)
# optimization process starts
from mip import Model, xsum, maximize, BINARY, GRB
mdl = Model("EV selection", solver_name=GRB)
x = [mdl.add_var(var_type=BINARY) for i in I]
mdl.objective = maximize(xsum(x[i] * w[i] * p[i] for i in I))
mdl += xsum(x[i] * (1 - m[i]) * pr for i in I) + xsum(x[i] * m[i] * pq for i in I) <= cap
mdl += xsum(x[i] for i in I) <= 5
mdl += xsum(soc_n[i] * B[i] + 0.99 * ((1 - m[i]) * pr + m[i] * pq) * x[i] * 15 for i in I) >= 120
mdl += xsum(soc_n[i] * B[i] + 0.99 * ((1 - m[i]) * pr + m[i] * pq) * x[i] * 15 for i in I) <= 24000
mdl.optimize()
s = [i for i in I if x[i].x >= 0.99] # selected EV
dfs = df[df['EV_no'].isin(s)]
print("selected EV for charging at time step", k, ":\n", dfs)
u = [i for i in I if x[i].x != 1]
print("unselected EV for charging at time step", k, ":\n", format(u))
return dfs
Error: I am getting following error message indication the line mdl.objective = maximize(xsum(x[i] * w[i] * p[i] for i in I)) as raise TypeError("Can not multiply with type {}".format(type(other)))
TypeError: Can not multiply with type <class 'pandas.core.series.Series'>