modelswarm.m
来自「仿真人工金融市场Jackson代码」· M 代码 · 共 631 行 · 第 1/2 页
M
631 行
} printf ("The Coevolution of Human Capital and Firm Structures \n"); //printf ("ora inizializzo il file \n"); // output = [Output create: [self getZone]]; // [output setModel: self]; // [output prepareFirmOutputFile]; // [output prepareHCOutputFile]; //printf ("inizializzato il file \n"); return self;}-buildActions { // Create the list of simulation actions. We put these in an action // group, because we want these actions to be executed in a specific // order, but these steps should take no (simulated) time. The // M(foo) means "The message called <foo>". You can send a message // To a particular object, or ForEach object in a collection. modelActions = [ActionGroup create: [self getZone]]; [modelActions createActionTo: self message: M(setStim)]; if (differenciated == 0) { [modelActions createActionForEach: workerList message: M(step)]; } else { [modelActions createActionForEach: workerList message: M(step1)]; } [modelActions createActionForEach: firmList message: M(checkEfficiency)]; [modelActions createActionForEach: workerList message: M(checkSuccesses)]; if (updHC==1) { [modelActions createActionForEach: workerList message:M(updateHumanCapital)]; } [modelActions createActionTo: self message: M(checkList)]; [modelActions createActionTo: self message: M(createNewFirm)]; [modelActions createActionTo: self message: M(incTime)]; // [modelActions createActionForEach: firmList message: M(step)]; [modelActions createActionTo: self message: M(chec)]; // [modelActions createActionTo: output message: M(writeDatas)]; [modelActions createActionTo: self message: M(setValuesToPlot)]; // [modelActions createActionTo: self message: M(check_FirmData)]; // Then we create a schedule that executes the modelActions. modelActions // is an ActionGroup, by itself it has no notion of time. In order to // have it executed in time, we create a Schedule that says to use // the modelActions ActionGroup at particular times. // This schedule has a repeat interval of 1, it will loop every time step. // The action is executed at time 0 relative to the beginning of the loop. // This is a simple schedule, with only one action that is just // repeated every time. See mousetraps for more complicated schedules. modelSchedule = [Schedule createBegin: [self getZone]]; [modelSchedule setRepeatInterval: 1]; modelSchedule = [modelSchedule createEnd]; [modelSchedule at: 0 createAction: modelActions]; return self;}-activateIn: (id) swarmContext { // Here, we activate the swarm in the context passed in // Then we activate our schedule in ourselves [super activateIn: swarmContext]; [modelSchedule activateIn: self]; return [self getSwarmActivity];}-setStim { stim = 0; stim=[uniformIntRand getIntegerWithMin: (int) 0 withMax: (int) 3]; //printf ("stimolo = %d\n", stim); return self;}-(int) getStimulus { return stim;}-(int)getTime { return time;}-incTime { //printf ("inctime \n"); time+=1; return self;}-chec { int tmp; if (time%daysInMonth ==0) { //pj: tmp = [firmList count]; //pj: tmp = [firmList getCount]; //printf (" numero elementi lista %d e tempo %d\n", tmp, time); } return self;}-(int) getWorldSizeX { return worldXSize ;}-(int) getWorldSizeY { return worldYSize;}-(int) getDaysInMonth { return daysInMonth;}-(int) getNumFirms { return numFirms; }-replaceList: (id) newMyList { firmList = newMyList; return self;}-prova { id index, agent; id newagent, newindex; id tempList; //pj: id rmList; //pj: int i=0; //pj: int contatore =0; // printf ("numero elementi nella lista prima --> %d\n", [firmList count]); index = [firmList begin: [self getZone]] ; tempList = [List create: [self getZone]]; while ((agent = [index next])){ if ([agent getFirmStatus] == 1 ){ // se e' efficente efficente [tempList addLast: agent]; } else { //metodo per la cancellatura degli agenti [firmWorld putObject: nil atX: [agent getX] Y: [agent getY]]; [firmSpace putValue: 0 atX: [agent getX] Y: [agent getY]]; } } //ciclo while [firmList removeAll]; // rimuovo ogni membro dalla lista newindex = [tempList begin: [self getZone]] ; while ((newagent = [newindex next])){ [firmList addLast: newagent]; } //printf ("numero elementi nella lista DOPO --> %d\n", [firmList count]); return self;}-checkList { if (time%daysInMonth ==0) [self prova]; return self;}// metodo che mi crea le Firm-createNewFirm { //pj: int exist = 0; int creo = 0; int tmp = 0; int i, coordX,coordY; int resto; int realFirms = 0; if (time%daysInMonth ==0) { //pj:creo = [firmList count]; //pj: creo = [firmList getCount]; //printf ("numero imprese prima %d \n", creo); if ((worldXSize*worldYSize) > creo ) { //if1 resto = ((worldXSize*worldYSize) - creo); if (resto > numFirms){ realFirms = numFirms; } else { realFirms = resto;} //printf ("ne creo %d \n", realFirms); for (i=0; i< realFirms; i++) { tmp = 0; while ((tmp!=1)) { coordX=[uniformIntRand getIntegerWithMin: (int)0 withMax:(int)(worldXSize-1)]; coordY=[uniformIntRand getIntegerWithMin: (int)0 withMax:(int)(worldYSize-1)]; if ([firmWorld getObjectAtX: coordX Y: coordY] == nil) { [self createOneFirmAtX: coordX Y: coordY withStat: 0]; tmp = 1; //printf ("create \n"); } //if }// while } //for }//if1 } // if (time%daysInMonth ==0) return self;}-(int)getFirmData: (int) type_Firm { return FirmStData[type_Firm];;}-check_FirmData { int i; printf ("imprese \n"); for (i=0;i<5;i++) printf ("%d ", [self getFirmData:i]); printf ("\n"); printf ("Worker Data \n"); for (i=0;i<3;i++) printf ("%d ", [self getWorkerData:i]); printf ("\n"); printf ("Capital Umano \n"); for (i=0;i<5;i++) printf ("%d ", [self getHCData:i]); printf ("\n"); return self;}-(int)getWorkerData: (int) type_Worker { return WorkStData[type_Worker];}-setValuesToPlot { int x,y; int myHC=0; int myStatus=0; int myFirmSize=0; int i; id tempobj, tempobj1; for (i=0;i<7;i++) HCData[i]=0; for (i=0;i<5;i++) FirmStData[i]=0; for (i=0;i<3;i++) WorkStData[i]=0; for (x=0;x<worldXSize; x++) for (y=0;y<worldYSize; y++) { //ciclo for //pj: tempobj = [world getObjectAtX: x Y: y]; //pj: previous returned nil if ( ( tempobj = [world getObjectAtX: x Y: y]) != nil ) { myStatus = [tempobj getWorkerStatus]; if (myStatus<2) { //if WorkStData[myStatus]+=1; } else { WorkStData[myStatus]+=1; myHC = [tempobj getHumanCapital]; HCData[myHC]+=1; } } } for (x=0;x<worldXSize; x++) for (y=0;y<worldYSize; y++) { // ciclo for //pj:tempobj1= [firmWorld getObjectAtX: x Y: y]; //pj: it was returning a nil if((tempobj1 = [firmWorld getObjectAtX: x Y: y]) != nil ) { if ([tempobj1 getFirmStatus] ==1) { //if status=1 significa efficente myFirmSize = 0; // printf ("old size %d --->", myFirmSize); myFirmSize = [tempobj1 getSize]; // printf ("new size %d \n ", myFirmSize); FirmStData[myFirmSize-2]+=1; //printf (" %d valore %d con indice0 %d \n", myFirmSize-2,FirmStData[myFirmSize-2], FirmStData[0]); // printf (" status %d size %d %d \n", [tempobj1 getFirmStatus],myFirmSize, myFirmSize-2); // printf ("Valroe 0 %d \n", FirmStData[0]); }//IF } }//CICLO FOR return self;}-(int)getHCData: (int)type_HC { return HCData[type_HC];}@end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?