diff options
-rw-r--r-- | src/consensus/consensus-simulation.py.in | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/consensus/consensus-simulation.py.in b/src/consensus/consensus-simulation.py.in index 38e29230a..161015d00 100644 --- a/src/consensus/consensus-simulation.py.in +++ b/src/consensus/consensus-simulation.py.in | |||
@@ -19,6 +19,10 @@ | |||
19 | 19 | ||
20 | from __future__ import absolute_import | 20 | from __future__ import absolute_import |
21 | from __future__ import print_function | 21 | from __future__ import print_function |
22 | from __future__ import division | ||
23 | from builtins import str | ||
24 | from builtins import range | ||
25 | from past.utils import old_div | ||
22 | import argparse | 26 | import argparse |
23 | import random | 27 | import random |
24 | from math import ceil, log, floor | 28 | from math import ceil, log, floor |
@@ -39,18 +43,18 @@ def bsc(n): | |||
39 | 43 | ||
40 | def simulate(k, n, verbose): | 44 | def simulate(k, n, verbose): |
41 | assert k < n | 45 | assert k < n |
42 | largest_arc = int(2**ceil(log(n, 2))) / 2 | 46 | largest_arc = old_div(int(2**ceil(log(n, 2))), 2) |
43 | num_ghosts = (2 * largest_arc) - n | 47 | num_ghosts = (2 * largest_arc) - n |
44 | if verbose: | 48 | if verbose: |
45 | print("we have", num_ghosts, "ghost peers") | 49 | print("we have", num_ghosts, "ghost peers") |
46 | # n.b. all peers with idx<k are evil | 50 | # n.b. all peers with idx<k are evil |
47 | peers = range(n) | 51 | peers = list(range(n)) |
48 | # py2-3 compatible, backwards. | 52 | # py2-3 compatible, backwards. |
49 | # refer to http://python-future.org/compatible_idioms.html#xrange | 53 | # refer to http://python-future.org/compatible_idioms.html#xrange |
50 | info = [1 << x for x in xrange(n)] | 54 | info = [1 << x for x in range(n)] |
51 | 55 | ||
52 | def done_p(): | 56 | def done_p(): |
53 | for x in xrange(k, n): | 57 | for x in range(k, n): |
54 | if bsc(info[x]) < n-k: | 58 | if bsc(info[x]) < n-k: |
55 | return False | 59 | return False |
56 | return True | 60 | return True |
@@ -63,7 +67,7 @@ def simulate(k, n, verbose): | |||
63 | if verbose: | 67 | if verbose: |
64 | print("-- subround --") | 68 | print("-- subround --") |
65 | new_info = [x for x in info] | 69 | new_info = [x for x in info] |
66 | for peer_physical in xrange(n): | 70 | for peer_physical in range(n): |
67 | peer_logical = peers[peer_physical] | 71 | peer_logical = peers[peer_physical] |
68 | peer_type = None | 72 | peer_type = None |
69 | partner_logical = (peer_logical + arc) % n | 73 | partner_logical = (peer_logical + arc) % n |
@@ -105,6 +109,6 @@ if __name__ == "__main__": | |||
105 | 109 | ||
106 | args = parser.parse_args() | 110 | args = parser.parse_args() |
107 | sum = 0.0 | 111 | sum = 0.0 |
108 | for n in xrange(0, args.r): | 112 | for n in range(0, args.r): |
109 | sum += simulate(args.k, args.n, args.verbose) | 113 | sum += simulate(args.k, args.n, args.verbose) |
110 | print(sum / args.r) | 114 | print(old_div(sum, args.r)) |