From 45baf656b8c4105c05f06c8e7acac58286cb15ec Mon Sep 17 00:00:00 2001 From: Denis Date: Sun, 9 Dec 2012 14:29:25 +0100 Subject: [PATCH] did some improvements --- .../P2P/uebungen/4/src/RandomGenerator.java | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/ws2012/P2P/uebungen/4/src/RandomGenerator.java b/ws2012/P2P/uebungen/4/src/RandomGenerator.java index 83af91a3..36701c20 100644 --- a/ws2012/P2P/uebungen/4/src/RandomGenerator.java +++ b/ws2012/P2P/uebungen/4/src/RandomGenerator.java @@ -11,7 +11,7 @@ import analysis.NetworkDumper; import node.Node; public class RandomGenerator { - public static int initNodeCount = 100; + public static int initNodeCount = 250; public static double initBirthRate = 0.50; public static double initDeathRate = 0.20; public static int initRounds = 13; @@ -25,6 +25,9 @@ public class RandomGenerator { * @throws IOException */ public static void main(String[] args) throws IOException { + double rate; + int add = 0; + int remove = 0; System.setProperty("java.util.logging.config.file", "logging.properties"); @@ -49,6 +52,7 @@ public class RandomGenerator { } switch (cmd) { + case "dump": nodes.get(0).gatherInformationOfNetwork(); try { @@ -89,9 +93,6 @@ public class RandomGenerator { System.out.println("Nodecount: " + nodes.size()); break; case "simulate": - double rate; - int add = 0; - int remove = 0; if (splitted.length > 1) { rate = Double.valueOf(splitted[2]); for (int i = 0; i < count; i++) { @@ -141,6 +142,39 @@ public class RandomGenerator { } System.out.println("Nodecount: " + nodes.size()); break; + case "prefsim": + if (splitted.length > 2) { + rate = Double.valueOf(splitted[2]); + int neighborcount = Integer.valueOf(splitted[3]); + for (int i = 0; i < count; i++) { + System.out.println("Round: " + i); + System.out.println("NodeCount: " + nodes.size()); + if (gen.nextDouble() < rate) { + add(1); + add++; + } + if (gen.nextDouble() < rate) { + removeWithNeighborCount(1, neighborcount); + remove++; + } + if (i % (count / 4) == 0) { + nodes.get(0).gatherInformationOfNetwork(); + try { + System.out.println(i); + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + NetworkDumper nd = new NetworkDumper(nodes.get(0)); + nd.write(nd.networkToDot(nodes.get(0).getNetwork())); + } + } + } + System.out.println("Nodecount: " + nodes.size()); + System.out.println("We added " + add + " Nodes"); + System.out.println("We removed " + remove + " Nodes"); + break; default: System.out.println("Unknown command."); break; @@ -153,14 +187,14 @@ public class RandomGenerator { if (nodes.size() == 0) { Node newNode = new Node(); nodes.add(newNode); - neighborCount.add(0); + neighborCount.add(1); } else { int index = gen.nextInt(nodes.size()); Node newNode = nodes.get(index).spawn(); neighborCount.set(index, neighborCount.get(index).intValue() + 1); nodes.add(newNode); - neighborCount.add(0); + neighborCount.add(1); } }