diff -cr ASM-20000602/ASMBatchSwarm.h ASM-20011125/ASMBatchSwarm.h *** ASM-20000602/ASMBatchSwarm.h Sun May 7 13:09:26 2000 --- ASM-20011125/ASMBatchSwarm.h Wed Oct 24 18:26:08 2001 *************** *** 14,19 **** --- 14,20 ---- id stopSchedule; ASMModelSwarm * asmModelSwarm; + id output; } *************** *** 21,28 **** - buildObjects; - buildActions; - activateIn: swarmContext; - go; - stopRunning; ! @end --- 22,31 ---- - buildObjects; - buildActions; - activateIn: swarmContext; + + - expostParamWrite; - go; - stopRunning; ! -(void) drop; @end diff -cr ASM-20000602/ASMBatchSwarm.m ASM-20011125/ASMBatchSwarm.m *** ASM-20000602/ASMBatchSwarm.m Mon Apr 24 20:25:06 2000 --- ASM-20011125/ASMBatchSwarm.m Wed Oct 24 18:26:08 2001 *************** *** 1,5 **** #import "ASMBatchSwarm.h" ! @implementation ASMBatchSwarm --- 1,5 ---- #import "ASMBatchSwarm.h" ! #import "Parameters.h" @implementation ASMBatchSwarm *************** *** 8,15 **** ASMBatchSwarm * obj; obj = [super createBegin: aZone]; ! obj->loggingFrequency = 1; ! obj->experimentDuration = 500; return obj; } --- 8,17 ---- ASMBatchSwarm * obj; obj = [super createBegin: aZone]; ! ! //overridden by settings from scm file ! // obj->loggingFrequency = 1; ! //obj->experimentDuration = 500; return obj; } *************** *** 18,38 **** -buildObjects { id modelZone; ! [super buildObjects]; modelZone = [Zone create: [self getZone]]; asmModelSwarm = [ASMModelSwarm create: modelZone]; ! ! [ObjectLoader load: self fromAppDataFileNamed: "batch.setup"]; ! [ObjectLoader load: asmModelSwarm fromAppDataFileNamed: "param.data"]; ! [asmModelSwarm initOutputForDataWrite]; [asmModelSwarm buildObjects]; - [asmModelSwarm initOutputForParamWrite]; output = [asmModelSwarm getOutput]; ! [output writeParams]; return self; } --- 20,45 ---- -buildObjects { id modelZone; ! BFParams * bfParams = [(id)arguments getBFParams]; ! ASMModelParams * asmModelParams = [(id)arguments getModelParams]; ! [super buildObjects]; modelZone = [Zone create: [self getZone]]; asmModelSwarm = [ASMModelSwarm create: modelZone]; ! ! [asmModelSwarm setParamsModel: asmModelParams BF: bfParams]; ! //ObjectLoader: is deprecated ! //: [ObjectLoader load: self fromAppDataFileNamed: "batch.setup"]; ! ! //pj: [ObjectLoader load: asmModelSwarm fromAppDataFileNamed: "param.data"]; ! [asmModelSwarm buildObjects]; output = [asmModelSwarm getOutput]; ! [output prepareOutputFile]; ! [output writeParams: asmModelParams BFAgent: bfParams Time: 0]; return self; } *************** *** 75,85 **** } -go { printf("\nYou typed 'asm -batchmode'. The simulation is running without graphics.\n\n"); ! printf("The Artificial Stock Market is running for %d time steps and writing ! its data.\n\n",experimentDuration); if(loggingFrequency) printf("It is logging data every %d timesteps to a time-dated output.data file.\n\n", loggingFrequency); --- 82,99 ---- } + + - expostParamWrite + { + [[asmModelSwarm getOutput] writeParams: [(id) arguments getModelParams] BFAgent: [(id) arguments getBFParams] Time: [asmModelSwarm getModelTime]]; + return self; + } + + -go { printf("\nYou typed 'asm -batchmode'. The simulation is running without graphics.\n\n"); ! printf("The Artificial Stock Market is running for %d time steps and writing its data.\n\n",experimentDuration); if(loggingFrequency) printf("It is logging data every %d timesteps to a time-dated output.data file.\n\n", loggingFrequency); *************** *** 93,98 **** --- 107,119 ---- { [getTopLevelActivity() terminate]; return self; + } + + + -(void) drop + { + [asmModelSwarm drop]; + [super drop]; } @end Only in ASM-20011125/: ASMModelParams.h Only in ASM-20011125/: ASMModelParams.m diff -cr ASM-20000602/ASMModelSwarm.h ASM-20011125/ASMModelSwarm.h *** ASM-20000602/ASMModelSwarm.h Fri Jun 2 11:03:37 2000 --- ASM-20011125/ASMModelSwarm.h Wed Oct 24 18:26:08 2001 *************** *** 4,51 **** #import "Dividend.h" #import "World.h" #import "Output.h" @interface ASMModelSwarm: Swarm { ! //Agent parameters ! int numBFagents; ! float initholding; ! double initialcash; ! double minholding; ! double mincash; ! double intrate; ! ! //Dividend parameters ! double baseline; //Also used by World. ! double mindividend; ! double maxdividend; ! double amplitude; ! int period; ! ! //Specialist parameters ! double maxprice; ! double minprice; ! double taup; ! BOOL exponentialMAs; //Also used by World. ! int sptype; ! int maxiterations; ! double minexcess; ! double eta; ! double etamax; ! double etamin; ! double rea; ! double reb; ! int randomSeed; //Agent parameters overridden by the BFagent. //These might be used for other agents that a user implements. ! double tauv; ! double lambda; ! double maxbid; ! double initvar; ! double maxdev; id warmupActions; id periodActions; id warmupSchedule; --- 4,54 ---- #import "Dividend.h" #import "World.h" #import "Output.h" + #import "ASMModelParams.h" + @interface ASMModelSwarm: Swarm { ! // //Agent parameters ! // int numBFagents; ! // float initholding; ! // double initialcash; ! // double minholding; ! // double mincash; ! // double intrate; ! ! // //Dividend parameters ! // double baseline; //Also used by World. ! // double mindividend; ! // double maxdividend; ! // double amplitude; ! // int period; ! ! // //Specialist parameters ! // double maxprice; ! // double minprice; ! // double taup; ! // BOOL exponentialMAs; //Also used by World. ! // int sptype; ! // int maxiterations; ! // double minexcess; ! // double eta; ! // double etamax; ! // double etamin; ! // double rea; ! // double reb; ! // int randomSeed; //Agent parameters overridden by the BFagent. //These might be used for other agents that a user implements. ! // double tauv; ! // double lambda; ! // double maxbid; ! // double initvar; ! // double maxdev; + int modelTime; id warmupActions; id periodActions; id warmupSchedule; *************** *** 58,71 **** id dividendProcess; id world; id output; ! BOOL setOutputForData; } ! +createBegin: (id)aZone; -createEnd; -getAgentList; -(int)getNumBFagents; -(double)getInitialCash; --- 61,80 ---- id dividendProcess; id world; id output; ! // int setOutputForData; ! ! BFParams * bfParams; //pj: a parameter object ! ASMModelParams * asmModelParams; //pj: a parameter object ! } ! //+createBegin: (id)aZone; ! -createEnd; + - setParamsModel: (ASMModelParams *) modelParams BF: (BFParams *) bfp ; //pj: new param receiver -getAgentList; -(int)getNumBFagents; -(double)getInitialCash; *************** *** 75,84 **** -setBatchRandomSeed: (int)newSeed; -buildObjects; ! -initOutputForDataWrite; ! -initOutputForParamWrite; ! -buildActions; ! -activateIn: (id)swarmContext; void warmUp(id warmupSchedule); void initPeriod(id initPeriodSchedule); --- 84,94 ---- -setBatchRandomSeed: (int)newSeed; -buildObjects; ! // pj: -initOutputForDataWrite; ! // pj: -initOutputForParamWrite; ! - writeParams; ! - buildActions; ! - activateIn: (id)swarmContext; void warmUp(id warmupSchedule); void initPeriod(id initPeriodSchedule); *************** *** 89,93 **** --- 99,107 ---- //-prepareBFagentForTrading; -periodStepPrice; + + -(long int) getModelTime; + + -(void) drop; @end diff -cr ASM-20000602/ASMModelSwarm.m ASM-20011125/ASMModelSwarm.m *** ASM-20000602/ASMModelSwarm.m Fri Jun 2 11:03:37 2000 --- ASM-20011125/ASMModelSwarm.m Wed Oct 24 18:26:08 2001 *************** *** 1,182 **** #import "ASMModelSwarm.h" #import #import "Output.h" - //#import "random.h" #import "BFParams.h" #import "BFCast.h" - #import #include - @implementation ASMModelSwarm - +createBegin: (id)aZone - { - ASMModelSwarm * obj; - id probeMap; - - obj = [super createBegin: aZone]; - - obj->numBFagents = 30; - obj->initholding = 1; - obj->initialcash = 10000; - obj->minholding = 0; - obj->mincash = 0; - obj->intrate = 0.1; - obj->baseline = 10; - obj->mindividend = 0.00005; - obj->maxdividend = 100; - obj->amplitude = 0.14178; - obj->period = .99; - obj->maxprice = 500; - obj->minprice = 0.001; - obj->taup = 50.0; - obj->exponentialMAs = 1; - obj->sptype = 2; //0 = REE, 1 = SLOPE, 2 = ETA - obj->maxiterations = 10; - obj->minexcess = 0.01; - obj->eta = 0.0005; - obj->etamax = 0.05; - obj->etamin = 0.00001; - obj->rea = 9.0; - obj->reb = 2.0; - obj->randomSeed = 0; - - //BFagent lambda and initvar set internally - obj->tauv = 50.0; - obj->lambda = 0.3; - obj->maxbid = 10.0; - obj->initvar = .4000212; - obj->maxdev = 100; - - // Build probes here. - probeMap = [EmptyProbeMap createBegin: aZone]; - [probeMap setProbedClass: [self class]]; - probeMap = [probeMap createEnd]; - - [probeMap addProbe: [probeLibrary getProbeForVariable: "numBFagents" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "initholding" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "initialcash" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "minholding" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "mincash" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "intrate" - inClass: [self class]]]; - - [probeMap addProbe: [probeLibrary getProbeForVariable: "baseline" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "mindividend" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "maxdividend" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "amplitude" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "period" - inClass: [self class]]]; - - [probeMap addProbe: [probeLibrary getProbeForVariable: "maxprice" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "minprice" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "taup" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "exponentialMAs" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "sptype" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "maxiterations" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "minexcess" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "eta" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "etamin" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "etamax" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "rea" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "reb" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "randomSeed" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "tauv" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "lambda" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "maxbid" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "initvar" - inClass: [self class]]]; - [probeMap addProbe: [probeLibrary getProbeForVariable: "maxdev" - inClass: [self class]]]; - [probeLibrary setProbeMap: probeMap For: [self class]]; - - return obj; - } - - - -initOutputForParamWrite - { - [output setNumBFagents: numBFagents]; - [output setInitHolding: initholding]; - [output setInitialCash: initialcash]; - [output setminHolding: minholding minCash: mincash]; - [output setIntRate: intrate]; - - [output setBaseline: baseline]; - [output setmindividend: mindividend]; - [output setmaxdividend: maxdividend]; - [output setTheAmplitude: amplitude]; - [output setThePeriod: period]; - - [output setExponentialMAs: exponentialMAs]; - - [output setMaxPrice: maxprice]; - [output setMinPrice: minprice]; - [output setTaup: taup]; - [output setSPtype: sptype]; - [output setMaxIterations: maxiterations]; - [output setMinExcess: minexcess]; - [output setETA: eta]; - [output setETAmin: etamin]; - [output setETAmax: etamax]; - [output setREA: rea]; - [output setREB: reb]; - [output setSeed: randomSeed]; - - [output setTauv: tauv]; - [output setLambda: lambda]; - [output setMaxBid: maxbid]; - [output setInitVar: initvar]; - [output setMaxDev: maxdev]; - - return self; - } - ! -createEnd { return [super createEnd]; } ! -(int)getNumBFagents { ! return numBFagents; } ! -(double)getInitialCash { ! return initialcash; } --- 1,41 ---- #import "ASMModelSwarm.h" #import #import "Output.h" #import "BFParams.h" #import "BFCast.h" #import #include @implementation ASMModelSwarm ! - createEnd { + modelTime=0; + //need to create output so it exists from beginning + output = [[Output createBegin: [self getZone]] createEnd]; return [super createEnd]; } + - setParamsModel: (ASMModelParams *) modelParams BF: (BFParams *) bfp + { + bfParams = bfp; + asmModelParams=modelParams; + fprintf(stderr,"Param object %d ",asmModelParams->numBFagents); + return self; + } ! -(int) getNumBFagents { ! return asmModelParams->numBFagents; } ! -(double) getInitialCash { ! return asmModelParams->initialcash; } *************** *** 185,193 **** return agentList; } - -(World *)getWorld { return world; } --- 44,52 ---- return agentList; } -(World *)getWorld { + if (world == nil) printf("Empty world!"); return world; } *************** *** 204,313 **** } -setBatchRandomSeed: (int)newSeed { ! randomSeed = newSeed; return self; } ! ! -buildObjects //Build and initialize all objects { int i; - id bfParams; ! /* Initialise random number stream (0 means set randomly) */ ! //pj ! //randomSeed = randset(randomSeed); // returns actual seed if 0 ! if(randomSeed != 0) [randomGenerator setStateFromSeed: randomSeed]; ! //pj: note I'm making this like other swarm apps. Same each time, new seeds only if precautions taken. ! ! /* Initialize the dividend, specialist, and world (order is crucial) */ dividendProcess = [Dividend createBegin: [self getZone]]; [dividendProcess initNormal]; ! [dividendProcess setBaseline: baseline]; ! [dividendProcess setmindividend: mindividend]; ! [dividendProcess setmaxdividend: maxdividend]; ! [dividendProcess setAmplitude: amplitude]; ! [dividendProcess setPeriod: period]; [dividendProcess setDerivedParams]; dividendProcess = [dividendProcess createEnd]; world = [World createBegin: [self getZone]]; ! [world setintrate: intrate]; ! [world setExponentialMAs: exponentialMAs]; ! [world initWithBaseline: baseline]; world = [world createEnd]; specialist = [Specialist createBegin: [self getZone]]; ! [specialist setMaxPrice: maxprice]; ! [specialist setMinPrice: minprice]; ! [specialist setTaup: taup]; ! [specialist setSPtype: sptype]; ! [specialist setMaxIterations: maxiterations]; ! [specialist setMinExcess: minexcess]; ! [specialist setETA: eta]; ! [specialist setETAmin: etamin]; ! [specialist setETAmax: etamax]; ! [specialist setREA: rea]; ! [specialist setREB: reb]; ! [specialist init]; [specialist setWorld: world]; specialist = [specialist createEnd]; ! output = [Output create: [self getZone]]; ! if (setOutputForData == 1) ! { ! [output setWorld: world]; ! [output setSpecialist: specialist]; ! [output prepareOutputFile]; ! } ! /* Initialize the agent modules and create the agents */ agentList = [List create: [self getZone]]; //create list for agents - ! if ((bfParams = ! [lispAppArchiver getWithZone: self key: "bfParams"]) == nil) ! raiseEvent(InvalidOperation, ! "Can't find the modelSwarm parameters"); ! [bfParams init]; ! ! [BFagent init]; ! ! [BFagent setBFParameterObject: bfParams]; ! //[BFagent init]; ! [BFagent setWorld: world]; ! //nowObject create the agents themselves ! for (i = 0; i < numBFagents; i++) ! { ! BFagent * agent; ! agent = [BFagent createBegin: [self getZone]]; ! [agent setID: i]; ! [agent setintrate: intrate]; ! [agent setminHolding: minholding minCash: mincash]; ! [agent setInitialCash: initialcash]; ! [agent setInitialHoldings]; ! [agent setPosition: initholding]; ! [agent initForecasts]; ! agent = [agent createEnd]; ! [agentList addLast: agent]; ! } ! // [BFagent didInitialize]; ! ! ! //Give the specialist access to the agentList [specialist setAgentList: agentList]; return self; } ! ! -initOutputForDataWrite { ! setOutputForData = 1; return self; } --- 63,167 ---- } + -(long int) getModelTime + { + return modelTime; + } + -setBatchRandomSeed: (int)newSeed { ! asmModelParams->randomSeed = newSeed; return self; } ! //Build and initialize objects ! -buildObjects { int i; ! // fprintf(stderr, "numBFagents %d \n intrate %f \n baseline %f \n eta %f \n initvar %f \n", asmModelParams->numBFagents,asmModelParams->intrate, asmModelParams->baseline, asmModelParams->eta, asmModelParams->initvar); ! asmModelParams->exponentialMAs = 1; ! if(asmModelParams->randomSeed != 0) ! [randomGenerator setStateFromSeed: asmModelParams->randomSeed]; ! //pj: note I'm making this like other swarm apps. Same each time, new seeds only if precautions taken. ! ! ! /* Initialize the dividend, specialist, and world (order is crucial) */ dividendProcess = [Dividend createBegin: [self getZone]]; [dividendProcess initNormal]; ! [dividendProcess setBaseline: asmModelParams->baseline]; ! [dividendProcess setmindividend: asmModelParams->mindividend]; ! [dividendProcess setmaxdividend: asmModelParams->maxdividend]; ! [dividendProcess setAmplitude: asmModelParams->amplitude]; ! [dividendProcess setPeriod:asmModelParams-> period]; [dividendProcess setDerivedParams]; dividendProcess = [dividendProcess createEnd]; world = [World createBegin: [self getZone]]; ! [world setintrate: asmModelParams->intrate]; ! [world setExponentialMAs: asmModelParams->exponentialMAs]; ! [world initWithBaseline:asmModelParams-> baseline]; world = [world createEnd]; specialist = [Specialist createBegin: [self getZone]]; ! [specialist setMaxPrice: asmModelParams->maxprice]; ! [specialist setMinPrice: asmModelParams-> minprice]; ! [specialist setTaup:asmModelParams-> taup]; ! [specialist setSPtype: asmModelParams-> sptype]; ! [specialist setMaxIterations: asmModelParams-> maxiterations]; ! [specialist setMinExcess: asmModelParams->minexcess]; ! [specialist setETA: asmModelParams-> eta]; ! [specialist setREA: asmModelParams-> rea]; ! [specialist setREB: asmModelParams->reb]; [specialist setWorld: world]; specialist = [specialist createEnd]; ! ! [output setWorld: world]; ! [output setSpecialist: specialist]; ! ! /* Initialize the agent modules and create the agents */ agentList = [List create: [self getZone]]; //create list for agents ! // if ((bfParams = ! // [lispAppArchiver getWithZone: self key: "bfParams"]) == nil) ! // raiseEvent(InvalidOperation, ! // "Can't find the BFParam's parameters"); ! // [bfParams init]; ! ! [BFagent init]; ! ! [BFagent setBFParameterObject: bfParams]; ! ! [BFagent setWorld: world]; ! //nowObject create the agents themselves ! for (i = 0; i < asmModelParams->numBFagents; i++) ! { ! BFagent * agent; ! agent = [BFagent createBegin: [self getZone]]; ! [agent setID: i]; ! [agent setintrate: asmModelParams->intrate]; ! [agent setminHolding: asmModelParams->minholding minCash:asmModelParams-> mincash]; ! [agent setInitialCash: asmModelParams->initialcash]; ! [agent setInitialHoldings]; ! [agent setPosition: asmModelParams->initholding]; ! [agent initForecasts]; ! agent = [agent createEnd]; ! [agentList addLast: agent]; ! } ! //Give the specialist access to the agentList [specialist setAgentList: agentList]; return self; } ! - writeParams { ! if (asmModelParams != nil && bfParams != nil) ! [output writeParams: asmModelParams BFAgent: bfParams Time: modelTime]; return self; } *************** *** 318,324 **** //getTime message -buildActions { - [super buildActions]; warmupActions = [ActionGroup create: [self getZone]]; --- 172,177 ---- *************** *** 435,440 **** --- 288,295 ---- } + + -warmupStepDividend { [world setDividend: [dividendProcess dividend]]; *************** *** 444,468 **** -warmupStepPrice { ! [world setPrice: [world getDividend]/intrate]; return self; } -periodStepDividend { [world setDividend: [dividendProcess dividend]]; return self; } - - //-prepareBFagentForTrading - //pj:{ - //pj:[BFagent prepareForTrading]; - //pj: return self; - //pj:} - - -periodStepPrice { [world setPrice: [specialist performTrading]]; --- 299,322 ---- -warmupStepPrice { ! // fprintf(stderr," Dividend %f \n", [world getDividend]); ! // fprintf(stderr," setPrice %f \n", [world getDividend]/asmModelParams->intrate ); ! ! // fprintf(stderr, "numBFagents %d \n intrate %f \n baseline %f \n eta %f \n initvar %f \n", ! // asmModelParams->numBFagents,asmModelParams->intrate, asmModelParams->baseline, asmModelParams->eta, asmModelParams->initvar); ! ! [world setPrice: ([world getDividend]/(double)asmModelParams->intrate )]; return self; } -periodStepDividend { + modelTime++; [world setDividend: [dividendProcess dividend]]; return self; } -periodStepPrice { [world setPrice: [specialist performTrading]]; *************** *** 476,481 **** --- 330,344 ---- [startupSchedule activateIn: self]; [periodSchedule activateIn: self]; return [self getSwarmActivity]; + } + + -(void) drop + { + [dividendProcess drop]; + [world drop]; + [specialist drop]; + [output drop]; + [super drop]; } @end diff -cr ASM-20000602/ASMObserverSwarm.h ASM-20011125/ASMObserverSwarm.h *** ASM-20000602/ASMObserverSwarm.h Sun May 7 13:09:26 2000 --- ASM-20011125/ASMObserverSwarm.h Wed Oct 24 18:26:08 2001 *************** *** 3,8 **** --- 3,11 ---- #import #import #import "ASMModelSwarm.h" + #import "ASMModelParams.h" + #import + @interface ASMObserverSwarm: GUISwarm { *************** *** 15,31 **** BOOL writeParams; BOOL writeData; ! id priceGraph; ! id priceData; ! id riskNeutralData; ! ! id priceGrapher; ! id riskNeutralGrapher; ! ! id volumeGraph; ! id volumeData; ! ! id volumeGrapher; id positionHisto; //Histo *cashHisto; //A histogram for agent cash holdings. --- 18,27 ---- BOOL writeParams; BOOL writeData; ! id priceGraph; ! ! id volumeGraph; ! id positionHisto; //Histo *cashHisto; //A histogram for agent cash holdings. *************** *** 39,49 **** id deviationGrapher; ! double *position; ! double *wealth; //double * cash; ! double *relativeWealth; ! int numagents; } + createBegin: aZone; --- 35,44 ---- id deviationGrapher; ! //double *position; ! // double *wealth; //double * cash; ! //double *relativeWealth; } + createBegin: aZone; *************** *** 56,69 **** - printRelWealthHisto; #endif - createEnd; - buildObjects; - updateHistos; - writeSimulationParams; - (BOOL)ifParamWrite; - expostParamWrite; ! - writeSimulationData; - buildActions; - activateIn: swarmContext; @end --- 51,71 ---- - printRelWealthHisto; #endif - createEnd; + - _writeRawData_; + - buildObjects; + + - priceGraphDeath_ : caller; + - volumeGraphDeath_ : caller; - updateHistos; - writeSimulationParams; - (BOOL)ifParamWrite; - expostParamWrite; ! ! -(BOOL) toggleDataWrite; - buildActions; - activateIn: swarmContext; + -(void) drop; @end diff -cr ASM-20000602/ASMObserverSwarm.m ASM-20011125/ASMObserverSwarm.m *** ASM-20000602/ASMObserverSwarm.m Mon Apr 24 20:25:06 2000 --- ASM-20011125/ASMObserverSwarm.m Wed Oct 24 18:26:08 2001 *************** *** 1,5 **** --- 1,6 ---- #import "ASMObserverSwarm.h" #import + #import "Parameters.h" #include *************** *** 22,28 **** [probeMap addProbe: [probeLibrary getProbeForMessage: "writeSimulationParams" inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForMessage: ! "writeSimulationData" inClass: [self class]]]; //The member functions that allow you to print a graph. #if 0 --- 23,29 ---- [probeMap addProbe: [probeLibrary getProbeForMessage: "writeSimulationParams" inClass: [self class]]]; [probeMap addProbe: [probeLibrary getProbeForMessage: ! "toggleDataWrite" inClass: [self class]]]; //The member functions that allow you to print a graph. #if 0 *************** *** 84,154 **** - buildObjects { ! id modelZone; ! ! [super buildObjects]; ! modelZone = [Zone create: [self getZone]]; ! asmModelSwarm = [ASMModelSwarm create: modelZone]; ! CREATE_ARCHIVED_PROBE_DISPLAY (asmModelSwarm); CREATE_ARCHIVED_PROBE_DISPLAY (self); - [actionCache waitForControlEvent]; - if ([controlPanel getState] == ControlStateQuit) - return self; [asmModelSwarm buildObjects]; ! numagents = [asmModelSwarm getNumBFagents]; ! position = xcalloc (numagents, sizeof (double)); ! wealth = xcalloc (numagents, sizeof (double)); ! //cash = xcalloc (numagents, sizeof (double)); ! relativeWealth = xcalloc (numagents, sizeof (double)); ! ! priceGraph = [Graph createBegin: [self getZone]]; ! SET_WINDOW_GEOMETRY_RECORD_NAME (priceGraph); ! priceGraph = [priceGraph createEnd]; ! ! [priceGraph setTitle: "Price v. time"]; ! [priceGraph setAxisLabelsX: "time" Y: "price"]; ! [priceGraph setRangesYMin: 0.0 Max: 200.0]; ! [priceGraph pack]; ! priceData = [priceGraph createElement]; ! [[priceData setLabel: "actualprice"] setColor: "blue"]; ! priceGrapher = [ActiveGraph createBegin: [self getZone]]; ! [priceGrapher setElement: priceData]; ! [priceGrapher setDataFeed: [asmModelSwarm getWorld]]; ! [priceGrapher setProbedSelector: M(getPrice)]; ! priceGrapher = [priceGrapher createEnd]; ! ! riskNeutralData = [priceGraph createElement]; ! [[riskNeutralData setLabel: "risk neutral price"] setColor: "black"]; ! ! riskNeutralGrapher = [ActiveGraph createBegin: [self getZone]]; ! [riskNeutralGrapher setElement: riskNeutralData]; ! [riskNeutralGrapher setDataFeed: [asmModelSwarm getWorld]]; ! [riskNeutralGrapher setProbedSelector: M(getRiskNeutral)]; ! riskNeutralGrapher = [riskNeutralGrapher createEnd]; ! ! volumeGraph = [Graph createBegin: [self getZone]]; ! SET_WINDOW_GEOMETRY_RECORD_NAME (volumeGraph); ! volumeGraph = [volumeGraph createEnd]; ! ! [volumeGraph setTitle: "Volume v. time"]; ! [volumeGraph setAxisLabelsX: "time" Y: "volume"]; ! [volumeGraph pack]; ! ! volumeData = [volumeGraph createElement]; ! [volumeData setLabel: "volume"]; ! ! volumeGrapher = [ActiveGraph createBegin: [self getZone]]; ! [volumeGrapher setElement: volumeData]; ! [volumeGrapher setDataFeed: [asmModelSwarm getSpecialist]]; ! [volumeGrapher setProbedSelector: M(getVolume)]; ! volumeGrapher = [volumeGrapher createEnd]; positionHisto = [Histogram createBegin: [self getZone]]; SET_WINDOW_GEOMETRY_RECORD_NAME (positionHisto); --- 85,132 ---- - buildObjects { ! int numagents; ! ASMModelParams * asmModelParams = [(id)arguments getModelParams]; ! BFParams * bfParams = [(id)arguments getBFParams]; ! [super buildObjects]; ! ! asmModelSwarm = [ASMModelSwarm create: self]; ! ! [asmModelSwarm setParamsModel: asmModelParams BF: bfParams]; ! CREATE_ARCHIVED_PROBE_DISPLAY (asmModelParams); CREATE_ARCHIVED_PROBE_DISPLAY (self); + [controlPanel setStateStopped]; [asmModelSwarm buildObjects]; + + numagents = asmModelParams->numBFagents; + + priceGraph = [EZGraph create: self setTitle: "Price v. time" + setAxisLabelsX: "time" Y: "price" + setWindowGeometryRecordName: "priceGraph"]; + [priceGraph enableDestroyNotification: self + notificationMethod: @selector (_priceGraphDeath_:)]; + [priceGraph createSequence: "actual price" + withFeedFrom: [asmModelSwarm getWorld] + andSelector: M(getPrice)]; + [priceGraph createSequence: "risk neutral price" + withFeedFrom: [asmModelSwarm getWorld] + andSelector: M(getRiskNeutral)]; ! ! volumeGraph = [EZGraph create: self setTitle: "Volume v. time" ! setAxisLabelsX: "time" Y: "volume" ! setWindowGeometryRecordName: "volumeGraph"]; ! [volumeGraph createSequence: "actual price" ! withFeedFrom: [asmModelSwarm getSpecialist] ! andSelector: M(getVolume)]; ! [priceGraph enableDestroyNotification: self ! notificationMethod: @selector (_volumeGraphDeath_:)]; positionHisto = [Histogram createBegin: [self getZone]]; SET_WINDOW_GEOMETRY_RECORD_NAME (positionHisto); *************** *** 210,235 **** return self; } - updateHistos { id index; id agent; int i; ! index = [[asmModelSwarm getAgentList] begin: [self getZone]]; for(i=0; (agent = [index next]); i++) { position[i] = [agent getAgentPosition]; ! wealth[i] = [agent getWealth]; //cash[i] = [agent getCash]; - relativeWealth[i] = wealth[i]/[asmModelSwarm getInitialCash]; - //profit[i] = [agent getProfit]; } [index drop]; [positionHisto drawHistogramWithDouble: position]; - //[cashHisto drawHistoWithDouble: cash]; [relativeWealthHisto drawHistogramWithDouble: relativeWealth]; return self; } --- 188,230 ---- return self; } + - priceGraphDeath_ : caller + { + [priceGraph drop]; + priceGraph = nil; + return self; + } + + - volumeGraphDeath_ : caller + { + [volumeGraph drop]; + volumeGraph = nil; + return self; + } + - updateHistos { id index; id agent; int i; ! int numagents = [[asmModelSwarm getAgentList] getCount]; ! double position[numagents]; ! double relativeWealth[numagents]; ! //double cash[numagents]; ! index = [[asmModelSwarm getAgentList] begin: [self getZone]]; for(i=0; (agent = [index next]); i++) { + double initcash=[(id)arguments getModelParams]->initialcash; position[i] = [agent getAgentPosition]; ! relativeWealth[i] = [agent getWealth]/initcash; //cash[i] = [agent getCash]; } [index drop]; [positionHisto drawHistogramWithDouble: position]; [relativeWealthHisto drawHistogramWithDouble: relativeWealth]; + //[cashHisto drawHistoWithDouble: cash]; return self; } *************** *** 238,251 **** - writeSimulationParams { writeParams = 1; return self; } - expostParamWrite { ! [asmModelSwarm initOutputForParamWrite]; ! [[asmModelSwarm getOutput] writeParams]; return self; } --- 233,249 ---- - writeSimulationParams { writeParams = 1; + [[asmModelSwarm getOutput] writeParams: [(id) arguments getModelParams] BFAgent: [(id) arguments getBFParams] Time: [asmModelSwarm getModelTime]]; + return self; } - expostParamWrite { ! // [asmModelSwarm initOutputForParamWrite]; ! if (writeParams == 1) ! [[asmModelSwarm getOutput] writeParams: [(id) arguments getModelParams] BFAgent: [(id) arguments getBFParams] Time: getCurrentTime()]; return self; } *************** *** 256,272 **** } ! - writeSimulationData { ! if(writeParams != 1) ! writeParams = 1; ! [asmModelSwarm initOutputForDataWrite]; ! writeData = 1; ! return self; } - buildActions { [super buildActions]; --- 254,284 ---- } ! -(BOOL) toggleDataWrite { ! if(writeData != YES) ! { ! [[asmModelSwarm getOutput] prepareOutputFile]; ! writeData = YES; ! } ! else ! writeData = NO; ! ! return writeData; ! } ! ! ! ! - _writeRawData_ ! { ! if (writeData == YES) ! [[asmModelSwarm getOutput] writeData]; ! // fprintf(stderr,"getcurrent %ld modeltime %ld",getCurrentTime(),[asmModelSwarm getModelTime]); return self; } + - buildActions { [super buildActions]; *************** *** 274,286 **** [asmModelSwarm buildActions]; displayActions = [ActionGroup create: [self getZone]]; ! if(writeData == 1) ! [displayActions createActionTo: [asmModelSwarm getOutput] ! message: M(writeData)]; [displayActions createActionTo: self message: M(updateHistos)]; ! [displayActions createActionTo: priceGrapher message: M(step)]; ! [displayActions createActionTo: riskNeutralGrapher message: M(step)]; ! [displayActions createActionTo: volumeGrapher message: M(step)]; //[displayActions createActionTo: deviationAverager message: M(update)]; //[displayActions createActionTo: deviationGrapher message: M(step)]; [displayActions createActionTo: probeDisplayManager --- 286,298 ---- [asmModelSwarm buildActions]; displayActions = [ActionGroup create: [self getZone]]; ! ! [displayActions createActionTo: self ! message: M(_writeRawData_)]; [displayActions createActionTo: self message: M(updateHistos)]; ! [displayActions createActionTo: priceGraph message: M(step)]; ! // [displayActions createActionTo: riskNeutralGrapher message: M(step)]; ! [displayActions createActionTo: volumeGraph message: M(step)]; //[displayActions createActionTo: deviationAverager message: M(update)]; //[displayActions createActionTo: deviationGrapher message: M(step)]; [displayActions createActionTo: probeDisplayManager *************** *** 304,309 **** --- 316,328 ---- return [self getSwarmActivity]; } + + -(void) drop + { + [asmModelSwarm drop]; + [super drop]; + } + @end diff -cr ASM-20000602/BFCast.m ASM-20011125/BFCast.m *** ASM-20000602/BFCast.m Fri Jun 2 11:03:37 2000 --- ASM-20011125/BFCast.m Wed Feb 7 15:30:52 2001 *************** *** 1,5 **** --- 1,6 ---- #import "BFCast.h" #import "BFParams.h" + #import @implementation BFCast diff -cr ASM-20000602/BFParams.h ASM-20011125/BFParams.h *** ASM-20000602/BFParams.h Thu May 25 13:22:37 2000 --- ASM-20011125/BFParams.h Fri Jun 29 16:30:15 2001 *************** *** 66,72 **** }; ! -init; -(int*) getBitListPtr; --- 66,72 ---- }; ! - init; -(int*) getBitListPtr; diff -cr ASM-20000602/BFParams.m ASM-20011125/BFParams.m *** ASM-20000602/BFParams.m Fri Jun 2 13:01:21 2000 --- ASM-20011125/BFParams.m Wed Oct 24 18:26:08 2001 *************** *** 69,75 **** } ! -init { int i; --- 69,75 ---- } ! - init; { int i; *************** *** 130,137 **** if (npool > npoolmax) npoolmax = npool; if (nnew > nnewmax) nnewmax = nnew; if (condwords > ncondmax) ncondmax = condwords; ! fprintf(stderr,"BFParams init complete"); ! return self; } -(int*) getBitListPtr --- 130,137 ---- if (npool > npoolmax) npoolmax = npool; if (nnew > nnewmax) nnewmax = nnew; if (condwords > ncondmax) ncondmax = condwords; ! // fprintf(stderr,"BFParams init complete"); ! return [super createEnd]; } -(int*) getBitListPtr diff -cr ASM-20000602/BFagent.m ASM-20011125/BFagent.m *** ASM-20000602/BFagent.m Fri Jun 2 13:01:21 2000 --- ASM-20011125/BFagent.m Thu Oct 25 16:41:40 2001 *************** *** 262,267 **** --- 262,270 ---- //pj: ReadBitname moved to BFParams + //pj: This is the only global variable I still need, and I'm looking for a way go get rid of it! + static double minstrength; + // PRIVATE METHODS @interface BFagent(Private) *************** *** 1222,1228 **** id rejectList = [Array create: [self getZone] setCount: getInt(privateParams,"npoolmax")]; ! static double avstrength,minstrength; ++gacount; currentTime = getCurrentTime(); --- 1225,1232 ---- id rejectList = [Array create: [self getZone] setCount: getInt(privateParams,"npoolmax")]; ! static double avstrength; ! ++gacount; currentTime = getCurrentTime(); *************** *** 1392,1399 **** /*------------------------------------------------------*/ -(BFCast *) CopyRule:(BFCast *) to From: (BFCast *) from { - - double minstrength = 1.0e20; [to setForecast: [from getForecast]]; [to setLforecast: [from getLforecast]]; [to setVariance: [from getVariance]]; --- 1396,1401 ---- *************** *** 1745,1751 **** { specificity++; } ! printf("CrossoverDiagnostic: newforecast Specificity %d should equal %d \n", [newForecast getSpecificity],specificity); } return newForecast; } --- 1747,1753 ---- { specificity++; } ! //printf("CrossoverDiagnostic: newforecast Specificity %d should equal %d \n", [newForecast getSpecificity],specificity); } return newForecast; } diff -cr ASM-20000602/ChangeLog ASM-20011125/ChangeLog *** ASM-20000602/ChangeLog Fri Jun 2 13:01:21 2000 --- ASM-20011125/ChangeLog Thu Oct 25 16:41:40 2001 *************** *** 1,3 **** --- 1,172 ---- + 2001-10-25 Paul E Johnson + + * BFagent.m ([BFagent -CopyRule:to:from]): minstrength has to be + put back in as a global variable because it is used in the + performGA as well as CopyRule methods. Changing it to a local + variable broke CopyRule for some forecasts in which Count=0. That + was hard to track down, I'll tell ya. + + 2001-10-24 Paul E Johnson + + * ASMObserverSwarm.hm (GUISwarm): Found way to make histograms + work without using these IVARS *position, *wealth,and + *relativeWealth. That means no more need for calloc calls in the + "m" file and it also means that this model should respond well if + agents are removed or added (i.e., numagents need not be a + constant). + + * Output.m ([Output -writeData]): hdfWriter is an EZGraph that + does not show on the screen, but it dumps its time series into a + file. That means there are 3 data outputs: 1 text, 1 archiver + dump (either hdf5 or scm) and 1 hdf5. This new EZGraph writer + requires a newish edition of swarm. + + 2001-10-23 + + * ASMObserverSwarm.h (GUISwarm): Convert volumeGraph to EZGraph + format, insert _volumeGraphDeath_ method for destroy notification. + + 2001-10-23 Paul E Johnson + + * ASMObserverSwarm.m ([ASMObserverSwarm -buildObjects]): Convert + Graph to EZGraphs, create _priceGraphDeath_: method for destroy + notification. + + 2001-06-29 Paul E. Johnson + + * BFParams.m ([BFParams -createEnd]): init method name changed to + createEnd, so that these settings are ready from the moment the + object is created. + + * Output.hm (SwarmObject): new dataArchiver object, writes in hdf5 + or lisp, according to cpp flag. + + * Parameters.h: New class to collect up parameter creation + + * Output.m ([Output -createEnd]): create timeString variable to + capture current time. Purify it. Use it in naming files + + 2001-06-28 Paul E. Johnson + + * ASMObserverSwarm.m ([ASMObserverSwarm -buildObjects]): fix + coding for graphs to unrwap object creation because Swarm no + longer returns values from creating methods. + + 2001-02-08 Paul E Johnson + + * Specialist.[hm]: removed setEtaMax/setEtaMin methods because + they were never used. Cleaned out unused variables. + + * Specialist.[hm]: removed init method, because its work has been + reallocated to other methods. + + * ASMObserverSwarm.m ([ASMObserverSwarm -expostParamWrite]): If + writeParams is YES at the end of the run, it dumps a copy of the + settings. That way, there will always be a record of the + simulation, even if the user punches the "writeSimulationParams" + button only at the very beginning. + + * Output.m ([Output -writeParams:BFAgent:Time:t]): Moved all + archiver-creating code and parmeter writing activity in here. + + * ASMObserverSwarm.m ([ASMObserverSwarm -writeSimulationParams]): + Whenever you punch the "writeSimulationParams" button, it tells + Output object to dump out a time-keyed set of parameters to + asm.scm. Note: If user does this before the model has started, + nothing happens because there are no objects to save yet. But it + will turn on a switch that causes params to be automatically saved + at the end of the run. + + * ASMModelSwarm.m ([ASMModelSwarm -createEnd]): added, set + modelTime=0; + + * ASMModelSwarm.m ([AsmModelSwarm -getModelTime): get + method to allow other classes to find out what Swarm "time step" + the model is on. + + 2001-02-07 Paul E Johnson + + * Output.m ([Output -dumpParametersModel:BFAgent:]): New method, + Model can tell it to do this and it will decide whether to use + Lisp or HDF5 and create a time-stamped parameter output file. + + * Output.m([Output -createEnd]): runTime is now calculated at + create time, so that any output files can be time stamped. + + * main.m (main): Now it will dump parameter values at the end of + the run, whatever Output is supposed to dump, will get dumped, + with a time-stamp. + + * ASMModelSwarm.m (buildObjects): get rid of conditional round + output object creation/setting. We are always setting up an output + object, whether or not the user wants to actually output + data. This gets rid of one layer of stupidity. + + * ASMModelSwarm.m (initOutputForDataWrite): delete this method and + associated IVAR + + * ASMModelParams.m ([ASMModelParams +createBegin:aZone]): added + probe for setOutputData + + * asm.scm (cons): added setOutputForData 1 to initialize it. + + 2001-02-06 Paul E Johnson + + * BFCast.m: added import of + + 2000-06-16 Paul Johnson + + * main.m (main): lispAppArchiver loading for ASMBatchSwarm + + * ASMBatchSwarm.m ([ASMBatchSwarm -buildObjects]): batch model + load parameters from asm.scm. Adjust asm.scm accordingly. + + 2000-06-08 Paul Johnson + + * Output.h:Removed the following methods: + -setNumBFagents: (int)BFagents; + -setInitHolding: (float)Holding; + -setInitialCash: (double)initcash; + -setminHolding: (double)holding minCash: (double)minimumcash; + -setIntRate: (double)Rate; + + -setBaseline: (double)theBaseline; + -setmindividend: (double)minimumDividend; + -setmaxdividend: (double)maximumDividend; + -setTheAmplitude: (double)theAmplitude; + -setThePeriod: (int)thePeriod; + -setExponentialMAs: (BOOL)aBool; + + -setMaxPrice: (double)maximumPrice; + -setMinPrice: (double)minimumPrice; + -setTaup: (double)aTaup; + -setSPtype: (int)i; + -setMaxIterations: (int)someIterations; + -setMinExcess: (double)minimumExcess; + -setETA: (double)ETA; + -setETAmin: (double)ETAmin; + -setETAmax: (double) ETAmax; + -setREA: (double)REA; + -setREB: (double)REB; + + -setSeed: (int)aSeed; + + -setTauv: (double)aTauv; + -setLambda: (double)aLambda; + -setMaxBid: (double)maximumBid; + -setInitVar: (double)initialVar; + -setMaxDev: (double)maximumDev; + + + * ASMModelSwarm.m ([ASMModelSwarm): removed parameter setting + activity to separate class called ASMModelParams. That class also + has probes now. So no more need for createBegin. Deleted all + IVARS from ASMModelSwarm.h that are in the param object, use -> to + get params back from parameter object. + + * ASMModelSwarm: Removed initParamForWrite. Now archiver can put + shallow and it works fine. + 2000-06-02 Paul Johnson * BFagent.h (Agent): Closed memory leaks by [index drop]. Still diff -cr ASM-20000602/Dividend.m ASM-20011125/Dividend.m *** ASM-20000602/Dividend.m Sun May 7 13:09:26 2000 --- ASM-20011125/Dividend.m Wed Oct 24 18:26:08 2001 *************** *** 134,140 **** dvdnd = mindividend; if (dvdnd > maxdividend) dvdnd = maxdividend; ! return dvdnd; } --- 134,142 ---- dvdnd = mindividend; if (dvdnd > maxdividend) dvdnd = maxdividend; ! ! // printf(" \n \n World dividend %f baseline %f rho %f max %f min %f\n \n", dvdnd, baseline, rho, maxdividend, mindividend); ! return dvdnd; } diff -cr ASM-20000602/Makefile ASM-20011125/Makefile *** ASM-20000602/Makefile Fri Jun 2 13:01:21 2000 --- ASM-20011125/Makefile Fri Jun 29 16:30:15 2001 *************** *** 6,12 **** APPLICATION = asm OBJECTS = Agent.o Dividend.o World.o \ Specialist.o Output.o ASMModelSwarm.o \ ! ASMObserverSwarm.o ASMBatchSwarm.o main.o BFParams.o BFCast.o BFagent.o BitVector.o OTHERCLEAN = param.data_* output.data* DATAFILES = batch.setup param.data --- 6,14 ---- APPLICATION = asm OBJECTS = Agent.o Dividend.o World.o \ Specialist.o Output.o ASMModelSwarm.o \ ! ASMObserverSwarm.o ASMBatchSwarm.o main.o BFParams.o BFCast.o BFagent.o BitVector.o \ ! ASMModelParams.o Parameters.o ! OTHERCLEAN = param.data_* output.data* DATAFILES = batch.setup param.data *************** *** 16,22 **** Agent.o: Agent.h Agent.m BFAgent.o: BFagent.h BFagent.m BFParams.h BFCast.h World.h BitVector.h Dividend.o: Dividend.h Dividend.m ! Output.o: Output.h Output.m ASMModelSwarm.o: ASMModelSwarm.h ASMModelSwarm.m BFParams.o Specialist.o: Specialist.h Specialist.m World.o: World.h World.m --- 18,24 ---- Agent.o: Agent.h Agent.m BFAgent.o: BFagent.h BFagent.m BFParams.h BFCast.h World.h BitVector.h Dividend.o: Dividend.h Dividend.m ! Output.o: Output.h Output.m BFParams.h ASMModelParams.h ASMModelSwarm.o: ASMModelSwarm.h ASMModelSwarm.m BFParams.o Specialist.o: Specialist.h Specialist.m World.o: World.h World.m *************** *** 25,28 **** ASMBatchSwarm.o: ASMBatchSwarm.h ASMBatchSwarm.m BFParams.o: BFParams.h BFParams.m World.h BFCast.o: BFCast.h BFCast.m BitVector.h ! BitVector.o: BitVector.h \ No newline at end of file --- 27,32 ---- ASMBatchSwarm.o: ASMBatchSwarm.h ASMBatchSwarm.m BFParams.o: BFParams.h BFParams.m World.h BFCast.o: BFCast.h BFCast.m BitVector.h ! BitVector.o: BitVector.h BitVector.m ! ASMModelParams.o: ASMModelParams.h ASMModelParams.m ! Parameters.o: Parameters.h Parameters.m ASMModelParams.h BFParams.h diff -cr ASM-20000602/Output.h ASM-20011125/Output.h *** ASM-20000602/Output.h Sun May 7 13:09:26 2000 --- ASM-20011125/Output.h Wed Oct 24 18:26:08 2001 *************** *** 4,99 **** #import #import #import #import "World.h" #import "Specialist.h" ! @interface Output: SwarmObject { World * outputWorld; Specialist * outputSpecialist; ! ! int numBFagents; ! float initholding; ! double initialcash; ! double minholding; ! double mincash; ! double intrate; ! ! double baseline; ! double mindividend; ! double maxdividend; ! double amplitude; ! int period; ! ! BOOL exponentialMAs; ! ! double maxprice; ! double minprice; ! double taup; ! int sptype; ! int maxiterations; ! double minexcess; ! double eta; ! double etamax; ! double etamin; ! double rea; ! double reb; ! int seed; ! double tauv; ! double lambda; ! double maxbid; ! double initvar; ! double maxdev; ! FILE * paramOutputFile; time_t runTime; int currentTime; double price; double dividend; double volume; ! FILE * dataOutputFile; } -setSpecialist: (Specialist *)theSpec; -setWorld: (World *)theWorld; - -setNumBFagents: (int)BFagents; - -setInitHolding: (float)Holding; - -setInitialCash: (double)initcash; - -setminHolding: (double)holding minCash: (double)minimumcash; - -setIntRate: (double)Rate; - - -setBaseline: (double)theBaseline; - -setmindividend: (double)minimumDividend; - -setmaxdividend: (double)maximumDividend; - -setTheAmplitude: (double)theAmplitude; - -setThePeriod: (int)thePeriod; ! -setExponentialMAs: (BOOL)aBool; ! ! -setMaxPrice: (double)maximumPrice; ! -setMinPrice: (double)minimumPrice; ! -setTaup: (double)aTaup; ! -setSPtype: (int)i; ! -setMaxIterations: (int)someIterations; ! -setMinExcess: (double)minimumExcess; ! -setETA: (double)ETA; ! -setETAmin: (double)ETAmin; ! -setETAmax: (double) ETAmax; ! -setREA: (double)REA; ! -setREB: (double)REB; ! ! -setSeed: (int)aSeed; ! ! -setTauv: (double)aTauv; ! -setLambda: (double)aLambda; ! -setMaxBid: (double)maximumBid; ! -setInitVar: (double)initialVar; ! -setMaxDev: (double)maximumDev; - -writeParams; -prepareOutputFile; -writeData; @end --- 4,52 ---- #import #import #import + #import #import "World.h" #import "Specialist.h" ! #import ! #import ! #import @interface Output: SwarmObject { + @private + BOOL dataFileExists; + World * outputWorld; Specialist * outputSpecialist; ! id archiver, dataArchiver; ! ! // FILE * paramOutputFile; time_t runTime; + char timeString[100]; + + FILE * dataOutputFile; + id hdfWriter; + id hdf5container; + @public int currentTime; double price; double dividend; double volume; ! } -setSpecialist: (Specialist *)theSpec; + -setWorld: (World *)theWorld; ! - writeParams: modelParam BFAgent: bfParms Time: (long int) t; -prepareOutputFile; + -writeData; + + -(void) drop; @end diff -cr ASM-20000602/Output.m ASM-20011125/Output.m *** ASM-20000602/Output.m Mon Apr 24 20:25:07 2000 --- ASM-20011125/Output.m Wed Oct 24 18:26:08 2001 *************** *** 4,298 **** @implementation Output ! - setSpecialist: (Specialist *)theSpec ! { ! outputSpecialist = theSpec; ! return self; ! } ! ! - setWorld: (World *)theWorld; ! { ! outputWorld = theWorld; ! return self; ! } ! ! - setNumBFagents: (int)BFagents ! { ! numBFagents = BFagents; ! return self; ! } ! ! - setInitHolding: (float)Holding ! { ! initholding = Holding; ! return self; ! } ! ! - setInitialCash: (double)initcash; { ! initialcash = initcash; ! return self; ! } ! ! - setminHolding: (double)holding minCash: (double)minimumcash ! { ! minholding = holding; ! mincash = minimumcash; ! return self; ! } ! - setIntRate: (double)Rate ! { ! intrate = Rate; ! return self; ! } ! - setBaseline: (double)theBaseline ! { ! baseline = theBaseline; ! return self; ! } ! - setmindividend: (double)minimumDividend ! { ! mindividend = minimumDividend; ! return self; ! } ! - setmaxdividend: (double)maximumDividend ! { ! maxdividend = maximumDividend; ! return self; ! } - - setTheAmplitude: (double)theAmplitude - { - amplitude = theAmplitude; - return self; - } - - setThePeriod: (int)thePeriod - { - period = thePeriod; - return self; - } ! - setExponentialMAs: (BOOL)aBool ! { ! exponentialMAs = aBool; ! return self; ! } - - setMaxPrice: (double)maximumPrice - { - maxprice = maximumPrice; return self; } - - setMinPrice: (double)minimumPrice - { - minprice = minimumPrice; - return self; - } ! - setTaup: (double)aTaup { ! taup = aTaup; ! return self; ! } ! - setSPtype: (int)i ! { ! sptype = i; return self; } ! - setMaxIterations: (int)someIterations { ! maxiterations = someIterations; ! return self; ! } ! - setMinExcess: (double)minimumExcess ! { ! minexcess = minimumExcess; ! return self; ! } - - setETA: (double)ETA - { - eta = ETA; - return self; - } ! - setETAmin: (double)ETAmin ! { ! etamin = ETAmin; return self; } ! - setETAmax: (double) ETAmax { ! etamax = ETAmax; ! return self; ! } ! - setREA: (double)REA ! { ! rea = REA; ! return self; ! } ! - setREB: (double)REB ! { ! reb = REB; ! return self; } - - setSeed: (int)aSeed; - { - seed = aSeed; - return self; - } ! - setTauv: (double)aTauv { ! tauv = aTauv; ! return self; ! } ! - setLambda: (double)aLambda ! { ! lambda = aLambda; ! return self; ! } - - setMaxBid: (double)maximumBid - { - maxbid = maximumBid; return self; } ! - setInitVar: (double)initialVar { - initvar = initialVar; - return self; - } ! - setMaxDev: (double)maximumDev ! { ! maxdev = maximumDev; ! return self; ! } ! - writeParams ! { ! char paramFile[256]; ! int i; ! ! if (!runTime) ! runTime = time(NULL); ! ! strcpy (paramFile,"param.data"); ! strcat (paramFile," "); ! ! strcat (paramFile, ctime (&runTime)); ! for (i = 0; i < 256; i++) ! { ! if (paramFile[i] == ' ' || paramFile[i] == ':') ! paramFile[i] = '_'; ! if (paramFile[i] == '\n') ! paramFile[i] = '\0'; ! } ! ! if(!(paramOutputFile = fopen(paramFile, "w"))) ! abort(); ! fprintf (paramOutputFile, "@begin\n"); ! fprintf (paramOutputFile, "numBFagents %d\n",numBFagents); ! fprintf (paramOutputFile, "initholding %f\n",initholding); ! fprintf (paramOutputFile, "initialcash %f\n",initialcash); ! fprintf (paramOutputFile, "minholding %f\n",minholding); ! fprintf (paramOutputFile, "mincash %f\n",minholding); ! fprintf (paramOutputFile, "intrate %f\n",intrate); ! ! fprintf (paramOutputFile, "baseline %f\n",baseline); ! fprintf (paramOutputFile, "mindividend %f\n",mindividend); ! fprintf (paramOutputFile, "maxdividend %f\n",maxdividend); ! fprintf (paramOutputFile, "amplitude %f\n",amplitude); ! fprintf (paramOutputFile, "period %d\n",period); ! ! fprintf (paramOutputFile, "exponentialMAs %d\n",exponentialMAs); ! ! fprintf (paramOutputFile, "maxprice %f\n",maxprice); ! fprintf (paramOutputFile, "minprice %f\n",minprice); ! fprintf (paramOutputFile, "taup %f\n",taup); ! fprintf (paramOutputFile, "sptype %d\n",sptype); ! fprintf (paramOutputFile, "maxiterations %d\n",maxiterations); ! fprintf (paramOutputFile, "minexcess %f\n",minexcess); ! fprintf (paramOutputFile, "eta %f\n",eta); ! fprintf (paramOutputFile, "etamax %f\n",etamax); ! fprintf (paramOutputFile, "etamin %f\n",etamin); ! fprintf (paramOutputFile, "rea %f\n",rea); ! fprintf (paramOutputFile, "reb %f\n",reb); ! ! fprintf (paramOutputFile, "randomSeed %d\n",seed); ! ! fprintf (paramOutputFile, "tauv %f\n",tauv); ! fprintf (paramOutputFile, "lambda %f\n",lambda); ! fprintf (paramOutputFile, "maxbid %f\n",maxbid); ! fprintf (paramOutputFile, "initvar %f\n",initvar); ! fprintf (paramOutputFile, "maxdev %f\n",maxdev); ! fprintf (paramOutputFile, "@end\n"); - fclose(paramOutputFile); ! return self; } ! - prepareOutputFile ! { ! char outputFile[256]; ! int i; ! ! if(!runTime) ! runTime = time(NULL); ! ! strcpy (outputFile,"output.data"); ! strcat (outputFile," "); ! ! strcat (outputFile,ctime (&runTime)); ! for (i = 0; i < 256; i++) ! { ! if (outputFile[i] == ' ' || outputFile[i] == ':') ! outputFile[i] = '_'; ! else if (outputFile[i] == '\n') ! outputFile[i] = '\0'; ! } ! ! if(!(dataOutputFile = fopen(outputFile,"w"))) ! abort(); ! fprintf (dataOutputFile, "currentTime\t price\t\t dividend\t volume\n\n"); ! return self; } - -writeData - { - fprintf (dataOutputFile, "%10ld\t %5f\t %8f\t %f\n", - getCurrentTime (), - [outputWorld getPrice], - [outputWorld getDividend], - [outputSpecialist getVolume]); - - return self; - } @end --- 4,208 ---- @implementation Output ! - createEnd { ! int i; ! ! char paramFileName[100]; ! char dataArchiveName[100]; ! char hdfEZGraphName[100]; ! if(!runTime) ! runTime = time(NULL); ! dataFileExists = NO; ! ! strcpy (timeString, ctime(&runTime)); ! for (i = 0; i < 100; i++) ! { ! if (timeString[i] == ' ' || timeString[i] == ':') ! timeString[i] = '_'; ! else if (timeString[i] == '\n') ! timeString[i] = '\0'; ! } ! if (swarmGUIMode == 1) ! strcpy (paramFileName,"guiSettings"); ! else ! strcpy (paramFileName,"batchSettings"); ! ! strcat (paramFileName, timeString); ! ! ! strcpy (dataArchiveName,"swarmDataArchive"); ! strcat (dataArchiveName, timeString); ! ! strcpy (hdfEZGraphName,"hdfGraph"); ! strcat (hdfEZGraphName, timeString); ! strcat (hdfEZGraphName, ".hdf"); ! ! #ifdef NO_LISP ! strcat (paramFileName,".hdf"); ! strcat (dataArchiveName,".hdf"); ! #else ! strcat (paramFileName,".scm"); ! strcat (dataArchiveName,".scm"); ! #endif ! ! #ifdef NO_LISP ! archiver = [HDF5Archiver create: [self getZone] setPath: paramFileName]; ! dataArchiver = [HDF5Archiver create: [self getZone] setPath: dataArchiveName]; ! #else ! //unlink ("settingsSaved.scm"); ! archiver = [LispArchiver create: [self getZone] setPath: paramFileName]; ! //unlink ("settingsSaved.scm"); ! dataArchiver = [LispArchiver create: [self getZone] setPath: dataArchiveName]; ! ! #endif ! ! { ! hdf5container = [HDF5 createBegin: [self getZone]]; ! [hdf5container setWriteFlag: YES]; ! [hdf5container setName: hdfEZGraphName]; ! hdf5container = [hdf5container createEnd]; ! ! hdfWriter = [EZGraph create: [self getZone] ! setHDF5Container: hdf5container ! setPrefix: "market"]; ! } return self; } ! - setSpecialist: (Specialist *)theSpec { ! outputSpecialist = theSpec; ! [hdfWriter createSequence: "volume" ! withFeedFrom: outputSpecialist ! andSelector: M(getVolume)]; return self; } ! - setWorld: (World *)theWorld; { ! outputWorld = theWorld; ! ! [hdfWriter createSequence: "price" ! withFeedFrom: outputWorld ! andSelector: M(getPrice)]; ! [hdfWriter createSequence: "dividend" ! withFeedFrom: outputWorld ! andSelector: M(getDividend)]; return self; } ! - writeParams: modelParam BFAgent: bfParms Time: (long int) t { ! char modelKey[20]; ! char paramKey[20]; ! ! sprintf (modelKey, "modelParams%ld",t); ! sprintf (paramKey, "bfParams%ld",t); ! ! [archiver putShallow: modelKey object: modelParam]; ! #ifndef NO_LISP ! [archiver sync]; ! #endif ! [archiver putShallow: paramKey object: bfParms]; ! #ifndef NO_LISP ! [archiver sync]; ! #endif ! return self; } ! //Setup the output file. ! - prepareOutputFile { ! char outputFile[256]; + if (dataFileExists == YES) return self; ! else{ ! ! strcpy (outputFile,"output.data"); ! strcat (outputFile, timeString); ! ! if(!(dataOutputFile = fopen(outputFile,"w"))) ! abort(); ! fprintf (dataOutputFile, "currentTime\t price\t\t dividend\t volume\n\n"); ! dataFileExists = YES; ! } return self; } ! -writeData { + long t = getCurrentTime(); + char worldName[50]; + char specName[50]; ! //**** I've got 3 ways to write out numerical results. *****// ! //**** Choose what you like ****// ! // First, just dump out the raw numbers in text. ! // This is the old standby! ! fprintf (dataOutputFile, "%10ld\t %5f\t %8f\t %f\n", ! t, ! [outputWorld getPrice], ! [outputWorld getDividend], ! [outputSpecialist getVolume]); ! // Second, dump those same values out to an hdf5 format file. This ! // uses the Archiver library "put shallow" to dump all primitive ! // types, ints and doubles mainly. ! ! sprintf (worldName, "world%ld",t); ! sprintf (specName, "specialist%ld",t); ! ! [dataArchiver putShallow: worldName object: outputWorld]; ! #ifndef NO_LISP ! [dataArchiver sync]; ! #endif ! ! [dataArchiver putShallow: specName object: outputSpecialist]; ! #ifndef NO_LISP ! [archiver sync]; ! #endif ! // Third, now use the EZGraph dump of its time strings. ! [hdfWriter step]; ! ! return self; } ! -(void) drop ! { ! [hdfWriter drop]; ! [archiver drop]; ! [dataArchiver drop]; ! [super drop]; } @end Only in ASM-20011125/: Parameters.h Only in ASM-20011125/: Parameters.m diff -cr ASM-20000602/README ASM-20011125/README *** ASM-20000602/README Fri Jun 2 11:03:37 2000 --- ASM-20011125/README Wed Oct 24 18:26:08 2001 *************** *** 9,18 **** randomSeed of your own. ! ASM 20000602 June 2, 2000 Thorough workover of BFagent class, creating three new classes (BitVector, BFParams, and BFCast) and a massive reorganization of BFagent itself. See long comment in BFagent.m. -------original readme follows This is the port to Swarm of the original NeXTstep version of --- 9,147 ---- randomSeed of your own. ! SNAP2: ASM 20000602 June 2, 2000 Thorough workover of BFagent class, creating three new classes (BitVector, BFParams, and BFCast) and a massive reorganization of BFagent itself. See long comment in BFagent.m. + + SNAP3: ASM 20011024 October 2001 + + The aim has been to bring this model into convenient Swarm standards. + Actually, the real aim has been to make ASM an effective teaching + tool and an example of good simulation coding practice. + Part of that is a modernization of the data handling, both the + input of parameter values, and record keeping of parameter values, as + well as the saving of data. One of my pet peeves about Swarm is that + we do not have a standard, idiot proof way to keep records on the + settings and results are for a particular run. We also don't have + fool proof ways to interate models and run simulations over again. + The first problem is dealt with here in the Output class, and the + second one is dealt with by the creation of a Parameter class, where + we could manage command line parameters if we wanted to. + + 1. Inputting Parameter Values. + + First, note the big parameter input file "asm.scm". This has the + initial values for three classes, bfParams, asmModelParms, and + asmBatchParams. This data is "called" to create the classes, you have + to stare at it a while to get used to it. Where we used to have the + createBegin/createEnd routine for a class, now we've got this + different thing that creates a class and initializes its ivars for us, + like so + + asmModelParams =[lispAppArchiver getWithZone: self key: "asmModelParams"]) + + The asmModelParms class is a new parameter-holding/setting class for + the values of the model level. The BFParams class is parameters used + by the BFAgents. + + The advantage of putting these parameter settings in separate files is + that those files can be edited and the model re-run without + recompiling the program. I've never seen a working example, but it + seems logical enough a person could write a program to pump out an + .scm file, then run the model, then write the .scm file, run the + model, etc. + + It is more within my background, instead, to pass command line + arguments to the model in order to vary parameters or get runs with + different seeds. That's why I've introduced a Parameters class, which + can handle both command line arguments and it also orchestrates the + creation of objects for BFParams and ASMModelParams. If we ever wanted + to set command line parameters with this model, we would do it here. + + Both BFParams and the ASMModelParams classes are created in the + Parameters class, and are then passed to the ASMObserverSwarm, and + then into model swarm. I did this to keep the user interface + consistent with the original ASM-Swarm model. + + 2. Outputting Results. + + I've done my best to consolidate and simplify all data writing into + the Output class. Simply put, nothing should get written unless Output + handles it. + + To show the possible data output tools, I have 3 + different ways of saving the output time streams from the model. All + three should be similar/equivalent representations of the numbers. + + 1) Text output of data streams. + 2) HDF5 or LISP format output of object dumps from a "putShallow" + call to a data archiver object. This dumps full snapshots of + the world and the specialist into a LISP on hdf5 archive. + 3) HDF5 output EZGraph which writes one vector per plotted line + into an hdf5 file. + + This code has a preprocessor flag to control the behavior of data + storage. If compile without any CPP flags, then the data files are + saved in the .scm format, which is "scheme". Otherwise, use the flag + NO_LISP, and it uses hdf5 format. In Swarm, that means you type the + make command: + + make EXTRACPPFLAGS=-DNO_LISP + + The buttons in the ASMObserverSwarm display turn on data saving. Look + for "writeSimulationParams" and the other "toggleDataWrite". These + were in the original ASM Swarm model, but I've replaced the + functionality with the newer storage methods. The data is saved only + if you turn on the writeData option. If "toggleDataWrite" is empty or + false, hit that button and it shows "true". When the model runs, + output will be created. If you run the program in batch mode, it + automatically turns on the data writing. + + Please note that if you want the simulation to save your parameter + values to a file, you can click the GUI button + "writeSimulationParams." If you push that button, the system writes + the parameter values into a file, such as + + guiSettingsThu_Jun_28_23_48_00_2001.scm + + if you did not compile with the NO_LISP flag. Otherwise you get a + .hdf file. One key change from the old ASM is that you can push that + button at time 0, and it will save a snap at that time, and any time + you stop the model, you can change parameters and punch the button + again, and it will also save a snapshot at quit time. I believe this + works fine now, but it was a little tricky making sure the objects are + created in the right order and early enough to allow this to work. + + Now, just a word about data formatting. Because it is familiar and + compatible with existing programs, I often prefer to save data in raw + ASCII format. In case you want text output, this shows you how to do it. + I think filenames that have the date in them are good to + help remember when they were originally created, for example. It + creates an ASCII file, for example, + + output.data_Thu_Jun_28_23_48_00_2001 + + However, I understand the reasons others are pushing to use more + refined formats. Many people are digging into hdf5 format for data + storage, and I've taken a look at that too. I took the easy road and + just dumped the whole world and specialist class with swarm's + archiver. It seems to work great?! The output file is called + something like + + swarmDataArchiveFri_Jun_29_16_29_25_2001.hdf + or + swarmDataArchiveFri_Jun_29_16_22_59_2001.scm + + You note here that output uses the current time and date to write the + output file names. Today I ran an example and ended up with these + three files of output: + + output.dataWed_Oct_24_11_30_18_2001 + swarmDataArchiveWed_Oct_24_11_30_18_2001.scm + hdfGraphWed_Oct_24_11_30_18_2001.hdf + + -------original readme follows This is the port to Swarm of the original NeXTstep version of diff -cr ASM-20000602/Specialist.h ASM-20011125/Specialist.h *** ASM-20000602/Specialist.h Mon Apr 24 20:25:07 2000 --- ASM-20011125/Specialist.h Wed Oct 24 18:26:08 2001 *************** *** 1,4 **** ! #import //Specialist is a SwarmObject #import "World.h" @class Agent; --- 1,4 ---- ! //#import //Specialist is a SwarmObject #import "World.h" @class Agent; *************** *** 17,47 **** double minprice; double eta; double etainitial; - double etamax; - double etamin; - double ldelpmax; double minexcess; double rea; double reb; double bidfrac; double offerfrac; int maxiterations; - int varcount; - SpecialistType sptype; id agentList; - World * worldForSpec; - - double bidtotal; - double offertotal; double volume; - double oldbidtotal; - double oldoffertotal; - double oldvolume; - - double price; - double taup; double taupdecay; double taupnew; } // Methods to set parameters --- 17,35 ---- double minprice; double eta; double etainitial; double minexcess; double rea; double reb; double bidfrac; double offerfrac; int maxiterations; id agentList; double volume; double taupdecay; double taupnew; + @private + World * worldForSpec; + SpecialistType sptype; } // Methods to set parameters *************** *** 54,65 **** -setMaxIterations: (int)someIterations; -setMinExcess: (double)minimumExcess; -setETA: (double)ETA; ! -setETAmin: (double)ETAmin; ! -setETAmax: (double)ETAmax; -setREA: (double)REA; -setREB: (double)REB; ! -init; -(double)performTrading; -(double)getVolume; -completeTrades; --- 42,52 ---- -setMaxIterations: (int)someIterations; -setMinExcess: (double)minimumExcess; -setETA: (double)ETA; ! -setREA: (double)REA; -setREB: (double)REB; ! -(double)performTrading; -(double)getVolume; -completeTrades; diff -cr ASM-20000602/Specialist.m ASM-20011125/Specialist.m *** ASM-20000602/Specialist.m Mon Apr 24 20:25:07 2000 --- ASM-20011125/Specialist.m Tue Oct 23 15:57:48 2001 *************** *** 62,68 **** -setTaup: (double)aTaup { ! taup = aTaup; return self; } --- 62,69 ---- -setTaup: (double)aTaup { ! taupnew = -expm1(-1.0/aTaup); //pj: moved here from init method ! taupdecay = 1.0 - taupnew; // moved to simplify! return self; } *************** *** 71,78 **** { if(i != 0 && i != 1 && i != 2) { ! printf("The specialist type chosen is invalid. Only 0, 1, or 2 are ! acceptable. The Specialist will be set to Slope (i.e., 1)."); i = 1; } sptype = (SpecialistType)i; --- 72,78 ---- { if(i != 0 && i != 1 && i != 2) { ! printf("The specialist type chosen is invalid. Only 0, 1, or 2 are acceptable. The Specialist will be set to Slope (i.e., 1)."); i = 1; } sptype = (SpecialistType)i; *************** *** 101,121 **** return self; } - - -setETAmin: (double)ETAmin - { - etamin = ETAmin; - return self; - } - - - -setETAmax: (double)ETAmax - { - etamax = ETAmax; - return self; - } - - -setREA: (double)REA { rea = REA; --- 101,106 ---- *************** *** 129,149 **** return self; } ! ! -init ! { ! /* construct constants and initial values */ ! bidtotal = 0.0; ! offertotal = 0.0; ! volume = 0.0; ! oldbidtotal = 0; ! oldoffertotal = 0; ! oldvolume = 0.0; ! taupnew = -expm1(-1.0/taup); ! taupdecay = 1.0 - taupnew; ! ! return self; ! } -(double)performTrading --- 114,122 ---- return self; } ! //pj: init method is now unnecessary. Moved IVARS inside methods, or ! //reset values when needed. ! // -init -(double)performTrading *************** *** 164,177 **** double demand, slope, imbalance, dividend; double slopetotal = 0.0; double trialprice = 0.0; ! ! id agent; ! id index; // Save previous values ! oldbidtotal = bidtotal; ! oldoffertotal = offertotal; ! oldvolume = volume; dividend = [worldForSpec getDividend]; // Main loop on {set price, get demand} --- 137,153 ---- double demand, slope, imbalance, dividend; double slopetotal = 0.0; double trialprice = 0.0; ! double offertotal = 0.0; //was IVAR ! double bidtotal = 0.0; //was IVAR ! ! id agent; id index; ! ! volume = 0.0; // Save previous values ! //oldbidtotal = bidtotal; //pj: old variables were never used anywhere ! //oldoffertotal = offertotal; ! //oldvolume = volume; dividend = [worldForSpec getDividend]; // Main loop on {set price, get demand} *************** *** 280,285 **** --- 256,263 ---- Agent * agent; id index; double bfp, ofp, tp, profitperunit; + double price = 0.0; //pj: was IVAR + price = [worldForSpec getPrice]; profitperunit = [worldForSpec getProfitPerUnit]; diff -cr ASM-20000602/World.m ASM-20011125/World.m *** ASM-20000602/World.m Tue May 30 14:48:08 2000 --- ASM-20011125/World.m Wed Oct 24 18:26:08 2001 *************** *** 117,123 **** // 3. The NAMES documentation file -- do "market -n > NAMES". //pj: ! //convenience macros to replace stuff from ASM random with Swarm random stuff #define drand() [uniformDblRand getDoubleSample] #define urand() [uniformDblRand getDoubleWithMin: -1 withMax: 1] --- 117,123 ---- // 3. The NAMES documentation file -- do "market -n > NAMES". //pj: ! // These are convenience macros to replace stuff from ASM random with Swarm random stuff #define drand() [uniformDblRand getDoubleSample] #define urand() [uniformDblRand getDoubleWithMin: -1 withMax: 1] *************** *** 420,427 **** return self; } - - -setPrice: (double)p /* * Sets the current price to p. Also computes profitperunit and * returnration. --- 420,425 ---- *************** *** 429,434 **** --- 427,435 ---- * effective benefit of encapsulation with the simplicity of use of * a global variable. */ + + -setPrice: (double)p + { if (price != savedprice) printf("Price was changed illegally"); *************** *** 491,497 **** } ! -updateWorld /* * Updates the history records, moving averages, and world bits to * reflect the current price and dividend. Note that this is called --- 492,498 ---- } ! /* * Updates the history records, moving averages, and world bits to * reflect the current price and dividend. Note that this is called *************** *** 504,509 **** --- 505,511 ---- * could be argued that it should be the one before, to match price. * For the p*r/d bits we do use the old one. */ + -updateWorld { register int i; int r, rago; diff -cr ASM-20000602/asm.scm ASM-20011125/asm.scm *** ASM-20000602/asm.scm Wed May 31 14:01:16 2000 --- ASM-20011125/asm.scm Thu Feb 8 17:09:07 2001 *************** *** 39,45 **** #:npoolmax -1 #:nnewmax -1 #:ncondmax -1 ! ))) --- 39,118 ---- #:npoolmax -1 #:nnewmax -1 #:ncondmax -1 ! )) ! (cons 'asmModelParams ! (make-instance 'ASMModelParams ! #:numBFagents 30 ! #:initholding 1D0 ! #:initialcash 10000D0 ! #:minholding 0D0 ! #:mincash 0D0 ! #:intrate 0.1D0 ! #:baseline 10D0 ! #:mindividend 0.00005D0 ! #:maxdividend 100D0 ! #:amplitude 0.14178D0 ! #:period 1.0 ! #:maxprice 500D0 ! #:minprice 0.001D0 ! #:taup 50.0D0 ! #:sptype 2 ! #:maxiterations 10 ! #:minexcess 0.01 ! #:eta 0.0005D0 ! #:etamax 0.05D0 ! #:etamin 0.00001D0 ! #:rea 9.0D0 ! #:reb 2.0D0 ! #:randomSeed 0 ! #:tauv 50.0D0 ! #:lambda 0.3D0 ! #:maxbid 10.0D0 ! #:initvar 0.4000212D0 ! #:maxdev 100D0 ! #:exponentialMAs 1 ! )) ! ! ! (cons 'asmBatchParams ! (make-instance 'ASMModelParams ! #:numBFagents 30 ! #:initholding 1F0 ! #:initialcash 10000D0 ! #:minholding 0D0 ! #:mincash 0D0 ! #:intrate 0.1D0 ! #:baseline 10D0 ! #:mindividend 0.00005D0 ! #:maxdividend 100D0 ! #:amplitude 0.14178D0 ! #:period 1.0 ! #:maxprice 500D0 ! #:minprice 0.001D0 ! #:taup 50.0D0 ! #:sptype 2 ! #:maxiterations 10 ! #:minexcess 0.01 ! #:eta 0.0005D0 ! #:etamax 0.05D0 ! #:etamin 0.00001D0 ! #:rea 9.0D0 ! #:reb 2.0D0 ! #:randomSeed 0 ! #:tauv 50.0D0 ! #:lambda 0.3D0 ! #:maxbid 10.0D0 ! #:initvar 0.4000212D0 ! #:maxdev 100D0 ! #:exponentialMAs 1 ! )) ! ! (cons 'asmBatchSwarm ! (make-instance 'ASMBatchSwarm ! #:loggingFrequency 1 ! #:experimentDuration 500 ! )) ! ) diff -cr ASM-20000602/main.m ASM-20011125/main.m *** ASM-20000602/main.m Mon Apr 24 20:25:07 2000 --- ASM-20011125/main.m Wed Oct 24 18:26:08 2001 *************** *** 1,6 **** --- 1,7 ---- #import #import "ASMObserverSwarm.h" #import "ASMBatchSwarm.h" + #import "Parameters.h" // The main() function is the top-level place where everything starts. // For a typical Swarm simulation, in main() you create a toplevel *************** *** 11,33 **** { id theTopLevelSwarm; // Swarm initialization: all Swarm apps must call this first. ! initSwarm (argc, argv); if(swarmGUIMode == 1) theTopLevelSwarm = [ASMObserverSwarm create: globalZone]; else ! theTopLevelSwarm = [ASMBatchSwarm create: globalZone]; ! [theTopLevelSwarm buildObjects]; [theTopLevelSwarm buildActions]; ! [theTopLevelSwarm activateIn: nil]; ! [theTopLevelSwarm go]; ! ! if(([[theTopLevelSwarm getActivity] getStatus] == Completed) && swarmGUIMode == 1) ! if([theTopLevelSwarm ifParamWrite]) ! [theTopLevelSwarm expostParamWrite]; ! // The toplevel swarm has finished processing, so it's time to quit. return 0; } --- 12,49 ---- { id theTopLevelSwarm; + + // Swarm initialization: all Swarm apps must call this first. ! initSwarmArguments (argc, argv, [Parameters class]); ! ! arguments= [(Parameters *) arguments init]; ! if(swarmGUIMode == 1) theTopLevelSwarm = [ASMObserverSwarm create: globalZone]; else ! // theTopLevelSwarm = [ASMBatchSwarm create: globalZone]; ! ! if ((theTopLevelSwarm = ! [lispAppArchiver getWithZone: globalZone key: "asmBatchSwarm"]) == nil) ! raiseEvent(InvalidOperation, ! "Can't find the batchSwarm parameters"); ! ! [theTopLevelSwarm buildObjects]; [theTopLevelSwarm buildActions]; ! ! // while (1) ! { ! id activity = [theTopLevelSwarm activateIn: nil]; ! [theTopLevelSwarm go]; ! [activity drop]; ! if (swarmGUIMode == 0) ! [theTopLevelSwarm expostParamWrite]; ! [theTopLevelSwarm drop]; ! //if ( [[theTopLevelSwarm getControlPanel] setStateQuit] ) break; ! } // The toplevel swarm has finished processing, so it's time to quit. return 0; } Only in ASM-20000602: param.data