Expand description
§micro_traffic_sim
gRPC interface for microscopic traffic simulation via cellular automata.
This crate provides a tonic-based gRPC client and server for interacting with
the micro_traffic_sim_core simulation engine. It allows you to:
- Create simulation sessions
- Define road networks as cellular grids / graphs
- Configure traffic lights with signal phases
- Set up conflict zones for unregulated intersections or where traffic lights have conflicting green phases
- Setup vehicle generators via trips technique
- Step through the simulation and observe vehicle/traffic light states
§Architecture
The simulation core (micro_traffic_sim_core) implements the cellular automaton
model for traffic flow. 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 micro_traffic_sim::pb::service_client::ServiceClient;
use micro_traffic_sim::pb::{SessionReq, UuiDv4, SessionGrid, Cell, Point};
use tonic::transport::Channel;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to the gRPC server
let channel = Channel::from_static("http://127.0.0.1:50051")
.connect()
.await?;
let mut client = ServiceClient::new(channel);
// Create a new session (SRID 0 = Euclidean coordinates)
let response = client.new_session(SessionReq { srid: 0 }).await?;
let session_id = response.into_inner().id.unwrap().value;
println!("Session created: {}", session_id);
// Now push grid cells, trips, traffic lights, and run simulation steps...
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 micro_traffic_sim§Protocol Buffers
All types are generated from .proto files and exposed under the pb module:
pb::service_client::ServiceClient- gRPC client stubpb::service_server::ServiceServer- gRPC server trait (withserverfeature)pb::Cell- Road network cellpb::Trip- Vehicle trip/generator configurationpb::TrafficLight- Traffic light with signal groupspb::ConflictZone- Priority rules for unregulated intersectionspb::SessionStep/pb::SessionStepResponse- Simulation step request/responsepb::VehicleState- Vehicle position and state per timestep
§Related Crates
micro_traffic_sim_core- The computation engine (cellular automaton implementation)
§Clients in Other Languages
- Go: clients/go (pkg.go.dev)
- Python: clients/python (PyPI)
Re-exports§
pub use pb::*;
Modules§
- pb
- Generated Protocol Buffer types and gRPC service definitions.