Skip to content

Instantly share code, notes, and snippets.

@resilience-me
Last active April 22, 2019 01:51
Show Gist options
  • Select an option

  • Save resilience-me/f5a09651aed95203049972945f4e0ede to your computer and use it in GitHub Desktop.

Select an option

Save resilience-me/f5a09651aed95203049972945f4e0ede to your computer and use it in GitHub Desktop.
from __future__ import division
import random
# Set parameters for the simulation
population = 2 ** 10
trustLines = 16
people = {}
def initiateWoT():
for node in range(population):
people[node] = random.sample(range(1, population), trustLines)
initiateWoT()
creditLines = 4
totalHops = 4
# Calculate geometric series for creditLines^totalHops
# to get total nodes in branching tree.
# Includes the person paying the tax, 1 + totalHops.
def calculateTreeSize():
computeTree = 0
for step in range(1 + totalHops):
computeTree += creditLines ** step
return computeTree
treeSize = calculateTreeSize()
def swarmRedistribution():
duplicates = {}
branchingTree = {}
taxPayer = random.randint(0, population)
branchingTree[0] = taxPayer
class LinkUtility():
index = {}
counter = 0
linkUtility = LinkUtility()
for creditLine in range(creditLines):
node = 0
while node < trustLines - linkUtility.counter:
issueIOU = random.randint(0, trustLines - 1 - linkUtility.counter)
node += 1
try:
duplicates[issueIOU]
except:
duplicates[issueIOU] = True
linkUtility.counter += 1
for step in range(1 + totalHops):
computeBranch = []
for node in range(creditLines ** step):
taxPayer = random.randint(0, population)
computeBranch.append(taxPayer)
branchingTree[step] = computeBranch
print(branchingTree[0][0])
# branchingTree = random.sample(range(1, trustLines), treeSize)
del duplicates
swarmRedistribution()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment