0

This is for a model in gams,

I have a binary variable (B(N)) and a real variable (u(N)), where N is a set. I want the binary variable to equal zero when u is zero, and to equal one when u isn't zero.

This would be easy if I could use 'if' statements but I can't use them in the model equations, so it needs to be done with math logic...

John B
  • 1
  • 4

2 Answers2

0

It's ok! I found a solution:

B(N) =L= rel_ne(u(N),0)
B(N) =G= rel_ne(u(N),0)

This seams to be working fine. It's probably not the most elegant solution but whatever.

rel_ne returns 1 if u(N) is not equal to 0, and returns 0 otherwise.

John B
  • 1
  • 4
0

I think another possibility to model that situation is the following:

B(N)*LB(N) =L= u(N) B(N)*UB(N) =G= u(N)

Where UB(N) is an upper bound and LB(N) a lower bound for the u(N) real variable. So, when u(N) is 0, B(N) is 0, and for a positive u(N) value, B(N) values 1.

In case you do not have explicit Upper/Lower Bounds, just set 0 for LB and a large number for UB.