LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
fj_branch_members.m
1function members = fj_branch_members(lqn, joinaidx)
2% FJ_BRANCH_MEMBERS Activities belonging to each branch of an AND-join.
3%
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).
8%
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.
13
14members = {};
15preds = find(lqn.graph(:, joinaidx) > 0)';
16ashift = lqn.ashift;
17nacts = lqn.nacts;
18
19for tail = preds
20 if tail <= ashift || tail > ashift + nacts
21 continue; % not an activity
22 end
23 chain = tail;
24 cur = tail;
25 guard = 0;
26 while guard < nacts
27 guard = guard + 1;
28 % The branch head is the activity the fork spawned.
29 if full(lqn.actposttype(cur)) == ActivityPrecedenceType.POST_AND
30 break;
31 end
32 prevs = find(lqn.graph(:, cur) > 0)';
33 prevs = prevs(prevs > ashift & prevs <= ashift + nacts);
34 if numel(prevs) ~= 1
35 break; % a merge or the start of the graph: stop here
36 end
37 cur = prevs(1);
38 chain(end+1) = cur; %#ok<AGROW>
39 end
40 members{end+1} = chain; %#ok<AGROW>
41end
42end