1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! # 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)
//!
//! ```rust,no_run
//! 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`](https://github.com/LdDl/micro_traffic_sim_grpc/tree/master/examples/rust_client).
//!
//! ## Running the Server
//!
//! The server binary is included when built with the `server` feature:
//!
//! ```sh
//! 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 stub
//! - [`pb::service_server::ServiceServer`] - gRPC server trait (with `server` feature)
//! - [`pb::Cell`] - Road network cell
//! - [`pb::Trip`] - Vehicle trip/generator configuration
//! - [`pb::TrafficLight`] - Traffic light with signal groups
//! - [`pb::ConflictZone`] - Priority rules for unregulated intersections
//! - [`pb::SessionStep`] / [`pb::SessionStepResponse`] - Simulation step request/response
//! - [`pb::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](https://github.com/LdDl/micro_traffic_sim_grpc/tree/master/clients/go) ([pkg.go.dev](https://pkg.go.dev/github.com/LdDl/micro_traffic_sim_grpc/clients/go))
//! - **Python**: [clients/python](https://github.com/LdDl/micro_traffic_sim_grpc/tree/master/clients/python) ([PyPI](https://pypi.org/project/micro-traffic-sim/))
//!
//! [`micro_traffic_sim_core`]: https://docs.rs/micro_traffic_sim_core/latest/micro_traffic_sim_core/
//! [tonic]: https://docs.rs/tonic/latest/tonic/
/// Generated Protocol Buffer types and gRPC service definitions.
///
/// This module contains all types generated from the `.proto` files:
///
/// - **Session management**: [`SessionReq`], [`NewSessionResponse`], [`InfoSessionResponse`]
/// - **Grid/Cells**: [`Cell`], [`Point`], [`SessionGrid`], [`ZoneType`]
/// - **Trips**: [`Trip`], [`SessionTrip`], [`TripType`], [`AgentType`], [`BehaviourType`]
/// - **Traffic Lights**: [`TrafficLight`], [`Group`], [`GroupType`], [`SessionTls`]
/// - **Conflict Zones**: [`ConflictZone`], [`SessionConflictZones`], [`ConflictWinnerType`]
/// - **Simulation**: [`SessionStep`], [`SessionStepResponse`], [`VehicleState`], [`TlsState`]
/// - **gRPC Client**: [`service_client::ServiceClient`]
/// - **gRPC Server**: [`service_server::ServiceServer`] (with `server` feature)
///
/// [`SessionReq`]: SessionReq
/// [`NewSessionResponse`]: NewSessionResponse
/// [`InfoSessionResponse`]: InfoSessionResponse
/// [`Cell`]: Cell
/// [`Point`]: Point
/// [`SessionGrid`]: SessionGrid
/// [`ZoneType`]: ZoneType
/// [`Trip`]: Trip
/// [`SessionTrip`]: SessionTrip
/// [`TripType`]: TripType
/// [`AgentType`]: AgentType
/// [`BehaviourType`]: BehaviourType
/// [`TrafficLight`]: TrafficLight
/// [`Group`]: Group
/// [`GroupType`]: GroupType
/// [`SessionTls`]: SessionTls
/// [`ConflictZone`]: ConflictZone
/// [`SessionConflictZones`]: SessionConflictZones
/// [`ConflictWinnerType`]: ConflictWinnerType
/// [`SessionStep`]: SessionStep
/// [`SessionStepResponse`]: SessionStepResponse
/// [`VehicleState`]: VehicleState
/// [`TlsState`]: TlsState
/// [`service_client::ServiceClient`]: service_client::ServiceClient
/// [`service_server::ServiceServer`]: service_server::ServiceServer
/// Decoder for the RunAndRecord RecordBatch columns blob.
///
/// Turns the opaque little-endian batch blob into structured vehicles and
/// traffic light signals so SDK users do not reimplement the binary parsing.
/// This module is always available and does not require the `server` feature).
// Re-export all generated types at crate root for convenience.
pub use *;