Commit b6b4a537 authored by Temujin's avatar Temujin

fixed comments

parent 62e7d090
"""Family Tree project for CSCI 30."""
"""
Problems to consider --
Handling value errors.
Questions:
Total nodes of the tree?
11 generations = 2^11 - 1
Tree setup procedure:
1 get all the nodes and edges, check if they're valid.
2 Make sure there's only one root.
3 Find and set the root
4 Set the generations
5 run precompute method
6 done
"""
class FamilyTree:
......@@ -32,6 +14,16 @@ class FamilyTree:
value = a Person object, acting as the node
"""
"""
Tree setup procedure:
1 get all the nodes and edges, check if they're valid.
2 Make sure there's only one root.
3 Find and set the root
4 Set the generations
5 run precompute method
6 done
"""
ordinal = ["first", "second", "third", "fourth", "fifth",
"sixth", "seventh", "eighth", "ninth", "tenth"]
times = ["once", "twice", "thrice", "four times", "five times",
......@@ -148,10 +140,7 @@ class FamilyTree:
self.dfs(rc.get_name(), *funcs)
def find_lca(self, name1, name2):
"""Find the lowest common ancestor of two nodes.
TODO: when one is the ancestor of the other
"""
"""Find the lowest common ancestor of two nodes."""
return self.slow_lca(name1, name2)
def slow_lca(self, name1, name2):
......@@ -171,11 +160,10 @@ class FamilyTree:
while p2.get_generation() < p1.get_generation():
p1 = p1.get_parent()
# Keep moving up at the same time until they're equal
# Move up at the same time until they're equal
while p1 is not p2:
p1 = p1.get_parent()
p2 = p2.get_parent()
return p1
def fast_lca(self, a, b):
......@@ -185,13 +173,6 @@ class FamilyTree:
"""
return
def get_degree(self, p1, p2, lca):
"""Find the degree between two people."""
distance_p1 = lca.get_generation() - p1.get_generation()
distance_p2 = lca.get_generation() - p2.get_generation()
deg = min[distance_p1 - 1, distance_p2 - 1]
return deg
def relationship(self, p1, p2):
"""Determine the relationship between two distinct people in the tree.
......@@ -223,16 +204,11 @@ class FamilyTree:
else:
return self.GREAT(furthest) + "grand" + self.TERM("nibling", d1, d2, p2.sex)
elif nearest == 0:
## TODO: PARENT RELATIONSHIP
if furthest == 1:
return self.TERM("child", d1, d2, p2.sex)
else:
return self.GREAT(furthest) + "grand" + self.TERM("child", d1, d2, p2.sex)
pass
def ORDINAL(self, n):
"""Return the index in the ordinal table."""
return self.ordinal[n]
......@@ -242,7 +218,7 @@ class FamilyTree:
return self.times[n]
def great(self, n):
"""Return a string of n 'greats' separated by - ."""
"""Return a string of n 'greats' separated by '-' ."""
return "-".join(["great"]*n)
def TERM(self, kind, d1, d2, sex):
......@@ -370,7 +346,7 @@ def main():
ftree = FamilyTree()
A = Person("A", 69, True)
B = Person("B", 69, True)
C = Person("C", 69, True)
C = Person("C", 69, False)
D = Person("D", 69, True)
E = Person("E", 666, False)
ftree.insert_person(A)
......@@ -395,8 +371,15 @@ def main():
print("The lca of {} and {} is {}".format(B, D, ftree.find_lca("B", "D")))
print("The lca of {} and {} is {}".format(A, B, ftree.find_lca("A", "B")))
print("relationship (A, B): {}".format(ftree.relationship(A, B)))
print("relationship (B, C): {}".format(ftree.relationship(B, C)))
# parent/child
print("relationship {} is {}'s: {}".format(B, A, ftree.relationship(A, B)))
print("relationship {} is {}'s: {}".format(A, B, ftree.relationship(B, A)))
# sibling
print("relationship {} is {}'s: {}".format(B, C, ftree.relationship(C, B)))
print("relationship {} is {}'s: {}".format(C, B, ftree.relationship(B, C)))
# nibling
print("relationship {} is {}'s: {}".format(D, C, ftree.relationship(C, D)))
print("relationship {} is {}'s: {}".format(C, D, ftree.relationship(D, C)))
if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment