Understanding the Existing Program

My next step was to meet with Jamie, an experienced programmer who developed the initial version of the program (and the two demos). Jamie helped me understand how the biologists were using the program, as well as how the program worked inside.

The Big Picture

For modeling purposes, the biologists think of the environment as a rectangular grid, with fish moving from cell to cell in the grid. Each cell contains zero or one fish.

Illustration of fish in grid

A simulation is often represented as a series of repeated timesteps. In this case, in each timestep every fish has an opportunity to move to one of its immediately adjoining neighbors, but only if the neighboring cell is empty. Confirming my earlier conclusions, Jamie told me that fish in this simulation only move forward and to the side; they never move backward. Thus, the fish in row 3 and column 2 (also known as location (3, 2)) in the illustration above has two neighboring locations to which it could move, the one in front of it and the one to its right (locations (3, 3) and (4, 2)). The fish in location (4, 8) has one location to which it could move, the one to its left.

One of the purposes of the simulation is to help the biologists understand how fish movement is affected by the size and density of the fish population. To do this, they run the simulation many times with different initial fish configurations. The program reads a file that specifies the size of the environment, the number of fish, and their starting locations. By changing the file read in by the program, the biologists can run the simulation with different initial conditions and see what happens.

The Design

As I had discovered when looking at SimpleMBSDemo1 and SimpleMBSDemo2, to model fish swimming in a bounded environment, the Marine Biology Simulation program has Fish objects and an environment object modeled as a BoundedGrid. The purpose of the program is to simulate fish moving in the environment, so SimpleMBSDemo2 also has a Simulation object.

The program also has classes to implement its graphical user interface, but I was not going to be modifying that, so we didn't spend much time talking about those.

In each timestep in the simulation, each fish has the opportunity to move to an adjoining location in the grid. This leads to a number of design questions. Who is responsible for keeping track of the fish in the environment? Who is responsible for knowing where a fish may move? Who is responsible for actually moving a fish? Who is responsible for knowing what behavior (moving, aging, breeding, dying, etc.) is required as part of the simulation? Jamie had considered several options and decided on the following design.

As I learned, the Marine Biology Simulation has more than four classes, but these four — the driver, Simulation, BoundedGrid, and Fish — constitute the conceptual core of the design.



Alyce Brady, Kalamazoo College