// behaviors of CSP class and helpers CSP { traversal toAll (UniversalVisitor) { to *; } // deep copy the CSP public CSP copy() {{ CopyVisitor cv = new CopyVisitor(CSP.class); toAll(cv); return (CSP)cv.get_return_val(); }} // get a set of all variables in the CSP Set vars() to Variable { init (@ return_val = new HashSet(); @) before Variable (@ return_val.add(host); @) } // get a reduced copy of the CSP, simplified with // assignment a CSP reduce(Assignment a) to Constraint { before CSP (@ return_val = host.copy(); return_val.set_constraints(Constraint_List.parse("")); @) before Constraint (@ return_val.addConstraint(host.reduce(a)); @) } // add a constraint to the CSP void addConstraint(Constraint c) {{ constraints.push(c); }} double unsat(Assignment a) {{ return ((double)unsatCount(a)) / constraintCount(); }} int constraintCount() to Constraint { init (@ return_val = 0; @) before Constraint (@ return_val++; @) } int unsatCount(Assignment a) to Constraint { init (@ return_val = 0; @) before Constraint (@ // LoD violation: if (host.reduce(a).get_relation().get_relationNumber() == 0) return_val++; @) } }