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) - passing node
object
35fprintf(
'Example 1: Using addNodeFailureRepair with node object\n');
36env1 = Environment(
'ServerEnv1');
38% Add failure and repair
for the server node in one call
39% Parameters: baseModel, nodeOrName, breakdownDist, repairDist, downServiceDist
40% Note: Can pass either node object (queue) or node name (
'Server')
41env1.addNodeFailureRepair(model, queue, Exp(0.1), Exp(1.0), Exp(0.5));
43% Initialize and print stage table
45fprintf('\nStage table for env1:\n');
48%% Method 2: Using separate breakdown and repair calls
49fprintf('\nExample 2: Using separate breakdown and repair calls with node
object\n');
50env2 = Environment('ServerEnv2');
52% Add breakdown (creates UP and DOWN stages) - using node
object
53env2.addNodeBreakdown(model, queue, Exp(0.1), Exp(0.5));
55% Add repair transition - using node
object
56env2.addNodeRepair(queue, Exp(1.0));
58% Initialize and print stage table
60fprintf('\nStage table for env2:\n');
63%% Method 3: With custom reset policies
64fprintf('\nExample 3: With custom reset policies using node
object\n');
65env3 = Environment('ServerEnv3');
67% Reset policy: clear all queues on breakdown
68resetBreakdown = @(q) 0*q; % Clear queues when server breaks down
70% Reset policy: keep all jobs on repair
71resetRepair = @(q) q; % Keep jobs when server
is repaired
73% Using node
object instead of
string name
74env3.addNodeFailureRepair(model, queue, Exp(0.1), Exp(1.0), Exp(0.5), ...
75 resetBreakdown, resetRepair);
78fprintf('\nStage table for env3:\n');
81%% Method 4: Modifying reset policies after creation
82fprintf('\nExample 4: Modifying reset policies after creation using node
object\n');
83env4 = Environment('ServerEnv4');
85% Create environment with default reset policies - using node
object
86env4.addNodeFailureRepair(model, queue, Exp(0.1), Exp(1.0), Exp(0.5));
88% Update breakdown reset policy to clear queues - using node
object
89env4.setBreakdownResetPolicy(queue, @(q) 0*q);
91% Update repair reset policy (keep jobs) - using node
object
92env4.setRepairResetPolicy(queue, @(q) q);
95fprintf('\nStage table for env4:\n');
98%% Solve the environment model
99fprintf('\nSolving environment model with ENV solver...\n');
101% Create solver options
102options = Solver.defaultOptions;
103options.timespan = [0, Inf];
104options.iter_max = 100;
105options.iter_tol = 0.01;
106options.method = 'default';
107options.verbose = true;
109% Create fluid solver for each stage
110sfoptions = FLD.defaultOptions;
111sfoptions.timespan = [0, 1e3];
112sfoptions.verbose = false;
114% Solve using ENV (Ensemble eNVironment) solver
115envSolver = ENV(env1, @(model) FLD(model, sfoptions), options);
117% Get and display results
118fprintf('\nAverage Performance Metrics:\n');
119[QN, UN, TN] = envSolver.getAvg();
120AvgTable = envSolver.getAvgTable()
122fprintf('\nInterpretation:\n');
123fprintf('- The system alternates between UP (operational) and DOWN (failed) states\n');
124fprintf('- UP state: Server processes jobs at rate 2.0\n');
125fprintf('- DOWN state: Server processes jobs at reduced rate 0.5\n');
126fprintf('- Breakdown occurs at rate 0.1 (mean time to failure = 10 time units)\n');
127fprintf('- Repair occurs at rate 1.0 (mean time to repair = 1 time unit)\n');
128fprintf('- Results show averaged performance across both states\n');
130%% Compute Reliability Metrics
131fprintf('\nReliability Metrics:\n');
132ReliabilityTable = env1.getReliabilityTable()
134fprintf('\nReliability Interpretation:\n');
135fprintf('- MTTF (Mean Time To Failure): %.2f time units\n', ReliabilityTable.Value(1));
136fprintf(' Expected time in UP state before breakdown occurs\n');
137fprintf('- MTTR (Mean Time To Repair): %.2f time units\n', ReliabilityTable.Value(2));
138fprintf(' Expected time in DOWN state before repair completes\n');
139fprintf('- MTBF (Mean Time Between Failures): %.2f time units\n', ReliabilityTable.Value(3));
140fprintf(' Average cycle time (MTTF + MTTR)\n');
141fprintf('- Availability: %.4f (%.2f%%)\n', ReliabilityTable.Value(4), ReliabilityTable.Value(4)*100);
142fprintf(' Fraction of time the system
is operational\n');