# having problem in modeling of if then else binary variables

 2 1 Hi, I am trying to model a problem: if 4.5<=s<=7.3 (s is a continuous variable) then x4=x5=x6=x7=1 else x1=x2=x3=x8=x9=x10=0. xi (1=1...10) are binary variables regarding periods 1 to 10. in fact, I want to make all x variables within time periods int(4.5) and int(7.3) get 1 others zero. (int is floor function eg int(5.1)=5, int(9.8)=9, int(3)=3) Thanks asked 17 Feb '13, 16:15 hesameivazy 71●6 accept rate: 0% I am wondering how would be the most efficient (least # of binary variables) while bounds of s (L, U) are known, 7.3 and 4.5 are not known (they are two continuous variables). I mean if a<=s<=b then x(i)=1 every i<=ceiling (b) and floor (a)<=i else x(i)=0 a and b are two continuous variables thanks (19 Feb '13, 11:46) hesameivazy I believe my answer does the job for you. (19 Feb '13, 11:58) Marco Luebbecke ♦

 4 Assume that $$L$$ and $$U$$ are known lower/upper bounds for $$s$$ (so that $$L\le s \le U$$). Define three new binary variables $$y_1, y_2, y_3$$ and add the constraints $$Ly_{1}+4.5y_{2}+7.3y_{3} \le s\le 4.5y_{1}+7.3y_{2}+Uy_{3}$$ and $$y_{1}+y_{2}+y_{3} = 1$$. Now constrain $$x_i\ge y_2$$ for $$i=4,\dots,7$$ and $$x_i\le 1-y_2$$ for $$i\in\{1,2,3,8,9,10\}$$. answered 17 Feb '13, 17:53 Paul Rubin ♦ 11.9k●4●12 accept rate: 19% 1 Seems like Paul's last constraint should be $$x_i \le y_2$$ instead of $$x_i \le 1 - y_2$$. (18 Feb '13, 18:11) Rob Pratt @Rob: Don't think so. $$y_2 = 1$$ if $$4.5\le s \le 7.3$$, in which case you want $$x_i = 0$$ for $$i\in \{1,2,3,8,9,10\}$$. Your change would let those $$x_i$$ equal 1. (18 Feb '13, 18:15) Paul Rubin ♦ OK, then the OP's "else" should instead be "and" (18 Feb '13, 18:18) Rob Pratt 1 Good point. Maybe I misread the question. If he does mean else (and means $$x_4,\dots,x_7$$ are unrestricted for $$s\notin [4.5,7.3]$$ and the other $$x_i$$ are unrestricted for $$x\in [4.5,7.3]$$, then you're right: the last constraint should be $$x_i\le y_2$$. (18 Feb '13, 18:37) Paul Rubin ♦ If s=7.3, wouldn't it also be possible that y3=1 too?? (07 Oct '14, 11:26) hfahad108 Yes. Avoiding that in practice requires ruling out values between 7.3 and $$7.3 + \epsilon$$ for some small $$\epsilon >0$$ (but not too small - needs to be larger than rounding error). (07 Oct '14, 16:16) Paul Rubin ♦ @Paul ... Many Thanks for your reply I am also wondering what will limit x_i to 0 if y_2 is 0 ? as x_i =1 is also >= y_2 (07 Oct '14, 21:00) hfahad108 I think the last comment under my answer covers that. There is/was some confusion about what the original poster meant. (08 Oct '14, 09:44) Paul Rubin ♦ showing 5 of 8 show 3 more comments
 1 @hesameivazy, were you looking for something more general? With @paul's $$L$$ and $$U$$, you may need $$x_{i}\leq s/i$$, $$x_{i}\leq (U-s)/(U-i)$$, $$x_{i}\geq i/s$$ answered 18 Feb '13, 15:55 Marco Luebbecke ♦ 3.2k●1●5●15 accept rate: 15% Yes I am looking for a more general formulation. (19 Feb '13, 11:40) hesameivazy
 toggle preview community wiki

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Tags: