# How group nodes if a path exists between nodes?

**URL:** https://discourse.julialang.org/t/how-group-nodes-if-a-path-exists-between-nodes/70127
**Category:** Graphs
**Tags:** lightgraphs, graphs
**Created:** [October 21, 2021, 5:24am UTC](https://discourse.julialang.org/t/how-group-nodes-if-a-path-exists-between-nodes/70127 "2021-10-21T05:24:47Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Manu\_Francis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manu_francis/32/10010_2.png) [@Manu\_Francis](https://discourse.julialang.org/u/Manu_Francis)
#### Post date: [October 21, 2021, 5:24am UTC](https://discourse.julialang.org/t/how-group-nodes-if-a-path-exists-between-nodes/70127/1 "2021-10-21T05:24:47Z")

</div>

Hi,  
If I have some nodes coordinates and I have to group these nodes together if there is path exist between them. Is there any algorithm available?

The graph structure looks like below:

```julia
# Load the packages
using LightGraphs, GraphPlot, MetaGraphs, GraphRecipes, Plots
# Create a generic graph
gr = SimpleGraph()
add_vertices!(gr, size(mat_arcTwoNodes, 1))
# Add edges based on the adjacency matrix
for i in 1:size(mat_arcTwoNodes, 1), j in 1:size(mat_arcTwoNodes, 2)
    if mat_arcTwoNodes[i,j] != 0
        add_edge!(gr, i, j)
    else
        nothing
    end
end
# Attach the metagraph to the original graph
mgr = MetaGraph(gr)
# Add the attribute of nodes
for i in 1:size(mat_arcTwoNodes,1)
    set_props!(mgr, i, Dict(
        Symbol("vec_xNode") => vec_xNode[i],
        Symbol("vec_yNode") => vec_yNode[i]
        ))
end
nodelabel = 1:nv(g)
# Plot the graph
graphplot(gr, x=vec_xNode, y=vec_yNode, names = 1:10, markersize = 2.0)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/6/0611b45d482ed999942b572bb731983836caff25.png)

If I have co-ordinates of nodes 4,5,6,7 and 3 in the graph generated using above code. I have to group 4,5, and 6 together and 3 and 7 as another group. Is there any algorithm available for this kind of grouping?

Thanks in advance,

Manu

---

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [October 21, 2021, 8:15am UTC](https://discourse.julialang.org/t/how-group-nodes-if-a-path-exists-between-nodes/70127/2 "2021-10-21T08:15:55Z")

</div>

Check [Find k-cliques in a graph](https://discourse.julialang.org/t/find-k-cliques-in-a-graph/24022/1)
