LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
renv_node_breakdown.m
1% Example demonstrating the node breakdown/repair API for random environments
2%
3% This example shows how to easily model a server that can break down and be
4% repaired using the new Env convenience methods.
5%
6% Copyright (c) 2012-2026, Imperial College London
7% All rights reserved.
8
9%% Create base queueing network model
10model = Network('ServerWithFailures');
11
12% Define nodes
13source = Source(model, 'Arrivals');
14queue = Queue(model, 'Server', SchedStrategy.FCFS);
15sink = Sink(model, 'Departures');
16
17% Define job class
18jobclass = OpenClass(model, 'Jobs');
19
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);
24
25% Set routing
26P = model.initRoutingMatrix();
27P{jobclass,jobclass} = [0, 1, 0; % Source -> Queue
28 0, 0, 1; % Queue -> Sink
29 0, 0, 0]; % Sink -> (absorbing)
30model.link(P);
31
32%% Create environment with breakdown/repair using new API
33
34% Method 1: Using addNodeFailureRepair (recommended) - passing node object
35fprintf('Example 1: Using addNodeFailureRepair with node object\n');
36env1 = Environment('ServerEnv1');
37
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));
42
43% Initialize and print stage table
44env1.init();
45fprintf('\nStage table for env1:\n');
46env1.getStageTable()
47
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');
51
52% Add breakdown (creates UP and DOWN stages) - using node object
53env2.addNodeBreakdown(model, queue, Exp(0.1), Exp(0.5));
54
55% Add repair transition - using node object
56env2.addNodeRepair(queue, Exp(1.0));
57
58% Initialize and print stage table
59env2.init();
60fprintf('\nStage table for env2:\n');
61env2.getStageTable()
62
63%% Method 3: With custom reset policies
64fprintf('\nExample 3: With custom reset policies using node object\n');
65env3 = Environment('ServerEnv3');
66
67% Reset policy: clear all queues on breakdown
68resetBreakdown = @(q) 0*q; % Clear queues when server breaks down
69
70% Reset policy: keep all jobs on repair
71resetRepair = @(q) q; % Keep jobs when server is repaired
72
73% Using node object instead of string name
74env3.addNodeFailureRepair(model, queue, Exp(0.1), Exp(1.0), Exp(0.5), ...
75 resetBreakdown, resetRepair);
76
77env3.init();
78fprintf('\nStage table for env3:\n');
79env3.getStageTable()
80
81%% Method 4: Modifying reset policies after creation
82fprintf('\nExample 4: Modifying reset policies after creation using node object\n');
83env4 = Environment('ServerEnv4');
84
85% Create environment with default reset policies - using node object
86env4.addNodeFailureRepair(model, queue, Exp(0.1), Exp(1.0), Exp(0.5));
87
88% Update breakdown reset policy to clear queues - using node object
89env4.setBreakdownResetPolicy(queue, @(q) 0*q);
90
91% Update repair reset policy (keep jobs) - using node object
92env4.setRepairResetPolicy(queue, @(q) q);
93
94env4.init();
95fprintf('\nStage table for env4:\n');
96env4.getStageTable()
97
98%% Solve the environment model
99fprintf('\nSolving environment model with ENV solver...\n');
100
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;
108
109% Create fluid solver for each stage
110sfoptions = FLD.defaultOptions;
111sfoptions.timespan = [0, 1e3];
112sfoptions.verbose = false;
113
114% Solve using ENV (Ensemble eNVironment) solver
115envSolver = ENV(env1, @(model) FLD(model, sfoptions), options);
116
117% Get and display results
118fprintf('\nAverage Performance Metrics:\n');
119[QN, UN, TN] = envSolver.getAvg();
120AvgTable = envSolver.getAvgTable()
121
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');
129
130%% Compute Reliability Metrics
131fprintf('\nReliability Metrics:\n');
132ReliabilityTable = env1.getReliabilityTable()
133
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');
Definition mmt.m:92