// ////////////////////////////////////////////////////////////// // inference algorithms /** : forward checking. */ private DomainRestoreInfo doForwardChecking(Variable var, Assignment assignment, CSP csp) { DomainRestoreInfo result = new DomainRestoreInfo(); foreach (Constraint constraint in csp.getConstraints(var)) { List <Variable> scope = constraint.getScope(); if (scope.Count == 2) { foreach (Variable neighbor in constraint.getScope()) { if (!assignment.hasAssignmentFor(neighbor)) { if (revise(neighbor, constraint, assignment, csp, result)) { if (csp.getDomain(neighbor).isEmpty()) { result.setEmptyDomainFound(true); return(result); } } } } } } return(result); }
/** * Reduces the domain of the specified variable to the specified * value and reestablishes arc-consistency. It is assumed that the * provided CSP is arc-consistent before the call. * @return An object which indicates success/failure and contains * data to undo the operation. */ public DomainRestoreInfo reduceDomains(Variable var, Object value, CSP csp) { DomainRestoreInfo result = new DomainRestoreInfo(); Domain domain = csp.getDomain(var); if (domain.contains(value)) { if (domain.Count > 1) { FIFOQueue<Variable> queue = new FIFOQueue<Variable>(); queue.Add(var); result.storeDomainFor(var, domain); csp.setDomain(var, new Domain(new Object[] { value })); reduceDomains(queue, csp, result); } } else { result.setEmptyDomainFound(true); } return result.compactify(); }
/** * Reduces the domain of the specified variable to the specified * value and reestablishes arc-consistency. It is assumed that the * provided CSP is arc-consistent before the call. * @return An object which indicates success/failure and contains * data to undo the operation. */ public DomainRestoreInfo reduceDomains(Variable var, Object value, CSP csp) { DomainRestoreInfo result = new DomainRestoreInfo(); Domain domain = csp.getDomain(var); if (domain.contains(value)) { if (domain.Count > 1) { FIFOQueue <Variable> queue = new FIFOQueue <Variable>(); queue.Add(var); result.storeDomainFor(var, domain); csp.setDomain(var, new Domain(new Object[] { value })); reduceDomains(queue, csp, result); } } else { result.setEmptyDomainFound(true); } return(result.compactify()); }
private void reduceDomains(FIFOQueue <Variable> queue, CSP csp, DomainRestoreInfo info) { while (!queue.isEmpty()) { Variable var = queue.pop(); foreach (Constraint constraint in csp.getConstraints(var)) { if (constraint.getScope().Count == 2) { Variable neighbor = csp.getNeighbor(var, constraint); if (revise(neighbor, var, constraint, csp, info)) { if (csp.getDomain(neighbor).isEmpty()) { info.setEmptyDomainFound(true); return; } queue.push(neighbor); } } } } }
private void reduceDomains(FIFOQueue<Variable> queue, CSP csp, DomainRestoreInfo info) { while (!queue.isEmpty()) { Variable var = queue.pop(); foreach (Constraint constraint in csp.getConstraints(var)) { if (constraint.getScope().Count == 2) { Variable neighbor = csp.getNeighbor(var, constraint); if (revise(neighbor, var, constraint, csp, info)) { if (csp.getDomain(neighbor).isEmpty()) { info.setEmptyDomainFound(true); return; } queue.push(neighbor); } } } } }
// ////////////////////////////////////////////////////////////// // inference algorithms /** : forward checking. */ private DomainRestoreInfo doForwardChecking(Variable var, Assignment assignment, CSP csp) { DomainRestoreInfo result = new DomainRestoreInfo(); foreach (Constraint constraint in csp.getConstraints(var)) { List<Variable> scope = constraint.getScope(); if (scope.Count == 2) { foreach (Variable neighbor in constraint.getScope()) { if (!assignment.hasAssignmentFor(neighbor)) { if (revise(neighbor, constraint, assignment, csp, result)) { if (csp.getDomain(neighbor).isEmpty()) { result.setEmptyDomainFound(true); return result; } } } } } } return result; }