Algorithm for checking connectivity of a lattice graph in Rn
Afficher commentaires plus anciens
Two points are adjacent if they have n-1 equal coordinates and 1 coordinate that differ by 1. For example, (1,4,3,0) in R^4 is adjacent to 8 points (0,4,3,0), (2,4,3,0), (1,3,3,0), (1,5,3,0), (1,4,2,0), (1,4,4,0), (1,4,3,-1) and (1,4,3,1). Two points are connected if there is a sequence of points between them, every two consecutive points are adjacent.
Suppose the input is a set of lattice points in R^n. What is a fast algorithm to check if they are connected? I only need to determine the connectivity (no need to find connected components); suppose all the points are contained in a given cube say [0,k]^n if this helps.
Thanks.
4 commentaires
Assuming you have the coordinates as numeric vectors or arrays -
p1=[1,4,3,0] ;
n=numel(p1); %dimension of the space
fun = @(x) isequal(sort(abs(p1-x)),[zeros(1,n-1) 1]);
This assumes that coordinates are checked correspondingly (x to x, y to y, z to z ....)
p2=[0,4,3,0];
fun(p2)
p3=[2,4,3,0];
fun(p3)
p4=[1,3,3,0];
fun(p4)
%non-adjacent point
p5=[1,2,3,4];
fun(p5)
You can also modify the function handle for checking for any two pairs as well
Fun = @(in1,in2) isequal(sort(abs(in1-in2)),[zeros(1,n-1) 1]);
Haoran
le 9 Fév 2023
Dyuman Joshi
le 9 Fév 2023
How are the points stored? As numeric arrays corresponding to each dimension?
Please specify if otherwise.
Haoran
le 9 Fév 2023
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!