I need to represent relationships between people as a graph in order to create a list of people that should be invited to a party. Each relationship is given as a tuple (A, B, cond), where A and B are different people and cond is one of the following:
- 0: either A, B, or both should be invited;
- 1: if A is excluded, B should be excluded;
- 2: if B is excluded, A should be excluded;
- 3: either A, B or both should be excluded;
Note that any list of people to be invited is accepted, as long as all relationships remain valid.
I tried to model the data using two DG (one for invitations, one for exclusions), noticing that cases 1 and 2 are imposing the same conditions but reversed. Another obesevation is that for cases 1 and 2, if the latter is invited, that forces the former to be invited as well.
To get a valid answer, I ran a DFS through the DGs, collapsing the nodes that hadn’t been accepted/rejected. However, this method is too time-consuming for large amounts of data. Is there a better approach to problems such as this one? I tried searching but nothing shows up.
Badescu Andrei is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.