l CE 392D - Homework 2

CE 392D - Dynamic Traffic Assignment

Spring 2018

Homework 2

Due on Canvas at 11:59 PM, Friday, March 9. Submit two files: a PDF containing your solutions to the textbook problems, and a ZIP file containing your code for the Python problems. Textbook problems must be solved individually, Python problems can be solved individually or in groups of two. More details below on how to submit the Python code.

Textbook questions

You are encouraged (but not required) to use your Python code to help answer these questions.

Chapter 10: Exercises 21, 23, 24

Python questions

In this assignment, you will implement all four of the link models learned in class: point queue, spatial queue, link transmission model, and cell transmission model. Download and unzip these files to a convenient directory. You will be editing just one file in this assignment: linkModel.py. You are welcome to look at the other files too (in particular you should look at link.py) but they should not be edited.

The link.py file defines the Link class. This will serve as the base class for each of the four link models, which will be implemented in linkModel.py. The units convention bears mentioning. To keep the important parts of the code simpler, a consistent set of units is used internally: all distances will be measured in ft, and all times will be measured in timesteps (so Δt = 1). This choice of units is less convenient for specifying the problem input data -- speeds are generally measured in mi/hr, jam density in veh/mi, capacity in veh/hr, link lengths in ft, and time steps in seconds.

The constructor for the Link class takes care of these unit conversions: the arguments are expressed in this common choice of units, and the constructor converts these to internal units. It also sets up a few lists and dictionaries which are used to move vehicles into and out of links (you do not need to edit or understand these.) If you end up overriding this constructor for any of your link models, you must either implement similar functionality or (better yet) call the Link.__init__ constructor explicitly. Notice that this is already done in the PointQueueLink and SpatialQueueLink classes to allow for different upstream and downstream capacities.

There are some other attributes and methods defined in the Link class; the most useful ones for this assignment are:

  • capacity, freeFlowSpeed, backwardWaveSpeed, jamDensity, and -- should be self-explanatory, just note units convention above.
  • freeFlowTime and backwardWaveTime -- the time needed to traverse the link at free-flow speed, and at the backward wave speed, rounded up to the nearest timestep.
  • maxVehicles -- the number of vehicles on the link if all points were at jam density
  • upstreamCount(t) -- returns cumulative entries to a link through time t. You should only call this for integer values of t (the Link constructor rounds up the free-flow time and backward wave time to the nearest timestep.)
  • downstreamCount(t) -- same as upstreamCount, but returns cumulative exits from a link.
  • vehiclesOnLink(t) -- returns the number of vehicles on a link at time t.
  • linkUpdate(t) -- the grader will call this method for the link at each time step. At a minimum, it needs to return the sending and receiving flow as a tuple. This is the default functionality. If you need to perform additional calculations for the link at each time step (e.g., moving vehicles between cells), you should override this method in your derived classes.

As with the first assignment, you can run grader.py to check your implementations against the test cases I will be using. You can browse these in the tests folder if you want to see the input data and the correct output values. All numerical values must be within 1% of the reference values to be marked correct.

Question 1: Point queues

In this question, you will implement the point queue model. Open linkModel.py and look at the PointQueueLink class, derived from the Link class in link.py. You will need to implement the functions calculating the sending and receiving flow for a point queue. The cumulative entries and exits at any point in time can be calculated with the upstreamCount and downstreamCount methods defined in link.py. Notice that point queues can have different upstream and downstream capacities.

Question 2: Spatial queues

In this question, you will implement the spatial queue model, by implementing the functions calculating the sending and receiving flow in the SpatialQueueLink class. You will need to refer to a link's jam density, as well as its upstream and downstream capacities.

Question 3: Link transmission model

In this question, you will implement the link transmission model model, by implementing the functions calculating the sending and receiving flow in the LinkTransmissionModelLink class. You will need to refer to a link's jam density, as well as its capacity and backward wave speed (note that the time needed to traverse the link at the backward wave speed is already calculated by the link constructor, and stored in backwardWaveTime).

Question 4: Cell transmission model

In this question, you will implement the cell transmission model, by implementing the functions calculating the sending and receiving flow in the CellTransmissionModelLink class. You will need to refer to a link's jam density, as well as its capacity and backward wave speed. This question is the most involved of the four, because you need to decide how to implement the division of a link into cells, how to track information by cell, and how to update cells. Feel free to define additional classes, methods, or override default methods in the Link class as necessary. In particular, you probably should override linkUpdate to ensure that your cell updates occur at each time step. Please summarize the main ideas of your CTM implementation in the README.txt file.

Submission instructions

Your answers to the textbook questions should be placed in a single PDF file and uploaded to Canvas. Please verify that your file uploaded correctly, that the pages are in the right order, etc.

For the Python questions, submit a single ZIP file and upload to Canvas. Please follow these instructions:

  1. Include a text file named README.txt which contains (at a minimum) the names of you and your partner (if any). Both partners do not need to submit this ZIP file. (But both partners should submit their PDF questions from the tetxbook separately.) You can add in additional comments or explanations about your implementation in this file, if necessary.
  2. Everything in the original ZIP file should be in the ZIP file you submit (do not just submit the files you changed.)
  3. Give your ZIP file the same name as the ZIP file you downloaded (in this case, hw2.zip).
  4. When I unzip your file, I should get a folder called hw1/ with all of your files in it (it should not expand in place.)
To grade your code, I will execute the following commands. (If you have a Linux environment, you can test these steps yourself. Failure to follow the instructions above will not usually result in a grade penalty, but it makes my life less convenient.) If you feel that the autograder is not correctly judging your code, let me know and I will review manually.
unzip hw2.zip
diff -bur master/ hw1/ # master is the original version; this shows me your changes
cd hw2
cat README.txt
python3 grader.py
cd ..
rm -r hw2 hw2.zip

Return to course homepage.