How to model y = floor(x)? [duplicate]

I went through the answers to this question: Modeling floor function exactly, but I still do not get how to model y = floor(x). Is that question answered and I just do not see it?

• You are essentially re-asking the same question, so I'd suggest that you ask a more specific version of your question, otherwise this one will probably get closed. Sep 21 '20 at 23:52
• The short answer is that you cannot model a floor function exactly; it fails at the integer values of $x$. Sep 21 '20 at 23:54
• Ok, now I get it. The whole discussion was about proving the statement "you cannot model a floor function exactly." Sep 22 '20 at 8:22
• Hi, this is why I answered. I hope this helps Sep 22 '20 at 12:15

    range r=1..4;

float x[r]=[1.5,4.0,2.0001,5.9999];

dvar int y[r];
dvar float f[r] in 0..0.9999999;

subject to
{
forall(i in r) y[i]==x[i]+f[i];

}

execute
{
writeln(x," ==> ",y);
}

assert forall(i in r) y[i]==ceil(x[i]);

//which gives

//    [1.5 4 2.0001 5.9999] ==>  [2 4 3 6]


I gave an OPL CPLEX example about how to model ceil. Floor is not very different.

range r=1..4;

float x[r]=[1.5,4.0,2.0001,5.9999];

dvar int y[r];
dvar float f[r] in 0..0.9999;

subject to
{
forall(i in r) y[i]==x[i]-f[i];

}

execute
{
writeln(x," ==> ",y);
}

assert forall(i in r) y[i]==floor(x[i]);


I tried finding floor value together with ceil value. c = ceil(x) and f=floor(x)

$$x \leq c \leq x+1$$ $$x \geq f \geq x-1$$

$$c-f \leq 1$$ $$x \leq f + M(c-x)$$ $$x \geq c - M(x-f)$$ $$x\in R^+, c,f \in Z^+$$

Possible cases: Case 1: x=3.9 $$3.9 \leq c \leq 4.9$$ $$3.9 \geq f \geq 2.9$$

$$c-f \leq 1$$ $$3.9 \leq f + M(c-3.9)$$ $$3.9 \geq c - M(3.9-f)$$ Result c=4, f=3

Case 2: x=3.1 $$3.1 \leq c \leq 4.1$$ $$3.1 \geq f \geq 2.1$$

$$c-f \leq 1$$ $$3.1 \leq f + M(c-3.1)$$ $$3.1 \geq c - M(3.1-f)$$ Result c=4, f=3

Case 3: x=3 $$3 \leq c \leq 4$$ $$3 \geq f \geq 2$$

$$c-f \leq 1$$ $$3 \leq f + M(c-3)$$ $$3 \geq c - M(3-f)$$ 3.a. c=4, f=2 is possible from const 1 and 2 but const 3 inf.

3.b. c=4, f=3 is possible from const 1 and 2 but const 5 inf.

3.c. c=3, f=2 is possible from const 1 and 2 but const 4 inf. Therefore c=3, f=3.

M is big number and determines the sensivity of x. For example, x=3.9 , M must be equal or greater than 10. Likewise, if x=3.99, $$M \geq 100$$

• What prevents $(x,y)=(3,2)$? Sep 22 '20 at 14:26
• @RobPratt I gave a new answer, I do not know there is something missed. Sep 22 '20 at 22:50
• Your third constraint is implied by your first two constraints and can be omitted. Also, Case 3 should have 3 instead of 3.1. Sep 22 '20 at 23:48
• I think you will find that $1/M$ plays the same role as $\epsilon$ in the linked question. Sep 23 '20 at 1:32
• You still need to replace 3,1 with 3 in Case 3. And $(c,f)=(4,3)$ is feasible. Sep 23 '20 at 5:54