objective function with nested sum
Awaiting user inputI have an objective function with multiple operations for which I tried nesting with help of quicksum (below):
X, I, Y, and B are model variables
I have tried the following code which works but the answer is not correct. seems something in the prioritization of operations goes wrong but I cannot detect where.
obj1 = gp.quicksum((I[month,item] - v[item]) * h[item] * X[month,item]
for item in items
for month in months
if month >= months[a +1])
obj2 = gp.quicksum((B[month,item] + v[item]) * p[item] * Y[month,item]
for item in items
for month in months
if month >= months[a +1])
obj = obj1 + obj2
LP.setObjective(obj, GRB.MINIMIZE)
P.S. I have tried https://support.gurobi.com/hc/en-us/community/posts/4413382171921-Values-of-parts-of-objective-function as well but the code gives error.
0
-
Hi Maryam,
It is hard to know what has gone wrong. Could you please clarify the following in the mathematical expression?
- The argument of the \(\mbox{min}\) function is \(r_i(t)\), but there is no variable named \(r_i(t)\) in the expression.
- The first sum goes over \(s\) but there is no variable in the expression that depends on \(s\). I assume that \(s\) represents what you are referring to as \(\texttt{months}\), but what \(a\) is then?
- The first term starts from \(s=0\) and the second term starts from \(s=1\), but in the code, both terms apparently are summed over the same set of \(s\) values (months).
Best regards,
Maliheh
0
Please sign in to leave a comment.
Comments
1 comment