LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
afterEventFork.m
1function [outspace, outrate, outprob, eventCache] = afterEventFork(sn, ind, event, class, isSimulation, eventCache, space_buf, space_srv, space_var, key) %#ok<INUSL>
2% [OUTSPACE, OUTRATE, OUTPROB, EVENTCACHE] = AFTEREVENTFORK(SN, IND, EVENT, CLASS, ISSIMULATION, EVENTCACHE, SPACE_BUF, SPACE_SRV, SPACE_VAR, KEY)
3%
4% Handle afterEvent logic for stateful Fork nodes (FJ-augmented structs
5% only, see ModelAdapter.fjtag). The fork state is a per-class count of
6% parent jobs momentarily held before the fork firing. Arrivals are
7% buffered here; the atomic multi-branch emission is not a DEP event but
8% a fork firing synchronization (sn.fjsync) handled by State.afterFJEvent.
9
10% Copyright (c) 2012-2026, Imperial College London
11% All rights reserved.
12
13outspace = [];
14outrate = [];
15outprob = 1;
16
17switch event
18 case EventType.ARV
19 space_srv(:,class) = space_srv(:,class) + 1;
20 outspace = [space_srv, space_var];
21 outrate = -1*ones(size(outspace,1),1); % passive action, rate is unspecified
22 case EventType.DEP
23 % departures from a Fork are never generated as regular syncs
24 % (see refreshSync); they occur only through sn.fjsync firings
25end
26
27if isSimulation
28 if nargin>=6 && isobject(eventCache)
29 eventCache(key) = {outprob, outspace, outrate};
30 end
31 if size(outspace,1) > 1
32 tot_rate = sum(outrate);
33 cum_rate = cumsum(outrate) / tot_rate;
34 firing_ctr = 1 + max([0,find( rand > cum_rate' )]); % select action
35 outspace = outspace(firing_ctr,:);
36 outrate = sum(outrate);
37 outprob = outprob(firing_ctr,:);
38 end
39end
40
41end
Definition fjtag.m:157
Definition Station.m:245