1classdef Task < LayeredNetworkElement
2 % A software server in a LayeredNetwork.
4 % Copyright (c) 2012-2026, Imperial College London
13 thinkTimeMean; %
double
23 %
public methods, including constructor
26 function self = Task(model, name, multiplicity, scheduling, thinkTime)
27 % self = TASK(MODEL, NAME, MULTIPLICITY, SCHEDULING, THINKTIME)
29 if nargin<2%~exist(
'name',
'var')
30 line_error(mfilename,'Constructor requires to specify at least a name.');
32 self@LayeredNetworkElement(name);
34 if nargin<3%~exist('multiplicity','var')
37 if nargin<4%~exist('scheduling','var')
38 scheduling = SchedStrategy.INF;
40 if nargin<5%~exist('thinkTime','var')
41 thinkTime = GlobalConstants.FineTol;
44 self.multiplicity = multiplicity;
46 case SchedStrategy.INF
47 if isfinite(multiplicity)
48 line_warning(mfilename,'Finite multiplicity
is not allowed with INF scheduling. Setting it to INF.\n');
49 self.multiplicity = Inf;
52 self.scheduling = SchedStrategy.toText(scheduling);
53 self.setThinkTime(thinkTime);
56 if isa(model,'LayeredNetwork')
57 model.tasks{end+1} = self;
60 model.reftasks{end+1} = self;
63 elseif isa(model,
'JLayeredNetwork')
64 % JLayeredNetwork support would go here
if it exists
65 self.obj = jline.lang.layered.Task(model.obj, name, multiplicity, scheduling, thinkTime);
70 function self = setReplication(self, replication)
71 self.replication = replication;
74 function self = on(self, parent)
75 % self = ON(self, PARENT)
76 if ~isa(parent,
'Host') && ~isa(parent,
'Processor')
77 line_error(mfilename,'Invalid .on() argument: expected a host processor.')
79 if isempty(self.parent)
83 line_error(mfilename,'Parent processor already defined.')
87 function self = setAsReferenceTask(self)
88 % self = SETASREFERENCETASK(self)
90 self.scheduling = SchedStrategy.REF;
93 function self = setThinkTime(self, thinkTime)
94 % self = SETTHINKTIME(self, THINKTIME)
96 if isnumeric(thinkTime)
97 if thinkTime <= GlobalConstants.FineTol
98 self.thinkTime = Immediate.getInstance();
99 self.thinkTimeMean = GlobalConstants.FineTol;
100 self.thinkTimeSCV = GlobalConstants.FineTol;
102 self.thinkTime = Exp(1/thinkTime);
103 self.thinkTimeMean = thinkTime;
104 self.thinkTimeSCV = 1.0;
106 elseif isa(thinkTime,'Distribution')
107 self.thinkTime = thinkTime;
108 self.thinkTimeMean = thinkTime.getMean();
109 self.thinkTimeSCV = thinkTime.getSCV();
114 function self = addEntry(self, newEntry)
115 % self = ADDENTRY(self, NEWENTRY)
117 self.entries = [self.entries; newEntry];
121 function self = addActivity(self, newAct)
122 % self = ADDACTIVITY(self, NEWACT)
124 newAct.setParent(self.name);
125 self.activities = [self.activities; newAct];
129 function self = setActivity(self, newAct, index)
130 % self = SETACTIVITY(self, NEWACT, INDEX)
132 self.activities(index,1) = newAct;
136 function self = removeActivity(self, index)
137 % self = REMOVEACTIVITY(self, INDEX)
139 idxToKeep = [1:index-1,index+1:length(self.activities)];
140 self.activities = self.activities(idxToKeep);
141 self.actNames = self.actNames(idxToKeep);
145 function self = addPrecedence(self, newPrec)
146 % self = ADDPRECEDENCE(self, NEWPREC)
149 for m=1:length(newPrec)
150 self.precedences = [self.precedences; newPrec{m}];
153 self.precedences = [self.precedences; newPrec];
158 function self = setReplyEntry(self, newReplyEntry)
159 % self = SETREPLYENTRY(self, NEWREPLYENTRY)
161 self.replyEntry = newReplyEntry;
164 function meanHostDemand = getMeanHostDemand(self, entryName)
165 % MEANHOSTDEMAND = GETMEANHOSTDEMAND(self, ENTRYNAME)
167 % determines the demand posed by the entry entryName
168 % the demand
is located in the activity of the corresponding entry
171 for j = 1:length(self.entries)
172 if strcmp(self.entries(j).name, entryName)
173 meanHostDemand = self.entries(j).activities(1).hostDemandMean;