diff options
| author | yujiao <yujiao.zhou@gmail.com> | 2015-05-25 22:07:14 -0700 |
|---|---|---|
| committer | yujiao <yujiao.zhou@gmail.com> | 2015-05-25 22:07:14 -0700 |
| commit | 4f98cb7df7f2921808d825cdcd82f95a0899640e (patch) | |
| tree | fad60a143e8f6a300c24900b53d9a32af2875e24 /src/uk/ac/ox/cs/pagoda/endomorph | |
| parent | e02ad77cefc3005e36ae48fe47bf7914007f094a (diff) | |
| download | ACQuA-4f98cb7df7f2921808d825cdcd82f95a0899640e.tar.gz ACQuA-4f98cb7df7f2921808d825cdcd82f95a0899640e.zip | |
fixed a bug in the process of generating gap tuples, see test in
TestGapMappedToLower.java
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/endomorph')
4 files changed, 46 insertions, 20 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/endomorph/Clique.java b/src/uk/ac/ox/cs/pagoda/endomorph/Clique.java index 1c269ea..9daea7e 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/Clique.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/Clique.java | |||
| @@ -13,6 +13,7 @@ public class Clique { | |||
| 13 | public Clique(NodeTuple u) { | 13 | public Clique(NodeTuple u) { |
| 14 | nodeTuples = new HashSet<NodeTuple>(); | 14 | nodeTuples = new HashSet<NodeTuple>(); |
| 15 | representative = u; | 15 | representative = u; |
| 16 | nodeTuples.add(u); | ||
| 16 | } | 17 | } |
| 17 | 18 | ||
| 18 | public boolean addNodeTuple(NodeTuple nodeTuple) { | 19 | public boolean addNodeTuple(NodeTuple nodeTuple) { |
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 8c7ce6a..4e2fc5f 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java | |||
| @@ -69,7 +69,7 @@ public class OpenEndMultiThreadPlan implements CheckPlan { | |||
| 69 | int count = 0; | 69 | int count = 0; |
| 70 | for (Clique c: dGraph.getTopologicalOrder()) { | 70 | for (Clique c: dGraph.getTopologicalOrder()) { |
| 71 | if (validated.contains(c)) | 71 | if (validated.contains(c)) |
| 72 | count += c.getNodeTuples().size() + 1; | 72 | count += c.getNodeTuples().size(); |
| 73 | } | 73 | } |
| 74 | return count; | 74 | return count; |
| 75 | } | 75 | } |
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 202021d..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,6 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.endomorph.plan; | 1 | package uk.ac.ox.cs.pagoda.endomorph.plan; |
| 2 | 2 | ||
| 3 | import java.util.Collection; | 3 | import java.util.Collection; |
| 4 | import java.util.Deque; | ||
| 5 | import java.util.HashSet; | 4 | import java.util.HashSet; |
| 6 | import java.util.LinkedList; | 5 | import java.util.LinkedList; |
| 7 | import java.util.Map; | 6 | import java.util.Map; |
| @@ -23,35 +22,39 @@ public class OpenEndPlan implements CheckPlan { | |||
| 23 | Checker checker; | 22 | Checker checker; |
| 24 | DependencyGraph dGraph; | 23 | DependencyGraph dGraph; |
| 25 | QueryRecord m_record; | 24 | QueryRecord m_record; |
| 25 | int m_answerArity; | ||
| 26 | 26 | ||
| 27 | public OpenEndPlan(Checker checker, DependencyGraph dGraph, QueryRecord record) { | 27 | public OpenEndPlan(Checker checker, DependencyGraph dGraph, QueryRecord record) { |
| 28 | this.checker = checker; | 28 | this.checker = checker; |
| 29 | this.dGraph = dGraph; | 29 | this.dGraph = dGraph; |
| 30 | m_record = record; | 30 | m_record = record; |
| 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 | Deque<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 | Set<Clique> validated = new HashSet<Clique>(); | ||
| 38 | Set<Clique> falsified = new HashSet<Clique>(); | ||
| 39 | 42 | ||
| 40 | boolean flag = true; | 43 | boolean flag = true; |
| 41 | Clique clique; | 44 | Clique clique; |
| 42 | Timer t = new Timer(); | 45 | Timer t = new Timer(); |
| 43 | 46 | ||
| 44 | 47 | AnswerTuple answerTuple; | |
| 45 | AnswerTuple answerTuple; | ||
| 46 | while (!topo.isEmpty()) { | 48 | while (!topo.isEmpty()) { |
| 47 | if (flag) { | 49 | if (flag) { |
| 48 | clique = topo.removeFirst(); | 50 | clique = topo.removeFirst(); |
| 51 | if (redundant(clique)) continue; | ||
| 49 | if (validated.contains(clique)) continue; | 52 | if (validated.contains(clique)) continue; |
| 50 | if (falsified.contains(clique)) { flag = false; continue; } | 53 | if (falsified.contains(clique)) { flag = false; continue; } |
| 51 | Utility.logDebug("start checking front ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); | 54 | Utility.logDebug("start checking front ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); |
| 52 | if (checker.check(answerTuple)) { | 55 | if (checker.check(answerTuple)) { |
| 53 | Utility.logDebug(answerTuple.toString() + " is verified."); | 56 | Utility.logDebug(answerTuple.toString() + " is verified."); |
| 54 | setMarkCascadely(clique, validated, dGraph.getOutGoingEdges()); | 57 | setMarkCascadelyValidated(clique); |
| 55 | } | 58 | } |
| 56 | else { | 59 | else { |
| 57 | falsified.add(clique); | 60 | falsified.add(clique); |
| @@ -64,10 +67,10 @@ public class OpenEndPlan implements CheckPlan { | |||
| 64 | if (validated.contains(clique)) { flag = true; continue; } | 67 | if (validated.contains(clique)) { flag = true; continue; } |
| 65 | Utility.logDebug("start checking back ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); | 68 | Utility.logDebug("start checking back ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); |
| 66 | if (!checker.check(answerTuple)) | 69 | if (!checker.check(answerTuple)) |
| 67 | setMarkCascadely(clique, falsified, dGraph.getInComingEdges()); | 70 | setMarkCascadelyFasified(clique); |
| 68 | else { | 71 | else { |
| 69 | Utility.logDebug(answerTuple.toString() + " is verified."); | 72 | Utility.logDebug(answerTuple.toString() + " is verified."); |
| 70 | validated.add(clique); | 73 | addProjections(clique); |
| 71 | flag = true; | 74 | flag = true; |
| 72 | } | 75 | } |
| 73 | } | 76 | } |
| @@ -80,9 +83,8 @@ public class OpenEndPlan implements CheckPlan { | |||
| 80 | Collection<AnswerTuple> validAnswers = new LinkedList<AnswerTuple>(); | 83 | Collection<AnswerTuple> validAnswers = new LinkedList<AnswerTuple>(); |
| 81 | for (Clique c: dGraph.getTopologicalOrder()) | 84 | for (Clique c: dGraph.getTopologicalOrder()) |
| 82 | if (validated.contains(c)) { | 85 | if (validated.contains(c)) { |
| 83 | count += c.getNodeTuples().size() + 1; | 86 | count += c.getNodeTuples().size(); |
| 84 | validAnswers.add(c.getRepresentative().getAnswerTuple()); | 87 | // validAnswers.add(c.getRepresentative().getAnswerTuple()); |
| 85 | |||
| 86 | for (NodeTuple nodeTuple: c.getNodeTuples()) { | 88 | for (NodeTuple nodeTuple: c.getNodeTuples()) { |
| 87 | ans = nodeTuple.getAnswerTuple(); | 89 | ans = nodeTuple.getAnswerTuple(); |
| 88 | validAnswers.add(ans); | 90 | validAnswers.add(ans); |
| @@ -95,12 +97,35 @@ public class OpenEndPlan implements CheckPlan { | |||
| 95 | return count; | 97 | return count; |
| 96 | } | 98 | } |
| 97 | 99 | ||
| 98 | private void setMarkCascadely(Clique clique, Set<Clique> marked, Map<Clique, Collection<Clique>> edges) { | 100 | private boolean redundant(Clique clique) { |
| 99 | marked.add(clique); | 101 | for (NodeTuple nodeTuple: clique.getNodeTuples()) |
| 102 | if (!passedAnswers.contains(AnswerTuple.create(nodeTuple.getAnswerTuple(), m_answerArity))) | ||
| 103 | return false; | ||
| 104 | return true; | ||
| 105 | } | ||
| 106 | |||
| 107 | private void addProjections(Clique clique) { | ||
| 108 | for (NodeTuple nodeTuple: clique.getNodeTuples()) | ||
| 109 | passedAnswers.add(AnswerTuple.create(nodeTuple.getAnswerTuple(), m_answerArity)); | ||
| 110 | } | ||
| 111 | |||
| 112 | private void setMarkCascadelyValidated(Clique clique) { | ||
| 113 | validated.add(clique); | ||
| 114 | addProjections(clique); | ||
| 115 | Map<Clique, Collection<Clique>> edges = dGraph.getOutGoingEdges(); | ||
| 116 | if (edges.containsKey(clique)) | ||
| 117 | for (Clique c: edges.get(clique)) | ||
| 118 | if (!validated.contains(c)) | ||
| 119 | setMarkCascadelyValidated(c); | ||
| 120 | } | ||
| 121 | |||
| 122 | private void setMarkCascadelyFasified(Clique clique) { | ||
| 123 | falsified.add(clique); | ||
| 124 | Map<Clique, Collection<Clique>> edges = dGraph.getInComingEdges(); | ||
| 100 | if (edges.containsKey(clique)) | 125 | if (edges.containsKey(clique)) |
| 101 | for (Clique c: edges.get(clique)) | 126 | for (Clique c: edges.get(clique)) |
| 102 | if (!marked.contains(c)) | 127 | if (!falsified.contains(c)) |
| 103 | setMarkCascadely(c, marked, edges); | 128 | setMarkCascadelyFasified(c); |
| 104 | } | 129 | } |
| 105 | 130 | ||
| 106 | } | 131 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/endomorph/plan/PlainPlan.java b/src/uk/ac/ox/cs/pagoda/endomorph/plan/PlainPlan.java index d6067d0..6931ccc 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/plan/PlainPlan.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/plan/PlainPlan.java | |||
| @@ -22,7 +22,7 @@ public class PlainPlan implements CheckPlan { | |||
| 22 | int count = 0; | 22 | int count = 0; |
| 23 | for (Clique clique: toCheck) | 23 | for (Clique clique: toCheck) |
| 24 | if (checker.check(clique.getRepresentative().getAnswerTuple())) { | 24 | if (checker.check(clique.getRepresentative().getAnswerTuple())) { |
| 25 | count += clique.getNodeTuples().size() + 1; | 25 | count += clique.getNodeTuples().size(); |
| 26 | for (NodeTuple nodeTuple: clique.getNodeTuples()) | 26 | for (NodeTuple nodeTuple: clique.getNodeTuples()) |
| 27 | Utility.logDebug(nodeTuple.getAnswerTuple().toString()); | 27 | Utility.logDebug(nodeTuple.getAnswerTuple().toString()); |
| 28 | } | 28 | } |
