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

19 ビュー (過去 30 日間)
Pedro Guevara
Pedro Guevara 2021 年 1 月 5 日
コメント済み: Steven Lord 2021 年 1 月 6 日
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 Center および File ExchangeGeneral Physics についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by