예제 #1
0
        // Attempt to assign the given value to me using the given strength.
        public void setValue(int value, Strength strength)
        {
            EditConstraint e = new EditConstraint(this, strength);

            if (e.isSatisfied())
            {
                this.value = value;
                deltablue.planner.propagateFrom(this);
            }
            e.destroyConstraint();
        }
예제 #2
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();
        }
예제 #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++;
        }
예제 #4
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++;
    }
예제 #5
0
 // Attempt to assign the given value to me using the given strength.
 public void setValue(int value, Strength strength)
 {
     EditConstraint e = new EditConstraint(this, strength);
     if (e.isSatisfied())
     {
         this.value = value;
         deltablue.planner.propagateFrom(this);
     }
     e.destroyConstraint();
 }
예제 #6
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();
 }