⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 firm.m

📁 仿真人工金融市场Jackson代码
💻 M
字号:
// Firm.m			Coevolution#import "Firm.h"#import "ModelSwarm.h"#import "WorkerSpace.h"#import <simtools.h>#import <collections.h>#import <space.h>#import <random.h>@implementation Firmint expect[4] = {-1, 1 , 1, -1};-createEnd {worldXSize = [modelswarm getWorldSizeX];worldYSize = [modelswarm getWorldSizeY];   return self;}-setToPrint: (int) ok1 { ok = ok1; if (ok==1) {   // printf ("oggetto da monitorare \n"); } return self;}-setWorkers {int cx,cy;int suc;for (suc = 0; suc<size; suc++) {cx = [uniformIntRand getIntegerWithMin: (int) 0 withMax: (int) (worldXSize-1)];cy = [uniformIntRand getIntegerWithMin: (int) 0 withMax: (int) (worldYSize-1)];   if ([[[modelswarm getWorld] getObjectAtX: cx Y: cy] getWorkerStatus] ==0) {[[[modelswarm getWorld] getObjectAtX: cx Y: cy] setStatus: 1];[[[modelswarm getWorld] getObjectAtX: cx Y: cy] setBossX: xPos Y: yPos];workerAddresses[suc][0] = cx;workerAddresses[suc][1] = cy;    		} // status == 0  else      {  suc-=1;     } // else  }// forif (ok==1)  { for (suc = 0; suc<size; suc++)   {     cx = workerAddresses[suc][1];     cy = workerAddresses[suc][0];//printf ("worker %d coordinate x %d y %d and status %d\n", suc,cx,cy,[[[modelswarm getWorld] getObjectAtX: cx Y: cy]getWorkerStatus]);    }  }return self;}-setSize: (int) tmp {//int tmp;// tmp=[uniformIntRand getIntegerWithMin: (int) 2 withMax: (int) 6]; size = tmp;return self;}-(int)getSize {return size;}-setX: (int) x Y: (int) y {  xPos = x;  yPos = y;  return self;}-(int) getX {return xPos;}-(int)getY {return yPos;}-checkEfficiency {int tim;int  i,j;int total = 0;int contatore = 0;tim = [modelswarm getTime];if (((tim % month)==0) && (status !=1)) {  for (i=0;i<4; i++) {    total = 0;   for (j=0;j<size; j++) {   total+=  [[world getObjectAtX:workerAddresses[j][0] Y:workerAddresses[j][1]]  reactTo: i]*weights[j];   }  total+=1 * weights[size]; if ((total * expect[i]) <= 0) {            i=5;for (j=0;j<size; j++)    [[world getObjectAtX: workerAddresses[j][0] Y:workerAddresses[j][1]]  	setStatus: 0];           } else  {    // tot*exp >0 	contatore+=1;		                }   if (contatore == 4) {     printf ("coordinate x %d  y %d\n", xPos, yPos);	  for (j=0;j<size; j++) {  [[world getObjectAtX:workerAddresses[j][0] Y:workerAddresses[j][1]] setStatus: 2];status = 1; // cambia il suo stato in efficienteprintf ("efficent in x %d e y %d\n", workerAddresses[j][0],workerAddresses[j][1]);	} // if contatore ==4}//if =4  } } // if tim ...return self;}-updateWeightsWithStim: (int) st andExp:(int) ex {int i;for (i=0; i<size; i++) {  weights[i]+=[[world getObjectAtX:workerAddresses[i][0]Y:workerAddresses[i][1]]  reactTo: st] * ex;	}  weights[size] +=ex;return self;}-coordinateStimulus: (int) stim withExp: (int) exp{int i;int reply[6] = {0,0,0,0,0,0};int sum=0;for (i=0; i<size; i++) {reply[i] =  [[world getObjectAtX:workerAddresses[i][0]Y:workerAddresses[i][1]]  reactTo: (int)stim];	sum+=reply[i];     }sum+=weights[size]; if ((sum*exp)<=0) {  [self updateWeightsWithStim: stim andExp: exp ]; 	}   else { [[world getObjectAtX:workerAddresses[i][0]  Y:workerAddresses[i][1]]   incrSuccesses: 1/size  ];	}return self;}-setWeights {int i;for (i=0; i<=size; i++) {weights[i] = [uniformIntRand getIntegerWithMin: (int) -5 withMax: (int)  5]; 	}return self;}-setMonth: (int) mo {month = mo;return self;}-setFirmStatus: (int) t0Status {status = t0Status;return self;}-(int)getFirmStatus {return status;  }-setModel: (id) mo withWorld: (id) w {world=w; //grid2d lavoratoremodelswarm = mo;status = 0;return self;}-step {return self;}@end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -