I went through 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?
Operations Research Stack Exchange is a question and answer site for operations research and analytics professionals, educators, and students. It only takes a minute to sign up.
Sign up to join this communityI went through 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?
in https://github.com/AlexFleischerParis/howtowithopl/blob/master/ceil.mod
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$