cs533 Project 1

The Dog and the Mailman

Due date: Friday, February 6th, by 11:59pm

Dog and Mailman

One day a mailman was greeted by a boy and a huge dog.
The mailman asked the boy, "Does your dog bite?"
"No," replied the boy. Just then the huge dog bit the mailman.
The man yelled, "I thought your dog doesn't bite!"
"He doesn't," replied the boy, "that's not my dog!"



You are to simulate various scenarios involving dogs and mailmen (you can substitute mailwomen if you want your mail carriers to be a woman or mailpeople if you want your mail carriers to be gender neutral). Basically, a mailman comes to the walkway of a house. The dog and the mailman see each other and take action. The dog tries to catch the mailman (either to bite him or to get the dog biscuits he's carrying) and the mailman tries to get away.


Let (x(t), y(t)) be the position of a dog at time t (where distance is in feet and t is in seconds, say). A mailman is located at position (p(t), 0) and is moving in the positive x direction. The dog always runs directly towards the mailman with a speed of s(t) beginning at t=0. Assume that (x(0), y(0)) = (0, 20), and the dog was lying down so s(0) = 0.

There are two types of dogs to consider:

  1. The speed of Type-1 dogs is:
      s(t) = 2t for 0 < t < 5 
      s(t) = 10 for 5 <= t 
  2. Type-2 dogs are a little bit faster than Type-1 one dogs, but they occasionally slip and fall. The speed of Type-2 dogs is:
      s(trun) = 3trun for 0 < trun < 4 
      s(trun) = 12 for 4 <= trun
    where trun is the time since the dog last slipped and fell. To determine if the dog slips and falls, call the function slip(trun) at each time step of your simulation.

You are to write a simulation program to determine when each type of dog bites the mailman for two different types of mailmen (i.e. there are a total of four different cases to consider). Each mailman has an untied shoe at t=0.

  1. Type-A mailmen stand still for 3 seconds to tie their shoe before running at a constant speed of 5.

  2. Type-B mailmen leave their shoes untied and try to run with a loose shoe at half their normal speed (i.e. 2.5).

Determine which type of mailman runs the furthest before getting bitten by each type of dog by simulating each situation at least ten times.


You can (and probably should) seed your random number generator with srandom(). Do a "man srandom" for more details. Seeding it with time() may be a good idea. Do a "man 2 time" for more details.

You are welcome to code your solution in any language (including scripting languages such as perl) you choose.

Your writeup should provide sufficient visual details for me to understand your results. This may be in tabular form but it may be in graphical form. Your graphs may show data, or xy coordinates.

If you are using Windows, MS Excel has good support for drawing graphs. You might try this tutorial http://www.urban.uiuc.edu/Courses/varkki/msexcel/graphs/Default.html to get started.

If you are using Unix, gnuplot has good support for drawing graphs. You might see http://www.gnuplot.info/ for more information.

You might look at the slides for this project (ppt).

Hand In

Hand-in a report (your report should be in pdf or postscript or text but not MS Word or any other native document format) containing:

  1. A short description of your model.
  2. The high-level algorithm used to perform the simulation.
  3. Your termination and starting conditions.
  4. The rule you use to update the simulation.
  5. Your conclusion about whether or not the mailman should stop and tie their shoe before running from the dog.

Also, you should include

  1. The source code of any scripts you used (note, this is not a substitution for the high-level description).

Tar up (with gzip) your files, for example:

    mkdir proj1
    cp * proj1  /* copy all your files to submit to proj1 directory */
    tar -czf proj1.tgz proj1

then attach proj1.tgz to an email with "cs533_proj1" as the subject. Type elm -scs525_proj1 < proj1.tgz to send it, if that is easier.

Return to the 533 Home Page

Send all questions to (claypool at cs.wpi.edu).