LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
getProb.m
1function Prob = getProb(self, node, state)
2% PROB = GETPROB(NODE, STATE) Returns state probability estimated via DES simulation
3%
4% @brief Estimates steady-state marginal state probabilities at a node via DES simulation
5%
6% This method estimates state probabilities by running a discrete-event simulation
7% and computing the fraction of total simulation time spent in each state.
8%
9% @param self SolverDES instance
10% @param node Queue or node object (or node index as integer)
11% @param state (optional) State specification as vector. If provided, returns
12% probability of this specific state. If omitted, uses current network state.
13%
14% @return Prob Estimated state probability value
15% - 0 if state not seen during simulation (rare event)
16%
17% @note DES estimates probabilities from finite simulation. Accuracy improves with
18% more samples. If the specified state is not observed during simulation,
19% probability 0 is returned.
20%
21% @warning Simulation-based estimate - results vary between runs unless seed is set.
22% Use 'seed' option in constructor for reproducible results.
23%
24% @see getProbAggr - Returns state probabilities aggregated over phases
25% @see getProbSys - Returns joint system state probabilities
26%
27% Example:
28% @code
29% solver = SolverDES(model, 'samples', 50000, 'seed', 42);
30% queue1 = model.nodes{1};
31%
32% % Estimate probability of state [2 jobs of class 0, 1 of class 1]
33% prob_state = solver.getProb(queue1, [2, 1]);
34% fprintf('Estimated Pr[state=[2,1]] = %.4f\n', prob_state);
35% @endcode
36
37if GlobalConstants.DummyMode
38 Prob = NaN;
39 return
40end
41
42% Convert model to Java
43jmodel = LINE2JLINE(self.model);
44
45% Create Java DES options
46joptions = jline.solvers.des.DESOptions();
47joptions.samples = self.options.samples;
48joptions.seed = self.options.seed;
49
50% Create Java solver
51jsolver = jline.solvers.des.SolverDES(jmodel, joptions);
52
53% Get stateful node from model
54sn = self.model.getStruct;
55if isa(node, 'Node')
56 nodeIdx = node.index;
57else
58 nodeIdx = node;
59end
60
61% Find the corresponding Java node
62statefulNodes = jmodel.getStatefulNodes();
63isf = sn.nodeToStateful(nodeIdx);
64jnode = statefulNodes.get(isf - 1); % Java is 0-indexed
65
66% Convert state to Java Matrix if provided
67if nargin < 3 || isempty(state)
68 jstate = [];
69else
70 jstate = JLINE.to_jline_matrix(state(:)');
71end
72
73% Call Java getProb method and extract probability value
74if isempty(jstate)
75 jresult = jsolver.getProb(jnode);
76else
77 jresult = jsolver.getProb(jnode, jstate);
78end
79
80% Extract the probability value from the ProbabilityResult object
81Prob = jresult.probability;
82
83end