Program2

SetDirectory[NotebookDirectory[]];
ClearAll[program2];
program2[s_String]:= Module[{adj,m,dd,skalazott,ddd2,ddd3,t,ddd,cc,v},
adj=Import[s,"AdjacencyMatrix"];
v=Import[s,"VertexCount"];
m=(adj/(Total[adj,2]));
dd=DiagonalMatrix[1/(Sqrt[m.ConstantArray[1.,v]])];
skalazott=dd.m.dd;
t=Table[ {Eigenvectors[skalazott][[2]][[i]] , Eigenvectors[skalazott][[3]][[i]]},{i,v}];
ddd=dd.t;
cc=ClusteringComponents[ddd,3,1];
GraphPlot[AdjacencyGraph[adj],VertexRenderingFunction->({If[cc[[#2]]==1,Orange,If[cc[[#3]]==2,Red,Blue]],EdgeForm[Black],Disk[#,.15]}&),ImageSize->800]]

program2["karate.gml"]

program2["dolphins.gml"]

Program k

SetDirectory[NotebookDirectory[]];
ClearAll[programk];
programk[s_String, k_Integer]:= Module[{adj,m,dd,skalazott,ddd2,ddd3,t,ddd,cc,v,lista},
adj=Import[s,"AdjacencyMatrix"];
v=Import[s,"VertexCount"];
m=(adj/(Total[adj,2]));
dd=DiagonalMatrix[1/(Sqrt[m.ConstantArray[1.,v]])];
skalazott=dd.m.dd;
lista[2]=Eigenvectors[skalazott][[2]];
lista[n_]:= Table[Flatten[{lista[n-1][[i]],Eigenvectors[skalazott][[n]][[i]]}],{i, Length[Eigenvectors[skalazott][[2]]]}];
ddd=dd.lista[k];
cc=ClusteringComponents[ddd,k,1];
GraphPlot[AdjacencyGraph[adj],VertexRenderingFunction->({If[cc[[#2]]==1,Orange,If[cc[[#3]]==2,Red,Blue]],EdgeForm[Black],Disk[#,.15]}&),ImageSize->800]] (*a színezést még nem sikerült megoldanom*)

programk["karate.gml",2]

programk["dolphins.gml",3]