diff options
Diffstat (limited to 'src/consensus')
-rw-r--r-- | src/consensus/consensus-simulation.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/consensus/consensus-simulation.py b/src/consensus/consensus-simulation.py index 19b636cbd..542fe0dac 100644 --- a/src/consensus/consensus-simulation.py +++ b/src/consensus/consensus-simulation.py | |||
@@ -17,10 +17,13 @@ | |||
17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | # Boston, MA 02110-1301, USA. | 18 | # Boston, MA 02110-1301, USA. |
19 | 19 | ||
20 | from __future__ import absolute_import | ||
21 | from __future__ import print_function | ||
20 | import argparse | 22 | import argparse |
21 | import random | 23 | import random |
22 | from math import ceil,log,floor | 24 | from math import ceil,log,floor |
23 | 25 | ||
26 | |||
24 | def bsc(n): | 27 | def bsc(n): |
25 | """ count the bits set in n""" | 28 | """ count the bits set in n""" |
26 | l = n.bit_length() | 29 | l = n.bit_length() |
@@ -32,6 +35,7 @@ def bsc(n): | |||
32 | x = x << 1 | 35 | x = x << 1 |
33 | return c | 36 | return c |
34 | 37 | ||
38 | |||
35 | def simulate(k, n, verbose): | 39 | def simulate(k, n, verbose): |
36 | assert k < n | 40 | assert k < n |
37 | largest_arc = int(2**ceil(log(n, 2))) / 2 | 41 | largest_arc = int(2**ceil(log(n, 2))) / 2 |
@@ -87,6 +91,7 @@ def simulate(k, n, verbose): | |||
87 | random.shuffle(peers) | 91 | random.shuffle(peers) |
88 | return rounds | 92 | return rounds |
89 | 93 | ||
94 | |||
90 | if __name__ == "__main__": | 95 | if __name__ == "__main__": |
91 | parser = argparse.ArgumentParser() | 96 | parser = argparse.ArgumentParser() |
92 | parser.add_argument("k", metavar="k", type=int, help="#(bad peers)") | 97 | parser.add_argument("k", metavar="k", type=int, help="#(bad peers)") |
@@ -98,6 +103,6 @@ if __name__ == "__main__": | |||
98 | sum = 0.0; | 103 | sum = 0.0; |
99 | for n in xrange (0, args.r): | 104 | for n in xrange (0, args.r): |
100 | sum += simulate(args.k, args.n, args.verbose) | 105 | sum += simulate(args.k, args.n, args.verbose) |
101 | print sum / args.r; | 106 | printsum / args.r; |
102 | 107 | ||
103 | 108 | ||