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.
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.
精彩评论