Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query from a Directed Acyclic Graph with exclusive subsets

Question in abstract terms:

I have a directed acyclic graph (DAG) which contains subsets of vertices which are exclusive when queried (only one item per subset should be present in the query's results). When I query the graph structure I would like to get the set of vertices which flow from a given vertex while only selecting a single item from known subsets of the vertices in the graph.

Question in concrete terms:

I have a DAG that stores my assemblies(vertices) and their dependencies(edges). Given an assembly or set of assemblies I need to query to get the set of all involved assemblies and their dependencies. The difficult part is that each assembly has multiple versions and only one instance of an assembly can be loaded into a process. The dependencies for a given assembly change between the various versions of the assembly.

Is there a name for this problem or group of problems? A standard algorithm I can research to find a solution?


Possible solution areas:

A transitive closure seems close to a good solution but the item chosen from the subset (assembly version) will change depending on the path taken through the graph, possibly through multiple branches so you would almost need to trace the path taken through the graph to generate the transitive closure.

A graph database might be able to help out quite a bit but we want to avoid going down that road right now unless we absolutely have to.

like image 323
Bryan Anderson Avatar asked Sep 22 '11 21:09

Bryan Anderson


People also ask

Is there any tool to make and analyze directed acyclic graphs DAG )?

DAGitty is a browser-based environment for creating, editing, and analyzing causal diagrams (also known as directed acyclic graphs or causal Bayesian networks).

How do you identify a DAG?

A directed graph is a DAG if and only if it can be topologically ordered, by arranging the vertices as a linear ordering that is consistent with all edge directions.

How do you find shortest path in directed acyclic graph explain with an example?

Given a Weighted Directed Acyclic Graph and a source vertex in the graph, find the shortest paths from given source to all other vertices. For a general weighted graph, we can calculate single source shortest distances in O(VE) time using Bellman–Ford Algorithm.

How do you check if a graph is directed acyclic?

A directed graph is acyclic if it contains no cycles. That is, starting at any node in the graph, no sequence of edges exists that can be followed to loop back to that starting node. As a result, directed acyclic graphs do not contain any self-loops.


1 Answers

I think that the set of vertices that flow from a given choice looks confusing because there is actually an underlying optimisation or satisfaction problem: given an assembly A, you can satisfy its dependencies via B1 or B2 or B3, and each of those choices then has its own knock-on consequences.

If we view this as a logic satisfaction problem, then we could consider a problem where assemblies come in only two versions, e.g. A1 or A2. Then a clause such as (a or b or not c) would translate to an upper-level assembly that required A1 or B1 or C2 - possibly indirectly via X1, X2 and X3 - and a conjunction of clauses would translate to an upper-upper level assembly that required all of the upper-level assemblies. So I think that if you could solve the general problem efficiently you could solve 3-SAT efficiently, and then P = NP.

Curiously, if you don't have the restriction that you are allowed only one assembly of each type (A1 or A2 or A3 but more than one at a time) then the problem translates very easily into Horn clauses (Knuth Vol 4 section 7.1.1 P 57) for which the satisfiability problem can be solved efficiently. To do this, you work with the inverse of the natural variables, so that X1 means that A1 is not included. Then if you treat the Horn clause version as a way of relaxing your problem, by ignoring the constraint that at most one version of each assembly can be supported, what you get is a mechanism for telling you that some assembly version A1 cannot be in the solution, because X1 = not A1 is true in the core of the Horn solution, and therefore true in every satisfying assignment.

like image 53
mcdowella Avatar answered Nov 15 '22 11:11

mcdowella