Note
Go to the end to download the full example code
Checking AequilibraE’s log#
AequilibraE’s log is a very useful tool to get more information about what the software is doing under the hood.
Information such as Traffic Class and Traffic Assignment stats, and Traffic Assignment outputs. If you have created your project’s network from OSM, you will also find information on the number of nodes, links, and the query performed to obtain the data.
In this example, we’ll use Sioux Falls data to check the logs, but we strongly encourage you to go ahead and download a place of your choice and perform a traffic assignment!
Imports
from uuid import uuid4
from tempfile import gettempdir
from os.path import join
from aequilibrae.utils.create_example import create_example
from aequilibrae.paths import TrafficAssignment, TrafficClass
We create an empty project on an arbitrary folder
fldr = join(gettempdir(), uuid4().hex)
project = create_example(fldr)
We build our graphs
project.network.build_graphs()
graph = project.network.graphs["c"]
graph.set_graph("free_flow_time")
graph.set_skimming(["free_flow_time", "distance"])
graph.set_blocked_centroid_flows(False)
/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/aequilibrae/project/network/network.py:342: FutureWarning: Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`
df = pd.read_sql(sql, conn).fillna(value=np.nan)
We get our demand matrix from the project and create a computational view
proj_matrices = project.matrices
demand = proj_matrices.get_matrix("demand_omx")
demand.computational_view(["matrix"])
Now let’s perform our traffic assignment
assig = TrafficAssignment()
assigclass = TrafficClass(name="car", graph=graph, matrix=demand)
assig.add_class(assigclass)
assig.set_vdf("BPR")
assig.set_vdf_parameters({"alpha": 0.15, "beta": 4.0})
assig.set_capacity_field("capacity")
assig.set_time_field("free_flow_time")
assig.set_algorithm("bfw")
assig.max_iter = 50
assig.rgap_target = 0.001
assig.execute()
with open(join(fldr, "aequilibrae.log")) as file:
for idx, line in enumerate(file):
print(idx + 1, "-", line)
1 - 2024-02-25 08:40:10,736;WARNING ; Field(s) name, lanes has(ve) at least one NaN value. Check your computations
2 - 2024-02-25 08:40:10,764;WARNING ; Field(s) name, lanes has(ve) at least one NaN value. Check your computations
3 - 2024-02-25 08:40:10,792;WARNING ; Field(s) name, lanes has(ve) at least one NaN value. Check your computations
4 - 2024-02-25 08:40:10,820;WARNING ; Field(s) name, lanes has(ve) at least one NaN value. Check your computations
5 - 2024-02-25 08:40:10,848;WARNING ; Field(s) name, lanes has(ve) at least one NaN value. Check your computations
6 - 2024-02-25 08:40:10,875;WARNING ; Field(s) name, lanes has(ve) at least one NaN value. Check your computations
7 - 2024-02-25 08:40:10,894;WARNING ; Cost field with wrong type. Converting to float64
8 - 2024-02-25 08:40:11,169;INFO ; Traffic Class specification
9 - 2024-02-25 08:40:11,170;INFO ; {'car': {'Graph': "{'Mode': 'c', 'Block through centroids': False, 'Number of centroids': 24, 'Links': 76, 'Nodes': 24}", 'Matrix': "{'Source': '/tmp/b9e255f6ca5b45cf89fbdeeb06ceafd1/matrices/demand.omx', 'Number of centroids': 24, 'Matrix cores': ['matrix'], 'Matrix totals': {'matrix': 360600.0}}"}}
10 - 2024-02-25 08:40:11,170;INFO ; Traffic Assignment specification
11 - 2024-02-25 08:40:11,170;INFO ; {'VDF parameters': {'alpha': 0.15, 'beta': 4.0}, 'VDF function': 'bpr', 'Number of cores': 4, 'Capacity field': 'capacity', 'Time field': 'free_flow_time', 'Algorithm': 'bfw', 'Maximum iterations': 250, 'Target RGAP': 0.0001}
12 - 2024-02-25 08:40:11,172;WARNING ; Cost field with wrong type. Converting to float64
13 - 2024-02-25 08:40:11,172;INFO ; bfw Assignment STATS
14 - 2024-02-25 08:40:11,172;INFO ; Iteration, RelativeGap, stepsize
15 - 2024-02-25 08:40:11,185;INFO ; 1,inf,1.0
16 - 2024-02-25 08:40:11,190;INFO ; 2,0.8550751349428284,0.32839952448634563
17 - 2024-02-25 08:40:11,195;INFO ; 3,0.4763455007221067,0.18660240547488702
18 - 2024-02-25 08:40:11,201;INFO ; 4,0.2355126365951965,0.2411477440291793
19 - 2024-02-25 08:40:11,210;INFO ; 5,0.10924072010481088,0.8185470737942447
20 - 2024-02-25 08:40:11,218;INFO ; 6,0.1980945227617506,0.14054330572978305
21 - 2024-02-25 08:40:11,223;INFO ; 7,0.0668172221544687,0.36171152718899235
22 - 2024-02-25 08:40:11,230;INFO ; 8,0.06792122267870576,0.9634685345644022
23 - 2024-02-25 08:40:11,238;INFO ; 9,0.10705582933092841,0.13757153109677167
24 - 2024-02-25 08:40:11,245;INFO ; 10,0.04038814432034633,0.16094034254279746
25 - 2024-02-25 08:40:11,254;INFO ; 11,0.027952481137756665,0.3408928228700516
26 - 2024-02-25 08:40:11,259;INFO ; 12,0.03269999206552473,0.5467680533028665
27 - 2024-02-25 08:40:11,266;INFO ; 13,0.024040970172177347,0.13812236751253087
28 - 2024-02-25 08:40:11,271;INFO ; 14,0.021451030909508475,0.19705281508905445
29 - 2024-02-25 08:40:11,277;INFO ; 15,0.017116638259274335,0.33993816583363656
30 - 2024-02-25 08:40:11,282;INFO ; 16,0.017350824111296178,0.7287610532385328
31 - 2024-02-25 08:40:11,290;INFO ; 17,0.02116470546437159,0.08183287977099345
32 - 2024-02-25 08:40:11,298;INFO ; 18,0.012464530324249013,0.15115985804759405
33 - 2024-02-25 08:40:11,306;INFO ; 19,0.01254978991985043,0.16834049481540547
34 - 2024-02-25 08:40:11,311;INFO ; 20,0.011860719789714877,0.5399903522726819
35 - 2024-02-25 08:40:11,317;INFO ; 21,0.012859165521052207,0.05496659199654713
36 - 2024-02-25 08:40:11,326;INFO ; 22,0.007671197552803324,0.06125561557359048
37 - 2024-02-25 08:40:11,331;INFO ; 23,0.005529178907230118,0.07401911120606994
38 - 2024-02-25 08:40:11,342;INFO ; 24,0.005466797330664673,0.19170977924358065
39 - 2024-02-25 08:40:11,348;INFO ; 25,0.00707366882330592,0.42287206962828094
40 - 2024-02-25 08:40:11,358;INFO ; 26,0.009664731222550847,0.941017705161317
41 - 2024-02-25 08:40:11,366;INFO ; 27,0.008756083467129042,0.05172611061874956
42 - 2024-02-25 08:40:11,374;INFO ; 28,0.005105221228052905,0.06397929882333851
43 - 2024-02-25 08:40:11,379;INFO ; 29,0.0035319062476952545,0.050590904988219755
44 - 2024-02-25 08:40:11,392;INFO ; 30,0.0031482926233623735,0.0584374878179482
45 - 2024-02-25 08:40:11,398;INFO ; 31,0.003063209044595418,0.09173138967981329
46 - 2024-02-25 08:40:11,403;INFO ; 32,0.0026646507707727665,0.07094979246384595
47 - 2024-02-25 08:40:11,410;INFO ; 33,0.002302802037873702,0.12412864151965049
48 - 2024-02-25 08:40:11,418;INFO ; 34,0.002751030256062654,0.12799355702548365
49 - 2024-02-25 08:40:11,425;INFO ; 35,0.002125634778303212,0.16620387933954625
50 - 2024-02-25 08:40:11,431;INFO ; 36,0.002099491223202113,0.10282963642099599
51 - 2024-02-25 08:40:11,437;INFO ; 37,0.0014407763657247766,0.14492101336893168
52 - 2024-02-25 08:40:11,446;INFO ; 38,0.0014180447044001398,0.06529689866681382
53 - 2024-02-25 08:40:11,452;INFO ; 39,0.0009714813735980109,0.09399257335249002
54 - 2024-02-25 08:40:11,452;INFO ; bfw Assignment finished. 39 iterations and 0.0009714813735980109 final gap
In lines 1-7, we receive some warnings that our fields name and lane have NaN
values.
As they are not relevant to our example, we can move on.
In lines 8-9 we get the Traffic Class specifications. We can see that there is only one traffic class (car). Its graph key presents information on blocked flow through centroids, number of centroids, links, and nodes. In the matrix key, we find information on where in the disk the matrix file is located. We also have information on the number of centroids and nodes, as well as on the matrix/matrices used for computation. In our example, we only have one matrix named matrix, and the total sum of this matrix element is equal to 360,600. If you have more than one matrix its data will be also displayed in the matrix_cores and matrix_totals keys.
In lines 10-11 the log shows the Traffic Assignment specifications. We can see that the VDF parameters, VDF function, capacity and time fields, algorithm, maximum number of iterations, and target gap are just like the ones we set previously. The only information that might be new to you is the number of cores used for computation. If you haven’t set any, AequilibraE is going to use the largest number of CPU threads available.
Line 12 displays us a warning to indicate that AequilibraE is converting the data type of the cost field.
Lines 13-61 indicate that we’ll receive the outputs of a bfw algorithm.
In the log there are also the number of the iteration, its relative gap, and the stepsize.
The outputs in lines 15-60 are exactly the same as the ones provided by the function
assig.report()
. Finally, the last line shows us that the bfw assignment has finished
after 46 iterations because its gap is smaller than the threshold we configured (0.001).
In case you execute a new traffic assignment using different classes or changing the parameters values, these new specification values would be stored in the log file as well so you can always keep a record of what you have been doing. One last reminder is that if we had created our project from OSM, the lines on top of the log would have been different to display information on the queries done to the server to obtain the data.
Total running time of the script: (0 minutes 0.830 seconds)