LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
initDefault.m
1function initDefault(self, nodes)
2% INITDEFAULT(NODES)
3
4% open classes empty
5% closed classes initialized at ref station
6% running jobs are allocated in class id order until all
7% servers are busy
8
9%refreshStruct(self); % we force update of the model before we initialize
10
11sn = self.getStruct(false);
12
13R = sn.nclasses;
14N = sn.njobs';
15if nargin < 2
16 nodes = 1:self.getNumberOfNodes;
17end
18
19for ind=nodes
20 if sn.isstation(ind)
21 ist = sn.nodeToStation(ind);
22 n0 = zeros(1,length(N)); % number of jobs in the initial state
23 s0 = zeros(1,length(N)); % number of active servers in the initial state
24 s = sn.nservers(ist); % allocate
25 for r=find(isfinite(N))' % for all closed classes
26 if sn.nodeToStation(ind) == sn.refstat(r)
27 n0(r) = N(r);
28 end
29 s0(r) = min(n0(r),s);
30 s = s - s0(r);
31 end
32 switch sn.nodetype(ind)
33 case NodeType.Cache
34 state_i = State.fromMarginalAndStarted(sn,ind,n0(:)',s0(:)');
35 state_i = [state_i, 1:sn.nvars(ind,2*R+1)]; %#ok<AGROW>
36 case NodeType.Place
37 if sum(self.nodes{ind}.state)>0
38 % if the user pre-loaded manually some jobs, keep them
39 state_i = self.nodes{ind}.state;
40 else
41 state_i = zeros(1,self.getNumberOfClasses);
42 for r=1:sn.nclasses
43 if sn.refstat(r) == ist
44 state_i(r) = sn.njobs(r);
45 else
46 state_i(r) = 0;
47 end
48 end
49 end
50 otherwise
51 state_i = State.fromMarginalAndStarted(sn,ind,n0(:)',s0(:)');
52 if sn.isstation(ind)
53 for r=1:sn.nclasses
54 switch sn.procid(sn.nodeToStation(ind),r)
55 case ProcessType.MAP
56 %state_i = State.cartesian(state_i, [1:sn.phases(i,r)]');
57 state_i = State.cartesian(state_i, 1);
58 end
59 end
60 end
61 end
62 for r=1:sn.nclasses
63 switch sn.routing(ind,r)
64 case {RoutingStrategy.RROBIN, RoutingStrategy.WRROBIN}
65 % start from first connected queue
66 state_i = [state_i, find(sn.connmatrix(ind,:),1)];
67 end
68 end
69 if isempty(state_i)
70 line_error(mfilename,sprintf('Default initialization failed on station %d.',ind));
71 end
72 elseif sn.isstateful(ind) % not a station
73 switch sn.nodetype(ind)
74 case NodeType.Cache
75 state_i = [zeros(1,self.getNumberOfClasses), 1:sum(self.nodes{ind}.itemLevelCap)];
76 case NodeType.Router
77 state_i = zeros(1, self.getNumberOfClasses);
78 case NodeType.Transition
79 % Differently from a server, the first nmodes states in a
80 % transitions count the servers that are not enabled and
81 % the last nodes count servers that just fired.
82 % This is required as the local state does not encode the
83 % buffer hence the enabling condition is not available.
84 state_i = sn.nodeparam{ind}.nmodeservers;
85 % For non-Markovian distributions, firingphases is NaN - treat as 1 phase
86 firingphases = sn.nodeparam{ind}.firingphases;
87 firingphases(isnan(firingphases)) = 1;
88 state_i = [state_i, zeros(1, sum(firingphases)), 0*state_i]; %#ok<AGROW>
89 otherwise
90 state_i = [];
91 end
92 %line_error(mfilename,'Default initialization not available on stateful node %d.',i);
93 end
94
95 if sn.isstateful(ind) % not a station
96 if size(state_i,1)==1
97 self.nodes{ind}.setStateSpace(state_i);
98 self.nodes{ind}.setStatePrior(1);
99 self.nodes{ind}.setState(state_i);
100 elseif size(state_i,1)>1
101 prior_state_i = zeros(1,size(state_i,1)); prior_state_i(1) = 1;
102 self.nodes{ind}.setStateSpace(state_i);
103 self.nodes{ind}.setStatePrior(prior_state_i);
104 self.nodes{ind}.setState(state_i(1,:));
105 else
106 self.nodes{ind}.setStateSpace([]);
107 self.nodes{ind}.setStatePrior([]);
108 self.nodes{ind}.setState([]);
109 end
110 end
111end
112
113if self.isStateValid % problem with example_initState_2
114 self.hasState = true;
115else
116 line_error(mfilename,sprintf('Default initialization failed.'));
117end
118end
Definition mmt.m:92