LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
oqn_multichain_cs.m
1clear node jobclass solver AvgTable;
2%% Example of an open queueing network with 3 chains, 5 classes, and class switching
3% Demonstrates job class switching within multiple open chains.
4% Chain 1: Interactive requests (2 classes that switch)
5% Chain 2: Batch jobs (2 classes that switch)
6% Chain 3: Real-time tasks (1 class)
7
8model = Network('oqn_multichain');
9
10%% Block 1: nodes
11node{1} = Source(model, 'RequestSource');
12node{2} = Queue(model, 'Router', SchedStrategy.FCFS);
13node{3} = Queue(model, 'WebCache', SchedStrategy.PS);
14node{4} = Queue(model, 'AppServer', SchedStrategy.FCFS);
15node{5} = Queue(model, 'DataServer', SchedStrategy.PS);
16node{6} = Sink(model, 'ResponseSink');
17
18%% Block 2: job classes
19% Chain 1: Interactive requests (can switch between InteractiveA and InteractiveB)
20jobclass{1} = OpenClass(model, 'InteractiveA', 0);
21jobclass{2} = OpenClass(model, 'InteractiveB', 0);
22% Chain 2: Batch jobs (can switch between BatchA and BatchB)
23jobclass{3} = OpenClass(model, 'BatchA', 0);
24jobclass{4} = OpenClass(model, 'BatchB', 0);
25% Chain 3: Real-time tasks
26jobclass{5} = OpenClass(model, 'RealTime', 0);
27
28%% Block 3: service times
29% Router
30node{2}.setService(jobclass{1}, Exp.fitMean(0.15));
31node{2}.setService(jobclass{2}, Exp.fitMean(0.18));
32node{2}.setService(jobclass{3}, Exp.fitMean(0.2));
33node{2}.setService(jobclass{4}, Exp.fitMean(0.22));
34node{2}.setService(jobclass{5}, Exp.fitMean(0.1));
35
36% WebCache
37node{3}.setService(jobclass{1}, Exp.fitMean(0.3));
38node{3}.setService(jobclass{2}, Exp.fitMean(0.35));
39node{3}.setService(jobclass{3}, Exp.fitMean(1.0));
40node{3}.setService(jobclass{4}, Exp.fitMean(1.2));
41node{3}.setService(jobclass{5}, Exp.fitMean(0.2));
42
43% AppServer
44node{4}.setService(jobclass{1}, Exp.fitMean(0.5));
45node{4}.setService(jobclass{2}, Exp.fitMean(0.6));
46node{4}.setService(jobclass{3}, Exp.fitMean(1.5));
47node{4}.setService(jobclass{4}, Exp.fitMean(1.8));
48node{4}.setService(jobclass{5}, Exp.fitMean(0.3));
49
50% DataServer
51node{5}.setService(jobclass{1}, Exp.fitMean(0.4));
52node{5}.setService(jobclass{2}, Exp.fitMean(0.45));
53node{5}.setService(jobclass{3}, Exp.fitMean(0.8));
54node{5}.setService(jobclass{4}, Exp.fitMean(1.0));
55node{5}.setService(jobclass{5}, Exp.fitMean(0.25));
56
57%% Block 4: arrival rates
58% Interactive requests
59node{1}.setArrival(jobclass{1}, Exp(0.8));
60node{1}.setArrival(jobclass{2}, Exp(0.3));
61% Batch jobs
62node{1}.setArrival(jobclass{3}, Exp(0.5));
63node{1}.setArrival(jobclass{4}, Exp(0.4));
64% Real-time tasks
65node{1}.setArrival(jobclass{5}, Exp(0.6));
66
67%% Block 5: routing with class switching
68M = model.getNumberOfNodes();
69K = model.getNumberOfClasses();
70
71P = model.initRoutingMatrix();
72
73% ===== Chain 1: Interactive requests with switching =====
74% InteractiveA routing:
75P{1,1}(1,2) = 1; % Source -> Router
76P{1,1}(2,3) = 0.6; % Router -> WebCache (stay in InteractiveA)
77P{1,2}(2,3) = 0.4; % Class switch to InteractiveB at Router
78P{1,1}(3,4) = 1; % WebCache -> AppServer
79P{1,1}(4,5) = 1; % AppServer -> DataServer
80P{1,1}(5,6) = 1; % DataServer -> Sink
81
82% InteractiveB routing:
83P{2,2}(1,2) = 1; % Source -> Router
84P{2,2}(2,3) = 0.7; % Router -> WebCache (stay in InteractiveB)
85P{2,1}(2,3) = 0.3; % Class switch to InteractiveA at Router
86P{2,2}(3,4) = 1; % WebCache -> AppServer
87P{2,2}(4,5) = 1; % AppServer -> DataServer
88P{2,2}(5,6) = 1; % DataServer -> Sink
89
90% ===== Chain 2: Batch jobs with switching =====
91% BatchA routing:
92P{3,3}(1,2) = 1; % Source -> Router
93P{3,3}(2,3) = 0.5; % Router -> WebCache (stay in BatchA)
94P{3,4}(2,3) = 0.5; % Class switch to BatchB at Router
95P{3,3}(3,4) = 1; % WebCache -> AppServer
96P{3,3}(4,5) = 1; % AppServer -> DataServer
97P{3,3}(5,6) = 1; % DataServer -> Sink
98
99% BatchB routing:
100P{4,4}(1,2) = 1; % Source -> Router
101P{4,4}(2,3) = 0.6; % Router -> WebCache (stay in BatchB)
102P{4,3}(2,3) = 0.4; % Class switch to BatchA at Router
103P{4,4}(3,4) = 1; % WebCache -> AppServer
104P{4,4}(4,5) = 1; % AppServer -> DataServer
105P{4,4}(5,6) = 1; % DataServer -> Sink
106
107% ===== Chain 3: Real-time tasks =====
108% RealTime routing:
109P{5,5}(1,2) = 1; % Source -> Router
110P{5,5}(2,3) = 1; % Router -> WebCache
111P{5,5}(3,4) = 1; % WebCache -> AppServer
112P{5,5}(4,5) = 1; % AppServer -> DataServer
113P{5,5}(5,6) = 1; % DataServer -> Sink
114
115model.link(P);
116
117%% Block 6: solve with multiple solvers
118options = Solver.defaultOptions;
119options.keep = true;
120options.verbose = 1;
121options.cutoff = 10;
122options.seed = 23000;
123
124disp('Open QN with 3 chains, 5 classes, and class switching:');
125disp('- Chain 1: InteractiveA and InteractiveB (switch at Router)');
126disp('- Chain 2: BatchA and BatchB (switch at Router)');
127disp('- Chain 3: RealTime');
128disp(' ');
129
130solver = {};
131solver{end+1} = MVA(model, options);
132solver{end+1} = FLD(model, options);
133solver{end+1} = SSA(model, options);
134
135for s = 1:length(solver)
136 fprintf('SOLVER: %s\n', solver{s}.getName());
137 AvgTable{s} = solver{s}.getAvgTable();
138 AvgTable{s}
139 fprintf('\n');
140end
Definition mmt.m:92