Author: toad
Date: 2008-02-09 14:57:29 +0000 (Sat, 09 Feb 2008)
New Revision: 17755

Modified:
   trunk/freenet/src/freenet/node/simulator/RealNodeNetworkColoringTest.java
   trunk/freenet/src/freenet/node/simulator/RealNodeRoutingTest.java
   trunk/freenet/src/freenet/node/simulator/RealNodeTest.java
Log:
Add option to always link neighbours.
Use the code for RealNodeRoutingTest too.

Modified: 
trunk/freenet/src/freenet/node/simulator/RealNodeNetworkColoringTest.java
===================================================================
--- trunk/freenet/src/freenet/node/simulator/RealNodeNetworkColoringTest.java   
2008-02-09 14:52:30 UTC (rev 17754)
+++ trunk/freenet/src/freenet/node/simulator/RealNodeNetworkColoringTest.java   
2008-02-09 14:57:29 UTC (rev 17755)
@@ -109,8 +109,8 @@
         Logger.normal(RealNodeRoutingTest.class, "Created "+totalNodes+" 
nodes");

         // Now link them up
-        makeKleinbergNetwork(subnetA, true /* make it easy, we're not testing 
swapping here */, DEGREE);
-               makeKleinbergNetwork(subnetB, true /* make it easy, we're not 
testing swapping here */, DEGREE);
+        makeKleinbergNetwork(subnetA, true /* make it easy, we're not testing 
swapping here */, DEGREE, false);
+               makeKleinbergNetwork(subnetB, true /* make it easy, we're not 
testing swapping here */, DEGREE, false);

         Logger.normal(RealNodeRoutingTest.class, "Added small-world links, 
weakly connect the subnets");


Modified: trunk/freenet/src/freenet/node/simulator/RealNodeRoutingTest.java
===================================================================
--- trunk/freenet/src/freenet/node/simulator/RealNodeRoutingTest.java   
2008-02-09 14:52:30 UTC (rev 17754)
+++ trunk/freenet/src/freenet/node/simulator/RealNodeRoutingTest.java   
2008-02-09 14:57:29 UTC (rev 17755)
@@ -28,9 +28,10 @@
  * 
  * Then run some node-to-node searches.
  */
-public class RealNodeRoutingTest {
+public class RealNodeRoutingTest extends RealNodeTest {

     static final int NUMBER_OF_NODES = 50;
+    static final int DEGREE = 5;
     static final short MAX_HTL = (short)7;

     public static void main(String[] args) throws FSParseException, 
PeerParseException, InvalidThresholdException, NodeInitException, 
ReferenceSignatureVerificationException {
@@ -54,27 +55,7 @@
         }
         Logger.normal(RealNodeRoutingTest.class, "Created "+NUMBER_OF_NODES+" 
nodes");
         // Now link them up
-        // Connect the set
-        for(int i=0;i<NUMBER_OF_NODES;i++) {
-            int next = (i+1) % NUMBER_OF_NODES;
-            int prev = (i+NUMBER_OF_NODES-1)%NUMBER_OF_NODES;
-            nodes[i].connect(nodes[next]);
-            nodes[i].connect(nodes[prev]);
-        }
-        Logger.normal(RealNodeRoutingTest.class, "Connected nodes");
-        // Now add some random links
-        for(int i=0;i<NUMBER_OF_NODES*5;i++) {
-            if(i % NUMBER_OF_NODES == 0)
-                Logger.normal(RealNodeRoutingTest.class, ""+i);
-            int length = (int)Math.pow(NUMBER_OF_NODES, random.nextDouble());
-            int nodeA = random.nextInt(NUMBER_OF_NODES);
-            int nodeB = (nodeA+length)%NUMBER_OF_NODES;
-            //System.out.println(""+nodeA+" -> "+nodeB);
-            Node a = nodes[nodeA];
-            Node b = nodes[nodeB];
-            a.connect(b);
-            b.connect(a);
-        }
+        makeKleinbergNetwork(nodes, false, DEGREE, true);

         Logger.normal(RealNodeRoutingTest.class, "Added random links");


Modified: trunk/freenet/src/freenet/node/simulator/RealNodeTest.java
===================================================================
--- trunk/freenet/src/freenet/node/simulator/RealNodeTest.java  2008-02-09 
14:52:30 UTC (rev 17754)
+++ trunk/freenet/src/freenet/node/simulator/RealNodeTest.java  2008-02-09 
14:57:29 UTC (rev 17755)
@@ -21,7 +21,7 @@
        /*
         Borrowed from mrogers simulation code (February 6, 2008)
         */
-       static void makeKleinbergNetwork (Node[] nodes, boolean idealLocations, 
int degree)
+       static void makeKleinbergNetwork (Node[] nodes, boolean idealLocations, 
int degree, boolean forceNeighbourConnections)
        {
                // First set the locations up so we don't spend a long time 
swapping just to stabilise each network.
                double div = 1.0 / (nodes.length + 1);
@@ -30,6 +30,12 @@
                        nodes[i].setLocation(loc);
                        loc += div;
                }
+               if(forceNeighbourConnections) {
+                       for(int i=0;i<nodes.length;i++) {
+                               int next = i+1 % nodes.length;
+                               connect(nodes[i], nodes[next]);
+                       }
+               }
                for (int i=0; i<nodes.length; i++) {
                        Node a = nodes[i];
                        // Normalise the probabilities


Reply via email to