LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
sampleAggr.m
1function sampleResult = sampleAggr(self, node, numSamples)
2% SAMPLERESULT = SAMPLEAGGR(NODE, NUMSAMPLES) Returns aggregated sample path at a node
3%
4% @brief Generates a discrete-event sample path with state aggregated over phases
5%
6% This method runs a DES transient simulation and records the sequence
7% of states visited at a specified station, with states aggregated to
8% show only the number of jobs per class (not per-phase details).
9%
10% @param self SolverDES instance
11% @param node Queue or node object to sample
12% @param numSamples Number of time points to sample
13%
14% @return sampleResult Structure containing the aggregated sample path with fields:
15% - sampleResult.handle: Reference to the sampled node
16% - sampleResult.t: Vector of time points
17% - sampleResult.state: Matrix of aggregated states (jobs per class)
18% - sampleResult.event: Cell array of events
19% - sampleResult.isaggregate: Boolean true (aggregated sample)
20%
21% @see sample - Returns detailed sample path with phase information
22% @see sampleSysAggr - Returns aggregated system-wide sample path
23%
24% Example:
25% @code
26% model = Network('MM1');
27% % ... model setup ...
28% solver = SolverDES(model, 'seed', 42);
29% queue = model.nodes{1};
30% result = solver.sampleAggr(queue, 1000);
31% @endcode
32
33if nargin < 2
34 line_error(mfilename, 'sampleAggr requires to specify a station.');
35end
36
37if nargin < 3
38 numSamples = self.options.samples;
39end
40
41% Convert model to Java
42jmodel = LINE2JLINE(self.model);
43
44% Create Java DES options
45joptions = jline.solvers.des.DESOptions();
46joptions.samples = self.options.samples;
47joptions.seed = self.options.seed;
48
49% Create Java solver
50jsolver = jline.solvers.des.SolverDES(jmodel, joptions);
51
52% Get stateful node from model
53sn = self.model.getStruct;
54if isa(node, 'Node')
55 nodeIdx = node.index;
56else
57 nodeIdx = node;
58end
59
60% Find the corresponding Java node
61statefulNodes = jmodel.getStatefulNodes();
62isf = sn.nodeToStateful(nodeIdx);
63jnode = statefulNodes.get(isf - 1); % Java is 0-indexed
64
65% Call Java sampleAggr method
66jresult = jsolver.sampleAggr(jnode, numSamples);
67
68% Convert Java result to MATLAB structure
69sampleResult = struct();
70sampleResult.handle = node;
71
72% Convert time matrix
73if ~isempty(jresult.t)
74 sampleResult.t = JLINE.from_jline_matrix(jresult.t);
75else
76 sampleResult.t = [];
77end
78
79% Convert state matrix
80if ~isempty(jresult.state) && isa(jresult.state, 'jline.util.matrix.Matrix')
81 sampleResult.state = JLINE.from_jline_matrix(jresult.state);
82else
83 sampleResult.state = [];
84end
85
86% Convert event matrix
87if ~isempty(jresult.event) && isa(jresult.event, 'jline.util.matrix.Matrix')
88 sampleResult.event = JLINE.from_jline_matrix(jresult.event);
89else
90 sampleResult.event = {};
91end
92
93sampleResult.isaggregate = jresult.isAggregate;
94sampleResult.nodeIndex = nodeIdx;
95sampleResult.numSamples = jresult.numSamples;
96
97end