LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
example_fes_single_class.m
1clear node jobclass
2
3% Single-class FES Aggregation Example
4%
5% This tests FES aggregation with a single job class, where it should be exact.
6
7fprintf('=== Single-Class FES Aggregation Example ===\n\n');
8
9%% Create original 4-station tandem network with 1 class
10fprintf('Creating original 4-station network...\n');
11
12N1 = 5; % number of jobs
13
14model = Network('OriginalModel');
15
16% Create stations
17node{1} = Delay(model, 'ThinkTime');
18node{2} = Queue(model, 'Queue1', SchedStrategy.PS);
19node{3} = Queue(model, 'Queue2', SchedStrategy.PS);
20node{4} = Queue(model, 'Queue3', SchedStrategy.PS);
21
22% Create job class
23jobclass{1} = ClosedClass(model, 'Class1', N1, node{1}, 0);
24
25% Set service times
26node{1}.setService(jobclass{1}, Exp.fitMean(5.0));
27node{2}.setService(jobclass{1}, Exp.fitMean(1.5));
28node{3}.setService(jobclass{1}, Exp.fitMean(1.0));
29node{4}.setService(jobclass{1}, Exp.fitMean(0.8));
30
31% Set up tandem routing
32P = model.initRoutingMatrix();
33P{1,1} = [0, 1, 0, 0;
34 0, 0, 1, 0;
35 0, 0, 0, 1;
36 1, 0, 0, 0];
37model.link(P);
38
39%% Solve original model with MVA
40fprintf('\n--- Solving Original Model ---\n');
41solverOriginal = SolverMVA(model);
42AvgTableOriginal = solverOriginal.getAvgTable;
43fprintf('Original model results:\n');
44disp(AvgTableOriginal);
45
46%% Aggregate stations 2 and 3 into a Flow-Equivalent Server
47fprintf('\n--- Creating FES Model ---\n');
48fprintf('Aggregating Queue1 and Queue2 into a single FES...\n');
49
50stationSubset = {node{2}, node{3}};
51options.verbose = true;
52options.solver = 'mva';
53
54try
55 [fesModel, fesStation, deaggInfo] = ModelAdapter.aggregateFES(model, stationSubset, options);
56
57 fprintf('\nFES model created successfully!\n');
58 fprintf('FES station name: %s\n', fesStation.getName());
59 fprintf('Number of stations in FES model: %d\n', fesModel.getNumberOfStations());
60
61 %% Solve FES model
62 fprintf('\n--- Solving FES Model ---\n');
63 solverFES = SolverMVA(fesModel);
64 AvgTableFES = solverFES.getAvgTable;
65 fprintf('FES model results:\n');
66 disp(AvgTableFES);
67
68 %% Compare throughputs
69 fprintf('\n--- Throughput Comparison ---\n');
70
71 % Find throughput at ThinkTime station
72 tputOrig = 0;
73 for row = 1:height(AvgTableOriginal)
74 if strcmp(string(AvgTableOriginal.Station(row)), 'ThinkTime')
75 tputOrig = AvgTableOriginal.Tput(row);
76 break;
77 end
78 end
79
80 tputFES = 0;
81 for row = 1:height(AvgTableFES)
82 if strcmp(string(AvgTableFES.Station(row)), 'ThinkTime')
83 tputFES = AvgTableFES.Tput(row);
84 break;
85 end
86 end
87
88 relError = abs(tputOrig - tputFES) / max(tputOrig, 1e-10) * 100;
89 fprintf('Throughput: Original=%.4f, FES=%.4f, RelError=%.2f%%\n', ...
90 tputOrig, tputFES, relError);
91
92 if relError < 1.0
93 fprintf('\nSUCCESS: FES aggregation is nearly exact (< 1%% error)\n');
94 else
95 fprintf('\nWARNING: FES aggregation has significant error\n');
96 end
97
98catch ME
99 fprintf('Error during FES aggregation: %s\n', ME.message);
100 fprintf('Stack trace:\n');
101 for i = 1:length(ME.stack)
102 fprintf(' %s (line %d)\n', ME.stack(i).name, ME.stack(i).line);
103 end
104end
105
106fprintf('\n=== Example Complete ===\n');