find grid cell with_max at_distance

62 views
Skip to first unread message

Etienne DELAY

unread,
Jul 22, 2017, 10:17:37 AM7/22/17
to GAMA

Hi,
All keyword  in the subject ! I would like to find the "best" cell at the max distance of myself in a perception area.

reflex perception {
        /* Define the perception */
        perceived_area <- (cone((180+heading)-3#km,(180+heading)+3#km) intersection world.shape) intersection circle(perception_distance);
         if (perceived_area != nil) {
             myVisibility <- dem_cell overlapping perceived_area where(each.elevation < 179);
         }
         
    }
   
    reflex mvt {
        speed <- rnd(100.0)#km;
        if(myVisibility != nil){
          
                food_target <- point(one_of(myVisibility where(each.NDVI97 < 0.3 and each.NDVI97 > 0.2) at_distance perception_distance of myself));
   
        }
        if(self.location != target_travel.location){
            do goto target: food_target;
        }
 
    }

But it doesn't work ...

E.

Patrick Taillandier

unread,
Jul 23, 2017, 3:45:30 AM7/23/17
to gama-p...@googlegroups.com
Hi,

I am not sure to understand this part of the code: "perception_distance of myself". What is "myself" here for you? Why do you need the filter the list of cells "myVisibility' by the distance "perception_distance" whereas you use the same distance to compute myVisibility in the previous reflex?

I have some difficulties to understand what is "food_target" and what is "target_travel" as they seem to be used in quite random way in your code.

Here a proposition to make the code simplier and more readable:

 reflex mvt {
        speed <- rnd(100.0)#km;
        if(not empty(myVisibility)){
                 list<dem_cell> possible_cells <- myVisibility where ((each.NDVI97 < 0.3) and (each.NDVI97 > 0.2));
                food_target <- one_of(possible_cells).location;
    
        }
        if(self.location != target_travel.location){ //you need to check that
            do goto target: food_target;
        }
 
    }

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

Etienne DELAY

unread,
Jul 23, 2017, 6:17:22 AM7/23/17
to GAMA
Hi, 
Thank you for your effort of readability ! Here I would like to introduce a little bit of fuzz ... in order to be less "random".

* My agent selects a perception area
* In this perception area, he wants to find the farthest cell with a NDVI in is own needs
* Convert this cell in "food target"

That why I have tried to introduce a distance notion in my previous code.

E.


To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.

Patrick Taillandier

unread,
Jul 25, 2017, 2:50:05 AM7/25/17
to gama-p...@googlegroups.com
Hi,

Very simple: just modify :
food_target <- one_of(possible_cells).location;
by
food_target <- (possible_cells farthest_to self).location;

To unsubscribe from this group and stop receiving emails from it, send an email to gama-platform+unsubscribe@googlegroups.com.

Etienne DELAY

unread,
Jul 25, 2017, 4:45:08 AM7/25/17
to GAMA

Cool, and distance_to also work ? I imagine...

Why should you specified location ?

E.

Patrick Taillandier

unread,
Jul 25, 2017, 4:48:38 AM7/25/17
to gama-p...@googlegroups.com
Hi,

you can also use: 

food_target <- (possible_cells with_max_of (each.location distance_to self)).location;

I precise location, because (but I am not sure) that in your model, food_target is a variable of type point, so set its value by the location (centroid) of the chosen cell. If food_target is a cell and not a point, you have to remove the ".location".


To unsubscribe from this group and stop receiving emails from it, send an email to gama-platform+unsubscribe@googlegroups.com.

Etienne DELAY

unread,
Jul 25, 2017, 5:39:34 AM7/25/17
to GAMA
Would the gama send me an error if the "type" is wrong ?
Reply all
Reply to author
Forward
0 new messages