LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
afterEventTransition.m
1function [outspace, outrate, outprob, eventCache] = afterEventTransition(sn, ind, inspace, K, Ks, event, class, isSimulation, eventCache, R, space_buf, space_srv, space_var, key)
2% job arrives in class, then reads and moves into hit or miss
3% class, then departs
4
5outspace = [];
6outrate = [];
7outprob = 1;
8switch event
9 case EventType.ENABLE
10 % no-op this is a global event
11 case EventType.FIRE
12 % no-op this is a global event
13 case EventType.PHASE
14 mode = class; % in a Transition, Event.class is interpreted as the mode
15 outspace = [];
16 outrate = [];
17 outprob = [];
18 [ni,nir,~,kir] = State.toMarginal(sn,ind,inspace,K,Ks,space_buf,space_srv,space_var);
19 % ni, nir, kir is the count of *enabled* servers while
20 % they progress their execution through the phases
21 if nir(mode)>0
22 for k=1:K(mode)
23 en = space_srv(:,Ks(mode)+k) > 0;
24 if any(en)
25 for kdest=setdiff(1:K(mode),k) % new phase
26 rate = 0;
27 space_srv_k = space_srv(en,:);
28 space_buf_k = space_buf(en,:);
29 space_var_k = space_var(en,:);
30 % MAP transitions currently unsupported
31 %if ismkvmodclass(class)
32 % space_var_k(sum(sn.nvars(ind,1:class))) = kdest;
33 %end
34 space_srv_k(:,Ks(mode)+k) = space_srv_k(:,Ks(mode)+k) - 1;
35 space_srv_k(:,Ks(mode)+kdest) = space_srv_k(:,Ks(mode)+kdest) + 1;
36
37 rate = sn.nodeparam{ind}.firingproc{mode}{1}(k,kdest)*kir(:,mode,k); % assume active
38 % We do not support class-dependence
39 outrate = [outrate; nir(mode).*rate];
40 outspace = [outspace; space_buf_k, space_srv_k, space_var_k];
41 outprob = [outprob; ones(size(rate,1),1)];
42 end
43 end
44 end
45 if isSimulation
46 if nargin>=7 && isobject(eventCache)
47 eventCache(key) = {outprob, outspace,outrate};
48 end
49
50 if size(outspace,1) > 1
51 tot_rate = sum(outrate);
52 cum_rate = cumsum(outrate) / tot_rate;
53 firing_ctr = 1 + max([0,find( rand > cum_rate' )]); % select action
54 outspace = outspace(firing_ctr,:);
55 outrate = sum(outrate);
56 outprob = outprob(firing_ctr,:);
57 end
58 end
59 end
60end
61end
62