diff options
author | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-06-14 17:48:22 +0200 |
---|---|---|
committer | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-06-14 17:48:22 +0200 |
commit | 7568f3782466531fe04fc14a40dc4d3a393c1fb9 (patch) | |
tree | 7778b598da5b698c35189234fe3a9dd58ae82913 /src/jrummikub/ai/fdsolver/constraint/SumConstraint.java | |
parent | 79767f762e39eac3a0247b9ee75b24258790e0de (diff) | |
download | JRummikub-7568f3782466531fe04fc14a40dc4d3a393c1fb9.tar JRummikub-7568f3782466531fe04fc14a40dc4d3a393c1fb9.zip |
Added TurnLogic with rule variables and constraints
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@436 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/ai/fdsolver/constraint/SumConstraint.java')
-rw-r--r-- | src/jrummikub/ai/fdsolver/constraint/SumConstraint.java | 51 |
1 files changed, 51 insertions, 0 deletions
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<Integer> x, y, z; + + public SumConstraint(Var<Integer> x, Var<Integer> y, Var<Integer> z) { + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public Collection<Var<?>> getWatchedVars() { + return Arrays.<Var<?>> asList(x, y, z); + } + + @Override + public Collection<Propagator> getPropagators(boolean negate) { + // TODO Auto-generated method stub + return Collections.emptyList(); + } + + @Override + public Satisfiability getSatisfiability() { + // HashSet<Integer> intersection = new HashSet<Integer>(); + 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; + } +} |