binary variable zero when the difference between two continuous is zero

54 views
Skip to first unread message

J C

unread,
Oct 10, 2021, 9:36:15 AM10/10/21
to AMPL-group
Hello everyone!

I have the next set of constraints:

1) 0 <= x(t) <= A;
2) x(t) - x(t-1) <= B*yup(t)
3) x(t-1) - x(t) <= B*ydw(t),
where x is a continuous variable, yup, ydw are binary variables, A and B are positive parameters.
The constraints work well while x(t) < A. But when x(t) = A the  constraints 2 and 3 have x(t) = x(t-1) which implies that yup(t) and ydw(t) must be zero, however  the binary variables take values of 1 in some periods. 

I am thinking in establish a new constraint like this x(t) - x(t-1) = z(t) where z should be a continuous variable that measure the difference between x(t) and x(t-1) and use new auxiliary binary variables to define when x(t) - x(t-1) = 0 or x(t) - x(t-1) > 0.

Anyone have some ideias?

Regards


AMPL Google Group

unread,
Oct 11, 2021, 12:01:29 PM10/11/21
to AMPL Modeling Language
Consider constraint (2) in particular. It expresses the following restriction:

(2a)
either yup[t] = 0 and x[t] - x[t-1] <= 0
    or yup[t] = 1 and x[t] - x[t-1] <= B

I guess this is not acceptable for your model, because when x[t] = x[t-1] it allows both yup[t] = 0 and yup[t] = 1. But I am not sure how you want to fix it. How would you change (2a) so that it is the correct restriction for your model?


--
Robert Fourer
am...@googlegroups.com
{#HS:1656502147-106638#}

J C

unread,
Oct 11, 2021, 1:31:37 PM10/11/21
to AMPL-group
Dear Robert,

Thanks for your response,

The original constraints are 

1) 0 <= x(t) <= A;
2) -B*ydw(t) <= x(t) - x(t-1) <= B*yup(t)

For example:
Of the constraint (2) it seems that:
When x(t-1) = 5 and x(t)=10, yup(t)=1 and ydw=0, because the difference x(t) - x(t-1) is positive. Now  when x(t-1) = 10 and x(t)=5, yup(t)=0 and ydw=1, because the difference x(t) - x(t-1) is negative. Acts only one binary variable at time. When there are differences between x(t) and x(t-1) all is ok in the model, but if for example t-1) = 5 and x(t)=5, any binary variable should be activate, due there is not change, however, in some periods when there is not change the any binary variable seems active. I am thinking that the (2) says when binary variables are 1, but does not say anything about when it is zero. Similar to x(t) - x(t-1) >= 0.0001*yaux.

Regards




--
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 ampl+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ampl/reply-77152-1656502147-4839691038-1633968084-57735778%40helpscout.net.

AMPL Google Group

unread,
Oct 12, 2021, 4:36:06 PM10/12/21
to AMPL Modeling Language
Your constraint (2) implies the following:
  • When x[t] - x[t-1] > 0, then yup[t] = 1, but ydw[t] can be either 0 or 1.
  • When x[t] - x[t-1] < 0, then ydw[t] = 1, but yup[t] can be either 0 or 1.
  • When x[t] = x[t-1], yup[t] can be either 0 or 1, and ydw[t] can be either 0 or 1.
To restrict the binary variables more nearly in the way that you describe, you could add constraint (3) yup[t] + ydn[t] = 1. Then (2) and (3) together imply:
  • When x[t] - x[t-1] > 0, then yup[t] = 1 and ydw[t] = 0.
  • When x[t] - x[t-1] < 0, then ydw[t] = 1 and yup[t] = 0.
  • When x[t] = x[t-1], then either yup[t] = 1 and ydw[t] = 0, or else ydw[t] = 1 and yup[t] = 0.
However it is not possible (when using linear constraints) to say that when x[t] = x[t-1], both yup[t] and ydw[t] must be 0.


--
Robert Fourer
am...@googlegroups.com
{#HS:1656502147-106638#}
On Mon, Oct 11, 2021 at 5:31 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Dear Robert,

Thanks for your response,

The original constraints are

1) 0 <= x(t) <= A;
2) -B*ydw(t) <= x(t) - x(t-1) <= B*yup(t)

For example:
Of the constraint (2) it seems that:
When x(t-1) = 5 and x(t)=10, yup(t)=1 and ydw=0, because the difference x(t) - x(t-1) is positive. Now when x(t-1) = 10 and x(t)=5, yup(t)=0 and ydw=1, because the difference x(t) - x(t-1) is negative. Acts only one binary variable at time. When there are differences between x(t) and x(t-1) all is ok in the model, but if for example t-1) = 5 and x(t)=5, any binary variable should be activate, due there is not change, however, in some periods when there is not change the any binary variable seems active. I am thinking that the (2) says when binary variables are 1, but does not say anything about when it is zero. Similar to x(t) - x(t-1) >= 0.0001*yaux.

Regards

On Mon, Oct 11, 2021 at 4:01 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
Consider constraint (2) in particular. It expresses the following restriction:

(2a)
either yup[t] = 0 and x[t] - x[t-1] <= 0
    or yup[t] = 1 and x[t] - x[t-1] <= B

I guess this is not acceptable for your model, because when x[t] = x[t-1] it allows both yup[t] = 0 and yup[t] = 1. But I am not sure how you want to fix it. How would you change (2a) so that it is the correct restriction for your model?


--
Robert Fourer
am...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages