示例#1
0
        private void change(Variable var, int newValue)
        {
            EditConstraint editC = new EditConstraint(var, Strength.preferred);
            ArrayList      editV = new ArrayList();

            editV.Add(editC);
            Plan plan = planner.extractPlanFromConstraints(editV);

            for (int i = 0; i < 10; i++)
            {
                var.value = newValue;
                plan.execute();
            }
            editC.destroyConstraint();
        }
示例#2
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++;
        }
示例#3
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++;
    }