Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit 163b44f

Browse files
committed
[#112] ortools-backend: temporarily avoid overflow issues in o.mult()
Signed-off-by: Lalith Suresh <[email protected]>
1 parent b939c0f commit 163b44f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

dcm/src/main/java/com/vmware/dcm/backend/ortools/Ops.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,10 @@ public IntVar mult(final IntVar left, final int right) {
252252
final Domain domain = left.getDomain();
253253
final long lDomainMinResult = domain.min() * right;
254254
final long lDomainMaxResult = domain.max() * right;
255-
final long lb = Math.min(lDomainMinResult, lDomainMaxResult);
256-
final long ub = Math.max(lDomainMinResult, lDomainMaxResult);
255+
256+
// Conservative. Should be fixed with: https://github.com/vmware/declarative-cluster-management/issues/112
257+
final long lb = Math.max(Math.min(lDomainMinResult, lDomainMaxResult), Integer.MIN_VALUE);
258+
final long ub = Math.min(Math.max(lDomainMinResult, lDomainMaxResult), Integer.MAX_VALUE);
257259
final IntVar ret = model.newIntVar(lb, ub, "");
258260
model.addEquality(ret, LinearExpr.term(left, right));
259261
return ret;
@@ -266,8 +268,10 @@ public IntVar mult(final IntVar left, final IntVar right) {
266268
final long lDomainMax = lDomain.max();
267269
final long rDomainMin = rDomain.min();
268270
final long rDomainMax = rDomain.max();
269-
final long lb = Math.min(lDomainMin * rDomainMin, lDomainMax * rDomainMax);
270-
final long ub = Math.max(lDomainMin * rDomainMin, lDomainMax * rDomainMax);
271+
272+
// Conservative. Should be fixed with: https://github.com/vmware/declarative-cluster-management/issues/112
273+
final long lb = Math.max(Math.min(lDomainMin * rDomainMin, lDomainMax * rDomainMax), Integer.MIN_VALUE);
274+
final long ub = Math.min(Math.max(lDomainMin * rDomainMin, lDomainMax * rDomainMax), Integer.MAX_VALUE);
271275
final IntVar ret = model.newIntVar(lb, ub, "");
272276
model.addProductEquality(ret, new IntVar[]{left, right});
273277
return ret;

dcm/src/test/java/com/vmware/dcm/ModelTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,6 @@ public void testStringCodeGen() {
16861686
final Model model = Model.build(conn, views);
16871687
model.updateData();
16881688
final Result<? extends Record> t1 = model.solve("T1");
1689-
System.out.println(t1);
16901689
assertEquals(42, t1.get(0).get(1));
16911690
}
16921691

0 commit comments

Comments
 (0)