You're right about the last bit - you can't start with a transitive closure.  I missed that.

Suppose you turn each dependency into a J sentence, say

a =: 5

or

c =: longerof (a , b)

or

f =: a following (e , g)

or combinations thereof.  There must be no loops in the dependencies, so you could do a topological sort on the tasks, to ensure that each assignment refers only to names that have already defined.  Then just execute the sorted script and see the results.

You would need the definitions

longerof =: >./
following =: +

and you need a topological sort, which isn't too hard.  I know I wrote one for the Advent of Code problems a couple of years ago.

Henry Rich

On 11/28/2017 7:32 PM, Raul Miller wrote:
Something based on transitive closure does sound like the way to go.

And this might be the essay Henry Rich was thinking of:
http://code.jsoftware.com/wiki/User:Roger_Hui/t

But I am having trouble following along here.

The text says "task C can only start after tasks A and B finish" and
    graph =: 4 4 $ 0 0 0 0  1 0 0 0  1 0 0 0  0 1 1 0  NB. col 0 =
depends-on A, col 1 = depends-on B, etc.

So, I am expecting
    nodes=: 'ABCD'

And when I look at which nodes C depends on in that graph, I do not
see a dependency on B:
    ((nodes i.'C'){graph)#nodes
A

So I am already lost.

But, wait, maybe I should be looking at the transitive closure of the graph?

    ((nodes i.'C'){(+. +./ .*~)^:_ graph)#nodes
A

D depends on A and B and C, but B and C only depend on A.

There might be another subtlety to this problem, but need to get the
problem statement correct before addressing any such thing.

That said, I think there's going to be another issue, though, with
transitive closure. You don't strictly want the transitive closure
here. It's not just that D depends on A, B and C - the A and B
dependencies are in parallel, while the C dependency is in series.
Parallel is handled by >. and series is handled by + - I suspect you
need a third operation to determine relevance at any given step. But
can't reason about that until we get the example right for the
numbers.

Thanks,



---
This email has been checked for viruses by AVG.
http://www.avg.com

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to