summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/ai/fdsolver/Constraints.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/ai/fdsolver/Constraints.java')
-rw-r--r--src/jrummikub/ai/fdsolver/Constraints.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/jrummikub/ai/fdsolver/Constraints.java b/src/jrummikub/ai/fdsolver/Constraints.java
new file mode 100644
index 0000000..0885d2a
--- /dev/null
+++ b/src/jrummikub/ai/fdsolver/Constraints.java
@@ -0,0 +1,56 @@
+package jrummikub.ai.fdsolver;
+
+import java.util.List;
+
+import jrummikub.ai.fdsolver.constraint.Filter;
+import jrummikub.ai.fdsolver.constraint.FilterConstraint;
+import jrummikub.ai.fdsolver.constraint.IfConstraint;
+import jrummikub.ai.fdsolver.constraint.IndexConstraint;
+import jrummikub.ai.fdsolver.constraint.LessThan;
+import jrummikub.ai.fdsolver.constraint.OffsetConstraint;
+import jrummikub.ai.fdsolver.constraint.SameConstraint;
+import jrummikub.ai.fdsolver.constraint.SumConstraint;
+
+public class Constraints {
+ public static Constraint when(Var<Boolean> cond, Constraint c) {
+ return new IfConstraint(false, cond, c);
+ }
+
+ public static Constraint unless(Var<Boolean> cond, Constraint c) {
+ return new IfConstraint(true, cond, c);
+ }
+
+
+ public static <T> Constraint index(Var<T> target, Var<Integer> index, List<Var<T>> list) {
+ return new IndexConstraint<T>(target, index, list);
+ }
+
+ public static <T> Constraint constant(Var<T> target, final T constant) {
+ return new FilterConstraint<T>(new Filter<T>() {
+ @Override
+ public boolean accept(T value) {
+ return value.equals(constant);
+ }
+ }, target);
+ }
+
+ public static Constraint offset(int offset, Var<Integer> x, Var<Integer> y) {
+ return new OffsetConstraint(offset, x, y);
+ }
+
+ public static <T> Constraint same(Var<T> x, Var<T> y) {
+ return new SameConstraint<T>(x, y);
+ }
+
+ public static Constraint sum(Var<Integer> x, Var<Integer> y, Var<Integer> z) {
+ return new SumConstraint(x, y, z);
+ }
+
+ public static <T extends Comparable<T>> Constraint lessThan(Var<T> x, Var<T> y) {
+ return new LessThan<T>(false, x, y);
+ }
+
+ public static <T extends Comparable<T>> Constraint lessThanEq(Var<T> x, Var<T> y) {
+ return new LessThan<T>(true, x, y);
+ }
+}