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.

Revisions

  1. resilience-me revised this gist Apr 22, 2019. No changes.
  2. resilience-me revised this gist Apr 22, 2019. 1 changed file with 13 additions and 10 deletions.
    23 changes: 13 additions & 10 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,11 @@
    # This simulation creates a web of trust with a static number of trust lines
    # per person. The swarm redistribution pulses then find credit line paths based
    # on those trust lines, without any loops (credit lines in Ripple cannot loop,
    # because when they do credit is cleared. )

    from __future__ import division
    import random

    # This simulation creates a web of trust with a static number of trust lines per person. The swarm redistribution pulses then find credit line paths based on those trust lines, 4 per person, without any loops (a person cannot be two times in a single pulse. )

    # Set parameters for the simulation

    population = 2 ** 13
    @@ -25,19 +28,19 @@ frequency = {}

    totalPulses = population

    def incrementFrequency(node, step):
    frequency.get(node, 0)
    if frequency.get(node) == None:
    frequency[node] = {}
    for hop in range(totalHops):
    frequency[node][hop] = 0
    frequency[node][step] += 1

    def swarmRedistribution():

    duplicates = {}
    branchingTree = {}

    def incrementFrequency(node, step):
    frequency.get(node, 0)
    if frequency.get(node) == None:
    frequency[node] = {}
    for hop in range(totalHops):
    frequency[node][hop] = 0
    frequency[node][step] += 1

    def selectCreditLines(step, agent):

    # Select credit line paths without any loops (a person cannot be two times in a single pulse. )
  3. resilience-me revised this gist Apr 22, 2019. 1 changed file with 11 additions and 16 deletions.
    27 changes: 11 additions & 16 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    from __future__ import division
    import random

    # This simulation creates a web of trust with a static number of trust lines per person. The swarm redistribution pulses then find credit line paths based on those trust lines, 4 per person, without any loops (a person cannot be two times in a single pulse. )

    # Set parameters for the simulation

    population = 2 ** 15
    population = 2 ** 13

    trustLines = 16

    @@ -17,21 +19,20 @@ initiateWoT()

    creditLines = 4

    totalHops = 5
    totalHops = 4

    frequency = {}

    totalPulses = 10000
    totalPulses = population

    def swarmRedistribution():

    duplicates = {}
    branchingTree = {}

    def incrementFrequency(node, step):
    try:
    frequency[node]
    except:
    frequency.get(node, 0)
    if frequency.get(node) == None:
    frequency[node] = {}
    for hop in range(totalHops):
    frequency[node][hop] = 0
    @@ -52,21 +53,15 @@ def swarmRedistribution():
    indexLength = trustLines - linkUtility.counter
    while node < indexLength:
    randomLink = random.randint(0, indexLength - 1)
    try:
    linkUtility.index[randomLink]
    except:
    if linkUtility.index.get(randomLink) == None:
    linkUtility.index[randomLink] = randomLink
    fromIndex = linkUtility.index[randomLink]
    try:
    linkUtility.index[indexLength - 1]
    except:
    if linkUtility.index.get(indexLength - 1) == None:
    linkUtility.index[indexLength - 1] = indexLength - 1
    linkUtility.index[fromIndex] = linkUtility.index[indexLength - 1]
    linkUtility.counter += 1
    indexLength -= 1
    try:
    duplicates[people[agent][fromIndex]]
    except:
    if duplicates.get(people[agent][fromIndex]) == None:
    duplicates[people[agent][fromIndex]] = True
    branchingTree[step].append(people[agent][fromIndex])
    incrementFrequency(people[agent][fromIndex], step-1)
    @@ -91,5 +86,5 @@ def swarmRedistribution():
    for i in range(totalPulses):
    swarmRedistribution()

    randomAgent = random.randint(0, population)
    randomAgent = random.randint(0, population - 1)
    print(frequency[randomAgent])
  4. resilience-me revised this gist Apr 22, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ import random

    # Set parameters for the simulation

    population = 2 ** 12
    population = 2 ** 15

    trustLines = 16

    @@ -17,11 +17,11 @@ initiateWoT()

    creditLines = 4

    totalHops = 4
    totalHops = 5

    frequency = {}

    totalPulses = 1000
    totalPulses = 10000

    def swarmRedistribution():

  5. resilience-me revised this gist Apr 22, 2019. 1 changed file with 4 additions and 6 deletions.
    10 changes: 4 additions & 6 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ frequency = {}
    totalPulses = 1000

    def swarmRedistribution():

    duplicates = {}
    branchingTree = {}

    @@ -33,10 +33,8 @@ def swarmRedistribution():
    frequency[node]
    except:
    frequency[node] = {}
    try:
    frequency[node][step]
    except:
    frequency[node][step] = 0
    for hop in range(totalHops):
    frequency[node][hop] = 0
    frequency[node][step] += 1

    def selectCreditLines(step, agent):
    @@ -71,7 +69,7 @@ def swarmRedistribution():
    except:
    duplicates[people[agent][fromIndex]] = True
    branchingTree[step].append(people[agent][fromIndex])
    incrementFrequency(agent, step)
    incrementFrequency(people[agent][fromIndex], step-1)
    break
    node += 1
    if node == indexLength:
  6. resilience-me revised this gist Apr 22, 2019. 1 changed file with 13 additions and 9 deletions.
    22 changes: 13 additions & 9 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -24,9 +24,21 @@ frequency = {}
    totalPulses = 1000

    def swarmRedistribution():

    duplicates = {}
    branchingTree = {}

    def incrementFrequency(node, step):
    try:
    frequency[node]
    except:
    frequency[node] = {}
    try:
    frequency[node][step]
    except:
    frequency[node][step] = 0
    frequency[node][step] += 1

    def selectCreditLines(step, agent):

    # Select credit line paths without any loops (a person cannot be two times in a single pulse. )
    @@ -59,6 +71,7 @@ def swarmRedistribution():
    except:
    duplicates[people[agent][fromIndex]] = True
    branchingTree[step].append(people[agent][fromIndex])
    incrementFrequency(agent, step)
    break
    node += 1
    if node == indexLength:
    @@ -76,15 +89,6 @@ def swarmRedistribution():
    branchingTree[step+1] = []
    for node in branchingTree[step]:
    selectCreditLines(step+1, node)
    try:
    frequency[node]
    except:
    frequency[node] = {}
    try:
    frequency[node][step]
    except:
    frequency[node][step] = 0
    frequency[node][step] += 1

    for i in range(totalPulses):
    swarmRedistribution()
  7. resilience-me revised this gist Apr 22, 2019. 1 changed file with 22 additions and 6 deletions.
    28 changes: 22 additions & 6 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ import random

    population = 2 ** 12

    trustLines = 4
    trustLines = 16

    people = {}

    @@ -19,6 +19,10 @@ creditLines = 4

    totalHops = 4

    frequency = {}

    totalPulses = 1000

    def swarmRedistribution():
    duplicates = {}
    branchingTree = {}
    @@ -58,8 +62,8 @@ def swarmRedistribution():
    break
    node += 1
    if node == indexLength:
    # If this happens, just increase the population,
    # and/or trust lines, or decrease credit lines,
    # If this happens, just increase the population,
    # and/or trust lines, or decrease credit lines,
    # or decrease the number of hops
    print("Failure. The pulse has looped. ")
    quit()
    @@ -72,6 +76,18 @@ def swarmRedistribution():
    branchingTree[step+1] = []
    for node in branchingTree[step]:
    selectCreditLines(step+1, node)

    for i in range(1000):
    swarmRedistribution()
    try:
    frequency[node]
    except:
    frequency[node] = {}
    try:
    frequency[node][step]
    except:
    frequency[node][step] = 0
    frequency[node][step] += 1

    for i in range(totalPulses):
    swarmRedistribution()

    randomAgent = random.randint(0, population)
    print(frequency[randomAgent])
  8. resilience-me revised this gist Apr 22, 2019. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -3,9 +3,9 @@ import random

    # Set parameters for the simulation

    population = 2 ** 10
    population = 2 ** 12

    trustLines = 16
    trustLines = 4

    people = {}

    @@ -58,6 +58,9 @@ def swarmRedistribution():
    break
    node += 1
    if node == indexLength:
    # If this happens, just increase the population,
    # and/or trust lines, or decrease credit lines,
    # or decrease the number of hops
    print("Failure. The pulse has looped. ")
    quit()

    @@ -70,5 +73,5 @@ def swarmRedistribution():
    for node in branchingTree[step]:
    selectCreditLines(step+1, node)

    for i in range(10000000):
    for i in range(1000):
    swarmRedistribution()
  9. resilience-me revised this gist Apr 22, 2019. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -51,13 +51,15 @@ def swarmRedistribution():
    linkUtility.counter += 1
    indexLength -= 1
    try:
    print(agent)
    duplicates[people[agent][fromIndex]]
    except:
    duplicates[people[agent][fromIndex]] = True
    branchingTree[step].append(people[agent][fromIndex])
    break
    node += 1
    if node == indexLength:
    print("Failure. The pulse has looped. ")
    quit()

    taxPayer = random.randint(0, population - 1)
    branchingTree[0] = []
    @@ -66,9 +68,7 @@ def swarmRedistribution():
    for step in range(totalHops):
    branchingTree[step+1] = []
    for node in branchingTree[step]:
    print(branchingTree[step])
    print(node)
    selectCreditLines(step+1, node)

    for i in range(100000):
    for i in range(10000000):
    swarmRedistribution()
  10. resilience-me revised this gist Apr 21, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,6 @@ trustLines = 16

    people = {}


    def initiateWoT():
    for node in range(population):
    people[node] = random.sample(range(population), trustLines)
  11. resilience-me revised this gist Apr 21, 2019. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -12,8 +12,7 @@ people = {}

    def initiateWoT():
    for node in range(population):
    people[node] = random.sample(range(1, population), trustLines)

    people[node] = random.sample(range(population), trustLines)

    initiateWoT()

    @@ -53,21 +52,24 @@ def swarmRedistribution():
    linkUtility.counter += 1
    indexLength -= 1
    try:
    print(agent)
    duplicates[people[agent][fromIndex]]
    except:
    duplicates[people[agent][fromIndex]] = True
    branchingTree[step].append(people[agent][fromIndex])
    break
    node += 1

    taxPayer = random.randint(0, population)
    taxPayer = random.randint(0, population - 1)
    branchingTree[0] = []
    branchingTree[0].append(taxPayer)

    for step in range(totalHops):
    branchingTree[step+1] = []
    print(step)
    for node in branchingTree[step]:
    print(branchingTree[step])
    print(node)
    selectCreditLines(step+1, node)

    swarmRedistribution()
    for i in range(100000):
    swarmRedistribution()
  12. resilience-me revised this gist Apr 21, 2019. 1 changed file with 46 additions and 43 deletions.
    89 changes: 46 additions & 43 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -9,10 +9,12 @@ trustLines = 16

    people = {}


    def initiateWoT():
    for node in range(population):
    people[node] = random.sample(range(1, population), trustLines)


    initiateWoT()

    creditLines = 4
    @@ -22,49 +24,50 @@ totalHops = 4
    def swarmRedistribution():
    duplicates = {}
    branchingTree = {}

    def selectCreditLines(step, agent):

    # Select credit line paths without any loops (a person cannot be two times in a single pulse. )

    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[people[agent][fromIndex]]
    except:
    duplicates[people[agent][fromIndex]] = True
    branchingTree[step].append(people[agent][fromIndex])
    break
    node += 1

    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
    branchingTree[0] = []
    branchingTree[0].append(taxPayer)

    for step in range(totalHops):
    branchingTree[step+1] = []
    print(step)
    for node in branchingTree[step]:
    selectCreditLines(step+1, node)

    swarmRedistribution()
  13. resilience-me revised this gist Apr 21, 2019. 1 changed file with 21 additions and 20 deletions.
    41 changes: 21 additions & 20 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -19,18 +19,6 @@ 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 = {}
    @@ -40,19 +28,32 @@ def swarmRedistribution():
    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
    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:
    duplicates[issueIOU]
    linkUtility.index[indexLength - 1]
    except:
    duplicates[issueIOU] = True
    linkUtility.counter += 1
    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



  14. resilience-me revised this gist Apr 21, 2019. 1 changed file with 26 additions and 7 deletions.
    33 changes: 26 additions & 7 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -34,16 +34,35 @@ treeSize = calculateTreeSize()
    def swarmRedistribution():
    duplicates = {}
    branchingTree = {}
    for step in range(treeSize)
    taxPayer = random.randint(0, population)
    computeBranch = []
    computeBranch.append(taxPayer)
    branchingTree[1] = computeBranch
    branchingTree[0] = taxPayer

    print(branchingTree[1])
    print(taxPayer)
    print(people[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

  15. resilience-me created this gist Apr 21, 2019.
    50 changes: 50 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    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 = {}
    for step in range(treeSize)
    taxPayer = random.randint(0, population)
    computeBranch = []
    computeBranch.append(taxPayer)
    branchingTree[1] = computeBranch

    print(branchingTree[1])
    print(taxPayer)
    print(people[taxPayer])

    # branchingTree = random.sample(range(1, trustLines), treeSize)
    del duplicates

    swarmRedistribution()