1function initDefault(self,
nodes)
5% closed
classes initialized at ref station
6% running jobs are allocated in
class id order until all
9%refreshStruct(self); % we force update of the model before we initialize
11sn = self.getStruct(
false);
16 nodes = 1:self.getNumberOfNodes;
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)
32 switch sn.nodetype(ind)
34 state_i = State.fromMarginalAndStarted(sn,ind,n0(:)
',s0(:)');
35 state_i = [state_i, 1:sn.nvars(ind,2*R+1)]; %#ok<AGROW>
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;
41 state_i = zeros(1,self.getNumberOfClasses);
43 if sn.refstat(r) == ist
44 state_i(r) = sn.njobs(r);
51 state_i = State.fromMarginalAndStarted(sn,ind,n0(:)
',s0(:)');
54 switch sn.procid(sn.nodeToStation(ind),r)
56 %state_i = State.cartesian(state_i, [1:sn.phases(i,r)]
');
57 state_i = State.cartesian(state_i, 1);
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)];
70 line_error(mfilename,sprintf('Default initialization failed on station %d.
',ind));
72 elseif sn.isstateful(ind) % not a station
73 switch sn.nodetype(ind)
75 state_i = [zeros(1,self.getNumberOfClasses), 1:sum(self.nodes{ind}.itemLevelCap)];
77 state_i = zeros(1, self.getNumberOfClasses);
79 switch sn.routing(ind,r)
80 case RoutingStrategy.RROBIN
81 % RR slot holds destination value; start at first connected queue
82 state_i = [state_i, find(sn.connmatrix(ind,:),1)]; %#ok<AGROW>
83 case RoutingStrategy.WRROBIN
84 % WRR slot holds POSITION in weighted_outlinks; start at 1
85 state_i = [state_i, 1]; %#ok<AGROW>
86 case RoutingStrategy.KCHOICES
87 % KCHOICES with memory: -1 marks "no prior pick".
88 if isfield(self.nodes{ind}.output.outputStrategy{1, r}, 'withMemory
') ...
89 || (iscell(self.nodes{ind}.output.outputStrategy{1, r}) ...
90 && length(self.nodes{ind}.output.outputStrategy{1, r}) >= 3 ...
91 && length(self.nodes{ind}.output.outputStrategy{1, r}{3}) >= 2 ...
92 && self.nodes{ind}.output.outputStrategy{1, r}{3}{2})
93 state_i = [state_i, -1]; %#ok<AGROW>
97 case NodeType.Transition
98 % Differently from a server, the first nmodes states in a
99 % transitions count the servers that are not enabled and
100 % the last nodes count servers that just fired.
101 % This is required as the local state does not encode the
102 % buffer hence the enabling condition is not available.
103 state_i = sn.nodeparam{ind}.nmodeservers;
104 % For infinite servers, use large finite value for state (SSA needs finite states)
105 state_i(isinf(state_i)) = GlobalConstants.MaxInt();
106 % For non-Markovian distributions, firingphases is NaN - treat as 1 phase
107 firingphases = sn.nodeparam{ind}.firingphases;
108 firingphases(isnan(firingphases)) = 1;
109 state_i = [state_i, zeros(1, sum(firingphases)), zeros(size(state_i))]; %#ok<AGROW>
113 %line_error(mfilename,'Default initialization not available on stateful node %d.
',i);
116 if sn.isstateful(ind) % not a station
117 if size(state_i,1)==1
118 self.nodes{ind}.setStateSpace(state_i);
119 self.nodes{ind}.setStatePrior(1);
120 self.nodes{ind}.setState(state_i);
121 elseif size(state_i,1)>1
122 prior_state_i = zeros(1,size(state_i,1)); prior_state_i(1) = 1;
123 self.nodes{ind}.setStateSpace(state_i);
124 self.nodes{ind}.setStatePrior(prior_state_i);
125 self.nodes{ind}.setState(state_i(1,:));
127 self.nodes{ind}.setStateSpace([]);
128 self.nodes{ind}.setStatePrior([]);
129 self.nodes{ind}.setState([]);
134if self.isStateValid % problem with example_initState_2
135 self.hasState = true;
137 line_error(mfilename,sprintf('Default initialization failed.
'));