[AMPL 15193] If-Else conditions changing original value being compared

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[AMPL 15193] If-Else conditions changing original value being compared

Ishita
Hi there,
I am having trouble with a linearized IF-Else constraint within my code. I have recently started doing conditional linearization operations so kindly bear with me. The code has the following logic--

IF R0<=R<=R1
Then F==F1

ELSE IF R1<=R<=R2
Then F==F2

Where R and F are variables and R1, R2 are parameters

Originally, R is the maximum value from a set of values, obtained by another linearized set of constraints.

Now, after this operation is done, when I check back the R, it changes to that of either R1 or R2, depending on the range of values R falls within. Is this something that is supposed to happen? Also, as I do this operation, I use binary variables as indicators, which I later use for another set of IF-Else operations. If needed I can supply with my actual code that I wrote.
Thanks in advance.
--Ishita

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: [AMPL 15204] If-Else conditions changing original value being compared

Robert Fourer-2
Hi Ishita,

It would be helpful to see the linearization that you use for these if-then-else constraints.  Also it would help to have an example of what you mean when you say, "after this operation is done, when I check back the R, it changes to that of either R1 or R2, depending on the range of values R falls within," to make it clear what you mean by this.

Also it is important to clarify whether R is required to be between R0 and R2, or whether R can be outside this range.

Bob Fourer
[hidden email]

=======

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ishita
Sent: Wednesday, November 22, 2017 3:16 AM
To: AMPL Modeling Language
Subject: [AMPL 15193] If-Else conditions changing original value being compared

I am having trouble with a linearized IF-Else constraint within my code. I have recently started doing conditional linearization operations so kindly bear with me. The code has the following logic--

IF R0<=R<=R1
Then F==F1

ELSE IF R1<=R<=R2
Then F==F2

Where R and F are variables and R1, R2 are parameters

Originally, R is the maximum value from a set of values, obtained by another linearized set of constraints.

Now, after this operation is done, when I check back the R, it changes to that of either R1 or R2, depending on the range of values R falls within. Is this something that is supposed to happen? Also, as I do this operation, I use binary variables as indicators, which I later use for another set of IF-Else operations. If needed I can supply with my actual code that I wrote.


--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [AMPL 15255] If-Else conditions changing original value being compared

Ishita
Hi Bob,
Thanks and sorry for late reply, I fixed the problem on my own, much appreciate your reply!
I however have another If-Else issue to handle, and if I am stuck after sometimes, I will post here.

Have a nice day!

--Ishita

On Friday, November 24, 2017 at 7:10:43 PM UTC+11, Robert Fourer wrote:
Hi Ishita,

It would be helpful to see the linearization that you use for these if-then-else constraints.  Also it would help to have an example of what you mean when you say, "after this operation is done, when I check back the R, it changes to that of either R1 or R2, depending on the range of values R falls within," to make it clear what you mean by this.

Also it is important to clarify whether R is required to be between R0 and R2, or whether R can be outside this range.

Bob Fourer
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="xXhSQ7RRAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@...

=======

From: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="xXhSQ7RRAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@... [mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="xXhSQ7RRAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@...] On Behalf Of Ishita
Sent: Wednesday, November 22, 2017 3:16 AM
To: AMPL Modeling Language
Subject: [AMPL 15193] If-Else conditions changing original value being compared

I am having trouble with a linearized IF-Else constraint within my code. I have recently started doing conditional linearization operations so kindly bear with me. The code has the following logic--

IF R0<=R<=R1
Then F==F1

ELSE IF R1<=R<=R2
Then F==F2

Where R and F are variables and R1, R2 are parameters

Originally, R is the maximum value from a set of values, obtained by another linearized set of constraints.

Now, after this operation is done, when I check back the R, it changes to that of either R1 or R2, depending on the range of values R falls within. Is this something that is supposed to happen? Also, as I do this operation, I use binary variables as indicators, which I later use for another set of IF-Else operations. If needed I can supply with my actual code that I wrote.


--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [AMPL 15263] If-Else conditions changing original value being compared

Ishita
In reply to this post by Robert Fourer-2
Hi Bob,
Thanks for the reply, sorry for getting back late. I thought I had the problem fixed but something went wrong and I am back to square one. So let me type out the problem below.

Say, b is my maximum value among a set of variable values, U is the upper bound of my value range and L is the lower bound, q, r, s are my binary variables, M is big value. So, I need to model the following--
If L<= b<= U, then  q, r are both 1, which in turn goes into an AND operation where s = q AND r

so I divide the comparison constraint condition into two parts--L<= b and b<= U. 
So if L<= b then q = 1 otherwise 0. 
Similarly, if b<= U, then r = 1 otherwise 0.

For, L<= b,
L<= b + M * (1-q)
L>= (b+1) - M * q

For b<= U,
b <= U + M * (1-r)
b >= (U+1) - M * r
 
For AND operation,
0 <= q + r - 2s <=1

So after this is performed, my b doesn't retain its actual value. Instead, b becomes U or L, depending on the constraint it satisfies. Is this something to happen normally? and b should never be outside the range of U and L.

Let me know if you need more information, thanks.
--Ishita

On Friday, November 24, 2017 at 7:10:43 PM UTC+11, Robert Fourer wrote:
Hi Ishita,

It would be helpful to see the linearization that you use for these if-then-else constraints.  Also it would help to have an example of what you mean when you say, "after this operation is done, when I check back the R, it changes to that of either R1 or R2, depending on the range of values R falls within," to make it clear what you mean by this.

Also it is important to clarify whether R is required to be between R0 and R2, or whether R can be outside this range.

Bob Fourer
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="xXhSQ7RRAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@...

=======

From: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="xXhSQ7RRAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@... [mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="xXhSQ7RRAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@...] On Behalf Of Ishita
Sent: Wednesday, November 22, 2017 3:16 AM
To: AMPL Modeling Language
Subject: [AMPL 15193] If-Else conditions changing original value being compared

I am having trouble with a linearized IF-Else constraint within my code. I have recently started doing conditional linearization operations so kindly bear with me. The code has the following logic--

IF R0<=R<=R1
Then F==F1

ELSE IF R1<=R<=R2
Then F==F2

Where R and F are variables and R1, R2 are parameters

Originally, R is the maximum value from a set of values, obtained by another linearized set of constraints.

Now, after this operation is done, when I check back the R, it changes to that of either R1 or R2, depending on the range of values R falls within. Is this something that is supposed to happen? Also, as I do this operation, I use binary variables as indicators, which I later use for another set of IF-Else operations. If needed I can supply with my actual code that I wrote.


--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: [AMPL 15279] If-Else conditions changing original value being compared

Robert Fourer-2
If b is an integer-valued variable and you are trying to linearize the constraint

   L <= b <= U  ==>  s = 1  else  s = 0

then your constraints look right.  But I do not know what you mean when you say, "my b doesn't retain its actual value."  If b is a variable, then when you invoke "solve" the value of b will be set by the solver to the value that it has in some optimal solution, and this may well be different from any value it had before solving.  (Of course if the value of b is fixed then you can make it a param, at which point the value of s is also fixed and can be defined with "param s = if L <= b <= U then 1 else 0".)

Also I do not understand why you state that "b should never be outside the range of U and L."  When you say "if L <= b <= U" you are implying that b might not be between L and U.

Bob Fourer
[hidden email]

=======

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ishita
Sent: Friday, December 1, 2017 8:31 AM
To: AMPL Modeling Language
Subject: Re: [AMPL 15263] If-Else conditions changing original value being compared

Thanks for the reply, sorry for getting back late. I thought I had the problem fixed but something went wrong and I am back to square one. So let me type out the problem below.

Say, b is my maximum value among a set of variable values, U is the upper bound of my value range and L is the lower bound, q, r, s are my binary variables, M is big value. So, I need to model the following--
If L<= b<= U, then  q, r are both 1, which in turn goes into an AND operation where s = q AND r

so I divide the comparison constraint condition into two parts--L<= b and b<= U.
So if L<= b then q = 1 otherwise 0.
Similarly, if b<= U, then r = 1 otherwise 0.

For, L<= b,
L<= b + M * (1-q)
L>= (b+1) - M * q

For b<= U,
b <= U + M * (1-r)
b >= (U+1) - M * r
 
For AND operation,
0 <= q + r - 2s <=1

So after this is performed, my b doesn't retain its actual value. Instead, b becomes U or L, depending on the constraint it satisfies. Is this something to happen normally? and b should never be outside the range of U and L.


--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [AMPL 15301] If-Else conditions changing original value being compared

Ishita
Hi Bob,
Thank you so much, I got the answer to my primary question, that value of b will change to something set by solver as it is a variable. 
As for the other part, sorry what I meant to write is that b must be less or equal than U, as set by an earlier constraint. It was a typo that b must be between L and U, it can very well be lower than L but never more than U.
Maybe I elaborate a little bit. Here, b is a set of m variables calculated within the code itself--it is the maximum value within a set of (m*n) variable values for each m i.e. b is maximum of (X[m] * d[m,n]). I use the following code to calculate this maximum value b--

b[m] >= X[m] * d[m,n]
b[m] <= (X[m] * d[m,n]) + (M *f[m,n]) 

where X,f are binary, d is a parameter constant and M is big value

So does calculation of b look ok or am I missing something? Would much appreciate if you can let me know, thanks!

--Ishita

On Monday, December 4, 2017 at 4:26:32 AM UTC+11, Robert Fourer wrote:
If b is an integer-valued variable and you are trying to linearize the constraint

   L <= b <= U  ==>  s = 1  else  s = 0

then your constraints look right.  But I do not know what you mean when you say, "my b doesn't retain its actual value."  If b is a variable, then when you invoke "solve" the value of b will be set by the solver to the value that it has in some optimal solution, and this may well be different from any value it had before solving.  (Of course if the value of b is fixed then you can make it a param, at which point the value of s is also fixed and can be defined with "param s = if L <= b <= U then 1 else 0".)

Also I do not understand why you state that "b should never be outside the range of U and L."  When you say "if L <= b <= U" you are implying that b might not be between L and U.

Bob Fourer
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="WABQjA_5AgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@...

=======

From: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="WABQjA_5AgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@... [mailto:<a href="javascript:" target="_blank" gdf-obfuscated-mailto="WABQjA_5AgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">am...@...] On Behalf Of Ishita
Sent: Friday, December 1, 2017 8:31 AM
To: AMPL Modeling Language
Subject: Re: [AMPL 15263] If-Else conditions changing original value being compared

Thanks for the reply, sorry for getting back late. I thought I had the problem fixed but something went wrong and I am back to square one. So let me type out the problem below.

Say, b is my maximum value among a set of variable values, U is the upper bound of my value range and L is the lower bound, q, r, s are my binary variables, M is big value. So, I need to model the following--
If L<= b<= U, then  q, r are both 1, which in turn goes into an AND operation where s = q AND r

so I divide the comparison constraint condition into two parts--L<= b and b<= U.
So if L<= b then q = 1 otherwise 0.
Similarly, if b<= U, then r = 1 otherwise 0.

For, L<= b,
L<= b + M * (1-q)
L>= (b+1) - M * q

For b<= U,
b <= U + M * (1-r)
b >= (U+1) - M * r
 
For AND operation,
0 <= q + r - 2s <=1

So after this is performed, my b doesn't retain its actual value. Instead, b becomes U or L, depending on the constraint it satisfies. Is this something to happen normally? and b should never be outside the range of U and L.


--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: [AMPL 15305] If-Else conditions changing original value being compared

Robert Fourer-2
Your constraints to determine b[m] look OK, provided you also have a constraint that forces at least one of the f[m,n] variables to be zero.

Bob Fourer
[hidden email]

=======

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ishita
Sent: Tuesday, December 5, 2017 3:29 AM
To: AMPL Modeling Language
Subject: Re: [AMPL 15301] If-Else conditions changing original value being compared

Thank you so much, I got the answer to my primary question, that value of b will change to something set by solver as it is a variable.

As for the other part, sorry what I meant to write is that b must be less or equal than U, as set by an earlier constraint. It was a typo that b must be between L and U, it can very well be lower than L but never more than U.
Maybe I elaborate a little bit. Here, b is a set of m variables calculated within the code itself--it is the maximum value within a set of (m*n) variable values for each m i.e. b is maximum of (X[m] * d[m,n]). I use the following code to calculate this maximum value b--

b[m] >= X[m] * d[m,n]
b[m] <= (X[m] * d[m,n]) + (M *f[m,n])

where X,f are binary, d is a parameter constant and M is big value

So does calculation of b look ok or am I missing something? Would much appreciate if you can let me know, thanks!


--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.