Algorithmadvanced
Pebble game for rigidity
Also called Jacobs-Hendrickson pebble game.
Jacobs and Hendrickson's O(n^2) algorithm that tests Laman's condition by moving two pebbles per vertex along edges, and finds rigid components and redundant edges.
- Time
- O(n m) worstΘ(n + m) best
- Space
- Θ(n + m) extra
- Where
- m = the number of edges; n = the number of vertices
- Model
- Word RAM
- Properties
- deterministicexactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Donald J. Jacobs, Bruce Hendrickson, 1997
The pebble game of Jacobs and Hendrickson decides the Laman counts of a graph, and so generic rigidity in the plane, without any coordinates and without looking at the exponentially many vertex subsets. Each vertex holds two pebbles, and an edge is accepted when four pebbles can be brought to its two ends by moving pebbles back along accepted edges. The accepted edges form a largest set of independent bars, the rejected edges are redundant, and a second pass finds the rigid components. On a graph with vertices and edges it takes time, and for the Laman test of a graph with edges.
In plain words
Give every joint of a structure two tokens. A token stands for one way in which the joint can still move. When a new rod arrives between two joints, it can only take away a way of moving if the two joints, together, still have four free tokens: three of the four are the ways the pair can move as a whole, and only the fourth can be used up. If they do, one token is put on the rod. If they do not, the rod adds nothing new, and it is redundant.
The tokens can be moved. A joint can take a token from a neighbor if it hands its own token to the rod between them in return. So the search for four tokens is a search along the rods. In the end, the rods that got a token are the useful ones.
The problem
The input is a graph with and a list of edges with , in a fixed order. A repeated edge is allowed. The outputs are:
- for each edge, whether it is independent of the earlier accepted edges or redundant, where a set of edges is independent when every set of vertices spans at most edges of ;
- the rank, the number of accepted edges, and from it the answers to "is generically rigid in the plane" (rank ) and "is a Laman graph" ( and every edge accepted);
- the rigid components: the maximal vertex sets with whose induced subgraph is generically rigid in the plane. Each edge lies in exactly one of them.
By Laman's theorem, the independent sets are exactly the edge sets whose rows in the rigidity matrix are independent at a generic placement, so they are the independent sets of a matroid, and the accepted edges are what the matroid greedy algorithm keeps.
The algorithm
The state is a directed graph on , one arc for each accepted edge, and a count of free pebbles at each vertex. An arc means that a pebble of covers the edge , so at all times.
PEBBLE-GAME(n, E)- 1
for each vertex v do peb[v] ← 2; D ← the directed graph on V with no arcs - 2
for each edge uv of E, in the given order do - 3
for (x, y) in ((u, v), (v, u)) do - 4
while peb[x] < 2 and FIND-PEBBLE(x, y) succeeds do nothing more - 5
if peb[u] + peb[v] = 4 then - 6
peb[u] ← peb[u] - 1; add the arc u → v to D; mark uv independent - 7
else mark uv redundant - 8
return the marks and D FIND-PEBBLE(x, y)- 9
search D by depth-first search from x for a vertex w ∉ {x, y} with peb[w] > 0 - 10
if there is no such w then return false - 11
reverse every arc of the path from x to w; peb[w] ← peb[w] - 1; peb[x] ← peb[x] + 1 - 12
return true RIGID-COMPONENTS(n, E)- 13
run PEBBLE-GAME(n, E); C ← an empty list - 14
for each edge uv of E such that no set in C contains both u and v do - 15
gather pebbles on u and v as in lines L3 and L4, but stop at 3 in total - 16
X ← the vertices from which D reaches some w ∉ {u, v} with peb[w] > 0 - 17
add V ∖ X to C - 18
return C
The search in line L9 may pass through but must not take a pebble from it, because needs its pebbles too. Reversing a path in line L11 moves one pebble from to : every inner vertex of the path loses one out-arc and gains one, so its count stays. Every out-degree is at most 2, so the search is cheap.
Example
Take and the edges in the order : a on , a triangle that shares vertex 3 with it, and the edge . The column "moves" lists the successful searches, written when takes a pebble from .
| step | edge | moves | result | free pebbles on after |
|---|---|---|---|---|
| 1 | none | accept, arc | 1, 2, 2, 2, 2, 2 | |
| 2 | accept, arc | 1, 1, 2, 2, 2, 2 | ||
| 3 | accept, arc | 0, 1, 2, 2, 2, 2 | ||
| 4 | accept, arc | 0, 1, 1, 2, 2, 2 | ||
| 5 | accept, arc | 0, 0, 1, 2, 2, 2 | ||
| 6 | , then the search from 0 fails | redundant: only 3 pebbles | 1, 0, 0, 2, 2, 2 | |
| 7 | none | accept, arc | 1, 0, 0, 1, 2, 2 | |
| 8 | none | accept, arc | 1, 0, 0, 1, 1, 2 | |
| 9 | accept, arc | 1, 0, 0, 1, 0, 2 | ||
| 10 | , | accept, arc | 0, 0, 1, 0, 0, 2 |
In step 6, after , the vertices that 0 can reach are , and the only free pebbles among them are the one on 0 and the two on 3. So the set already spans accepted edges, and would be a sixth. After step 9 the rank is 8 , and RIGID-COMPONENTS returns and : two rigid bodies joined at a hinge. Step 10 adds the ninth independent edge, the rank becomes , and the whole graph is one rigid component. At the end free pebbles remain, the three motions of the plane.
Correctness
The proof shows the following.
- Invariant. At every step and . So for every vertex set , , where is the set of accepted edges, the number of them inside , and the number of arcs that leave .
- Accepted edges are independent. Four pebbles on and mean for every , so adding keeps the count .
- Rejected edges are dependent. If fewer than four pebbles can be gathered, the vertices reachable from the failed search form a set with no arc leaving it and no free pebble except on and . The identity gives , so would break the count on .
- Greedy basis. Hence an edge is accepted exactly when it is independent of the edges accepted before it, which is the greedy algorithm in the planar rigidity matroid. The number of accepted edges is the rank.
- Components. After three pebbles are gathered on an edge , the vertices that cannot reach any other free pebble form a closed set with exactly 3 free pebbles, so it spans accepted edges and is rigid, and the largest rigid set that contains and has the same two properties, so the two sets are equal.
Proof: The pebble game accepts exactly the edges that are independent of the earlier accepted edges, finds the rigid components, and runs in O(nm) timefull
Let have vertices and a list of edges with ; repeated edges are allowed. For a set of edges and , let be the number of edges of with both ends in . Call sparse if for every with . By Laman's theorem, the sparse sets are the independent sets of the generic rigidity matroid of the plane, and a vertex set with is rigid when is generically rigid, which means that , the edges of inside , has rank in this matroid.
During the game, is the set of accepted edges and is its orientation. For let , and let be the number of arcs of from to . Call closed if . Line numbers refer to the pseudocode on the main page.
Lemma 1 (invariant). At every step, and for every vertex . Hence , and for every ,
Proof. Line L1 sets with no arcs. Consider a move in line L11 along the path , . After the reversal, has one out-arc less and one pebble more. Each inner vertex loses the arc and gains the arc , and its count stays. The vertex gains one out-arc and loses one pebble, and before, so it stays at least 0. Line L6 runs only when , so ; it takes one pebble from and adds one out-arc at . So the invariant holds. Summing it over gives , and each arc with its tail in either has its head in , which gives , or leaves , which gives .
Moves only reverse arcs, so they never change as a set of edges.
Lemma 2 (accepted edges are independent). is sparse at every step.
Proof. At the start is empty. Moves do not change . When line L6 accepts , then just before, so for every that contains and , gives . After the edge is added, . Sets that do not contain both ends do not change.
In particular, , so has at most arcs.
Lemma 3 (pebbles of the partner stay). During the search from with partner (line L9), does not change.
Proof. The search never takes a pebble from . If the path passes through , then is an inner vertex, and its count stays, as in Lemma 1.
So in lines L3 and L4, each successful search adds one pebble to , and the searches for the second end do not lower the count of the first end. Each loop of line L4 ends when or when a search fails.
Lemma 4 (a failed search gives a closed set). Suppose that at some state the search from with partner fails, and let be the set of vertices that reaches in . Then is closed, every free pebble in lies on or , and . This stays true while further searches with the ends and are made.
Proof. The set reached by a search is closed by definition, and a free pebble on a vertex of other than and would have been found. Now let a later search start at with partner (a search from fails again, since nothing has changed). If , the search stays in the closed set and finds no pebble, so nothing changes. If , a path from that entered could not leave it again, and it would end at a vertex of with a free pebble other than and , which does not exist. So the path avoids , and reversing it changes no arc with an end in . So keeps its properties. It remains to show . If not, is closed and , because the search was made with . By , . For this says , and for it contradicts Lemma 2.
Lemma 5 (rejected edges are dependent). If line L7 rejects , then is not sparse. More precisely, there is a set with .
Proof. Line L5 fails, so after lines L3 and L4 some end has , and its loop ended with a failed search. By Lemma 4 that failure persists to the end of line L4, so the set that reaches is closed, contains and , and has . By , , and by Lemma 2 equality holds. Adding gives edges inside .
Theorem 1 (correctness of PEBBLE-GAME). The game marks an edge independent exactly when it is independent of the edges accepted before it, so the accepted edges are the basis that the matroid greedy algorithm picks in the given order. The number of accepted edges is the rank of in the planar generic rigidity matroid.
Proof. By Lemma 2, an accepted edge keeps sparse. By Lemma 5, a rejected edge would break sparsity. Sparsity is independence in the matroid, so the game is the greedy algorithm. Each rejected edge lies in the span of at the time it is rejected, and only grows, so at the end spans and is a basis: .
So is generically rigid in the plane if and only if , and is a Laman graph if and only if and no edge is rejected.
Lemma 6 (every edge is spanned). After the game, every edge of lies in a set with . Hence, at every later state, .
Proof. For an accepted edge take , since and by Lemma 2. For a rejected edge take the set of Lemma 5; only grows after it, and Lemma 2 keeps the equality. Then gives at every state, so .
Lemma 7 (three pebbles). For every edge of , line L15 ends with .
Proof. The loops stop at a total of 3 or at a failed search. In the second case, Lemma 4 gives a closed set with , so by , against Lemma 2.
Lemma 8 (union of rigid sets). If and are rigid and , then is rigid. So for each edge there is exactly one largest rigid set that contains and , its rigid component, and two rigid components share at most one vertex.
Proof. Take a generic placement , so the points are distinct. At , rigid sets give infinitesimally rigid subframeworks (Asimow and Roth). Let be an infinitesimal motion of . It is an infinitesimal motion of and of , so on it is a trivial motion and on a trivial motion . A trivial motion of the plane has the form with the rotation by a right angle. The difference vanishes at two distinct points and of , so , hence and then . So is trivial on , the subframework is infinitesimally rigid, and is generically rigid. The set is rigid, because it spans the edge . So the union of all rigid sets that contain and is rigid, and it is the unique largest one. Two different components that share two vertices would have a rigid union larger than both.
Lemma 9 (the component is tight in ). Let be the rigid component of an edge of . Then .
Proof. It suffices to show that spans in the matroid, because then . Edges of in are spanned trivially. Let be rejected. Then contains a unique circuit through , and . The vertex set of is rigid: has edges (shown below), and is independent, so has rank at least . The sets and share the two ends of , so is rigid by Lemma 8, and by maximality . So , and is spanned by .
The circuit count in this proof is the standard fact for the count matroid: a circuit on vertex set has , because is not sparse, so some has , and by minimality lies inside , so , and is sparse, so .
Theorem 2 (correctness of RIGID-COMPONENTS). For each edge handled in line L14, the set of line L17 is the rigid component of . The list holds every rigid component exactly once.
Proof. By Lemma 7, after line L15.
. Suppose reaches a vertex with a free pebble. Then , so by Lemma 1, and reversing the path gives one more pebble, so , against Lemma 6. The same holds for .
is rigid. If a vertex had an arc to a vertex of , then would reach a free pebble off , so . So is closed. A vertex with a free pebble would reach itself, so the only free pebbles in are on and , and . By , . These edges of are independent and lie in , so has rank and is rigid. Hence .
. By Lemma 9 and , . Since , , so and has no free pebble except on and . A vertex of reaches only vertices of , so it reaches no free pebble off , and .
So . The moves of line L15 do not change , and Lemmas 1 to 9 hold at every state, so later edges are handled correctly too. Every rigid component has and rank , so it contains an edge, and the first such edge reached in line L14 is not yet covered (by Lemma 8 no other component contains both its ends), so is added. Later edges of are covered and skipped, so no component is added twice.
Theorem 3 (running time). PEBBLE-GAME takes time, the Laman test with early stop takes time, RIGID-COMPONENTS takes time, and the space is .
Proof. has at most arcs (Lemma 2), so one depth-first search and one path reversal take time. For one edge, each loop of line L4 has at most two successful searches, because each adds one pebble to , Lemma 3 protects that count from the other loop, and . Each loop has at most one failed search. So each edge costs at most six searches, time, and PEBBLE-GAME takes . The Laman test first checks and stops at the first rejected edge, so it handles at most edges, in time.
For the components: each component has edges of (Lemma 9), and two components share no edge (Lemma 8), so there are at most of them. Each one costs for line L15 (at most five searches) and for the backward search of line L16 over the arcs, so for all of them. For line L14, keep for each vertex the list of components that contain it, stored as hash sets; testing an edge looks at the at most components of , in time. So the total is , which is when . The arrays , the adjacency lists of and the marks take space, and the component lists take more, because for and .
Complexity
- One search. has at most arcs, because the accepted edges satisfy the count on , and every out-degree is at most 2. So a depth-first search in line L9 and the reversal in line L11 take time.
- One edge. Lines L3 and L4 make at most four successful searches, one per missing pebble, and at most two failed ones. So each edge costs , and PEBBLE-GAME takes time. When no search is needed, as for a forest, each edge costs , so the best case is .
- Laman test. A Laman graph has , and the test can stop at the first redundant edge, so it takes time. This is the bound of Jacobs and Hendrickson.
- Components. Each component holds at least one accepted edge and two components share no edge, so there are at most of them. Each one costs for the gathering and the backward search in line L16. The membership test of line L14 costs per edge. So RIGID-COMPONENTS also takes time. Lee and Streinu keep the components during the game and get for all of them.
- Space. , the counts and the marks take space.
Properties
- Exact and combinatorial. The game uses only the graph. It decides generic rigidity, so it says nothing about a particular placement: at special positions, such as on a conic, a graph that the game calls rigid gives an infinitesimally flexible framework.
- Order dependent output, order independent rank. Which edges are marked redundant depends on the order, but their number does not, and neither do the rigid components.
- Incremental. Edges can be added one at a time, and the state after each edge is a valid certificate: the orientation shows the count, and the free pebbles count the degrees of freedom, .
- Deterministic. With a fixed order of the arcs in each adjacency list, the moves are fixed, as in the trace above.
- The count matroid in general. The same game with pebbles per vertex and acceptance at pebbles decides the counts for (Lee and Streinu). The case is the graphic matroid, and is the planar rigidity matroid.
Variants and improvements
- pebble games. Lee and Streinu (2008) gave the general game and proved that it accepts exactly the -sparse graphs. For and it tests the body-and-bar counts of Tay's theorem in space.
- Components during the game. Instead of a second pass, keep the components as the edges arrive. A new edge inside a known component is redundant at once, which saves the search.
- Rigidity percolation and proteins. Jacobs and Hendrickson designed the game for networks with millions of sites, in models of glass, and Jacobs, Rader, Kuhn and Thorpe used a version for bond-bending networks in the program FIRST, which finds the rigid and flexible regions of proteins.
- Other exact tests. Hendrickson (1992) tested the Laman counts by bipartite matching on doubled edges, and the two spanning tree form of Laman's theorem gives a test by spanning tree packing. Algorithms based on matroid sums by Gabow and Westermann are faster in theory.
- Randomized rank. For any dimension, the rank of the rigidity matrix at a random integer placement gives the generic rank with high probability. It is slower, by elimination, but it works in space, where no count test is known.
When to use it
- To decide whether a sketch of points and distances is well-constrained in the generic sense, and to find over-constrained edges, in CAD degrees of freedom analysis.
- To design a rigid formation or a sensor network in the plane, and to see which links are redundant.
- To find rigid clusters in large planar networks, where computing ranks of large matrices would be too slow.
Do not use it for bar-and-joint frameworks in three dimensions: the count is not sufficient there, as the double banana shows, and is not even a matroid count for the game (). Do not use it to check a particular placement: compute the rank of the rigidity matrix at the given coordinates instead.
Pitfalls
- Taking the partner's pebble. The search from must not take a free pebble from , or the four pebbles are counted twice. It may still pass through .
- Blocking the partner. Treating as a wall in the search from is wrong in the other direction: a path through to a free pebble is a legal move and may be the only one.
- Three or four. An edge needs four pebbles to be accepted. Three pebbles is the test for components. Mixing the two gives either too many or too few accepted edges.
- Repeated edges. A second copy of an accepted edge is redundant, because the pair already spans edges. Code that drops duplicates silently changes the counts of a multigraph.
- Testing a vertex set by its accepted edges. The accepted edges inside a vertex set can be fewer than the rank of , because an edge inside can be rejected through a circuit that leaves . For a rigid component the count is exact, but to test an arbitrary set, run a new game on .
- Recursion. A recursive search can be deep on a long path. Use an explicit stack, as the implementation does.
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/pebble-game-rigidity/. The authors are listed in prov/AEGQ05.jsonl.
from typing import Sequence
class PebbleGame:
"""The (2, 3) pebble game of Jacobs and Hendrickson on the vertices 0 .. n-1.
Each vertex starts with two free pebbles. An accepted edge is an arc of a
directed graph, covered by one pebble of its tail, so for every vertex
peb[v] + (out-degree of v) = 2 at all times. The accepted edges are an
independent set of the generic 2D rigidity matroid: every set of k >= 2
vertices spans at most 2k - 3 of them.
"""
def __init__(self, n: int) -> None:
if n < 1:
raise ValueError("n must be at least 1")
self.n = n
self.peb = [2] * n # @line L1
self.out: list[list[int]] = [[] for _ in range(n)] # @line L1
self.accepted = 0
def find_pebble(self, x: int, y: int) -> bool:
"""Move one free pebble to x from a vertex other than x and y.
Searches the directed graph from x by depth-first search. On success it
reverses the arcs of the path, so x gains a pebble, the end of the path
loses one, and the other vertices keep their counts. Cost O(n), because
every out-degree is at most 2.
"""
parent = {x: x}
stack = [x]
found = -1
while stack and found < 0: # @line L9
a = stack.pop()
for b in self.out[a]:
if b in parent:
continue
parent[b] = a
if b != y and self.peb[b] > 0:
found = b
break
stack.append(b)
if found < 0: # @line L10
return False
b = found
while b != x: # @line L11
a = parent[b]
self.out[a].remove(b)
self.out[b].append(a)
b = a
self.peb[found] -= 1 # @line L11
self.peb[x] += 1 # @line L11
return True # @line L12
def gather(self, u: int, v: int, target: int) -> int:
"""Gather free pebbles on u and v, up to target in total (target <= 4).
Returns peb[u] + peb[v] at the end. It is less than target only when no
sequence of moves can put target pebbles on u and v.
"""
for x, y in ((u, v), (v, u)): # @line L3
while self.peb[x] < 2 and self.peb[u] + self.peb[v] < target: # @line L4
if not self.find_pebble(x, y): # @line L4
break
return self.peb[u] + self.peb[v]
def add_edge(self, u: int, v: int) -> bool:
"""Try to accept the edge uv. Returns True if it is independent.
Precondition: 0 <= u, v < n and u != v. Cost O(n).
"""
if u == v or not (0 <= u < self.n and 0 <= v < self.n):
raise ValueError("an edge needs two different vertices in range")
if self.gather(u, v, 4) == 4: # @line L5
self.peb[u] -= 1 # @line L6
self.out[u].append(v) # @line L6
self.accepted += 1
return True
return False # @line L7
def component_of(self, u: int, v: int) -> frozenset[int]:
"""The rigid component that contains u and v, for an edge uv already offered.
Gathers three pebbles on u and v. Then a vertex is in the component
exactly when it cannot reach a free pebble on a vertex other than u
and v. Cost O(n).
"""
self.gather(u, v, 3) # @line L15
rev: list[list[int]] = [[] for _ in range(self.n)]
for a in range(self.n):
for b in self.out[a]:
rev[b].append(a)
seen = [False] * self.n
stack = [w for w in range(self.n) if w != u and w != v and self.peb[w] > 0]
for w in stack:
seen[w] = True
while stack: # @line L16
b = stack.pop()
for a in rev[b]:
if not seen[a]:
seen[a] = True
stack.append(a)
return frozenset(w for w in range(self.n) if not seen[w]) # @line L17
def pebble_game(n: int, edges: Sequence[tuple[int, int]]) -> list[bool]:
"""Run the (2, 3) pebble game on the edges in the given order.
Returns one flag per edge: True if the edge is independent of the edges
accepted before it, False if it is redundant. The accepted edges are the
greedy basis of the generic 2D rigidity matroid for this order.
Precondition: n >= 1, and each edge has two different ends in 0 .. n-1.
Repeated edges are allowed (the second copy is redundant).
Cost O(n m) time and O(n + m) space for m edges.
"""
game = PebbleGame(n)
marks = [game.add_edge(u, v) for u, v in edges] # @line L2
return marks # @line L8
def rigidity_rank(n: int, edges: Sequence[tuple[int, int]]) -> int:
"""Rank of the edge set in the generic 2D rigidity matroid. Cost O(n m)."""
return sum(pebble_game(n, edges))
def is_generically_rigid(n: int, edges: Sequence[tuple[int, int]]) -> bool:
"""True if the graph is generically rigid in the plane. Cost O(n m)."""
return n == 1 or rigidity_rank(n, edges) == 2 * n - 3
def is_laman(n: int, edges: Sequence[tuple[int, int]]) -> bool:
"""True if the graph is generically minimally rigid in the plane.
That is 2n - 3 edges and at most 2k - 3 edges on every k >= 2 vertices.
A single vertex with no edges counts as minimally rigid. The game stops at
the first redundant edge, so the cost is O(n^2).
"""
if n == 1:
return len(edges) == 0
if len(edges) != 2 * n - 3:
return False
game = PebbleGame(n)
return all(game.add_edge(u, v) for u, v in edges)
def rigid_components(n: int, edges: Sequence[tuple[int, int]]) -> list[frozenset[int]]:
"""The rigid components of the graph: the maximal vertex sets X with |X| >= 2
whose induced subgraph is generically rigid in the plane.
Every edge lies in exactly one component, and two components share at most
one vertex. Isolated vertices are in no component. The components come in
the order of their first edge. Cost O(n m).
"""
game = PebbleGame(n)
for u, v in edges: # @line L13
game.add_edge(u, v)
comps: list[frozenset[int]] = [] # @line L13
member: list[set[int]] = [set() for _ in range(n)]
for u, v in edges: # @line L14
if member[u] & member[v]: # @line L14
continue
comp = game.component_of(u, v)
for w in comp:
member[w].add(len(comps))
comps.append(comp) # @line L17
return comps # @line L18
test_pebble_game_rigidity.py 197 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/pebble-game-rigidity/. The authors are listed in prov/AEGQ05.jsonl.
import random
from fractions import Fraction
from itertools import combinations
from pebble_game_rigidity import (
PebbleGame,
is_generically_rigid,
is_laman,
pebble_game,
rigid_components,
rigidity_rank,
)
Edge = tuple[int, int]
def greedy_marks(n: int, edges: list[Edge], within: int = -1) -> list[bool]:
"""Brute force over vertex subsets: keep an edge when, with the kept edges,
every set of k >= 2 vertices (inside the mask within) still spans at most
2k - 3 edges. This is the greedy basis of the count matroid."""
full = (1 << n) - 1 if within < 0 else within
subs = []
s = full
while s:
if bin(s).count("1") >= 2:
subs.append(s)
s = (s - 1) & full
cap = {s: 2 * bin(s).count("1") - 3 for s in subs}
cnt = dict.fromkeys(subs, 0)
marks = []
for u, v in edges:
b = 1 << u | 1 << v
hit = [s for s in subs if s & b == b]
ok = all(cnt[s] < cap[s] for s in hit)
marks.append(ok)
if ok:
for s in hit:
cnt[s] += 1
return marks
def sparse(n: int, edges: list[Edge]) -> bool:
"""Every set of k >= 2 vertices spans at most 2k - 3 of the edges."""
return all(greedy_marks(n, edges))
def matrix_rank(rows: list[list[Fraction]]) -> int:
rows = [r[:] for r in rows]
rank = 0
cols = len(rows[0]) if rows else 0
for c in range(cols):
piv = next((i for i in range(rank, len(rows)) if rows[i][c] != 0), -1)
if piv < 0:
continue
rows[rank], rows[piv] = rows[piv], rows[rank]
for i in range(len(rows)):
if i != rank and rows[i][c] != 0:
f = rows[i][c] / rows[rank][c]
rows[i] = [a - f * b for a, b in zip(rows[i], rows[rank])]
rank += 1
return rank
def matrix_rigidity_rank(n: int, edges: list[Edge], rng: random.Random) -> int:
"""Rank of the 2D rigidity matrix at a random integer point, in exact arithmetic."""
p = [(Fraction(rng.randrange(-10**6, 10**6)), Fraction(rng.randrange(-10**6, 10**6))) for _ in range(n)]
rows = []
for u, v in edges:
r = [Fraction(0)] * (2 * n)
dx, dy = p[u][0] - p[v][0], p[u][1] - p[v][1]
r[2 * u], r[2 * u + 1] = dx, dy
r[2 * v], r[2 * v + 1] = -dx, -dy
rows.append(r)
return matrix_rank(rows)
def brute_components(n: int, edges: list[Edge]) -> set[frozenset[int]]:
"""Brute force: the maximal vertex sets X, |X| >= 2, whose induced edges have rank 2|X| - 3."""
rigid = []
for k in range(2, n + 1):
for xs in combinations(range(n), k):
s = set(xs)
mask = sum(1 << x for x in xs)
inside = [e for e in edges if e[0] in s and e[1] in s]
if sum(greedy_marks(n, inside, mask)) == 2 * k - 3:
rigid.append(frozenset(xs))
return {x for x in rigid if not any(x < y for y in rigid)}
def random_graph(n: int, rng: random.Random) -> list[Edge]:
pairs = list(combinations(range(n), 2))
if rng.random() < 0.5:
m = rng.randrange(0, min(len(pairs), 2 * n + 2) + 1)
else:
m = max(0, min(len(pairs), 2 * n - 3 + rng.choice((-1, 0, 0, 1))))
edges = rng.sample(pairs, m)
return [(v, u) if rng.random() < 0.5 else (u, v) for u, v in edges]
def check_invariant(game: PebbleGame) -> None:
for v in range(game.n):
assert game.peb[v] >= 0
assert game.peb[v] + len(game.out[v]) == 2
def test_example_trace() -> None:
edges = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (0, 3), (3, 4), (4, 5), (3, 5), (2, 5)]
assert pebble_game(6, edges) == [True] * 5 + [False] + [True] * 4
assert rigid_components(6, edges[:9]) == [frozenset({0, 1, 2, 3}), frozenset({3, 4, 5})]
assert rigid_components(6, edges) == [frozenset(range(6))]
assert rigidity_rank(6, edges[:9]) == 8
assert is_generically_rigid(6, edges)
assert not is_laman(6, edges)
def test_small_cases() -> None:
assert is_laman(1, [])
assert is_laman(2, [(0, 1)])
assert not is_laman(2, [(0, 1), (1, 0)])
assert pebble_game(2, [(0, 1), (1, 0)]) == [True, False]
assert rigid_components(3, []) == []
assert rigid_components(3, [(0, 1)]) == [frozenset({0, 1})]
assert is_laman(3, [(0, 1), (1, 2), (0, 2)])
assert not is_generically_rigid(4, [(0, 1), (1, 2), (2, 3), (3, 0)])
# K4 plus a pendant vertex: 2n - 3 edges but flexible
k4p = list(combinations(range(4), 2)) + [(3, 4)]
assert len(k4p) == 7 and not is_laman(5, k4p) and rigidity_rank(5, k4p) == 6
# K33 is a Laman graph
k33 = [(a, b) for a in range(3) for b in range(3, 6)]
assert is_laman(6, k33)
def test_against_brute_force() -> None:
rng = random.Random(7)
for _ in range(600):
n = rng.randrange(1, 9)
edges = random_graph(n, rng)
marks = pebble_game(n, edges)
assert marks == greedy_marks(n, edges)
assert is_laman(n, edges) == (n == 1 and not edges or len(edges) == 2 * n - 3 and n >= 2 and sparse(n, edges))
game = PebbleGame(n)
for u, v in edges:
game.add_edge(u, v)
check_invariant(game)
def test_rank_against_matrix() -> None:
rng = random.Random(11)
for _ in range(300):
n = rng.randrange(2, 9)
edges = random_graph(n, rng)
assert rigidity_rank(n, edges) == matrix_rigidity_rank(n, edges, rng)
def henneberg_graph(n: int, rng: random.Random) -> list[Edge]:
"""A random Laman graph on n >= 2 vertices, built by Henneberg moves."""
edges: list[Edge] = [(0, 1)]
for v in range(2, n):
if v >= 3 and rng.random() < 0.5:
a, b = edges.pop(rng.randrange(len(edges)))
c = rng.choice([w for w in range(v) if w != a and w != b])
edges += [(v, a), (v, b), (v, c)]
else:
a, b = rng.sample(range(v), 2)
edges += [(v, a), (v, b)]
rng.shuffle(edges)
return edges
def test_henneberg_graphs_are_laman() -> None:
rng = random.Random(3)
for _ in range(300):
n = rng.randrange(2, 40)
edges = henneberg_graph(n, rng)
assert is_laman(n, edges)
assert rigid_components(n, edges) == [frozenset(range(n))]
u, v = rng.sample(range(n), 2)
moved = edges[1:] + [(u, v)]
if n <= 8:
assert is_laman(n, moved) == sparse(n, moved)
elif n <= 16 and rng.random() < 0.2:
assert rigidity_rank(n, moved) == matrix_rigidity_rank(n, moved, rng)
def test_components_against_brute_force() -> None:
rng = random.Random(5)
for _ in range(300):
n = rng.randrange(2, 9)
edges = random_graph(n, rng)
comps = rigid_components(n, edges)
assert len(comps) == len(set(comps))
assert set(comps) == brute_components(n, edges)
for u, v in edges:
assert sum(1 for c in comps if u in c and v in c) == 1
History
Rigidity percolation, the study of when a random network becomes rigid, needed a fast exact test of the Laman counts on very large graphs. Hendrickson (1992) had given a polynomial test by bipartite matching. Jacobs and Thorpe used a pebble game for rigidity percolation in 1995, and in 1997 Jacobs and Hendrickson published the full algorithm, with its proof, the rigid cluster decomposition and a quadratic worst case. It later became the core of the FIRST program for proteins. Lee and Streinu (2008) generalized it to all counts with , proved the equivalence with sparsity in this setting, and gave the component algorithms. The pebble game of rigidity is not related to the red-blue pebble game of I/O complexity.
References
- Donald J. Jacobs and Bruce Hendrickson, An algorithm for two-dimensional rigidity percolation, the pebble game, Journal of Computational Physics 137(2), 346 to 365, 1997, the pebble game for the Laman counts, the search for free pebbles, the rigid cluster decomposition, and the quadratic worst case bound
- Audrey Lee and Ileana Streinu, Pebble game algorithms and sparse graphs, Discrete Mathematics 308(8), 1425 to 1437, 2008, the (k, l) pebble games, the proof that they accept exactly the (k, l)-sparse graphs, and the detection of components
- G. Laman, On graphs and rigidity of plane skeletal structures, Journal of Engineering Mathematics 4(4), 331 to 340, 1970, the counts that the pebble game tests
- Bruce Hendrickson, Conditions for unique graph realizations, SIAM Journal on Computing 21(1), 65 to 84, 1992, the earlier matching-based test of the Laman counts and of redundant rigidity
- Jack Graver, Brigitte Servatius and Herman Servatius, Combinatorial Rigidity, Graduate Studies in Mathematics 2, American Mathematical Society, 1993, Chapter 4, Linear and Planar Rigidity (the generic rigidity matroid in the plane)
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 AEGQ05 Edit this page History Report an error Markdown