简体   繁体   中英

How to assign dummy binary variables in PYOMO

Suppose I have two real variables: X & Y and two binary variables x & y.

I want to add the following constraint pyomo:

when X>0 x--->1 else x-->0
when Y>0 y--->1 else y-->0
and x+y==1

My approach was cons1: x>=X cons2: y>=Y cons3: x+y==1

but the above doesn't seem to work and the values of x and y are random.

Your first two conditions require big M constraints. You can try something like

M_x * x >= X , M_y * y >= Y , and x + y == 1 where M_x and M_y are be constants that you set to values that doesn't unnecessarily bound X and Y. These constraints won't restrict the values of X and Y to 1 and will make x = 1 when X > 0 and y = 1 when Y > 0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM