LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
QN2LINE.m
1function model = QN2LINE(sn, modelName)
2% MODEL = QN2LINE(QN, MODELNAME)
3
4% Copyright (c) 2012-2026, Imperial College London
5% All rights reserved.
6if nargin<2%~exist('modelName','var')
7 modelName = 'sn';
8end
9%%
10M = sn.nstations; %number of stations
11K = sn.nclasses; %number of classes
12rt = sn.rt;
13NK = sn.njobs; % initial population per class
14Ktrue = nnz(NK); % classes that are not artificial
15
16%% initialization
17model = Network(modelName);
18hasSink = 0;
19idSource = [];
20for ist = 1:M
21 switch sn.sched(ist)
22 case SchedStrategy.INF
23 node{ist} = Delay(model, sn.nodenames{ist});
24 case SchedStrategy.FORK
25 node{ist} = ForkStation(model, sn.nodenames{ist});
26 case SchedStrategy.EXT
27 node{ist} = Source(model, 'Source'); idSource = ist;
28 node{M+1} = Sink(model, 'Sink'); hasSink = 1;
29 otherwise
30 node{ist} = Queue(model, sn.nodenames{ist}, SchedStrategy.toFeature(sn.sched(ist)));
31 node{ist}.setNumServers(sn.nservers(ist));
32 end
33end
34
35PH = sn.proc;
36for k = 1:K
37 if k<=Ktrue
38 if isinf(NK(k))
39 jobclass{k} = OpenClass(model, sn.classnames{k}, 0);
40 else
41 jobclass{k} = ClosedClass(model, sn.classnames{k}, NK(k), node{sn.refstat(k)}, 0);
42 end
43 else
44 % if the reference node is unspecified, as in artificial classes,
45 % set it to the first node where the rate for this class is
46 % non-null
47 for ist=1:M
48 if sum(nnz(sn.proc{ist}{k}{1}))>0
49 break
50 end
51 end
52 if isinf(NK(k))
53 jobclass{k} = OpenClass(model, sn.classnames{k});
54 else
55 jobclass{k} = ClosedClass(model, sn.classnames{k}, NK(k), node{ist}, 0);
56 end
57 end
58
59 for ist=1:M
60 SCVik = map_scv(PH{ist}{k});
61 % if SCVik >= 0.5
62 switch sn.sched(ist)
63 case SchedStrategy.EXT
64 if isnan(sn.rates(ist,k))
65 node{ist}.setArrival(jobclass{k}, Disabled.getInstance());
66 elseif sn.rates(ist,k)==0
67 node{ist}.setArrival(jobclass{k}, Immediate.getInstance());
68 else
69 node{ist}.setArrival(jobclass{k}, APH.fitMeanAndSCV(map_mean(PH{ist}{k}),SCVik));
70 end
71 case SchedStrategy.FORK
72 % do nothing
73 otherwise
74 if isnan(sn.rates(ist,k))
75 node{ist}.setService(jobclass{k}, Disabled.getInstance());
76 elseif sn.rates(ist,k)==0
77 node{ist}.setService(jobclass{k}, Immediate.getInstance());
78 else
79 node{ist}.setService(jobclass{k}, APH.fitMeanAndSCV(map_mean(PH{ist}{k}),SCVik));
80 end
81 end
82 % else
83 % this could be made more precised by fitting into a 2-state
84 % APH, especially if SCV in [0.5,0.1]
85 % nPhases = max(1,round(1/SCVik));
86 % switch sn.sched(i)
87 % case SchedStrategy.EXT
88 % node{i}.setArrival(jobclass{k}, Erlang(nPhases/map_mean(PH{i}{k}),nPhases));
89 % case SchedStrategy.FORK
90 % do nothing
91 % otherwise
92 % node{i}.setService(jobclass{k}, Erlang(nPhases/map_mean(PH{i}{k}),nPhases));
93 % end
94 end
95 %end
96end
97
98myP = cell(K,K);
99for k = 1:K
100 for c = 1:K
101 myP{k,c} = zeros(M+hasSink);
102 for ist=1:M
103 for m=1:M
104 % routing matrix for each class
105 if hasSink && m == idSource % direct to sink
106 myP{k,c}(ist,M+1) = rt((ist-1)*K+k,(m-1)*K+c);
107 else
108 myP{k,c}(ist,m) = rt((ist-1)*K+k,(m-1)*K+c);
109 end
110 end
111 end
112 end
113end
114
115model.link(myP);
116end