Grid with some Squares being smaller than others

20 views
Skip to first unread message

Amélia Graber

unread,
Oct 5, 2025, 4:00:07 PMOct 5
to GAMA
Hello, 

I am trying to define a grid with square plots, where some of those squares are subdivided into smaller plots and some are kept larger. But with the following code, all squares are further subdivided and end up being of the same size. Why is this the case? And how could I only subdivide some squares?

Best,
Amélia

action build_square_plots {

list<geometry> plots_list <- to_squares(shape, shape.width / 2);

loop while: (plots_list with_max_of each.area).area > 200000#m2 {

geometry p <- (plots_list with_max_of each.area);

plots_list >> p;

plots_list <- plots_list + to_squares(p, p.width / 2);

}

float target_mean_area <- 1500#m2;

// Probabilistic correction: some plots are split further, not all

loop g over: copy(plots_list) {

float current_mean_area <- (plots_list mean_of each.area);

float prob <- (current_mean_area - target_mean_area) / target_mean_area;

prob <- max(0.0, min(1.0, prob)); // keep probability in [0,1]

if flip(prob) {

plots_list >> g;

plots_list <- plots_list + to_squares(g, g.width / 2);

}

}

brouillet_study_area_Till_Square_Plots.gaml

Benoit Gaudou

unread,
Oct 6, 2025, 2:30:05 AMOct 6
to gama-p...@googlegroups.com
Dear Amélia,
I tried your code and get indeed all the squares splitted.

I modified it a little bit to get the expected result:
I replaced : 

// Probabilistic correction: some plots are split further, not all

loop g over: copy(plots_list) {


by : 

// Probabilistic correction: some plots are split further, not all

list<geometry> l_c <- copy(plots_list);

loop g over: l_c {


So basically the copy of the list is made once before the call to the loop.
I am not sure to understand exactly what happened but I have the feeling that your copy was done at each loop ...

Cheers
Benoit

--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/gama-platform/5295b044-3948-4e55-9826-7a415af2ec45n%40googlegroups.com.

Amélia Graber

unread,
Oct 7, 2025, 8:33:55 AM (13 days ago) Oct 7
to GAMA
Dear Benoit,

Thank you for the quick answer! 

I am running into another problem: 
I am trying to make households chose their land use type depending on conditions (mostly based on their income). I want there to be only one land use possible per cycle, but with my if else loop, the statements of the first condition are run for pretty much all squares (which is fine), and then the statements of the else block are also run and overwrite the land use (which I do not want, only one set of statements should be run not the if and the else statements). I have triple checked with chat GPT and changing the statements in the blocks that my if-else logic does not contain mistakes, is there something GAMA specific that I could be doing wrong? 


reflex do_dry_land_use when:(season.current_season = DRY){

ask households {

myself.income <- myself.income + sum_of(my_plots , each.income_generated);

float additional_income <- 0.0;

loop plott over: copy(my_plots) {

if plott.soil_height > 0 {

float brick_income <- 0;

if self.income < self.min_income_hh {

float needed_income <- myself.min_income_hh - self.income;

int soil_layers_bricked <- 0;

ask plott {

land_use <- 5; // BRICK

int needed_layers <- ceil(needed_income / (area_plot * brick_income_p_layer));

soil_layers_bricked <- min(needed_layers, soil_height);

//brick_income <- area_plot*brick_income_p_layer * soil_layers_bricked; //ceil = round up; for now => bias towards reducing one plot completely and keep other plots with more soil, not some soil off each plot

soil_height <- soil_height - soil_layers_bricked;

}

brick_income <- plott.area_plot * brick_income_p_layer * soil_layers_bricked;

additional_income <- brick_income;

}

else if self.income >= self.min_income_hh {

bool market_worth_it <- (market_income* plott.area_plot - weight_dist_to_infra_market*plott.dist_to_water) > 0;

if market_worth_it {

ask plott {

land_use <- 2; // market gardening

}

additional_income <- plott.area_plot*market_income;

}

else if ! market_worth_it {

ask plott {

land_use <- 3; // bare land

}

}

}

}

else if plott.soil_height = 0 {

bool market_worth_it <- (market_income* plott.area_plot - weight_dist_to_infra_market*plott.dist_to_water) > 0;

if market_worth_it {

ask plott {

land_use <- 2; // market gardening

}

additional_income <- plott.area_plot*market_income;

}

else if !market_worth_it and self.income < min_income_hh {

float brick_income <- 0.0;

ask plott {

land_use <- 7;

brick_income <- area_plot*brick_income_p_layer * soil_height; //ceil = round up; for now => bias towards reducing one plot completely and keep other plots with more soil, not some soil off each plo

soil_height <- 0;

} // swamp because low soil and sold

additional_income <- brick_income + plott.price;

my_plots >> plott;

}

else if ! market_worth_it and self.income >= min_income_hh {

ask plott {

land_use <- 4; // swamp land (because low and not used)

}

}

}

}

self.income <- self.income + additional_income;

}

}

brouillet_study_area_Till_Square_Plots.gaml

Kevin Chapuis

unread,
Oct 7, 2025, 10:46:10 AM (13 days ago) Oct 7
to gama-p...@googlegroups.com
Dear Amelia,
The model is a bit dense for me to dig in but on the logic behind your if else statement, I can say that simplification can be made: for instance, try the most to keep the if else logic without adding another layer of conditions. That is, in your case, none of the "else if" conditions are required: you can simply use if self.income < self.min_income_hh {...} else if self.income >= self.min_income_hh {...}
You can duplicate the logic to all except the last one, which should be in cascade rather than a chain "if else if else if":

if market_worth_it {...}

else {

if income < min_income_hh {...}

else {...}

}

Best,
Kevin



--
Chapuis Kevin
Fellow researcher at IRD
Computer modeling & simulation
--
Alt-Mail: kevin.chapuis@ird.fr

Amélia Graber

unread,
Oct 14, 2025, 2:17:26 AM (7 days ago) Oct 14
to GAMA
Thank you for the answer!

Yes, that makes sense, they slipped in there as i was trying to debug the loop. 

I ended up creating actions and defining the order of actions in a reflex in the global species which fixed the problem.

Reply all
Reply to author
Forward
0 new messages