So, as I mentioned in the ranting thread, I wanted to make a script to track a person's blood relations, so I can add a line like "He is your great great uncle." when I honours someone. At first, I thought this would be simple. Find the lowest common ancestor of person A and person B, look at the distance from that ancestor for each of them, now you know exactly how person A and person B are related. Easy.
But then I remembered incest, and everything was ruined. One person can have multiple distances to the lowest common ancestor, there can be a bunch of lowest common ancestors, there can be ancestors who aren't the lowest but still matter for determining the relationship, or all of the above. I've been thinking about it for a couple days now, and no matter what I try I can't think of a method/algorithm for determining which common ancestors matter for determining the relationship between two people. Every time I think of something that might work, I can find an example that screws it up.
So, does anyone have any ideas for how to find all the blood relationships between two people, accounting for any amount of entanglement due to incest? I tried searching for family tree programs or anything else that might already do this, but I couldn't find anything useful.
0
Comments
Also, it's better modelled as a directed acyclic graph. With that, all I need to do is calculate the distance from certain common ancestor nodes, there doesn't need to be any real pathfinding involved, plus it saves on storage because all I need to know about a person is their parents. That part is easy. The only real problem is knowing which common ancestors matter.
For example, say you're looking for the relationship between two people (named A and . B is the daughter of A's sister and A's great grandfather. The lowest common ancestor is A's father (distance of 1 from A and 2 from , and that tells us that B is A's niece. But A's great grandfather is another common ancestor that matters (because he's necessary to see that B is also A's great niece), and his distance is 3 from A and 1 (also 4, but that doesn't matter here) from B. If we just look for the shortest path or lowest common ancestor, we ignore that relationship.
Also, if I did use a more general pathfinding algorithm, I'd need to find the lowest cost path that goes through a specific node, not just the lowest cost in general. And then I'd still have exactly the same problem; I need a way to find out which nodes I need to find paths through.
And when you add the entire family tree, it's not practical to calculate every possible path (because I don't want the closest relationship, I want every relationship).
With a DAG, the distance does tell you the relationship. Without incest, if person A's distance from the lowest common ancestor is 1 and person B's distance is 2, you know for certain that person B is person A's niece/nephew.
The only complication added by incest (and so the only problem I need to solve) is not knowing which common ancestors I need to look at.
The reason I can't simply look at every common ancestor is that most of them will be useless (for example, looking at the distance from their grandparents for two siblings can't tell you whether they're siblings or first cousins), and I can't think of a way to check for those ambiguities.