Sharks and Fish

Sharks and Fish

This problem basically involves a simulation of "particles" moving around and interacting subject to certain rules, which are not entirely physical but instructive and amusing. Also, this problem can be stated in different forms (see below), some are discrete (the sharks and fish can only occupy a discrete set of positions), and some are continuous (the sharks and fish can be anywhere).

There is a set of rules to follow in all forms of the problem:

  1. Sharks and fish live in a 2D ocean, moving, breeding, eating and dying.

  2. The ocean is square and periodic, so fish swimming out to the left reenter at the right, and so on.

  3. The ocean may either be discrete, where sharks and fish are constrained to move from one grid point to a neighboring grid point, or the ocean may be continuous.

  4. In all cases, the sharks and fish move according to a "force law" which may be written as:

     force on a shark (or fish) = force_External (a current, felt
                                     independently by each shark or fish,
                                     including a random component)
                                      +
                                  force_Nearest_Neighbors 
                                     (sharks are strongly attracted by
                                      nearby fish)
                                      +
                                  force_"Gravity"
                                     (sharks are attracted to fish, and
                                      fish repelled by sharks)
    

  5. These three kind of forces can be parallelized in different ways: The external force can be computed independently for each fish, and will be the easiest force to parallelize. Forces which only depend on the nearest neighbors, or very close neighbors, require relatively little cooperation between processors and are next easiest to parallelize. Forces which depend on all other fish, like gravity, would require smart algorithms to compute efficiently (in parallel or serial).

  6. Fish and Sharks breed if old enough.

  7. A shark eats any fish it "collides" with, and dies if it does not eat for too long.

Here are few forms or different instances of the Sharks and Fish problem.


Form 1


Form 2 (aka The Game of Life)


Form 3