1% Example demonstrating the node breakdown/repair API
for random environments
3% This example shows how to easily model a server that can
break down and be
4% repaired
using the
new Env convenience methods.
6% Copyright (c) 2012-2026, Imperial College London
9%% Create base queueing network model
10model = Network(
'ServerWithFailures');
13source = Source(model,
'Arrivals');
14queue = Queue(model,
'Server', SchedStrategy.FCFS);
15sink = Sink(model,
'Departures');
20% Set service and arrival rates (UP state)
21source.setArrival(
jobclass, Exp(0.8)); % Arrival rate
22queue.setService(
jobclass, Exp(2.0)); % Service rate when UP
23queue.setNumberOfServers(1);
26P = model.initRoutingMatrix();
28 0, 0, 1; % Queue -> Sink
29 0, 0, 0]; % Sink -> (absorbing)
32%% Create environment with breakdown/repair
using new API
34% Method 1: Using addNodeFailureRepair (recommended)
35fprintf(
'Example 1: Using addNodeFailureRepair convenience method\n');
36env1 = Env(
'ServerEnv1');
38% Add failure and repair
for the server node in one call
39% Parameters: baseModel, nodeName, breakdownDist, repairDist, downServiceDist
40env1.addNodeFailureRepair(model,
'Server', Exp(0.1), Exp(1.0), Exp(0.5));
42% Initialize and print stage table
44fprintf(
'\nStage table for env1:\n');
47%% Method 2: Using separate breakdown and repair calls
48fprintf(
'\nExample 2: Using separate breakdown and repair calls\n');
49env2 = Env(
'ServerEnv2');
51% Add breakdown (creates UP and DOWN stages)
52env2.addNodeBreakdown(model,
'Server', Exp(0.1), Exp(0.5));
54% Add repair transition
55env2.addNodeRepair(
'Server', Exp(1.0));
57% Initialize and print stage table
59fprintf(
'\nStage table for env2:\n');
62%% Method 3: With custom reset policies
63fprintf(
'\nExample 3: With custom reset policies\n');
64env3 = Env(
'ServerEnv3');
66% Reset policy: clear all queues on breakdown
67resetBreakdown = @(q) 0*q; % Clear queues when server breaks down
69% Reset policy: keep all jobs on repair
70resetRepair = @(q) q; % Keep jobs when server
is repaired
72env3.addNodeFailureRepair(model,
'Server', Exp(0.1), Exp(1.0), Exp(0.5), ...
73 resetBreakdown, resetRepair);
76fprintf(
'\nStage table for env3:\n');
79%% Method 4: Modifying reset policies after creation
80fprintf(
'\nExample 4: Modifying reset policies after creation\n');
81env4 = Env(
'ServerEnv4');
83% Create environment with
default reset policies
84env4.addNodeFailureRepair(model,
'Server', Exp(0.1), Exp(1.0), Exp(0.5));
86% Update breakdown reset policy to clear queues
87env4.setBreakdownResetPolicy(
'Server', @(q) 0*q);
89% Update repair reset policy (keep jobs)
90env4.setRepairResetPolicy(
'Server', @(q) q);
93fprintf(
'\nStage table for env4:\n');
96%% Solve the environment model
97fprintf(
'\nSolving environment model with ENV solver...\n');
99% Create solver options
100options = Solver.defaultOptions;
101options.timespan = [0, Inf];
102options.iter_max = 100;
103options.iter_tol = 0.01;
104options.method =
'default';
105options.verbose =
true;
107% Create fluid solver
for each stage
108sfoptions = FLD.defaultOptions;
109sfoptions.timespan = [0, 1e3];
110sfoptions.verbose =
false;
112% Solve
using ENV (Ensemble eNVironment) solver
113envSolver = ENV(env1, @(model) FLD(model, sfoptions), options);
115% Get and display results
116fprintf(
'\nAverage Performance Metrics:\n');
117[QN, UN, TN] = envSolver.getAvg();
118AvgTable = envSolver.getAvgTable()
120fprintf(
'\nInterpretation:\n');
121fprintf(
'- The system alternates between UP (operational) and DOWN (failed) states\n');
122fprintf(
'- UP state: Server processes jobs at rate 2.0\n');
123fprintf(
'- DOWN state: Server processes jobs at reduced rate 0.5\n');
124fprintf(
'- Breakdown occurs at rate 0.1 (mean time to failure = 10 time units)\n');
125fprintf(
'- Repair occurs at rate 1.0 (mean time to repair = 1 time unit)\n');
126fprintf(
'- Results show averaged performance across both states\n');
128%% Compute Reliability Metrics
129fprintf(
'\nReliability Metrics:\n');
130ReliabilityTable = env1.getReliabilityTable()
132fprintf(
'\nReliability Interpretation:\n');
133fprintf(
'- MTTF (Mean Time To Failure): %.2f time units\n', ReliabilityTable.Value(1));
134fprintf(
' Expected time in UP state before breakdown occurs\n');
135fprintf(
'- MTTR (Mean Time To Repair): %.2f time units\n', ReliabilityTable.Value(2));
136fprintf(
' Expected time in DOWN state before repair completes\n');
137fprintf(
'- MTBF (Mean Time Between Failures): %.2f time units\n', ReliabilityTable.Value(3));
138fprintf(
' Average cycle time (MTTF + MTTR)\n');
139fprintf(
'- Availability: %.4f (%.2f%%)\n', ReliabilityTable.Value(4), ReliabilityTable.Value(4)*100);
140fprintf(
' Fraction of time the system is operational\n');