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

📄 modelswarm.m

📁 仿真人工金融市场Jackson代码
💻 M
字号:
#import "ModelSwarm.h"// Model Swarm for Monopoly application@implementation ModelSwarm// createBegin: here we set up the default simulation parameters.+createBegin: (id) aZone {  ModelSwarm * obj;//  ProbeMap * probeMap; id <ProbeMap> probeMap;  // First, call our superclass createBegin   obj = [super createBegin: aZone];  obj->a=100;  //funzione inversa di domanda del mk (coeff rel. consum)  obj->b=1;   //   stesso p = a -bY  obj->c0=50;  // costo fisso relativo funz. produzione del monopolista  obj->c1=1; // costo variabile  obj->choice_d = strdup("Constant");  obj->d=5;  //investimento in reputazione del monopolista (>=0)  obj->choice_f = strdup("Constant");  obj->f=0.3333; // percentuale di produzione del falsificatore (0=<f<=1)  obj->choice_k = strdup("Constant");  obj->k=50; // risposta percentuale del consumatore all'investimento in 	    //reputazione  obj->random_seed=222;  obj->random_distrib = strdup("Uniform"); //shock relativo ad f  obj->max_mean= 0.01;  //massimo_uniforme Media_Normale  obj->min_variance = -0.01; //minimo_uni  Var_normale      // Now fill in various simulation parameters with default values.  probeMap = [EmptyProbeMap createBegin: aZone];  [probeMap setProbedClass: [self class]];  probeMap = [probeMap createEnd];  // Add in a bunch of variables, one per simulation parameter  [probeMap addProbe: [probeLibrary getProbeForVariable: "a"				    inClass: [self class]]];  [probeMap addProbe: [probeLibrary getProbeForVariable: "b"				    inClass: [self class]]];  [probeMap addProbe: [probeLibrary getProbeForVariable: "c0"				    inClass: [self class]]];  [probeMap addProbe: [probeLibrary getProbeForVariable: "c1"				    inClass: [self class]]];  [probeMap addProbe: [probeLibrary getProbeForVariable: "choice_d"				    inClass: [self class]]];  [probeMap addProbe: [probeLibrary getProbeForVariable: "d"				    inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForVariable: "choice_f"				    inClass: [self class]]];  [probeMap addProbe: [probeLibrary getProbeForVariable: "f"				    inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForVariable: "choice_k"				    inClass: [self class]]];  [probeMap addProbe: [probeLibrary getProbeForVariable: "k"				    inClass: [self class]]];  [probeMap addProbe: [probeLibrary getProbeForVariable: "random_seed"				    inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForVariable: "random_distrib"                                    inClass: [self class]]];  [probeMap addProbe: [probeLibrary getProbeForVariable: "max_mean"				    inClass: [self class]]];  [probeMap addProbe: [probeLibrary getProbeForVariable: "min_variance"				    inClass: [self class]]];  // Now install our custom probeMap into the probeLibrary.  [probeLibrary setProbeMap: probeMap For: [self class]];  return obj;}-createEnd {  return [super createEnd];}-saveParameters {    [ObjectSaver save: self toFileNamed: "model.setup"];  return self;}  -loadParameters {  [ObjectLoader load: self fromFileNamed: "model.setup"];  return self;}-buildObjects: (ObserverSwarm *) oS {  observerSwarm=oS;    tempo = 0;    [self buildRandomDistributions];  [self buildAgents];  [self write_parameters];  return self;}-getCFactor {return cfactor;}-buildRandomDistributions {  aGenerator=[PMMLCG1gen create: [self getZone] setStateFromSeed:random_seed];  uniformDouble=[UniformDoubleDist create: [self getZone] setGenerator: aGenerator];  uniformInteger=[UniformIntegerDist create: [self getZone] setGenerator: aGenerator];  return self;} -buildAgents {    // Create Firm object  firm=[Firm create: globalZone];  [firm setAlpha: a];  [firm setBeta: b];  [firm setInitialConditions];     [firm setModel: self];  [firm setValC: c0];  [firm setValC1: c1];  [firm setValD: d];   firm=[firm createEnd];  //create CounterFactor object	cfactor = [CFactor create: globalZone];	[cfactor setInitialConditions];    	[cfactor setModel: self];	[cfactor setF: f]; if (random_distrib[0] == 'N' || random_distrib [0]=='n')  {         [cfactor  setType:1];	[cfactor setMedia: max_mean andVarianza: min_variance];     } else {        [cfactor setType:0];   	 [cfactor setMin: min_variance andMax: max_mean];}	cfactor = [cfactor createEnd];  // Create Market object which  // represents the demand function  market=[Market create: globalZone];  [market copyModel: self];  [market setAlpha: a];  [market setBeta: b];  [market setD: d];  [market setC1: c1];  [market setKperc: k];  market = [market createEnd];        return self;}-buildActions {  [super buildActions];    modelActions = [ActionGroup create: [self getZone]];  [modelActions createActionTo: firm message: M(step)];  [modelActions createActionTo:cfactor  message: M(step)];  [modelActions createActionTo:market  message: M(step)];  [modelActions createActionTo:cfactor  message: M(shock_f)];  [modelActions createActionTo:market  message: M(updateK)];  [modelActions createActionTo:cfactor  message: M(updateCF)];  [modelActions createActionTo:self  message: M(incTime)];     modelSchedule = [Schedule createBegin: [self getZone]];  [modelSchedule setRepeatInterval: 1];  modelSchedule = [modelSchedule createEnd];  [modelSchedule at: 0 createAction: modelActions];    return self;}-activateIn: (id) swarmContext {  [super activateIn: swarmContext];  // Now activate our own schedule.  [modelSchedule activateIn: self];    // Finally, return our activity.  return [self getSwarmActivity];}-(double)getDblWithMin: (double) min withMax: (double) max {	  return [uniformDouble getDoubleWithMin: min withMax: max];}-(int)getIntWithMin: (int) min withMax: (int) max {  int num;  if(min==max)     num=min;  else     num=[uniformInteger getIntegerWithMin: min withMax: max];    return num;}-getFirm {  return firm;}-getMarket {return market;}-(int) getTime {return tempo;}-(double)getAlpha {return a;}  -(double)getBeta {return b;}-incTime {tempo+=1;return self;}-(double)getVal1 {return [uniformInteger getIntegerWithMin: 1 withMax: 100];}-(double)getVal2 {return [uniformInteger getIntegerWithMin: 1 withMax: 10];}-changeIteration {printf ("----------------------\n");return self;}-(int)getChoiceD {if ((choice_d[0] == 'C') || (choice_d[0]=='c')) {return 0; }else return 1;}-(double) getCFactorF {return f;}-(double) getMarketD {return d ;}-(int)getChoiceF {if ((choice_f[0] == 'C') || (choice_f[0]=='c')) {return 0; }else return 1;}-(int)getChoiceK {if ((choice_k[0] == 'C') || (choice_k[0]=='c')) {return 0; }else return 1;}-write_parameters {printf ("Here it is the parameters of the simulation\n");printf ("---------\n");printf ("a ---> %f\n", a);printf ("b ---> %f\n", b);printf ("c ---> %f\n", c0);printf ("c1 ---> %f\n", c1);if ([self getChoiceD]== 0) 	printf ("d ---> %f\n", d);      else printf ("You choose the D parameters variable\n");if ([self getChoiceF]== 0)     printf ("f ---> %f\n", f);      else printf ("You choose the f parameters variable\n");if ([self getChoiceK]== 0)  printf ("k ---> %f\n", k);   else printf ("You choose the k parameters variable\n"); if (random_distrib[0] == 'N' || random_distrib [0] =='n') {printf ("You choose Normal Random Distribution with mean %f and variance  %f\n",max_mean, min_variance);} else printf ("You choose Uniform Random Distribution with max %f and minimo%f\n",max_mean, min_variance);printf ("---------\n");return self;}@end

⌨️ 快捷键说明

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