Expand description
This is a simple traffic simulation module with a focus on performance and realism.
This is a personal project, with currently poor documentation and is not quite feature complete.
§Goals
The goal of this package is to be capable of simulating any road network in a realistic manner, with reasonable performance. This includes simulating things such as:
- Car following
- Lane-changing decisions and dynamics
- Yielding at give way/stop signs
- Merging and diverging
- Simple path finding
The primary gap right now is the lack of a lane-changing. There are pieces in place, but it is in general a very hard problem to solve.
§Hello world
This sample code demonstrates how to simulate a single vehicle on a straight, single-lane road.
use traffic_sim::{Simulation, LinkAttributes, VehicleAttributes};
use traffic_sim::math::{LineSegment2d, Point2d};
// Create a simulation
let mut simulation = Simulation::new();
// Add a link, which is a single lane of traffic
// This one is a straight line 100m long
let link_id = simulation.add_link(&LinkAttributes {
curve: &LineSegment2d::from_ends(Point2d::new(0.0, 0.0), Point2d::new(100.0, 0.0)),
speed_limit: 16.6667, // m/s (60km/h)
});
// Add a vehicle to the start of the link we just created
let veh_id = simulation.add_vehicle(&VehicleAttributes {
width: 2.0, // m
length: 5.0, // m
wheel_base: 1.5, // m
max_acc: 2.0, // m
comf_dec: 2.0, // m
}, link_id);
// Simulate 10 frames, each advancing time by 0.1s.
// Each frame, print out the coordinates of our single vehicle
for _ in 0..10 {
simulation.step(0.1);
println!("Vehicle is at {:?}", simulation.get_vehicle(veh_id).position());
}
Re-exports§
pub use cgmath;
Modules§
- math
- Mathematical structs and functions.
Structs§
- Interval
- An interval on the real number line.
- KeyData
- The actual data stored in a
Key
. - Link
- A link represents a single lane of traffic.
- Link
Attributes - The attributes of a link.
- Link
Group - A set of adjacent links. Lane changing is only permitted between members of a link group.
- LinkId
- Unique ID of a Link.
- Simulation
- A traffic simulation.
- Traffic
Light - A set of coordinated traffic lights.
- Traffic
Light Id - Unique ID of a TrafficLight.
- Vehicle
- A simulated vehicle.
- Vehicle
Attributes - The attributes of a simulated vehicle.
- Vehicle
Id - Unique ID of a Vehicle.
Enums§
- Traffic
Control - A traffic control.
Traits§
- Key
- Key used to access stored values in a slot map.