7

It seems this must be a common scheduling problem, but I don't see the solution or even what to call the problem. It's like a topological sort, but different....

Given some dependencies, say

A -> B -> D -- that is, A must come before B, which must come before D
A -> C -> D

there might be multiple solutions to a topological sort:

    A, B, C, D
and A, C, B, D

are both solutions.

I need an algorithm that returns this:

(A) -> (B,C) -> (D)

That is, do A, then all of B and C, then you can do D. All the ambiguities or don't-cares are grouped.

I think algorithms such as those at Topological Sort with Grouping won't correctly handle cases like the following.

A -> B -> C -> D -> E
A - - - > M - - - > E

For this, the algorithm should return

(A) -> (B, C, D, M) -> (E)

This

A -> B -> D -> F
A -> C -> E -> F

should return

(A) -> (B, D, C, E) -> (F)

While this

A -> B -> D -> F
A -> C -> E -> F
     C -> D
     B -> E

should return

(A) -> (B, C) -> (D, E) -> (F)    

And this

A -> B -> D -> F
A -> C -> E -> F
A -> L -> M -> F
     C -> D
     C -> M
     B -> E
     B -> M
     L -> D
     L -> E

should return

(A) -> (B, C, L) -> (D, E, M) -> (F)    

Is there a name and a conventional solution to this problem? (And do the algorithms posted at Topological Sort with Grouping correctly handle this?)

Edit to answer requests for more examples:

A->B->C
A->C 

should return

(A) -> (B) -> (C). That would be a straight topological sort.

And

A->B->D
A->C->D
A->D

should return

(A) -> (B, C) -> (D)

And

A->B->C
A->C
A->D

should return

(A) -> (B,C,D)
Community
  • 1
  • 1
JPM
  • 2,029
  • 2
  • 24
  • 27
  • What is the expected answer for: A->B->C, A->C ? – ElKamina Jan 12 '12 at 00:18
  • Sorry to pester you, but how about A->B->D, A->C->D, A->D ? – ElKamina Jan 12 '12 at 00:37
  • Oh really! Last one! A->B->C, A->C, A->D – ElKamina Jan 12 '12 at 00:44
  • (A) -> (B,C,D) is incorrect right? Because B->C ? – ElKamina Jan 12 '12 at 01:02
  • Can there be input like this A->B->C->D->E, A->M->F? The answer seems to be A->(B,C,D,E,M,F)? –  Jan 12 '12 at 01:30
  • I am not convinced your question is well-defined. A->B->C plus A->C plus A->D gives A->(B,C,D)? Which just drops the dependency between B and C by grouping them together? – Nemo Jan 12 '12 at 01:47
  • The interpretation of `A -> B -> C -> D -> E; A -> M -> E` as `(A) -> (B, C, D, M) -> (E)` seems highly suspect to me. The answer says 'the order of B, C, and D does not matter'; the data says 'B must precede C, and C must precede D'. – Jonathan Leffler Jan 12 '12 at 02:32
  • Yes, some dependencies in the original graph will be lost in the result. DenIs is right in his example. – JPM Jan 12 '12 at 03:05
  • Seems similar to https://stackoverflow.com/questions/5004973/algorithm-for-computing-partial-orderings-of-dependency-graphs/5057093#5057093 – Gabriel Devillers Aug 02 '21 at 12:14

1 Answers1

7

Let G be the transitive closure of the graph. Let G' be the undirected graph that results from removing the orientation from G and taking the complement. The connected components of the G' are the sets you are looking for.

wye.bee
  • 708
  • 4
  • 11