aboutsummaryrefslogtreecommitdiff
path: root/src/uk/ac/ox/cs/pagoda/endomorph/plan
diff options
context:
space:
mode:
authorRncLsn <rnc.lsn@gmail.com>2015-05-28 17:24:00 +0100
committerRncLsn <rnc.lsn@gmail.com>2015-05-28 17:24:00 +0100
commit1055e67727b1aca80ae7ffaceabce3aacb00b6d2 (patch)
tree71632dfc0fdf596d0286a4912245cacedfd2b534 /src/uk/ac/ox/cs/pagoda/endomorph/plan
parentde3749532d060f26c966a81c03f9a5d846c33d06 (diff)
parent4f98cb7df7f2921808d825cdcd82f95a0899640e (diff)
downloadACQuA-1055e67727b1aca80ae7ffaceabce3aacb00b6d2.tar.gz
ACQuA-1055e67727b1aca80ae7ffaceabce3aacb00b6d2.zip
Merge branch 'upstream' into Query-dependent-skolemisation
Conflicts: src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java src/uk/ac/ox/cs/pagoda/query/GapByStore4ID2.java src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java src/uk/ac/ox/cs/pagoda/util/Utility.java test/uk/ac/ox/cs/pagoda/junit/ClauseTester.java test/uk/ac/ox/cs/pagoda/junit/TestGapMappedToLower.java
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/endomorph/plan')
-rw-r--r--src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java85
-rw-r--r--src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java67
2 files changed, 82 insertions, 70 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java b/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java
index 862fdc8..4e2fc5f 100644
--- a/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java
+++ b/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java
@@ -1,81 +1,88 @@
1package uk.ac.ox.cs.pagoda.endomorph.plan; 1package uk.ac.ox.cs.pagoda.endomorph.plan;
2 2
3import uk.ac.ox.cs.pagoda.endomorph.Clique; 3import java.util.Collection;
4import java.util.Collections;
5import java.util.LinkedList;
6import java.util.Map;
7import java.util.Set;
8import java.util.concurrent.ConcurrentHashMap;
9import java.util.concurrent.ConcurrentLinkedDeque;
10import java.util.concurrent.atomic.AtomicInteger;
11
4import uk.ac.ox.cs.pagoda.endomorph.DependencyGraph; 12import uk.ac.ox.cs.pagoda.endomorph.DependencyGraph;
13import uk.ac.ox.cs.pagoda.endomorph.Clique;
5import uk.ac.ox.cs.pagoda.query.AnswerTuple; 14import uk.ac.ox.cs.pagoda.query.AnswerTuple;
6import uk.ac.ox.cs.pagoda.reasoner.full.Checker; 15import uk.ac.ox.cs.pagoda.reasoner.full.Checker;
7import uk.ac.ox.cs.pagoda.reasoner.full.HermitChecker; 16import uk.ac.ox.cs.pagoda.reasoner.full.HermitChecker;
8import uk.ac.ox.cs.pagoda.util.Utility; 17import uk.ac.ox.cs.pagoda.util.Utility;
9 18
10import java.util.*;
11import java.util.concurrent.ConcurrentHashMap;
12import java.util.concurrent.ConcurrentLinkedDeque;
13import java.util.concurrent.atomic.AtomicInteger;
14
15public class OpenEndMultiThreadPlan implements CheckPlan { 19public class OpenEndMultiThreadPlan implements CheckPlan {
16 20
17 Checker checker; 21 Checker checker;
18 DependencyGraph dGraph; 22 DependencyGraph dGraph;
19 // Clique[] topo; 23
20// AtomicInteger open, end;
21 ConcurrentLinkedDeque<Clique> topo;
22 Set<Clique> validated, falsified;
23 AtomicInteger counter = new AtomicInteger();
24
25 public OpenEndMultiThreadPlan(Checker checker, DependencyGraph dGraph) { 24 public OpenEndMultiThreadPlan(Checker checker, DependencyGraph dGraph) {
26 this.checker = checker; 25 this.checker = checker;
27 this.dGraph = dGraph; 26 this.dGraph = dGraph;
28 } 27 }
29 28
29// Clique[] topo;
30// AtomicInteger open, end;
31 ConcurrentLinkedDeque<Clique> topo;
32
33 Set<Clique> validated, falsified;
34
30 @Override 35 @Override
31 public int check() { 36 public int check() {
32 Collection<Clique> cliques = dGraph.getTopologicalOrder(); 37 Collection<Clique> cliques = dGraph.getTopologicalOrder();
33// topo = new LinkedBlockingDeque<Clique>(cliques); 38// topo = new LinkedBlockingDeque<Clique>(cliques);
34 topo = new ConcurrentLinkedDeque<Clique>(cliques); 39 topo = new ConcurrentLinkedDeque<Clique>(cliques);
35 40
36// topo = new Clique[cliques.size()]; 41// topo = new Clique[cliques.size()];
37// int index = 0; 42// int index = 0;
38// for (Clique clique: cliques) topo[index++] = clique; 43// for (Clique clique: cliques) topo[index++] = clique;
39// open = new AtomicInteger(); 44// open = new AtomicInteger();
40// end = new AtomicInteger(cliques.size() - 1); 45// end = new AtomicInteger(cliques.size() - 1);
41 46
42// validated = Collections.synchronizedSet(new HashSet<Clique>()); 47// validated = Collections.synchronizedSet(new HashSet<Clique>());
43// falsified = Collections.synchronizedSet(new HashSet<Clique>()); 48// falsified = Collections.synchronizedSet(new HashSet<Clique>());
44 validated = Collections.newSetFromMap(new ConcurrentHashMap<Clique, Boolean>()); 49 validated = Collections.newSetFromMap(new ConcurrentHashMap<Clique, Boolean>());
45 falsified = Collections.newSetFromMap(new ConcurrentHashMap<Clique, Boolean>()); 50 falsified = Collections.newSetFromMap(new ConcurrentHashMap<Clique, Boolean>());
46 51
47 int numOfThreads = 10; 52 int numOfThreads = 10;
48 Collection<Thread> threads = new LinkedList<Thread>(); 53 Collection<Thread> threads = new LinkedList<Thread>();
49 for(int i = 0; i < numOfThreads; ++i) 54 for (int i = 0; i < numOfThreads; ++i)
50 threads.add(new Thread(new SubThread(new HermitChecker(checker), i))); 55 threads.add(new Thread(new SubThread(new HermitChecker(checker), i)));
51 56
52 for (Thread thread: threads) thread.start(); 57 for (Thread thread: threads) thread.start();
53 58
54 for (Thread thread: threads) { 59 for (Thread thread: threads) {
55 try { 60 try {
56 thread.join(); 61 thread.join();
57 } catch (InterruptedException e) { 62 } catch (InterruptedException e) {
58 e.printStackTrace(); 63 e.printStackTrace();
59 } 64 }
60 } 65 }
61 66
62 Utility.logDebug("HermiT was called " + counter.get() + " times."); 67 Utility.logDebug("HermiT was called " + counter.get() + " times.");
63 68
64 int count = 0; 69 int count = 0;
65 for (Clique c: dGraph.getTopologicalOrder()) { 70 for (Clique c: dGraph.getTopologicalOrder()) {
66 if (validated.contains(c)) 71 if (validated.contains(c))
67 count += c.getNodeTuples().size(); 72 count += c.getNodeTuples().size();
68 } 73 }
69 return count; 74 return count;
70 } 75 }
71 76
72 private void setMarkCascadely(Clique clique, Set<Clique> marked, Map<Clique, Collection<Clique>> edges) { 77 private void setMarkCascadely(Clique clique, Set<Clique> marked, Map<Clique, Collection<Clique>> edges) {
73 marked.add(clique); 78 marked.add(clique);
74 if (edges.containsKey(clique)) 79 if (edges.containsKey(clique))
75 for (Clique c: edges.get(clique)) 80 for (Clique c: edges.get(clique))
76 if(!marked.contains(c)) 81 if (!marked.contains(c))
77 setMarkCascadely(c, marked, edges); 82 setMarkCascadely(c, marked, edges);
78 } 83 }
84
85 AtomicInteger counter = new AtomicInteger();
79 86
80 class SubThread implements Runnable { 87 class SubThread implements Runnable {
81 88
diff --git a/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java b/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java
index 3294c31..a740833 100644
--- a/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java
+++ b/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java
@@ -1,7 +1,12 @@
1package uk.ac.ox.cs.pagoda.endomorph.plan; 1package uk.ac.ox.cs.pagoda.endomorph.plan;
2 2
3import uk.ac.ox.cs.pagoda.endomorph.Clique; 3import java.util.Collection;
4import uk.ac.ox.cs.pagoda.endomorph.DependencyGraph; 4import java.util.HashSet;
5import java.util.LinkedList;
6import java.util.Map;
7import java.util.Set;
8
9import uk.ac.ox.cs.pagoda.endomorph.*;
5import uk.ac.ox.cs.pagoda.query.AnswerTuple; 10import uk.ac.ox.cs.pagoda.query.AnswerTuple;
6import uk.ac.ox.cs.pagoda.query.QueryRecord; 11import uk.ac.ox.cs.pagoda.query.QueryRecord;
7import uk.ac.ox.cs.pagoda.query.QueryRecord.Step; 12import uk.ac.ox.cs.pagoda.query.QueryRecord.Step;
@@ -10,40 +15,40 @@ import uk.ac.ox.cs.pagoda.summary.NodeTuple;
10import uk.ac.ox.cs.pagoda.util.Timer; 15import uk.ac.ox.cs.pagoda.util.Timer;
11import uk.ac.ox.cs.pagoda.util.Utility; 16import uk.ac.ox.cs.pagoda.util.Utility;
12 17
13import java.util.*;
14
15public class OpenEndPlan implements CheckPlan { 18public class OpenEndPlan implements CheckPlan {
16 19
17 public static final int TIME_OUT_MIN = 1; 20 public static final int TIME_OUT_MIN = 1;
18 21
19 Checker checker; 22 Checker checker;
20 DependencyGraph dGraph; 23 DependencyGraph dGraph;
21 QueryRecord m_record; 24 QueryRecord m_record;
22 int m_answerArity; 25 int m_answerArity;
23 Set<Clique> validated = new HashSet<Clique>(); 26
24 Set<Clique> falsified = new HashSet<Clique>();
25 Set<AnswerTuple> passedAnswers = new HashSet<AnswerTuple>();
26 public OpenEndPlan(Checker checker, DependencyGraph dGraph, QueryRecord record) { 27 public OpenEndPlan(Checker checker, DependencyGraph dGraph, QueryRecord record) {
27 this.checker = checker; 28 this.checker = checker;
28 this.dGraph = dGraph; 29 this.dGraph = dGraph;
29 m_record = record; 30 m_record = record;
30 m_answerArity = record.getAnswerVariables().length; 31 m_answerArity = record.getAnswerVariables().length;
31 } 32 }
32 33
34 Set<Clique> validated = new HashSet<Clique>();
35 Set<Clique> falsified = new HashSet<Clique>();
36 Set<AnswerTuple> passedAnswers = new HashSet<AnswerTuple>();
37
33 @Override 38 @Override
34 public int check() { 39 public int check() {
35 LinkedList<Clique> topo = new LinkedList<Clique>(dGraph.getTopologicalOrder()); 40 LinkedList<Clique> topo = new LinkedList<Clique>(dGraph.getTopologicalOrder());
36 Utility.logInfo("Entrances: " + dGraph.getEntrances().size() + " Exists: " + dGraph.getExits().size()); 41 Utility.logInfo("Entrances: " + dGraph.getEntrances().size() + " Exists: " + dGraph.getExits().size());
37 42
38 boolean flag = true; 43 boolean flag = true;
39 Clique clique; 44 Clique clique;
40 Timer t = new Timer(); 45 Timer t = new Timer();
41 46
42 AnswerTuple answerTuple; 47 AnswerTuple answerTuple;
43 while (!topo.isEmpty()) { 48 while (!topo.isEmpty()) {
44 if (flag) { 49 if (flag) {
45 clique = topo.removeFirst(); 50 clique = topo.removeFirst();
46 if(redundant(clique)) continue; 51 if (redundant(clique)) continue;
47 if (validated.contains(clique)) continue; 52 if (validated.contains(clique)) continue;
48 if (falsified.contains(clique)) { flag = false; continue; } 53 if (falsified.contains(clique)) { flag = false; continue; }
49 Utility.logDebug("start checking front ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); 54 Utility.logDebug("start checking front ... " + (answerTuple = clique.getRepresentative().getAnswerTuple()));
@@ -60,8 +65,8 @@ public class OpenEndPlan implements CheckPlan {
60 clique = topo.removeLast(); 65 clique = topo.removeLast();
61 if (falsified.contains(clique)) continue; 66 if (falsified.contains(clique)) continue;
62 if (validated.contains(clique)) { flag = true; continue; } 67 if (validated.contains(clique)) { flag = true; continue; }
63 Utility.logDebug("start checking back ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); 68 Utility.logDebug("start checking back ... " + (answerTuple = clique.getRepresentative().getAnswerTuple()));
64 if(!checker.check(answerTuple)) 69 if (!checker.check(answerTuple))
65 setMarkCascadelyFasified(clique); 70 setMarkCascadelyFasified(clique);
66 else { 71 else {
67 Utility.logDebug(answerTuple.toString() + " is verified."); 72 Utility.logDebug(answerTuple.toString() + " is verified.");
@@ -88,38 +93,38 @@ public class OpenEndPlan implements CheckPlan {
88 } 93 }
89 94
90 m_record.addLowerBoundAnswers(validAnswers); 95 m_record.addLowerBoundAnswers(validAnswers);
91 m_record.addProcessingTime(Step.FULL_REASONING, t.duration()); 96 m_record.addProcessingTime(Step.FullReasoning, t.duration());
92 return count; 97 return count;
93 } 98 }
94 99
95 private boolean redundant(Clique clique) { 100 private boolean redundant(Clique clique) {
96 for(NodeTuple nodeTuple : clique.getNodeTuples()) 101 for (NodeTuple nodeTuple: clique.getNodeTuples())
97 if(!passedAnswers.contains(AnswerTuple.getInstance(nodeTuple.getAnswerTuple(), m_answerArity))) 102 if (!passedAnswers.contains(AnswerTuple.create(nodeTuple.getAnswerTuple(), m_answerArity)))
98 return false; 103 return false;
99 return true; 104 return true;
100 } 105 }
101 106
102 private void addProjections(Clique clique) { 107 private void addProjections(Clique clique) {
103 for(NodeTuple nodeTuple : clique.getNodeTuples()) 108 for (NodeTuple nodeTuple: clique.getNodeTuples())
104 passedAnswers.add(AnswerTuple.getInstance(nodeTuple.getAnswerTuple(), m_answerArity)); 109 passedAnswers.add(AnswerTuple.create(nodeTuple.getAnswerTuple(), m_answerArity));
105 } 110 }
106 111
107 private void setMarkCascadelyValidated(Clique clique) { 112 private void setMarkCascadelyValidated(Clique clique) {
108 validated.add(clique); 113 validated.add(clique);
109 addProjections(clique); 114 addProjections(clique);
110 Map<Clique, Collection<Clique>> edges = dGraph.getOutGoingEdges(); 115 Map<Clique, Collection<Clique>> edges = dGraph.getOutGoingEdges();
111 if (edges.containsKey(clique)) 116 if (edges.containsKey(clique))
112 for (Clique c: edges.get(clique)) 117 for (Clique c: edges.get(clique))
113 if(!validated.contains(c)) 118 if (!validated.contains(c))
114 setMarkCascadelyValidated(c); 119 setMarkCascadelyValidated(c);
115 } 120 }
116 121
117 private void setMarkCascadelyFasified(Clique clique) { 122 private void setMarkCascadelyFasified(Clique clique) {
118 falsified.add(clique); 123 falsified.add(clique);
119 Map<Clique, Collection<Clique>> edges = dGraph.getInComingEdges(); 124 Map<Clique, Collection<Clique>> edges = dGraph.getInComingEdges();
120 if(edges.containsKey(clique)) 125 if (edges.containsKey(clique))
121 for(Clique c : edges.get(clique)) 126 for (Clique c: edges.get(clique))
122 if(!falsified.contains(c)) 127 if (!falsified.contains(c))
123 setMarkCascadelyFasified(c); 128 setMarkCascadelyFasified(c);
124 } 129 }
125 130