|
19 | 19 | import org.chocosolver.solver.variables.IntVar; |
20 | 20 | import org.chocosolver.solver.variables.events.IntEventType; |
21 | 21 | import org.chocosolver.util.ESat; |
| 22 | +import org.chocosolver.util.tools.MathUtils; |
22 | 23 |
|
23 | 24 | /** |
24 | 25 | * Z = ceil(X/Y) |
@@ -95,31 +96,30 @@ public void propagate(int evtmask) throws ContradictionException { |
95 | 96 | int z_max = Z.getUB(); |
96 | 97 |
|
97 | 98 | // z >= ceil(x.min / y.max) |
98 | | - hasChanged = Z.updateLowerBound((x_min + y_max - 1) / y_max, this, |
| 99 | + hasChanged = Z.updateLowerBound(MathUtils.safeAdd(x_min, y_max - 1) / y_max, this, |
99 | 100 | lcg() ? Reason.r(X.getMinLit(), Y.getMaxLit()) : Reason.undef()); |
100 | 101 | // z <= ceil(x.max / y.min) |
101 | | - hasChanged |= Z.updateUpperBound((x_max + y_min - 1) / y_min, this, |
| 102 | + hasChanged |= Z.updateUpperBound(MathUtils.safeAdd(x_max, y_min - 1) / y_min, this, |
102 | 103 | lcg() ? Reason.r(X.getMaxLit(), Y.getMinLit()) : Reason.undef()); |
103 | 104 |
|
104 | 105 | // x >= y.min * (z.min - 1) + 1 |
105 | | - hasChanged |= X.updateLowerBound(y_min * (z_min - 1) + 1, this, |
| 106 | + hasChanged |= X.updateLowerBound(MathUtils.safeMultiply(y_min, (z_min - 1)) + 1, this, |
106 | 107 | lcg() ? Reason.r(Y.getMinLit(), Z.getMinLit()) : Reason.undef()); |
107 | 108 | // x <= y.max * z.max |
108 | | - hasChanged |= X.updateUpperBound(y_max * z_max, this, |
| 109 | + hasChanged |= X.updateUpperBound(MathUtils.safeMultiply(y_max, z_max), this, |
109 | 110 | lcg() ? Reason.r(Y.getMaxLit(), Z.getMaxLit()) : Reason.undef()); |
110 | 111 |
|
111 | 112 | // y >= ceil(x.min / z.max) |
112 | 113 | if (z_max >= 1) { |
113 | | - hasChanged |= Y.updateLowerBound((x_min + z_max - 1) / z_max, this, |
| 114 | + hasChanged |= Y.updateLowerBound(MathUtils.safeAdd(x_min, z_max - 1) / z_max, this, |
114 | 115 | lcg() ? Reason.r(X.getMinLit(), Z.getMaxLit()) : Reason.undef()); |
115 | 116 | } |
116 | 117 |
|
117 | 118 | // y <= ceil(x.max / z.min-1) - 1 |
118 | 119 | if (z_min >= 2) { |
119 | | - hasChanged |= Y.updateUpperBound((x_max + z_min - 2) / (z_min - 1) - 1, this, |
| 120 | + hasChanged |= Y.updateUpperBound(MathUtils.safeAdd(x_max, z_min - 2) / (z_min - 1) - 1, this, |
120 | 121 | lcg() ? Reason.r(X.getMaxLit(), Z.getMinLit()) : Reason.undef()); |
121 | 122 | } |
122 | | - |
123 | 123 | } while (hasChanged); |
124 | 124 | } |
125 | 125 |
|
|
0 commit comments