LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
example_mapqn2renv.m
1% Example: Transform MMPP service queue to random environment model
2%
3% This example shows how to transform a closed queueing network with MMPP2
4% service into a random environment model with exponential services
5% modulated by the MMPP phases.
6%
7% MMPP2 (2-phase Markov Modulated Poisson Process) is a point process
8% where service completions occur at rates modulated by a 2-state Markov chain.
9% This transformation converts such a network into an equivalent random
10% environment model where:
11% - Environment has 2 stages (one per MMPP phase)
12% - Service rates are exponential with rates from MMPP D1 diagonal
13% - Environment transitions follow MMPP D0 matrix structure
14
15clear; close all;
16
17% Create closed queueing network with MMPP2 service
18model = Network('MMPP_ClosedQN');
19
20% Create nodes
21delay = Delay(model, 'Delay'); % Think time station
22queue = Queue(model, 'Queue', SchedStrategy.FCFS); % Service station with MMPP2
23
24% Create closed job class with N=5 jobs
25N = 5; % Number of jobs in the system
26jobclass = ClosedClass(model, 'Class1', N, delay);
27
28% Set think time (exponential with mean 1.0)
29delay.setService(jobclass, Exp(1.0));
30
31% Set MMPP2 service distribution
32% Parameters: lambda0, lambda1, sigma01, sigma10
33% lambda0, lambda1 = service rates in phases 0, 1
34% sigma01, sigma10 = phase transition rates
35%
36% Using very different service rates to show distinct phase behavior:
37% Phase 0: slow service (rate 1.0) -> high queue length
38% Phase 1: fast service (rate 10.0) -> low queue length
39%
40% This creates an MMPP2 with:
41% D0 = [-0.2-1.0, 0.2 ] = [-1.2, 0.2]
42% [ 0.3, -0.3-10.0] [ 0.3, -10.3]
43%
44% D1 = [1.0, 0 ]
45% [ 0, 10.0]
46queue.setService(jobclass, MMPP2(1.0, 10.0, 0.2, 0.3));
47
48% Create cyclic routing: Delay -> Queue -> Delay
49model.link(Network.serialRouting(delay, queue));
50
51fprintf('=== MMPP2 Closed QN to Random Environment Transformation ===\n\n');
52
53fprintf('Original Network:\n');
54fprintf(' Topology: Delay -> MMPP2 Queue -> Delay (cyclic)\n');
55fprintf(' Population: N = %d jobs\n', N);
56fprintf(' Think time: Exp(1.0)\n');
57fprintf(' Service: MMPP2 with phases 0,1\n\n');
58
59% Transform to random environment model
60fprintf('Transforming to random environment model...\n');
61envModel = MAPQN2RENV(model);
62
63fprintf('Transformation complete!\n\n');
64
65fprintf('Environment Model Structure:\n');
66fprintf(' Environment: MAPQN_Env with 2 stages\n');
67fprintf(' Stage 0 (Phase 0): Closed QN with Exp service rate 1.0 (SLOW)\n');
68fprintf(' Stage 1 (Phase 1): Closed QN with Exp service rate 10.0 (FAST)\n');
69fprintf(' Transitions:\n');
70fprintf(' Phase 0 -> Phase 1: Rate 0.2\n');
71fprintf(' Phase 1 -> Phase 0: Rate 0.3\n\n');
72
73% Display environment model structure
74fprintf('Environment stages:\n');
75stageNames = envModel.envGraph.Nodes.Name;
76stageTypes = envModel.envGraph.Nodes.Type;
77for i = 1:length(stageNames)
78 fprintf(' %s: %s\n', stageNames{i}, stageTypes{i});
79end
80fprintf('\n');
81
82% Display the stage network structure
83fprintf('Stage network details:\n');
84stageModels = envModel.envGraph.Nodes.Model;
85for i = 1:length(stageModels)
86 stageModel = stageModels{i};
87 if ~isempty(stageModel)
88 fprintf(' %s: Network with %d nodes\n', stageNames{i}, length(stageModel.nodes));
89 end
90end
91fprintf('\n');
92
93% Solve the original MMPP2 model using JMT
94try
95 fprintf('Solving original MMPP2 model using JMT...\n');
96 solver = JMT(model);
97 avgTable = solver.getAvgTable();
98 fprintf('Original MMPP2 Queue results:\n');
99 disp(avgTable);
100catch ME
101 fprintf('JMT solver error: %s\n', ME.message);
102end
103
104% Solve the environment model using BLN with FLD
105fprintf('\nSolving environment model using BLN (with FLD)...\n');
106try
107 % Setup solver options (similar to renv_twostages_repairmen.m)
108 options = Solver.defaultOptions;
109 options.timespan = [0, Inf];
110 options.iter_max = 100;
111 options.iter_tol = 0.01;
112 options.method = 'default';
113 options.verbose = false;
114
115 sfoptions = FLD.defaultOptions;
116 sfoptions.timespan = [0, 100];
117 sfoptions.verbose = false;
118
119 envSolver = BLN(envModel, @(m) FLD(m, sfoptions), options);
120 [QN, UN, TN] = envSolver.getAvg();
121 AvgTable = envSolver.getAvgTable();
122
123 fprintf('\nEnvironment Model AvgTable:\n');
124 disp(AvgTable);
125
126 fprintf('Note: The random environment model captures MMPP dynamics through\n');
127 fprintf('switching between phases with exponential service rates.\n\n');
128catch ME
129 fprintf('BLN error: %s\n\n', ME.message);
130 fprintf('Note: BLN requires transient analysis support.\n');
131 fprintf('The environment model was created successfully.\n\n');
132end
133
134% Solve the environment model using BLN with CTMC
135fprintf('\nSolving environment model using BLN (with CTMC, cutoff=100)...\n');
136try
137 % Setup solver options
138 options = Solver.defaultOptions;
139 options.timespan = [0, Inf];
140 options.iter_max = 100;
141 options.iter_tol = 0.01;
142 options.method = 'default';
143 options.verbose = false;
144
145 ctmcoptions = CTMC.defaultOptions;
146 ctmcoptions.timespan = [0, 100];
147 ctmcoptions.cutoff = 100;
148 ctmcoptions.verbose = false;
149
150 envSolverCTMC = BLN(envModel, @(m) CTMC(m, ctmcoptions), options);
151 [QN_ctmc, UN_ctmc, TN_ctmc] = envSolverCTMC.getAvg();
152 AvgTableCTMC = envSolverCTMC.getAvgTable();
153
154 fprintf('\nEnvironment Model AvgTable (CTMC):\n');
155 disp(AvgTableCTMC);
156catch ME
157 fprintf('BLN/CTMC error: %s\n\n', ME.message);
158end
159
160% Solve individual stage networks using MVA (steady-state)
161fprintf('Solving stage networks individually (steady-state with MVA)...\n');
162try
163 stageModels = envModel.envGraph.Nodes.Model;
164 for i = 1:length(stageModels)
165 stageModel = stageModels{i};
166 stageName = envModel.envGraph.Nodes.Name{i};
167 if ~isempty(stageModel)
168 fprintf('\n Stage %s:\n', stageName);
169 stageSolver = MVA(stageModel);
170 stageAvgTable = stageSolver.getAvgTable();
171 disp(stageAvgTable);
172 end
173 end
174catch ME2
175 fprintf('Stage solver error: %s\n', ME2.message);
176end
177
178fprintf('\n=== Transformation Complete ===\n');
Definition mmt.m:92