Skip to content

Learning Guide

ASU Trans+AI Lab edited this page Oct 27, 2024 · 1 revision

TAPLite.cpp Traffic Assignment Learning Guide

Overview

TAPLite.cpp is a C++ program that performs traffic assignment calculations, building on implementations provided by Dr. Hillel Bar-Gera’s TNTP and mincostroutes.cpp. It includes advanced data structures, such as deque for modified label-correcting (MLC) algorithms, and is optimized for performance using OpenMP for parallel processing. This guide will cover key sections of the code, including data structures, cost functions, assignment algorithms, and file input/output methods.


Sections

1. Constants and Macros

  • Constants like FLOAT_ACCURACY, NO_COSTPARAMETERS, and IVTT are defined for use in computations and comparisons.
  • Macros such as MIN(x, y), MAX(x, y), SQR(x), and FABS(x) simplify and streamline calculations.

2. Data Structures

  • link_record Structure: Holds data on network links, including IDs, capacities, travel times, and costs.
  • mode_type Structure: Represents each mode of travel (e.g., car, truck) with attributes like Value of Time (VOT), Passenger Car Equivalents (PCE), and occupancy rates.

3. Memory Allocation Utilities

  • Utility functions Alloc_1D, Alloc_2D, and Alloc_3D allocate dynamic memory for one-dimensional, two-dimensional, and three-dimensional arrays, respectively.
  • Example: Alloc_3D(number_of_modes, no_zones, no_zones, sizeof(double)) allocates a 3D array to hold data for each mode.

4. File I/O

  • Settings File (settings.csv): Configuration options for the number of processors, demand period, and logging preferences.
  • Mode Type File (mode_type.csv): Information on each mode, including mode_type, vot, pce, and occ.
  • Node and Link Files (node.csv and link.csv): Define network geometry and link attributes.

5. Initialization and Setup

  • Init Function: Initializes variables, reads the OD flow data, and sets up links.
  • InitLinks Function: Sets up links by reading data from link.csv, calculates the allowed usage modes, and initializes link capacities.

6. Cost Functions

  • Link_Travel_Time Function: Calculates link travel time based on volume, capacity, and free-flow travel time using a Volume-Delay Function (VDF).
  • Link_Travel_Time_Integral Function: Computes the travel time integral for a link.
  • Link_GenCost Function: Combines travel time and additional costs (e.g., tolls) into a generalized link cost.

7. Modified Label-Correcting Algorithm (MLC)

  • Minpath Function: Implements the shortest path search using the deque MLC algorithm. It updates link costs based on the minimum path cost between nodes.
  • FindMinCostRoutes Function: Computes the minimum cost routes across the network and stores them in a tree structure.

8. Traffic Assignment

  • All_or_Nothing_Assign Function: Assigns OD flows to links based on the shortest paths.
  • Search Direction Calculation (VolumeDifference): Computes the difference in volumes between the current and sub-assignment volumes.

9. Line Search for Flow Adjustment

  • LinksSDLineSearch Function: Uses a bisection method to optimize the assignment by adjusting the step size Lambda.

10. Performance Metrics and Output

  • Logging: The program logs results to files like TAP_log.csv and link_performance.csv, capturing iteration details, travel times, volumes, and more.
  • Performance Calculation: Summarizes system-wide travel times and outputs OD performance.

Key Functions Reference

Link Cost Calculation

  • double Link_Travel_Time(int k, double* Volume): Calculates the travel time for a link based on current volume.
  • double Link_GenCost(int k, double* Volume): Computes the generalized cost including tolls for each link.

Shortest Path and Traffic Assignment

  • int Minpath(int mode, int Orig, int* PredLink, double* CostTo): Calculates the minimum path cost using MLC.
  • void All_or_Nothing_Assign(...): Executes the traffic assignment based on shortest paths.

Line Search for Convergence

  • double LinksSDLineSearch(double* MainVolume, double* SDVolume): Uses bisection for step size adjustment in iterative optimization.

Practical Example of Running TAPLite

To execute TAPLite:

  1. Set configuration parameters in settings.csv.
  2. Define modes and demand data in mode_type.csv and corresponding demand files.
  3. Run the program, observing output logs for each iteration and final convergence metrics.

Sample Execution Output