From 7568f3782466531fe04fc14a40dc4d3a393c1fb9 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Tue, 14 Jun 2011 17:48:22 +0200 Subject: Added TurnLogic with rule variables and constraints git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@436 72836036-5685-4462-b002-a69064685172 --- .../ai/fdsolver/constraint/SumConstraint.java | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/jrummikub/ai/fdsolver/constraint/SumConstraint.java (limited to 'src/jrummikub/ai/fdsolver/constraint/SumConstraint.java') diff --git a/src/jrummikub/ai/fdsolver/constraint/SumConstraint.java b/src/jrummikub/ai/fdsolver/constraint/SumConstraint.java new file mode 100644 index 0000000..80b19e2 --- /dev/null +++ b/src/jrummikub/ai/fdsolver/constraint/SumConstraint.java @@ -0,0 +1,51 @@ +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; + } +} -- cgit v1.2.3