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.