KH-Model with Movement and Replacement
Winter 2017
Psychology 120
We have a working KH-model that does everything in the original model and, in addition, we can change various parameter values. Before we investigate it systematically, let’s add two features to the KH-model that require a minimal amount of new code: movement and replacement.
For movement, we would like to add the ability of agents to move randomly, aggregate, and coordinate their behavior all without rewriting or copying and pasting the code into new agents. This can be accomplished through the mechanism of inheritance using the special term extends. Using inheritance is straightforward for agents most of the time, but not for Environments that extends SimState. Simply extending an Environment that extends SimState can have some unexpected consequences. What we need is a partially implemented BasicEnvironment, which has the components needed to implement moving agents. Partially implementing a class is somewhat like an abstract class in Java but it is not formally abstraction. To accomplish the goal of adding movement to the KH-Model, you should use the project BasicMovement.zip, which implements agents that can move, aggregate, and coordinate. The project KH-Model.zip contains the basic KH-Model we implemented in class. Your first task will be to use the mechanism of inheritance (using extends) to implement a KH-Model with movement.
You will need to construct a new Agent constructor method that calls super.
public Agent(BasicEnvironment state, int x, int y, int xdir,int ydir, boolean female, double attractivenessA) { super(state,x,y); //Your code here }
You will also need to change the “findDate” method to search for nearby agents as possible dates. To do this, you will need get agents in dateSearchRadius:
Bag dates = state.space.getMooreNeighbors(x, y, searchRadius, mode, false);
Note that include origin is false since we are not allowing self dating. Thus, the modified method “findDate” is just like before except that we get a bag of agents spatially within the date search radius.
Since you have added movement to the KH-model, there is the issue of placing agents in unique locations in the environment. You should go into the Environment and write a new “placeAgent” method that uses the inherited method “place”.
public void placeAgent(boolean female){ //Your code here }
Hint: Look in the BasicEnvironment.
One way in which the KH-model is unrealistic is that there is only a finite population of male and female agents, which all start out with the same dating experience. As they pair off, the population empties out, but is this like real life? No. New people are always entering or re-entering the dating pool, so it would be a step towards a more realistic model to include replacement.
To do this, you will need to add an option for replacement with get and set methods. Next, write a method in Agent creates a new dateable agent of a given gender:
public void replicate (Environment state, boolean gender){ //Your code here }
Hint: It requires only one line of code.
Thus, when a female-male pair is removed from the population, a new male and female are created and placed in the population. A simulation will then run until you stop it.
How to Extend the KH Model to Include Movement & Replacement
Step 1
Download and install these zipped projects:
Use inheritance (with extends) to add movement to the KH-model.
Step 2
You will need to construct a new Agent constructor method that calls super.
public Agent(BasicEnvironment state, int x, int y, int xdir,int ydir, boolean female, double attractivenessA) { super(state,x,y); //Your code here }
Modify “findDate” to search for nearby agents as possible dates. To do this, you will need get agent in dateSearchRadius:
Bag dates = state.space.getMooreNeighbors(x, y, searchRadius, mode, false);
Make sure to add a findLocalDate boolean. You should create a conditional statement using the boolean variable findLocalDate to control whether searches locally in space or the entire populations. Thus if findLocalDate = false, the classic KH-model is simulated.
Step 3
Finally, you need to include male/female replacement into the model. To do this, you will need to add an option for replacement with get and set methods. Next, write a method in Agent creates a new datable agent of a given sex:
public void replicate (Environment state, boolean gender){ //Your code here }
Hint: It requires only one line of code.
You can then modify “findLocalDate” and “findDate” methods by introducing the replicate method into a conditional statement.
if(replacement){ //add your code here //Line #1 for females //Line #2 for males }
Step 4
In the Environment class of the KH-Model, you should remove
SparseGrid2D space;
This is already defined in BasicEnvironment and will create problems is left in.
Preliminary Analysis of the Model
Step 5
Try out different parameters values, record the parameter values and setting together with the resulting correlation values. For both rules do the following:
1. Try at least the following exponentN (i.e. “choosiness”) values: 1, 2, and 3.
2. Try at least the following Maxd (maximum dates at which an agent chooses anything) values: 10, 50, 100, 10,000
3. Try at least the following scaleK (maximum attractiveness) values: 2, 5, 10, 100
4. Try at least the following population sizes (each for males and females) values: 100, 500, 1000, 2000
Step 6
1. With replacement turned on, do you get the same results as in step 4?
2. Now, try random movement. Try randomMovement =1 and randomMovement = 0.01. Is there a difference?
3. You can try coordination (coordinate) and aggregation (aggregate) to see if that makes a difference. Find something interesting to show us!
Step 7
Finally, show us that your model does everything required and tell us about what you found in steps 5 and 6.