Model problem: Union of two agent shapes into one by distance and group

25 views
Skip to first unread message

Benjamin Mewes

unread,
Feb 22, 2017, 10:05:07 AM2/22/17
to GAMA
Imagine: I have several agents of a certain area (irregular shape). Given a condition, they can dissolve into subagents (which works already).

In the next reflex, they are allowed to merge (union) with those neighbors that have higher value of membership (mu). So, I have some questions you might help me with:


1. Right now, I find the corresponding neighbors via:

list<Objects> Neighbours update: self neighbors_at (sqrt(shape.area/2));



where Objects are my agents.I found no leaner way to find the nearest neighbors of the agents (those who "touch" its shape). Touches doesn't work in all cases, as some agents might not be topologically correct. Do you know any way to make this neighborhood detection better?

2. For joining, I analyse the corresponding neighbors from a list and union the shape of my agent with the shape of the neighboring agent that has a higher membership (mu):

                    if (Neighbor.group > self.group) {
                        geometry new_ar
<- (shape union Neighbor.shape );
                       
                        create
Objects {
                            shape
<- new_ar;
                            color
<- #orange;
                            originates_from
<< myself.name;
                            originates_from
<< Neighbor.name;                                
                            ma
<- true;
                       
}
                       
                        ask
Neighbor {
                            write name
+ " dies..";
                           
do die;
                       
}
                       
                        ask
self {
                            write name
+ " dies..";
                           
do die;
                       
}            
                   
}

For some irregular forms that need to be merged with dissolved agents in form of a square, a JST error occurs. Do you know a better strategy to merry agents?

Here's my complete model:
/**
* Name: dissolveSYN
* Author: xyz
* Description:
* Tags: Tag1, Tag2, TagN
*/


model dissolveSYN

/* Insert your model definition here */

global {
    file shape_file_gis_objects
<- shape_file('../includes/shp_syn_dis/dissolve_Polygons.shp');
    file grid_data
<- file("../includes/shp_syn_dis/grid.tif");
   
   
float min_area <- 10E2;
   
    geometry shape
<- envelope(grid_data);    
   
    init
{
       
        create
Objects from: shape_file_gis_objects {
           
group <- rnd(1.0);
            mu
<- rnd(1.0);
            color
<- #red;
       
}        
   
}
}

species
Objects {
   
float group;
   
    rgb color
;
   
float mu;
   
    list
<string>originates_from;

    list
<geometry> dissolved;
    list
<Objects> Neighbours update: self neighbors_at (sqrt(shape.area/2));
       
   
bool ma update: false;

    reflex dissolve
when: ((mu < 0.3) and (shape.area > min_area^2))  {
        dissolved
<- to_squares(self.shape,min_area);
        write name
+ " dissolves...";
       
        ma
<- true;
       
       
if(length(dissolved)!=0) {
           
            loop g over
: dissolved {
               
                create
Objects {
                    mu
<- rnd(1.0);
                    shape
<- g;
                    ma
<- true;
                    color
<- #blue;
                   
                    originates_from
<< myself.name;    
               
}
                       
           
}
           
            ask
self {
                write name
+ " dies...";
               
do die;
           
}
       
       
}
       
   
}
   
    reflex to_merge
{
       
        loop
Neighbor over: shuffle(Neighbours) {
               
if(Neighbor.ma != true){
                   
                   
if (Neighbor.group > self.group) {
                        geometry new_ar
<- (shape union Neighbor.shape );
                       
                        create
Objects {
                            shape
<- new_ar;
                            color
<- #orange;
                            originates_from
<< myself.name;
                            originates_from
<< Neighbor.name;                                
                            ma
<- true;
                       
}
                       
                        ask
Neighbor {
                            write name
+ " dies..";
                           
do die;
                       
}
                       
                        ask
self {
                            write name
+ " dies..";
                           
do die;
                       
}            
                   
}
           
}
           
       
}
   
}
   
   
    aspect colored_area
{
        draw shape color
: color border:#black;
   
}
   
}

grid cell file
: grid_data;

experiment dissolveAgents type
:gui {
        output
{
        display
AgentGRID {
                grid cell lines
:#black;
                species
Objects aspect:colored_area ;
               
}
               
       
}
               


       

}

The required data can be found here:https://dl.dropboxusercontent.com/u/24841978/dissolve.zip

.




Reply all
Reply to author
Forward
0 new messages