LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ActivityPrecedence.m
1classdef ActivityPrecedence
2 % An auxiliary class to specify precedence among Activity elements.
3 %
4 % Copyright (c) 2012-2026, Imperial College London
5 % All rights reserved.
6
7 properties
8 preActs; %string array
9 postActs; %string array
10 preType; %string
11 postType; %string
12 preParams; %double array
13 postParams; %double array
14 end
15
16 methods
17 %public methods, including constructor
18
19 %constructor
20 function obj = ActivityPrecedence(preActs, postActs, preType, postType, preParams, postParams)
21 % OBJ = ACTIVITYPRECEDENCE(PREACTS, POSTACTS, PRETYPE, POSTTYPE, PREPARAMS, POSTPARAMS)
22
23 if nargin<2 %~exist('preActs','var') || ~exist('postActs','var')
24 line_error(mfilename,'Constructor requires to specify at least pre and post activities.');
25 end
26
27 if nargin<3 %~exist('preType','var')
28 preType = ActivityPrecedenceType.PRE_SEQ;
29 end
30 if nargin<4 %~exist('postType','var')
31 postType = ActivityPrecedenceType.POST_SEQ;
32 end
33 if nargin<5 %~exist('preParams','var')
34 preParams = [];
35 end
36 if nargin<6 %~exist('postParams','var')
37 postParams = [];
38 end
39 for a=1:length(preActs)
40 if isa(preActs{a},'Activity')
41 preActs{a} = preActs{a}.getName;
42 end
43 end
44 obj.preActs = preActs;
45 for a=1:length(postActs)
46 if isa(postActs{a},'Activity')
47 postActs{a} = postActs{a}.getName;
48 end
49 end
50 obj.postActs = postActs;
51 obj.preType = preType;
52 obj.postType = postType;
53 obj.preParams = preParams;
54 obj.postParams = postParams;
55 end
56
57 end
58
59 methods (Static, Hidden)
60 function ap = Sequence(preAct, postAct)
61 % AP = SEQUENCE(PREACT, POSTACT)
62 %
63 % Auxiliary method, use Serial instead.
64
65 if isa(preAct,'Activity')
66 preAct = preAct.name;
67 end
68 if isa(postAct,'Activity')
69 postAct = postAct.name;
70 end
71 ap = ActivityPrecedence({preAct},{postAct});
72 end
73 end
74
75 methods (Static)
76 function ap = Serial(varargin)
77 % AP = SERIAL(VARARGIN)
78
79 ap = cell(nargin-1,1);
80 for m = 1:nargin-1
81 ap{m} = ActivityPrecedence.Sequence(varargin{m},varargin{m+1});
82 end
83 end
84
85 function ap = AndJoin(preActs, postAct, quorum)
86 % AP = ANDJOIN(PREACTS, POSTACT, QUORUM)
87
88 for a = 1:length(preActs)
89 if isa(preActs{a},'Activity')
90 preActs{a} = preActs{a}.name;
91 end
92 end
93 if isa(postAct,'Activity')
94 postAct = postAct.name;
95 end
96 if nargin<3 %~exist('quorum','var')
97 quorum = [];
98 end
99 ap = ActivityPrecedence(preActs,{postAct},ActivityPrecedenceType.PRE_AND,ActivityPrecedenceType.POST_SEQ,quorum,[]);
100 end
101
102 function ap = OrJoin(preActs, postAct)
103 % AP = ORJOIN(PREACTS, POSTACT)
104
105 for a = 1:length(preActs)
106 if isa(preActs{a},'Activity')
107 preActs{a} = preActs{a}.name;
108 end
109 end
110 if isa(postAct,'Activity')
111 postAct = postAct.name;
112 end
113 ap = ActivityPrecedence(preActs,{postAct},ActivityPrecedenceType.PRE_OR,ActivityPrecedenceType.POST_SEQ);
114 end
115
116 function ap = AndFork(preAct, postActs)
117 % AP = ANDFORK(PREACT, POSTACTS)
118
119 if isa(preAct,'Activity')
120 preAct = preAct.name;
121 end
122 for a = 1:length(postActs)
123 if isa(postActs{a},'Activity')
124 postActs{a} = postActs{a}.name;
125 end
126 end
127 ap = ActivityPrecedence({preAct},postActs,ActivityPrecedenceType.PRE_SEQ,ActivityPrecedenceType.POST_AND);
128 end
129
130 function ap = Xor(preAct, postActs, probs)
131 % AP = XOR(PREACT, POSTACTS, PROBS)
132 %
133 % This is a pseudonym for OrFork
134 ap = ActivityPrecedence.OrFork(preAct, postActs, probs);
135 end
136
137 function ap = OrFork(preAct, postActs, probs)
138 % AP = ORFORK(PREACT, POSTACTS, PROBS)
139 %
140 % OrFork is the terminology used in LQNs for a probabilistic
141 % or, where a call chooses a branch with given probability
142
143 if isa(preAct,'Activity')
144 preAct = preAct.name;
145 end
146 for a = 1:length(postActs)
147 if isa(postActs{a},'Activity')
148 postActs{a} = postActs{a}.name;
149 end
150 end
151 ap = ActivityPrecedence({preAct},postActs,ActivityPrecedenceType.PRE_SEQ,ActivityPrecedenceType.POST_OR,[],probs);
152 end
153
154 function ap = Loop4para(preAct, loopAct, endAct, loopCounts)
155 if iscell(loopAct)
156 ap = ActivityPrecedence.Loop3para(preAct, {loopAct{:}, endAct}, loopCounts);
157 else
158 ap = ActivityPrecedence.Loop3para(preAct, {loopAct, endAct}, loopCounts);
159 end
160 end
161
162 function ap = Loop3para(preAct, postActs, counts)
163 % AP = LOOP(PREACT, POSTACTS, COUNTS)
164 % Example:
165 % ActivityPrecedence.Loop(A20, {A21, A22}, 3)
166 % runs A20 once, then 3 times A21, then ends running A22 once.
167
168 if isa(preAct,'Activity')
169 preAct = preAct.name;
170 end
171 for a = 1:length(postActs)
172 if isa(postActs{a},'Activity')
173 postActs{a} = postActs{a}.name;
174 end
175 end
176 ap = ActivityPrecedence({preAct},postActs,ActivityPrecedenceType.PRE_SEQ,ActivityPrecedenceType.POST_LOOP,[],counts);
177 end
178
179 function ap = Loop(varargin)
180 if length(varargin)==3
181 ap = ActivityPrecedence.Loop3para(varargin{1}, varargin{2}, varargin{3});
182 elseif length(varargin)==4
183 ap = ActivityPrecedence.Loop4para(varargin{1}, varargin{2}, varargin{3}, varargin{4});
184 else
185 line_error(mfilename,'Incorrect number of arguments to Loop construct.');
186 end
187 end
188
189 function ap = CacheAccess(preAct, postActs)
190 % AP = ORFORK(PREACT, POSTACTS, PROBS)
191
192 if isa(preAct,'Activity')
193 preAct = preAct.name;
194 end
195 for a = 1:length(postActs)
196 if isa(postActs{a},'Activity')
197 postActs{a} = postActs{a}.name;
198 end
199 end
200 ap = ActivityPrecedence({preAct},postActs,ActivityPrecedenceType.PRE_SEQ,ActivityPrecedenceType.POST_CACHE);
201 end
202 end
203
204end