dirkschumacher / ompr

R package to model Mixed Integer Linear Programs
https://dirkschumacher.github.io/ompr/
Other
268 stars 35 forks source link

Adding a constraint using sum_expr and an index that is dependent on outside variables. #333

Closed sarahjean0659 closed 2 years ago

sarahjean0659 commented 3 years ago

Hello,

I am having issues with adding the below constraint using sum_expr and an index dependent on outside variables. It seems that when computing the choices of w, it isn't able to call the current choices for v, j, and k. Note that s[j,k] is an external data matrix.

add_constraint(sum_expr(sum_expr(b[j,k]*z[r,d,k,v,j,w], w=1:( v-s[j,k])), j=1:2) >= a[r,d,k,v]-u[r,d,k,v], r=1:2, d=1:2,k=1:2, v=1:10)

Is there an existing solution to this? Or do I just need to rewrite this formulation? If so, any suggestions would be appreciated!