Skip to main content

Crate macro_traffic_sim

Crate macro_traffic_sim 

Source
Expand description

§macro_traffic_sim

gRPC interface for macroscopic traffic simulation via 4-step demand model.

This crate provides a tonic-based gRPC client and server for interacting with the macro_traffic_sim_core computation engine. It allows you to:

  • Create simulation sessions
  • Define transport networks (meso nodes, links, zones)
  • Load origin-destination demand matrices
  • Configure the 4-step model (trip generation, distribution, mode choice, assignment)
  • Run the pipeline and observe progress
  • Retrieve results (link volumes, OD matrices, convergence info)

§Architecture

The computation core (macro_traffic_sim_core) implements the classical 4-step traffic demand model (Generation, Distribution, Mode Choice, Assignment). This crate wraps it with a gRPC API defined in Protocol Buffers, enabling language-agnostic access from Go, Python, or any gRPC-compatible client.

§Quick Start (Client)

use macro_traffic_sim::pb::macro_service_client::MacroServiceClient;
use macro_traffic_sim::pb::*;
use tonic::transport::Channel;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let channel = Channel::from_static("http://127.0.0.1:50052")
        .connect()
        .await?;
    let mut client = MacroServiceClient::new(channel);

    // Create a new session
    let response = client.new_session(NewSessionRequest {}).await?;
    let session_id = response.into_inner().session_id.unwrap().value;
    println!("Session created: {}", session_id);

    // Now push network, zones, OD matrix, configure, and run...
    Ok(())
}

For a complete working example, see examples/rust_client.

§Running the Server

The server binary is included when built with the server feature:

cargo run --features server --bin macro_traffic_sim

§Protocol Buffers

All types are generated from .proto files and exposed under the pb module:

§Clients in Other Languages

Re-exports§

pub use pb::*;

Modules§

pb
Generated Protocol Buffer types and gRPC service definitions.