How to know if the 'species' overlaps a geometry: myself cannot be used

137 views
Skip to first unread message

Patrick Giraudoux

unread,
Aug 4, 2014, 10:40:38 AM8/4/14
to gama-p...@googlegroups.com


I am trying to introduce a condition in one of the reflex of a species (called here ater), by:

if ((myself overlaps zoneFav) and !(myself overlaps fondVallee) and  (countRep>1)){
         countRep<-1;   
}

In clear, if the agents is included in the geometry zoneFav and not included in fondVallee (defined as species), I want its reproduction count be 1.

However an error occur telling "the variable myself is not defined or accessible in this context. Check its name or declare it". The message is quite clear, but I wonder where the declaration is appropriate and how to declare it.

Thanks for any hint,

Patrick

Patrick Taillandier

unread,
Aug 4, 2014, 10:43:35 AM8/4/14
to gama-p...@googlegroups.com
Hi,

You should use "self" instead of "myself".

Some explanations about self and myself: https://code.google.com/p/gama-platform/wiki/G__PseudoVariables

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 4, 2014, 11:16:01 AM8/4/14
to gama-p...@googlegroups.com
Great ! Thanks.  I am a newbie and must admit that the appropriate use of "self" and "myself" is not under full control yet...

Best,

Patrick

Patrick Giraudoux

unread,
Aug 4, 2014, 11:28:18 AM8/4/14
to gama-p...@googlegroups.com
Well, it does not like "self" either, but for another (good) reason: self is well recognised as a "pseudo-variable self of type ater Represents the current agent, instance of species ater", BUT "No operator found for applying 'overlaps' to types [ater, species] (operators available for [types [geometry, geometry]])". I suspect that may be due to its aspect definition:

aspect base {
        if(is_infected){
            draw circle (50.0) color:#red;
        }
        else {
            draw circle(50.0) color:#green;
        }
    }


But I am not sure (I got an example where overlapping() - not overlaps - was working with no geoemtry clearly defined. Any suggestion about where and how to define a geometry for a species that would make it accepted using overlaps ? ater is expected to be a vole (a rodent), but cannot be drawn at real size, since it must be seen during the simulations...

Patrick Giraudoux

unread,
Aug 4, 2014, 11:52:28 AM8/4/14
to gama-p...@googlegroups.com
It does not like:

   
        if ((circle(1) overlaps zoneFav) and !(circle(1) overlaps fondVallee) and (countRep>1)){
         countRep<-1;   
        }

For the same reason: "No operator found for applying 'overlaps' to types [geometry, species] (operators available for [types [geometry,
 geometry]])".

Hard to understand: zoneFav and FondVallee are two species built  from imported shapefile, with in init:

create fondVallee from:fondevallee;
create zoneFav from:zonefavorable;

and as species:

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


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

Patrick Giraudoux

unread,
Aug 4, 2014, 12:02:53 PM8/4/14
to gama-p...@googlegroups.com
This seems to be syntaxically correct:

if ((geometry(self) overlaps geometry(zoneFav)) and !(geometry(self) overlaps geometry(fondVallee)) and (countRep>1)){
         countRep<-1;   
        }

... but I wonder about the result: I do not know about the exact "geometries" that have been "extracted"... Hope it is the real polygon shape (and not the bounding box or whatever) for zoneFav and fondVallee and that the geometry of self is a point (?) or something close to...

Any idea on it ?

Thanks in advance,

Patrick

Patrick Taillandier

unread,
Aug 4, 2014, 1:06:33 PM8/4/14
to gama-p...@googlegroups.com
Hi,

To be honest, It is quite difficult to help you with just some parts of your model. If you want for us to help you more efficiently, do not hesitate to attached to your mail your complete model (or at least, a simplified version of it).

So some answers:

  if ((circle(1) overlaps zoneFav) and !(circle(1) overlaps fondVallee) and (countRep>1)){
         countRep<-1;    
        }


The "overlaps" operator can only be used for geometry/agent and cannot be used for species (or list of agents). In your case, if you want to know if a agent/geometry overlaps at least one agent of a species species, you can use the "overlapping" operator that returns a list of agents of a specific species that overlaps a specific agent/geometry:

if not (empty(zoneFav overlapping self) and empty(fondVallee overlapping self)){
         countRep<-1;    
        }
 

You can replace self by circle(1) if you prefer (slower in terms of computation).

Concerning:
if ((geometry(self) overlaps geometry(zoneFav)) and !(geometry(self) overlaps geometry(fondVallee)) and (countRep>1)) 
if should work (with the real geometries), but it is very very slow as it require to compute the union of zoneFav geometries and fondVallee geometries before testing the overlaps operator.....

Some docs about:

Cheers,

Patrick




2014-08-04 18:02 GMT+02:00 Patrick Giraudoux <patrick....@univ-fcomte.fr>:

--

Srirama Bhamidipati

unread,
Aug 4, 2014, 1:55:51 PM8/4/14
to gama-p...@googlegroups.com
Hallo Patrick G,

Yes, I use overlapping for identifying species on geometries, and its works perfect for me. If you see my other post titled "unable to label voronoi polygons", you will see I use : polygons overlapping(self) where polygons is a species and you can also see use of self. You can copy paste the model and play. 

cheers
Srirama

Patrick Giraudoux

unread,
Aug 4, 2014, 3:36:16 PM8/4/14
to gama-p...@googlegroups.com
If you want for us to help you more efficiently, do not hesitate to attached to your mail your complete model (or at least, a simplified version of it).

Sorry not to have done it before, but I was afraid of boring you (and other people on the list) with too many details time consuming to read. You have all the necessary documents here attached. Actually I had a fantastic training at Besançon in July organized by Nicolas Marilleau and colleagues, and I am just building a pilot model about my own training and research issue (further collaboration with specialists, including Nicolas, on schedule). I am quite enthusiastic about multi-agent modelling in a spatially explicit context, which seems to correspond quite exactly to what we currently need for the questions we want to address in landscape ecology and population dynamics.

My need here is to find a way to know if the location of a given individual of a given species (here a "vole" in the real world) is or is not within the boundaries of geometry imported from a shapefile. Any operator providing the value true/false welcome (the shorter the computing time, the better).


That is what I believed to have done lines 222-223, but this is likely not optimal "it should work (with the real geometries), but it is very very slow as it require to compute the union of zoneFav geometries and fondVallee geometries before testing the overlaps operator.....". Will carefully check the threads you gave.

Many thanks for your hints and the time taken.

Best,

Patrick




Volefiles.zip

Patrick Giraudoux

unread,
Aug 4, 2014, 3:38:36 PM8/4/14
to gama-p...@googlegroups.com
Thanks Srirama, too. I will see that carefully.

Best,

Patrick

Patrick Giraudoux

unread,
Aug 4, 2014, 4:03:12 PM8/4/14
to gama-p...@googlegroups.com
if (not empty(zoneFav overlapping self) and empty(fondVallee overlapping self) and (countRep>1)){
         countRep<-1;   
        }



Should make it... self is included in zoneFave but not in fondVallee...

Thanks a lot. This makes overlaps and overlapping clearer to me...

Best,

Patrick
Reply all
Reply to author
Forward
0 new messages