Citizen class documentation

Authors

Generated by pauljohn

Contents -

  1. Software documentation for the Citizen class
  2. Citizen variables
  3. Citizen functions

Software documentation for the Citizen class

Citizen : Swarm

Declared in:
Citizen.h

The Citizen is the root agent in this model. This class has the key record-keeping and scheduling role.

We do not ever intend that this class should be instantiated. Rather, subclasses which implement particular theories should be written and used in the models. The Citizen class contains general purpose variables and methods that we exect all subclasses are likely to need.

Subclassing Guide For starters, we suggest you allow Citizen's step method to work as it is. If you allow step to be called, it will control movement and will tell the agent to interact. The interact method will cause the agent to find someone and discuss with them. In order for this to function, it is necessary for a subclass to override these two methods:

- selectADiscussantInPosition: (Position *)position;

- adjustOpinionAgainst: other;

There are a number of class variables and class methods. Class variables save on storage because one value is set and used by all agents. The Class methods are the ones that begin with plus signs. There are a number of advantages in using Class methods and variables in the serialization part of this program. Class values need not be serialized, rather they are easily set at runtime.

Each Citizen has personal stances or opinions that we are calling "culture" in honor of Robert Axelrod. Original versions of this model benefitted greatly from the assistance of Rick Riolo of the University of Michigan and Lars Erik Cederman of UCLA.

The culture is kept in an integer array. The number of opinions is set by the numCultureFeatures parameter. The number of positions that exist for each issue is set by the numCultureTraits parameter. Every citizen holds some position on each issue at all times. The initial positions are assigned by code in the ModelSwarm. Typically, opinions are randomly assigned.

Each citizen is aware of various "positions" (2D grids) in which it can interact. One position is the home grid, another is the work grid. To allow the possibility that a model might have agents with many positions they would visit, we have put all positions into a Swarm Array, positions.

The Citizen class has vital record keeping tools, including the moving averages that summarize the experiences of the agents. These keep track of the rate of acquaintance among agents, the rate of similarity, and identicality (a word?).

Citizen also has machinery to schedule agent actions and move agents around.

We expect that subclasses will handle the problems of choosing discussants, and responding to the interaction. Some methods are included in this class to keep track of experiences/observations, and they can be used in subclasses.

The one method that is vital for any sublcass is "interact". In the root class Citizen, this is the method that chooses a discussant and then responds to the interaction. Since interact calls both the "selectADiscussantInPosition" and "adjustOpinionAgainst:" methods, then the subclass must either override interact or it must do something about selecting discussants and responding to them. Note the subclass HJCitizen is mainly about choosing discussants differently and responding to them strategically. Not that this class has code in it that mandates that a subclass must implement these last two methods.


Instance Variables

Method summary

getNumCultureFeatures 

+ (int) getNumCultureFeatures;

Returns the number of issues/features that this class is using.


getNumCultureTraits 

+ (int) getNumCultureTraits;

Returns the number of opinions (traits) that the agents might hold for each issue/feature


getObserverSwarm 

+ (id) getObserverSwarm;

Return the observerSwarm that objects of type Citizen are using


setConsistentAdjustment: 

+ (id) setConsistentAdjustment: (BOOL)o;

Set the consistentAdjustment parameter


setDayLength: 

+ (id) setDayLength: (int)d;

The dayLength is the number of timesteps that are considered as a separate time frame for the agent. The day begins at home and the agent should return there at the end of the day


setModelSwarm: 

+ (void) setModelSwarm: (id)model;

When agents change their opinions, they tell the centralized record keeper about it. This method tells the agent who the record keeper is.


setNumCultureFeatures: 

+ (void) setNumCultureFeatures: (int)f;

Methods that set/get fixed features common to all citizens (Class Variables)
A class method that sets the number of issues/culture features. All agents are able to access the variable numCultureFeatures.


setNumCultureTraits: 

+ (void) setNumCultureTraits: (int)t;

A class method that sets the number of culture traits. All agents are able to access the variable numCultureTraits.


setObserverSwarm: 

+ (void) setObserverSwarm: (id)observer;

Sometimes it is useful to let the agent know the location of the class that is drawing graphs in the simultion. This does it.


setOnlyOneAdjusts: 

+ (id) setOnlyOneAdjusts: (BOOL)o;

In Axelrod's original model, only one agent could change as a result of interaction. We wanted to generalize a bit, so we created these toggles.


setOnlySelfAdjusts: 

+ (id) setOnlySelfAdjusts: (BOOL)o;

These control adjustment: to self, to other, to both?
Set the YES or NO variable indicating only the agent who initiates the interaction--self--is able to change its opinion in response to the interaction.


setParochialism: 

+ (id) setParochialism: (double)p;

Set the parochialism parameter. This is the probability that an agent will look outside its current cell for a discussion partner. This is relevant only when there is more than one agent in a cell.


setWrapAround: 

+ (id) setWrapAround: (BOOL)w;

Do agents look for discussants within the truncated VonNeumann neighborhood? If yes, then wrapAround is YES. If no, then the grid in the position has to be a torus, and wrapAround is NO


activateIn: 

- (id) activateIn: (id)swarmContext;

If the NO_MASTER_SCHEDULE CPP flag is used, then each agent is a Swarm unto itself, and so it has to create a schedule and activate its schedule within the larger condext. This ties the agent's schedule into the time stepping of the system.


adjustOpinionAgainst: 

- (id) adjustOpinionAgainst: (id)other;

All sublcasses must know how to adjustOpinionAgains: another agent


bareLispOutDeep: 

- (void) bareLispOutDeep: (id)stream;

For serialization, each agent needs to dump out its instance variables, so that the agent can be brought back to life in exactly the same state.


becomeUnavailable 

- (id) becomeUnavailable;

Remove self from locations in which others can reach for interaction


buildActions 

- (id) buildActions;

Create the schedule on which actions can be placed. This is only used if there is no master schedule.


buildObjects 

- (id) buildObjects;

"Initialize Classes that require zone allocations
When a Citizen object is created, several record keeping objects must be created. This method creates those objects.


changeFeature: to: 

- (int) changeFeature: (int)f to: (int)value;

This does two things. It changes the culture feature f to v, and it also reports that change to the record keeper, the ModelSwarm.


computeSimilarityWith: 

- (int) computeSimilarityWith: (int*)otherCulture;

Take a culture array and find out how many elements are the same as agent's own culture, and return that integer value


createAttribute: 

- (Attribute*) createAttribute: (const char*)other;

Create an attribute record for a contact. That means create an object where data about the other can be stored. Also it inserts that Attribute into the contacts map, which agents can use to lookup these attributes.


createEnd 

- (id) createEnd;

Initialize important instance variables
Finalizes the creation of objects from Citizen, and in so doing it sets initial values for a number of start-time variables.


describeInteractionWith: 

- (id) describeInteractionWith: (Citizen*)other;

For diagnostic information about the agent and his discussant


drawColor: 

- (void) drawColor: (int)col;

Sometimes, such as in showContacts, we want agents to be able to signal to us by drawing on the raster. Since the rasters represent only the home positions, this method gets world 0 and draws a color there.


getAgentName 

- (const char*) getAgentName;

Description forthcoming.


getChangeFlag 

- (BOOL) getChangeFlag;

Return YES or NO indicating that the agent has changed an opinion/trait during the current step


getContacts 

- (id) getContacts;

Retrieve/Display information about contacts
Return a Swarm Map of the agents that have been in contact.


getCultureArray 

- (int*) getCultureArray;

Return a pointer to the first element of this agent's culture array


getCultureFeature: 

- (int) getCultureFeature: (int)f;

Return the value of feature f from this agent's culture array


getFeature: 

- (int) getFeature: (int)f;

Return culture feature f


getFlexibility 

- (double) getFlexibility;

Description forthcoming.


getIDNumber 

- (int) getIDNumber;

Return agent's identification number


getInteractionFlag 

- (BOOL) getInteractionFlag;

Returns the flag indicating that the agent interacted with another agent during this period.


getNContacts 

- (int) getNContacts;

Return the number of contacts that have been made


getNFriends 

- (int) getNFriends;

Description forthcoming.


getPerceivedAcquaintance 

- (double) getPerceivedAcquaintance;

Provide information on perceptions
Return the (moving average) perceived likelihood that you have a randomly chosen feature in common with someone you come across


getPerceivedHarmony 

- (double) getPerceivedHarmony;

Return the (moving average) proportion of traits that are the same between this agent and the agent he interacts with


getPerceivedIdentical 

- (double) getPerceivedIdentical;

Return the (moving average) proportion of people agent interacts with who are identical with the agent


goHome 

- (id) goHome;

Move to Position 0, thought of as home.


grabRandomPersonInPosition: Parochialism: 

- (id) grabRandomPersonInPosition: (Position*)position Parochialism: (double)paroch;

Give the agent one of its positions, have it search around for a discussant in there. This method takes into account parochialism, looking within with probability equal to 'paroch'. It may return nil if it does not find someone after looking in all 4 neighboring cells


interact 

- (id) interact;

Here is the key method. The agent is told to find a discussant and then, if one is found, adjust opinion against: the input from the other.


lispInReset 

- (id) lispInReset;

When archived agents are reborn, they don't have all the information they need. We have to tell them to go get their positions from the model swarm, or else they don't ever situate themselves.


moveToOtherPosition 

- (id) moveToOtherPosition;

In a model with only two possible positions per agent, then moveToOtherPosition can be used to move from 1 to 0 or 0 to 1. This method figures out the current position, then moves to the other grid. The value 99 is "out of all positions", a value that is used if a person is simply unavailable for contact from others. Because we want to generalize to models with many different positions possible, this method is deprecated


moveToPosition: 

- (id) moveToPosition: (Position*)position;

Give a position object to the agent. From that position object, the agent can get coordinates where it is supposed to go and put itself there. Like 'go home' tells an agent to go to position 0 at known x,y coordinates. If the agent is currently in a world, it removes itself and goes where it is told


pulseFeature: Magnitude: 

- (int) pulseFeature: (int)f Magnitude: (int)mag;

Suppose we want to investigate the impact of shocks on the model. This one changes feature f by a given magnitude


sayHi 

- (id) sayHi;

Provide diagnostic information (console printouts)
For diagnostic information about this agent, his position, and culture


scheduleAvailablePosition: Start: 

- (id) scheduleAvailablePosition: (Position*)position Start: (int)x;

At future time x, move self to the indicated world


scheduleInteractionTime: 

- (id) scheduleInteractionTime: (int)x;

At time future x, schedule self to initiate an interaction


scheduleMeAgain: 

- (id) scheduleMeAgain: (int)x;

At time x, schedule me for a step method


scheduleSleepAt: 

- (id) scheduleSleepAt: (int)x;

scheduleSleepAt will make the agent unavailable for contacts by others


selectADiscussantInPosition: 

- (id) selectADiscussantInPosition: (Position*)position;

All sublcasses must have rulse for selecting discussants


setAgentName: 

- (void) setAgentName: (char*)aName;

Set a string for the agent's name. Hopefully, it is unique


setChangeFlag: 

- (void) setChangeFlag: (BOOL)aValue;

Set the change flag for the agent. At birth and at the outset of each step, the change flag needs to be set to NO


setFeature: to: 

- (id) setFeature: (int)f to: (int)v;

Set/Get/Adjust information about individual culture features
Set culture feature f to value v. This method is used when agents are created


setFlexibility: 

- (void) setFlexibility: (double)input;

Set citizen flexibility parameter. between 0 and 1


setHomeDuration: 

- (id) setHomeDuration: (int)d;

Set/get values of individual level variables
Determines how long agent stays home each day


setIDnum: 

- (void) setIDnum: (int)num;

An ID number is an integer, unique!


setInteractionFlag: 

- (void) setInteractionFlag: (BOOL)aValue;

Set the interaction flag for the agent. At birth and at the outset of each step, the interaction flag needs to be set to NO


setPosition: GridN: atX: Y: 

- (id) setPosition: (int)w GridN: (int)grid atX: (int)xloc Y: (int)yloc;

Define the agent's locations and movement abilities
The introduction of serialization changed the semantics of the way agents track their locations. Here is one. The variable w indicates whether the values being set apply to a home or work position, and grid indicates which of the grids of that type is being used. The position of the agent in that grid is to be (xloc,yloc). There's some fancy footwork through which the agent then uses these values to retrive a pointer to the grid from the model swarm and then it encapsulates the information into a Position object


setPosition: X: Y: 

- (id) setPosition: (int)w X: (int)x Y: (int)y;

This tells the agents their coordinates in world w. It does not put them there.


setSchedule: 

- (id) setSchedule: (id)sched;

These methods can create agent schedules and place actions on them
For Master schedule models, the agents have to know where to insert actions to schedule themselves


showContacts 

- (int) showContacts;

If the model is run in GUI mode, this method will make contacts appear in white on the rasters


showFriends 

- (int) showFriends;

If the model is run in GUI mode, this method will make friends appear in red on the rasters, and the reds will be shaded by similarity


step 

- (id) step;

Interaction is governed by these methods
This is the central action method. The agent schedules its activities over a 'dayLength' period, beginning at home--positions[0] and then going to another place.


updateAcqRecord: 

- (int) updateAcqRecord: (id)other;

Given the other, check a randomly chosen feature. If we agree on that, then count that as a +1 in the acqMA. If they are not, add a 0. acqMA's value is thus the proportion of meetings that produce agreement


updateAttribute: Total: Selected: 

- (Attribute*) updateAttribute: (Attribute*)aContact Total: (int)similarity Selected: (BOOL)agree;

When agents interact, they gain information about he extent of their similarity. This method records that experience by updating the "attribute record" that the agent has stored. In the root Citizen class, all this does is take the attribute and set the similarity (number of shared features) in it. However, it passes an extra argument, which represents agreement on a randomly selected feature. Some subclasses want that extra info to do the book keeping they want.


updateContactRecord: Feature: Similarity: 

- (BOOL) updateContactRecord: (Citizen*)other Feature: (int)featureToTest Similarity: (int)k;

Citizens keep records on the people that they interact with in a Swarm Map collection. So, if someone is a stranger, then an Attribute object is created and stored for the other. If the other is already known to this citizen, then the attribute information is updated. Subclasses can override or augment this method to make record keeping more or less elaborate


updateSimilarityRecords: 

- (id) updateSimilarityRecords: (int)numCommonFeatures;

For each person that the agent has an interaction with, update the "same" (harmony) and "identical" moving averages.




Instance Variables for Citizen Class

acqMA

@protected id acqMA;

Moving average objects for record keeping


changeFlag

@protected BOOL changeFlag;

Indicates whether agent changed an opinion on the most recent step. Important to reset this to NO at start of new step.


contacts

@protected id contacts;

A map where agent stores recollections in the form of "Attribute" objects. The keys used to nsert and find Attribute objects allow agent to find out if it already knows another agent and check its memory.


culture

@protected int* culture;

Pointer to a dynamically allocated integer array of culture traits


currentPosition

@protected int currentPosition;

integer of current Position in positions[]


flexibility

@protected double flexibility;

in [0,1], parameter governing responsiveness to input. Used variously by different classes


gridNum

@protected int gridNum;

Which home grid does the agent go to? Which work grid does agent go to? These values are kept for serialization purposes. Since this value is saved, the agent can use it to retrieve environment information from ModelSwarm and rebuild its Position records.


homeDuration

@protected int homeDuration;

How many steps does agent stay home at start of day?


idnum

@protected int idnum;

Agent identification number


interactionFlag

@protected BOOL interactionFlag;

Indicates whether agent successfully initiated an interaction on the most recent step. Important to reset this to NO at start of new step


name

@protected char* name;

Character string serving same purpose as idnum"


numFriends

@protected int numFriends;

0 for models that don't have friends, for others a tally of people who are more similar to agent than the friendship threshold


positions

@protected id positions;

Array of Positions where agent might go. position[0] is the home Position. positions[1] is the work Position.


schedule

@protected id schedule;

Swarm schedule where agents place their intended actions to be executed





Citizen variables

consistentAdjustment

BOOL consistentAdjustment;

Description forthcoming.


dayLength

int dayLength;

Description forthcoming.


modelSwarm

id modelSwarm;

Description forthcoming.


numCultureFeatures

int numCultureFeatures;

Description forthcoming.


numCultureTraits

int numCultureTraits;

Description forthcoming.


observerSwarm

id observerSwarm;

Description forthcoming.


onlyOneAdjusts

BOOL onlyOneAdjusts;

Description forthcoming.


onlySelfAdjusts

BOOL onlySelfAdjusts;

Description forthcoming.


parochialism

double parochialism;

Description forthcoming.


pplPerCell

int pplPerCell;

Description forthcoming.


wrapAround

BOOL wrapAround;

Description forthcoming.


Citizen functions

spotCheckFeatureWith

BOOL spotCheckFeatureWith(id other, int* culture);

Description forthcoming.