LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
getProb.m
1function Prob = getProb(self, node, state)
2% PROBSTATE = GETPROBSTATE(NODE, STATE) Returns state probabilities estimated via simulation
3%
4% @brief Estimates steady-state marginal state probabilities at a node via SSA simulation
5%
6% This method estimates state probabilities by running a stochastic simulation and
7% collecting statistics on how often each state is visited. The SSA solver performs
8% CTMC stochastic sampling, recording state transitions and dwell times.
9%
10% Probabilities are estimated as the fraction of total time spent in each state
11% during the simulation. This is an empirical estimate and converges to steady-state
12% as the number of samples increases.
13%
14% @param self SolverSSA instance
15% @param node Queue or node object (or node index as integer)
16% @param state (optional) State specification as vector. If provided, returns
17% probability of this specific state. If omitted, returns probabilities
18% for all reachable states at the node with phase information.
19%
20% @return Prob Estimated state probability value
21% - If state parameter specified: scalar probability of that state
22% - If state not specified: probability mass across all states (sum=1)
23% - 0 if state not seen during simulation (rare event)
24% - Includes phase information from service distributions
25%
26% @note SSA estimates probabilities from finite simulation. Accuracy improves with
27% more samples. If the specified state is not observed during simulation,
28% a warning is issued and probability 0 is returned.
29% For phase-detailed states (CTMC-style), use getProb().
30%
31% @warning Simulation-based estimate - results vary between runs unless seed is set.
32% Use 'seed' option in constructor for reproducible results.
33% For small models, CTMC provides exact probabilities.
34%
35% @see getProbAggr - Returns state probabilities aggregated over phases
36% @see getProbSys - Returns joint system state probabilities
37% @see getAvg - Get average metrics (alternative analysis method)
38%
39% Example:
40% @code
41% solver = SolverSSA(model, 'samples', 50000, 'seed', 42);
42% queue1 = model.nodes{1};
43%
44% % Estimate probability of state [2 jobs of class 0, 1 of class 1]
45% queue1.setState([2, 1]);
46% prob_state = solver.getProb(queue1);
47% fprintf('Estimated Pr[state=[2,1]] = %.4f\\n', prob_state);
48%
49% % Get all state probabilities
50% all_probs = solver.getProb(queue1);
51% @endcode
52
53if GlobalConstants.DummyMode
54 Prob = NaN;
55 return
56end
57
58switch self.options.method
59 case {'default','nrm'}
60 self.options.method = 'serial';
61end
62% we do not use probSysState as that is for joint states
63[~, tranSysState] = self.runAnalyzer;
64sn = self.getStruct;
65isf = sn.nodeToStateful(node.index);
66TSS = cell2mat({tranSysState{1},tranSysState{1+isf}});
67TSS(:,1)=[TSS(1,1);diff(TSS(:,1))];
68if nargin<3 %~exist('state','var')
69 if size(sn.state{isf},1)>1
70 error('There are multiple station states, choose an initial state as a parameter to getProb.');
71 end
72 state = sn.state{isf};
73end
74% add padding of zeros for FCFS stations
75state = [zeros(1,size(TSS(:,2:end),2)-size(state,2)),state];
76rows = findrows(TSS(:,2:end), state);
77if ~isempty(rows)
78 Prob = sum(TSS(rows,1))/sum(TSS(:,1));
79else
80 line_warning(mfilename,'The state was not seen during the simulation.\n');
81 Prob = 0;
82end
83end