Banner
ABM Lab 2


Freezing Aggregation

Winter 2017

Psychology 120


In this lab, you will build an agent-based model from the beginning to answer the problem in the next section.  Once you completed the model and can answer the question in the problem, show us and you have finished the lab.  There will then be a homework assignment due the following week.

Problem

Suppose agents move randomly (“Brownian motion”) and when they attempt to move to another location that contains a “frozen” agent, they also freeze in their current location (a frozen agent no longer moves).  What will the aggregate of agents look like when they all freeze assuming (1) that one agent in the middle of the space is frozen and (2) all other agents are not frozen at the start of a simulation?

Step 1

Create a new Java project called “freezingAggregation”.  Next, create a package within the src folder.  Put MASON in the project path so that you can use the MASON classes and methods.  Create three files: (1) “Agent” which implements Steppable, (2) “Environment” which extends SimState, and (2) AgentsWithGUI which uses the code below (paste it into the file AgentsWithGUI.java) or copy and paste the file out of a previous project.

package freezingAggregation; 

import sim.engine.*;
import sim.display.*;
import sim.portrayal.grid.*;
import java.awt.*;
import javax.swing.*;
import sim.portrayal.simple.OvalPortrayal2D;

public class AgentsWithGUI extends GUIState {
	public Display2D display;
	public JFrame displayFrame;
	SparseGridPortrayal2D agentsPortrayal = 
			new SparseGridPortrayal2D();

	public static void main(String[] args) {
		AgentsWithGUI ex = new AgentsWithGUI();
		Console c = new Console(ex);
		c.setVisible(true);
		System.out.println("Start Simulation");
	}

	public AgentsWithGUI() {
		super(new Environment(System.currentTimeMillis()));
	}

	public void quit() {
		super.quit(); 

		if (displayFrame!=null) displayFrame.dispose();
		displayFrame = null;
		display = null;
	}

	public void start() {
		super.start();
		setupPortrayals();
	}

	public void load(SimState state) {
		super.load(state);
		setupPortrayals();
	}

	public void setupPortrayals() {
		Environment se = (Environment)state;
		agentsPortrayal.setField(se.space);
		OvalPortrayal2D o = new OvalPortrayal2D(Color.red);
		agentsPortrayal.setPortrayalForAll(o);
		display.reset();
		display.repaint();
	}

	public void init(Controller c){
		super.init(c);
		display = new Display2D(400,400,this);
		displayFrame = display.createFrame();
		c.registerFrame(displayFrame);
		displayFrame.setVisible(true);
		display.setBackdrop(Color.WHITE);
		display.attach(agentsPortrayal,"Agents");
	}

	public Object getSimulationInspectedObject() {
		return state;
	}
}

Step 2

In the Agent class, create a method that implements the following aggregation rule in pseudocode:

If(Not in contact with a frozen agent)
    move randomly
else
   freeze forever

To implement this rule, write a method of the form:

	public void moveTillFrozen(SimState state){
		
	}

You probably want to have at least the following variables in your Agent class:

	int x;
	int y;
	int dirx;
	int diry;
	boolean frozen;

(1) Include an option for agents to move in a bounded space or toroidal space.

(2) Include and option to prohibit two or more agents from occupying the same location at the same time.

Step 3

Initial Conditions:

(1) In the Environment class, create n Agents, place them randomly in space, and

(2) place the n + 1 Agent in the middle of the space.  Set frozen = false for the randomly placed agents (at the time they are created)

Step 4

Create getters and setters for the relevant parameters.

Run your program, debug it.

Show us that your program works as specified and you are done.

 

Homework

Take the program you have written home and do the following:

(1) There are two parameters that can be varied (assuming a square space), spatial dimensions (gridWidth x gridHeight, e.g., 50 x 50, 100 x 100, 200 x 200) and population size n (e.g., 100, 1000, 5,000).  Do the results vary with different combinations of spatial dimensions and populations size?

(2) Does a bounded space change the results?

(3) Does prohibiting two or more agents from occupying the same location at the same time alter the results?

Answers these questions in a few sentences and illustrate your answers with snapshots from your simulations.  Send your results to me (jcschank@ucdavis.edu) and Jay (jpjeff@ucdavis.edu) by February 17.