LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
spaceCache.m
1function SS = spaceCache(n, m, retrievalSystemCapacity)
2% SS = SPACECACHE(N, M, RETRIEVALSYSTEMCAPACITY)
3%
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).
12
13% Copyright (c) 2012-2026, Imperial College London
14% All rights reserved.
15
16if nargin < 3 || isempty(retrievalSystemCapacity)
17 retrievalSystemCapacity = 0;
18end
19
20totalCacheCapacity = sum(m);
21nItems = sum(n);
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;
27else
28 retrievalWidth = 0;
29end
30nVars = totalCacheCapacity + retrievalWidth;
31
32SS = zeros(0, nVars);
33try
34 if totalCacheCapacity == 0
35 % degenerate cache with zero capacity
36 SS = zeros(1, max(nVars,1));
37 else
38 items = 1:nItems;
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
48 if s == 0
49 retrCombos = zeros(1,0); % the empty subset
50 elseif numel(remaining) < s
51 continue;
52 else
53 retrCombos = nchoosek(remaining, s);
54 end
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;
59 end
60 for pp = 1:size(cachePerms,1)
61 SS = [SS; [cachePerms(pp,:), bitmap]];
62 end
63 end
64 end
65 end
66 end
67catch ME
68 line_error(mfilename,'The model is too large, LINE cannot generate the state space explicitly.');
69end
70
71end