Package util.iterators

Examples of util.iterators.DisposableValueIterator


            }
        } else {
            if (variable.hasEnumeratedDomain()) {
                bests.clear();
                double bestVal = Double.MAX_VALUE;
                DisposableValueIterator it = variable.getValueIterator(true);
                while (it.hasNext()) {
                    int value = it.next();
                    double current = vAct[currentVar].activity(value);
                    if (current < bestVal) {
                        bests.clear();
                        bests.add(value);
                        bestVal = current;
View Full Code Here


    }

    @Override
    public void explain(VariableState what, Explanation to) {
        AntiDomain invdom = solver.getExplainer().getRemovedValues(this);
        DisposableValueIterator it = invdom.getValueIterator();
        while (it.hasNext()) {
            int val = it.next();
            if ((what == VariableState.LB && val < this.getLB())
                    || (what == VariableState.UB && val > this.getUB())
                    || (what == VariableState.DOM)) {
//                System.out.println("solver.explainer.explain(this,"+ val +") = " + solver.explainer.explain(this, val));
                to.add(solver.getExplainer().explain(this, val));
            }
        }
        it.dispose();
//        System.out.println("BitsetIntVarImpl.explain " + this + invdom +  " expl: " + expl);
    }
View Full Code Here

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    @Override
    public DisposableValueIterator getValueIterator(boolean bottomUp) {
        if (_viterator == null || !_viterator.isReusable()) {
            _viterator = new DisposableValueIterator() {

                int index;

                @Override
                public void bottomUpInit() {
View Full Code Here

    @Test(groups = "1s")
    public void testBool1() {
        Solver solver = new Solver();
        BoolVar var = VariableFactory.bool("b", solver);
        DisposableValueIterator vit = var.getValueIterator(true);
        Assert.assertTrue(vit.hasNext());
        Assert.assertEquals(0, vit.next());
        Assert.assertTrue(vit.hasNext());
        Assert.assertEquals(1, vit.next());
        Assert.assertFalse(vit.hasNext());
    }
View Full Code Here

    @Test(groups = "1s")
    public void testBool2() {
        Solver solver = new Solver();
        BoolVar var = VariableFactory.bool("b", solver);
        DisposableValueIterator vit = var.getValueIterator(false);
        Assert.assertTrue(vit.hasPrevious());
        Assert.assertEquals(1, vit.previous());
        Assert.assertTrue(vit.hasPrevious());
        Assert.assertEquals(0, vit.previous());
        Assert.assertFalse(vit.hasPrevious());
    }
View Full Code Here

    @Test(groups = "1s")
    public void testBound1() {
        Solver solver = new Solver();
        IntVar var = VariableFactory.bounded("b", 1, 3, solver);
        DisposableValueIterator vit = var.getValueIterator(true);
        Assert.assertTrue(vit.hasNext());
        Assert.assertEquals(1, vit.next());
        Assert.assertTrue(vit.hasNext());
        Assert.assertEquals(2, vit.next());
        Assert.assertTrue(vit.hasNext());
        Assert.assertEquals(3, vit.next());
        Assert.assertFalse(vit.hasNext());
    }
View Full Code Here

    @Test(groups = "1s")
    public void testBound2() {
        Solver solver = new Solver();
        IntVar var = VariableFactory.bounded("b", 1, 3, solver);
        DisposableValueIterator vit = var.getValueIterator(false);
        Assert.assertTrue(vit.hasPrevious());
        Assert.assertEquals(3, vit.previous());
        Assert.assertTrue(vit.hasPrevious());
        Assert.assertEquals(2, vit.previous());
        Assert.assertTrue(vit.hasPrevious());
        Assert.assertEquals(1, vit.previous());
        Assert.assertFalse(vit.hasPrevious());
    }
View Full Code Here

    @Test(groups = "1s")
    public void testEnum1() {
        Solver solver = new Solver();
        IntVar var = VariableFactory.enumerated("b", new int[]{1, 2, 4}, solver);
        DisposableValueIterator vit = var.getValueIterator(true);
        Assert.assertTrue(vit.hasNext());
        Assert.assertEquals(1, vit.next());
        Assert.assertTrue(vit.hasNext());
        Assert.assertEquals(2, vit.next());
        Assert.assertTrue(vit.hasNext());
        Assert.assertEquals(4, vit.next());
        Assert.assertFalse(vit.hasNext());
    }
View Full Code Here

    @Test(groups = "1s")
    public void testEnum2() {
        Solver solver = new Solver();
        IntVar var = VariableFactory.enumerated("b", new int[]{1, 2, 4}, solver);
        DisposableValueIterator vit = var.getValueIterator(false);
        Assert.assertTrue(vit.hasPrevious());
        Assert.assertEquals(4, vit.previous());
        Assert.assertTrue(vit.hasPrevious());
        Assert.assertEquals(2, vit.previous());
        Assert.assertTrue(vit.hasPrevious());
        Assert.assertEquals(1, vit.previous());
        Assert.assertFalse(vit.hasPrevious());
    }
View Full Code Here

    @Test(groups = "1s")
    public void testCste1() {
        Solver solver = new Solver();
        IntVar var = VariableFactory.fixed(8, solver);
        DisposableValueIterator vit = var.getValueIterator(true);
        Assert.assertTrue(vit.hasNext());
        Assert.assertEquals(8, vit.next());
        Assert.assertFalse(vit.hasNext());
    }
View Full Code Here

TOP

Related Classes of util.iterators.DisposableValueIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.