private Object getMinConflictValueFor(Variable var, Assignment assignment, CSP csp) { List <Constraint> constraints = csp.getConstraints(var); Assignment duplicate = assignment.copy(); int minConflict = int.MAX_VALUE; List <Object> resultCandidates = new List <Object>(); foreach (Object value in csp.getDomain(var)) { duplicate.setAssignment(var, value); int currConflict = countConflicts(duplicate, constraints); if (currConflict <= minConflict) { if (currConflict < minConflict) { resultCandidates.clear(); minConflict = currConflict; } resultCandidates.Add(value); } } if (!resultCandidates.isEmpty()) { return(Util.selectRandomlyFromList(resultCandidates)); } else { return(null); } }
protected void fireStateChanged(Assignment assignment, CSP csp) { foreach (CSPStateListener listener in listeners) { listener.stateChanged(assignment.copy(), csp.copyDomains()); } }
private Object getMinConflictValueFor(Variable var, Assignment assignment, CSP csp) { List<Constraint> constraints = csp.getConstraints(var); Assignment duplicate = assignment.copy(); int minConflict = int.MAX_VALUE; List<Object> resultCandidates = new List<Object>(); foreach (Object value in csp.getDomain(var)) { duplicate.setAssignment(var, value); int currConflict = countConflicts(duplicate, constraints); if (currConflict <= minConflict) { if (currConflict < minConflict) { resultCandidates.clear(); minConflict = currConflict; } resultCandidates.Add(value); } } if (!resultCandidates.isEmpty()) return Util.selectRandomlyFromList(resultCandidates); else return null; }
protected void fireStateChanged(Assignment assignment, CSP csp) { foreach (CSPStateListener listener in listeners) listener.stateChanged(assignment.copy(), csp.copyDomains()); }