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
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
indexLength = trustLines - linkUtility.counter
while node < indexLength:
randomLink = random.randint(0, indexLength - 1)
try:
linkUtility.index[randomLink]
except:
linkUtility.index[randomLink] = randomLink
fromIndex = linkUtility.index[randomLink]
try:
linkUtility.index[indexLength - 1]
except:
linkUtility.index[indexLength - 1] = indexLength - 1
linkUtility.index[fromIndex] = linkUtility.index[indexLength - 1]
linkUtility.counter += 1
indexLength -= 1
try:
duplicates[fromIndex]
except:
duplicates[fromIndex] = True
branchingTree[0].append(fromIndex)
break
node += 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