Urban Network Analysis
(This comment is in __init__.py in the _01_UrbanNetworkAnalysis directory)
This part mainly covers the four-step transportation planning process: Trip Generation, Trip Distribution, Mode Split, and Trip Assignment
Trip Assignment – Transportation Networks
-
class
PyTrans.UrbanNetworkAnalysis.TransportationNetworks.
Link
(**kwargs)[source]
Class for handling link object in Transportation Networks
Parameters: |
- link_id (int) – identifier of link
- length (float) – length of link
- capacity (float) – capacity of link
- alpha (float) – first BPR function parameter, usually 0.15
- beta (float) – second BPR function parameter, usually 4.0
- from_node (int) – id of origin node of link
- to_node (int) – id of destination node of link
- flow (float) – flow on link
- free_speed (float) – free flow speed of link
- v (float) – speed limit of link
- SO (boolean) – True if objective is to find system optimal solution,
False if objective is to find user equilibrium
|
Variables: |
- t0 (float) – link travel time under free flow speed
- time (float) – link travel time based on the BPR function
|
-
bpr
(alpha=None, beta=None, flow=None)[source]
Method for calculating the BPR function
Parameters: |
- alpha (float) – first BPR function parameter, usually 0.15
- beta (float) – second BPR function parameter, usually 4.0
- flow (float) – flow on link
|
Returns: | link travel time
|
Return type: | float
|
-
get_objective_function
()[source]
Method for calculating objective function value
Returns: | objective function value |
Return type: | float |
-
get_time
()[source]
Method for getting link travel time based on the BPR function
This method is used when setting ‘time’ variable
-
class
PyTrans.UrbanNetworkAnalysis.TransportationNetworks.
Network
(link_file, trip_file, node_file=None, SO=False)[source]
Class for handling Transportation Networks. This class contains methods to read various TNTP format files from the source and methods of network-wide operations
Parameters: |
- link_file (string) – file path of network file, which containing various link information
- trip_file (string) – file path of trip table. An Origin label and then Origin node number, followed by Destination node numders and OD flow
- node_file (string) – file path of node file, which containing coordinates information of nodes
- SO (boolean) – True if objective is to find system optimal solution,
False if objective is to find user equilibrium
|
Variables: |
- graph (networkx.DiGrapy) – graph of links with Link object and travel time under the current condition
- origins (list) – list of origin nodes
- od_vols (dictionary) – key: tuple(origin node, destination node), value: traffic flow
|
-
all_or_nothing_assignment
()[source]
Method for implementing all-or-nothing assignment based on the current graph.
It updates link traffic flow
-
build_datastructure
()[source]
Method for opening .tntp format network information files and preparing variables for the analysis
-
open_link_file
()[source]
Method for opening network file, containing various link information
Returns: |
- list – list of Link objects having current link condition
- list – list of Node objects
|
-
open_node_file
(graph)[source]
Method for opening node file, containing position information of nodes
This method adds ‘pos’ key-value pair in graph variable
-
open_trip_file
(demand_factor=1.0)[source]
Method for opening trip tables containing OD flows of each OD pair
- demand_factor float
- demand factor
-
update_linkcost
()[source]
Method for updating link travel time.
-
class
PyTrans.UrbanNetworkAnalysis.TransportationNetworks.
Node
(node_id=0)[source]
Class for handling node object in Transportation Networks
Parameters: | node_id (int) – identifier of a node |
-
class
PyTrans.UrbanNetworkAnalysis.TransportationNetworks.
Visualization
[source]
Class for handling visualization effect
-
reLocateAlink
(px1, py1, px2, py2, offset=0.5)[source]
Method for adjusting location of a link
Parameters: |
- px1 (float) – x coordinate of a node
- py1 (float) – y coordinate of a node
- px2 (float) – x coordinate of another node
- py2 (float) – y coordinate of another node
|
Returns: |
- fx (float) – new coordinate of px1
- fy (float) – new coordinate of py1
- tx (float) – new coordinate of px2
- ty (float) – new coordinate of py2
|
-
reLocateLinks
(graph)[source]
Method for modifying links in graph
- graph: networkx DiGraph
- graph to present
Trip Assignment – Frank-Wolfe algorithm
-
class
PyTrans.UrbanNetworkAnalysis.Frank_Wolfe.
Run
(link_file, trip_file, node_file, SO)[source]
Class of implementing Frank-Wolfe algorithm for networks privided from
Transportation Networks for Research Core Team (https://github.com/bstabler/TransportationNetworks)
Parameters: |
- link_file (string) – file path of network file, which containing various link information
- trip_file (string) – file path of trip table. An Origin label and then Origin node number, followed by Destination node numders and OD flow
- node_file (string) – file path of node file, which containing coordinates information of nodes
- SO (boolean) – True if objective is to find system optimal solution,
False if objective is to find user equilibrium
|
Variables: |
- graph (networkx DiGraph) – graph of links when completing the algorithm
- network (nested dictionary) – dictionary of links information and history of Frank-Wolfe algorithm implementation by iteration
- fwResult (dictionary) – dictionary of theta (optimal move size) and objective function value over iterations
|
Example
A Quick example
#Set the paths of Transportation Networks file
>>> directory = ".\Data\TransportationNetworks\SiouxFalls\"
>>> link_file = '{}SiouxFalls_net.tntp'.format(directory)
>>> trip_file = '{}SiouxFalls_trips.tntp'.format(directory)
>>> node_file = '{}SiouxFalls_node.tntp'.format(directory)
>>> SO = False
#Implement Frank-Wolfe algorithm
>>> fw = Run(link_file, trip_file, node_file, SO)
>>> fw.showODFlow()
>>> fw.showODFlowMap()
-
BPR
(t0, xa, ca, alpha, beta)[source]
Method for calculating link travel time based on BPR function
Parameters: |
- t0 (float) – link travel time under free flow speed
- xa (float) – traffic link flow
- ca (float) – capacity of link
- alpha (float) – first BPR function parameter, usually 0.15
- beta (float) – second BPR function parameter, usually 4.0
|
Returns: | ta – link travel time under the current traffic flow
|
Return type: | float
|
-
calculateZ
(theta)[source]
Method for calculating objective function value
Parameters: | theta (float) – optimal move size |
Returns: | objective function value |
Return type: | float |
-
lineSearch
()[source]
Method for estimating theta (optimal move size)
Returns: | optimal move size (rate) between 0 and 1 |
Return type: | float |
-
showODFlow
()[source]
Method for presenting table of the optimal traffic assignment of the Frank-Wolfe algorithm procedure
-
showODFlowMap
()[source]
Method for presenting the traffic assignment result on a map
Trip Assignment – User Equilibrium & System Optimum
Trip Assignment – Path based assignment & Gradient Programming
Trip Assignment – Dynamic Traffic Assignment