LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
initFromMarginal.m
1function initFromMarginal(self, n, options) % n(i,r) : number of jobs of class r in node or station i (autodetected)
2% INITFROMMARGINAL(N, OPTIONS) % N(I,R) : NUMBER OF JOBS OF CLASS R IN NODE OR STATION I
3
4%global GlobalConstants.CoarseTol
5
6if nargin<3 %~exist('options','var')
7 options = Solver.defaultOptions;
8end
9
10if ~self.hasStruct
11 self.refreshStruct;
12end
13sn = getStruct(self);
14
15if self.getNumberOfStations() < self.getNumberOfNodes()
16 if size(n,1)==self.getNumberOfStations()
17 nnodes = zeros(sn.nnodes,size(n,2));
18 for ist=1:sn.nstations
19 ind = sn.stationToNode(ist);
20 nnodes(ind,:) = n(ist,:);
21 end
22 n = nnodes;
23 elseif size(n,1)==self.getNumberOfNodes()
24 % no-op
25 else
26 line_error(mfilename,'The supplied matrix of marginal states does not have the correct number of rows. One either one per station or one per node.');
27 end
28end
29
30[isvalidn] = State.isValid(sn, n, [], options);
31if ~isvalidn
32 % line_error(mfilename,'The specified state does not have the correct number of jobs.');
33 line_warning(mfilename,'Initial state not contained in the state space. Trying to recover.\n');
34 n = round(n);
35 [isvalidn] = State.isValid(sn, n, [], options);
36 if ~isvalidn
37 line_error(mfilename,'Cannot recover - stopping.');
38 end
39end
40for ind=1:sn.nnodes
41 if sn.isstateful(ind)
42 switch sn.nodetype(ind)
43 case NodeType.Place
44 state_i = n(ind,:);
45 otherwise
46 if max(abs(n(ind,:) - round(n(ind,:)))) < GlobalConstants.CoarseTol
47 state_i = State.fromMarginal(sn,ind,round(n(ind,:)));
48 else % the state argument is purposedly given fractional, e.g. for Fluid solver initialization
49 state_i = n(ind,:);
50 end
51 end
52 if size(state_i,1)==1
53 self.nodes{ind}.setStateSpace(state_i);
54 self.nodes{ind}.setStatePrior(1);
55 self.nodes{ind}.setState(state_i);
56 elseif size(state_i,1)>1
57 prior_state_i = zeros(1,size(state_i,1)); prior_state_i(1) = 1;
58 self.nodes{ind}.setStateSpace(state_i);
59 self.nodes{ind}.setStatePrior(prior_state_i);
60 self.nodes{ind}.setState(state_i(1,:));
61 else
62 self.nodes{ind}.setStateSpace([]);
63 self.nodes{ind}.setStatePrior([]);
64 self.nodes{ind}.setState([]);
65 end
66 if isempty(self.nodes{ind}.getState)
67 line_error(mfilename,sprintf('Invalid state assignment for station %d.',ind));
68 end
69 end
70end
71self.hasState = true;
72end