Generating a random graph by degree sequence

This is the first matlab program I wrote. Under the pressure of the teacher, I have to implement the pseudo code in the ...
This is the first matlab program I wrote. Under the pressure of the teacher, I have to implement the pseudo code in the paper. I refer to the rewards identity anonymization on for this program In this paper, the first algorithm of graphs is pseudocode. After writing it, I finally understand what teachers often say to learn, instead of spending a lot of time systematically learning a certain language. The main idea is to randomly select a node v with a degree of d(v) from the degree sequence, set d(v) to 0, and then select d(v) nodes from the remaining nodes to connect with it, and the degree of the connected nodes will be reduced by 1, iterating until all the degrees are 0, the edge is connected, and the random graph will be formed (code roughness, many inclusions). Theast).
d = [13,13,13,13,11,12,12,5,7,12,7,11,7,12,12,5,3,5,7,5,3,5,3,3,7,11,11]; n = length(d); V = []; tab1 = []; tab2 = []; s=0; count = 0; alen = 1; blen = 1; vlen = 1; for i = 1:n s = s + d(i); end if mod(s,2)~=0 disp('No'); return ; end while 1 for i = 1:n if(d(i)<0) disp('No'); break; end end %If all degrees are 0, output G for i = 1:n if(d(i) ==0) count = count+1; end if (count == n) G = graph(tab1,tab2); plot(G); return; end end Arr = randperm(n); for i = 1:n v = Arr(i); if d(v)>0 %Randomly select a vertex with degree greater than 0 v a = d(v); %a One and v Connected nodes d(v) = 0; [B,I] = sort(d); %And return the largest a Number,take d Sort from small to large, B Is the sorted sequence, I Is the sorted index for j = n-a+1:n %Will this a Nodes exist V in V(vlen) = I(j); vlen = vlen+1; end for k = 1:a tab2(blen) = V(blen); w = tab2(blen); d(w) = d(w)-1; tab1(alen) = v; alen = alen+1; blen = blen+1; end end i = i+1; end end

5 May 2020, 04:04 | Views: 5286

Add new comment

For adding a comment, please log in
or create account

0 comments