LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
LayeredNetwork.m
1classdef LayeredNetwork < Model & Ensemble
2 % LayeredNetwork Hierarchical software performance modeling framework
3 %
4 % LayeredNetwork implements Layered Queueing Networks (LQN) for modeling
5 % hierarchical software systems with clients, application servers, and
6 % resource layers. It supports modeling of complex software architectures
7 % with tasks, entries, activities, and their interactions across multiple
8 % system layers.
9 %
10 % @brief Layered queueing network for hierarchical software performance models
11 %
12 % Key characteristics:
13 % - Hierarchical multi-layer architecture modeling
14 % - Software-centric performance analysis
15 % - Task and entry abstraction levels
16 % - Activity-based detailed modeling
17 % - Host resource modeling
18 % - Client-server interaction patterns
19 %
20 % LQN model components:
21 % - Hosts: Physical or logical processing resources
22 % - Tasks: Software processes or services
23 % - Entries: Service request entry points
24 % - Activities: Detailed task execution steps
25 % - Reference tasks: External workload generators
26 %
27 % LayeredNetwork is used for:
28 % - Software performance engineering
29 % - Multi-tier application modeling
30 % - Microservice architecture analysis
31 % - Distributed system performance evaluation
32 % - Capacity planning for software systems
33 %
34 % Example:
35 % @code
36 % lqn = LayeredNetwork('WebApp');
37 % client = Host(lqn, 'ClientTier', Inf);
38 % server = Host(lqn, 'ServerTier', 4);
39 % web_task = Task(lqn, 'WebServer', 1, server);
40 % request_entry = Entry(lqn, 'ProcessRequest', web_task);
41 % @endcode
42 %
43 % Copyright (c) 2012-2026, Imperial College London
44 % All rights reserved.
45
46 properties (Hidden)
47 lsn;
48 usedFeatures; % cell with structures of booleans listing the used classes
49 % it must be accessed via getUsedLangFeatures
50 end
51
52 properties
53 hosts = [];
54 tasks = [];
55 reftasks = [];
56 activities = [];
57 entries = [];
58 end
59
60 methods
61 %public methods, including constructor
62
63 function self = reset(self, isHard)
64 if nargin<2
65 isHard = false;
66 end
67 self.ensemble = {};
68 if isHard
69 self.hosts = {};
70 self.tasks = {};
71 self.reftasks = {};
72 self.entries = {};
73 self.activities = {};
74 end
75 end
76
77 % constructor
78 function self = LayeredNetwork(name, filename)
79 % LAYEREDNETWORK Create a layered queueing network model
80 %
81 % @brief Creates a LayeredNetwork instance for hierarchical modeling
82 % @param name String identifier for the layered model
83 % @param filename Optional filename for model import/export
84 % @return self LayeredNetwork instance ready for hierarchical modeling
85
86 self@Ensemble({})
87 if nargin<1 %~exist('name','var')
88 [~,name]=fileparts(lineTempName);
89 end
90 name = char(name);
91 self@Model(name);
92 self.ensemble = {};
93 self.hosts = {};
94 self.tasks = {};
95 self.reftasks = {};
96 self.entries = {};
97 self.activities = {};
98
99 if nargin>=2 %exist('filename','var')
100 self = LayeredNetwork.parseXML(filename, false);
101 end
102 end
103
104
105 function sn = summary(self)
106 % sn = SUMMARY()
107
108 sn = self.getStruct;
109 end
110
111 plot(self, showTaskGraph)
112 plotGraph(self, useNodes)
113 plotGraphSimple(self, useNodes)
114 plotTaskGraph(self, useNodes)
115 end
116
117 methods
118 idx = getNodeIndex(self,node)
119 node = getNodeByName(self,name)
120 [names,hostnames,tasknames,entrynames,actnames] = getNodeNames(self)
121
122 writeXML(self,filename,useAbstractNames);
123 end
124
125 methods
126
127 LQN = getStruct(self);
128
129 function E = getNumberOfLayers(self)
130 % E = GETNUMBEROFLAYERS()
131
132 E = getNumberOfModels(self);
133 end
134
135 function E = getNumberOfModels(self)
136 % E = GETNUMBEROFMODELS()
137
138 if isempty(self.ensemble)
139 self.ensemble = getEnsemble(self);
140 end
141 E = length(self.ensemble);
142 end
143
144 function layers = getLayers(self)
145 % LAYERS = GETLAYERS()
146
147 layers = getEnsemble(self);
148 end
149
150 % setUsedFeatures : records that a certain language feature has been used
151 function self = setUsedLangFeature(self,e,className)
152 % SELF = SETUSEDLANGFEATURE(SELF,E,CLASSNAME)
153
154 self.usedFeatures{e}.setTrue(className);
155 end
156
157 function self = initUsedFeatures(self)
158 % SELF = INITUSEDFEATURES()
159
160 for e=1:getNumberOfModels(self)
161 self.usedFeatures{e} = SolverFeatureSet;
162 end
163 end
164
165 function usedFeatures = getUsedLangFeatures(self)
166 % USEDFEATURES = GETUSEDLANGFEATURES()
167
168 E = getNumberOfLayers(self);
169 usedFeatures = cell(1,E);
170 for e=1:E
171 usedFeatures{e} = self.ensemble{e}.getUsedLangFeatures;
172 end
173 self.usedFeatures = usedFeatures;
174 end
175
176 function view(self)
177 jlqnmodel = JLINE.from_line_layered_network(self);
178 jlqnmodel.view();
179 end
180
181 function result = nodeIndex(self, varargin)
182 % NODEINDEX Kotlin-style alias for getNodeIndex
183 result = self.getNodeIndex(varargin{:});
184 end
185
186 function result = nodeByName(self, varargin)
187 % NODEBYNAME Kotlin-style alias for getNodeByName
188 result = self.getNodeByName(varargin{:});
189 end
190
191 function result = nodeNames(self, varargin)
192 % NODENAMES Kotlin-style alias for getNodeNames
193 result = self.getNodeNames(varargin{:});
194 end
195
196 function result = struct(self, varargin)
197 % STRUCT Kotlin-style alias for getStruct
198 result = self.getStruct(varargin{:});
199 end
200
201 function result = numberOfLayers(self, varargin)
202 % NUMBEROFLAYERS Kotlin-style alias for getNumberOfLayers
203 result = self.getNumberOfLayers(varargin{:});
204 end
205
206 function result = numberOfModels(self, varargin)
207 % NUMBEROFMODELS Kotlin-style alias for getNumberOfModels
208 result = self.getNumberOfModels(varargin{:});
209 end
210
211 function result = layers(self, varargin)
212 % LAYERS Kotlin-style alias for getLayers
213 result = self.getLayers(varargin{:});
214 end
215
216 function result = usedLangFeatures(self, varargin)
217 % USEDLANGFEATURES Kotlin-style alias for getUsedLangFeatures
218 result = self.getUsedLangFeatures(varargin{:});
219 end
220
221 function sanitize(self)
222 % SANITIZE()
223 % Validates the LayeredNetwork configuration.
224 % Ensures that if entries are defined, activities are also defined to serve those entries.
225
226 numEntries = length(self.entries);
227 numActivities = length(self.activities);
228
229 if numEntries > 0 && numActivities == 0
230 msg = sprintf('LayeredNetwork ''%s'' has %d entry(ies) but no activities. Entries must be bound to activities to form a valid LQN model. Use activity.boundTo(entry) to establish the binding.', self.name, numEntries);
231 line_error(mfilename, msg);
232 end
233 end
234
235 end
236
237 methods (Static)
238 function myLN = readXML(filename, verbose)
239 if nargin < 2
240 verbose = false;
241 end
242 myLN = LayeredNetwork.parseXML(filename, verbose);
243 end
244
245 function myLN = load(filename, verbose)
246 if nargin < 2
247 verbose = false;
248 end
249 myLN = LayeredNetwork.parseXML(filename, verbose);
250 end
251
252 myLN = parseXML(filename, verbose)
253
254 function myLN = fromNetwork(model)
255 myLN = QN2LQN(model);
256 end
257 end
258end