β08-14-2021 11:21 PM
Hi! I want to find all closed circles in a directed connection diagram. That is, a node has a path back to itself through any node. Thank you very much!
β08-15-2021 10:36 PM
Hi,
You may try using the following code snippet to find the loops in the path.
MATCH p=((n)-[*..10]-(m)) WHERE ID(n)=Id(m) RETURN p
This code uses ID to find the same starting and ending node upto 10 hops. The maximum number of hops can be defined using param tag if required.
Best
Ishwarya
β08-15-2021 11:40 PM
Thank you very much!
β08-16-2021 04:07 AM
Hi @ruanlovelin !
This is probably one of the most expected functionalities on APOC. You should also consider cycles that are not closing on your starting node tho. I'm sending you an example of a working cypher on a small dummy db.
MATCH (p:NODE {ID: 4})
CALL apoc.path.expandConfig(p, {
relationshipFilter: "CON>",
minLevel: 1
})
YIELD path
with relationships(path) as rel, path
UNWIND rel as r
WITH path, rel, endNode(r) as node, count(endNode(r)) as c
where c> 1
RETURN path
UNION
MATCH (p:NODE {ID: 4})
CALL apoc.path.expandConfig(p, {
relationshipFilter: "CON>",
minLevel: 1,
terminatorNodes: [p]
})
YIELD path
RETURN path
H
β08-17-2021 02:38 AM
I haven't understood it in a short time. I'll ask you if I have any questions .Thank you very much!
β08-17-2021 03:03 AM
Hi!
First part of the union should calculate cycles that doesn't close on initial node. Second part does it.
H
β08-18-2021 07:43 PM
Thank you for your reply, I really appreciate it. I want to query whether a node is in a closed circleοΌOr query all such circles. Could you tell me the second part solve it or not?
β08-19-2021 02:44 AM
Hi,
Second part will give you cycles that start and close on the node p you define.
H
β08-19-2021 05:21 PM
Thank you very much!
OnΒ November 16 and 17 for 24 hours across all timezones, youβll learn about best practices for beginners and experts alike.