How to know if a network of nodes are connected to each other?

19 次查看(过去 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.

采纳的回答

Steven Lord
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')
ans = logical
1
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')
ans = logical
0
  2 个评论
Pedro Guevara
Pedro Guevara 2021-1-6
Many thanks.
I do not fully understand that "distances between the points of that set is finite", but I will analyze the code you gave me to understand what is the logic of its application. Thank you very much for your help friend.
Steven Lord
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 个)

类别

Help CenterFile Exchange 中查找有关 General Physics 的更多信息

产品


版本

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by