package jrummikub.ai.fdsolver.constraint; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import jrummikub.ai.fdsolver.Constraint; import jrummikub.ai.fdsolver.Propagator; import jrummikub.ai.fdsolver.Satisfiability; import jrummikub.ai.fdsolver.Var; public class SumConstraint implements Constraint { Var x, y, z; public SumConstraint(Var x, Var y, Var z) { this.x = x; this.y = y; this.z = z; } @Override public Collection> getWatchedVars() { return Arrays.> asList(x, y, z); } @Override public Collection getPropagators(boolean negate) { // TODO Auto-generated method stub return Collections.emptyList(); } @Override public Satisfiability getSatisfiability() { // HashSet intersection = new HashSet(); for (int xv : x.getRange()) { for (int yv : y.getRange()) { if (z.getRange().contains(xv + yv)) { if (z.getRange().size() == 1 && x.getRange().size() == 1 && y.getRange().size() == 1) { return Satisfiability.TAUT; } else { return Satisfiability.SAT; } } } } return Satisfiability.UNSAT; } }