Author: mrogers
Date: 2006-10-05 13:48:47 +0000 (Thu, 05 Oct 2006)
New Revision: 10606

Modified:
   trunk/apps/load-balancing-sims/phase6/Sim.java
Log:
Add edges to Kleinberg graph independently

Modified: trunk/apps/load-balancing-sims/phase6/Sim.java
===================================================================
--- trunk/apps/load-balancing-sims/phase6/Sim.java      2006-10-05 13:32:30 UTC 
(rev 10605)
+++ trunk/apps/load-balancing-sims/phase6/Sim.java      2006-10-05 13:48:47 UTC 
(rev 10606)
@@ -41,7 +41,8 @@

        private void makeKleinbergNetwork()
        {
-               // Add exactly DEGREE/2 outgoing edges to each node
+               // Add DEGREE/2 outgoing edges to each node, with replacement
+               double outDegree = DEGREE * 0.5;
                for (int i = 0; i < NODES; i++) {
                        // Calculate the normalising constant
                        double c = 0.0;
@@ -50,13 +51,13 @@
                                c += 1.0 / latticeDistance (i, j);
                        }
                        // Add the outgoing edges
-                       int deg = 0;
-                       for (int j = 0; deg < DEGREE/2; j = (j+1) % NODES) {
+                       for (int j = 0; j < NODES; j++) {
                                if (i == j) continue;
-                               double prob = 1.0 / latticeDistance (i, j) / c;
+                               int dist = latticeDistance (i, j);
+                               double prob = outDegree / dist / c;
                                if (Math.random() < prob)
-                                       if (nodes[i].connectBothWays
-                                       (nodes[j], LATENCY)) deg++;
+                                       nodes[i].connectBothWays
+                                               (nodes[j], LATENCY);
                        }
                }
        }


Reply via email to