1function members = fj_branch_members(lqn, joinaidx)
2% FJ_BRANCH_MEMBERS Activities belonging to each branch of an AND-join.
4% MEMBERS = FJ_BRANCH_MEMBERS(LQN, JOINAIDX) returns a cell array with one entry
5% per branch feeding the AND-join activity JOINAIDX. Each entry lists the global
6% activity indices lying on that branch, from its head (the activity spawned by
7% the AND-fork) to its tail (the immediate predecessor of the join).
9% A branch
is recovered by walking backwards from each immediate predecessor of
10% the join until an activity marked POST_AND
is reached, that activity being the
11% branch head spawned by the fork. Branches between a fork and its join are
12% disjoint paths, so the walk
is unambiguous.
15preds = find(lqn.graph(:, joinaidx) > 0)
';
20 if tail <= ashift || tail > ashift + nacts
21 continue; % not an activity
28 % The branch head is the activity the fork spawned.
29 if full(lqn.actposttype(cur)) == ActivityPrecedenceType.POST_AND
32 prevs = find(lqn.graph(:, cur) > 0)';
33 prevs = prevs(prevs > ashift & prevs <= ashift + nacts);
35 break; % a merge or the start of the graph: stop here
38 chain(end+1) = cur; %#ok<AGROW>
40 members{end+1} = chain; %#ok<AGROW>