Logic for a genealogical tree program

I am creating a family tree program in Java, or at least trying. I developed several classes:

  • Person - recipient and setter for the name age of gender, etc.
  • FamilyMember - expands recipients and setters to set parents and children
  • A family of several family members and methods for adding member removal.
  • FamilyTree, which is the main class for establishing relationships.

I have two main problems:

1) I need to establish relationships between people. I am currently doing:

FamilyMember A, FamilyMember B B.setMother(A); A.setChild(B); 

The example above is intended to establish the relationship of maternal children.

It seems very awkward. It is a very long time to realize all relationships. Any ideas on how to implement multiple relationships in a less procedural way?

2) I should be able to display the family tree. How can i do this? Are there any custom classes to make life easier?

Thank you for your time...

+6
java family-tree
source share
3 answers

As for drawing the structure, it is difficult to avoid collisions (intersection of lines) if more than two generations are displayed. Therefore, if your application allows you to save it up to two, that's great. I wrote several programs that use this kind of presentation, either vertically:

alt text

or horizontally:

alt text

If you need more generations displayed immediately, you will need to come up with other ideas, and they can become quite sparse so that you can show everyone in the same generation at the same level.

As for representing relationships as a data structure - well, that's messy. The simplest, purest thing is that any two people who are respectively the mother and father of the same person are β€œmarried”. But how do you want to represent several partners, step-by-step children and the like? It's hard to answer without knowing more about what your program should do. Your dataset may not have these complications. However, if this is the case, it is better to think over complex cases first - simple ideas cannot be easily expanded to cover difficult cases.

Draw (manually) some of the most difficult cases that you expect; which will suggest what data you need to record and how to organize it. The choices you make when you draw (who comes first, which characters and text to use for each node, etc.) will inform your decisions about the data structure.

Setting up both motherhood B and child A seems redundant - and redundancy leads to errors - choose one. Which one of? Well, there’s more information when you establish the mother mother B (A gender), and we know that any person will need exactly two parents against 0 or more children. So I'm usually going to just install mother B; you can always recognize the children of any person, iterating over everyone to choose a set whose parent is equal to the individual in question. And in fact, maintaining the relationship between mother and father (compared to simple parental relationships) can reduce duplication (provided that you keep the gender with individuals).

+4
source share

something like below class (this is pseudo code, not a real Java class)

 class Node { public Node Parent { get;set;} public List<Node> Childs {get;set;} } 

uses

  Node ultimateGrandParent = new Node(); ultimateGrandParent.Parent = null; ultimateGrandParent.Childs = new List<Node>(); 
0
source share

Any ideas on how to implement multiple relationships in a less procedural way?

Yes, you yourself can represent relationships as objects. Any two people can have zero or more relationships.

A few years ago I worked on a police record system that did this more broadly for associations between any two people in the master name index.

Relations can be directed. Mother is the mother mother of the child.

Relations can be hierarchical. Mother was born.

2) I should be able to display the family tree. How can i do this? Are there any custom classes there to make life easier?

Yes, there is existing code that supports charting. I personally had good experience with a pre-visualization tool .

You can find the idea of ​​a pre-offer that interests you; try clicking the nodes in in this example . (However, if you intend to use your software for use by people other than your own, the tree may not be enough.)

0
source share

All Articles