Skip to content

Commit

Permalink
#28 added caching of JEval node evaluators
Browse files Browse the repository at this point in the history
  • Loading branch information
hoechp committed Feb 25, 2017
1 parent e53f1fa commit db6f64e
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 9 deletions.
Binary file modified .gradle/3.2/taskArtifacts/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/3.2/taskArtifacts/fileSnapshots.bin
Binary file not shown.
Binary file modified .gradle/3.2/taskArtifacts/taskArtifacts.bin
Binary file not shown.
Binary file modified .gradle/3.2/taskArtifacts/taskArtifacts.lock
Binary file not shown.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.21'

// guava
compile group: 'com.google.guava', name: 'guava', version: '21.0'

// gson:
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'

// jeval:
compile group: 'net.sourceforge.jeval', name: 'jeval', version: '0.9.4'


// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/org/fujaba/graphengine/PatternEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.concurrent.TimeUnit;

import javax.naming.spi.DirStateFactory.Result;

Expand All @@ -16,6 +17,10 @@
import org.fujaba.graphengine.pattern.PatternGraph;
import org.fujaba.graphengine.pattern.PatternNode;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

import net.sourceforge.jeval.Evaluator;

/**
Expand All @@ -25,6 +30,23 @@
*/
public class PatternEngine {

private static LoadingCache<Node, Evaluator> evaluatorCache = null;

public static Evaluator getNodeEvaluator(Node node) {
if (evaluatorCache == null) {
CacheLoader<Node, Evaluator> evaluatorCacheLoader = new CacheLoader<Node, Evaluator>() {
public Evaluator load(Node node) {
return buildNodeEvaluator(node);
}
};
evaluatorCache = CacheBuilder.newBuilder()
.maximumSize(5000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.build(evaluatorCacheLoader);
}
return evaluatorCache.getUnchecked(node);
}

/**
* Calculates a reachability graph based on a graph of the initial situation
* and a prioritized list of patterns to match and apply on the graph and resulting graphs.
Expand Down Expand Up @@ -953,7 +975,8 @@ public static Graph applyMatch(Match match) {
}

public static boolean evaluate(Node node, String expression) {
return evaluate(buildNodeEvaluator(node), expression);
//return evaluate(buildNodeEvaluator(node), expression); // uncached
return evaluate(getNodeEvaluator(node), expression); // cached
}
public static Evaluator buildNodeEvaluator(Node node) {
Evaluator evaluator = new Evaluator();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/data.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"nodes":[{"id":0,"label":"{graph\u003d1}","x":-0.03090169943749474,"y":-0.09510565162951536,"size":10,"color":"#00F"},{"id":1,"label":"{graph\u003d2}","x":-0.08090169943749474,"y":-0.058778525229247314,"size":10,"color":"#000"},{"id":2,"label":"{graph\u003d3}","x":-0.1,"y":-6.123233995736766E-18,"size":10,"color":"#000"},{"id":3,"label":"{graph\u003d4}","x":-0.08090169943749474,"y":0.0587785252292473,"size":10,"color":"#000"},{"id":4,"label":"{graph\u003d5}","x":-0.03090169943749475,"y":0.09510565162951536,"size":10,"color":"#000"},{"id":5,"label":"{graph\u003d6}","x":0.030901699437494774,"y":0.09510565162951536,"size":10,"color":"#000"},{"id":6,"label":"{graph\u003d7}","x":0.08090169943749473,"y":0.05877852522924733,"size":10,"color":"#000"},{"id":7,"label":"{graph\u003d8}","x":0.1,"y":1.8369701987210297E-17,"size":10,"color":"#000"},{"id":8,"label":"{graph\u003d9}","x":0.08090169943749476,"y":-0.05877852522924729,"size":10,"color":"#000"},{"id":9,"label":"{graph\u003d10}","x":0.03090169943749476,"y":-0.09510565162951536,"size":10,"color":"#000"}],"edges":[{"id":10,"label":"correctTranportRule","source":0,"target":1,"size":10,"color":"#888"},{"id":11,"label":"correctTranportRule","source":1,"target":0,"size":10,"color":"#888"},{"id":12,"label":"correctEmptyTranportRule","source":1,"target":2,"size":10,"color":"#888"},{"id":13,"label":"correctTranportRule","source":2,"target":3,"size":10,"color":"#888"},{"id":14,"label":"correctTranportRule","source":2,"target":4,"size":10,"color":"#888"},{"id":15,"label":"correctEmptyTranportRule","source":2,"target":1,"size":10,"color":"#888"},{"id":16,"label":"correctTranportRule","source":3,"target":2,"size":10,"color":"#888"},{"id":17,"label":"correctTranportRule","source":3,"target":5,"size":10,"color":"#888"},{"id":18,"label":"correctTranportRule","source":4,"target":6,"size":10,"color":"#888"},{"id":19,"label":"correctTranportRule","source":4,"target":2,"size":10,"color":"#888"},{"id":20,"label":"correctTranportRule","source":5,"target":3,"size":10,"color":"#888"},{"id":21,"label":"correctTranportRule","source":5,"target":7,"size":10,"color":"#888"},{"id":22,"label":"correctTranportRule","source":6,"target":7,"size":10,"color":"#888"},{"id":23,"label":"correctTranportRule","source":6,"target":4,"size":10,"color":"#888"},{"id":24,"label":"correctTranportRule","source":7,"target":6,"size":10,"color":"#888"},{"id":25,"label":"correctTranportRule","source":7,"target":5,"size":10,"color":"#888"},{"id":26,"label":"correctEmptyTranportRule","source":7,"target":8,"size":10,"color":"#888"},{"id":27,"label":"correctTranportRule","source":8,"target":9,"size":10,"color":"#888"},{"id":28,"label":"correctEmptyTranportRule","source":8,"target":7,"size":10,"color":"#888"},{"id":29,"label":"correctTranportRule","source":9,"target":8,"size":10,"color":"#888"}]}
{"nodes":[{"id":0,"label":"{a0\u003dv0}","x":-0.015643446504023086,"y":-0.09876883405951378,"size":10,"color":"#00F"},{"id":1,"label":"{a0\u003dv0}","x":-0.04539904997395468,"y":-0.08910065241883679,"size":10,"color":"#000"},{"id":2,"label":"{a0\u003dv1}","x":-0.07071067811865475,"y":-0.07071067811865475,"size":10,"color":"#000"},{"id":3,"label":"{a0\u003dv2}","x":-0.08910065241883677,"y":-0.045399049973954685,"size":10,"color":"#000"},{"id":4,"label":"{a0\u003dv0}","x":-0.09876883405951378,"y":-0.015643446504023092,"size":10,"color":"#000"},{"id":5,"label":"{a0\u003dv2}","x":-0.09876883405951377,"y":0.015643446504023103,"size":10,"color":"#000"},{"id":6,"label":"{a0\u003dv1}","x":-0.08910065241883679,"y":0.04539904997395468,"size":10,"color":"#000"},{"id":7,"label":"{a0\u003dv1}","x":-0.07071067811865475,"y":0.07071067811865475,"size":10,"color":"#000"},{"id":8,"label":"{a0\u003dv1}","x":-0.045399049973954685,"y":0.08910065241883677,"size":10,"color":"#000"},{"id":9,"label":"{a0\u003dv2}","x":-0.0156434465040231,"y":0.09876883405951377,"size":10,"color":"#000"},{"id":10,"label":"{a0\u003dv1}","x":0.01564344650402307,"y":0.09876883405951378,"size":10,"color":"#000"},{"id":11,"label":"{a0\u003dv0}","x":0.04539904997395462,"y":0.08910065241883681,"size":10,"color":"#000"},{"id":12,"label":"{a0\u003dv1}","x":0.07071067811865475,"y":0.07071067811865477,"size":10,"color":"#000"},{"id":13,"label":"{a0\u003dv2}","x":0.08910065241883677,"y":0.04539904997395469,"size":10,"color":"#000"},{"id":14,"label":"{a0\u003dv2}","x":0.09876883405951377,"y":0.015643446504023103,"size":10,"color":"#000"},{"id":15,"label":"{a0\u003dv2}","x":0.09876883405951378,"y":-0.015643446504023068,"size":10,"color":"#000"},{"id":16,"label":"{a0\u003dv1}","x":0.0891006524188368,"y":-0.045399049973954664,"size":10,"color":"#000"},{"id":17,"label":"{a0\u003dv1}","x":0.07071067811865477,"y":-0.07071067811865474,"size":10,"color":"#000"},{"id":18,"label":"{a0\u003dv2}","x":0.0453990499739547,"y":-0.08910065241883677,"size":10,"color":"#000"},{"id":19,"label":"{a0\u003dv1}","x":0.015643446504023113,"y":-0.09876883405951377,"size":10,"color":"#000"}],"edges":[{"id":20,"label":"e0","source":0,"target":5,"size":10,"color":"#888"},{"id":21,"label":"e0","source":0,"target":9,"size":10,"color":"#888"},{"id":22,"label":"e0","source":1,"target":16,"size":10,"color":"#888"},{"id":23,"label":"e0","source":1,"target":3,"size":10,"color":"#888"},{"id":24,"label":"e0","source":2,"target":15,"size":10,"color":"#888"},{"id":25,"label":"e0","source":2,"target":10,"size":10,"color":"#888"},{"id":26,"label":"e0","source":3,"target":14,"size":10,"color":"#888"},{"id":27,"label":"e0","source":3,"target":4,"size":10,"color":"#888"},{"id":28,"label":"e0","source":4,"target":7,"size":10,"color":"#888"},{"id":29,"label":"e0","source":4,"target":14,"size":10,"color":"#888"},{"id":30,"label":"e0","source":5,"target":16,"size":10,"color":"#888"},{"id":31,"label":"e0","source":5,"target":18,"size":10,"color":"#888"},{"id":32,"label":"e0","source":6,"target":0,"size":10,"color":"#888"},{"id":33,"label":"e0","source":6,"target":19,"size":10,"color":"#888"},{"id":34,"label":"e0","source":7,"target":19,"size":10,"color":"#888"},{"id":35,"label":"e0","source":7,"target":11,"size":10,"color":"#888"},{"id":36,"label":"e0","source":8,"target":11,"size":10,"color":"#888"},{"id":37,"label":"e0","source":8,"target":10,"size":10,"color":"#888"},{"id":38,"label":"e0","source":9,"target":15,"size":10,"color":"#888"},{"id":39,"label":"e0","source":9,"target":16,"size":10,"color":"#888"},{"id":40,"label":"e0","source":10,"target":0,"size":10,"color":"#888"},{"id":41,"label":"e0","source":10,"target":14,"size":10,"color":"#888"},{"id":42,"label":"e0","source":11,"target":10,"size":10,"color":"#888"},{"id":43,"label":"e0","source":11,"target":3,"size":10,"color":"#888"},{"id":44,"label":"e0","source":12,"target":11,"size":10,"color":"#888"},{"id":45,"label":"e0","source":12,"target":12,"size":10,"color":"#888"},{"id":46,"label":"e0","source":13,"target":3,"size":10,"color":"#888"},{"id":47,"label":"e0","source":13,"target":4,"size":10,"color":"#888"},{"id":48,"label":"e0","source":14,"target":4,"size":10,"color":"#888"},{"id":49,"label":"e0","source":14,"target":17,"size":10,"color":"#888"},{"id":50,"label":"e0","source":15,"target":16,"size":10,"color":"#888"},{"id":51,"label":"e0","source":15,"target":4,"size":10,"color":"#888"},{"id":52,"label":"e0","source":16,"target":8,"size":10,"color":"#888"},{"id":53,"label":"e0","source":16,"target":5,"size":10,"color":"#888"},{"id":54,"label":"e0","source":17,"target":19,"size":10,"color":"#888"},{"id":55,"label":"e0","source":17,"target":1,"size":10,"color":"#888"},{"id":56,"label":"e0","source":18,"target":13,"size":10,"color":"#888"},{"id":57,"label":"e0","source":18,"target":16,"size":10,"color":"#888"},{"id":58,"label":"e0","source":19,"target":12,"size":10,"color":"#888"},{"id":59,"label":"e0","source":19,"target":14,"size":10,"color":"#888"}]}
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,16 @@ private double testRoadworkExample(boolean debug, IsomorphismHandler ih, int fro
public void testRoadworkExample() {

ArrayList<IsomorphismHandler> toTest = new ArrayList<IsomorphismHandler>();
//toTest.add(new IsomorphismHandlerParallel());
//toTest.add(new IsomorphismHandlerCombinatorial());
//toTest.add(new IsomorphismHandlerCSPHighHeuristics());
toTest.add(new IsomorphismHandlerParallel());
toTest.add(new IsomorphismHandlerCombinatorial());
toTest.add(new IsomorphismHandlerCSPHighHeuristics());
toTest.add(new IsomorphismHandlerCSPLowHeuristics());
//toTest.add(new IsomorphismHandlerDepthFirstBacktracking());
//toTest.add(new IsomorphismHandlerSorting());
toTest.add(new IsomorphismHandlerDepthFirstBacktracking());
toTest.add(new IsomorphismHandlerSorting());

boolean debug = false;
int fromLevel = 3;
int toLevel = 3;
int fromLevel = 1;
int toLevel = 1;
boolean drawSigmaJs = false;
boolean drawAlchemyJs = false;

Expand Down

0 comments on commit db6f64e

Please sign in to comment.