LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Source.m
1classdef Source < Station
2 % Source External job arrival node for open queueing networks
3 %
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.
8 %
9 % @brief External arrival node generating jobs for open queueing networks
10 %
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
17 %
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
24 %
25 % Source is used for:
26 % - Web server client arrivals
27 % - Manufacturing job arrivals
28 % - Call center customer generation
29 % - Network packet injection
30 % - Open system workload modeling
31 %
32 % Example:
33 % @code
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
38 % @endcode
39 %
40 % Copyright (c) 2012-2026, Imperial College London
41 % All rights reserved.
42
43 properties
44 schedStrategy;
45 arrivalProcess;
46 end
47
48 methods
49 %Constructor
50 function self = Source(model, name)
51 % SOURCE Create an external arrival source node
52 %
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
57 self@Station(name);
58 if model.isMatlabNative()
59 self.numberOfServers = 1;
60 if(model ~= 0)
61 classes = model.getClasses();
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;
67 self.setModel(model);
68 model.addNode(self);
69 end
70 elseif model.isJavaNative()
71 self.setModel(model);
72 self.obj=jline.lang.nodes.Source(model.obj, name);
73 end
74 end
75
76 function setArrival(self, class, distribution)
77 % SETARRIVAL(CLASS, DISTRIBUTION)
78 % distribution can be a Distribution object or a Workflow object
79
80 % If Workflow, convert to PH distribution
81 if isa(distribution, 'Workflow')
82 distribution = distribution.toPH();
83 end
84
85 if isempty(self.obj)
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);
92 end
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;
98 else
99 self.classCap(class.index) = Inf;
100 end
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);
105 c = class.index;
106 procTypeId = ProcessType.toId(ProcessType.fromText(builtin('class', distribution)));
107 self.model.sn.procid(ist, c) = procTypeId;
108 end
109 else
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);
119 end
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;
125 else
126 self.classCap(class.index) = Inf;
127 end
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);
131 c = class.index;
132 procTypeId = ProcessType.toId(ProcessType.fromText(builtin('class', distribution)));
133 self.model.sn.procid(ist, c) = procTypeId;
134 end
135 end
136 end
137
138 function distrib = getArrivalProcess(self, oclass)
139 distrib = self.arrivalProcess{oclass};
140 end
141
142 end
143
144end