Skip to content

Commit

Permalink
Add functions for reconnecting the graph
Browse files Browse the repository at this point in the history
  • Loading branch information
TeunHuijben committed Jun 14, 2020
1 parent d869beb commit 29d4d8b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
42 changes: 42 additions & 0 deletions MATLAB/avg/connectGraph.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
%connectGraph This function keeps increasing the threshold on the error
%to include more connections, untill the graph is connected.
%
% SYNOPSIS:
% [error_idx] = connectGraph(I,error)
%
% Input:
% I: 2xN matrix of indices indications the connections
% error: vector of error values for every combinations in I
%
% Output:
% error_idx: indices of the to-be-removed connection in I
%
% NOTE:
%
% (C) Copyright 2017 QI Group
% All rights reserved Faculty of Applied Physics
% Delft University of Technology
% Lorentzweg 1
% 2628 CJ Delft
% The Netherlands
%
% Teun Huijben, June 2020.

function error_idx = connectGraph(I,error)

[a,b] = sort(abs(error)); %sort the errors
first_above5 = find(a>5,1); %find the index of lowest error

error_idx = abs(error)>5; %indices of all errors
I_new = I;
I_new(:,error_idx) = []; %remove errors from graph

start = first_above5;
while (isConnected(I_new)==0 | max(I_new(:))<max(I(:)))
error_idx = (abs(error)>abs(error(b(start)))); %indices of all errors including new one
I_new = I;
I_new(:,error_idx) = [];
start = start+1;
end

end
34 changes: 34 additions & 0 deletions MATLAB/avg/isConnected.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
%isConnected This function checks whether the graph is connected
%
% SYNOPSIS:
% [connected] = isConnected(I)
%
% Input:
% I: 2xN matrix of indices indications the connections
%
% Output:
% connected: Boolean indicating whether is connected
%
% NOTE:
%
% (C) Copyright 2017 QI Group
% All rights reserved Faculty of Applied Physics
% Delft University of Technology
% Lorentzweg 1
% 2628 CJ Delft
% The Netherlands
%
% Teun Huijben, June 2020.

function connected = isConnected(I)

Gr = graph(I(1,:),I(2,:));
clusters = conncomp(Gr);
if max(clusters)==1
connected = true;
else
connected = false;
end

end

0 comments on commit 29d4d8b

Please sign in to comment.