Re: Constraint for: If x>0 then y=1

499 views
Skip to first unread message

Bob Pay

unread,
Oct 29, 2012, 2:14:48 PM10/29/12
to gams...@googlegroups.com
Hi
try this, maybe it helps:

x < M y
x> y

if x is positive, second is not considered, and from first, for example x =10, 10 < M y ,and in result, y must be 1 to meet constraint.

if x = 0, then first constrain is not considered, but second constrain, 0 > y, as y is binary, it takes value 0.

I am not sure about it.

you can check H.P Williams book, Model Building for more details.



On Mon, Oct 29, 2012 at 8:46 PM, JapanGo <markus...@googlemail.com> wrote:
Hello GAMS community,

I am trying to find a constraint solution for the case:

if x>0 then y=1
where x is a positive integer variable and y is a binary variable.
Thus in cases where x=0 also y=0

I tried several combination (including big M, -y, (1-y) formulations etc.) but do not get to the wanted result. Maybe it is not possible with a single constraint, but needs two?

Would be great to get your opinions on it. Thanks!

--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/TmhGHHfdrsYJ.
To post to this group, send email to gams...@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.



--
Babak Saleck Pay
M.Sc
Socio-Economic System Engineering
Group of Industrial Engineering
University of Tehran
Tehran,Iran

Destin Zed

unread,
Oct 30, 2012, 5:20:34 AM10/30/12
to gams...@googlegroups.com
JapanGo,

Modification to Bob's formulation.

y >= EPSILON*x
y <= x

If x equals 10, then y >= EPSILON and y <= 10 which forces y to have only a value of 1. On the other hand, if x is zero, y >= 0 and y <= 0 which forces y to be 0.

I hope this works for you.

Destin

Destin Zed

unread,
Nov 16, 2012, 12:27:12 PM11/16/12
to gams...@googlegroups.com
But that is non-linear!

On Thu, Nov 15, 2012 at 1:42 PM, HJW Vermue <hjwv...@gmail.com> wrote:
Regardless of what I wrote before, I obviously meant y>=min(x,1), as that does fulfill the requirements stated.


On Tuesday, October 30, 2012 10:59:33 AM UTC+1, JapanGo wrote:
Hello Destin,
hello Babak,

thanks to both of you. The adaption of Destin made it work.
As a feedback to the community: One can also model the constraint with big M:
yM >= x
y <= x
To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/5QkqUvVb-ZkJ.

Guangjian Liu

unread,
Jan 22, 2013, 8:16:35 AM1/22/13
to gams...@googlegroups.com


发自我的 iPad

在 2012-11-15,20:42,HJW Vermue <hjwv...@gmail.com> 写道:

Regardless of what I wrote before, I obviously meant y>=min(x,1), as that does fulfill the requirements stated.

On Tuesday, October 30, 2012 10:59:33 AM UTC+1, JapanGo wrote:
Hello Destin,
hello Babak,

thanks to both of you. The adaption of Destin made it work.
As a feedback to the community: One can also model the constraint with big M:
yM >= x
y <= x


Am Dienstag, 30. Oktober 2012 10:22:47 UTC+1 schrieb Destin Zed:
To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/5QkqUvVb-ZkJ.

Sina Zabihi

unread,
Mar 17, 2015, 8:27:24 AM3/17/15
to gams...@googlegroups.com
hello dears
maybe this constrains help you
y>=epsilon*x
y<=big M*x
Reply all
Reply to author
Forward
0 new messages