LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ServerType.m
1classdef ServerType < Element
2 % ServerType Represents a type of server within a heterogeneous multiserver queue
3 %
4 % ServerType defines a group of identical servers with:
5 % - A unique name identifying this server type
6 % - A count of servers of this type
7 % - A list of job classes that are compatible with (can be served by) this type
8 %
9 % Server types enable modeling of heterogeneous multiserver queues where different
10 % servers may have different service rates and serve different subsets of job classes.
11 %
12 % Example:
13 % @code
14 % fastServer = ServerType('Fast', 2);
15 % fastServer.setCompatible([classA, classB]);
16 % queue.addServerType(fastServer);
17 % queue.setService(classA, fastServer, Exp(2.0));
18 % @endcode
19 %
20 % Copyright (c) 2012-2026, Imperial College London
21 % All rights reserved.
22
23 properties
24 id; % Unique identifier within the queue
25 numOfServers; % Number of servers of this type
26 compatibleClasses; % Cell array of compatible JobClass objects
27 parentQueue; % The Queue this server type belongs to
28 end
29
30 methods
31 function self = ServerType(name, numOfServers, compatibleClasses)
32 % SERVERTYPE Create a new server type
33 %
34 % self = SERVERTYPE(name, numOfServers) creates a server type with
35 % the specified name and number of servers. Compatible classes can
36 % be added later using setCompatible() or addCompatible().
37 %
38 % self = SERVERTYPE(name, numOfServers, compatibleClasses) creates
39 % a server type with initial compatible classes.
40 %
41 % @param name String name identifying this server type
42 % @param numOfServers Number of servers of this type (must be >= 1)
43 % @param compatibleClasses (optional) Cell array or array of JobClass objects
44
45 self@Element(name);
46
47 if numOfServers < 1
48 line_error(mfilename, 'Number of servers must be at least 1');
49 end
50
51 self.id = -1; % Will be set when added to a queue
52 self.numOfServers = numOfServers;
53 self.parentQueue = [];
54
55 if nargin < 3
56 self.compatibleClasses = {};
57 else
58 if iscell(compatibleClasses)
59 self.compatibleClasses = compatibleClasses;
60 else
61 % Convert array to cell array
62 self.compatibleClasses = cell(1, length(compatibleClasses));
63 for i = 1:length(compatibleClasses)
64 self.compatibleClasses{i} = compatibleClasses(i);
65 end
66 end
67 end
68 end
69
70 function id = getId(self)
71 % GETID Get the server type ID
72 %
73 % id = GETID() returns the unique identifier of this server type
74 % within its queue, or -1 if not yet added to a queue.
75
76 id = self.id;
77 end
78
79 function self = setId(self, id)
80 % SETID Set the server type ID
81 %
82 % self = SETID(id) sets the unique identifier. This is typically
83 % called by the Queue when the server type is added.
84
85 self.id = id;
86 end
87
88 function n = getNumOfServers(self)
89 % GETNUMOFSERVERS Get the number of servers of this type
90 %
91 % n = GETNUMOFSERVERS() returns the number of servers.
92
93 n = self.numOfServers;
94 end
95
96 function self = setNumOfServers(self, n)
97 % SETNUMOFSERVERS Set the number of servers of this type
98 %
99 % self = SETNUMOFSERVERS(n) sets the number of servers (must be >= 1).
100
101 if n < 1
102 line_error(mfilename, 'Number of servers must be at least 1');
103 end
104 self.numOfServers = n;
105 end
106
107 function classes = getCompatibleClasses(self)
108 % GETCOMPATIBLECLASSES Get the list of compatible job classes
109 %
110 % classes = GETCOMPATIBLECLASSES() returns a cell array of
111 % compatible JobClass objects.
112
113 classes = self.compatibleClasses;
114 end
115
116 function self = setCompatible(self, classes)
117 % SETCOMPATIBLE Set the list of compatible job classes
118 %
119 % self = SETCOMPATIBLE(classes) sets the list of job classes that
120 % can be served by this server type.
121 %
122 % @param classes Array or cell array of JobClass objects
123
124 if iscell(classes)
125 self.compatibleClasses = classes;
126 else
127 % Convert array to cell array
128 self.compatibleClasses = cell(1, length(classes));
129 for i = 1:length(classes)
130 self.compatibleClasses{i} = classes(i);
131 end
132 end
133 end
134
135 function self = addCompatible(self, jobClass)
136 % ADDCOMPATIBLE Add a job class to the compatible list
137 %
138 % self = ADDCOMPATIBLE(jobClass) adds a job class to the list of
139 % classes that can be served by this server type.
140 %
141 % @param jobClass The JobClass to add
142
143 if ~self.isCompatible(jobClass)
144 self.compatibleClasses{end+1} = jobClass;
145 end
146 end
147
148 function self = removeCompatible(self, jobClass)
149 % REMOVECOMPATIBLE Remove a job class from the compatible list
150 %
151 % self = REMOVECOMPATIBLE(jobClass) removes a job class from the
152 % list of compatible classes.
153 %
154 % @param jobClass The JobClass to remove
155
156 idx = [];
157 for i = 1:length(self.compatibleClasses)
158 if self.compatibleClasses{i} == jobClass
159 idx = i;
160 break;
161 end
162 end
163 if ~isempty(idx)
164 self.compatibleClasses(idx) = [];
165 end
166 end
167
168 function result = isCompatible(self, jobClass)
169 % ISCOMPATIBLE Check if a job class is compatible with this server type
170 %
171 % result = ISCOMPATIBLE(jobClass) returns true if the job class
172 % can be served by this server type.
173 %
174 % @param jobClass The JobClass to check
175 % @return result Boolean indicating compatibility
176
177 result = false;
178 for i = 1:length(self.compatibleClasses)
179 if self.compatibleClasses{i} == jobClass
180 result = true;
181 return;
182 end
183 end
184 end
185
186 function n = getNumCompatibleClasses(self)
187 % GETNUMCOMPATIBLECLASSES Get the number of compatible classes
188 %
189 % n = GETNUMCOMPATIBLECLASSES() returns the count of compatible classes.
190
191 n = length(self.compatibleClasses);
192 end
193
194 function result = hasCompatibleClasses(self)
195 % HASCOMPATIBLECLASSES Check if any compatible classes are defined
196 %
197 % result = HASCOMPATIBLECLASSES() returns true if at least one
198 % compatible class is defined.
199
200 result = ~isempty(self.compatibleClasses);
201 end
202
203 function queue = getParentQueue(self)
204 % GETPARENTQUEUE Get the parent queue
205 %
206 % queue = GETPARENTQUEUE() returns the Queue this server type
207 % belongs to, or [] if not yet added to a queue.
208
209 queue = self.parentQueue;
210 end
211
212 function self = setParentQueue(self, queue)
213 % SETPARENTQUEUE Set the parent queue
214 %
215 % self = SETPARENTQUEUE(queue) sets the parent queue. This is
216 % typically called by the Queue when the server type is added.
217
218 self.parentQueue = queue;
219 end
220
221 function summary(self)
222 % SUMMARY Print a summary of this server type
223 %
224 % SUMMARY() displays information about this server type.
225
226 line_printf('ServerType: <strong>%s</strong>', self.name);
227 line_printf(' ID: %d', self.id);
228 line_printf(' Number of servers: %d', self.numOfServers);
229 line_printf(' Compatible classes: %d', length(self.compatibleClasses));
230 for i = 1:length(self.compatibleClasses)
231 line_printf(' - %s', self.compatibleClasses{i}.getName());
232 end
233 end
234 end
235end