aequilibrae.paths.TrafficAssignment#

class aequilibrae.paths.TrafficAssignment(project=None)[source]#

Traffic assignment class.

For a comprehensive example on use, see the Use examples page.

>>> from aequilibrae import Project
>>> from aequilibrae.matrix import AequilibraeMatrix
>>> from aequilibrae.paths import TrafficAssignment, TrafficClass

>>> project = Project.from_path("/tmp/test_project")
>>> project.network.build_graphs()

>>> graph = project.network.graphs['c'] # we grab the graph for cars
>>> graph.set_graph('free_flow_time') # let's say we want to minimize time
>>> graph.set_skimming(['free_flow_time', 'distance']) # And will skim time and distance
>>> graph.set_blocked_centroid_flows(True)

>>> proj_matrices = project.matrices

>>> demand = AequilibraeMatrix()
>>> demand = proj_matrices.get_matrix("demand_omx")

# We will only assign one user class stored as 'matrix' inside the OMX file
>>> demand.computational_view(['matrix'])

# Creates the assignment class
>>> assigclass = TrafficClass("car", graph, demand)

>>> assig = TrafficAssignment()

# The first thing to do is to add at list of traffic classes to be assigned
>>> assig.set_classes([assigclass])

# Then we set the volume delay function
>>> assig.set_vdf("BPR")  # This is not case-sensitive

# And its parameters
>>> assig.set_vdf_parameters({"alpha": "b", "beta": "power"})

# The capacity and free flow travel times as they exist in the graph
>>> assig.set_capacity_field("capacity")
>>> assig.set_time_field("free_flow_time")

# And the algorithm we want to use to assign
>>> assig.set_algorithm('bfw')

# Since we haven't checked the parameters file, let's make sure convergence criteria is good
>>> assig.max_iter = 1000
>>> assig.rgap_target = 0.00001

>>> assig.execute() # we then execute the assignment

# If you want, it is possible to access the convergence report
>>> import pandas as pd
>>> convergence_report = pd.DataFrame(assig.assignment.convergence_report)

# Assignment results can be viewed as a Pandas DataFrame
>>> results_df = assig.results()

# Information on the assignment setup can be recovered with
>>> info = assig.info()

# Or save it directly to the results database
>>> results = assig.save_results(table_name='base_year_assignment')

# skims are here
>>> avg_skims = assigclass.results.skims # blended ones
>>> last_skims = assigclass._aon_results.skims # those for the last iteration
__init__(project=None) None[source]#

Methods

__init__([project])

add_class(traffic_class)

Adds a traffic class to the assignment

algorithms_available()

Returns all algorithms available for use

execute([log_specification])

Processes assignment

info()

Returns information for the traffic assignment procedure

log_specification()

report()

Returns the assignment convergence report

results()

Prepares the assignment results as a Pandas DataFrame

save_results(table_name[, keep_zero_flows, ...])

Saves the assignment results to results_database.sqlite

save_select_link_flows(table_name[, project])

Saves the select link link flows for all classes into the results database.

save_select_link_matrices(file_name)

Saves the Select Link matrices for each TrafficClass in the current TrafficAssignment class

save_select_link_results(name)

Saves both the Select Link matrices and flow results at the same time, using the same name.

save_skims(matrix_name[, which_ones, ...])

Saves the skims (if any) to the skim folder and registers in the matrix list

select_link_flows()

Returns a dataframe of the select link flows for each class

set_algorithm(algorithm)

Chooses the assignment algorithm.

set_capacity_field(capacity_field)

Sets the graph field that contains link capacity for the assignment period -> e.g. 'capacity1h'.

set_classes(classes)

Sets Traffic classes to be assigned

set_cores(cores)

Allows one to set the number of cores to be used AFTER traffic classes have been added

set_path_file_format(file_format)

Specify path saving format.

set_save_path_files(save_it)

Turn path saving on or off.

set_time_field(time_field)

Sets the graph field that contains free flow travel time -> e.g. 'fftime'.

set_vdf(vdf_function)

Sets the Volume-delay function to be used

set_vdf_parameters(par)

Sets the parameters for the Volume-delay function.

Attributes

all_algorithms

bpr_parameters