Skip to content

Instantly share code, notes, and snippets.

@ramsesoriginal
Last active May 2, 2018 21:37
Show Gist options
  • Save ramsesoriginal/7a80b439eebabab65447d487eb7fd81c to your computer and use it in GitHub Desktop.
Save ramsesoriginal/7a80b439eebabab65447d487eb7fd81c to your computer and use it in GitHub Desktop.
def test():
class Node(object):
def __init__(self, name, *successors):
self.successors = list(successors)
self.name = name
self.color = "white"
def __repr__(self):
return self.name + "(" + self.color + ")"
def reset(g):
for n in g:
n.color = "white"
n1 = Node("C3ab")
n2 = Node("C2a", n1)
n3 = Node("C1b", n1)
n4 = Node("C2a", n2)
n5 = Node("C1a", n4, n2)
n6 = Node("B2")
n7 = Node("B1", n6)
n8 = Node("A1")
n9 = Node("D1", Node("D2", Node("D3", Node("D4", Node("D5", Node("D6", Node("D7"), Node("D7")))), Node("D4"))))
print("OK:")
G = [n7, n1,n2,n3,n8,n4,n5,n6]
reset(G)
print(G, topologische_sortierung(G))
G = []
reset(G)
print(G, topologische_sortierung(G))
G = [n1]
reset(G)
print(G, topologische_sortierung(G))
G = [n1, n6, n8]
reset(G)
print(G, topologische_sortierung(G))
G = [n6, n7]
reset(G)
print(G, topologische_sortierung(G))
G = [n6, n6]
reset(G)
print(G, topologische_sortierung(G))
#####LONG
'''
G= []
multistart = Node("start")
end = Node("end")
for i in range(10000):
G.append(Node(str(i),end))
if i%7==0:
multistart.successors.append(G[i])
for j in range (i//2, i-1):
if (i-j)%11 == 0:
G[j].successors.append(G[i])
G.append(multistart)
print(G, topologische_sortierung(G))
'''
print("Nicht Ok:")
n1.successors.append(n2)
G = [n1, n2]
reset(G)
print(G, topologische_sortierung(G))
G = [n4, n1, n2]
reset(G)
print(G, topologische_sortierung(G))
G = [n1, n2, n4]
reset(G)
print(G, topologische_sortierung(G))
n8.successors.append(n8)
G = [n8]
reset(G)
print(G, topologische_sortierung(G))
G = [n8,n8]
reset(G)
print(G, topologische_sortierung(G))
d = Node("d")
b = Node("b")
c = Node("c", b)
b.successors.append(c)
a = Node("a")
a.successors.append(a)
G = [a, b, c, d]
print(G, topologische_sortierung(G))
print("Nicht genau definiert...")
G = [n9]
reset(G)
print(G, topologische_sortierung(G))
test()
]
reset(G)
print(G, topologische_sortierung(G))
G = []
reset(G)
print(G, topologische_sortierung(G))
G = [n1]
reset(G)
print(G, topologische_sortierung(G))
G = [n1, n6, n8]
reset(G)
print(G, topologische_sortierung(G))
G = [n6, n7]
reset(G)
print(G, topologische_sortierung(G))
G = [n6, n6]
reset(G)
print(G, topologische_sortierung(G))
#####LONG
'''
G= []
multistart = Node("start")
end = Node("end")
for i in range(10000):
G.append(Node(str(i),end))
if i%7==0:
multistart.successors.append(G[i])
for j in range (i//2, i-1):
if (i-j)%11 == 0:
G[j].successors.append(G[i])
G.append(multistart)
print(G, topologische_sortierung(G))
'''
print("Nicht Ok:")
n1.successors.append(n2)
G = [n1, n2]
reset(G)
print(G, topologische_sortierung(G))
G = [n4, n1, n2]
reset(G)
print(G, topologische_sortierung(G))
G = [n1, n2, n4]
reset(G)
print(G, topologische_sortierung(G))
n8.successors.append(n8)
G = [n8]
reset(G)
print(G, topologische_sortierung(G))
G = [n8,n8]
reset(G)
print(G, topologische_sortierung(G))
print("Nicht genau definiert...")
G = [n9]
reset(G)
print(G, topologische_sortierung(G))
d = Node("d")
b = Node("b")
c = Node("c", b)
b.successors.append(c)
a = Node("a")
a.successors.append(a)
G = [a, b, c, d]
print(G, topologische_sortierung(G))
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment