
function [Adj, Sdj, IAdj, PiB ] = NetEvol(Adj)

global alpha N

Index  = 1:N;                  % index
IAdj   = adj2inc(Adj);         % Incidence matrix
Sdj    = sum(full(Adj));       % vertexes' degree

% Edge removing:

[rw, ~]               = size(IAdj);
Nrem                  = randperm(rw);
Erem                  = Index(IAdj(Nrem(1),:));
Adj(Erem(1),Erem(2))  = 0;
Adj(Erem(2),Erem(1))  = 0;


% Edge adding:

% Preferential attachment:
PiB = (Sdj+alpha)./sum(Sdj+alpha);     % probability of attachment
Nadd = randsample(N,2,true,PiB);       % select two nodes
Ind1  = Nadd(1);  Ind2  = Nadd(2);
% avoid that the choosen first index has maximum degree
while ((Sdj(Ind1)) == N-1)
     Nadd = randsample(N,N,true,PiB);
     Ind1  = Nadd(1);
end
% avoid loops and overwriting of connections
while (Ind1 == Ind2 || Adj(Ind1,Ind2))    
        Nadd = randsample(N,1,true,PiB);
        Ind2 = Nadd(1);
end

Adj(Ind1,Ind2) = 1; 
Adj(Ind2,Ind1) = 1;

end

