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

📄 observerswarm.m

📁 仿真人工金融市场Jackson代码
💻 M
字号:
#import "ObserverSwarm.h"#import <analysis.h>#import <analysis/ActiveGraph.h> @implementation ObserverSwarm// createBegin: here we set up the default observation parameters.+createBegin: (id) aZone {  ObserverSwarm * obj; id <ProbeMap> probeMap;      // Superclass createBegin to allocate ourselves.  obj = [super createBegin: aZone];  // Fill in the relevant parameters (only one, in this case).  obj->displayFrequency = 1;  // Also, build a customized probe map. Without a probe map, the default  // is to show all variables and messages. Here we choose to  // customize the appearance of the probe, give a nicer interface.  probeMap = [EmptyProbeMap createBegin: aZone];  [probeMap setProbedClass: [self class]];  probeMap = [probeMap createEnd];  // Add in a bunch of variables, one per simulation parameters  [probeMap addProbe: [probeLibrary getProbeForVariable: "displayFrequency"				    inClass: [self class]]];   [probeLibrary setProbeMap: probeMap For: [self class]];  return obj;}-createEnd {  return [super createEnd];}-buildObjects {  id modelZone;  [super buildObjects];  modelZone = [Zone create: [self getZone]];  modelSwarm = [ModelSwarm create: modelZone];    [probeDisplayManager createProbeDisplayFor: modelSwarm];  [probeDisplayManager createProbeDisplayFor: self];  [controlPanel setStateStopped]; //pj:   [controlPanel waitForControlEvent];//    // Check now if the user hit the quit button: if so, abort.//    if ([controlPanel getState] == ControlStateQuit)//      return self;  [modelSwarm buildObjects: self];  [self buildGraphs];    return self;}-buildGraphs {  theGraph = [EZGraph create: self setTitle: "Quantity vs. Time" setAxisLabelsX: "Time" Y: "Quantity" setWindowGeometryRecordName: "theGraph" ];  [theGraph createSequence: "SMQ"            withFeedFrom: [modelSwarm getFirm]            andSelector: M(getMyQuantity)];  [theGraph createSequence: "MQ"	    withFeedFrom: [modelSwarm getFirm]	    andSelector: M(getMonop)];  [theGraph createSequence: "CQ"	    withFeedFrom: [modelSwarm getCFactor]	    andSelector: M(getCFQ)];// Now we draw the price graph vs time  theGraphPrice = [EZGraph create: self setTitle: "Prices vs. Time" setAxisLabelsX: "Time" Y: "Prices" setWindowGeometryRecordName: "theGraphPrice"];  [theGraphPrice createSequence: "SMP"	    withFeedFrom: [modelSwarm getFirm] 	    andSelector: M(getMyPrice)];  [theGraphPrice createSequence: "MP"	    withFeedFrom: [modelSwarm getMarket] 	    andSelector: M(getEquilibriumPrice)];  // graphXY    // create graph for price of commodity  priceGraph = [Graph createBegin: globalZone];  SET_WINDOW_GEOMETRY_RECORD_NAME (priceGraph);  priceGraph = [priceGraph createEnd];  [priceGraph setTitle: "Quantity(t-1) vs. Quantity(t)"];  [priceGraph setAxisLabelsX: "y(t-1)" Y: "y(t)"];  [priceGraph setWidth: 400 Height: 250]; [priceGraph pack];  [priceGraph setScaleModeX: 1 Y: 0];  priceElement = [priceGraph createElement];  [priceElement setLabel: "MQ"];  [priceElement  setColor: "blue"];   [priceElement  setWidth: 1];  priceElement_1 = [priceGraph createElement];  [priceElement_1 setLabel: "CQ"];  [priceElement_1  setColor: "black"] ;  [priceElement_1 setWidth: 1];// piano delle fasi del prezzo di equilibrio  priceGraph1 = [Graph createBegin: globalZone];  SET_WINDOW_GEOMETRY_RECORD_NAME (priceGraph1);  priceGraph1 = [priceGraph1 createEnd];  [priceGraph1 setTitle: "Price(t-1) vs. Price(t)"];  [priceGraph1 setAxisLabelsX: "p(t-1)" Y: "p(t)"];  [priceGraph1 setWidth: 400 Height: 250]; [priceGraph1 pack];  [priceGraph1 setScaleModeX: 1 Y: 0];  priceElement1 = [priceGraph1 createElement];  [priceElement1 setLabel: "P"];  [priceElement1 setColor: "black"] ;  [priceElement1 setWidth: 1];    return self;  }  -buildActions {  [super buildActions];    [modelSwarm buildActions];  displayActions = [ActionGroup create: [self getZone]];  [self buildGraphActions];    [displayActions createActionTo: probeDisplayManager message: M(update)];  [displayActions createActionTo: actionCache   message:M(doTkEvents)];  displaySchedule = [Schedule createBegin: [self getZone]];  [displaySchedule setRepeatInterval: displayFrequency]; // note frequency!  displaySchedule = [displaySchedule createEnd];  [displaySchedule at: 0 createAction: displayActions];  return self;}-buildGraphActions {  [displayActions createActionTo: theGraph  message: M(step)];  [displayActions createActionTo: theGraphPrice  message: M(step)];  [displayActions createActionTo: self        message: M(step1)];  [displayActions createActionTo: self        message: M(step2)];  [displayActions createActionTo: self        message: M(step3)];   return self;} -step1 {id myFirm;id myCF;myFirm = [modelSwarm getFirm];myCF = [modelSwarm getCFactor];  [priceElement  addX: [myFirm getMonop]  Y: [myFirm getLastMonop]];  [priceElement_1  addX: [myCF getCFQ]  Y: [myCF getLastCF]];  return self;}-step3 {id myFirm;id myCF;myFirm = [modelSwarm getFirm];myCF = [modelSwarm getCFactor];//  [priceElement  addX: [myFirm getMonop]  Y: [myFirm getLastMonop]];  [priceElement_1  addX: [myCF getCFQ]  Y: [myCF getLastCF]];//printf ("now %f  last %f \n",  [myCF getCFQ], [myCF getLastCF]);  return self;}-step2 {id myMarket;myMarket = [modelSwarm getMarket];  [priceElement1  addX: [myMarket getEquilibriumPrice]  Y: [myMarketgetLastEquilibriumPrice]];  return self;}-activateIn: (id) swarmContext {  // First, activate ourselves (just pass along the context).  [super activateIn: swarmContext];  // Activate the model swarm in ourselves. The model swarm is a  // subswarm of the observer swarm.  [modelSwarm activateIn: self];  // Now activate our schedule in ourselves. This arranges for the  // execution of the schedule we built.  [displaySchedule activateIn: self];    // Activate returns the swarm activity - the thing that's ready to run.  return [self getSwarmActivity];}@end

⌨️ 快捷键说明

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