Skip to content

Commit

Permalink
Add a simple example of usage of the driving skill
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaillandier committed May 7, 2022
1 parent 8c0ba94 commit 27d562b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 5 deletions.
Expand Up @@ -15,8 +15,8 @@ global {
float step <- 0.2#s;

string map_name;
file shp_roads <- file("../includes/" + map_name + "/roads.shp");
file shp_nodes <- file("../includes/" + map_name + "/nodes.shp");
file shp_roads <- file("../../includes/" + map_name + "/roads.shp");
file shp_nodes <- file("../../includes/" + map_name + "/nodes.shp");

geometry shape <- envelope(shp_roads) + 50;

Expand Down
Expand Up @@ -15,8 +15,8 @@ global {
float step <- 0.1 #s;

string map_name <- "rouen";
file shp_roads <- file("../includes/" + map_name + "/roads.shp");
file shp_nodes <- file("../includes/" + map_name + "/nodes.shp");
file shp_roads <- file("../../includes/" + map_name + "/roads.shp");
file shp_nodes <- file("../../includes/" + map_name + "/nodes.shp");

geometry shape <- envelope(shp_roads) + 50;

Expand Down
@@ -0,0 +1,75 @@
/**
* Name: Traffic
* Description: define species for traffic simulation
* Author: Patrick Taillandier & Duc Pham
* Tags: driving skill, graph, agent_movement, skill, transport
*/

model simple_traffic_model

global {
shape_file nodes_shape_file <- shape_file("../../includes/rouen/nodes.shp");
shape_file roads_shape_file <- shape_file("../../includes/rouen/roads.shp");

geometry shape <- envelope(roads_shape_file);
graph road_network;
init {
create intersection from: nodes_shape_file;

create road from: roads_shape_file {
// Create another road in the opposite direction
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 number: 1000 with: (location: one_of(intersection).location);
}

}

species road skills: [skill_road] {
rgb color <- #white;

aspect base {
draw shape color: color end_arrow: 1;
}
}

species intersection skills: [skill_road_node] ;

species vehicle skills: [advanced_driving] {
rgb color <- rnd_color(255);
init {
vehicle_length <- 1.9 #m;
max_speed <- 100 #km / #h;
max_acceleration <- 3.5;
}

reflex select_next_path when: current_path = nil {
// A path that forms a cycle
do compute_path graph: road_network target: one_of(intersection);
}

reflex commute when: current_path != nil {
do drive;
}
aspect base {
draw triangle(5.0) color: color rotate: heading + 90 border: #black;
}
}

experiment city type: gui {
output {
display map type: opengl background: #gray synchronized: true {
species road aspect: base;
species vehicle aspect: base; }
}
}
Expand Up @@ -14,7 +14,7 @@ global{
map filtering <- map(["highway"::["primary", "secondary", "tertiary", "motorway", "living_street","residential", "unclassified"]]);

//OSM file to load
file<geometry> osmfile <- file<geometry>(osm_file("../includes/rouen.gz", filtering)) ;
file<geometry> osmfile <- file<geometry>(osm_file("../../includes/rouen.gz", filtering)) ;

geometry shape <- envelope(osmfile);
graph the_graph;
Expand Down

0 comments on commit 27d562b

Please sign in to comment.