/** * For efficiency reasons the queue manages updated variables vj whereas the original AC3 * manages neighbor arcs (vi, vj). Constraints which are not binary are ignored. */ private void reduceDomains(ICollection <VAR> queue, CSP <VAR, VAL> csp, DomainLog <VAR, VAL> log) { while (!queue.IsEmpty()) { VAR var = queue.Pop(); foreach (IConstraint <VAR, VAL> constraint in csp.getConstraints(var)) { VAR neighbor = csp.getNeighbor(var, constraint); if (neighbor != null && revise(neighbor, var, constraint, csp, log)) { if (csp.getDomain(neighbor).isEmpty()) { log.setEmptyDomainFound(true); return; } queue.Add(neighbor); } } } }
/** * Removes all values from the domains of the neighbor variables of <code>var</code> in the * constraint graph which are not consistent with the new value for <code>var</code>. * It is called after <code>assignment</code> has (recursively) been extended with a value * assignment for <code>var</code>. */ public IInferenceLog <VAR, VAL> apply(CSP <VAR, VAL> csp, Assignment <VAR, VAL> assignment, VAR var) { DomainLog <VAR, VAL> log = new DomainLog <VAR, VAL>(); foreach (IConstraint <VAR, VAL> constraint in csp.getConstraints(var)) { VAR neighbor = csp.getNeighbor(var, constraint); if (neighbor != null && !assignment.contains(neighbor)) { if (revise(neighbor, constraint, assignment, csp, log)) { if (csp.getDomain(neighbor).isEmpty()) { log.setEmptyDomainFound(true); return(log); } } } } return(log); }