Beispiel #1
0
        // Attempt to find a way to enforce this constraint. If successful,
        // record the solution, perhaps modifying the current dataflow
        // graph. Answer the constraint that this constraint overrides, if
        // there is one, or nil, if there isn't.
        // Assume: I am not already satisfied.
        //
        public Constraint satisfy(int mark)
        {
            chooseMethod(mark);
            if (!isSatisfied())
            {
                if (strength == Strength.required)
                {
                    deltablue.error("Could not satisfy a required constraint");
                }
                return(null);
            }
            // constraint can be satisfied
            // mark inputs to allow cycle detection in addPropagate
            markInputs(mark);
            Variable   outvar     = output();
            Constraint overridden = outvar.determinedBy;

            if (overridden != null)
            {
                overridden.markUnsatisfied();
            }
            outvar.determinedBy = this;
            if (!deltablue.planner.addPropagate(this, mark))
            {
                Console.WriteLine("Cycle encountered");
                return(null);
            }
            outvar.mark = mark;
            return(overridden);
        }
Beispiel #2
0
        // Entry point for retracting a constraint. Remove the given
        // constraint and incrementally update the dataflow graph.
        // Details: Retracting the given constraint may allow some currently
        // unsatisfiable downstream constraint to be satisfied. We therefore collect
        // a list of unsatisfied downstream constraints and attempt to
        // satisfy each one in turn. This list is traversed by constraint
        // strength, strongest first, as a heuristic for avoiding
        // unnecessarily adding and then overriding weak constraints.
        // Assume: c is satisfied.
        //
        public void incrementalRemove(Constraint c)
        {
            Variable outvar = c.output();

            c.markUnsatisfied();
            c.removeFromGraph();
            ArrayList unsatisfied = removePropagateFrom(outvar);
            Strength  strength    = Strength.required;

            do
            {
                for (int i = 0; i < unsatisfied.Count; ++i)
                {
                    Constraint u = (Constraint)unsatisfied[i];
                    if (u.strength == strength)
                    {
                        incrementalAdd(u);
                    }
                }
                strength = strength.nextWeaker();
            } while (strength != Strength.weakest);
        }
Beispiel #3
0
 // Entry point for retracting a constraint. Remove the given
 // constraint and incrementally update the dataflow graph.
 // Details: Retracting the given constraint may allow some currently
 // unsatisfiable downstream constraint to be satisfied. We therefore collect
 // a list of unsatisfied downstream constraints and attempt to
 // satisfy each one in turn. This list is traversed by constraint
 // strength, strongest first, as a heuristic for avoiding
 // unnecessarily adding and then overriding weak constraints.
 // Assume: c is satisfied.
 //
 public void incrementalRemove(Constraint c)
 {
     Variable outvar = c.output();
     c.markUnsatisfied();
     c.removeFromGraph();
     ArrayList unsatisfied = removePropagateFrom(outvar);
     Strength strength = Strength.required;
     do
     {
         for (int i = 0; i < unsatisfied.Count; ++i)
         {
             Constraint u = (Constraint)unsatisfied[i];
             if (u.strength == strength)
                 incrementalAdd(u);
         }
         strength = strength.nextWeaker();
     } while (strength != Strength.weakest);
 }