Skip to content

Instantly share code, notes, and snippets.

@import-benjamin
Created November 25, 2017 14:46
Show Gist options
  • Save import-benjamin/8ec1287794e99ca179aef5623a9adfc0 to your computer and use it in GitHub Desktop.
Save import-benjamin/8ec1287794e99ca179aef5623a9adfc0 to your computer and use it in GitHub Desktop.
graph theory : convert adjacency matrix to incidence matrix
// desc : retourne une matrice adjacence sous forme de matrice d'incidence.
// input : matrice d'adjacence (M)
// output : matrice d'incidence (res)
function res = adja2incidence(M) // soucis : les boucles ne sont pas notées
[S, T] = mat2listes(M)
res =zeros(length(T), length(S)-1)
for k=1:size(M, 1) // on marque tout les arcs rentrant dans le sommet
res(k, predecesseurs(M,k)) = -1
end
for k=1:size(M, 1) // on marque tout les arcs sortant du sommet
succ = liste_succ(S, T, k)
boucle = find(succ==k)
if(boucle<>[]) then
res(k,boucle) = [2]
else
res(k, liste_succ(S, T, k)) = 1
end
end
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment