Wed Feb 26, 2020 12:43 am

## Interesting 'Daisy Chain' problem.

Comments and questions related to the Enterprise Control Language
Hi,
I have a series of tasks whose run sequence is dictated by a 'state' number. Runs can also occur in parallel. Each sequence is terminated with a 'next state' of zero.
e.g.

Code: Select all
`state    next-state    Task   1         2         Job1   2         3         Job2   3         0         Job3  55        77         Job4  77        22         Job5  22        23         Job6  23         0         Job7   4         0         Job8`

This would run these jobs in parallel:
Code: Select all
`Job1,Job2,Job3Job4,Job5,Job6,Job7Job8`

The daisy-chaining from one state to another is easy enough, my question is, given just this dataset, what ECL returns a list of all the start states.
e.g., in this case, the result would be 1,4,55 (I've deliberately mixed the numbers up as the numbers given to states may well not be in sequence)

There is LOOP, but I wondered if there was something a bit clever?

Yours

Allan
Allan

Posts: 419
Joined: Sat Oct 01, 2011 7:26 pm

Allan,

Here's how I would do it:
Code: Select all
`rec := {UNSIGNED1 state, UNSIGNED1 next_state, STRING4 Task};ds := DATASET([{  1,  2, 'Job1'},               {  2,  3, 'Job2'},               {  3,  0, 'Job3'},               { 55, 77, 'Job4'},               { 77, 22, 'Job5'},               { 22, 23, 'Job6'},               { 23,  0, 'Job7'},               {  4,  0, 'Job8'}],rec);StartTbl := TABLE(ds,{ds,BOOLEAN start := FALSE});Flagged  := ITERATE(StartTbl,                     TRANSFORM({StartTbl},                               SELF.start := LEFT.next_state = 0,                               SELF := RIGHT));Starters := PROJECT(Flagged(start = TRUE),rec);Starters;`

HTH,

Richard
rtaylor

Posts: 1519
Joined: Wed Oct 26, 2011 7:40 pm

You're essentially looking for all those not referenced in next_state, right?

Code: Select all
`ds(state not in set(ds, next_state));`

JOIN logic could be used, especially if ds is large.
Tony Kirk

Posts: 15
Joined: Thu Jun 23, 2011 5:01 pm

Tony,

Nice!!

Richard
rtaylor

Posts: 1519
Joined: Wed Oct 26, 2011 7:40 pm

Thanks, Both of you.

Tony, Whatever they're paying you it's not enough.

Allan
Allan

Posts: 419
Joined: Sat Oct 01, 2011 7:26 pm