Skip to end of metadata
Go to start of metadata

This week's project uses double-linked list to generate the simulation of consumer, producer, and obstacle. I first tested the add, append, and remove methods from the LinkedList class, which has the ability to add, append, and remove from an empty list; add and remove from a list with one item. For a list with multiple items, it has the ability of adding to the beginning and the end of the list, and also the ability of removing from the beginning, the middle, and the end of the list.

In the Landscape class, I created an initialize method which sets the default number of consumers, producers, and obstacles as 800, 200, 50. When the user doesn't specify those as part of the command line arguments, the simulation will run using the default values.   

Then I created three subclasses of the Cell class. The producers produce food for consumers, and the obstacles block the others from moving. 

Consumer class

• isNeighbor uses 12 as its range to get neighbors 

• updateState counts the number of producers and obstacles. The consumer will move +/- 3 when there is no obstacle around, make a new consumer when there are more than 6 producers as its neighbors, and die if there are less than 2 producers around. It also deletes agents when they are off the landscape.   

• draw method draws a blue hungry cell chasing its food 

Producer Class

• isNeighbor uses 12 as its range to get neighbors 

• updateState counts the number of consumers, producers, and obstacles. The producers will move +/- 3 when there is no obstacle around, make a new producer when there are 5 or 6 producers in its neighborhood, and die if there are more than 5 consumers around. It also deletes agents when they are off the landscape.   

• draw method draws a green figure with yellow hat 


Obstacle Class
• isNeighbor uses 15 as its range to get neighbors 

• updateState has an extra parameter type and counts the number of obstacles.

type == 0 : obstacles don't move

type == 1 : the obstacle dies when more than one exists in the neighborhood;  it creates a new obstacle by 1% chance when there is no obstacle in the neighborhood.

• draw method draws a grey halloween ghost 

LandscapeDisplay Class

The LandscapeDisplay runs the simulation with 8 inputs: number of iterations, width and height of the landscape, scale, type of obstacle rule, and numbers of consumers, producers, and Obstacle. If the user doesn't provide the number of agents, the simulation will run with initialized values. 

When type == 0 : the total number of agents 1280 quickly reduces and stabilize to 609 of agents.


When type == 1 : the total number of agents 1350 quickly reduces to 650 and then slowly increases to 676 

When I changed the deletion rule of Producer to detecte the prodder when there are more than five of consumers or less than 2 producers, the total number of consumers and producers decreases a lot.

  

My extensions: create two sets of simulation rules for obstacle, get creative with the visualizations of each agent type, and experiment with different rules.
I got help from Dale to speed up the simulation. I added a filed in the delete method so it wouldn't call index of repeatedly. I also adjusted the addAgent and removeAgent conditions of the Producer. I got help from Tarini, Erin, and Joseph as well.  

Labels