Skip to main content
Version: 🚧 Alpha 🚧

4. Weight for Road Network

This step assigns each road a destruction_coeff and uses it to weight the road graph. In the source model, the coefficient is initialized randomly between 1 and 2; the graph weight is the road perimeter multiplied by that coefficient.

Formulation​

  • Add a destruction_coeff variable to the road agent. The value of this variable is higher or equal to 1 or lower or equal to 2. At initialization, the value of this variable is randomly defined between 1 and 2.
  • In the road network graph, a higher destruction_coeff makes the route across a road more costly. The graph weight for a road is its perimeter multiplied by destruction_coeff.
  • The color of the road depends on the destruction_coeff. If "destruction_coeff = 1", the road is green, if "destruction_coeff = 2", the road is red.

Model Definition​

road agent​

The road species defines destruction_coeff between 1 and 2. It maps that value to red and green color components so the road color reflects the coefficient.

species road {
float destruction_coeff <- rnd(1.0,2.0) max: 2.0;
int colorValue <- int(255*(destruction_coeff - 1)) update: int(255*(destruction_coeff - 1));
rgb color <- rgb(min([255, colorValue]),max ([0, 255 - colorValue]),0) update: rgb(min([255, colorValue]),max ([0, 255 - colorValue]),0) ;

aspect base {
draw shape color: color;
}
}

weighted road network​

The model maps each road to its perimeter multiplied by destruction_coeff, then passes that map to with_weights when creating the graph.

global {
graph the_graph;

init {
create road from: shape_file_roads;
map<road, float> weights_map <- road as_map (each:: (each.destruction_coeff * each.shape.perimeter));
the_graph <- as_edge_graph(road) with_weights weights_map;
}
}

Complete Model​

gama.library/models/Tutorials/Road%20Traffic/models/Model%2004.gaml
loading...