Homework I

Due in stages

Goals of this Assignment:

Problem A (due Wednesday, January 16):

We are looking for a parking place on a long street, proceeding according to the following plan:

Each space is empty with probability p, and occupied with probability 1-p.

Write a Python simulation program to find E(D), the mean value of the distance D from the place we park to our destination 0. For each of several values of p of your choice, find the optimal c, reporting the results in a README file.

Here are some sample answers. In order to try a lot of values of c, I wrote a shell script. (Or I could have written another Python script which called my program.)

localhost:~/156% foreach c ( 6 5 4 3 2 1 0 )
foreach? python ParkingPlace.py $c 0.4 10000
foreach? end
mean distance is 4.6576
mean distance is 3.7464
mean distance is 2.898
mean distance is 2.1522
mean distance is 1.5836
mean distance is 1.2972
mean distance is 1.4886
localhost:~/156%
localhost:~/156%
localhost:~/156% foreach c ( 12 11 10 9 8 7 6 5 4 3 2 1 0 )
foreach?  python ParkingPlace.py $c 0.1 10000
foreach? end
mean distance is 8.0974
mean distance is 7.661
mean distance is 7.2868
mean distance is 6.9822
mean distance is 6.762
mean distance is 6.6244
mean distance is 6.5858
mean distance is 6.6548
mean distance is 6.8416
mean distance is 7.1546
mean distance is 7.615
mean distance is 8.2364
mean distance is 9.0366

Looks like, for instance, that with p = 0.1, the best c is 6. (I should have had better output labels.)

Problem B (due Friday, January 18):

This problem models a voting process similar to that of the recent Iowa caucuses. It's quite a simplified model, but good enough for our early learning purposes. Here's how it works:

Command-line usage will be:

% python Iowa.py initial_votes nrepetitions

where initial_votes is in descending numerical order

Your program will find the following quantities:

Here are some sample runs:

localhost:~/156% python Iowa.py 10 8 4 10000
P(init. top wins) = 0.5938
E(number of rounds) = 4.0092
localhost:~/156% python Iowa.py 12 6 4 10000
P(init. top wins) = 0.8235
E(number of rounds) = 3.2346

Problem C (due Wednesday, January 30):

Here you will write a SimPy program to simulate a cell phone network, as follows:

Your program will find the following quantities:

Here are some sample output values:

localhost:~/156% python Cell.py 2 0.5 2 2 3 1 1000000
percentage of rejected handoff calls: 0.123501763512
percentage of rejected local calls: 0.46789498383
mean banned period for locals 0.333385839636

localhost:~/156% python Cell.py 2 0.5 2 2 7 2 1000000
percentage of rejected handoff calls: 0.00110584029391
percentage of rejected local calls: 0.044118073593
mean banned period for locals 0.122240141744

localhost:~/156% python Cell.py 1 0.5 2 2 7 2 1000000
percentage of rejected handoff calls: 0.000100849431798
percentage of rejected local calls: 0.0158323129654
mean banned period for locals 0.111255902476

localhost:~/156% python Cell.py 1 0.5 2 2 7 2 1000000
percentage of rejected handoff calls: 0.000100849431798
percentage of rejected local calls: 0.0158323129654
mean banned period for locals 0.111255902476

localhost:~/156% python Cell.py 1 1 2 1 7 2 1000000
percentage of rejected handoff calls: 0.00345660940314
percentage of rejected local calls: 0.130168942564
mean banned period for locals 0.245352553346