Commit 90fc63ed authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

optimization attempt

1 merge request!1Add Svn history
Showing with 16 additions and 14 deletions
+16 -14
......@@ -66,7 +66,7 @@ public class Grid extends Grid2D<Cell, Individual> {
// Lecture fichier contenant les HSI de toutes les mailles
String filePath = "data/input/HSI/hsi_BRO" + Time.getSeason() + marnageInit + ".txt";
Scanner scanner = new Scanner(new File(filePath));
Scanner scanner = new Scanner(new File(filePath));
// Initialisation de chaque cellule contenant HSI
// On boucle sur chaque ligne detecte
......@@ -171,7 +171,7 @@ public class Grid extends Grid2D<Cell, Individual> {
xPike = (position.getIndex() - (yPike * gridWidth));
// Determination de la liste des mailles pour une distance donnee qui depend de la phase du jour et de la saison
switch (Time.getSeason()) {
switch (Time.getSeason()) {
case "PRINTEMPS": switch (Time.getPhaseJour()) {
case "AUBE" : listeCoord = AreaMovement.areaPrinAube; break;
case "JOUR" : listeCoord = AreaMovement.areaPrinJour; break;
......@@ -221,21 +221,23 @@ public class Grid extends Grid2D<Cell, Individual> {
// Calcul des mailles comprises dans le lac
boolean stop = false;
for (int cpt=0; cpt<listeCoord[0].length; cpt++) {
if (listeCoord[0][cpt] == 0 & listeCoord[1][cpt] == 0 & stop == true) break;
if (listeCoord[0][cpt] == 0 & listeCoord[1][cpt] == 0) stop = true;
// Calcul de l'indice de la maille partir des coordonnees (x,y)
int newCell = xPike + listeCoord[0][cpt] + (yPike + listeCoord[1][cpt]) * gridWidth;
final int max = (gridWidth * gridHeight)-2;
for (int cpt=0; cpt<listeCoord[0].length; cpt++) {
int newCell = computeIndex(xPike, listeCoord, cpt, yPike);
// Test si l'indice calcule appartient la grille totale
if (newCell >= 0 & newCell <= (gridWidth * gridHeight)-2)
// Si l'indice calcule est compris dans le lac on l'ajoute a la liste
if (getCell(newCell).getHabitatQuality() >= 0)
neighbours.add(getCell(newCell));
if (newCell >= 0 && newCell <= max) {
final Cell cell = getCell(newCell);
// Si l'indice calcule est compris dans le lac on l'ajoute a la liste
if (cell.getHabitatQuality() >= 0) {
neighbours.add(cell);
}
}
}
return neighbours;
}
private int computeIndex(int xPike, int[][] listeCoord, int cpt, int yPike) {
return xPike + listeCoord[0][cpt] + (yPike + listeCoord[1][cpt]) * gridWidth;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment