How to know if a network of nodes are connected to each other?
16 次查看(过去 30 天)
显示 更早的评论
Good Morning. I wanted to ask if there is any function that allows me to know if all the nodes of a network in a mesh can communicate with each other. That is, any coordinate point (in 2D) can communicate with any other coordinate point (2D) through a "path" that I already have drawn in a matrix.
I leave the following example so that it is better understood:
This is my matrix that relates the name of the element (1st column) that is joined by 2 nodes whose names are in the 2nd and 3rd column.
Data_Elementos =
1 1 7
2 7 8
3 8 2
4 7 9
5 8 10
6 4 9
7 9 13
8 9 10
9 13 14
10 14 10
11 10 3
12 6 11
13 11 9
14 11 15
15 12 5
16 10 12
17 12 16
18 16 14
19 15 13
20 15 16
21 11 12
The graph of that mesh is this (to contrast the information of the matrix):
I need to know if there is a function that tells me if all the nodes of the mesh (1,7,4,9,13,6,11,15) are connected by some route with all the other nodes.
Thank you very much for your time.
0 个评论
采纳的回答
Steven Lord
2021-1-6
编辑:Steven Lord
2021-1-6
Data_Elementos =[...
1 1 7;
2 7 8;
3 8 2;
4 7 9;
5 8 10;
6 4 9;
7 9 13;
8 9 10;
9 13 14;
10 14 10;
11 10 3;
12 6 11;
13 11 9;
14 11 15;
15 12 5;
16 10 12;
17 12 16;
18 16 14;
19 15 13;
20 15 16;
21 11 12];
G = graph(Data_Elementos(:, 2), Data_Elementos(:, 3));
plot(G)
This doesn't look like the picture you posted, but that's because I don't have the coordinates of the vertices. If you did have those coordinates, you could specify them in the plot call (like plot(G, 'XData', xcoords, 'YData', ycoords) or plot(G, 'XData', xcoords, 'YData', ycoords, 'ZData', zcoords)).
Now to determine if all the points in a set are connected you could check if the distance matrix between points in that set is all finite.
pointsInSet = [1,7,4,9,13,6,11,15];
d = distances(G, pointsInSet, pointsInSet);
all(isfinite(d), 'all')
If I remove the edge [1 7] node 1 is no longer connected to the rest of the graph.
G2 = rmedge(G, 1, 7);
d2 = distances(G2, pointsInSet, pointsInSet);
all(isfinite(d2), 'all')
2 个评论
Steven Lord
2021-1-6
The distance (measured by a car driving) between Boston, Massachusetts and New York, New York is finite. You can drive from Boston to New York and vice versa.
The distance (measured by a car driving) between Boston, Massachusetts and Sydney, Australia is non-finite. You can't get between the two cities only by driving (unless you have an amphibious car -- the duck boats used in Boston don't count as they aren't AFAIK ocean-worthy.)
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!