Christian Kniep
Christian Kniep

Reputation: 71

How to filter out cycles in CYPHER query

I am playing around with an inventory for a network technique. I got (https://i.sstatic.net/3dCeL.png):

ports are PART_OF network cards or switches. Ports are bidirectional connected via 'CON'.

If I now want to get the path from HCA1 to HCA2 I am not only getting the path hca1->hca1_port->sw_in_port->sw->sw_out_port->hca2_port->hca2 but also the loops through switch0 and switch1.

My query looks like this:

START a=node:node_auto_index(name="Hca1"),  
b=node:node_auto_index(name="Hca2")
MATCH p=a-[r*2..15]-b
return a,b,p`

The result: https://i.sstatic.net/bKjLP.png

How do I query for straight pathes without cycles? Anyone?

Cheers Christian

Upvotes: 2

Views: 209

Answers (2)

Christian Kniep
Christian Kniep

Reputation: 71

Oh and shortest path is also working.

allShortestPaths will be quite big if I push in a bigger topology (CLOS, which has a lot of allShortestPaths

START a=node:node_auto_index(name="Hca1"),       
      b=node:node_auto_index(name="Hca6")
MATCH p= allShortestPaths((a)-[*]-(b))
RETURN a,b,p

returns: enter image description here

only one of them:

MATCH (start:HCA { name:"Hca1" }),(end:HCA { name:"Hca6" }),
p = shortestPath((start)-[*..15]-(end))
RETURN p

result: enter image description here

Upvotes: 1

Christian Kniep
Christian Kniep

Reputation: 71

Ah, cool allShortestPaths seems to work for me.

START a=node:node_auto_index(name="Hca1"),
      b=node:node_auto_index(name="Hca2")
MATCH p= allShortestPaths((a)-[*]-(b))
return a,b,p

results in ths graph...

enter image description here

Thanks guys.

Upvotes: 1

Related Questions