VivaldiPosition positions[][] = new VivaldiPosition[ELEMENTS_X][ELEMENTS_Y];
Coordinates realCoordinates[][] = new Coordinates[ELEMENTS_X][ELEMENTS_Y];
//Init all
for(int i = 0 ; i < ELEMENTS_X ; i++) {
for(int j = 0 ; j < ELEMENTS_Y ; j++) {
realCoordinates[i][j] = new HeightCoordinatesImpl(i*DISTANCE,j*DISTANCE,MAX_HEIGHT);
positions[i][j] = new VivaldiPositionImpl(new HeightCoordinatesImpl(0,0,0));
}
}
//Main loop
for(int iter = 0 ; iter < MAX_ITERATIONS ; iter++) {
//For each node :
for(int i = 0 ; i < ELEMENTS_X ; i++) {
for(int j = 0 ; j < ELEMENTS_Y ; j++) {
VivaldiPosition position = positions[i][j];
//Pick N random nodes
for(int k = 0 ; k < NB_CONTACTS ; k++) {
int i1 = (int) (Math.random() * ELEMENTS_X);
int j1 = (int) (Math.random() * ELEMENTS_Y);
if(i1 == i && j1 ==j) continue;
VivaldiPosition position1 = positions[i1][j1];
float rtt = realCoordinates[i1][j1].distance(realCoordinates[i][j]);
position.update(rtt,position1.getCoordinates(),position1.getErrorEstimate());
}
if(iter == MAX_ITERATIONS -1) {
System.out.println(iter + " (" + i + "," + j + ") : " + realCoordinates[i][j] + " , " + position);
//System.out.println(position.getCoordinates());
}
}
}
}