What's norm? How is it different to 1.0?
On Sun, Oct 08, 2006 at 08:45:39PM +0000, mrogers at freenetproject.org wrote: > Author: mrogers > Date: 2006-10-08 20:45:38 +0000 (Sun, 08 Oct 2006) > New Revision: 10651 > > Modified: > trunk/apps/load-balancing-sims/phase6/Sim.java > Log: > Kleinberg shortcuts chosen randomly with replacement > > Modified: trunk/apps/load-balancing-sims/phase6/Sim.java > =================================================================== > --- trunk/apps/load-balancing-sims/phase6/Sim.java 2006-10-08 20:21:05 UTC > (rev 10650) > +++ trunk/apps/load-balancing-sims/phase6/Sim.java 2006-10-08 20:45:38 UTC > (rev 10651) > @@ -41,24 +41,23 @@ > > private void makeKleinbergNetwork() > { > - // Add DEGREE/2 outgoing edges to each node, with replacement > - double outDegree = DEGREE * 0.5; > + // Calculate the normalising constant > + double norm = 0.0; > + for (int i = 1; i < NODES; i++) > + norm += 1.0 / latticeDistance (0, i); > + > + // Add DEGREE shortcuts per node, randomly with replacement > for (int i = 0; i < NODES; i++) { > - // Calculate the normalising constant > - double c = 0.0; > - for (int j = 0; j < NODES; j++) { > - if (i == j) continue; > - c += 1.0 / latticeDistance (i, j); > + for (int j = 0; j < i; j++) { > + double p = 1.0 / latticeDistance (i, j) / norm; > + for (int k = 0; k < DEGREE; k++) { > + if (Math.random() < p) { > + nodes[i].connectBothWays > + (nodes[j], LATENCY); > + break; > + } > + } > } > - // Add the outgoing edges > - for (int j = 0; j < NODES; j++) { > - if (i == j) continue; > - int dist = latticeDistance (i, j); > - double prob = outDegree / dist / c; > - if (Math.random() < prob) > - nodes[i].connectBothWays > - (nodes[j], LATENCY); > - } > } > } > > > _______________________________________________ > cvs mailing list > cvs at freenetproject.org > http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: Digital signature URL: <https://emu.freenetproject.org/pipermail/devl/attachments/20061025/7b7f3014/attachment.pgp>