LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
QN2LQN.m
1function lqn=QN2LQN(model)
2
3lqn = LayeredNetwork(model.getName());
4sn = model.getStruct;
5
6PH = Host(lqn, model.getName(), Inf, SchedStrategy.INF); % pseudo host
7for c=1:sn.nchains
8 inchain = sn.inchain{c};
9 RT{c} = Task(lqn,['RefTask_',num2str(c)], sum(sn.njobs(inchain)), SchedStrategy.REF).on(PH); % reference task for chain c
10 RE{c} = Entry(lqn,['Chain_',num2str(c)]).on(RT{c}); % entry on reference task for chain c
11end
12
13for i=1:sn.nnodes
14 switch sn.nodetype(i)
15 case {NodeType.Queue, NodeType.Delay}
16 P{i} = Host(lqn, sn.nodenames{i}, sn.nservers(sn.nodeToStation(i)), SchedStrategy.fromId(sn.sched(sn.nodeToStation(i))));
17 T{i} = Task(lqn,['T_',sn.nodenames{i}], Inf, SchedStrategy.INF).on(P{i});
18 for r=1:sn.nclasses
19 c = find(sn.chains(:,r)); % chain of class r
20 if sn.visits{c}(i,r)>0
21 E{i,r} = Entry(lqn, ['E',num2str(i),'_',num2str(r)]).on(T{i});
22 A{i,r} = Activity(lqn, ['Q',num2str(i),'_',num2str(r)], model.nodes{i}.getServiceProcess(model.classes{r})).on(T{i}).boundTo(E{i,r}).repliesTo(E{i,r});
23 end
24 end
25 case NodeType.ClassSwitch
26 % no-op
27 otherwise
28 line_error(mfilename,sprintf('Node type %s is not yet supported.\n',NodeType.toText(sn.nodetype(i))));
29 end
30end
31
32boundToRE = cell(1,sn.nchains);
33for i=1:sn.nnodes
34 switch sn.nodetype(i)
35 case {NodeType.ClassSwitch}
36 for r=1:sn.nclasses
37 c = find(sn.chains(:,r)); % chain of class r
38 if any(sn.rtnodes(:, ((i-1)*sn.nclasses + r))>0)
39 PA{c,i,r} = Activity(lqn, ['CS','_',num2str(c),'_',num2str(i),'_',num2str(r)], Immediate()).on(RT{c}); % pseudo-activity in ref task
40 end
41 end
42 case {NodeType.Queue, NodeType.Delay}
43 for r=1:sn.nclasses
44 c = find(sn.chains(:,r)); % chain of class r
45 if sn.visits{c}(i,r)>0
46 inchain = sn.inchain{c};
47 if i == sn.refstat(inchain(1)) && r == inchain(1)
48 PA{c,i,r} = Activity(lqn, ['A',num2str(i),'_',num2str(r)], Immediate()).on(RT{c}).boundTo(RE{c}).synchCall(E{i,r}); % pseudo-activity in ref task
49 boundToRE{c} = [i,r];
50 else
51 PA{c,i,r} = Activity(lqn, ['A',num2str(i),'_',num2str(r)], Immediate()).on(RT{c}).synchCall(E{i,r}); % pseudo-activity in ref task
52 end
53 %RT{c}.addPrecedence(ActivityPrecedence.Serial(PN{c,i},PA{i,r}));
54 end
55 end
56 case NodeType.ClassSwitch
57 % no-op
58 otherwise
59 line_error(mfilename,sprintf('Node type %s is not yet supported.\n',NodeType.toText(sn.nodetype(i))));
60 end
61end
62
63usedInORFork = zeros(sn.nnodes,sn.nclasses);
64for c=1:sn.nchains
65 inchain = sn.inchain{c};
66 %refstat = sn.refstat(inchain(1));
67 for i=1:sn.nnodes
68 switch sn.nodetype(i)
69 case {NodeType.Queue, NodeType.Delay,NodeType.ClassSwitch}
70 for r=inchain
71 orfork_prec = {};
72 orfork_prob = [];
73 for j=1:sn.nnodes
74 switch sn.nodetype(j)
75 case {NodeType.Queue, NodeType.Delay,NodeType.ClassSwitch}
76 for s=inchain
77 pr = sn.rtnodes((i-1)*sn.nclasses + r, (j-1)*sn.nclasses + s);
78 if pr>0 && any(sn.rtnodes(:, ((i-1)*sn.nclasses + r))>0)
79 if ~isempty(boundToRE{c})
80 if boundToRE{c}(1)==j && boundToRE{c}(2)==s
81 if ~isempty(PA{c,i,r})
82 orfork_prec{end+1} = Activity(lqn, ['End_',num2str(c),'_',num2str(i),'_',num2str(r)], Immediate()).on(RT{c});
83 orfork_prob(end+1)= pr;
84 end
85 else
86 orfork_prec{end+1} = PA{c,j,s};
87 orfork_prob(end+1) = pr;
88 end
89 end
90 end
91 end
92 end
93 end
94 if ~isempty(orfork_prec)
95 if ~isempty(PA{c,i,r})
96 RT{c}.addPrecedence(ActivityPrecedence.OrFork(PA{c,i,r}, orfork_prec, orfork_prob));
97 usedInORFork(i,r) = usedInORFork(i,r) + 1;
98 end
99 end
100 end
101 end
102 end
103end
104
105end