Data structurecore
Liaison graph
Also called contact graph of an assembly, assembly connection graph.
An undirected graph with a node per part and an edge per contact or fastening, the input of most assembly sequence generators.
- Time
- O(n log n + K) worst
- Space
- Θ(n + m) extra
- Where
- K = the number of pairs of parts whose closed x intervals meet; m = the number of liaisons; n = the number of parts
- Model
- Word RAM
- Evidence
- Proof sketchCode in 1 languages
The liaison graph of an assembly has one node for each part and one edge, called a liaison, for each pair of parts that touch or that a fastener joins. Each liaison can carry data: the kind of joint, the contact normal, the contact area. Assembly sequence methods use it in three ways: a liaison is the unit of work that a sequence orders, a set of parts counts as a subassembly only if it is connected in the graph, and the liaisons that cross a split are the joints that the split must make or break. This page builds the graph from a model of axis-aligned boxes and gives the operations that the assembly planners call.
In plain words
Draw a dot for each part of a product. When two parts touch, or a screw or a weld holds them together, draw a line between their dots. That picture is the liaison graph.
The picture answers simple questions fast. Which parts touch this part? Do these four parts hold together as one piece, or do they fall into two piles? If I lift these parts off the rest, which joints do I break? A planner asks these questions thousands of times, so it is worth building the picture once.
To build it from a CAD model, do not test every pair of parts. Sort the parts from left to right, and compare each part only with the earlier parts that reach far enough to the right to touch it. Parts far apart are never compared.
The abstract type
An assembly is a set of parts . The liaison graph is an undirected graph with a label on each edge. On this page a part is a closed axis-aligned box , and the interiors of the boxes are pairwise disjoint. A contact liaison joins and when has positive area in a plane, that is, the two parts share a patch of a face. Its label is : the contact normal from to is with and a unit vector along the axis , and is the area of the patch. Boxes that touch only along an edge or at a corner do not give a liaison. A fastener liaison is added by hand, because a bolt or a weld is not in the geometry of the two parts.
The graph has no motion model and no hand model of its own. It is the same for every planner. The planners add them: the blocking graphs add the motions, and the AND/OR graph adds the two-handed hand model.
The operations are:
- : the graph of all contact liaisons.
- : add a fastener liaison.
- : the parts that share a liaison with .
- : true if the induced subgraph is connected. Most planners accept a set as a subassembly only if this holds.
- : the liaisons with one end in and one end outside, the joints made when is joined to the rest.
- : every connected nonempty set of parts, each once. Their number bounds the size of the AND/OR graph of all plans.
Representation
The code keeps, for each part , a bit mask of its neighbours, and a dictionary from the pair with to the label. A set of parts is a bit mask too, so the neighbourhood of a set (the parts outside with a neighbour in ) is the union of over , without . For a product of a few dozen parts, a mask fits in one or two machine words. For large products, adjacency lists with a hash set of edges give the same operations, with a breadth first search for IS-CONNECTED.
Operations
BUILD(b[1..n]) ▷ closed boxes with disjoint interiors- 1
order ← the parts sorted by lo_x; active ← empty list - 2
for each part i in order do - 3
remove from active every j with hi_x(b_j) < lo_x(b_i) - 4
for each j in active do c ← CONTACT(b_i, b_j) - 5
if c ≠ nil then add the liaison {i, j} with label c - 6
append i to active CONTACT(a, b) ▷ w_m: overlap width of a and b on axis m- 7
for each axis k do - 8
if hi_k(a) = lo_k(b) then s ← +1 else if hi_k(b) = lo_k(a) then s ← -1 else skip k - 9
if w_m > 0 for both other axes m then return (k, s, the product of the two w_m) - 10
return nil IS-CONNECTED(S) ▷ S: a bit mask of parts- 11
R ← {the lowest part of S}; repeat R' ← R; R ← R ∪ (N(R) ∩ S) until R = R' - 12
return R = S CUT(S)- 13
return the liaisons {i, j} with i in S and j not in S GROW(S, B) ▷ S connected, B: banned parts- 14
output S - 15
C ← N(S) \ B - 16
for each w in C, in increasing order do - 17
GROW(S ∪ {w}, B); B ← B ∪ {w} CONNECTED-SUBSETS()- 18
B ← ∅ - 19
for each part v in increasing order do - 20
GROW({v}, B); B ← B ∪ {v}
Build. This is the sort step of a sweep along , as in the rectangle intersection sweep. Two parts in contact have closed intervals that meet. So when part comes, the only earlier parts that can touch it are the ones whose interval has not ended before . Line L3 drops the others, and they can never come back, because later parts start even further right. Each pair that survives gets the exact test CONTACT. With integer or rational coordinates, the test is exact.
Contact. Disjoint interiors force at least one axis with overlap width at most 0. The patch has positive area exactly when one axis has width 0, where one box ends and the other starts, and the two other widths are positive.
Connected subsets. GROW never lists a set twice: the first branch that takes candidate covers every larger set that contains , so the later branches ban . A set is listed by the call for its lowest part.
Example
Take a frame of five boxes, with corners and :
| part | name | corners |
|---|---|---|
| 0 | base plate | , |
| 1 | left post | , |
| 2 | right post | , |
| 3 | block | , |
| 4 | top plate | , |
The posts and the block stand on the base plate. The block sits between the posts, and the top plate rests on the posts, with an empty gap of height 1 above the block.
BUILD sorts by and gets the order . Part 0 finds an empty list. Part 1 is compared with 0. Part 4 is compared with 0 and 1. Part 3 is compared with 0, 1 and 4. When part 2 comes, with , line L3 drops part 1, whose interval ends at , and part 2 is compared with 0, 4 and 3. That is 9 calls of CONTACT, out of the 10 pairs. The pair is never tested. Seven calls find a contact:
| liaison | axis | sign | area |
|---|---|---|---|
| 2 | |||
| 2 | |||
| 4 | |||
| 2 | |||
| 2 | |||
| 2 | |||
| 2 |
For the normal from part 2 to part 3 points along , because the block lies to the left of the right post. The pairs and do not touch: the top plate is 2 above the base and 1 above the block.
CUT() gives , and : inserting the block makes three joints at once. IS-CONNECTED is false for the three pairs without a liaison, , and , and true for every set of four parts, because no single part holds the frame together. CONNECTED-SUBSETS lists sets: 5 single parts, 7 pairs, 9 triples, 5 sets of four and the whole frame. Of the nonempty sets, only the three pairs above and the triple are not connected.
Correctness
CONTACT is correct because the intersection of two boxes is a box whose sides are the three overlap widths, so it is a planar patch of positive area exactly when one width is 0 and the two others are positive. The sweep tests every pair in contact: such a pair has meeting intervals, and since the parts come in order of , the earlier part is still in the active list when the later one comes. IS-CONNECTED grows the component of one part inside . GROW outputs each connected set that contains its first argument and avoids the banned set exactly once, by induction on the number of free parts: a larger set is produced only in the branch of the first candidate it contains. The full proofs are in the correctness proof.
Proof: The sweep finds every contact liaison, and GROW lists every connected subassembly oncefull
We use the pseudocode of the page. The parts are closed axis-aligned boxes whose interiors are pairwise disjoint. For a box and an axis , write for its interval on that axis. For two boxes and , the overlap width on axis is .
Lemma 1 (contact test). Let and be closed boxes with disjoint interiors. The set has positive area in a plane exactly when there is one axis with or , and for the two other axes . In that case lies in the plane normal to , its area is the product of the two widths , and the outward normal of on it is in the first case and in the second. CONTACT on line L4 returns exactly this.
Proof. The intersection of two boxes is the product of the three intervals of length . The interiors meet exactly when on all three axes, so by the hypothesis some . If some , the intersection is empty. If two widths are 0, the intersection lies in a line and has no area. So has positive area in a plane exactly when one width is 0 and the two others are positive. A width of 0 on axis , with for both boxes, means that one interval ends where the other starts, which is or , and only one of the two can hold. In the first case lies on the side of where the coordinate grows, so the outward normal of on the patch is . The patch is a rectangle with sides for the two other axes.
Lemma 2 (the sweep sees every contact pair). Lines L1 to L6 call CONTACT on every pair for which CONTACT can return a contact.
Proof. If and are in contact, their intersection is not empty, so their closed intervals meet: and . Say that comes before in the order of line L1, so . Line L6 puts in the active list when is processed. Line L3 removes only at a step with . Every step from up to and including has , because the order is sorted. So is still active at step , and line L4 tests the pair.
Theorem 1 (BUILD). BUILD returns the graph whose edges are exactly the pairs of parts that share a face patch of positive area, each labelled with its axis, the sign of the normal from the smaller index to the larger, and the area.
Proof. Line L4 calls CONTACT only on pairs of distinct parts, each pair at most once, because is active only for the steps after its own. By Lemma 1, an edge is added only for a real contact, with the stated label. By Lemma 2, no contact is missed.
Lemma 3 (IS-CONNECTED). IS-CONNECTED() returns true exactly when is not empty and the subgraph induced by is connected. It does at most rounds.
Proof. Let be the lowest part of . After round , the set is the set of parts of that a path inside of at most edges joins to : this holds for , and line L11 adds exactly the parts of one edge away from . The loop stops when a round adds nothing, so is then closed under steps inside , and is the component of in the induced subgraph. The answer is true exactly when this component is all of . Each round that goes on adds a part, so there are at most rounds.
Lemma 4 (one call of GROW). Let be connected, let be a set disjoint from , and call a set reachable from when is connected, and . The call GROW(, ) outputs every reachable set exactly once, and nothing else.
Proof. By induction on the number of parts outside . Line L14 outputs , which is reachable. Let be the candidates of line L15, which are the parts outside and with a neighbour in . The call for on line L17 has the first set , which is connected because has a neighbour in , and the banned set , which is disjoint from . It has one more part in its first set, so by induction it outputs exactly the sets reachable from , each once.
Take a reachable . A path inside joins a part of to , so some part of has a neighbour in . That part is not in , so it is a candidate. Let be the first candidate in . Then is reachable from , and from no with : if then , and if then . So is output exactly once, in the call for . The set itself is output only on line L14, because every set that a child call outputs contains a candidate. Every output set is reachable from , because a set reachable from is reachable from .
Theorem 2 (CONNECTED-SUBSETS). Lines L18 to L20 output every connected nonempty set of parts exactly once.
Proof. The loop calls GROW(, ) for each part . By Lemma 4 this outputs exactly the connected sets whose lowest part is . Each connected nonempty set has one lowest part.
Termination and cost. The sweep makes steps over a list of at most parts. In GROW, every call outputs one set, and by Theorem 2 there are exactly calls in total, where is the number of connected sets. One call does word operations on bit masks to form its candidates on line L15, plus constant work for each child call. So the enumeration costs word operations when is at most the word length.
Complexity
| operation | worst-case time |
|---|---|
| BUILD | , the pairs of parts whose closed intervals meet |
| ADD | expected (dictionary) |
| NEIGHBOURS() | word operations to scan the mask, with lists |
| IS-CONNECTED() | $O( |
| CUT() | |
| CONNECTED-SUBSETS | word operations, the number of connected sets |
Here is the word length, and the mask bounds assume . Space is . The sweep does calls of CONTACT, and . Both can be : lay long bars along side by side, and long bars along on top of them, and every bar of the lower layer touches every bar of the upper layer, so . With an interval tree on the intervals of the active parts, the sweep can skip pairs whose intervals do not meet, but it still pays for each liaison it reports.
can be small or large. A chain of parts has connected sets, a star with one central part has , and a product where every part touches every other has . The frame above has 27 of 31.
Variants
- Contact types. Real liaison graphs label each liaison with its kind: plane contact, cylindrical fit, thread, snap fit, weld, glue. A cylindrical fit allows motion only along its axis, and the planners turn this into motion constraints.
- Contact normals for planning. The normals on the labels are the raw data of the infinitesimal blocking graph: a part with a plane contact of normal against another part cannot move along any direction with .
- Liaison diagram with numbered liaisons. The question methods of Bourjault and of De Fazio and Whitney number the liaisons and describe a state of the assembly by the set of liaisons made. A state is then a set of edges, not a set of parts.
- Graph of connections. Homem de Mello and Sanderson describe an assembly by a relational model and its graph of connections, which is the same graph with contacts and attachments as two kinds of edge.
- Polyhedral parts. For general solids the contact test is a face to face test on the boundary representations, with a tolerance. The sweep stays the same, with bounding boxes in place of the parts.
When to use it
Use the liaison graph as the first structure of any assembly planner. It decides which subsets are physical subassemblies, it is the vocabulary of the question methods, and its connected sets index the nodes of the AND/OR graph. It is also the base of design reviews that count joints, such as design for assembly. It is not a model of motion: two parts can be free of contact and still block each other, as the top plate blocks the block in the example. For motion, build the blocking graphs.
Pitfalls
- Contact is not blocking. The top plate and the block do not touch, yet the plate stops the block from moving up. A planner that uses only liaisons to test motions accepts wrong sequences.
- Edge contacts. Two boxes that share only an edge have no liaison here, but under an infinitesimal motion along a diagonal they still collide. The blocking tests must use the geometry, not the liaison list.
- Tolerances. Real CAD faces that should touch often have a gap or an overlap of . With floating point coordinates, a contact test needs a tolerance and a rule for what it means. The code here uses exact coordinates, so the question does not come up.
- Fasteners are not in the geometry. When the CAD model leaves out a bolt, a rivet or a weld, nothing in the geometry joins the parts it holds. Add such liaisons by hand.
- Parts versus liaisons. A state can be a set of parts or a set of liaisons. When all liaisons inside a set of parts must be made together (the usual monotone model), the two are the same thing for a connected set of two or more parts. When a part can be placed with one liaison made and another left open, they differ.
- Exponential lists. CONNECTED-SUBSETS is output sensitive, not polynomial. A product with one central part, such as a base plate that holds all others, has more than connected sets.
Implementations
The Python module builds the graph of a list of boxes with integer or Fraction corners by the sweep, keeps neighbours as bit masks, and gives NEIGHBOURS, CUT, IS-CONNECTED and CONNECTED-SUBSETS by the GROW scheme. A shared helper holds the box predicates and a generator of random assemblies. The tests compare the sweep with the pairwise test on every pair for random assemblies of up to 30 boxes, compare each contact area and normal with a count of unit faces on a voxel grid, compare the connected sets and IS-CONNECTED with a check of all subsets for up to 9 parts, and check the counts for chains, stars and complete graphs.
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
# Shared helper of the ma4 cad pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Axis-aligned boxes for the assembly planning pages.
A box is a tuple (x0, y0, z0, x1, y1, z1) with x0 < x1, y0 < y1 and z0 < z1.
Coordinates are int or Fraction, so every test here is exact. A part is a
closed box, and two parts of an assembly may touch but their interiors must
be disjoint.
"""
from fractions import Fraction
AXES6 = ((1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1))
AXIS_NAMES = {
(1, 0, 0): "+x", (-1, 0, 0): "-x",
(0, 1, 0): "+y", (0, -1, 0): "-y",
(0, 0, 1): "+z", (0, 0, -1): "-z",
}
def check_box(b):
if len(b) != 6 or not all(b[k] < b[k + 3] for k in range(3)):
raise ValueError("a box is (x0, y0, z0, x1, y1, z1) with x0 < x1, y0 < y1, z0 < z1")
def interiors_overlap(a, b):
"""True if the open boxes a and b meet, that is, the parts collide."""
return all(a[k] < b[k + 3] and b[k] < a[k + 3] for k in range(3))
def is_valid_assembly(boxes):
for b in boxes:
check_box(b)
n = len(boxes)
return all(not interiors_overlap(boxes[i], boxes[j])
for i in range(n) for j in range(i + 1, n))
def face_contact(a, b):
"""Return (k, s, area) if a and b share a planar patch of positive area.
The contact normal from a to b is s times the unit vector e_k. Boxes that
touch only along an edge or at a corner give None.
"""
for k in range(3):
if a[k + 3] == b[k]:
s = 1
elif b[k + 3] == a[k]:
s = -1
else:
continue
area = 1
for m in range(3):
if m == k:
continue
w = min(a[m + 3], b[m + 3]) - max(a[m], b[m])
if w <= 0:
area = 0
break
area *= w
if area > 0:
return (k, s, area)
return None
def translate(b, d, t):
"""The box b moved by t times the vector d."""
return tuple(b[k] + t * d[k % 3] for k in range(6))
def blocks(a, b, d):
"""True if box b blocks box a when a translates to infinity along d.
d is one of AXES6. This is the extended translation model: a moves by
t d for all t > 0, and b blocks it if a + t d meets the interior of b
for some t > 0.
"""
k = 0 if d[0] else (1 if d[1] else 2)
for m in range(3):
if m != k and not (a[m] < b[m + 3] and b[m] < a[m + 3]):
return False
if d[k] > 0:
return b[k] >= a[k + 3]
return b[k + 3] <= a[k]
def free_by_sampling(movers, others, d):
"""Reference test: do the boxes movers leave along d without a collision?
Only for integer corners. Each collision of two boxes happens for t in an
open interval with integer ends, so the half integers t = 1/2, 1, 3/2, ...
up to the size of the scene meet every such interval.
"""
span = 0
for b in list(movers) + list(others):
span = max(span, max(abs(c) for c in b))
for step in range(1, 4 * span + 3):
t = Fraction(step, 2)
for a in movers:
moved = translate(a, d, t)
if any(interiors_overlap(moved, b) for b in others):
return False
return True
def members(mask):
"""The indices of the set bits of mask, in increasing order."""
out = []
i = 0
while mask:
if mask & 1:
out.append(i)
mask >>= 1
i += 1
return out
def random_boxes(rng, n, size=4, max_side=2, connected=True, tries=400):
"""n boxes with integer corners in [0, size]^3 and disjoint interiors.
With connected=True, each new box shares a face patch with an earlier
box, so the contact graph is connected. The result depends only on rng.
"""
while True:
boxes = []
for _ in range(tries):
lo = []
hi = []
for _k in range(3):
side = rng.randint(1, max_side)
x0 = rng.randint(0, size - side)
lo.append(x0)
hi.append(x0 + side)
b = tuple(lo + hi)
if any(interiors_overlap(b, c) for c in boxes):
continue
if connected and boxes and not any(face_contact(b, c) for c in boxes):
continue
boxes.append(b)
if len(boxes) == n:
return boxes
liaison_graph.py 123 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/liaison-graph/. The authors are listed in prov/RHWBG9.jsonl.
"""The liaison graph of an assembly of axis-aligned boxes.
A node is a part. A liaison joins two parts that share a face patch of
positive area (a contact), or two parts that the designer joins on purpose
(a fastener). A set of parts is stored as a bit mask.
"""
def contact(a, b):
"""Return (k, s, area) if boxes a and b share a planar patch of positive area.
The boxes are (x0, y0, z0, x1, y1, z1) with disjoint interiors. The
contact normal from a to b is s times e_k.
"""
for k in range(3): # @line L7
if a[k + 3] == b[k]: # @line L8
s = 1
elif b[k + 3] == a[k]:
s = -1
else:
continue
area = 1
for m in range(3): # @line L9
if m == k:
continue
w = min(a[m + 3], b[m + 3]) - max(a[m], b[m])
if w <= 0:
area = 0
break
area *= w
if area > 0:
return (k, s, area)
return None # @line L10
class LiaisonGraph:
def __init__(self, n):
self.n = n
self.adj = [0] * n # adj[i]: bit mask of the neighbours of i
self.label = {} # (i, j) with i < j -> data of the liaison
def add_liaison(self, i, j, data):
if i == j:
raise ValueError("a liaison joins two different parts")
if i > j:
i, j = j, i
self.adj[i] |= 1 << j
self.adj[j] |= 1 << i
self.label[(i, j)] = data
def neighbours(self, i):
return [j for j in range(self.n) if self.adj[i] >> j & 1]
def liaisons(self):
return sorted(self.label)
def neighbourhood(self, mask):
"""N(S): the parts outside mask that share a liaison with a part of mask."""
out = 0
m = mask
while m:
low = m & -m
out |= self.adj[low.bit_length() - 1]
m ^= low
return out & ~mask
def cut(self, mask):
"""The liaisons with exactly one end in mask."""
return [(i, j) for (i, j) in self.liaisons()
if (mask >> i & 1) != (mask >> j & 1)] # @line L13
def is_connected(self, mask):
"""True if mask is nonempty and its parts form one connected piece."""
if mask == 0:
return False
reach = mask & -mask # @line L11
while True:
grow = (reach | self.neighbourhood(reach)) & mask
if grow == reach:
return reach == mask # @line L12
reach = grow
def connected_subsets(self, within=None):
"""Each connected subset of within (default: all parts) once."""
full = (1 << self.n) - 1 if within is None else within
out = []
def grow(s, banned):
out.append(s) # @line L14
cand = self.neighbourhood(s) & full & ~banned # @line L15
while cand: # @line L16
w = cand & -cand
grow(s | w, banned) # @line L17
banned |= w
cand ^= w
banned = ~full # @line L18
m = full
while m: # @line L19
v = m & -m
grow(v, banned) # @line L20
banned |= v
m ^= v
return out
def build(boxes):
"""The contact liaisons of a list of boxes, found by a sweep along x."""
g = LiaisonGraph(len(boxes))
order = sorted(range(len(boxes)), key=lambda i: boxes[i][0]) # @line L1
active = []
for i in order: # @line L2
x0 = boxes[i][0]
active = [j for j in active if boxes[j][3] >= x0] # @line L3
for j in active: # @line L4
a, b = (j, i) if j < i else (i, j)
c = contact(boxes[a], boxes[b])
if c is not None: # @line L5
g.add_liaison(a, b, ("contact",) + c)
active.append(i) # @line L6
return g
test_liaison_graph.py 159 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/liaison-graph/. The authors are listed in prov/RHWBG9.jsonl.
import random
from fractions import Fraction
from assembly_boxes import face_contact, random_boxes, is_valid_assembly
from liaison_graph import LiaisonGraph, build
# ---- independent references ----
def all_pairs(boxes):
"""The pairwise test on every pair, with no sweep."""
out = {}
for i in range(len(boxes)):
for j in range(i + 1, len(boxes)):
c = face_contact(boxes[i], boxes[j])
if c is not None:
out[(i, j)] = ("contact",) + c
return out
def voxel_faces(boxes, size):
"""Count unit faces between different boxes on a voxel grid."""
owner = {}
for idx, b in enumerate(boxes):
for x in range(b[0], b[3]):
for y in range(b[1], b[4]):
for z in range(b[2], b[5]):
owner[(x, y, z)] = idx
out = {}
for (x, y, z), a in owner.items():
for k in range(3):
q = [x, y, z]
q[k] += 1
b = owner.get(tuple(q))
if b is None or b == a:
continue
i, j, s = (a, b, 1) if a < b else (b, a, -1)
key = (i, j)
prev = out.get(key, ("contact", k, s, 0))
assert prev[1] == k and prev[2] == s
out[key] = ("contact", k, s, prev[3] + 1)
return out
def connected_by_bfs(n, pairs, mask):
parts = [i for i in range(n) if mask >> i & 1]
if not parts:
return False
seen = {parts[0]}
stack = [parts[0]]
while stack:
u = stack.pop()
for (i, j) in pairs:
for a, b in ((i, j), (j, i)):
if a == u and mask >> b & 1 and b not in seen:
seen.add(b)
stack.append(b)
return len(seen) == len(parts)
EXAMPLE = [
(0, 0, 0, 4, 2, 1), # 0 base plate
(0, 0, 1, 1, 2, 3), # 1 left post
(3, 0, 1, 4, 2, 3), # 2 right post
(1, 0, 1, 3, 2, 2), # 3 block
(0, 0, 3, 4, 2, 4), # 4 top plate
]
# ---- tests ----
def test_example():
g = build(EXAMPLE)
assert g.liaisons() == [(0, 1), (0, 2), (0, 3), (1, 3), (1, 4), (2, 3), (2, 4)]
assert g.label[(0, 3)] == ("contact", 2, 1, 4)
assert g.label[(1, 3)] == ("contact", 0, 1, 2)
assert g.neighbours(3) == [0, 1, 2]
assert g.cut(0b01000) == [(0, 3), (1, 3), (2, 3)]
assert g.is_connected(0b11110)
assert not g.is_connected(0b11000)
assert len(g.connected_subsets()) == 27
assert g.label[(2, 3)] == ("contact", 0, -1, 2)
def test_sweep_matches_all_pairs():
rng = random.Random(1)
for trial in range(300):
n = rng.randint(1, 30)
boxes = random_boxes(rng, n, size=8, max_side=3, connected=trial % 2 == 0)
assert is_valid_assembly(boxes)
g = build(boxes)
assert g.label == all_pairs(boxes)
def test_contacts_match_voxel_faces():
rng = random.Random(2)
for _ in range(200):
n = rng.randint(2, 12)
boxes = random_boxes(rng, n, size=5, max_side=3, connected=False)
assert build(boxes).label == voxel_faces(boxes, 5)
def test_edge_and_corner_touch_are_not_liaisons():
a = (0, 0, 0, 1, 1, 1)
edge = (1, 1, 0, 2, 2, 1)
corner = (1, 1, 1, 2, 2, 2)
face = (1, 0, 0, 2, 1, 1)
g = build([a, edge, corner, face])
assert (0, 1) not in g.label and (0, 2) not in g.label
assert g.label[(0, 3)] == ("contact", 0, 1, 1)
def test_fraction_coordinates():
h = Fraction(1, 2)
boxes = [(0, 0, 0, h, 1, 1), (h, Fraction(1, 3), 0, 1, 1, 1)]
g = build(boxes)
assert g.label[(0, 1)] == ("contact", 0, 1, Fraction(2, 3))
def test_connected_subsets_against_all_subsets():
rng = random.Random(3)
for _ in range(150):
n = rng.randint(1, 9)
boxes = random_boxes(rng, n, size=5, max_side=2, connected=rng.random() < 0.7)
g = build(boxes)
pairs = g.liaisons()
brute = sorted(m for m in range(1, 1 << n) if connected_by_bfs(n, pairs, m))
got = g.connected_subsets()
assert len(got) == len(set(got))
assert sorted(got) == brute
for m in range(1 << n):
assert g.is_connected(m) == connected_by_bfs(n, pairs, m)
def test_counts_on_simple_graphs():
for n in range(1, 9):
chain = LiaisonGraph(n)
for i in range(n - 1):
chain.add_liaison(i, i + 1, ("fastener",))
assert len(chain.connected_subsets()) == n * (n + 1) // 2
star = LiaisonGraph(n)
for i in range(1, n):
star.add_liaison(0, i, ("fastener",))
assert len(star.connected_subsets()) == 2 ** (n - 1) + n - 1
full = LiaisonGraph(n)
for i in range(n):
for j in range(i + 1, n):
full.add_liaison(i, j, ("fastener",))
assert len(full.connected_subsets()) == 2 ** n - 1
def test_fastener_liaison():
g = build([(0, 0, 0, 1, 1, 1), (2, 0, 0, 3, 1, 1)])
assert g.liaisons() == []
g.add_liaison(1, 0, ("fastener", "bolt"))
assert g.liaisons() == [(0, 1)] and g.is_connected(0b11)
History
Bourjault introduced the graph of liaisons in his 1984 thesis at Besançon as the base of an automatic method for generating assembly sequences: the method asks the engineer questions about the liaisons. De Fazio and Whitney (1987) kept the liaison diagram and cut down the number of questions. Homem de Mello and Sanderson (1986 and 1990) built their AND/OR graph of plans on a relational model whose graph of connections is the same object. Whitney's book (2004) uses the liaison diagram as the start of assembly sequence analysis.
References
- Alain Bourjault, Contribution à une approche méthodologique de l'assemblage automatisé: élaboration automatique des séquences opératoires, Thèse d'État, Université de Franche-Comté, Besançon, 1984, the graph of liaisons of a product and the questions asked on its liaisons
- Thomas L. De Fazio and Daniel E. Whitney, Simplified generation of all mechanical assembly sequences, IEEE Journal of Robotics and Automation 3(6), 640 to 658 (1987), the liaison diagram of a product and the numbering of its liaisons
- Luiz S. Homem de Mello and Arthur C. Sanderson, AND/OR graph representation of assembly plans, IEEE Transactions on Robotics and Automation 6(2), 188 to 199 (1990), the relational model of an assembly and its graph of connections
- Daniel E. Whitney, Mechanical Assemblies: Their Design, Manufacture, and Role in Product Development, Oxford University Press, 2004, the chapter on assembly sequence analysis (the liaison diagram)
Where this leads
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 | W4 complete |
|
Tag RHWBG9 Edit this page History Report an error Markdown