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 thinkTime;
13 thinkTimeMean; %double
14 thinkTimeSCV; %double
15 entries = [];
16 activities = [];
17 precedences = [];
18 replyEntry;
19 end
20
21
22 methods
23 %public methods, including constructor
24
25 %constructor
26 function self = Task(model, name, multiplicity, scheduling, thinkTime)
27 % self = TASK(MODEL, NAME, MULTIPLICITY, SCHEDULING, THINKTIME)
28 name = char(name);
29 if nargin<2%~exist('name','var')
30 line_error(mfilename,'Constructor requires to specify at least a name.');
31 end
32 self@LayeredNetworkElement(name);
33
34 if nargin<3%~exist('multiplicity','var')
35 multiplicity = 1;
36 end
37 if nargin<4%~exist('scheduling','var')
38 scheduling = SchedStrategy.INF;
39 end
40 if nargin<5%~exist('thinkTime','var')
41 thinkTime = GlobalConstants.FineTol;
42 end
43 self.replication = 1;
44 self.multiplicity = multiplicity;
45 switch scheduling
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;
50 end
51 end
52 self.scheduling = SchedStrategy.toText(scheduling);
53 self.setThinkTime(thinkTime);
54 self.parent = [];
55
56 if isa(model,'LayeredNetwork')
57 model.tasks{end+1} = self;
58 switch scheduling
59 case 'ref'
60 model.reftasks{end+1} = self;
61 end
62 self.model = model;
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);
66 model.addTask(self);
67 end
68 end
69
70 function self = setReplication(self, replication)
71 self.replication = replication;
72 end
73
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.')
78 end
79 if isempty(self.parent)
80 self.parent = parent;
81 parent.addTask(self);
82 else
83 line_error(mfilename,'Parent processor already defined.')
84 end
85 end
86
87 function self = setAsReferenceTask(self)
88 % self = SETASREFERENCETASK(self)
89
90 self.scheduling = SchedStrategy.REF;
91 end
92
93 function self = setThinkTime(self, thinkTime)
94 % self = SETTHINKTIME(self, THINKTIME)
95
96 if isnumeric(thinkTime)
97 if thinkTime <= GlobalConstants.FineTol
98 self.thinkTime = Immediate.getInstance();
99 self.thinkTimeMean = GlobalConstants.FineTol;
100 self.thinkTimeSCV = GlobalConstants.FineTol;
101 else
102 self.thinkTime = Exp(1/thinkTime);
103 self.thinkTimeMean = thinkTime;
104 self.thinkTimeSCV = 1.0;
105 end
106 elseif isa(thinkTime,'Distribution')
107 self.thinkTime = thinkTime;
108 self.thinkTimeMean = thinkTime.getMean();
109 self.thinkTimeSCV = thinkTime.getSCV();
110 end
111 end
112
113 %addEntry
114 function self = addEntry(self, newEntry)
115 % self = ADDENTRY(self, NEWENTRY)
116
117 self.entries = [self.entries; newEntry];
118 end
119
120 %addActivity
121 function self = addActivity(self, newAct)
122 % self = ADDACTIVITY(self, NEWACT)
123
124 newAct.setParent(self.name);
125 self.activities = [self.activities; newAct];
126 end
127
128 %setActivity
129 function self = setActivity(self, newAct, index)
130 % self = SETACTIVITY(self, NEWACT, INDEX)
131
132 self.activities(index,1) = newAct;
133 end
134
135 %removeActivity
136 function self = removeActivity(self, index)
137 % self = REMOVEACTIVITY(self, INDEX)
138
139 idxToKeep = [1:index-1,index+1:length(self.activities)];
140 self.activities = self.activities(idxToKeep);
141 self.actNames = self.actNames(idxToKeep);
142 end
143
144 %addPrecedence
145 function self = addPrecedence(self, newPrec)
146 % self = ADDPRECEDENCE(self, NEWPREC)
147
148 if iscell(newPrec)
149 for m=1:length(newPrec)
150 self.precedences = [self.precedences; newPrec{m}];
151 end
152 else
153 self.precedences = [self.precedences; newPrec];
154 end
155 end
156
157 %setReplyEntry
158 function self = setReplyEntry(self, newReplyEntry)
159 % self = SETREPLYENTRY(self, NEWREPLYENTRY)
160
161 self.replyEntry = newReplyEntry;
162 end
163
164 function meanHostDemand = getMeanHostDemand(self, entryName)
165 % MEANHOSTDEMAND = GETMEANHOSTDEMAND(self, ENTRYNAME)
166
167 % determines the demand posed by the entry entryName
168 % the demand is located in the activity of the corresponding entry
169
170 meanHostDemand = -1;
171 for j = 1:length(self.entries)
172 if strcmp(self.entries(j).name, entryName)
173 meanHostDemand = self.entries(j).activities(1).hostDemandMean;
174 break;
175 end
176 end
177 end
178
179 end
180
181end