Skip to main content
Version: 🚧 Alpha 🚧

Driving Skill

The driving extension represents roads, intersections and vehicles as agents. Its three skills are road_skill, intersection_skill and driving.

Build a road network​

Road agents represent directed roads between intersection agents. A road can have multiple lanes. For a two-way road, define a road in each direction and set each road's linked_road to the other; this lets vehicles use the lanes of the linked road when the model permits it.

The road_skill supplies source_node, target_node, num_lanes, maxspeed, and linked_road. Its all_agents variable lists the vehicles on that road; vehicle_ordering provides vehicle ordering by lane. The default values declared for num_lanes and maxspeed are 2 and 50 km/h.

Intersection agents use intersection_skill. The roads_in and roads_out variables identify incoming and outgoing roads. priority_roads, stop and block provide information used to model priority, stop rules and vehicles blocking an intersection.

Lane representation on a road

Add vehicles​

Create a graph from the road and intersection agents, then give vehicle agents the driving skill. A vehicle can compute a route to a target intersection and move along it with drive.

The following pattern is used by the simple traffic model included with the extension. It assumes nodes_shape_file and roads_shape_file are shape-file variables loaded from the network data. The model creates a reverse road for every road in the input data, links the two directions, builds the graph and assigns each vehicle a route:

global {
graph<geometry, geometry> road_network;

init {
create intersection from: nodes_shape_file;

create road from: roads_shape_file {
create road {
num_lanes <- myself.num_lanes;
shape <- polyline(reverse(myself.shape.points));
maxspeed <- myself.maxspeed;
linked_road <- myself;
myself.linked_road <- self;
}
}

road_network <- as_driving_graph(road, intersection);
create vehicle (location: one_of(intersection).location) number: 1000;
}
}

species road skills: [road_skill];
species intersection skills: [intersection_skill];

species vehicle skills: [driving] {
init {
vehicle_length <- 1.9 #m;
max_speed <- 100 #km / #h;
max_acceleration <- 3.5;
}

reflex select_next_path when: current_path = nil {
do compute_path (graph: road_network, target: one_of(intersection));
}

reflex commute when: current_path != nil {
do drive();
}
}

compute_path accepts a graph and either a target intersection or an ordered list of nodes. It returns the computed path, or nil if no valid path is found. The drive action requires a valid current path; the model should compute one before calling it. drive_random is available for movement that selects the next road randomly.

The driving skill exposes parameters such as vehicle_length, num_lanes_occupied, max_speed, max_acceleration, max_deceleration, time_headway, and lane-change settings. Their values can be set in the vehicle species or changed during a simulation. See the full Driving Skill documentation for the driving model, attributes and actions. The GAML editor also provides the skill's available attributes and actions while editing a model. For the road and intersection skills, see their reference entries and intersection reference.

For an in-depth description of the driving model, see the research article on the driving skill.