@Test(timeOut = 60000, groups = "1s", expectedExceptions = ContradictionException.class) public void testSelectValue2() throws ContradictionException { Model model = new Model(); IntVar x = model.intVar("x", new int[]{0, 3, 5, 6, 7, 8, 11}); int[] order = {7, 6, 8, 5, 3, 11, 0}; IntDomainMiddle sel = new IntDomainMiddle(v -> 7, true); int i = 0; while (x.getDomainSize() > 0) { int val = sel.selectValue(x); Assert.assertEquals(val, order[i++]); x.removeValue(val, Cause.Null); } }
@SuppressWarnings("PointlessBooleanExpression") @Override public int selectValue(IntVar var) { double mean = middle.applyAsDouble(var); int value; if (roundingPolicy == FLOOR) { value = (int) Math.floor(mean); } else { value = (int) Math.ceil(mean); } if (var.hasEnumeratedDomain()) { if (!var.contains(value)) { double a = var.previousValue(value); double b = var.nextValue(value); if (mean - a < b - mean) { return (int) a; } else if (mean - a > b - mean) { return (int) b; } else { if (roundingPolicy == FLOOR) { return (int) a; } else { return (int) b; } } } } return value; }
IntDomainMiddle implements IntValueSelector { @SuppressWarnings("PointlessBooleanExpression") @Override public int selectValue(IntVar var) { double mean = middle.applyAsDouble(var); int value; if (roundingPolicy == FLOOR) { value = (int) Math.floor(mean); } else { value = (int) Math.ceil(mean); } if (var.hasEnumeratedDomain()) { if (!var.contains(value)) { double a = var.previousValue(value); double b = var.nextValue(value); if (mean - a < b - mean) { return (int) a; } else if (mean - a > b - mean) { return (int) b; } else { if (roundingPolicy == FLOOR) { return (int) a; } else { return (int) b; } } } } return value; } }
IntDomainMiddle implements IntValueSelector { @SuppressWarnings("PointlessBooleanExpression") @Override public int selectValue(IntVar var) { double mean = middle.applyAsDouble(var); int value; if (roundingPolicy == FLOOR) { value = (int) Math.floor(mean); } else { value = (int) Math.ceil(mean); } if (var.hasEnumeratedDomain()) { if (!var.contains(value)) { double a = var.previousValue(value); double b = var.nextValue(value); if (mean - a < b - mean) { return (int) a; } else if (mean - a > b - mean) { return (int) b; } else { if (roundingPolicy == FLOOR) { return (int) a; } else { return (int) b; } } } } return value; } IntDomainMiddle(boolean roundingPolicy);  IntDomainMiddle(ToDoubleFunction<IntVar> middle, boolean roudingPolicy); }
IntDomainMiddle implements IntValueSelector { @SuppressWarnings("PointlessBooleanExpression") @Override public int selectValue(IntVar var) { double mean = middle.applyAsDouble(var); int value; if (roundingPolicy == FLOOR) { value = (int) Math.floor(mean); } else { value = (int) Math.ceil(mean); } if (var.hasEnumeratedDomain()) { if (!var.contains(value)) { double a = var.previousValue(value); double b = var.nextValue(value); if (mean - a < b - mean) { return (int) a; } else if (mean - a > b - mean) { return (int) b; } else { if (roundingPolicy == FLOOR) { return (int) a; } else { return (int) b; } } } } return value; } IntDomainMiddle(boolean roundingPolicy);  IntDomainMiddle(ToDoubleFunction<IntVar> middle, boolean roudingPolicy); @SuppressWarnings("PointlessBooleanExpression") @Override int selectValue(IntVar var); }
IntDomainMiddle implements IntValueSelector { @SuppressWarnings("PointlessBooleanExpression") @Override public int selectValue(IntVar var) { double mean = middle.applyAsDouble(var); int value; if (roundingPolicy == FLOOR) { value = (int) Math.floor(mean); } else { value = (int) Math.ceil(mean); } if (var.hasEnumeratedDomain()) { if (!var.contains(value)) { double a = var.previousValue(value); double b = var.nextValue(value); if (mean - a < b - mean) { return (int) a; } else if (mean - a > b - mean) { return (int) b; } else { if (roundingPolicy == FLOOR) { return (int) a; } else { return (int) b; } } } } return value; } IntDomainMiddle(boolean roundingPolicy);  IntDomainMiddle(ToDoubleFunction<IntVar> middle, boolean roudingPolicy); @SuppressWarnings("PointlessBooleanExpression") @Override int selectValue(IntVar var); final static boolean FLOOR; }