The goals of this lab include doing the specific tasks outlined
below and understanding the general concepts behind the tasks.
In this lab we will look at using some classes to simulate
random walks. Ideally you would have read chapter 7 of Astrachan,
but because of the late arrival of the books and because we didn't
cover the RandomWalk class in during class-time,
some explanation is in order.
Quoting Astrachan,
In one
dimension, the idea would be you flip a coin. If the coin comes up
heads, you take a step to your left, if it comes up tails, you take a
step to the right. You continue doing this for some period of time,
and you see how many steps away from your starting position, you end
up. In two dimensions, you could roll a four-sided die and based
on the die's outcome, you could take a step north, south, east, or
west.
``A random walk is a model
built on mathematical and physical concepts that is used to explain
how molecules move in an enclosed space. This model is also the
basis for several models that predict stock market prices''.
Lab 2 table of contents
In this section of the lab you'll copy files, compile a basic simulation of a random walk, and view the simulation using an animation tool.
First change into your cps100e subdirectory (type pwd
to verify where you are). Create a
lab2 subdirectory by typing mkdir lab2 and change
into this subdirectory (be sure to check that you're
in the lab2 subdirectory.) Now copy the files for the lab
(don't forget the . when copying).
You should see the files listed below (these are links to the files in case you use Netscape, and for users outside of Duke).
Be sure you're in the lab2 subdirectory, and check to see that all files are there (type ls). Then, from an xterm window (at the prompt [1] ola@teer8% or similar) compile the first version of the program by typing: make frogs . This should compile two files and link them together with the library libtapestry.a. Now run the program by typing: frogs at the prompt. The program will prompt you for the number of steps you wish to take in a random walk. Although it may seem to do nothing, it is creating a file to store information about the random walk that was simulated. If you type ls after the program runs, you should see a file called frog.out which was created by frogs. Type ls -lt and write down here _______________ how big the file frog.out is. (the -lt means long format, and sorted by time.)
( If you get a message samba: command not found, then you didn't change your path in lab1 and you should check with a TA. )
To make samba work, you'll need to click on the start button in the Polka Control Panel. You can slow the animation down using the slide-bar. You can pause/start using the pause/start button. To quit samba, use the quit button.
In this part of the lab you'll change the one-dimensional walker to a two-dimensional walker. First you'll modify the program frogs to use four frogs instead of two.
For this part of lab, you'll change the one-dimensional east/west frog to a two-dimensional east/west/north/south frog. To do this you'll change the private section of the class RandomWalk which will require changing member functions as well (and these changes will require still more changes.)
If the roll is 3 or 4 change myYposition by subtracting/adding one, respectively.
You should notice some errors. Cut and paste the errors using the mouse or using control commands that the TAs will help with. Cut the errors and paste them into your README file.
You'll see that GetPosition() is called incorrectly. The x and y coordinate should be arguments passed to GetPosition() [you won't need to call GetYFromID() any more].
to
Because all frogs now start in the middle of the screen. Enter this change, the re-compile the program.
submit100e lab2.N README frog.cc walk.cc walk.h observer.cc
You can enter the files in any order (you don't need to submit observer.h because it didn't change, but you can submit it.)
Remember that every assignment must have a README file submitted with it (please use all capital letters). Include your name, the date, and an estimate of how long you worked on the assignment in the README file. You must also include a list of names of all those people with whom you collaborated on the assignment.
Your post should include a description of who you are, where you're from, what your interests are, and other similar information. You should also include whether you own a computer and what language you've programmed in before. Be sure to use the right subject line as described above.
You should also send email to the head UTA Rachel Pottinger: rap@cs.duke.edu with the subject line: lab2 email. You should get an acknowledgment back, but not a lengthy reply.