Problems with experimental section

68 views
Skip to first unread message

Fidel

unread,
Oct 16, 2024, 5:36:16 PM10/16/24
to GAMA

In the output section of my GAMA experiment, I have the following code for a pie chart:

display "Statistics" type: 2d { chart "Agents per Zone" type: pie { loop z over: env.zones.keys { write "P"; data z value: robotThreshold count (each.assigned_zone = z) color: env.zone_colors[z]; } } }

The graph updates correctly (looping between zones), but it doesn't write anything to stdout. I want to add logical code (an if statement) to prevent the chart from being drawn during the first iteration when the data isn't available yet. I've tried using experiment conditions with a refresh, but a flag variable is ignored. I can't think of another way to achieve this. How can I prevent the chart from being drawn on the first iteration or simple add logic that can be executed?

The main problem is that I want to create a specific environment (which derives from another generic environment) within the experimental section (in its init), but I find that the output section is executed ¡before! the init of experiment, which forces me to declare it globally (and I don't think this is appropriate). 

Thanks!!

Fidel

unread,
Oct 24, 2024, 9:11:15 AM10/24/24
to GAMA
Here's the English translation:

Hello everyone, as I understand it's complicated to imagine the problem, I'm attaching an easy-to-test demo that I'd appreciate if someone experienced in [gama] could try. The idea is simple: shouldn't the environment be available to visualize from the first iteration? In the attached demo, it is NEVER visualized, which seems unintuitive to me. Is it like this due to some design consideration? I appreciate any comments. Thank you very much!
multienv_test.gaml

lesquoy....@gmail.com

unread,
Nov 16, 2024, 2:29:00 AM11/16/24
to GAMA
Hello Fidel and sorry for the late reply,

I tested your model and I think that it is acting exactly as expected.
What happens here is that the init block of AbstractEnv is called, it starts by calling the setup action of ConcretEnv2 which sets environment_ready to true, but when it's done we are back in the init block and set environment_ready back to false.
So the display is correctly saying that environment is not ready.
If you switch the two lines in the init it will work as you would expect.

Hope this helps,

Baptiste

Fidel

unread,
Dec 3, 2024, 5:28:13 AM12/3/24
to GAMA
Hi Baptiste,

Thank you for your response. You're right, the demo I added works with a simple change in order but I oversimplified the problem. While it's true that it works fine with the display, I'm having issues with the graphics plots.

In the example I attached, an error occurs because the environment is not ready (it's null) and I don't understand why this is happening. Additionally, when I try to filter for it to be different from null, the graph never gets drawn.

Do you have any idea what might be causing this behavior?

Best regards
multienv_test2.gaml

lesquoy....@gmail.com

unread,
Jan 20, 2025, 5:29:52 AMJan 20
to GAMA
Hello again Fidel and once again sorry for the late answer,

I think you found a bug in GAMA indeed I am not sure yet to what extent but it seems like a lot of variables in the chart statement are only evaluated once. Basically in your example the "env.ready" line is evaluated once (here it raises an exception but you would have a similar result if you change the condition to "cycle > 1" for example), then the result is "saved" and every cycle when it needs to be evaluated again, instead of looking for the current value of this expression, gama picks up the previously saved one.

I've created an issue on github for developers to fix it, you can follow its advancement here.

Regards,

Baptiste

Fidel

unread,
Jan 31, 2025, 4:19:25 AMJan 31
to GAMA
Perfect, I'll keep an eye on the bug. 
Thank you very much!

Reply all
Reply to author
Forward
0 new messages