Exemplo n.º 1
0
        // Extract a plan for resatisfaction starting from the outputs of
        // the given constraints, usually a set of input constraints.
        //
        public Plan extractPlanFromConstraints(ArrayList constraints)
        {
            ArrayList sources = new ArrayList();

            for (int i = 0; i < constraints.Count; ++i)
            {
                Constraint c = (Constraint)constraints[i];
                if (c.isInput() && c.isSatisfied())
                {
                    sources.Add(c);
                }
            }
            return(makePlan(sources));
        }
Exemplo n.º 2
0
        public void addConstraintsConsumingTo(Variable v, ArrayList coll)
        {
            Constraint determiningC = v.determinedBy;
            ArrayList  cc           = v.constraints;

            for (int i = 0; i < cc.Count; ++i)
            {
                Constraint c = (Constraint)cc[i];
                if (c != determiningC && c.isSatisfied())
                {
                    coll.Add(c);
                }
            }
        }
Exemplo n.º 3
0
        // Update the walkabout strengths and stay flags of all variables
        // downstream of the given constraint. Answer a collection of
        // unsatisfied constraints sorted in order of decreasing strength.
        //
        public ArrayList removePropagateFrom(Variable outvar)
        {
            outvar.determinedBy = null;
            outvar.walkStrength = Strength.weakest;
            outvar.stay         = true;
            ArrayList unsatisfied = new ArrayList();
            ArrayList todo        = new ArrayList();

            todo.Add(outvar);
            while (!(todo.Count == 0))
            {
#if USE_STACK
                Variable v = (Variable)todo[todo.Count - 1];
                todo.RemoveAt(todo.Count - 1);
#else
                Variable v = (Variable)todo[0];
                todo.RemoveAt(0);
#endif
                for (int i = 0; i < v.constraints.Count; ++i)
                {
                    Constraint c = (Constraint)v.constraints[i];
                    if (!c.isSatisfied())
                    {
                        unsatisfied.Add(c);
                    }
                }
                Constraint determiningC = v.determinedBy;
                for (int i = 0; i < v.constraints.Count; ++i)
                {
                    Constraint nextC = (Constraint)v.constraints[i];
                    if (nextC != determiningC && nextC.isSatisfied())
                    {
                        nextC.recalculate();
                        todo.Add(nextC.output());
                    }
                }
            }
            return(unsatisfied);
        }