How to properly write a constraint with the right hand side needs to choose among three possible numbers
回答済みI have a constraint with the right-hand side that needs to choose among three possible numbers. Regardless the left handside, my focus now is on the right-hand side. The constraint is shown in the next image. I set the f parameter as follows
f = 1 if i in P else -1 if i in D else 0
Note: Cr contains P and D

By the way, this is my trial for the left- hand side.

-
正式なコメント
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 why not try our AI Gurobot?. -
Hi Sabrin,
Since \( f_i^r \) is indexed by both \( i \) and \( r \), you will need something like a dictionary or a function that maps the different values of \( i \) and \( r \) to their respective \( f \) values. E.g.:
f = {(r, i) : 1 if i in P else -1 if i in D else 0 for r in R for i in Cr[r]}Then, you can use \( \texttt{f[r, i]} \) on the right-hand sides of the constraints.
I see that \( y_{ij}^r \) is dependent on \( r \) in your mathematical formulation. However, in your code, you use \( \texttt{yr[i, j]} \), which has no dependency on \( \texttt{r} \). Is there a reason why the \( \texttt{y} \) variables in your code have no dependency on \( \texttt{r} \)?
Thanks,
Eli
1 -
Thanks a lot I was searching for something like that.
0 -
With regard to the yr[i,j] I have corrected to yr[r,i,j]
0
投稿コメントは受け付けていません。
コメント
4件のコメント