LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pas_placement.m
1function [P, placeable] = pas_placement(H)
2% [P, PLACEABLE] = PAS_PLACEMENT(H)
3%
4% Placement-order logic of a pass-and-swap (P&S) / order-independent network
5% with swap graph H. Isolates the check that decides which class orderings are
6% feasible (adhere to the placement partial order) for PFQN_PAS_IS / PFQN_PASNC.
7%
8% An ordering c = (c_1, ..., c_ell) is FEASIBLE iff it is non-decreasing with
9% respect to H, i.e. class a never appears before class b whenever H(b,a) ~= 0
10% (Comte & Dorsman, 2021, arXiv:2009.12299). Equivalently H(b,a) ~= 0 means b
11% must be placed before a. Collecting these constraints and taking the
12% transitive closure yields the precedence matrix
13% P(i,j) = 1 iff class i must be placed before class j,
14% so an ordering is feasible iff every class is placed only after all of its
15% P-predecessors. H may be given as a mere Hasse diagram; the closure makes the
16% full order explicit.
17%
19% H - (R x R) swap-graph adjacency (H(b,a) ~= 0 forces b before a). The empty
20% or all-zero graph yields P = 0 (no constraints, pure OI: every ordering
21% feasible).
22%
23% Returns:
24% P - (R x R) precedence closure; P(i,j)=1 iff i must precede j.
25% placeable - function handle placeable(x) returning the row vector of class
26% indices that may be placed next given the remaining per-class
27% count vector x (1 x R): those present classes with no remaining
28% predecessor still to be placed. Used to enumerate/sample the
29% feasible orderings and to check placement-order adherence.
30%
31% See also PFQN_PAS_IS, PFQN_PASNC, PAS_SWAP2PREC.
32%
33% Copyright (c) 2012-2026, Imperial College London
34% All rights reserved.
35
36R = size(H, 1);
37if isempty(H)
38 P = [];
39 placeable = @(x) find(x > 0);
40 return
41end
42H = (H ~= 0);
43
44% Transitive closure of the "must precede" relation (P(i,j)=1 iff i precedes j,
45% i.e. edge i->j in H). Iterate R times so paths of any length are captured.
46P = H;
47for it = 1:R %#ok<NASGU>
48 Pnext = (P | (P * H)) > 0;
49 if isequal(Pnext, P)
50 break
51 end
52 P = Pnext;
53end
54P = double(P);
55
56placeable = @(x) local_placeable(x, P);
57end
58
59function idx = local_placeable(x, P)
60% Class j is placeable iff it is present (x(j)>0) and no still-present class i
61% must precede it: sum_i x(i) P(i,j) == 0.
62x = x(:)';
63if isempty(P)
64 idx = find(x > 0);
65else
66 idx = find((x * P) == 0 & x > 0);
67end
68end
Definition Station.m:245