print paths with cycles

167 views
Skip to first unread message

M.Alipour

unread,
May 10, 2012, 4:00:14 AM5/10/12
to Neo4j
Hi,
Is there a way to "print" "paths that have cycles" in a Directed
Cycling Graph that
created by Neo4j graph database service?
Thanks.

Mattias Persson

unread,
May 10, 2012, 4:05:29 AM5/10/12
to ne...@googlegroups.com
You can create a traversal with certain criterias and look at each returned path if it contains any node more than once. What are querying, paths between start/end nodes or something else?

2012/5/10 M.Alipour <mahdiali...@gmail.com>



--
Mattias Persson, [mat...@neotechnology.com]
Hacker, Neo Technology
www.neotechnology.com

Michael Hunger

unread,
May 10, 2012, 4:13:17 AM5/10/12
to ne...@googlegroups.com
If you have potential starting candidate or starting nodes this would be faster otherwise you have to probably start traversals from all nodes in the graph.

What is the size of your graph?

For smaller graphs a cypher query like this should do it: start n=node(*) match p=n-[*]-n return n,p

If you have better starting points than just _all_ nodes it would of course be better and more limits on relationship-type and direction would speed it up too.
(e.g. start n=node(*) match p=n-[:KNOWS*]->n return n,p)

Michael

M.Alipour

unread,
May 10, 2012, 5:28:38 AM5/10/12
to Neo4j
Thanks,
I want to get "all cycles" in my graph, then, by remove these cycles,
convert my graph to a DAG.
Graph size:290000 nodes.


On May 10, 12:05 pm, Mattias Persson <matt...@neotechnology.com>
wrote:
> You can create a traversal with certain criterias and look at each returned
> path if it contains any node more than once. What are querying, paths
> between start/end nodes or something else?
>
> 2012/5/10 M.Alipour <mahdialipour2...@gmail.com>
>
> > Hi,
> > Is there a way to "print" "paths that have cycles" in a Directed
> > Cycling Graph that
> > created by Neo4j graph database service?
> > Thanks.
>
> --
> Mattias Persson, [matt...@neotechnology.com]
> Hacker, Neo Technologywww.neotechnology.com

Michael Hunger

unread,
May 10, 2012, 5:36:51 AM5/10/12
to ne...@googlegroups.com
That's not too big.

so if you know which of the relationships in the cycle you want to remove it gets easier.
It would also be easier if you know the max-length of your potential cycles.

Is your graph fully connected? Or are there isolated subgraphs?

with cypher in 1.8 you can do:

start n=node(*) match n-[*0..]->x-[r:TYPE]->n delete r

with a traversal it is similar, you start at a node and traverse from there up until your max length or until you hit the start-node again (or another node that is already on your path) and your remove the last relationship to it.

Michael

Mattias Persson

unread,
May 10, 2012, 7:03:04 AM5/10/12
to ne...@googlegroups.com


2012/5/10 M.Alipour <mahdiali...@gmail.com>

Thanks,
I want to get "all cycles" in my graph, then, by remove these cycles,
convert my graph to a DAG.
Graph size:290000 nodes.

"all cycles" is not really something that computes to me. You have to have some kind of relationship types/directions to traverse your paths with. Graphs are connected and if you just look at nodes and relationships there are cycles absolutely everywhere.

On May 10, 12:05 pm, Mattias Persson <matt...@neotechnology.com>
wrote:
> You can create a traversal with certain criterias and look at each returned
> path if it contains any node more than once. What are querying, paths
> between start/end nodes or something else?
>
> 2012/5/10 M.Alipour <mahdialipour2...@gmail.com>
>
> > Hi,
> > Is there a way to "print" "paths that have cycles" in a Directed
> > Cycling Graph that
> > created by Neo4j graph database service?
> > Thanks.
>
> --
> Mattias Persson, [matt...@neotechnology.com]
> Hacker, Neo Technologywww.neotechnology.com

Jacopo Farina

unread,
May 10, 2012, 11:10:21 AM5/10/12
to ne...@googlegroups.com
It's about strongly connected components in graphs, and a SCC imply the existence of at least one cycle. I used it with a 7M nodes graph and worked pretty well, but that code is based on the embedded version of Neo4j.
Cheers,
Jacopo Farina

2012/5/10 Mattias Persson <mat...@neotechnology.com>
Message has been deleted

TC

unread,
Jun 3, 2014, 5:43:25 PM6/3/14
to ne...@googlegroups.com
can you post the link again? i cannot search for it now.
i need to make spanning trees in graphs while it has cycles during traversal so i have to make it converted to DAG.
Reply all
Reply to author
Forward
0 new messages