1% Example: Transform MMPP service queue to random environment model
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.
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
17% Create closed queueing network with MMPP2 service
18model = Network(
'MMPP_ClosedQN');
21delay = Delay(model,
'Delay'); % Think time station
22queue = Queue(model,
'Queue', SchedStrategy.FCFS); % Service station with MMPP2
24% Create closed job
class with N=5 jobs
25N = 5; % Number of jobs in the system
26jobclass = ClosedClass(model,
'Class1', N, delay);
28% Set think time (exponential with mean 1.0)
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
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
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]
46queue.setService(
jobclass, MMPP2(1.0, 10.0, 0.2, 0.3));
48% Create cyclic routing: Delay -> Queue -> Delay
49model.link(Network.serialRouting(delay, queue));
51fprintf(
'=== MMPP2 Closed QN to Random Environment Transformation ===\n\n');
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');
59% Transform to random environment model
60fprintf(
'Transforming to random environment model...\n');
61envModel = MAPQN2RENV(model);
63fprintf(
'Transformation complete!\n\n');
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');
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});
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));
93% Solve the original MMPP2 model
using JMT
95 fprintf(
'Solving original MMPP2 model using JMT...\n');
97 avgTable = solver.getAvgTable();
98 fprintf(
'Original MMPP2 Queue results:\n');
101 fprintf(
'JMT solver error: %s\n', ME.message);
104% Solve the environment model
using BLN with FLD
105fprintf(
'\nSolving environment model using BLN (with FLD)...\n');
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;
115 sfoptions = FLD.defaultOptions;
116 sfoptions.timespan = [0, 100];
117 sfoptions.verbose =
false;
119 envSolver = BLN(envModel, @(m) FLD(m, sfoptions), options);
120 [QN, UN, TN] = envSolver.getAvg();
121 AvgTable = envSolver.getAvgTable();
123 fprintf(
'\nEnvironment Model AvgTable:\n');
126 fprintf(
'Note: The random environment model captures MMPP dynamics through\n');
127 fprintf(
'switching between phases with exponential service rates.\n\n');
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');
134% Solve the environment model
using BLN with CTMC
135fprintf(
'\nSolving environment model using BLN (with CTMC, cutoff=100)...\n');
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;
145 ctmcoptions = CTMC.defaultOptions;
146 ctmcoptions.timespan = [0, 100];
147 ctmcoptions.cutoff = 100;
148 ctmcoptions.verbose =
false;
150 envSolverCTMC = BLN(envModel, @(m) CTMC(m, ctmcoptions), options);
151 [QN_ctmc, UN_ctmc, TN_ctmc] = envSolverCTMC.getAvg();
152 AvgTableCTMC = envSolverCTMC.getAvgTable();
154 fprintf(
'\nEnvironment Model AvgTable (CTMC):\n');
157 fprintf(
'BLN/CTMC error: %s\n\n', ME.message);
160% Solve individual stage networks
using MVA (steady-state)
161fprintf(
'Solving stage networks individually (steady-state with MVA)...\n');
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();
175 fprintf(
'Stage solver error: %s\n', ME2.message);
178fprintf(
'\n=== Transformation Complete ===\n');