1classdef Source < Station
2 % Source External job arrival node
for open queueing networks
4 % Source represents an external arrival node that generates jobs
for open
5 %
classes according to specified arrival processes. It serves as the entry
6 % point
for jobs entering the network from the external environment, with
7 % configurable arrival rates and distributions
for each job
class.
9 % @brief External arrival node generating jobs
for open queueing networks
11 % Key characteristics:
12 % - External job generation
for open
classes
13 % - Class-dependent arrival processes
14 % - Infinite capacity job source
15 % - Configurable inter-arrival time distributions
16 % - Integration with network routing
18 % Source node features:
19 % - Multiple job
class support
20 % - Flexible arrival process specification
21 % - Poisson, MAP, and general arrival processes
22 % - Arrival rate configuration per
class
23 % - Disabled arrival capability
for specific
classes
26 % - Web server client arrivals
27 % - Manufacturing job arrivals
28 % - Call center customer generation
29 % - Network packet injection
30 % - Open system workload modeling
34 % model = Network(
'WebServer');
35 % source = Source(model,
'ClientArrivals');
36 % webClass = OpenClass(model,
'WebRequests', 1);
37 % source.setArrival(webClass, Exp(2.0)); % Poisson arrivals, rate 2
40 % Copyright (c) 2012-2026, Imperial College London
41 % All rights reserved.
50 function self = Source(model, name)
51 % SOURCE Create an external arrival source node
53 % @brief Creates a Source node
for external job generation
54 % @param model Network model to add the source node to
55 % @param name String identifier
for the source node
56 % @
return self Source instance ready
for arrival process configuration
58 if model.isMatlabNative()
59 self.numberOfServers = 1;
62 self.classCap = Inf*ones(1,length(
classes));
63 self.output = Dispatcher(
classes);
64 self.server = ServiceTunnel();
65 self.input = RandomSource(
classes);
66 self.schedStrategy = SchedStrategy.EXT;
70 elseif model.isJavaNative()
72 self.obj=jline.lang.nodes.Source(model.obj, name);
76 function setArrival(self,
class, distribution)
77 % SETARRIVAL(CLASS, DISTRIBUTION)
78 % distribution can be a Distribution
object or a Workflow
object
80 % If Workflow, convert to PH distribution
81 if isa(distribution,
'Workflow')
82 distribution = distribution.toPH();
86 % Check if arrival was already configured
87 if length(self.input.sourceClasses) >= class.index && ~isempty(self.input.sourceClasses{1,
class.index})
88 % Note: We no longer invalidate hasStruct here as it causes severe performance
89 % issues in iterative solvers like LN. The refreshRates/refreshProcesses methods
90 % called during solver post-iteration phase handle updating procid appropriately.
91 self.model.setInitialized(false);
93 self.input.sourceClasses{1,
class.index}{2} = ServiceStrategy.LI;
94 self.input.sourceClasses{1,
class.index}{3} = distribution;
95 self.arrivalProcess{1,
class.index} = distribution;
96 if distribution.isDisabled()
97 self.classCap(
class.index) = 0;
99 self.classCap(
class.index) = Inf;
101 % Update cached procid
if struct exists to avoid stale values
102 % This
is needed because we don
't invalidate hasStruct for performance
103 if self.model.hasStruct && ~isempty(self.model.sn)
104 ist = self.model.getStationIndex(self);
106 procTypeId = ProcessType.toId(ProcessType.fromText(builtin('class', distribution)));
107 self.model.sn.procid(ist, c) = procTypeId;
110 self.obj.setArrival(class.obj, distribution.obj);
111 % Also update MATLAB-side storage to keep in sync with Java object
112 % This ensures getArrivalProcess returns the correct distribution
113 % Check if arrival was already configured
114 if length(self.input.sourceClasses) >= class.index && ~isempty(self.input.sourceClasses{1, class.index})
115 % Note: We no longer invalidate hasStruct here as it causes severe performance
116 % issues in iterative solvers like LN. The refreshRates/refreshProcesses methods
117 % called during solver post-iteration phase handle updating procid appropriately.
118 self.model.setInitialized(false);
120 self.input.sourceClasses{1, class.index}{2} = ServiceStrategy.LI;
121 self.input.sourceClasses{1, class.index}{3} = distribution;
122 self.arrivalProcess{1,class.index} = distribution;
123 if distribution.isDisabled()
124 self.classCap(class.index) = 0;
126 self.classCap(class.index) = Inf;
128 % Update cached procid if struct exists to avoid stale values
129 if self.model.hasStruct && ~isempty(self.model.sn)
130 ist = self.model.getStationIndex(self);
132 procTypeId = ProcessType.toId(ProcessType.fromText(builtin('class', distribution)));
133 self.model.sn.procid(ist, c) = procTypeId;
138 function distrib = getArrivalProcess(self, oclass)
139 distrib = self.arrivalProcess{oclass};