예제 #1
0
        /**
         * Makes a CSP consisting of binary constraints arc-consistent.
         *
         * @return An object which indicates success/failure and contains data to
         *         undo the operation.
         */
        public IInferenceLog <VAR, VAL> apply(CSP <VAR, VAL> csp)
        {
            ICollection <VAR> queue = CollectionFactory.CreateFifoQueueNoDuplicates <VAR>();

            queue.AddAll(csp.getVariables());
            DomainLog <VAR, VAL> log = new DomainLog <VAR, VAL>();

            reduceDomains(queue, csp, log);
            return(log.compactify());
        }
예제 #2
0
        /**
         * Reduces the domain of the specified variable to the specified value and
         * reestablishes arc-consistency. It is assumed that the provided CSP was
         * arc-consistent before the call.
         *
         * @return An object which indicates success/failure and contains data to
         *         undo the operation.
         */
        public IInferenceLog <VAR, VAL> apply(CSP <VAR, VAL> csp, Assignment <VAR, VAL> assignment, VAR var)
        {
            Domain <VAL> domain = csp.getDomain(var);
            VAL          value  = assignment.getValue(var);

            if (!domain.contains(value))
            {
                throw new Exception("domain does not contain value");
            }

            DomainLog <VAR, VAL> log = new DomainLog <VAR, VAL>();

            if (domain.size() > 1)
            {
                ICollection <VAR> queue = CollectionFactory.CreateFifoQueue <VAR>();
                queue.Add(var);
                log.storeDomainFor(var, domain);
                csp.setDomain(var, new Domain <VAL>(value));
                reduceDomains(queue, csp, log);
            }
            return(log.compactify());
        }