CE 392D - Dynamic Traffic Assignment

Spring 2018

Homework 3

Due on Canvas at 11:59 PM, Friday, April 6. 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

Chapter 11: Exercises 6, 9, 11

Python questions

In this assignment, you will implement the three simple link models learned in class: links in series, diverges, and merges. Download and unzip these files to a convenient directory. You will be editing just one file in this assignment: nodeModel.py. You are welcome to look at the other files too (in particular you should look at node.py) but they should not be edited.

The node.py file defines the Node class. This will serve as the base class for each of the three node models, which will be implemented in nodeModel.py.

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

  • upstreamLinks, downstreamLinks -- these are lists containing the IDs of the links which enter and leave the node, respectively.
  • sendingFlow and receivingFlow -- these are dictionaries whose keys are the IDs of incoming/outgoing links and whose corresponding values are the current sending/receiving flows for those links.
  • proportion -- this is a dictionary-of-dictionaries; each entry is referred to using two keys, the first of which is an incoming link and the second of which is an outgoing link. The corresponding value is the fraction of the sending flow on the incoming link which wants to leave using the outgoing link; for instance if proportion['(h,i)']['(i,j)'] = 0.5 then half of the vehicles in the sending flow from link (h,i) will leave the node on link (i,j). (The way this works is that proportion is a dictionary with a key for each incoming link, but each of its values is another dictionary with a key for each outgoing link.)
  • priority -- only used for merge links, these values are used to determine each incoming link's "fair share" of the downstream link receiving flow: if the merge is congested, the amount of space initially allocated to a link is proportional to its priority value. In class we used the capacities of incoming links as priority values; for this assignment the priority values will be given in the test cases and may or may not reflect the capacity. These are also stored as dictionaries, with keys corresponding to the IDs of incoming links and values corresponding to the priority value.

To understand how these work, you may find it helpful to add some print statements to see what these lists and dictionaries look like and what information they contain.

As with earlier assignments, 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: Links in series

In this question, you will implement the node model for a node with a single incoming and outgoing link. Open nodeModel.py and look at the SeriesNode class, derived from the Node class in node.py. You will need to implement the function calculating the transition flows, stored in transitionFlows. This is also a dictionary-of-dictionaries (see the description of proportion above) and it has a value corresponding to each combination of incoming and outgoing link (for this type of node, there is just one such combination). The part of calculateTransitionFlows that sets up this dictionary-of-dictionaries is already implemented for you, you just need to calculate and store the number of vehicles which is allowed to move in transitionFlows, and return this dictionary.

Question 2: Diverge nodes

In this question, you will implement the diverge node model, by implementing the functions calculating the sending and receiving flow in the DivergeNode class. You will need to refer to the proportion dictionary, as well as the sendingFlow and receivingFlow dictionaries. Your implementation should work for any number of downstream links (not just 2).

Question 3: Merge nodes

In this question, you will implement the diverge node model, by implementing the functions calculating the sending and receiving flow in the MergeNode class. You will need to refer to the priority dictionary, as well as the sendingFlow and receivingFlow dictionaries. Your implementation should work for any number of downstream links (not just 2).

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, hw3.zip).
  4. When I unzip your file, I should get a folder called hw3/ 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 hw3.zip
diff -bur master/ hw1/ # master is the original version; this shows me your changes
cd hw3
cat README.txt
python3 grader.py
cd ..
rm -r hw3 hw3.zip

Return to course homepage.