EQUATION("Status") /* Determine the status of this agent */ v[0]=VS(p->up, "ProbAction"); if(RND>v[0]) v[1]=VL("Status",1); //don’t change else {//do change, if you want v[2]=VL("NRich",1); v[3]=VL("NRich0",1); v[4]=VL("NRich1",1); v[5]=VL("NPoor",1); v[6]=VL("NPoor0",1); v[7]=VL("NPoor1",1); //collect data v[10]=V("Type"); //type of the agent if(v[10]==0) {//type RICH v[8]=(v[3]-v[4])/v[2]; //share of rich having 0 v[9]=(v[6]-v[7])/v[5]; //share of poor having 0 } else {//type POOR v[8]=v[3]; //number of rich having 0 v[9]=v[4]; //number of rich having 1 } if(v[8]>v[9]) v[1]=0; else v[1]=1; if(v[8]==v[9]) //in a tie, choose randomly { if(RND<0.5) v[1]=0; else v[1]=1; } } RESULT( v[1] ) EQUATION("NRich") /* Number of rich people */ v[0]=0; CYCLE(cur, "Agent") { v[2]=VS(cur,"Type"); v[3]=VS(cur,"Status"); if(v[2]==0) //if it is a rich agent v[0]++; } RESULT( v[0] ) EQUATION("NRich0") /* Number of rich people with status 0 */ v[0]=0; CYCLE(cur, "Agent") { v[2]=VS(cur,"Type"); v[3]=VS(cur,"Status"); if(v[2]==0 && v[3]==0) //if it is a rich agent and the status is 0 v[0]++; } RESULT( v[0] ) EQUATION("NRich1") /* Number of rich people with status 1 */ v[0]=0; CYCLE(cur, "Agent") { v[2]=VS(cur,"Type"); v[3]=VS(cur,"Status"); if(v[2]==0 && v[3]==1) //if it is a rich agent and the status is 1 v[0]++; } RESULT( v[0] ) EQUATION("NPoor") /* Number of poor people */ v[0]=0; CYCLE(cur, "Agent") { v[2]=VS(cur,"Type"); v[3]=VS(cur,"Status"); if(v[2]==1) //if it is a poor agent v[0]++; } RESULT( v[0] ) EQUATION("NPoor0") /* Number of poor people with status 0 */ v[0]=0; CYCLE(cur, "Agent") { v[2]=VS(cur,"Type"); v[3]=VS(cur,"Status"); if(v[2]==1 && v[3]==0) //if it is a poor agent and the status is 0 v[0]++; } RESULT( v[0] ) EQUATION("NPoor1") /* Number of poor people with status 1 */ v[0]=0; CYCLE(cur, "Agent") { v[2]=VS(cur,"Type"); v[3]=VS(cur,"Status"); if(v[2]==1 && v[3]==1) //if it is a poor agent and the status is 1 v[0]++; } RESULT( v[0] ) EQUATION("Share0") /* Share of agents with status 0 */ v[0]=V("NRich0"); v[1]=V("NRich"); v[3]=V("NPoor0"); v[4]=V("NPoor"); RESULT((v[0]+v[3])/(v[1]+v[4]) ) EQUATION("Share1") /* Share of agents with status 1 */ v[0]=V("NRich1"); v[1]=V("NRich"); v[3]=V("NPoor1"); v[4]=V("NPoor"); RESULT((v[0]+v[3])/(v[1]+v[4]) )