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);
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 infinite servers, use large finite value for state (SSA needs finite states)
86 state_i(isinf(state_i)) = GlobalConstants.MaxInt();
87 % For non-Markovian distributions, firingphases is NaN - treat as 1 phase
88 firingphases = sn.nodeparam{ind}.firingphases;
89 firingphases(isnan(firingphases)) = 1;
90 state_i = [state_i, zeros(1, sum(firingphases)), zeros(size(state_i))]; %#ok<AGROW>
94 %line_error(mfilename,'Default initialization not available on stateful node %d.
',i);
97 if sn.isstateful(ind) % not a station
99 self.nodes{ind}.setStateSpace(state_i);
100 self.nodes{ind}.setStatePrior(1);
101 self.nodes{ind}.setState(state_i);
102 elseif size(state_i,1)>1
103 prior_state_i = zeros(1,size(state_i,1)); prior_state_i(1) = 1;
104 self.nodes{ind}.setStateSpace(state_i);
105 self.nodes{ind}.setStatePrior(prior_state_i);
106 self.nodes{ind}.setState(state_i(1,:));
108 self.nodes{ind}.setStateSpace([]);
109 self.nodes{ind}.setStatePrior([]);
110 self.nodes{ind}.setState([]);
115if self.isStateValid % problem with example_initState_2
116 self.hasState = true;
118 line_error(mfilename,sprintf('Default initialization failed.
'));