示例#1
0
        /**
         * Establishes arc-consistency for (xi, xj).
         * @return value true if the domain of xi was reduced.
         */
        private bool makeArcConsistent(VAR xi, VAR xj, IConstraint <VAR, VAL> constraint, CSP <VAR, VAL> csp)
        {
            Domain <VAL>          currDomain = csp.getDomain(xi);
            ICollection <VAL>     newValues  = CollectionFactory.CreateQueue <VAL>();
            Assignment <VAR, VAL> assignment = new Assignment <VAR, VAL>();

            foreach (VAL vi in currDomain)
            {
                assignment.add(xi, vi);
                foreach (VAL vj in csp.getDomain(xj))
                {
                    assignment.add(xj, vj);
                    if (constraint.isSatisfiedWith(assignment))
                    {
                        newValues.Add(vi);
                        break;
                    }
                }
            }
            if (newValues.Size() < currDomain.size())
            {
                csp.setDomain(xi, new Domain <VAL>(newValues));
                return(true);
            }
            return(false);
        }
示例#2
0
        /**
         * Replaces the domain of the specified variable by new domain, which
         * contains all values of the old domain except the specified value.
         */
        public bool removeValueFromDomain(VAR var, VAL value)
        {
            Domain <VAL>      currDomain = getDomain(var);
            ICollection <VAL> values     = CollectionFactory.CreateQueue <VAL>();

            foreach (VAL v in currDomain)
            {
                if (!v.Equals(value))
                {
                    values.Add(v);
                }
            }
            if (values.Size() < currDomain.size())
            {
                setDomain(var, new Domain <VAL>(values));
                return(true);
            }
            return(false);
        }