LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Task.m
1classdef Task < LayeredNetworkElement
2 % A software server in a LayeredNetwork.
3 %
4 % Copyright (c) 2012-2026, Imperial College London
5 % All rights reserved.
6
7 properties
8 parent;
9 multiplicity; %int
10 replication; %int
11 scheduling; %string
12 priority = 0; %int, priority level (0 = default/no priority)
13 fanInSource = ''; %string, source task for fan-in
14 fanInValue = 0; %int, fan-in value (load distribution count)
15 fanOutDest = {}; %cell of strings, destination tasks for fan-out
16 fanOutValue = []; %vector of ints, fan-out values
17 thinkTime;
18 thinkTimeMean; %double
19 thinkTimeSCV; %double
20 setupTime;
21 setupTimeMean; %double
22 setupTimeSCV; %double
23 delayOffTime;
24 delayOffTimeMean; %double
25 delayOffTimeSCV; %double
26 entries = [];
27 activities = [];
28 precedences = [];
29 replyEntry;
30 end
31
32
33 methods
34 %public methods, including constructor
35
36 %constructor
37 function self = Task(model, name, multiplicity, scheduling, thinkTime)
38 % self = TASK(MODEL, NAME, MULTIPLICITY, SCHEDULING, THINKTIME)
39 name = char(name);
40 if nargin<2%~exist('name','var')
41 line_error(mfilename,'Constructor requires to specify at least a name.');
42 end
43 self@LayeredNetworkElement(name);
44
45 if nargin<3%~exist('multiplicity','var')
46 multiplicity = 1;
47 end
48 if nargin<4%~exist('scheduling','var')
49 scheduling = SchedStrategy.INF;
50 end
51 if nargin<5%~exist('thinkTime','var')
52 thinkTime = GlobalConstants.FineTol;
53 end
54 self.replication = 1;
55 self.multiplicity = multiplicity;
56 switch scheduling
57 case SchedStrategy.INF
58 if isfinite(multiplicity)
59 line_warning(mfilename,'Finite multiplicity is not allowed with INF scheduling. Setting it to INF.\n');
60 self.multiplicity = Inf;
61 end
62 end
63 self.scheduling = SchedStrategy.toText(scheduling);
64 self.setThinkTime(thinkTime);
65 self.setSetupTime(Immediate());
66 self.setDelayOffTime(Immediate());
67 self.parent = [];
68
69 if isa(model,'LayeredNetwork')
70 model.tasks{end+1} = self;
71 switch scheduling
72 case 'ref'
73 model.reftasks{end+1} = self;
74 end
75 self.model = model;
76 elseif isa(model,'JLayeredNetwork')
77 % JLayeredNetwork support would go here if it exists
78 self.obj = jline.lang.layered.Task(model.obj, name, multiplicity, scheduling, thinkTime);
79 model.addTask(self);
80 end
81 end
82
83 function self = setReplication(self, replication)
84 self.replication = replication;
85 end
86
87 function self = on(self, parent)
88 % self = ON(self, PARENT)
89 if ~isa(parent,'Host') && ~isa(parent,'Processor')
90 line_error(mfilename,'Invalid .on() argument: expected a host processor.')
91 end
92 if isempty(self.parent)
93 self.parent = parent;
94 parent.addTask(self);
95 else
96 line_error(mfilename,'Parent processor already defined.')
97 end
98 end
99
100 function self = setAsReferenceTask(self)
101 % self = SETASREFERENCETASK(self)
102
103 self.scheduling = SchedStrategy.REF;
104 end
105
106 function self = setThinkTime(self, thinkTime)
107 % self = SETTHINKTIME(self, THINKTIME)
108
109 if isnumeric(thinkTime)
110 if thinkTime <= GlobalConstants.FineTol
111 self.thinkTime = Immediate.getInstance();
112 self.thinkTimeMean = GlobalConstants.FineTol;
113 self.thinkTimeSCV = GlobalConstants.FineTol;
114 else
115 self.thinkTime = Exp(1/thinkTime);
116 self.thinkTimeMean = thinkTime;
117 self.thinkTimeSCV = 1.0;
118 end
119 elseif isa(thinkTime,'Distribution')
120 self.thinkTime = thinkTime;
121 self.thinkTimeMean = thinkTime.getMean();
122 self.thinkTimeSCV = thinkTime.getSCV();
123 end
124 end
125
126 function self = setSetupTime(self, setupTime)
127 % self = SETSETUPTIME(self, SETUPTIME)
128 % Set the setup time (cold start time) for the task.
129
130 if isnumeric(setupTime)
131 if setupTime <= GlobalConstants.FineTol
132 self.setupTime = Immediate.getInstance();
133 self.setupTimeMean = GlobalConstants.FineTol;
134 self.setupTimeSCV = GlobalConstants.FineTol;
135 else
136 self.setupTime = Exp(1/setupTime);
137 self.setupTimeMean = setupTime;
138 self.setupTimeSCV = 1.0;
139 end
140 elseif isa(setupTime,'Distribution')
141 self.setupTime = setupTime;
142 self.setupTimeMean = setupTime.getMean();
143 self.setupTimeSCV = setupTime.getSCV();
144 end
145 end
146
147 function self = setDelayOffTime(self, delayOffTime)
148 % self = SETDELAYOFFTIME(self, DELAYOFFTIME)
149 % Set the delay-off time (teardown time) for the task.
150
151 if isnumeric(delayOffTime)
152 if delayOffTime <= GlobalConstants.FineTol
153 self.delayOffTime = Immediate.getInstance();
154 self.delayOffTimeMean = GlobalConstants.FineTol;
155 self.delayOffTimeSCV = GlobalConstants.FineTol;
156 else
157 self.delayOffTime = Exp(1/delayOffTime);
158 self.delayOffTimeMean = delayOffTime;
159 self.delayOffTimeSCV = 1.0;
160 end
161 elseif isa(delayOffTime,'Distribution')
162 self.delayOffTime = delayOffTime;
163 self.delayOffTimeMean = delayOffTime.getMean();
164 self.delayOffTimeSCV = delayOffTime.getSCV();
165 end
166 end
167
168 function result = hasSetupDelayoff(self)
169 % result = HASSETUPDELAYOFF(self)
170 % Check if this task has setup/delayoff configured (i.e., non-trivial values).
171
172 hasSetup = ~isempty(self.setupTime) && ~isa(self.setupTime, 'Immediate') ...
173 && self.setupTimeMean > GlobalConstants.FineTol;
174 hasDelayoff = ~isempty(self.delayOffTime) && ~isa(self.delayOffTime, 'Immediate') ...
175 && self.delayOffTimeMean > GlobalConstants.FineTol;
176 result = hasSetup || hasDelayoff;
177 end
178
179 %addEntry
180 function self = addEntry(self, newEntry)
181 % self = ADDENTRY(self, NEWENTRY)
182
183 self.entries = [self.entries; newEntry];
184 end
185
186 %addActivity
187 function self = addActivity(self, newAct)
188 % self = ADDACTIVITY(self, NEWACT)
189
190 newAct.setParent(self.name);
191 self.activities = [self.activities; newAct];
192 end
193
194 %setActivity
195 function self = setActivity(self, newAct, index)
196 % self = SETACTIVITY(self, NEWACT, INDEX)
197
198 self.activities(index,1) = newAct;
199 end
200
201 %removeActivity
202 function self = removeActivity(self, index)
203 % self = REMOVEACTIVITY(self, INDEX)
204
205 idxToKeep = [1:index-1,index+1:length(self.activities)];
206 self.activities = self.activities(idxToKeep);
207 self.actNames = self.actNames(idxToKeep);
208 end
209
210 %addPrecedence
211 function self = addPrecedence(self, newPrec)
212 % self = ADDPRECEDENCE(self, NEWPREC)
213
214 if iscell(newPrec)
215 for m=1:length(newPrec)
216 self.precedences = [self.precedences; newPrec{m}];
217 end
218 else
219 self.precedences = [self.precedences; newPrec];
220 end
221 end
222
223 %setReplyEntry
224 function self = setReplyEntry(self, newReplyEntry)
225 % self = SETREPLYENTRY(self, NEWREPLYENTRY)
226
227 self.replyEntry = newReplyEntry;
228 end
229
230 function meanHostDemand = getMeanHostDemand(self, entryName)
231 % MEANHOSTDEMAND = GETMEANHOSTDEMAND(self, ENTRYNAME)
232
233 % determines the demand posed by the entry entryName
234 % the demand is located in the activity of the corresponding entry
235
236 meanHostDemand = -1;
237 for j = 1:length(self.entries)
238 if strcmp(self.entries(j).name, entryName)
239 meanHostDemand = self.entries(j).activities(1).hostDemandMean;
240 break;
241 end
242 end
243 end
244
245 % Getter methods for API consistency with Java/Python
246 function val = getMultiplicity(obj)
247 % GETMULTIPLICITY Get the multiplicity (number of task instances)
248 val = obj.multiplicity;
249 end
250
251 function val = getReplication(obj)
252 % GETREPLICATION Get the replication factor
253 val = obj.replication;
254 end
255
256 function val = getScheduling(obj)
257 % GETSCHEDULING Get the scheduling strategy
258 val = obj.scheduling;
259 end
260
261 function val = getThinkTimeMean(obj)
262 % GETTHINKTIMEMEAN Get the mean think time
263 val = obj.thinkTimeMean;
264 end
265
266 function val = getThinkTimeSCV(obj)
267 % GETTHINKTIMESCV Get the SCV of think time
268 val = obj.thinkTimeSCV;
269 end
270
271 function val = getParent(obj)
272 % GETPARENT Get the parent host/processor
273 val = obj.parent;
274 end
275
276 function val = getPrecedences(obj)
277 % GETPRECEDENCES Get the list of activity precedences
278 val = obj.precedences;
279 end
280
281 function val = getSetupTimeMean(obj)
282 % GETSETUPTIMEMEAN Get the mean setup time
283 val = obj.setupTimeMean;
284 end
285
286 function val = getDelayOffTimeMean(obj)
287 % GETDELAYOFFTIMEMEAN Get the mean delay-off time
288 val = obj.delayOffTimeMean;
289 end
290
291 % setPriority
292 function self = setPriority(self, priority)
293 % self = SETPRIORITY(self, PRIORITY)
294 self.priority = priority;
295 end
296
297 % setFanIn
298 function self = setFanIn(self, source, value)
299 % self = SETFANIN(self, SOURCE, VALUE)
300 self.fanInSource = source;
301 self.fanInValue = value;
302 end
303
304 % setFanOut
305 function self = setFanOut(self, dest, value)
306 % self = SETFANOUT(self, DEST, VALUE)
307 self.fanOutDest{end+1} = dest;
308 self.fanOutValue(end+1) = value;
309 end
310
311 end
312
313end