intro-swarm-model-startup.txt ---------------------------- This describes the basic algorithm followed in the SimpleModel1 model implementation, assuming the model is run in GUI mode. Note the basic order of events is the same for all the models in the ~rlr/SwarmStuff/CSCS-Demos directory, as well as most models implemented using the UM-ExpTools parameter-processing classes. The primary differences between models are in the details of precisely which model objects, which graphs, etc, are created. A typical Swarm model includes these files: main.m The main entry point...all starts and ends here! ObserverSwarm.h / .m The GUI-run swarm: create control panel, probes, graphs, and so on. Create a ModelSwarm, tell it to create its objects, schedule, etc. BatchSwarm.h / .m The non-GUI-run swarm. Create a ModelSwarm, tell it to create its objects, schedule, etc. ModelSwarm.h / .m Swarm that holds pointers to the agent list, the world, and other parts of the "real" model. Also defines the schedule of model activity. Parameters.h / .m Run-time settable parameters. Makefile Used by "make" command. A model will then contain 1 or more additional classes, each defined by a pair of .h/.m files. So for example, for the SimpleModel1 program, there is just one additional class: Agent.h/.m The single type of agent in this program, defining what "memory" each agent has (its instance variables) and what it can be asked to do (its methods, i.e., what messages one can send to it. So, starting from main.m, we basically see create an ObserverSwarm, which also - sets up a probemap for itself - creates the Parameters object tell ObserverSwarm to buildObjects, passing in parameters - creates the ModelSwarm object - tells Parameters object to initialize itself, to process command line arguments. Exchange addresses between ModelSwarm and Parameters and self. - create probe for self and parameters - tell the controlPanel to wait <** user can change things via gui, press start/next **> - tell ModelSwarm to buildObjects - tell Parameters object to start RNG, clock, and report file - create a Shuffler object, link it to a RNG object. - perhaps pass parameter values to the Agent class - create the 2D world, and an agentList - for loop to create Agent instances - creates the specified number - add them to the agentList - randonly place agents in the 2D world After the ModelSwarm is done building model-related objects, the ObserverSwarm continues to setup GUI objects: - create a Colormap, assign names to colors. - create worldRaster, agentDisplay, and setup mouse buttons - - update gui, process events, and wait for user again <** wait for another start/next **> - return Now main.m tells the ObserverSwarm to buildActions...the schedule of activity - tell model to build its action schedule which is basically to send the step message to the ModelSwarm each step. (See below for what happens in the ModelSwarm-step message.) - set up actions to tell all the GUI parts to update themselves each time step tell ObserverSwarm to activitate itself, then "go" (It activates the ModelSwarm under it.) <**now it runs/stops until user presses QUIT**> tell Parameters to close report file ...Done...return from main! ------------------------------------------------- The ModelSwarm-step method is set up to - shuffle the agentList - send the step message to each object on the agentList - send to self (ie ModelSwarm) stepReport, to write line to report file ------------------------------------------------- The Agent step method does this - tell agent to try to make a random move - pick a random neighbor; if there is one, then - play one round of the PD against that neighbor and update each agent's wealth and other IVs.