%TODO: change the following two lines to target directories accordingly. path(path,'D:/MATLAB/meshpart'); path(path, 'D:/MATLAB'); %generating a random, symmetric matrix n = 200; A = rand(n,n); A = triu(A,1); A = A + A'; %generating a random graph based on the matrix G = @(p) A < p; thres_conn = log(n)/n; thres_big = 1/(n-1); t1 = linspace(0, thres_big, 50); t2 = linspace(thres_big, thres_conn, 100); %link probbailities t = [t1 ones(1,40)*thres_big t2]; pspec1 = []; pspec2 = []; f = 1; %change simulation speed using this parameter delay = 0.5; %determines the delay values , the simulation is slower at the beginning , %and gets faster at the end. speech changes are based on this vector pl = delay .* linspace(1, .15, 25); %drawing the graph layout to be used during simulation steps. [x y] = draw_dot(G(sqrt(thres_conn*thres_big))); for (tt = t) subplot(4,2,[1 2 3 4 5 6]); gplot(G(tt), [x' y'], 'b.-'); hold on; % [Glc p] = largest_component(G(tt)); , replaced by the following % find connected components of graph G [p Glc] = components(G(tt)); gplot(Glc, [x(p)' y(p)'], 'r'); hold off; title(sprintf('p = %d', tt)); subplot(4,2,[7 8]); % finding the largest connected component C = components(G(tt)); R = sparse(1:n, C, 1, n, max(C)); numC = max(C); comp_sizes = sum(R); pspec2 = [pspec2 comp_sizes]; pspec1 = [pspec1 ones(1,numC)*tt]; plot(pspec1, pspec2, '.'); title('size of components'); xlabel('p'); if (f > length(pl)) pause(0.15 * delay); else pause(pl(f)); end; f = f+1; end;