I am trying to maximize the division of two quantities in PySCIPOpt. Since it is a division of two linear metrics, it becomes a nonlinear optimization.
My code is somewhat like this:
model = Model()
x={}
for i in range(0,len(data)):
x[i] = model.addVar(vtype = 'B',name = 'x(%s)'%i)
data['Index'] = range(0,len(data))
profit = 0
volume = 0
for index in data['Index']:
profit += x[index] * data['Predicted.Profit'][index]
volume += x[index] * data['Predicted.Liters.Sold'][index]
model.setObjective(profit/volume,"maximize")
As soon as I hit the setObjective
command, my kernel gets busy for more than 20 minutes and just keeps working. I want to know is there something wrong with my definition of Objective function? Could I be doing something else? Something more efficient?
By the way, my dataset's shape is 178848x36
edit
The function ran after twenty minutes! But gave an error saying : AssertionError: given coefficients are neither Expr or number but ProdExpr
How do i Bypass this error? Since I wish to optimize the division of decisionVariables! As well as make this objective function declaration more efficient?
Edit2
Is there a way to cast ProdExpr as Expr??