FileDocCategorySizeDatePackage
VivaldiVisualTest.javaAPI DocAzureus 3.0.3.44583Tue Jun 06 06:30:48 BST 2006com.aelitis.azureus.core.dht.netcoords.vivaldi.ver1.impl.tests

VivaldiVisualTest

public class VivaldiVisualTest 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 VivaldiVisualTest()

  
    
    final Display display = new Display();
    Shell shell = new Shell(display);
    final VivaldiPanel panel = new VivaldiPanel(shell);
    shell.setLayout(new FillLayout());
    shell.setSize(800,800);
    shell.setText("Vivaldi Simulator");
    shell.open();
    
    Thread runner = new Thread("Viviladi Simulator") {
      public void run() {
        VivaldiPosition positions[][] = new VivaldiPosition[ELEMENTS_X][ELEMENTS_Y];
        final List lPos = new ArrayList(ELEMENTS_X*ELEMENTS_Y);        
        HeightCoordinatesImpl realCoordinates[][] = new HeightCoordinatesImpl[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-ELEMENTS_X * DISTANCE/2,j*DISTANCE-ELEMENTS_Y*DISTANCE/2,MAX_HEIGHT);
            if(i >= ELEMENTS_X / 2 && 1 == 0) {
              positions[i][j] = new VivaldiPositionImpl(realCoordinates[i][j]);
              positions[i][j].setErrorEstimate(0.01f);
            } else {
              positions[i][j] = new VivaldiPositionImpl(new HeightCoordinatesImpl(1000+DISTANCE*i,1000+DISTANCE*j,20)); 
            }
            
            lPos.add(positions[i][j]);
          }
        }
        
        //Main loop
        for(int iter = 0 ; iter < MAX_ITERATIONS ; iter++) {
          if(iter%100 == 0) System.out.println(iter);
          if(display.isDisposed()) return;
          display.syncExec( new Runnable() {
            public void run() {
              panel.refresh(lPos);
            }
          });
          try {
            //Thread.sleep(100);
          } catch (Exception e) {
            // TODO: handle exception
          }
          
          //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]);
                //rtt *= (Math.random() - 0.5)/20 + 1;  
                position.update(rtt,position1.getCoordinates(),position1.getErrorEstimate());
              }
              
            }
          }
          
        }
      }
    };
    runner.setDaemon(true);
    runner.start();
    
    while (!shell.isDisposed ()) {
      if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
  
Methods Summary
public static voidmain(java.lang.String[] args)

    new VivaldiVisualTest();