Assignments | Class Photo | Course Home | Lab Hours/Tutoring | MATLAB info | Schedule | Submit

Saint Louis University

Computer Science 145
Scientific Programming

Michael Goldwasser

Spring 2009

Dept. of Math & Computer Science

Assignment 09

Flood Levels


Contents:


Overview

Topic: Flood Levels
Related Reading: notes about finding connected components in an array
Due: Monday, 27 April 2009, 11:59pm


Collaboration Policy

For this assignment, you are allowed to work with one other student if you wish. If any student wishes to have a partner but has not been able to locate one, please let the instructor know so that we can match up partners. One member of the partnership should submit the final script, making sure that all members' names are included as part of comments at the beginning of the file.

Please make sure you adhere to the policies on academic integrity in this regard.


Overview

Our goal for this assignment is to write a program that simulates the rising and falling water levels over a fixed terrain. We will represent the terrain as a two-dimensional array of numbers, representing the height of the terrain at each point. As a simple example, the array

7 2 5
3 4 1
represents the terrain shown in the following figure.

We then consider what happens when a terrain is surrounded by water with a given sea level. If the water level gets strictly greater than the terrain level at the boundary, the water will flood that portion of the terrain, as well as any neighboring terrain locations that are strictly below that water level. For example, if the above terrain were surrounded by a water level of 5, we would find associated water depths of

0 3 0
2 1 4
as diagrammed in the following figure.

However, it is not simply that all smaller terrain values get covered by water. As an example, consider the terrain

3 5 7 8
9 2 6 4
1 6 7 3
If we give this an exterior water level of 5, there will not be any water on top of the terrain with height 2. That location is buffered both horizontally and vertically by taller structures that block out the water. In this case, the external water level of 5 leads to water levels of
2 0 0 0
0 0 0 1
4 0 0 2

The same terrain, with an external water level of 8 would produce internal water levels of

5 3 1 0
0 6 2 4
7 2 1 5

If we take that water level, but then drop the exterior water level to 2, we get internal water levels of

0 0 0 0
0 3 0 0
1 0 0 0
The interesting thing to note is that the terrain spot with height 2 is covered by 3 units of water. Even though the external water has dropped, those three units of water remain as a "lake" because it is surrounded by higher ground that keeps the water from draining (note that there are only 3 units of water, because a fourth and further unit of water will drain away because it would have combined altitude of 6 with the terrain, and thus would drain past the neighboring terrain of height 5).

Your Task

You are to implement a single function matching the following specification.
function water = recomputeWater(terrain, outsideLevel, water)
    % Recalculate water level based on new exterior level.
    % Terrain is a fixed array with heights of land
    % outsideLevel is the new height for the surrounding water
    % water is a previous map of water depths above the terrain.
    %    (if water is not specified, it is assumed to be 0 everywhere)
    %
    % Result of the call is a recomputed water array that reflects
    % any necessary changes to the system.

Tools We are Providing

Your only responsibility is the above function. For convenience, we provide the following additional scripts:

An Example

As a detailed example, we consider the following terrain specification.
     6     6    10     5    10     7     0     9     7
     6     1     3     5     5     6     2     6     5
     7     5     2     8     8     7     6     5     5
     4     3     7     2     6    10     6     7     7
     5     6     8     2     7     2     7     4     2
     9     2     4     3     6     4     3     8     3
Shown below is a movie produced using our animateFlood function.

We also provide more detailed frame-by-frame information for this example.


Michael Goldwasser
CSCI 145, Spring 2009
Last modified: Saturday, 18 April 2009
Assignments | Class Photo | Course Home | Lab Hours/Tutoring | MATLAB info | Schedule | Submit