Appendix 1 - Java Code for Individual based model
INDIVIDUALS
abstract class IndividuC{
static int nIndiv=0;
// general characteristics
int id; // identifier of the individual
PopulationIndividuCentree Pop; // population to which it belongs
float consoBase[] = new float[12]; // monthly basic consumption
Vector voisins=new Vector(); // relationships/neighbourhood (other individuals)
// parameters for the dynamics
float gA; // parameters of social influence
float gB;
float gE; // weight of environmental term in the decision
int eA;
int eB;
float beta;
// state variable
int comportementEff ; // behaviour followed by the individual
// CONSTRUCTOR
IndividuC(PopulationIndividuCentree PAI, int cpt, GainSocial gs,
float gEE, float seuil,
float[] consoB, float b){
Pop=PAI;
comportementEff=cpt; // initial behaviour
gA=gs.gAA;
gB=gs.gBB;
gE=gEE;
consoBase = consoB;
id = nIndiv++;
beta=b;
}
// OPERATIONS ON THE NEIGHBOURHOOD
// ---- test on the belonging of an individual to the neighbourhood
boolean monVoisin(IndividuC indv){
for (int i=0;i probaB){
result=0; // 0 stands for A
}
return (comportementEff = result);
}
//*** STEP
void step(){
int nvA=nVoisinsA();
int nvB=voisins.size()-nvA;
comportementEff=choixCptPert(nvA,nvB);
}
A SPECIFIC KIND OF INDIVIDUAL
class Citadin extends IndividuC{}
POPULATION
class PopulationIndividuCentree{
static int nPopAI=0;
static int nStep=0;
int id;
IndividuC [] cit;
int citadins; // = cit.length
int nA; // number of individual following the A behaviour
int nVoisins ; // average number of links for an individual
GainSocial gsC;
float gEC;
float sEC;
float beta;
int nIndDt; // number of individuals to evolve at each time step
// CONSTRUCTOR
PopulationIndividuCentree(int n, float nAC, int nVC, GainSocial gsCC , float gECC,float sECC,float nI, float b, Time ti, float prelFixe, float multCC){
id = nPopAI++;
citadins=n;
nA=(int)((float)citadins*nAC);
gsC=gsCC; gEC=gECC;
sEC=sECC;
beta=b;
nIndDt=(int)(nI*n);
nVoisins=nVC;
generationPopAlea(nVC);
}
// GENERATION OF INDIVIDUALS AND LINKS
// ---- Generation of the population
void generationPopAlea(){
generationIndivAlea();
generationLiensIntra(nVC,cit);
}
// ---- Generating the individuals
private void generationIndivAlea(){
int nARest=nA;
int nBRest=nB;
int rand;
int cpt;
cit=new IndividuC[citadins];
int i;
float[] conso = lectureConsos("consoCit");
for (i=0;i0){
alea1=(int)(Math.random()*(double) taille);
alea2=(int)(Math.random()*(double) taille);
if (alea1 != alea2 && !(pop[alea2].monVoisin(pop[alea1]))) {
// a new link is established if it doesn't already exist
pop[alea1].ajouterVoisin(pop[alea2]);
pop[alea2].ajouterVoisin(pop[alea1]);
// one link less to find
nLienR--;
}
}
}
// STEP
boolean [] evolC = null; // array recording the individuals having yet evolved in the current time step
void step(){
if (evolC == null) evolC = new boolean[citadins];
java.util.Arrays.fill(evolC, false);
int nCitE= nIndDt;// number of individuals to evolve in the time step
int ev=0; // number of individuals having yet evolved in the time step
int rgAlea; // index in the array "cit" of the individual to evolve
int i;
int opAv;
int opAp;
Random r=new Random(nStep*15);
ev=0;
while (ev < ncite){
rgalea=(int)(r.nextDouble()*(double) cit.length);
if (!evolc[rgalea]) {
evolc[rgalea] = true;
cit[rgAlea].step();
ev++;
}
}
nStep++;
}