# how to linearize this function?

 0 Hi! I have got a stock problem and solving it on GAMS but I didnt linearize th function above; if a<=b then c=0 and a=a if a>b then c= a-b and a=b This question is marked "community wiki". asked 01 Jan '14, 09:27 gcndn 11●1●2 accept rate: 0% a is my variable about customer demand if there are not enough stock in warehouse customers all demand doesnot satisfied so there will be lost sales if there are enough stock all "a" (customer demand) will satisfied I meant this and I didnt write it on GAMS b is my stock and c is my loss sales amount (01 Jan '14, 10:03) gcndn

 2 I'm not sure what you are aiming for with the "If a>b then ... a=b". That looks more like a programming structure than a constraint. Can we add a variable s for "sales" so the constraints are If a<=b then c=0 and s = a, and if a>b then c= a-b and s=b ? Then something like s<=a s<=b c>= a-b c>= 0 works if the objective/constraints are such that s naturally maximizes and c naturally minimizes. answered 01 Jan '14, 13:10 Mike Trick ♦♦ 1.0k●1●6 accept rate: 21%
 1 Building on your comment, I'd suggest to rewrite (or, more precisely, shorten) your if-then-expression like: if a <= b then c = 0 else c = a - b  which can be equivalently expressed as: c = max(0, a-b)  [If you need to capture the amount of sales explicitly, s = a - c will do the "trick" -- pun intended.] The max-expression, in turn, can be rewritten ["mip'ed"] as: c >= 0 c >= a - b c <= (a - b) * w c <= (b - a) * (1 - w) w binary  If a, b are data/parameters, you're done. If not -- i. e., a and/or b are variables -- we have two quadratic constraints. Linearizing these directly (as initially suggested -- if you've read this post before) turns out to be a bit cumbersome. Fortunately, though, there's another modeling trick we can use here:  if a <= b then c = 0 else c = a - b <=> if a > b then c = a - b else c = 0 => if a > b then c = a - b (1) and if a <= b then c = 0 (2)  From propositional logic we know: x → y ⊨ ¬ x ∨ y  I. e., (1) <=> a <= b ∨ c = a - b (3) (2) <=> a > b ∨ c = 0 (4)  Let 0 <= a <= U_a, 0 <= b <= U_b, & U_b <= U_a (with U_a, U_b const): (3) + (4) <=> a <= b + U_a * w (5) a >= (b + eps) - (U_b + eps) * (1 - w) (6) c = (a - b) * w (7) w binary eps const, > 0, << 1  Now, the "only" thing left to do is: linearize (7). (7) <=> c >= 0 c <= U_a * w c >= (a - b) - U_a * (1 - w) c <= (a - b) + U_b * (1 - w)  Et voilà! P.S.: As usual, mostly shamelessly copied from @Paul Rubin's blog: ...and AIMMS' modeling guide (chapter on integer programming tricks): Any mistakes are mine, though. answered 01 Jan '14, 16:48 fbahr ♦ 4.6k●7●17 accept rate: 13%
 0 thank you very much answered 06 Jan '14, 09:26 gcndn 11●1●2 accept rate: 0%
 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:

×231
×51