FileDocCategorySizeDatePackage
VivaldiTest.javaAPI DocAzureus 3.0.3.43017Mon Apr 24 13:20:30 BST 2006com.aelitis.azureus.core.dht.netcoords.vivaldi.ver1.impl.tests

VivaldiTest

public class VivaldiTest extends Object

Fields Summary
private static final int
MAX_HEIGHT
private static final int
ELEMENTS_X
private static final int
ELEMENTS_Y
private static final int
DISTANCE
private static final int
MAX_ITERATIONS
private static final int
NB_CONTACTS
Constructors Summary
public VivaldiTest()

  
    
    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());
          }          
        }
      }
    }
  
Methods Summary
public static voidmain(java.lang.String[] args)

    new VivaldiTest();