inside and various ways about overlaps

128 views
Skip to first unread message

Patrick Giraudoux

unread,
Aug 5, 2014, 4:05:57 AM8/5/14
to gama-p...@googlegroups.com
Hi,

Definitely I have a problem trying to implement functions using overlappings... What I want to do looks simple:

- I have grid cellPred
- I have a species called pred
- I have a polygon called zoneFav (imported shapefile) defined as a species

I want to create a number of pred both within the cells of cellPred and within the polygon zoneFav. I tried to do it with:

create pred number:nb_pred{
            list<cellPred> mysel<-cellPred inside(zoneFav);
            cellPred cellule_choisie <-one_of(mysel);
            my_cellPred<-cellule_choisie;
            location<-my_cellPred.location;
        }

But when preparing the simulation I get the following error



Can anybody tell me what is going wrong ?

Best,


Patrick Giraudoux

unread,
Aug 5, 2014, 4:11:55 AM8/5/14
to
Looks like the error image did not go through in my last message. You'll find it here:





Srirama Bhamidipati

unread,
Aug 5, 2014, 5:06:08 AM8/5/14
to gama-p...@googlegroups.com
Hi,

My remarks would be:


1. consider using overlapping operator, eg.  list<cellPred> mysel<-cellPred overlapping(zoneFav);
2. consider using any_location_in operator on your selected cells eg., location<-any_location_in(mysel); then the agent is placed randomly with the area enclosed by selected cells

you can also use union operator for the selected cells to avoid too much calculations by the model in further steps. I never tried, but for step 1, you could also try the intersection operator, so cellPred that intersect ZoneFav will form the selected cells on which you can apply a union and then any_location_in for placing your agents.

Of course youc an always wait for the comments from experts.

regards,
Srirama


Patrick Giraudoux

unread,
Aug 5, 2014, 5:34:28 AM8/5/14
to gama-p...@googlegroups.com
1. consider using overlapping operator, eg.  list<cellPred> mysel<-cellPred overlapping(zoneFav);

That one does not work either: length(mysel) is always 0, although a large number of cells in the cellPred grid visually overlap the polygon zoneFav

I am going to try solution 2... (will come back to to the list to give the result) but actually I would really like to understand why "our" previous command lines go wrong...

Best,

Patrick

Patrick Giraudoux

unread,
Aug 5, 2014, 5:45:13 AM8/5/14
to gama-p...@googlegroups.com
2. consider using any_location_in operator on your selected cells eg., location<-any_location_in(
mysel); then the agent is placed randomly with the area enclosed by selected cells

Does not work either. The syntax:

location<-any_location_in(zoneFav);

is not accepted and one should write:

location<-any_location_in(geometry(zoneFav));

However when launching the experiment, I got "fatal" errors only:













Will see what can be done with other operators...

Thanks anyway for the hints.

Patrick

Patrick Taillandier

unread,
Aug 5, 2014, 5:46:00 AM8/5/14
to gama-p...@googlegroups.com
Hi,

Just a question: what is zoneFav ? One agent or a species of agents? 

One thing, do not hesitate to use the "write" statement to better understand what is going on:

create pred number:nb_pred{
            list<cellPred> mysel<-cellPred inside(zoneFav);
            write "mysel:" + mysel;
            my_cellPred <-one_of(mysel);
             write "my_cellPred:" + my_cellPred;
            location<-my_cellPred.location;
            write "location:" + location;
        }

cheers,

Patrick


--
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 post to this group, send email to gama-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Patrick Giraudoux

unread,
Aug 5, 2014, 5:58:26 AM8/5/14
to gama-p...@googlegroups.com
Just a question: what is zoneFav ? One agent or a species of agents? 


zoneFav has been defined as following:

in global:

    file zonefavorable<-file("../includes/ZoneInf2500Romanche.shp");

in init

create zoneFav from:zonefavorable;

in entities

species zoneFav{
    string fonction;
    aspect geom {
        draw shape color:rgb(0,255,0,50);
    }
}

So strictly speaking zoneFav is a species of agent? Actually I have only one creation in the init.

One thing, do not hesitate to use the "write" statement to better understand what is going on:

Yes indeed. This is what I do actually to monitor eg length(mysel) after list<cellPred> mysel<-cellPred overlapping(zoneFav) (and get 0...)

Best,

Patrick




Patrick Taillandier

unread,
Aug 5, 2014, 6:03:26 AM8/5/14
to gama-p...@googlegroups.com
How many zoneFav agents do you have?

If you have only one, you can write something like:

in the global section:

init {
    ...
    create zoneFav from:zonefavorable;
    zoneFav la_zone_fav <- one_of(zoneFav);
    create pred number:nb_pred{
            list<cellPred> mysel<-cellPred inside(la_zone_fav);
            write "mysel:" + mysel;
            my_cellPred <-one_of(mysel);
             write "my_cellPred:" + my_cellPred;
            location<-my_cellPred.location;
            write "location:" + location;
        }

....

}


Just a question: how did you define the geometry (shape variable) of the world?

As you use shapefile, you have to write something like (in the global section):
  geometry shape <- envelope(zonefavorable);


Cheers,

Patrick



Patrick Giraudoux

unread,
Aug 5, 2014, 6:16:01 AM8/5/14
to gama-p...@googlegroups.com
How many zoneFav agents do you have?

Exactly one and in will not be more: this is just the area of the Haute Romanche vallee (parc des Ecrins) below 2500m of altitude where the rodents can live... and where the modelling take place (outside is rock and glaciers)

If you have only one, you can write something like:

in the global section:

init {
    ...
    create zoneFav from:zonefavorable;
    zoneFav la_zone_fav <- one_of(zoneFav);
    create pred number:nb_pred{

            list<cellPred> mysel<-cellPred inside(la_zone_fav);
            write "mysel:" + mysel;
            my_cellPred <-one_of(mysel);
             write "my_cellPred:" + my_cellPred;
            location<-my_cellPred.
location;
            write "location:" + location;
        }

OK. Clear. Will try it.


Just a question: how did you define the geometry (shape variable) of the world?

from the DEM 50 m resolution (it geographically includes zoneFav and the grid cell is generated from it) as following :

file mydem1<-file("../includes/DEM_Romanche_LIIres50.asc"); // X: 360 Y: 284
geometry shape <- envelope(mydem1); // X: 360 Y: 284


Thanks a lot ! Hope to reach an acceptable level of autonomy as soon as possible, not to bore people with very simple questions (anyway work hard for that...)... Would be nice to have some "yellow" books as we have many in R (I am a R user/developer)...

Thanks again for your time and support.

Best,

Patrick

Srirama Bhamidipati

unread,
Aug 5, 2014, 6:18:58 AM8/5/14
to gama-p...@googlegroups.com
Hallo,

I get 369 cells inside your zoneFav. I think the error is because you ask for cells before creating them. If you place your selection after creation of zoneFav, it works. Here you see it

                create fondVallee from:fondevallee;
create zoneFav from:zonefavorable;
zoneFav la_zone_fav <- one_of(zoneFav);
write zoneFav;
write la_zone_fav;
list<cellPred> testList <- cellPred inside(la_zone_fav);
write 'number of cells inside'+length(testList);

And result for write statements is 

zoneFav
zoneFav0
number of cells inside369

Patrick Giraudoux

unread,
Aug 5, 2014, 6:22:51 AM8/5/14
to gama-p...@googlegroups.com
Works perfect ! Exactly what I needed !

Now will take some time to digest all the steps and understand how it works exactly (and why I did not my statements did not work before). Excellent basis to start with.

Many thanks, Patrick

Patrick G.

Patrick Giraudoux

unread,
Aug 5, 2014, 6:29:39 AM8/5/14
to gama-p...@googlegroups.com
Indeed Srirama ! Thanks.

Srirama Bhamidipati

unread,
Aug 5, 2014, 6:36:57 AM8/5/14
to gama-p...@googlegroups.com
Hmm. Overlapping also works and results in 575 cells that includes the not completely inside (peripheral) cells :) :) 

Patrick Giraudoux

unread,
Aug 5, 2014, 7:21:50 AM8/5/14
to gama-p...@googlegroups.com
Good. Now we have two ways. One with partial overlap and one with overlap.

I was wondering if the "putative" concept of incomplete grid may work in GAMA. In our case, only the grid cells overlapping zoneFav (partially or totally) will be used for further computations. It would likely (?) save computation time if we can nullify (die ?) all the cells not overlapping zoneFav (they will never be used anyway). Wonder whether this idea is crazy or not... and if not how to do it...

Cheers,

Patrick




Alexis Drogoul

unread,
Aug 5, 2014, 9:34:54 AM8/5/14
to gama-p...@googlegroups.com
Hi,

Regarding saving computation time in an incomplete grid, there is no way to « deactivate » unused grid agents. However, if you dont define any update of attributes or any behaviors (reflexes, etc.) in the species, they will never be scheduled. And if you need to ask the used grid agents to do something, you can : define one or several actions in their species, build a global list of the grid agents that intersect the shape, and have a global reflex that asks this list to execute these actions.

Cheers
Alexis
> --
> 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 post to this group, send email to gama-p...@googlegroups.com.
> Visit this group at http://groups.google.com/group/gama-platform.
> For more options, visit https://groups.google.com/d/optout.

--
Senior Researcher, UMI UMMISCO 209, IRD & UPMC, France.
Invited Researcher, DREAM, Can Tho University, Viet Nam.
--
alexis....@gmail.com | http://tiny.cc/liqemw
[Vietnam] +84915088155 [France] +33608698845
--
GAMA: https://code.google.com/p/gama-platform/

Reply all
Reply to author
Forward
0 new messages