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's gravatar image

gcndn
1112
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

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.

link

answered 01 Jan '14, 13:10

Mike%20Trick's gravatar image

Mike Trick ♦♦
1.0k16
accept rate: 21%

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.

link

answered 01 Jan '14, 16:48

fbahr's gravatar image

fbahr ♦
4.6k716
accept rate: 13%

edited 02 Jan '14, 13:58

thank you very much

link

answered 06 Jan '14, 09:26

gcndn's gravatar image

gcndn
1112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • 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

Asked: 01 Jan '14, 09:27

Seen: 4,639 times

Last updated: 06 Jan '14, 09:26

OR-Exchange! Your site for questions, answers, and announcements about operations research.