1classdef Task < LayeredNetworkElement
2 % A software server in a LayeredNetwork.
4 % Copyright (c) 2012-2026, Imperial College London
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)
16 thinkTimeMean; %
double
19 setupTimeMean; %
double
22 delayOffTimeMean; %
double
23 delayOffTimeSCV; %
double
32 %
public methods, including constructor
35 function self = Task(model, name, multiplicity, scheduling, thinkTime)
36 % self = TASK(MODEL, NAME, MULTIPLICITY, SCHEDULING, THINKTIME)
38 if nargin<2%~exist(
'name',
'var')
39 line_error(mfilename,'Constructor requires to specify at least a name.');
41 self@LayeredNetworkElement(name);
43 if nargin<3%~exist('multiplicity','var')
46 if nargin<4%~exist('scheduling','var')
47 scheduling = SchedStrategy.INF;
49 if nargin<5%~exist('thinkTime','var')
50 thinkTime = GlobalConstants.FineTol;
53 self.multiplicity = multiplicity;
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;
61 self.scheduling = SchedStrategy.toText(scheduling);
62 self.setThinkTime(thinkTime);
63 self.setSetupTime(Immediate());
64 self.setDelayOffTime(Immediate());
67 if isa(model,'LayeredNetwork')
68 model.tasks{end+1} = self;
71 model.reftasks{end+1} = self;
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);
81 function self = setReplication(self, replication)
82 self.replication = replication;
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.')
90 if isempty(self.parent)
94 line_error(mfilename,'Parent processor already defined.')
98 function self = setAsReferenceTask(self)
99 % self = SETASREFERENCETASK(self)
101 self.scheduling = SchedStrategy.REF;
104 function self = setThinkTime(self, thinkTime)
105 % self = SETTHINKTIME(self, THINKTIME)
107 if isnumeric(thinkTime)
108 if thinkTime <= GlobalConstants.FineTol
109 self.thinkTime = Immediate.getInstance();
110 self.thinkTimeMean = GlobalConstants.FineTol;
111 self.thinkTimeSCV = GlobalConstants.FineTol;
113 self.thinkTime = Exp(1/thinkTime);
114 self.thinkTimeMean = thinkTime;
115 self.thinkTimeSCV = 1.0;
117 elseif isa(thinkTime,'Distribution')
118 self.thinkTime = thinkTime;
119 self.thinkTimeMean = thinkTime.getMean();
120 self.thinkTimeSCV = thinkTime.getSCV();
124 function self = setSetupTime(self, setupTime)
125 % self = SETSETUPTIME(self, SETUPTIME)
126 % Set the setup time (cold start time) for the task.
128 if isnumeric(setupTime)
129 if setupTime <= GlobalConstants.FineTol
130 self.setupTime = Immediate.getInstance();
131 self.setupTimeMean = GlobalConstants.FineTol;
132 self.setupTimeSCV = GlobalConstants.FineTol;
134 self.setupTime = Exp(1/setupTime);
135 self.setupTimeMean = setupTime;
136 self.setupTimeSCV = 1.0;
138 elseif isa(setupTime,'Distribution')
139 self.setupTime = setupTime;
140 self.setupTimeMean = setupTime.getMean();
141 self.setupTimeSCV = setupTime.getSCV();
145 function self = setDelayOffTime(self, delayOffTime)
146 % self = SETDELAYOFFTIME(self, DELAYOFFTIME)
147 % Set the delay-off time (teardown time) for the task.
149 if isnumeric(delayOffTime)
150 if delayOffTime <= GlobalConstants.FineTol
151 self.delayOffTime = Immediate.getInstance();
152 self.delayOffTimeMean = GlobalConstants.FineTol;
153 self.delayOffTimeSCV = GlobalConstants.FineTol;
155 self.delayOffTime = Exp(1/delayOffTime);
156 self.delayOffTimeMean = delayOffTime;
157 self.delayOffTimeSCV = 1.0;
159 elseif isa(delayOffTime,'Distribution')
160 self.delayOffTime = delayOffTime;
161 self.delayOffTimeMean = delayOffTime.getMean();
162 self.delayOffTimeSCV = delayOffTime.getSCV();
166 function result = hasSetupDelayoff(self)
167 % result = HASSETUPDELAYOFF(self)
168 % Check if this task has setup/delayoff configured (i.e., non-trivial values).
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;
178 function self = addEntry(self, newEntry)
179 % self = ADDENTRY(self, NEWENTRY)
181 self.entries = [self.entries; newEntry];
185 function self = addActivity(self, newAct)
186 % self = ADDACTIVITY(self, NEWACT)
188 newAct.setParent(self.name);
189 self.activities = [self.activities; newAct];
193 function self = setActivity(self, newAct, index)
194 % self = SETACTIVITY(self, NEWACT, INDEX)
196 self.activities(index,1) = newAct;
200 function self = removeActivity(self, index)
201 % self = REMOVEACTIVITY(self, INDEX)
203 idxToKeep = [1:index-1,index+1:length(self.activities)];
204 self.activities = self.activities(idxToKeep);
205 self.actNames = self.actNames(idxToKeep);
209 function self = addPrecedence(self, newPrec)
210 % self = ADDPRECEDENCE(self, NEWPREC)
213 for m=1:length(newPrec)
214 self.precedences = [self.precedences; newPrec{m}];
217 self.precedences = [self.precedences; newPrec];
222 function self = setReplyEntry(self, newReplyEntry)
223 % self = SETREPLYENTRY(self, NEWREPLYENTRY)
225 self.replyEntry = newReplyEntry;
228 function meanHostDemand = getMeanHostDemand(self, entryName)
229 % MEANHOSTDEMAND = GETMEANHOSTDEMAND(self, ENTRYNAME)
231 % determines the demand posed by the entry entryName
232 % the demand
is located in the activity of the corresponding entry
235 for j = 1:length(self.entries)
236 if strcmp(self.entries(j).name, entryName)
237 meanHostDemand = self.entries(j).activities(1).hostDemandMean;
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;
249 function val = getReplication(obj)
250 % GETREPLICATION Get the replication factor
251 val = obj.replication;
254 function val = getScheduling(obj)
255 % GETSCHEDULING Get the scheduling strategy
256 val = obj.scheduling;
259 function val = getThinkTimeMean(obj)
260 % GETTHINKTIMEMEAN Get the mean think time
261 val = obj.thinkTimeMean;
264 function val = getThinkTimeSCV(obj)
265 % GETTHINKTIMESCV Get the SCV of think time
266 val = obj.thinkTimeSCV;
269 function val = getParent(obj)
270 % GETPARENT Get the parent host/processor
274 function val = getPrecedences(obj)
275 % GETPRECEDENCES Get the list of activity precedences
276 val = obj.precedences;
279 function val = getSetupTimeMean(obj)
280 % GETSETUPTIMEMEAN Get the mean setup time
281 val = obj.setupTimeMean;
284 function val = getDelayOffTimeMean(obj)
285 % GETDELAYOFFTIMEMEAN Get the mean delay-off time
286 val = obj.delayOffTimeMean;
290 function self = setPriority(self, priority)
291 % self = SETPRIORITY(self, PRIORITY)
292 self.priority = priority;
296 function self = setFanIn(self, source, value)
297 % self = SETFANIN(self, SOURCE, VALUE)
298 self.fanInSource = source;
299 self.fanInValue = value;