kill an agent contains in a cell

94 views
Skip to first unread message

Dimitry NGOUNOU

unread,
Oct 9, 2019, 3:52:17 AM10/9/19
to GAMA
Good morning all,
how to kill an agent contained in a cell

m <- one_of(species where ( each.location=l.location  )  );
 
if (m != nil)
{
m.die();
}

Alexis Drogoul (IRD)

unread,
Oct 9, 2019, 3:55:33 AM10/9/19
to GAMA
Hi,

Provided "c" is the cell and "s" is the species of the agents you want to kill: ask one_of(s inside c) {do die;} should do the trick.

Alexis


Rares

unread,
Dec 7, 2019, 12:47:21 PM12/7/19
to GAMA
Salut Alexis,

I've tried your line of code, gama platform seems to run it, but it's not providing desired results (kill the agent). function  write  dead_tree  returns only 0, so i guess is not running? as well agents are not killed on screen. Can you please give me feedback?


grid landcover {...}
species trees_54 {

      ask landcover {
        ask one_of (trees_54 inside landcover(grid_value = 1.0)) {
                if (myself.grid_value = 1.0) {
               
            dead_tree <- dead_tree +1;
               
            do die;
            }
            } 
        }
         
          if (every_cycle (3)) {
              write dead_tree;
          }




}

On Wednesday, 9 October 2019 09:55:33 UTC+2, Alexis Drogoul (IRD) wrote:
Hi,

Provided "c" is the cell and "s" is the species of the agents you want to kill: ask one_of(s inside c) {do die;} should do the trick.

Alexis

Le 9 oct. 2019 à 14:48, Dimitry NGOUNOU <tripot...@gmail.com> a écrit :

Good morning all,
how to kill an agent contained in a cell

m <- one_of(species where ( each.location=l.location  )  );
 
if (m != nil)
{
m.die();
}


--
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-p...@googlegroups.com.

Youcef Sklab

unread,
Dec 8, 2019, 3:20:29 PM12/8/19
to GAMA
Hi,
I think with the operator inside, you should provide the instance of the cell in which the agent you want to ask to die is inside. If you share your entire code, we could help you better.  

youcef

Rares

unread,
Dec 9, 2019, 10:18:57 AM12/9/19
to GAMA
Hi Youcef,
thank you for replying.

Could you please give me a syntax example of what do you mean? e.g. "should provide the instance of the cell in which the agent you want to ask to die is inside".  
The code has many lines and multiple files (point, landcover, DEM), and to share it here is will take couple of pages :), but in case is really necessary, then i will upload gladly.

Have a good day!
Rares

Youcef Sklab

unread,
Dec 9, 2019, 1:34:55 PM12/9/19
to GAMA
Hi,
Suppose you want to kill an agent inside the first cell, so, you could write:

 ask landcover {
        ask one_of (trees_54 inside landcover[0]) {

                      dead_tree <- dead_tree +1;
                       do die;
            }

In my understanding of the inside operator, to get the agents in a cell you should precise which cell is concerned (here for example: landcover[0])), and not a conditional expression that returns a list of cells ((trees_54 inside landcover(grid_value = 1.0)).  

so, it depends on the rest of your code to see how it would be possible to specify the cell of the agent to ask to die.  

Rares

unread,
Dec 11, 2019, 1:00:36 PM12/11/19
to GAMA
 your explanation made me understand. I did manage to get all list of cells position [grid_x, grid_y] and then add a condition regarding grid_value, and got the desired results.


grid landcover {
        reflex trees_bed_rock {
           
                ask one_of (trees_54 inside landcover [grid_x, grid_y]) {

                    if (myself.grid_value = 1.0) {  
                       
                        dead_tree <- dead_tree +1;   
                        do tree_die;
                    }
         
                }
            }
}

species trees_54 {...}


Output: landcover type grid species, where gray patch (grid_value = 1.0) is not suitable for trees_54 species (.shp)



P.S.   I've noticed as well that the code block ask landcover { }, was slowing considerable the simulation speed (of CPU), removed it and left  the code block  ask one_of (...) {..}
Reply all
Reply to author
Forward
0 new messages