0

suppose we have a quantity variable x (which is upperbounded by n), and a logic variable y which is equal to

y = 1 if x >= s; where s is a generic number

y = 0 otherwise => if x is strictly lesser than s => if x < s


Surfing around on the internet I found out this clear explanation https://youtu.be/iQ3PlKKorXA?t=35 which turned out to be the common pattern about either-or constraint. Therefore following the video, the solution would be:

s - x <= (1 - y)*n

x - s <= y*n

And yet x could be equal to s in both the cases.
How can we fix this?

Matteo
  • 1

2 Answers2

1

You can consider the following two constraints:

x-s ≤ My - ɛ(1-y) 
s-x ≤ M(1-y) 

where M is a sufficiently large upper bound and ɛ is a small positive constant.

The first enforce the logical constraint if x >= s then y = 1 and the second the constraint if x < s then y = 0.

Note that these are often referred to as indicator constraints and are supported by several solvers (e.g., cplex) with advantages in terms of a more numerically stable model.

abc
  • 11,579
  • 2
  • 26
  • 51
  • thk for your answer. Can you link some references? – Matteo Dec 30 '21 at 00:02
  • btw I was looking for sth more theoretical instead of using machine precision de facto. Machine precision could vary from architecture to architecture therefore the result is not unique – Matteo Dec 30 '21 at 00:09
  • 1
    @Matteo In practice, there are feasibility tolerances involved. So talking about machine precision is just not appropriate. – Erwin Kalvelagen Dec 31 '21 at 02:44
1

With many solvers you can use logical constraints.

For example with CPLEX OPL you can write

int s=3;
dvar int x;
dvar boolean y;

subject to
{
  y==(x>=s);
}
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • thx for your answer, but that wasn't my point. My concern is not about how to write it on a solver. I'd like a full mathematical answer, Obviously `y==(x>=s)` is not in mathematical language – Matteo Dec 30 '21 at 11:38
  • first we declare a unique mathematic way which doesn't rely on eps due to finite arithmetic (take a look at the answer above) – Matteo Dec 30 '21 at 11:41