Beispiel #1
0
    //  This is the standard DeltaBlue benchmark. A long chain of
    //  equality constraints is constructed with a stay constraint on
    //  one end. An edit constraint is then added to the opposite end
    //  and the time is measured for adding and removing this
    //  constraint, and extracting and executing a constraint
    //  satisfaction plan. There are two cases. In case 1, the added
    //  constraint is stronger than the stay constraint and values must
    //  propagate down the entire length of the chain. In case 2, the
    //  added constraint is weaker than the stay constraint so it cannot
    //  be accomodated. The cost in this case is, of course, very
    //  low. Typical situations lie somewhere between these two
    //  extremes.
    //
    private void chainTest(int n)
    {
        planner = new Planner();

        Variable prev = null, first = null, last = null;

        // Build chain of n equality constraints
        for (int i = 0; i <= n; i++)
        {
            String name = "v" + i;
            Variable v = new Variable(name);
            if (prev != null)
                new EqualityConstraint(prev, v, Strength.required);
            if (i == 0) first = v;
            if (i == n) last = v;
            prev = v;
        }

        new StayConstraint(last, Strength.strongDefault);
        Constraint editC = new EditConstraint(first, Strength.preferred);
        ArrayList editV = new ArrayList();
        editV.Add(editC);
        Plan plan = planner.extractPlanFromConstraints(editV);
        for (int i = 0; i < 100; i++)
        {
            first.value = i;
            plan.execute();
            if (last.value != i)
                error("Chain test failed!");
        }
        editC.destroyConstraint();
        deltablue.chains++;
    }
Beispiel #2
0
    // This test constructs a two sets of variables related to each
    // other by a simple linear transformation (scale and offset). The
    // time is measured to change a variable on either side of the
    // mapping and to change the scale and offset factors.
    //
    private void projectionTest(int n)
    {
        planner = new Planner();

        Variable scale = new Variable("scale", 10);
        Variable offset = new Variable("offset", 1000);
        Variable src = null, dst = null;

        ArrayList dests = new ArrayList();

        for (int i = 0; i < n; ++i)
        {
            src = new Variable("src" + i, i);
            dst = new Variable("dst" + i, i);
            dests.Add(dst);
            new StayConstraint(src, Strength.normal);
            new ScaleConstraint(src, scale, offset, dst, Strength.required);
        }

        change(src, 17);
        if (dst.value != 1170) error("Projection test 1 failed!");

        change(dst, 1050);
        if (src.value != 5) error("Projection test 2 failed!");

        change(scale, 5);
        for (int i = 0; i < n - 1; ++i)
        {
            if (((Variable)dests[i]).value != i * 5 + 1000)
                error("Projection test 3 failed!");
        }

        change(offset, 2000);
        for (int i = 0; i < n - 1; ++i)
        {
            if (((Variable)dests[i]).value != i * 5 + 2000)
                error("Projection test 4 failed!");
        }
        deltablue.projections++;
    }