1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| public void calculGREG() {
// recherche de la distance entre 2 individus contigus :
System.out.println("Gregarisme : calculating distances between individuals ...");
double r_min;
for (int p = 0; p < Pop.size(); p++) {
Poissons Po = (Poissons) Pop.get(p);
int nbre_voisins = 0;
// Rayon minimum pour avoir un seul voisin :
r_min = 0; //on le fixe a 0, puis on l'augmentera dans la boucle while jusqu'a ce qu'on trouve un voisin
// nombre de voisins dans ce rayon r_min:
while (nbre_voisins < 2) {
r_min = r_min + 0.1;
nbre_voisins = 0;
for (int v = 0; v < Pop.size(); v++) {
Poissons voisin_potentiel = (Poissons) Pop.get(v);
double Px = voisin_potentiel.x - Po.x;
double Py = voisin_potentiel.y - Po.y;
double rayonCarre = (Px * Px + Py * Py);
if (rayonCarre < r_min * r_min) {
nbre_voisins = nbre_voisins + 1;
}
}
}
Po.DistVoisin_init = r_min;
// fin de la recherche de dist entre indiv contigus
//System.out.println("Po.DistVoisin_init =" + Po.DistVoisin_init);
}
} |
Partager