Thu Sep 19, 2019 3:30 pm
Login Register Lost Password? Contact Us


Interesting 'Daisy Chain' problem.

Comments and questions related to the Enterprise Control Language

Mon Aug 19, 2019 1:24 pm Change Time Zone

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,Job3
Job4,Job5,Job6,Job7
Job8

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: 375
Joined: Sat Oct 01, 2011 7:26 pm

Mon Aug 19, 2019 2:15 pm Change Time Zone

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
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1475
Joined: Wed Oct 26, 2011 7:40 pm

Mon Aug 19, 2019 3:05 pm Change Time Zone

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

Mon Aug 19, 2019 3:14 pm Change Time Zone

Tony,

Nice!! ;)

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1475
Joined: Wed Oct 26, 2011 7:40 pm

Tue Aug 20, 2019 8:06 am Change Time Zone

Thanks, Both of you.

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

Allan
Allan
 
Posts: 375
Joined: Sat Oct 01, 2011 7:26 pm


Return to ECL

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron