Algorithmadvanced
Symmetric-feasible sequence pair
Also called Balasa-Lampaert symmetric placement.
Balasa and Lampaert's condition on a sequence pair under which a symmetric packing exists, letting annealing search only placements that meet symmetry constraints.
- Solves
- Floorplanning
- Time
- O(n) check · repairO(n^2) relations_and_y
- Space
- O(n^2) extra
- Where
- g = the number of cells in the symmetric set; n = the number of cells
- Model
- Word RAM
- Properties
- deterministiciterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Florin Balasa, Koen Lampaert, 2000
A symmetric-feasible sequence pair is a sequence pair whose two orders treat a symmetric set the same way as its mirror image does, so that the packing can place the group mirror-symmetric about one vertical axis. Its topic is analog sizing and layout, one of the five topics of this sub-area. Balasa and Lampaert gave the condition in 2000 and proved that every such pair has a symmetric placement. The condition is cheap to test and to restore after a move, so an annealing placer can search only these pairs, and every pair it sees meets the symmetry constraint.
In plain words
A sequence pair is two lists of the blocks. Two blocks in the same order in both lists sit side by side; two blocks in opposite orders sit one above the other.
In analog layout, some blocks come in matched pairs that must be mirror images about one vertical line, and some blocks must sit on that line. Most pairs of lists cannot give such a picture: they might ask a matched pair to sit one above the other.
The rule says: read the group's blocks in the first list, swap each block for its partner, and reverse. That must be the order in which the group's blocks appear in the second list. If the lists obey this, a mirror picture exists. If a move breaks it, rewrite the group's slots of the second list in this order to fix it. So the search only visits good lists.
The problem
Given rectangular cells with widths and heights , and one symmetric set with a pairing (pairs of cells of equal size, and self-symmetric cells with ), find a placement without overlap, of small area, in which the cells of each pair have the same and centers mirrored about a common vertical axis , and each self-symmetric cell has its center on the axis. This is floorplanning with the symmetry constraint. Cells outside are free.
A sequence pair is two orders of the cells, with positions and . As on the sequence-pair page, is left of when is before in both orders, and is below when is after in and before in . The pair is symmetric-feasible when
The algorithm
The search is simulated annealing over sequence pairs, as for plain floorplans. Each move changes one or both orders. REPAIR then restores the condition: it takes the group cells in their order, maps each to its partner, reverses this list, and writes it into the slots that the group cells take in . The free cells keep their slots. The cost of a pair is the area (and wire length) of SYM-PACK.
SYM-PACK(Γ+, Γ−, w, h, sym) ▷ one symmetric set, axis vertical- 1
if the pair is not symmetric-feasible then return NONE - 2
for all cells u ≠ v, find whether u is left of v or below v - 3
merge the two cells of each pair into one node of the vertical graph - 4
order the nodes topologically along the below arcs - 5
y(node) ← the longest path to it, with arc weight h_u; each cell takes the y of its node - 6
constraints on x_u ≥ 0, X and W: x_u + w_u ≤ x_v for u left of v; x_u + w_u ≤ W; x_s + w_s / 2 = X for a self-symmetric s; x_u + x_sym(u) + w_u = 2X for a pair- 7
solve the linear program: minimize W subject to the constraints of L6 - 8
return x, y, the axis X, the width W and the height max (y_u + h_u)
Line L1 takes time: list the group cells in the order of , and compare with the reversed list of mirrors in the order of . Line L3 is what gives the two cells of a pair one . Line L6 is not a system of difference constraints, because a pair adds a sum . So the code solves a small linear program, with an exact simplex method in fractions.
Example
Take four cells: a pair of size , a self-symmetric cell of size (width by height), and a free cell of size . Let and .
The group cells in are . Their mirrors are , and reversed this is , which is the order of the group in . So the pair is symmetric-feasible.
| cells | order in | order in | relation |
|---|---|---|---|
| , any other | first | first | left of it |
| , | first | first | left of |
| , | first | first | below |
| , | first | first | below |
So is at , the node at , and at . For : is at 0, is at least 1, is at least 2, and is at least 1. The program gives , and the axis . The centers of the pair are at 1.5 and 2.5, and . The width is 3 and the height is 2, so the area 6 equals the total area of the cells, with no gap.
The order breaks the condition: is before in but is before in , so would be below , and the two cells of a pair could not share one . REPAIR rewrites the group slots as and gives back the order above.
Correctness
The full proofs are in the proof file. The key lemma: if the condition holds and are in the group, then left of implies left of , and below implies below . Each follows from two uses of the condition. The same condition, read for , says that the two cells of a pair are in the same order in both lists, so they are side by side and never one above the other. For two self-symmetric cells it says the orders are opposite, so they are stacked on the axis and never side by side.
From the lemma, the merged vertical graph of line L3 has no cycle: the potential rises along every below relation between group cells, and is the same for the two cells of a pair. So lines L4 and L5 give the least that keeps every below relation and gives each pair one .
For a group with no free cells, the proof file builds a symmetric directly: average the least placement with its mirror image. The mirror keeps the relations by the key lemma, so the average keeps them too, and it has the same width. With free cells, Balasa and Lampaert prove that a symmetric placement that keeps the relations always exists. This page cites that result and does not prove it. Given that it exists, line L7 finds the one of least width. The and constraints share no variable, so SYM-PACK gives the least area among the symmetric placements that keep the relations of the pair.
Proof: The key lemma of symmetric-feasible sequence pairs, and what SYM-PACK returnspartial
Notation. The cells have widths and heights . A sequence pair is two orders and of the cells, with positions and . As on the sequence pair page, is left of if and , and is below if and . Every two distinct cells are in exactly one of these four relations ( left of , left of , below , below ).
A symmetric set is a set of cells with an involution . A pair is with , and the two cells have the same width and height. A self-symmetric cell has . The pair is symmetric-feasible for if
A placement is symmetric if there is a vertical axis such that the two cells of each pair have the same and centers mirrored about the axis, and each self-symmetric cell has its center on the axis.
Lemma 1 (the key lemma). Let hold, and let be in .
- If is left of , then is left of .
- If is below , then is below .
- The two cells of a pair are in a left-of relation, not a below relation.
- Two self-symmetric cells are in a below relation, not a left-of relation.
Proof. (1) , so with , gives . Apply to , , which are distinct: if and only if , which holds. So is before in both orders.
(2) , so with , gives . Apply to , : if and only if , which is false. So and .
(3) Take , . Then reads . The two cells are in the same order in both sequences.
(4) For self-symmetric, reads . The two cells are in opposite orders.
Lemma 1 is what makes symmetry possible. Part 3 says that the two cells of a pair are never asked to be one above the other, so they can share one . Part 4 says that the self-symmetric cells, which all sit on the axis, are never asked to be side by side. Parts 1 and 2 say that the relations inside the group look the same in a mirror.
Lemma 2 (the count). Let have cells among . For each , exactly orders satisfy . So there are symmetric-feasible pairs.
Proof. Condition says that the order of the group cells in is the list of the mirrors of the group cells, taken in the reverse of their order in . This fixes one of the relative orders of in , and leaves the rest of free. Each relative order is taken by permutations.
The same argument shows that REPAIR, which keeps the slots of in and refills them in this forced order, returns a symmetric-feasible pair, and returns itself when already holds.
Lemma 3 (the merged vertical graph is acyclic). Let hold. Merge the two cells of each pair into one node, and draw an arc from the node of to the node of when is below . This graph has no cycle.
Proof. The below relation itself is a strict partial order: if is below and is below , then is before in and after in . Suppose the merged graph has a cycle. Write it as a closed walk of below relations below , below , ..., where is or its mirror. If at every step, transitivity gives below , which is false. So the walk changes to the mirror at least once. Join the runs between two changes by transitivity. This gives group cells with below and , indices mod .
Let for . If is below , then , and by Lemma 1 (2) is below , so . So . Also . Around the cycle, , which is false.
Theorem 4 (the coordinates). Lines L3 to L5 give each cell the least such that every below relation holds and the two cells of each pair have the same .
Proof. By Lemma 3, line L4 orders all nodes. The constraints for below , with one variable per node, form a system of difference constraints on a DAG. The longest-path values of line L5 satisfy it, and every solution is at least these values, by induction along the order.
Theorem 5 (the group alone). Let hold, and let every cell be in . Let be the least coordinates that keep the left-of relations (longest paths in the horizontal graph), and the least width. Then
keeps every left-of relation, fits in , and is symmetric about . So for a group alone, symmetry costs no width.
Proof. Let . As and , we have . If is left of , then by Lemma 1 (1) is left of , so , and so . So keeps the relations, and does too. The constraints are linear, so the mean keeps them and fits in . Finally , so the centers and add to , and a self-symmetric cell has the center .
Free cells. With cells outside , the mirror above breaks the relations between free cells and group cells, and Theorem 5 does not apply. Balasa and Lampaert prove that every symmetric-feasible pair still has a symmetric placement that keeps all the relations of the pair (Balasa and Lampaert 2000, the section on symmetric-feasible sequence pairs). This page does not repeat that proof. Line L7 solves the linear program of line L6, so it finds such a placement when one exists. In the tests it found one for every symmetric-feasible pair that was tried, and line L7 raises an error if it ever does not.
Theorem 6 (what SYM-PACK returns). If line L7 succeeds, the placement keeps every relation of the pair, is symmetric, and has the least width and the least height among all such placements. So its area is the least among the symmetric placements that keep the relations of the pair.
Proof. Every left-of relation and the symmetry equations are rows of the program of line L6, and bounds every right edge. The program minimizes , so the width is the least. The part is Theorem 4, and the symmetry of holds because each pair is one node. Two cells in a relation do not overlap, and every two cells are in a relation, so no two cells overlap. The and constraints share no variable, so the least width and the least height are reached together.
What is proved here: Lemmas 1 to 3 and Theorems 4 to 6, and the symmetric placement for a group with no free cells. What is cited: the existence of a symmetric placement when free cells are present. What is measured: the tests check the count of Lemma 2, Lemma 1 on all pairs of 4 cells, the placements of random instances, and, on two small instances, that the best area over all symmetric-feasible pairs equals the best area of a search over a half-unit grid.
Complexity
- The test and the repair. time with the position arrays.
- The search space. For each , exactly orders pass the test, so there are symmetric-feasible pairs among the pairs. With several groups of sizes , the conditions fix the relative orders of disjoint sets, and the count is .
- The packing. Lines L2 to L5 take time. The program of line L7 has variables and rows. Interior-point methods solve it in polynomial time. The exact simplex method of the code has no polynomial bound, but it is fast at the sizes of an analog placement.
These counts are proved. The time of a whole annealing run depends on the schedule, and there is no bound on the quality it reaches.
Properties
- Every visited placement is symmetric. A placer that applies REPAIR after each move never needs a penalty for broken symmetry.
- No loss of optimality for the relations. By Theorem 6 of the proof file, the packing is the least symmetric one for its pair. In the two exhaustive tests of the implementation, the best packing over all symmetric-feasible pairs equals the best symmetric placement found by a grid search. This is measured on small instances; it is not a theorem of this page.
- Symmetry without width cost for a group alone. For a group with no free cells, the least symmetric width equals the least width without symmetry.
- One axis per group. Different groups have their own axes, which the program can tie together if the circuit needs one axis for all.
Variants and improvements
- Several symmetric sets. The condition is applied to each group, and the program has one axis variable for each.
- A horizontal axis. Swap the roles of the left-of and below relations.
- The solution space. Balasa, Maruvada and Krishnamoorthy study how a placer explores the space of symmetric-feasible codes.
- Symmetry islands. The ASF-B*-tree keeps a group in a compact region with a tree whose every packing is symmetric by construction.
- Common centroid. Matched devices made of many unit cells use a common-centroid layout, which mirror symmetry about one axis does not give.
When to use it
Use it in an annealing placer for analog blocks with mirror symmetry, when the placer already uses sequence pairs. It is a good fit for a few symmetric sets among tens of cells. For tight proximity of a group, or for a group that must form one connected region, a tree that builds islands is a better fit.
Pitfalls
- Testing only the pairs. The condition must hold for every two distinct cells of the group, not only for the cells of each pair. A test that only checks partners passes pairs that have no symmetric placement. For two pairs and , the orders and keep each pair side by side, but put below and below . As each pair shares one , the pair would be both below and above the pair .
- Plain longest paths for . The least of each cell is in general not symmetric. Moving each cell to the mirror position after the longest path can create overlaps with free cells. The step must solve the symmetry equations and the relations together.
- Half units. The axis and the cell positions can be at half units, as for a self-symmetric cell of odd width with its center on an axis at a whole unit. Round to the manufacturing grid only after the whole group is placed, and round the two cells of a pair together.
- Cells of different size in a pair. The condition does not check sizes. The two cells of a pair must have the same width and height, or no mirror placement exists.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/symmetric-feasible-sequence-pair/. The authors are listed in prov/RFE075.jsonl.
"""Symmetric-feasible sequence pairs and a symmetric packing of them.
Cells are 0 .. n - 1 with widths w and heights h. A sequence pair is two
permutations gp (Gamma+) and gm (Gamma-) of the cells. One symmetric set with
a vertical axis is a dict sym: each cell of the group maps to its partner, and a
self-symmetric cell maps to itself. Cells not in sym are free.
Relations (as on the sequence-pair page): u is left of v if u is before v in
both sequences; u is below v if u is after v in gp and before v in gm.
"""
from fractions import Fraction
def positions(seq: list) -> dict:
return {c: i for i, c in enumerate(seq)}
def is_symmetric_feasible(gp: list, gm: list, sym: dict) -> bool:
"""Balasa and Lampaert's condition: for distinct x, y in the group,
pos+(x) < pos+(y) if and only if pos-(sym y) < pos-(sym x)."""
pp, pm = positions(gp), positions(gm)
g = list(sym)
return all((pp[x] < pp[y]) == (pm[sym[y]] < pm[sym[x]]) for x in g for y in g if x != y)
def repair(gp: list, gm: list, sym: dict) -> list:
"""Return a new gm that keeps the slots of the group cells and of the free
cells, and refills the group slots in the only order that the condition
allows: the mirrors of the group cells, in the reverse order of gp."""
forced = [sym[x] for x in reversed([c for c in gp if c in sym])]
it = iter(forced)
return [next(it) if c in sym else c for c in gm]
def _simplex_min(c: list, rows: list):
"""Minimize c.x subject to rows (a, sense, b) with sense in '<=', '=', '>=', and x >= 0.
Exact two-phase simplex in Fraction with Bland's rule. Returns (value, x) or None when
infeasible. The callers here always have a bounded objective."""
n, m = len(c), len(rows)
ns = sum(1 for _, sense, _ in rows if sense != "=")
N = n + ns + m
T, basis, s = [], [], n
for i, (a, sense, b) in enumerate(rows):
row = [Fraction(0)] * (N + 1)
for j in range(n):
row[j] = Fraction(a[j])
if sense != "=":
row[s] = Fraction(1 if sense == "<=" else -1)
s += 1
row[N] = Fraction(b)
if row[N] < 0:
row = [-v for v in row]
row[n + ns + i] = Fraction(1)
T.append(row)
basis.append(n + ns + i)
def pivot(r: int, col: int) -> None:
pv = T[r][col]
T[r] = [v / pv for v in T[r]]
for i in range(len(T)):
if i != r and T[i][col] != 0:
f = T[i][col]
T[i] = [a - f * b for a, b in zip(T[i], T[r])]
basis[r] = col
def run(cost: list, allowed: range) -> None:
while True:
enter = None
for j in allowed:
if j not in basis and cost[j] - sum(cost[basis[i]] * T[i][j] for i in range(len(T))) < 0:
enter = j
break
if enter is None:
return
best = None
for i in range(len(T)):
if T[i][enter] > 0:
ratio = T[i][N] / T[i][enter]
if best is None or ratio < best[0] or (ratio == best[0] and basis[i] < basis[best[1]]):
best = (ratio, i)
if best is None:
raise ArithmeticError("unbounded linear program")
pivot(best[1], enter)
run([0] * (n + ns) + [1] * m, range(N))
if sum(T[i][N] for i in range(len(T)) if basis[i] >= n + ns) != 0:
return None
for i in range(len(T) - 1, -1, -1): # drive the artificial variables out
if basis[i] >= n + ns:
j = next((j for j in range(n + ns) if T[i][j] != 0), None)
if j is None:
del T[i], basis[i] # a redundant row
else:
pivot(i, j)
run(list(c) + [0] * (N - n), range(n + ns))
x = [Fraction(0)] * n
for i, b in enumerate(basis):
if b < n:
x[b] = T[i][N]
return sum(Fraction(ci) * xi for ci, xi in zip(c, x)), x
def sym_pack(gp: list, gm: list, w: list, h: list, sym: dict):
"""A placement with the group mirrored about one vertical axis, that keeps
every relation of the sequence pair, with the least width and the least
height among such placements. Returns None if the pair is not
symmetric-feasible."""
n = len(gp)
if not is_symmetric_feasible(gp, gm, sym): # @line L1
return None
pp, pm = positions(gp), positions(gm)
left = [(u, v) for u in range(n) for v in range(n) if pp[u] < pp[v] and pm[u] < pm[v]] # @line L2
below = [(u, v) for u in range(n) for v in range(n) if pp[u] > pp[v] and pm[u] < pm[v]]
node = {u: min(u, sym.get(u, u)) for u in range(n)} # @line L3: a pair is one node
succ: dict = {node[u]: [] for u in range(n)}
indeg = {k: 0 for k in succ}
for u, v in below:
succ[node[u]].append((u, node[v]))
indeg[node[v]] += 1
order, stack = [], [k for k in succ if indeg[k] == 0] # @line L4: Kahn's order
while stack:
k = stack.pop()
order.append(k)
for _, t in succ[k]:
indeg[t] -= 1
if indeg[t] == 0:
stack.append(t)
assert len(order) == len(succ), "the merged vertical graph has a cycle"
ynode = {k: Fraction(0) for k in succ}
for k in order: # @line L5: longest paths
for u, t in succ[k]:
ynode[t] = max(ynode[t], ynode[k] + h[u])
y = [ynode[node[u]] for u in range(n)]
# x: variables x_0 .. x_{n-1}, X (the axis), W (the width); minimize W
nv = n + 2
X, W = n, n + 1
rows = []
def row(coef: dict, sense: str, b) -> None:
a = [0] * nv
for k, v in coef.items():
a[k] += v
rows.append((a, sense, b))
for u, v in left: # @line L6
row({v: 1, u: -1}, ">=", w[u])
for u in range(n):
row({W: 1, u: -1}, ">=", w[u])
for u, v in sym.items():
if u == v:
row({u: 2, X: -2}, "=", -w[u]) # center of u on the axis
elif u < v:
row({u: 1, v: 1, X: -2}, "=", -w[u]) # centers mirrored about the axis
res = _simplex_min([0] * n + [0, 1], rows) # @line L7
if res is None:
raise ArithmeticError("no symmetric x placement; this contradicts Balasa and Lampaert's theorem")
width, sol = res
x = sol[:n]
height = max((y[u] + h[u] for u in range(n)), default=Fraction(0))
return {"x": x, "y": y, "axis": sol[X], "width": width, "height": height} # @line L8
test_symmetric_feasible_sequence_pair.py 171 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/symmetric-feasible-sequence-pair/. The authors are listed in prov/RFE075.jsonl.
import itertools
import math
import random
from fractions import Fraction
from symmetric_feasible_sequence_pair import _simplex_min, is_symmetric_feasible, positions, repair, sym_pack
def check_placement(gp, gm, w, h, sym, p) -> None:
n = len(gp)
x, y, ax = p["x"], p["y"], p["axis"]
pp, pm = positions(gp), positions(gm)
for u in range(n):
assert x[u] >= 0 and y[u] >= 0
assert x[u] + w[u] <= p["width"] and y[u] + h[u] <= p["height"]
assert p["width"] == max(x[u] + w[u] for u in range(n))
for u in range(n):
for v in range(n):
if u == v:
continue
if pp[u] < pp[v] and pm[u] < pm[v]:
assert x[u] + w[u] <= x[v]
if pp[u] > pp[v] and pm[u] < pm[v]:
assert y[u] + h[u] <= y[v]
# no overlap, checked directly on the rectangles
assert x[u] + w[u] <= x[v] or x[v] + w[v] <= x[u] or y[u] + h[u] <= y[v] or y[v] + h[v] <= y[u]
for u, v in sym.items():
assert y[u] == y[v]
assert (x[u] + Fraction(w[u], 2)) + (x[v] + Fraction(w[v], 2)) == 2 * ax
def test_small_example() -> None:
# cells: 0 and 1 a pair (1 x 1), 2 self-symmetric (2 x 1), 3 free (1 x 2)
w, h, sym = [1, 1, 2, 1], [1, 1, 1, 2], {0: 1, 1: 0, 2: 2}
gp, gm = [3, 1, 0, 2], [3, 2, 1, 0]
assert is_symmetric_feasible(gp, gm, sym)
p = sym_pack(gp, gm, w, h, sym)
check_placement(gp, gm, w, h, sym, p)
assert (p["width"], p["height"], p["axis"]) == (3, 2, 2)
assert sym_pack(gp, [3, 2, 0, 1], w, h, sym) is None
def test_count_of_feasible_pairs() -> None:
for n, sym in ((3, {0: 1, 1: 0}), (3, {0: 0, 1: 1, 2: 2}), (4, {0: 1, 1: 0, 2: 3, 3: 2}), (4, {0: 1, 1: 0, 2: 2})):
perms = list(itertools.permutations(range(n)))
cnt = sum(1 for a in perms for b in perms if is_symmetric_feasible(list(a), list(b), sym))
assert cnt == math.factorial(n) ** 2 // math.factorial(len(sym))
def test_repair() -> None:
rng = random.Random(2000)
sym = {0: 1, 1: 0, 2: 2, 3: 4, 4: 3}
for _ in range(300):
gp, gm = list(range(7)), list(range(7))
rng.shuffle(gp)
rng.shuffle(gm)
gm2 = repair(gp, gm, sym)
assert is_symmetric_feasible(gp, gm2, sym)
assert [c for c in gm2 if c not in sym] == [c for c in gm if c not in sym]
assert repair(gp, gm2, sym) == gm2
def test_mirror_lemma_on_all_pairs() -> None:
sym = {0: 1, 1: 0, 2: 2, 3: 3}
perms = list(itertools.permutations(range(4)))
for a in perms:
for b in perms:
if not is_symmetric_feasible(list(a), list(b), sym):
continue
pp, pm = positions(a), positions(b)
for u in sym:
for v in sym:
if u == v:
continue
if pp[u] < pp[v] and pm[u] < pm[v]: # u left of v
assert pp[sym[v]] < pp[sym[u]] and pm[sym[v]] < pm[sym[u]]
if pp[u] > pp[v] and pm[u] < pm[v]: # u below v
assert pp[sym[u]] > pp[sym[v]] and pm[sym[u]] < pm[sym[v]]
assert (pp[0] < pp[1]) == (pm[0] < pm[1]) # a pair is side by side
assert (pp[2] < pp[3]) != (pm[2] < pm[3]) # self-symmetric cells are stacked
def brute_min_area(w, h, sym, free, xmax, ymax):
"""The least bounding-box area of a symmetric, overlap-free placement with x on a
half-unit grid and y on the unit grid, found by trying every grid position."""
halves = [Fraction(k, 2) for k in range(2 * xmax + 1)]
ys = list(range(ymax + 1))
pairs = [(u, v) for u, v in sym.items() if u < v]
selfs = [u for u, v in sym.items() if u == v]
best = None
n = len(w)
spots = list(itertools.product(halves, ys))
for ax in halves:
for choice in itertools.product(*([spots] * len(pairs) + [ys] * len(selfs) + [spots] * len(free))):
x, y = [None] * n, [None] * n
k = 0
for u, v in pairs:
x[u], y[u] = choice[k]
x[v], y[v] = 2 * ax - w[u] - x[u], y[u]
k += 1
for s in selfs:
x[s], y[s] = ax - Fraction(w[s], 2), choice[k]
k += 1
for f in free:
x[f], y[f] = choice[k]
k += 1
if min(x) < 0:
continue
ok = all(x[a] + w[a] <= x[b] or x[b] + w[b] <= x[a] or y[a] + h[a] <= y[b] or y[b] + h[b] <= y[a] for a in range(n) for b in range(a + 1, n))
if ok:
area = max(x[a] + w[a] for a in range(n)) * max(y[a] + h[a] for a in range(n))
best = area if best is None else min(best, area)
return best
def best_over_pairs(w, h, sym):
n = len(w)
perms = list(itertools.permutations(range(n)))
best = None
for a in perms:
for b in perms:
p = sym_pack(list(a), list(b), w, h, sym)
if p is None:
continue
check_placement(list(a), list(b), w, h, sym, p)
area = p["width"] * p["height"]
best = area if best is None else min(best, area)
return best
def test_exhaustive_against_grid_search() -> None:
# a pair 1 x 1, a self-symmetric cell 2 x 1 and a free cell 1 x 2
w, h, sym = [1, 1, 2, 1], [1, 1, 1, 2], {0: 1, 1: 0, 2: 2}
assert best_over_pairs(w, h, sym) == brute_min_area(w, h, sym, [3], 4, 3) == 6
# two pairs: 2 x 1 and 1 x 2
w, h, sym = [2, 2, 1, 1], [1, 1, 2, 2], {0: 1, 1: 0, 2: 3, 3: 2}
assert best_over_pairs(w, h, sym) == brute_min_area(w, h, sym, [], 4, 3)
def test_random_instances_always_pack() -> None:
rng = random.Random(7)
for _ in range(60):
n = rng.randint(4, 7)
w = [rng.randint(1, 4) for _ in range(n)]
h = [rng.randint(1, 4) for _ in range(n)]
cells = list(range(n))
rng.shuffle(cells)
sym = {}
for i in range(rng.randint(0, 2)):
a, b = cells.pop(), cells.pop()
w[b], h[b] = w[a], h[a]
sym[a], sym[b] = b, a
for i in range(rng.randint(0, min(2, len(cells)))):
s = cells.pop()
sym[s] = s
gp, gm = list(range(n)), list(range(n))
rng.shuffle(gp)
rng.shuffle(gm)
gm = repair(gp, gm, sym)
p = sym_pack(gp, gm, w, h, sym)
check_placement(gp, gm, w, h, sym, p)
def test_simplex_small() -> None:
# min x + y with x + 2y >= 4, 3x + y >= 6: optimum at (8/5, 6/5)
val, x = _simplex_min([1, 1], [([1, 2], ">=", 4), ([3, 1], ">=", 6)])
assert val == Fraction(14, 5) and x == [Fraction(8, 5), Fraction(6, 5)]
assert _simplex_min([1], [([1], "<=", -1)]) is None
History
Murata, Fujiyoshi, Nakatake and Kajitani gave the sequence pair in 1995. Balasa and Lampaert gave the symmetric-feasible condition, with the proof that every such pair has a symmetric placement and an annealing placer that keeps the condition, in IEEE Transactions on CAD in 2000. Balasa, Maruvada and Krishnamoorthy studied the search space in 2004. Later analog placers moved to trees, such as the ASF-B*-tree of Lin and Lin in 2007, which also keep a group in one region.
References
- Florin Balasa and Koen Lampaert, Symmetry within the sequence-pair representation in the context of placement for analog design, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 19(7), 721 to 731, 2000, the definition of a symmetric-feasible sequence pair, the theorem that such a pair has a symmetric placement, the size of the reduced search space, and the annealing placer
- F. Balasa, S. C. Maruvada and K. Krishnamoorthy, On the exploration of the solution space in analog placement with symmetry constraints, IEEE TCAD 23(2), 177 to 191, 2004, the exploration of the space of symmetric-feasible codes
- Hiroshi Murata, Kunihiro Fujiyoshi, Shigetoshi Nakatake and Yoji Kajitani, VLSI module placement based on rectangle-packing by the sequence-pair, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 15(12), 1518 to 1524, 1996, the sequence pair and its decoding by constraint graphs
- Georges G. E. Gielen and Rob A. Rutenbar, Computer-aided design of analog and mixed-signal integrated circuits, Proceedings of the IEEE 88(12), 1825 to 1854, 2000, the section on analog placement under symmetry constraints
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag RFE075 Edit this page History Report an error Markdown