gama-platform / gama.old

Main repository for developing the 1.x versions of GAMA
GNU General Public License v3.0
300 stars 99 forks source link

restrict and order sequence of GRID neighbors #1870

Closed sriramab closed 8 years ago

sriramab commented 8 years ago

Steps to reproduce

  1. Open any grid model, make sure you create another species (not grid) of the same grid
  2. Check the neighbors of a cell. a) right click a cell and inspect its neighbours b) open attribute table and select the same cell and inspect its neighbors c) create an attribute to collect a list of neighbours of the same cell d) now do the same three above with the species layer
  3. In all cases, the neighbours are the same, but their sequence is different.
  4. Moreover, even if you stick to any one method of inspecting, close the inspect window, open it again with the same method, the results is different sequence of cells.

    Expected behaviour

I am trying to replicate some ArcGIS type raster operations and I would like that this sequence is restricted/ controlled in clockwise or anti-clockwise direction because it is affecting my calculation every time I call list of neighbours. I fear hard coding a sequence of cells will give different results every time. May be it can be corrected with some internal random seed that controls the sequence of neighbors.

Actual behaviour

different sequence of neighbor cells generated every time.

System and version

MacOS X Mavericks, java 8, gama standalone

AlexisDrogoul commented 8 years ago

Well, the ordering of the grid neighbors has been the object of long debates over the years, if I remember well. It was once fixed, and we decided to make it different at each call, but I dont really remember why (probably to avoid some side effects due to the ordering). I think @benoitgaudou participated to this debate and was in favor of returning randomized lists -- maybe he can shed a light on this issue ?

sriramab commented 8 years ago

Hmm, getting a predictable order can be useful to use many ArcGIS like raster operations (window and focal statistics and some others from spatial analyst) in GAMA.

hqnghi88 commented 8 years ago

Hi, just an idea about the grid, which is related with my work with Benoit in the past, is the diffusion on the grid. I think that i had impression that randomized order give more likely effect of a parallele diffusion. Cheers.

sriramab commented 8 years ago

Hmm, I wonder, because the first step for diffusion of soil (landslides, soil erosion) or water(flood) would need a fixed sequence to apply algorithms. And recently for this task I was reading some CA models and having an order would help a lot.

Unless of course if u meant some other kind of diffusions and algorithms within gama.

AlexisDrogoul commented 8 years ago

I'm afraid there is nothing we will do on this issue. neighbors is computed in such a way that the result is always randomized, using GAMA random number generator, so that (1) we avoid the side effects of having the neighbors always returned in the same order; (2) it is still replicable if you run the same simulation with the same seed and generator. That said, why dont you declare your own attribute (e.g. list<cell> fixed_neighbors <- neighbors sorted_by (each direction_to self); or anything like this) and use this one instead of neighbors ?

sriramab commented 8 years ago

yes I tried that yesterday, it is buggy. I will report an issue. thank you

sriramab commented 8 years ago

Also I would like to report, that with same seed and generator, the sequence differs every time you run the model. that is why I am puzzled. I am defining seed in experiment, is that the right way? experiment floodBates type: gui { /* Insert here the definition of the input and output of the model / float seed <- 0.5140073008712904; output { display bates type: opengl ambient_light: 100 { species cell aspect: box; grid cell triangulation: true; //lines:#black; }

}

}

AlexisDrogoul commented 8 years ago

You define the seed where you want it to be fixed. If you define it in experiment and dont fix it in simulations, then the simulation seeds will be randomly produced using the experiment seed. If you want to obtain a repeatable sequence of neighbors, you have to define your seed in global.

sriramab commented 8 years ago

I will explore a bit, because even a reflex causes a change not just experiment. :( a bit confusing ... Thank you, I come back later.