public static Network initParamFromFile(Network n, String fileName) throws Exception {
    n = LtWeightInitiator.initParam(n, 0.0);

    BufferedReader br = new BufferedReader(new FileReader(fileName));
    String tmpLine = null;
    while (true) {
      tmpLine = br.readLine();
      if (tmpLine == null) break;
      String[] tmp = tmpLine.split("\t");
      Long from = Long.parseLong(tmp[0]);
      Long to = Long.parseLong(tmp[1]);
      double value = Double.parseDouble(tmp[2]);
      Long rid = n.findEdge(from, to);
      if (rid == null) continue;
      Relation r = n.getRelation(rid);
      r.setLtWeight(value);
    }
    br.close();

    /*Collection<LinkUnit> linkWeights = IOUtility.readLinkValue( fileName );
    for( LinkUnit linkunit : linkWeights ){
    	Integer from = linkunit.getFrom();
    	Integer to = linkunit.getTo();
    	double value = linkunit.getValue();
    	Integer rid = n.findEdge( from , to );
    	Relation r = n.getRelation( rid );
    	r.setLtWeight( value );
    }
    */
    return n;
  }
Exemple #2
0
  private void runAnt(int weightPh) {
    GeographicTopography gt = new GeographicTopography(seed, 10, 2.0, 5);
    AntRouter ar = new AntRouter(weightPh, 1.0, 1.0, .1, 1.0, "AdHocPheromones.csv");

    Node a = gt.getRandomNode();
    Node b = gt.getRandomNode();
    while (a == b) b = gt.getRandomNode();

    Topography t = gt;
    Router r = ar;
    Mailer m = new SimpleMailer(a, b);

    Network n = new Network(t, r, m, 10, 100, 20);
    // System.out.println(n);

    ConclusionMonitor arcm = new ConclusionMonitor();
    n.registerMonitor(arcm);
    n.registerMonitor(ar);
    // n.registerMonitor(new PrintMonitor());
    n.registerMonitor(new CsvMonitor("AdHocAntRouter.csv"));

    n.run(10000);

    System.out.println("Ant Router " + weightPh);
    arcm.printStats();
  }
 /**
  * Assign Ic Probability ofr network n.
  *
  * @param n input network
  * @param w init weight
  */
 public static Network initParam(Network n, double w) {
   for (Long rid : n.getEdges()) {
     Relation r = n.getRelation(rid);
     r.setLtWeight(w);
   }
   return n;
 }
 public static double getVertexCount(Network forest, Collection<Long> a0) {
   int count = 0;
   for (Long v : forest.getVertices()) {
     if (!a0.contains(v)) {
       count++;
     }
   }
   return (double) count;
 }
Exemple #5
0
 public void paint(Graphics window) {
   window.setColor(Color.WHITE);
   window.fillRect(0, 0, getWidth(), getHeight());
   window.setColor(Color.black);
   scan = new Scanner(net.recieve(false));
   int x = scan.nextInt();
   int y = scan.nextInt();
   System.out.println(x + " " + y);
   window.fillRect(x, y, x + 50, y + 50);
 }
Exemple #6
0
  public void run() {
    seed = new Random().nextLong();

    System.out.println("AdHocTest");
    System.out.println("Running Test with BF Router");
    GeographicTopography gt = new GeographicTopography(seed, 10, 2.0, 5);
    HashBFRouter hbf = new HashBFRouter();

    Node a = gt.getRandomNode();
    Node b = gt.getRandomNode();
    while (a == b) b = gt.getRandomNode();

    Topography t = gt;
    Router r = hbf;
    Mailer m = new SimpleMailer(a, b);

    Network n = new Network(t, r, m, 10, 100, 20);
    // System.out.println(n);

    for (int i = 0; i < 100; i++) r.updateRouter();

    ConclusionMonitor bfcm = new ConclusionMonitor();
    n.registerMonitor(bfcm);
    // n.registerMonitor(new PrintMonitor());
    n.registerMonitor(new CsvMonitor("AdHocHashBFRouter.csv"));

    n.run(10000);

    System.out.println("BF Router");
    bfcm.printStats();

    System.out.println("Running Test with Ant Router");

    runAnt(5);
    /*
    for (int i = 5; i < 51; i+=5) {
        runAnt(i);
    }
    */

  }
Exemple #7
0
 public static void main(String[] args) {
   Network meh = new Network();
   while (true) {
     System.out.println(meh.recieve(false));
   }
 }
 public static double getEdgeCount(Network forest) {
   return (double) forest.getEdgeCount();
 }