From 0a63df955ee7e748c43a0cd9303add78eda0018b Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Tue, 14 Jun 2011 17:48:24 +0200 Subject: Cache propagators git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@437 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/ai/fdsolver/Constraint.java | 10 ++++++---- src/jrummikub/ai/fdsolver/Solver.java | 4 ++-- src/jrummikub/ai/fdsolver/constraint/ComparatorConstraint.java | 2 +- src/jrummikub/ai/fdsolver/constraint/FilterConstraint.java | 2 +- src/jrummikub/ai/fdsolver/constraint/IfConstraint.java | 2 +- src/jrummikub/ai/fdsolver/constraint/IndexConstraint.java | 2 +- src/jrummikub/ai/fdsolver/constraint/OffsetConstraint.java | 2 +- src/jrummikub/ai/fdsolver/constraint/SameConstraint.java | 2 +- src/jrummikub/ai/fdsolver/constraint/SumConstraint.java | 2 +- 9 files changed, 15 insertions(+), 13 deletions(-) (limited to 'src/jrummikub/ai') 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> getWatchedVars(); +public abstract class Constraint { + Collection cachedPropagators; + + public abstract Collection> getWatchedVars(); - public Collection getPropagators(boolean negate); + public abstract Collection 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 implements Constraint { +public class ComparatorConstraint extends Constraint { Var x, y; Comparator comparator, reverseComparator; ComparatorPropagator 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 implements Constraint { +public class FilterConstraint extends Constraint { private Var var; private Propagator trueProp, falseProp; private Filter 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 condition; Constraint child; Collection> 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 implements Constraint { +public class IndexConstraint extends Constraint { Var target; Var index; List> 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 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 implements Constraint { +public class SameConstraint extends Constraint { private Var 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 x, y, z; public SumConstraint(Var x, Var y, Var z) { -- cgit v1.2.3