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_fired, 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_fired_k = space_fired(en,:);
30 space_var_k = space_var(en,:);
31 % MAP transitions currently unsupported
32 %if ismkvmodclass(class)
33 % space_var_k(sum(sn.nvars(ind,1:class))) = kdest;
34 %end
35 space_srv_k(:,Ks(mode)+k) = space_srv_k(:,Ks(mode)+k) - 1;
36 space_srv_k(:,Ks(mode)+kdest) = space_srv_k(:,Ks(mode)+kdest) + 1;
37
38 rate = sn.nodeparam{ind}.firingproc{mode}{1}(k,kdest)*kir(:,mode,k); % assume active
39 % We do not support class-dependence
40 outrate = [outrate; nir(mode).*rate];
41 outspace = [outspace; space_buf_k, space_srv_k, space_fired_k, space_var_k];
42 outprob = [outprob; ones(size(rate,1),1)];
43 end
44 end
45 end
46 if isSimulation
47 if nargin>=7 && isobject(eventCache)
48 eventCache(key) = {outprob, outspace,outrate};
49 end
50
51 if size(outspace,1) > 1
52 tot_rate = sum(outrate);
53 cum_rate = cumsum(outrate) / tot_rate;
54 firing_ctr = 1 + max([0,find( rand > cum_rate' )]); % select action
55 outspace = outspace(firing_ctr,:);
56 outrate = sum(outrate);
57 outprob = outprob(firing_ctr,:);
58 end
59 end
60 end
61end
62end
63