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