-
I'm very new to GAMA. I have worked through the tutorials and am now trying out a small project. This is some of my code so far:
I'm trying to replicate the code from the Road Traffic tutorial but placing people in any building rather than just a specific type - per the tutorial:
I'm getting an error message next to the 'location' line. Any help would be appreciated. Thanks, K |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hi,
You cannot use the operator "any_location_in" for a list, it is supposed to
be used with an agent or a geometry. If you want to locate the people
agents inside the building, you have to use the keyword "myself" to refer
to the building.
create building from: shape_file_buildings {
color <- #green;
create people number: nb_people {
location <- any_location_in(myself);
}
}
Cheers,
Patrick
Le ven. 24 mai 2024 à 22:49, kmamor ***@***.***> a écrit :
… I'm very new to GAMA. I have worked through the tutorials and am now
trying out a small project. This is some of my code so far:
model MK
global {
file shape_file_roads <- shape_file("../includes/MK_roads.shp");
file shape_file_buildings <- shape_file("../includes/MK_buildings.shp");
geometry shape <- envelope(shape_file_roads);
graph the_graph;
int nb_people <- 200;
init {
create roads from: shape_file_roads ;
the_graph <- as_edge_graph(roads);
create building from: shape_file_buildings {
color <- #green ;
create people number: nb_people {
list<building> building_list ;
location <- any_location_in (building_list);
}
}
}
}
species roads {
rgb color <- rgb (255,0,127) ;
aspect base {
draw shape color: color ;
}
}
species building {
rgb color <- #blue ;
aspect base {
draw shape color: color ;
}
}
species people skills: [moving] {
rgb color <- #red ;
aspect base {
draw circle(10) color: color border: #black;
}
}
experiment MK type: gui {
output {
display city_display {
/**
species roads aspect: base ;
*
*/
species building aspect: base;
species people aspect: base ;
}
}
}
I'm trying to replicate the code from the Road Traffic tutorial but
placing people in any building rather than just a specific type - per the
tutorial:
list<building> residential_buildings <- building where (each.type="Residential");
create people number: nb_people {
location <- any_location_in (one_of (residential_buildings));
}
I'm getting an error message next to the 'location' line. Any help would
be appreciated.
Thansk,
K
—
Reply to this email directly, view it on GitHub
<#184>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALPWHIRRXF63IM44YLD6GTZD5ORNAVCNFSM6AAAAABIH2ELVGVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZWG4ZDINJXGY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Thanks Patrick for responding - your suggestion works. I want to understand the tutorial a bit more. If I code:
I get an error. The shapefile is taken from OSM via QCIS and has an attribute 'building' of which one of the tags is 'house' . I thought I was simply copying the code from the tutorial (Road Traffic):
Where I assume the shapefile has an attribute 'type' with a tag 'residential'. Why is mine not working? Also should I be able to form a list of the entire 'building' file by coding something like:
Thanks, K |
Beta Was this translation helpful? Give feedback.
-
Hi,
To be able to use the "building" attribute in the shapefile, you need to
define a "building" variable for the building. However, it is not advisable
to have a variable with the same name as a species. It is preferable to
define a variable with another name (for example type) and to make the link
with the data in the shapefile using the "get" operator.
So, you can define the building species like this:
species building {
rgb color <- #blue;
string type;
aspect base {
draw shape color: color;
}
}
And create the building agents like this:
create building from: shape_file_buildings with: (type:get("building")){
color <- #green;
create people number: nb_people {
location <- any_location_in(myself);
}
}
Cheers,
Patrick
|
Beta Was this translation helpful? Give feedback.
That runs but is creating (a lot!) more than 200 people(nb_people = 200). I think that because the create people is coded within the create building section then each time a building is created so too are 200 people. What I'm hoping for is the buildings per the shapefile to be created and then 200 people are spread randomly over those. I think I need to separate the create building and create people. The following I think is achieving this (using code from the incremental model):
Thanks ag…