LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
refreshGlobalSync.m
1function gsync = refreshGlobalSync(self)
2% SYNC = REFRESHGLOBALSYNC()
3
4sn = self.sn;
5local = self.getNumberOfNodes+1;
6nclasses = sn.nclasses;
7gsync = {};
8emptystate = cellzeros(sn.nnodes,1,0,0);
9if any(sn.isstatedep(:))
10 rtmask = self.sn.rtfun(emptystate, emptystate);
11else
12 rtmask = ceil(self.sn.rt);
13end
14
15% see _kb/04-networkstruct.md (refreshGlobalSync/refreshSync) for rationale
16for ind=1:sn.nnodes
17
18 if sn.isstateful(ind)
19 if sn.nodetype(ind) == NodeType.Transition
20 for m=1:sn.nodeparam{ind}.nmodes
21 % mode enabling
22 enablingPlaces = find(sn.nodeparam{ind}.enabling{m});
23 % inhibitor-arc input places (finite threshold). Added as
24 % LOCAL events (no state effect) so their markings are read
25 % into ep_space and the enabling test can apply the upper
26 % bound. Exclude places already listed as enabling inputs.
27 inhibitingPlaces = setdiff(find(~isinf(sn.nodeparam{ind}.inhibiting{m})), enablingPlaces);
28 gsync{end+1,1}.active{1} = ModeEvent(EventType.ENABLE, ind, m, 1.0);
29 gsync{end,1}.passive = cell(1,length(enablingPlaces)+length(inhibitingPlaces));
30 for ep=1:length(enablingPlaces)
31 gsync{end,1}.passive{ep} = ModeEvent(EventType.LOCAL, enablingPlaces(ep), m, 1.0); % ID_LOCAL has no state effects
32 end
33 for ip=1:length(inhibitingPlaces)
34 gsync{end,1}.passive{length(enablingPlaces)+ip} = ModeEvent(EventType.LOCAL, inhibitingPlaces(ip), m, 1.0);
35 end
36 end
37 for m=1:sn.nodeparam{ind}.nmodes
38 % mode firing
39 % see _kb/04-networkstruct.md (refreshGlobalSync/refreshSync) for rationale
40 firingPlaces = find(sn.nodeparam{ind}.firing{m} > 0);
41 enablingPlaces = find(sn.nodeparam{ind}.enabling{m});
42 % inhibitor-arc input places (finite threshold), read into
43 % ep_space for the firing enabling-degree test. Added as
44 % LOCAL events (no token effect); exclude places already
45 % present as enabling (PRE) or firing (POST) passives.
46 inhibitingPlaces = setdiff(find(~isinf(sn.nodeparam{ind}.inhibiting{m})), union(enablingPlaces, firingPlaces));
47 gsync{end+1,1}.active{1} = ModeEvent(EventType.FIRE, ind, m);
48
49 gsync{end,1}.passive = {};
50 for ep=1:length(enablingPlaces)
51 % TODO: this creates a departure event for each
52 % job pulled from the enabling places, which is
53 % inefficient
54 gsync{end,1}.passive{end+1} = ModeEvent(EventType.PRE, enablingPlaces(ep), m, sn.nodeparam{ind}.enabling{m}(enablingPlaces(ep)));
55 end
56 for fp=1:length(firingPlaces)
57 % TODO: this creates an arrival event for each
58 % fired job to the destination place, which is
59 % inefficient
60 gsync{end,1}.passive{end+1} = ModeEvent(EventType.POST, firingPlaces(fp), m, sn.nodeparam{ind}.firing{m}(firingPlaces(fp)));
61 end
62 for ip=1:length(inhibitingPlaces)
63 gsync{end,1}.passive{end+1} = ModeEvent(EventType.LOCAL, inhibitingPlaces(ip), m, 1.0);
64 end
65 end
66 end
67
68 end
69end
70if ~isempty(self.sn) %&& isprop(self.sn,'nvars')
71 self.sn.gsync = gsync;
72end
73end