1function SS = spaceCache(n, m, retrievalSystemCapacity)
2% SS = SPACECACHE(N, M, RETRIEVALSYSTEMCAPACITY)
4% Generate the local-variable state space of a cache node.
5% n : total number of distinct items
6% m : per-level cache capacity (row vector)
7% retrievalSystemCapacity (optional,
default 0): number of extra slots tracking
8% items currently in the retrieval system. When > 0 each emitted row has
9% totalCacheCapacity + retrievalSystemCapacity columns; cache slots hold
10% 1..n item indices (or 0 when partially filled at low item count k) and
11% retrieval slots hold 0 (empty) or 1..n (item being fetched).
13% Copyright (c) 2012-2026, Imperial College London
16if nargin < 3 || isempty(retrievalSystemCapacity)
17 retrievalSystemCapacity = 0;
20totalCacheCapacity = sum(m);
22% The retrieval system
is encoded as a per-item occupancy bitmap (one column per
23% item) appended after the cache contents; bit i
is set iff item i
is currently
24% being retrieved. With no retrieval system the bitmap
is omitted entirely.
25if retrievalSystemCapacity > 0
26 retrievalWidth = nItems;
30nVars = totalCacheCapacity + retrievalWidth;
34 if totalCacheCapacity == 0
35 % degenerate cache with zero capacity
36 SS = zeros(1, max(nVars,1));
39 % Cache contents: every ordered placement of totalCacheCapacity distinct items.
40 cacheCombos = nchoosek(items, totalCacheCapacity);
41 for ci = 1:size(cacheCombos,1)
42 cacheCombo = cacheCombos(ci,:);
43 cachePerms = perms(cacheCombo);
44 remaining = setdiff(items, cacheCombo);
45 % Retrieval-system occupancy: every subset of the remaining items of
46 % size <= retrievalSystemCapacity, as a one-hot bitmap.
47 for s = 0:retrievalSystemCapacity
49 retrCombos = zeros(1,0); % the empty subset
50 elseif numel(remaining) < s
53 retrCombos = nchoosek(remaining, s);
55 for rci = 1:size(retrCombos,1)
56 bitmap = zeros(1, retrievalWidth);
57 for c = 1:size(retrCombos,2)
58 bitmap(retrCombos(rci,c)) = 1;
60 for pp = 1:size(cachePerms,1)
61 SS = [SS; [cachePerms(pp,:), bitmap]];
68 line_error(mfilename,'The model
is too large, LINE cannot generate the state space explicitly.');