summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jrummikub/ai/fdsolver/Constraint.java10
-rw-r--r--src/jrummikub/ai/fdsolver/Solver.java4
-rw-r--r--src/jrummikub/ai/fdsolver/constraint/ComparatorConstraint.java2
-rw-r--r--src/jrummikub/ai/fdsolver/constraint/FilterConstraint.java2
-rw-r--r--src/jrummikub/ai/fdsolver/constraint/IfConstraint.java2
-rw-r--r--src/jrummikub/ai/fdsolver/constraint/IndexConstraint.java2
-rw-r--r--src/jrummikub/ai/fdsolver/constraint/OffsetConstraint.java2
-rw-r--r--src/jrummikub/ai/fdsolver/constraint/SameConstraint.java2
-rw-r--r--src/jrummikub/ai/fdsolver/constraint/SumConstraint.java2
9 files changed, 15 insertions, 13 deletions
diff --git a/src/jrummikub/ai/fdsolver/Constraint.java b/src/jrummikub/ai/fdsolver/Constraint.java
index f7955ce..b081d4b 100644
--- a/src/jrummikub/ai/fdsolver/Constraint.java
+++ b/src/jrummikub/ai/fdsolver/Constraint.java
@@ -2,10 +2,12 @@ package jrummikub.ai.fdsolver;
import java.util.Collection;
-public interface Constraint {
- public Collection<Var<?>> getWatchedVars();
+public abstract class Constraint {
+ Collection<Propagator> cachedPropagators;
+
+ public abstract Collection<Var<?>> getWatchedVars();
- public Collection<Propagator> getPropagators(boolean negate);
+ public abstract Collection<Propagator> getPropagators(boolean negate);
- public Satisfiability getSatisfiability();
+ public abstract Satisfiability getSatisfiability();
}
diff --git a/src/jrummikub/ai/fdsolver/Solver.java b/src/jrummikub/ai/fdsolver/Solver.java
index c3ede1b..2277ba4 100644
--- a/src/jrummikub/ai/fdsolver/Solver.java
+++ b/src/jrummikub/ai/fdsolver/Solver.java
@@ -99,7 +99,7 @@ public class Solver {
finishedConstraint(constraint, dirtyVar);
continue;
}
- for (Propagator propagator : constraint.getPropagators(false)) {
+ for (Propagator propagator : constraint.cachedPropagators) {
if (propagator.getWatchedVars().contains(dirtyVar)) {
propagator.propagate();
if (contradiction) {
@@ -124,8 +124,8 @@ public class Solver {
}
public void addConstraint(Constraint constraint) {
+ constraint.cachedPropagators = constraint.getPropagators(false);
constraints.add(constraint);
-
for (Var<?> var : constraint.getWatchedVars()) {
var.makeDirty();
var.getConstraints().add(constraint);
diff --git a/src/jrummikub/ai/fdsolver/constraint/ComparatorConstraint.java b/src/jrummikub/ai/fdsolver/constraint/ComparatorConstraint.java
index 24e7ecf..ab0edde 100644
--- a/src/jrummikub/ai/fdsolver/constraint/ComparatorConstraint.java
+++ b/src/jrummikub/ai/fdsolver/constraint/ComparatorConstraint.java
@@ -12,7 +12,7 @@ import jrummikub.ai.fdsolver.Propagator;
import jrummikub.ai.fdsolver.Satisfiability;
import jrummikub.ai.fdsolver.Var;
-public class ComparatorConstraint<T> implements Constraint {
+public class ComparatorConstraint<T> extends Constraint {
Var<T> x, y;
Comparator<T> comparator, reverseComparator;
ComparatorPropagator<T> trueX, trueY, falseX, falseY;
diff --git a/src/jrummikub/ai/fdsolver/constraint/FilterConstraint.java b/src/jrummikub/ai/fdsolver/constraint/FilterConstraint.java
index e676882..d01a109 100644
--- a/src/jrummikub/ai/fdsolver/constraint/FilterConstraint.java
+++ b/src/jrummikub/ai/fdsolver/constraint/FilterConstraint.java
@@ -12,7 +12,7 @@ import jrummikub.ai.fdsolver.Propagator;
import jrummikub.ai.fdsolver.Satisfiability;
import jrummikub.ai.fdsolver.Var;
-public class FilterConstraint<T> implements Constraint {
+public class FilterConstraint<T> extends Constraint {
private Var<T> var;
private Propagator trueProp, falseProp;
private Filter<T> filter;
diff --git a/src/jrummikub/ai/fdsolver/constraint/IfConstraint.java b/src/jrummikub/ai/fdsolver/constraint/IfConstraint.java
index 802acc2..3046eb5 100644
--- a/src/jrummikub/ai/fdsolver/constraint/IfConstraint.java
+++ b/src/jrummikub/ai/fdsolver/constraint/IfConstraint.java
@@ -11,7 +11,7 @@ import jrummikub.ai.fdsolver.Propagator;
import jrummikub.ai.fdsolver.Satisfiability;
import jrummikub.ai.fdsolver.Var;
-public class IfConstraint implements Constraint {
+public class IfConstraint extends Constraint {
Var<Boolean> condition;
Constraint child;
Collection<Var<?>> vars;
diff --git a/src/jrummikub/ai/fdsolver/constraint/IndexConstraint.java b/src/jrummikub/ai/fdsolver/constraint/IndexConstraint.java
index 999924f..9d80a37 100644
--- a/src/jrummikub/ai/fdsolver/constraint/IndexConstraint.java
+++ b/src/jrummikub/ai/fdsolver/constraint/IndexConstraint.java
@@ -13,7 +13,7 @@ import jrummikub.ai.fdsolver.Propagator;
import jrummikub.ai.fdsolver.Satisfiability;
import jrummikub.ai.fdsolver.Var;
-public class IndexConstraint<T> implements Constraint {
+public class IndexConstraint<T> extends Constraint {
Var<T> target;
Var<Integer> index;
List<Var<T>> list;
diff --git a/src/jrummikub/ai/fdsolver/constraint/OffsetConstraint.java b/src/jrummikub/ai/fdsolver/constraint/OffsetConstraint.java
index f91dcda..a324d2a 100644
--- a/src/jrummikub/ai/fdsolver/constraint/OffsetConstraint.java
+++ b/src/jrummikub/ai/fdsolver/constraint/OffsetConstraint.java
@@ -10,7 +10,7 @@ import jrummikub.ai.fdsolver.Propagator;
import jrummikub.ai.fdsolver.Satisfiability;
import jrummikub.ai.fdsolver.Var;
-public class OffsetConstraint implements Constraint {
+public class OffsetConstraint extends Constraint {
private Var<Integer> x, y;
int offset;
Propagator propX, propY;
diff --git a/src/jrummikub/ai/fdsolver/constraint/SameConstraint.java b/src/jrummikub/ai/fdsolver/constraint/SameConstraint.java
index 7fc8961..954b6fa 100644
--- a/src/jrummikub/ai/fdsolver/constraint/SameConstraint.java
+++ b/src/jrummikub/ai/fdsolver/constraint/SameConstraint.java
@@ -10,7 +10,7 @@ import jrummikub.ai.fdsolver.Propagator;
import jrummikub.ai.fdsolver.Satisfiability;
import jrummikub.ai.fdsolver.Var;
-public class SameConstraint<T> implements Constraint {
+public class SameConstraint<T> extends Constraint {
private Var<T> x, y;
Propagator propX, propY;
diff --git a/src/jrummikub/ai/fdsolver/constraint/SumConstraint.java b/src/jrummikub/ai/fdsolver/constraint/SumConstraint.java
index 80b19e2..c96a751 100644
--- a/src/jrummikub/ai/fdsolver/constraint/SumConstraint.java
+++ b/src/jrummikub/ai/fdsolver/constraint/SumConstraint.java
@@ -10,7 +10,7 @@ import jrummikub.ai.fdsolver.Propagator;
import jrummikub.ai.fdsolver.Satisfiability;
import jrummikub.ai.fdsolver.Var;
-public class SumConstraint implements Constraint {
+public class SumConstraint extends Constraint {
Var<Integer> x, y, z;
public SumConstraint(Var<Integer> x, Var<Integer> y, Var<Integer> z) {