///////////////////////////////////////////////////////////////////////////////////////// // Source code for generating complex via Evolutionary Preferential Attachment // ///////////////////////////////////////////////////////////////////////////////////////// # include # include # include # define N 4000 // Number of nodes of the network # define m_o 2 // Number of nodes contained in the initial (fully-connected) core # define m 2 // Number of links launched by each node (m<=m_o) # define K_MAX 4000 //Overstimated number of the maximum degree a node can reach /////////////////////////////////////////////////////////// // Variables for Random numbers generation: // #define FNORM (2.3283063671E-10F) #define RANDOM ((ira[ip++]=ira[ip1++]+ira[ip2++])^ira[ip3++]) #define FRANDOM (FNORM*RANDOM) unsigned char ip,ip1,ip2,ip3; unsigned ira[256]; double r,v; // /////////////////////////////////////////////////////////// // Some auxiliary variables and counters: int II,i,j,jj,g,gg,y,q,steps,t,w,counter; /////////////////////////////////////////////////////////// // Variables for Network topology: // int k[N]; //Degree of nodes int C[N][K_MAX]; //For each node, it stores the nodes it is attached to int unido[m]; //List of nodes attached to by the last node incorporated double P[N], P_prov[N]; //Probabilities of attachment double norma,norma2; //Norms for the probabilities of attachment int s; //Intant size of the network double fit[N]; //Fitness of nodes (entering in the attachment probability) double eps; //Weight of the node's fitness into the attachment probability (i.e. the degree of selection). // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// //Variables for Evolutionary Dynamics: // double b,R,Pu,Su; //Variables of the Dilemma: b (Temptation), R (Reward), Pu (Punishment), Su (Suckers payoff) int e[N]; //State (strategy) of each node (we use "0" for cooperators and "1" for defectors) int e_a[N]; //Same as e[N], used for updating the strategy in parallel int k_m; //It will allocate the maximum degree of the neighbors of a node double ben[N]; //Payoff of the nodes after playing a round robin double p; //It will allocate the probability that a node changes it strategy double ro; // Probability that a new node plays as cooperator in its first game int n_coop; //Number of cooperators in the network // /////////////////////////////////////////////////////////// int tauT; //Number of consecutives node aditions int tauD; //Number of consecutives game round robins void inicia_rand(int semilla); void nucleo_inicial(); void jugada(); void nuevo_nodo(); char file[256]; FILE *fich; int main() { ////////////////////////// // SET PARAMETERS: eps=0.99; tauT=10; tauD=1; ro=0.5; b=1.5; R=1.; Pu=0.; Su=0.; // ////////////////////////// //OUTPUT FILE: sprintf(file,"%d-Net-%i-%i-%.2lf-%.2lf.dat",N,tauT,tauD,b,eps); fich=fopen(file,"w"); ////////////////////////// // INITIALIZE VARIABLES: steps=N-m_o; //Number of nodes that will be added to the network initial core s=m_o; //Initial size of the network n_coop= 0; for(i=0;ii) { if(e[i]==0 && e[y]==0) //TWO COOPERATORS { ben[i]+=R; ben[y]+=R; } if(e[i]==0 && e[y]==1) //COOPERATOR AND DEFECTOR { ben[i]+=Su; ben[y]+=b; } if(e[i]==1 && e[y]==1) //TWO DEFECTORS { ben[i]+=Pu; ben[y]+=Pu; } if(e[i]==1 && e[y]==0) //DEFECTOR AND COOPERATOR { ben[i]+=b; ben[y]+=Su; } } } } //END OF ROUND ROBIN for(i=0;ik[t]) {k_m=k[i];} else {k_m=k[t];} //IF THE PAYOFF OF t IS LARGER THAN THAT OF i, i MAY CHANGE ITS STRATEGY if(ben[i]