@@ -239,14 +239,19 @@ public AbstractGraph CreateSubsetDescendent(AbstractGraph parent, String headNod |
239 | 239 | parent.setNodeNeighbours(); |
240 | 240 |
|
241 | 241 | HashMap<String, Node> DescendentNodes = new HashMap<String, Node>(); |
| 242 | + HashMap<String,Boolean> visited = new HashMap<>(); |
242 | 243 | ArrayList<Edge> DescendentEdges = new ArrayList<>(); |
243 | 244 | ArrayList<Token> SubsetTokens = new ArrayList<>(); |
244 | 245 |
|
| 246 | + for (Node n:parent.getNodes().values()) { |
| 247 | + visited.put(n.getId(),false); |
| 248 | + } |
245 | 249 |
|
246 | 250 | Node n = parent.getNodes().get(headNodeID); |
247 | 251 |
|
248 | 252 | //Add the head Node to the descendent nodes hashmap |
249 | 253 | DescendentNodes.put(n.getId(), new Node(n)); |
| 254 | + visited.put(n.getId(),true); |
250 | 255 | for (Edge e : n.getDirectedEdgeNeighbours()) { |
251 | 256 | DescendentEdges.add(new Edge(e)); |
252 | 257 | } |
@@ -270,21 +275,24 @@ public AbstractGraph CreateSubsetDescendent(AbstractGraph parent, String headNod |
270 | 275 | Stack<Node> stack = new Stack<>(); |
271 | 276 | while (n != null) { |
272 | 277 | for (Node nn : n.getDirectedNeighbours()) { |
273 | | - DescendentNodes.put(nn.getId(), new Node(nn)); |
274 | | - stack.push(nn); |
275 | | - //Set the min and max span appropriately as found |
276 | | - if (nn.getAnchors() != null) { |
277 | | - for (int i = 0; i < nn.getAnchors().size(); i++) { |
278 | | - if (nn.getAnchors().get(i).getFrom() < minFrom) { |
279 | | - minFrom = nn.getAnchors().get(i).getFrom(); |
280 | | - } |
281 | | - if (nn.getAnchors().get(i).getEnd() > maxEnd) { |
282 | | - maxEnd = nn.getAnchors().get(i).getEnd(); |
| 278 | + if (!visited.get(nn.getId())) { |
| 279 | + DescendentNodes.put(nn.getId(), new Node(nn)); |
| 280 | + stack.push(nn); |
| 281 | + visited.put(nn.getId(), true); |
| 282 | + //Set the min and max span appropriately as found |
| 283 | + if (nn.getAnchors() != null) { |
| 284 | + for (int i = 0; i < nn.getAnchors().size(); i++) { |
| 285 | + if (nn.getAnchors().get(i).getFrom() < minFrom) { |
| 286 | + minFrom = nn.getAnchors().get(i).getFrom(); |
| 287 | + } |
| 288 | + if (nn.getAnchors().get(i).getEnd() > maxEnd) { |
| 289 | + maxEnd = nn.getAnchors().get(i).getEnd(); |
| 290 | + } |
283 | 291 | } |
284 | 292 | } |
285 | | - } |
286 | | - for (Edge ne : nn.getDirectedEdgeNeighbours()) { |
287 | | - descEdge.put(ne.getSource() + " " + ne.getTarget(), new Edge(ne)); |
| 293 | + for (Edge ne : nn.getDirectedEdgeNeighbours()) { |
| 294 | + descEdge.put(ne.getSource() + " " + ne.getTarget(), new Edge(ne)); |
| 295 | + } |
288 | 296 | } |
289 | 297 | } |
290 | 298 | if (!stack.empty()) { |
@@ -310,7 +318,6 @@ public AbstractGraph CreateSubsetDescendent(AbstractGraph parent, String headNod |
310 | 318 | return subset; |
311 | 319 | } |
312 | 320 |
|
313 | | - |
314 | 321 | /** |
315 | 322 | * Overloaded method to search for subgraph pattern using different parameters |
316 | 323 | * |
|