{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n# Checking AequilibraE's log\n\nAequilibraE's log is a very useful tool to get more information about\nwhat the software is doing under the hood.\n\nInformation such as Traffic Class and Traffic Assignment stats, and Traffic Assignment\noutputs. If you have created your project's network from OSM, you will also find\ninformation on the number of nodes, links, and the query performed to obtain the data.\n\nIn this example, we'll use Sioux Falls data to check the logs, but we strongly encourage\nyou to go ahead and download a place of your choice and perform a traffic assignment!\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Imports\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from uuid import uuid4\nfrom tempfile import gettempdir\nfrom os.path import join\nfrom aequilibrae.utils.create_example import create_example\nfrom aequilibrae.paths import TrafficAssignment, TrafficClass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We create an empty project on an arbitrary folder\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fldr = join(gettempdir(), uuid4().hex)\nproject = create_example(fldr)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We build our graphs\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "project.network.build_graphs()\n\ngraph = project.network.graphs[\"c\"]\ngraph.set_graph(\"free_flow_time\")\ngraph.set_skimming([\"free_flow_time\", \"distance\"])\ngraph.set_blocked_centroid_flows(False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We get our demand matrix from the project and create a computational view\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "proj_matrices = project.matrices\ndemand = proj_matrices.get_matrix(\"demand_omx\")\ndemand.computational_view([\"matrix\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's perform our traffic assignment\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "assig = TrafficAssignment()\n\nassigclass = TrafficClass(name=\"car\", graph=graph, matrix=demand)\n\nassig.add_class(assigclass)\nassig.set_vdf(\"BPR\")\nassig.set_vdf_parameters({\"alpha\": 0.15, \"beta\": 4.0})\nassig.set_capacity_field(\"capacity\")\nassig.set_time_field(\"free_flow_time\")\nassig.set_algorithm(\"bfw\")\nassig.max_iter = 50\nassig.rgap_target = 0.001\n\nassig.execute()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "with open(join(fldr, \"aequilibrae.log\")) as file:\n for idx, line in enumerate(file):\n print(idx + 1, \"-\", line)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In lines 1-7, we receive some warnings that our fields name and lane have ``NaN`` values.\nAs they are not relevant to our example, we can move on.\n\nIn lines 8-9 we get the Traffic Class specifications.\nWe can see that there is only one traffic class (car). Its **graph** key presents information\non blocked flow through centroids, number of centroids, links, and nodes.\nIn the **matrix** key, we find information on where in the disk the matrix file is located.\nWe also have information on the number of centroids and nodes, as well as on the matrix/matrices\nused for computation. In our example, we only have one matrix named matrix, and the total\nsum of this matrix element is equal to 360,600. If you have more than one matrix its data\nwill be also displayed in the *matrix_cores* and *matrix_totals* keys.\n\nIn lines 10-11 the log shows the Traffic Assignment specifications.\nWe can see that the VDF parameters, VDF function, capacity and time fields, algorithm,\nmaximum number of iterations, and target gap are just like the ones we set previously.\nThe only information that might be new to you is the number of cores used for computation.\nIf you haven't set any, AequilibraE is going to use the largest number of CPU threads\navailable.\n\nLine 12 displays us a warning to indicate that AequilibraE is converting the data type\nof the cost field.\n\nLines 13-61 indicate that we'll receive the outputs of a *bfw* algorithm.\nIn the log there are also the number of the iteration, its relative gap, and the stepsize.\nThe outputs in lines 15-60 are exactly the same as the ones provided by the function\n``assig.report()``. Finally, the last line shows us that the *bfw* assignment has finished\nafter 46 iterations because its gap is smaller than the threshold we configured (0.001).\n\nIn case you execute a new traffic assignment using different classes or changing the\nparameters values, these new specification values would be stored in the log file as well\nso you can always keep a record of what you have been doing. One last reminder is that\nif we had created our project from OSM, the lines on top of the log would have been\ndifferent to display information on the queries done to the server to obtain the data.\n\n\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.18" } }, "nbformat": 4, "nbformat_minor": 0 }