Here is my problem statement:
I have a cube with specified dimensions. as time passes, some balls are generated in this cube. I have simulated the the coordinates (x,y,z location), time of generation and size of the balls. Now I need to find the shortest path of overlapped balls that connect upper side of the cube to the lower and find the time that this path is completed.
What I thought up to now is to find the pair euclidean distance between all the points and the pair sum of the ball radius. Then compare the distance to the sum to find the overlapping matrix. Then find all objects at the top that have z-size less than 0 and z+size greater than depth of the cube and then I should find the path. I appreciate any help and idea in advance.
For example consider the following data and the code that I've developed up to now:
offspr_x = [1 3 5 1 2]
offspr_y = [3 3 1 8 2]
offspr_z = [1 4 5 3 2]
size = [2 1 4 6 3]
time = [2 5 6 3 8]
Pos= [offspr_x' offspr_y' offspr_z']
dd=pdist(Pos,'euclidean')
ddm = squareform(dd)
% compute similar matrix based on sum of object sizes (assumes size is radius)
drad = meshgrid(size)+ meshgrid(size)';
dadj = ddm.*(ddm <= drad);
Now I need to convert the overlap matrix to a graph object and try to find the shortest path between those points that offspr_z-size < 0 (all objects at the top have z-size less than 0) and offspr_z+size > 5 (objects at bottom have z+size greater than 5):
starts = find(offspr_z-size < 0)
ends = find(offspr_z+size > 5)
UPDATE: As @beaker suggested, I also tried Floyd–Warshall and here is the code that I used:
function D = FastFloyd(D)
n = size(D, 1);
for k=1:n
i2k = repmat(D(:,k), 1, n);
k2j = repmat(D(k,:), n, 1);
D = min(D, i2k+k2j);
end
end
Therefore, for:
dadj(dadj==0)=Inf
D = FastFloyd(dadj)
I got the following result:
D =
3.4641 4.1815 6.0000 5.3852 1.7321
4.1815 4.8990 3.0000 5.4772 2.4495
6.0000 3.0000 6.0000 8.3066 4.3589
5.3852 5.4772 8.3066 10.7703 6.1644
1.7321 2.4495 4.3589 6.1644 3.4641
But I need to find the shortest (soonest) path between starts and ends vectors (those points that overlap the upper and lower surface of the cube). I say soonest because I'm not interested in the least distance but in the least time of generation ...