Algorithm Search⌘K

Algorithmresearch

Frontier vertex algorithm

Also called Hoffmann-Lomonosov-Sitharam frontier algorithm.

Builds a DR-plan of a constraint graph by finding minimal dense clusters with network flow and collapsing each to its frontier vertices, step by step.

Time
O(m^5 (n + m)^2) worstΘ(n + m) best
Space
Θ(n + m) extra
Where
m = the number of constraints; n = the number of entities
Properties
deterministicexactiterative
Origin
Christoph M. Hoffmann, Andrew Lomonosov, Meera Sitharam, 2001

The Frontier vertex algorithm of Hoffmann, Lomonosov and Sitharam builds a DR-plan for a weighted constraint graph. It starts with every constraint as a small cluster. Then it repeats one step: find a smallest set of clusters and entities that is dense, that is, has no more degrees of freedom than one rigid body, by the network flows of degrees of freedom analysis; record that set as a new cluster with the old clusters as its children; and replace the new cluster in the graph by its frontier vertices, the entities that still have constraints to the outside, tied to one new core vertex. Keeping the frontier vertices is what lets two clusters share an entity, which the older planners that contract a cluster to one node get wrong. For points and distances in the plane, every cluster it finds is rigid and the roots of the plan are the rigid components of the graph.

In plain words

A drawing has many points and many rules between them. Some groups of points are fixed in shape by their own rules. The method finds such a group, the smallest one it can, and writes it down as one stiff piece. Then it simplifies the drawing: the inside of the piece is replaced by one block, but the points of the piece that touch other rules stay, so other pieces can still use them. On the simpler drawing it looks for the next small stiff group, which may now contain whole pieces, and so on. When no stiff group is left, the record of which piece was built from which smaller pieces is a plan for the solver: solve the small pieces first, then put them together.

The problem

The input is a constraint graph G=(V,E)G = (V, E) in the sense of the constraint graph page. Each entity vv has a weight w(v)>0w(v) > 0, its degrees of freedom, and each constraint ee has a weight w(e)>0w(e) > 0, the number of equations it adds. DD is the number of degrees of freedom of a rigid body: 3 in the plane and 6 in space. For a set XX of entities, let E(X)E(X) be the constraints with all their entities in XX, and let the density be

ρ(X)=w(E(X))−w(X).\rho(X) = w(E(X)) - w(X).

This page calls XX dense when ρ(X)≥−D\rho(X) \ge -D, as Hoffmann, Lomonosov and Sitharam do. (The DR-plan page calls such a set rigid, and the constraint graph page keeps "dense" for ρ(X)>−D\rho(X) > -D.) The main case is points and distances in the plane: w(v)=2w(v) = 2, w(e)=1w(e) = 1 and D=3D = 3, so ρ(X)=∣E(X)∣−2∣X∣\rho(X) = |E(X)| - 2|X| and the counts are those of Laman's theorem.

The output is a DR-plan: a list of clusters, each with its vertex set U⊆VU \subseteq V, its children (earlier clusters), its leaves (entities of UU in no child), its frontier and its density ρ(U)\rho(U) in GG. Each cluster is the union of its children and leaves, and the roots are the clusters that are no one's child, together with the entities in no constraint. A set XX with ∣X∣≥2|X| \ge 2 is rigid when G[X]G[X] is generically rigid in the plane, and the rigid components of GG are the maximal rigid sets.

The algorithm

The algorithm works on a simplified graph SS. Its nodes are points, the entities that are still present, and cores, one for each cluster that is not yet a child of another one. A cluster KK with frontier FF is shown in SS as its core cc, of weight DD, with an edge cfcf of weight w(f)w(f) to each f∈Ff \in F. The rest of KK is gone from SS. The core, its frontier and these edges have density ∣F∣⋅w(f)−D−∣F∣⋅w(f)=−D|F| \cdot w(f) - D - |F| \cdot w(f) = -D when all frontier weights are equal, so they look like one rigid body, which is what the cluster is.

A set of nodes of SS is closed when it holds the whole frontier of each core in it, and a target is a closed set that is dense and holds at least two cores. A target that holds two cores and no shared point would have density at most −2D-2D, so every target holds two cores aa and bb that share a point, a candidate pair. Given aa and bb, a set ZZ of largest density with {a,b}⊆Z⊆S\{a, b\} \subseteq Z \subseteq S is a maximum-weight closure: an edge of SS is a profit w(e)w(e) that needs both its ends, and a node is a cost w(x)w(x). One minimum cut finds it.

  1. FRONTIER(V, E, w, D)
  2. 1for each constraint uv of E, unless uv already lies inside a cluster do
  3. 2SIMPLIFY({u, v}) ▷ each constraint starts as a cluster
  4. 3repeat
  5. 4for each candidate pair {a, b} of S do
  6. 5Z ← MAX-CLOSURE(S, {a, b}); if ρ(Z) ≥ -D then X ← Z plus the frontier of each core in Z; leave the for
  7. 6if no pair gave a dense set then leave the repeat
  8. 7while some core c of X has a target inside X ∖ {c} do
  9. 8search X ∖ {c}, without the points that touch no other core of X, as in lines L4 and L5
  10. 9X ← the target found
  11. 10SIMPLIFY(X): U ← the union of the vertex sets of the nodes of X
  12. 11add to X every core whose cluster lies inside U; their clusters are the children
  13. 12F ← the points of X with a neighbor outside X ▷ the frontier
  14. 13delete from S the nodes of X that are not in F, and the edges inside X
  15. 14add a core c of weight D, and an edge cf of weight w(f) for each f ∈ F
  16. 15record the cluster U with its children, leaves, frontier F and density ρ(U) in G
  17. 16return the clusters

Line L1 skips a repeated constraint, which the first copy has made a cluster. After lines L1 and L2, every edge of SS joins a core to a point. Line L5 adds the frontier of each core of ZZ, which keeps the set closed and never lowers its density, since a point ff with k≥1k \ge 1 cores costs w(f)w(f) and brings k⋅w(f)k \cdot w(f). Lines L7 to L9 make the target minimal: they drop one core at a time, and the points that no other core touches, and look again. They drop cores and not points, because a set without a frontier point of one of its cores is not closed. Line L11 also absorbs clusters that the new set swallows whole, so that no cluster lies inside another one. Line L15 records the density in GG, not in SS: the simplified graph has lost the extra constraints inside each cluster.

Example

Take the triangular prism: points 0 to 5, the triangles 012 and 345, and the bars 03, 14 and 25. It has 9=2⋅6−39 = 2 \cdot 6 - 3 constraints and it is a Laman graph, so it is rigid. Every point has three constraints.

step target found cores in it density in SS new cluster frontier
L1, L2 each bar none 1−4=−31 - 4 = -3 9 clusters of two points both ends
1 {e01,e02,e12,0,1,2}\{e_{01}, e_{02}, e_{12}, 0, 1, 2\} 3 3⋅2−9=−33 \cdot 2 - 9 = -3 {0,1,2}\{0, 1, 2\} {0,1,2}\{0, 1, 2\}
2 {e34,e35,e45,3,4,5}\{e_{34}, e_{35}, e_{45}, 3, 4, 5\} 3 −3-3 {3,4,5}\{3, 4, 5\} {3,4,5}\{3, 4, 5\}
3 all of SS 5 6⋅2−15=−36 \cdot 2 - 15 = -3 {0,…,5}\{0, \ldots, 5\} none

The densities in SS use the count of the proofs page: a closed set with kk cores has density ∑p2(d(p)−1)−3k\sum_p 2(d(p) - 1) - 3k, where d(p)d(p) is the number of its cores at the point pp. In step 1 the first candidate pair is e01,e02e_{01}, e_{02}, which share the point 0, and the largest closure that holds them is the triangle. No smaller target exists: without e12e_{12}, the set {e01,e02,0,1,2}\{e_{01}, e_{02}, 0, 1, 2\} has density 2−6=−42 - 6 = -4. The triangle keeps all three points, because each of them has a bar to the other triangle. In step 3 the simplified graph has the cores T1T_1 and T2T_2 of the triangles and the cores of the three bars, and every point lies in two cores. A proper closed part, such as T1T_1 with the bar 03, has density 2−6=−42 - 6 = -4. So the last cluster has five children: two triangles and three bars. This is the step that the triangle merges of Fudos and Hoffmann cannot make, since no three of the clusters pairwise share a point. The solver must place the two triangles against each other with all three bars at once.

The frontier matters in the graph with triangles 012 and 345 and the bars 03, 04 and 15. When {0,1,2}\{0, 1, 2\} becomes a cluster, the point 0 stays on its frontier, since it has the bars 03 and 04. So the triangle 034 is still visible, and after {3,4,5}\{3, 4, 5\} the algorithm finds the cluster {0,3,4,5}\{0, 3, 4, 5\}, made of the bars 03 and 04 and the triangle 345. A planner that contracts {0,1,2}\{0, 1, 2\} to one node no longer sees that 03 and 04 meet at one point (see the pitfalls of the DR-plan page).

Correctness

The proof shows the following for the algorithm above.

  • The plan. Each cluster is the union of its children and leaves, each child is a proper subset made earlier, each cluster is a child at most once, every constraint lies in a root, and the roots cover VV. The main loop stops after at most m−1m - 1 steps. This holds for any positive weights.
  • Finding and shrinking. A frontier vertex shared by two live clusters is never deleted, so shared entities stay visible. The search of lines L4 and L5 finds a target whenever there is one, and lines L7 to L9 return a target with no proper closed subset that is a target. This also holds for any positive weights.
  • Rigidity in the plane. For points and distances in the plane, every cluster is generically rigid, and when the algorithm stops, the roots with two or more points are exactly the rigid components of GG. The proof uses Laman's theorem and the fact that the rigidity rank of a graph is the sum of 2∣R∣−32|R| - 3 over its rigid components.

The rigidity claims need the plane and the weights 2, 1 and 3. In space, with w(v)=3w(v) = 3, w(e)=1w(e) = 1 and D=6D = 6, the double banana has ρ=18−24=−6\rho = 18 - 24 = -6 with no smaller dense part, so the algorithm makes it a cluster, but it is not rigid.

What is measured: the tests on this page check by brute force over all vertex subsets that every cluster is rigid by the Laman count, that the plan has the structure above, and that the roots are the rigid components, on random graphs with at most 7 points, together with the prism, K4K_4, two triangles that share a point and the graph with the shared point 0. A further run on 400 random graphs with 2 to 7 points found no failure.

Proof: The Frontier algorithm builds a DR-plan whose clusters are rigid in the plane and whose roots are the rigid componentsfull

Line numbers refer to the pseudocode on the main page. G=(V,E)G = (V, E) has nn entities and mm distinct constraints; a repeated constraint is skipped in line L1, so we assume there is none. During the run, SS is the simplified graph. Its points are the entities still in SS, and its cores are the cores of the live clusters, those that are not yet a child. For a core cc, U(c)U(c) is the vertex set of its cluster and F(c)F(c) is the set of points joined to cc. For a point xx, U(x)={x}U(x) = \{x\}. A set XX of nodes of SS is closed if F(c)⊆XF(c) \subseteq X for every core c∈Xc \in X, and U(X)=⋃x∈XU(x)U(X) = \bigcup_{x \in X} U(x).

Lemmas 1 to 3 and Theorem 5 hold for any positive weights. Lemma 4 and Theorems 6 and 7 are for points and distances in the plane: w(v)=2w(v) = 2, w(e)=1w(e) = 1, D=3D = 3. There, a set X⊆VX \subseteq V with ∣X∣≥2|X| \ge 2 is rigid when E(X)E(X) has rank 2∣X∣−32|X| - 3 in the generic rigidity matroid of the plane, that is, when the framework (X,E(X))(X, E(X)) is infinitesimally rigid at a generic placement, and a rigid component is a maximal rigid set.

Lemma 1 (invariants). After each call of SIMPLIFY, for all live cores c≠c′c \ne c':

  1. a point xx is joined to cc if and only if x∈U(c)x \in U(c), and every edge of SS that is not between two points joins a core to a point;
  2. if x∈U(c)∩U(c′)x \in U(c) \cap U(c'), then xx is a point of SS, so x∈F(c)∩F(c′)x \in F(c) \cap F(c');
  3. U(c)⊈U(c′)U(c) \not\subseteq U(c').

Moreover, no core is ever in a frontier, and after lines L1 and L2 no edge joins two points.

Proof. At the start there are no cores. Consider a call SIMPLIFY(XX), where XX is closed: in line L2, X={u,v}X = \{u, v\} has no core, and in line L10, XX is closed by Lemma 2 and Lemma 3 below. Assume the claims before the call.

First, every point x∈U=U(X)x \in U = U(X) lies in XX. Either x∈Xx \in X, or x∈U(c)x \in U(c) for a core c∈Xc \in X; then xx is joined to cc by claim 1, and x∈F(c)⊆Xx \in F(c) \subseteq X since XX is closed. Let X′X' be XX with the cores added in line L11. For such an added core c′′c'', F(c′′)F(c'') consists of points of U(c′′)⊆UU(c'') \subseteq U, so F(c′′)⊆XF(c'') \subseteq X. Hence no core of X′X' has a neighbor outside X′X', and no core is in the frontier FF of line L12.

Claim 2. Let c′c' be a live core that stays live, so U(c′)⊈UU(c') \not\subseteq U and c′∉X′c' \notin X'. Let x∈U∩U(c′)x \in U \cap U(c'). Then x∈U(y)x \in U(y) for some y∈Xy \in X. If y=xy = x is a point, xx is joined to c′c' by claim 1. If yy is a core, xx is a point joined to c′c' by claim 2. In both cases xx is a point in XX with the neighbor c′∉X′c' \notin X', so x∈Fx \in F: it stays a point and is joined to the new core and to c′c'.

Claim 1. The new core is joined exactly to F⊆UF \subseteq U. A point of UU in SS lies in XX, as shown, so after line L13 it is in FF or deleted; hence the points of UU left in SS are exactly FF. For an old core c′c' that stays live, a point deleted in line L13 had no neighbor outside X′X', so it was not joined to c′c', and by claim 1 it was not in U(c′)U(c'). So the equivalence still holds for c′c'.

Claim 3. Before the call the live sets form an antichain. If U⊆U(c′)U \subseteq U(c') for a live c′c' that stays live, then U(y)⊆U(c′)U(y) \subseteq U(c') for each core y∈Xy \in X, which is false; and if XX has no core, X={u,v}X = \{u, v\} and c′c' would contain the constraint uvuv, which line L1 excludes. All live clusters inside UU are absorbed in line L11. So the antichain is kept.

Line L13 deletes the edges inside XX, so after line L2 for uvuv the edge uvuv is gone, and after lines L1 and L2 no edge joins two points. □\square

After lines L1 and L2, every edge of SS joins a core cc to a point f∈F(c)f \in F(c) and has weight w(f)w(f). For a closed set XX with cores CC and points PP, let dX(f)d_X(f) be the number of cores of XX joined to ff. Then

ρS(X)=∑f∈Pw(f) (dX(f)−1)−D ∣C∣.(1)\rho_S(X) = \sum_{f \in P} w(f) \, (d_X(f) - 1) - D \, |C|. \qquad (1)

For points and distances in the plane this reads ρS(X)=∑f2(dX(f)−1)−3∣C∣\rho_S(X) = \sum_f 2(d_X(f) - 1) - 3|C|. A target is a closed set XX with ρS(X)≥−D\rho_S(X) \ge -D and ∣C∣≥2|C| \ge 2.

Lemma 2 (the search finds targets). Let YY be a closed set of nodes, after lines L1 and L2. The search of lines L4 and L5 on YY returns only targets inside YY, each point of which is joined to a core of it. If YY contains a target, the search returns one.

Proof. MAX-CLOSURE(YY, {a,b}\{a, b\}) is a maximum-weight closure in the network with a node for each edge of SS inside YY, of profit w(e)w(e), that needs both its ends, and a node for each x∈Yx \in Y of cost w(x)w(x), with aa and bb forced. By Picard's reduction, see maximum-weight closure, the source side of a minimum cut gives a set ZZ with {a,b}⊆Z⊆Y\{a, b\} \subseteq Z \subseteq Y and the largest ρS(Z)\rho_S(Z). A point is on the source side only if an edge node ee that reaches it is, and then the other end of ee, a core, is too, since the arcs from ee have infinite capacity. So every point of ZZ is joined to a core of ZZ. Line L5 then adds F(c)F(c) for each core c∈Zc \in Z; these points lie in YY since YY is closed, and each of them costs w(f)w(f) and brings d⋅w(f)d \cdot w(f) with d≥1d \ge 1, so the density does not drop. The result is closed, holds the two cores aa and bb, and is a target if line L5 accepts it.

Let W⊆YW \subseteq Y be a target with cores CWC_W. If no point of WW were joined to two cores of WW, then by (1) ρS(W)≤−D∣CW∣≤−2D<−D\rho_S(W) \le -D|C_W| \le -2D < -D. So two cores a,b∈Wa, b \in W share a point, and {a,b}\{a, b\} is a candidate pair of YY. Since WW is a feasible set for MAX-CLOSURE(YY, {a,b}\{a, b\}), that call returns a set of density at least ρS(W)≥−D\rho_S(W) \ge -D, and line L5 accepts it. The search tries every candidate pair, so it returns a target. □\square

Lemma 3 (minimal targets). Lines L7 to L9 end with a target XX such that no closed set W⊊XW \subsetneq X is a target.

Proof. XX is a target when line L7 is reached, by Lemma 2, and line L9 replaces it by a target. For a core c∈Xc \in X, let YcY_c be X∖{c}X \setminus \{c\} without the points that are joined to no other core of XX. YcY_c is closed, since every other core of XX keeps its frontier. A target found in YcY_c lacks cc, so each change makes XX smaller, and the loop ends. At the end, by Lemma 2, no YcY_c contains a target. Now let W⊊XW \subsetneq X be a closed target. Every point of XX is joined to a core of XX (Lemma 2, and line L5 adds only frontier points), so if WW held every core of XX, it would hold every point too, and W=XW = X. So WW misses a core cc. Drop from WW the points joined to no core of WW: by (1) this raises the density by their weights and keeps WW closed, so the result is still a target. It lies in YcY_c, which is a contradiction. □\square

Lemma 4 (every core has two frontier points). For points and distances in the plane, let XX be the target of Lemma 3, with cores CC, ∣C∣=k≥2|C| = k \ge 2. Then ∣F(c)∣≥2|F(c)| \ge 2 for every c∈Cc \in C.

Proof. Suppose ∣F(c)∣≤1|F(c)| \le 1. If k=2k = 2, at most one point lies on both cores, so by (1) ρS(X)≤2−6=−4\rho_S(X) \le 2 - 6 = -4, and XX is not a target. If k≥3k \ge 3, let WW be XX without cc and without the points joined only to cc. WW is closed and has k−1≥2k - 1 \ge 2 cores. In (1), dropping cc adds 3, the point of F(c)F(c), if there is one, loses at most 2, and the dropped points had the term 0. So ρS(W)≥ρS(X)+1≥−2\rho_S(W) \ge \rho_S(X) + 1 \ge -2, and W⊊XW \subsetneq X is a target, against Lemma 3. □\square

Theorem 5 (the plan). For any positive weights:

  1. each cluster is the union of its children and its leaves;
  2. each child is a proper subset of its parent and was made earlier;
  3. each cluster is a child of at most one cluster;
  4. the main loop stops after at most m−1m - 1 steps, so there are at most 2m−12m - 1 clusters;
  5. every constraint lies in a root, and the roots cover VV.

Proof. (1) The leaves are defined in line L15 as the entities of UU in no child. (2) A child is a live cluster inside UU before the call. A cluster of line L2 has no child, since a live cluster inside {u,v}\{u, v\} would be an earlier copy of uvuv, and its leaves are single entities. In line L10, XX holds at least two cores whose sets form an antichain (Lemma 1), so no child equals UU, and every point of XX lies in the set of a core of XX, so there are no leaves. (3) Line L13 deletes every core of X′X', so a cluster stops being live when it becomes a child. (4) After lines L1 and L2 there are at most mm live clusters, and each step absorbs at least two and adds one. (5) Each constraint is in the cluster of line L2 for it or for its first copy. Follow the parent of that cluster, which is unique by (3); the sets grow along the way, and at the end the chain stops at a live cluster, which is a root. Line L16 lists as roots the live clusters and the entities in no constraint, so the roots cover VV. □\square

For the rest, the weights are those of points and distances in the plane, and all frameworks are at one generic placement of VV. We use three facts about rigidity in the plane.

  • (R1) If AA and BB are rigid and share at least two vertices, then A∪BA \cup B is rigid with the edges E(A)∪E(B)E(A) \cup E(B). An infinitesimal motion is trivial on AA and on BB, and a trivial motion of the plane is fixed by its values at two distinct points, so the two agree.
  • (R2) Every edge lies in exactly one rigid component, and two rigid components share at most one vertex. An edge is rigid, so it lies in a maximal rigid set; by (R1) two rigid components that share two vertices would have a rigid union.
  • (R3) For a multigraph HH with rigid components R1,…,RtR_1, \ldots, R_t, the rank of HH is ∑i(2∣Ri∣−3)\sum_i (2|R_i| - 3). Take a basis BiB_i of the edges inside each RiR_i, so ∣Bi∣=2∣Ri∣−3|B_i| = 2|R_i| - 3. The BiB_i are disjoint by (R2), and their union spans HH, since each edge of HH lies in some RiR_i and so in the closure of BiB_i. So it is enough that the union is independent. If ⋃iBi\bigcup_i B_i held a circuit QQ, then QQ minus any edge would be independent with 2∣V(Q)∣−32|V(Q)| - 3 edges, so V(Q)V(Q) is rigid by Laman's theorem and lies in one component RjR_j; then Q⊆BjQ \subseteq B_j, which is impossible.

Theorem 6 (clusters are rigid). For points and distances in the plane, the vertex set of every cluster is rigid. Hence the recorded density ρ(U)=∣E(U)∣−2∣U∣\rho(U) = |E(U)| - 2|U| is at least −3-3.

Proof. By induction on the order of the clusters. A cluster of line L2 is one constraint, which is rigid. Let the cluster UU come from the target XX of Lemma 3, with cores CC, k≥2k \ge 2, and points PP. Each U(c)U(c) with c∈Cc \in C is rigid by induction, U=⋃c∈CU(c)U = \bigcup_{c \in C} U(c), and ∣F(c)∣≥2|F(c)| \ge 2 by Lemma 4. A vertex that lies in two of the sets U(c)U(c) is a point of PP in both frontiers, by Lemma 1. For each c∈Cc \in C, let LcL_c be a minimally rigid graph on F(c)F(c), with 2∣F(c)∣−32|F(c)| - 3 edges, and let HH be the multigraph on PP that is the union of the LcL_c.

If HH is rigid, UU is rigid. Let uu be an infinitesimal motion of the framework on UU with the edges ⋃cE(U(c))⊆E(U)\bigcup_c E(U(c)) \subseteq E(U). On each U(c)U(c) it is trivial, since U(c)U(c) is rigid. So on PP it keeps the length of each edge of each LcL_c to first order, and as HH is rigid, uu agrees on PP with one trivial motion TT. On each U(c)U(c), uu is a trivial motion that agrees with TT on the two or more points of F(c)F(c), so it is TT. Every vertex of UU lies in some U(c)U(c), so u=Tu = T on UU. Thus the rank of E(U)E(U) is 2∣U∣−32|U| - 3.

HH is rigid. Let R1,…,RtR_1, \ldots, R_t be the rigid components of HH. Each F(c)F(c) spans the rigid graph LcL_c, so by (R2) it lies in exactly one component; let CiC_i be the cores with F(c)⊆RiF(c) \subseteq R_i. An edge of LcL_c lies in the component of F(c)F(c), so the edges of HH inside RiR_i are the edges of the LcL_c with c∈Cic \in C_i, and as every vertex of a rigid set with two or more vertices has an edge in it, Ri=⋃c∈CiF(c)R_i = \bigcup_{c \in C_i} F(c). So Wi=Ci∪RiW_i = C_i \cup R_i is closed, and by (1),

ρS(Wi)=∑c∈Ci2∣F(c)∣−3∣Ci∣−2∣Ri∣=∑c∈Ci(2∣F(c)∣−3)−2∣Ri∣≥(2∣Ri∣−3)−2∣Ri∣=−3,\rho_S(W_i) = \sum_{c \in C_i} 2|F(c)| - 3|C_i| - 2|R_i| = \sum_{c \in C_i} (2|F(c)| - 3) - 2|R_i| \ge (2|R_i| - 3) - 2|R_i| = -3,

since the number of edges of HH inside RiR_i is at least their rank, 2∣Ri∣−32|R_i| - 3. If some CiC_i has two or more cores, WiW_i is a target inside XX, so Wi=XW_i = X by Lemma 3, Ri=PR_i = P, and HH is rigid. Otherwise every CiC_i has one core, and by (R3)

rank⁡H=∑c∈C(2∣F(c)∣−3)=∑f∈P2dX(f)−3k=ρS(X)+2∣P∣≥2∣P∣−3,\operatorname{rank} H = \sum_{c \in C} (2|F(c)| - 3) = \sum_{f \in P} 2 d_X(f) - 3k = \rho_S(X) + 2|P| \ge 2|P| - 3,

so HH is rigid. Finally, rigid UU means ∣E(U)∣≥2∣U∣−3|E(U)| \ge 2|U| - 3. □\square

Theorem 7 (roots are the rigid components). For points and distances in the plane, when the algorithm stops, the live clusters are exactly the rigid components of GG. So the roots with two or more entities are the rigid components.

Proof. The algorithm stops when the search of lines L4 and L5 on all of SS, a closed set, finds nothing, so by Lemma 2 SS holds no target. Let RR be a rigid component, and let CRC_R be the live cores cc with ∣U(c)∩R∣≥2|U(c) \cap R| \ge 2. For such cc, U(c)U(c) is rigid (Theorem 6), so U(c)∪RU(c) \cup R is rigid by (R1), and U(c)⊆RU(c) \subseteq R as RR is maximal. Each edge of G[R]G[R] lies in a live cluster (Theorem 5), which then meets RR in two vertices, so the edges of G[R]G[R] are exactly ⋃c∈CRE(U(c))\bigcup_{c \in C_R} E(U(c)).

Suppose k=∣CR∣≥2k = |C_R| \ge 2. Consider the tuples (Tc)c∈CR(T_c)_{c \in C_R} of trivial motions that agree on every vertex lying in two or more of the sets U(c)U(c). Each tuple gives an infinitesimal motion of (R,E(R))(R, E(R)), since every edge lies in some U(c)U(c), and different tuples give different motions. RR is rigid, so these tuples form a space of dimension at most 3. A vertex in d≥2d \ge 2 of the sets is a point in their frontiers (Lemma 1), and the agreement there is 2(d−1)2(d - 1) linear equations, so the dimension is at least 3k−∑f2(d(f)−1)3k - \sum_f 2(d(f) - 1). Let WW be CRC_R with all their frontiers. WW is closed, and by Lemma 1, dW(f)d_W(f) is the number of sets U(c)U(c), c∈CRc \in C_R, that contain ff. By (1),

ρS(W)=∑f2(dW(f)−1)−3k≥−3,\rho_S(W) = \sum_f 2(d_W(f) - 1) - 3k \ge -3,

so WW is a target in SS, a contradiction. Hence k=1k = 1; as every vertex of RR has an edge in G[R]G[R], R⊆U(c)⊆RR \subseteq U(c) \subseteq R for the one core cc. So every rigid component is a live cluster. Conversely, a live cluster is rigid, so it lies in a rigid component, which is a live cluster; by the antichain of Lemma 1 the two are the same. □\square

Running time. The number of edges between cores and points never grows: the new core gets one edge for each point of F⊆XF \subseteq X, and each point of XX had an edge to a core of XX, which line L13 deletes. So after lines L1 and L2, SS has at most n+mn + m nodes and 2m2m edges. One MAX-CLOSURE runs a maximum flow on a network with O(n+m)O(n + m) nodes and arcs, and the flow value is at most the total weight 2n+3m2n + 3m; each augmenting path carries at least one unit and is found by breadth-first search in O(n+m)O(n + m), so one call costs O((n+m)2)O((n + m)^2). Two cores share a point in at most ∑fd(f)2≤(2m)2\sum_f d(f)^2 \le (2m)^2 ways, so one search makes O(m2)O(m^2) calls. Lines L7 to L9 make at most mm rounds, since each round removes a core, of at most mm searches each, and the main loop runs at most m−1m - 1 times (Theorem 5). The total is O(m5(n+m)2)O(m^5 (n + m)^2). □\square

Complexity

Let ss be the size of SS. The number of core-point edges never grows: a new core gets at most one edge for each point of XX, and each such point had an edge to a core of XX, which is deleted. So SS has at most n+mn + m nodes and 2m2m edges, and s=O(n+m)s = O(n + m). One MAX-CLOSURE is a maximum flow in a network with O(n+m)O(n + m) nodes and arcs, and the flow is at most w(V)+D⋅mw(V) + D \cdot m; with augmenting paths of Edmonds and Karp and the weights 2, 1 and 3, each path carries at least one unit, so one flow costs O((n+m)2)O((n + m)^2). There are O(m2)O(m^2) candidate pairs, since two cores share a point in at most ∑pd(p)2≤(2m)2\sum_p d(p)^2 \le (2m)^2 ways. Lines L7 to L9 make at most mm rounds, each of at most mm searches. The main loop runs at most m−1m - 1 times. That gives O(m5)O(m^5) flows and O(m5(n+m)2)O(m^5 (n + m)^2) time, a crude bound for this simple version, in which each flow starts from zero. The flow test of degrees of freedom analysis, which adds the constraints one at a time and keeps the flow, is faster. In the best case no two constraints share an entity: there are no candidate pairs and the work is Θ(n+m)\Theta(n + m), with an index from points to clusters for line L11. The Python code scans all clusters in line L11 and needs O(m2)O(m^2) for this case. Space is Θ(n+m)\Theta(n + m) for SS, the network and the plan.

As a measured point, the Python code takes about 2 seconds on a random graph with 20 points and 69 constraints.

Properties

  • Deterministic and exact. All weights are integers and the flows are integer flows, so the densities are exact. The order of the candidate pairs fixes which plan comes out.
  • Bottom-up and not unique. A graph can have many DR-plans. The plan depends on which target is found first, and the largest cluster size, the cost of the plan, can depend on that order.
  • Shared entities. A point in two live clusters is on the frontier of both, and it stays in SS until a cluster swallows both of them.
  • Counts only. The algorithm sees the graph and the weights, not the geometry. Dependent or special constraints, such as three collinear points, are not seen.

Variants and improvements

  • MFA. Hoffmann, Lomonosov and Sitharam also gave a modified Frontier algorithm, which changes how a cluster is found so that the plan stays closer to an optimal one more often (Part II).
  • Incremental flows. The flow test of degrees of freedom analysis adds the constraints one at a time and detects a dense set when the extra DD units of the new constraint cannot be pushed. It reuses the flow and is faster than a fresh flow for each pair.
  • Canonical DR-plans. For systems that are not over-constrained, Baker, Sitharam, Wang and Willoughby give canonical DR-plans and a polynomial algorithm that finds an optimal one, while optimal DR-planning is NP-hard in general.
  • The pebble game. For points and distances in the plane, the pebble game finds the rigid components in O(nm)O(nm) time. It gives the roots of the plan but not the plan below them.
  • Witness checks. A cluster that is dense by the count can still be flexible in space, or at special positions. A rank test at a random witness configuration can confirm each cluster.

When to use it

Use it when a constraint system must be solved in small pieces and the pieces can share entities, as in large 2D sketches and in assemblies of parts. It handles any weights, so it plans for points, lines, circles and rigid bodies with constraints of any number of equations. In the plane with points and distances its clusters are rigid. In space, or with special geometry, the counts can lie, and each cluster needs a check. If only the rigid components are needed, the pebble game is faster. If the whole system can be built by merging three clusters at a time, the triangle merges of Fudos and Hoffmann are simpler.

Pitfalls

  • Contracting a cluster to one node. It hides shared entities, and the planner then misses clusters such as the triangle 034 of the example. Keep the frontier vertices.
  • Shrinking by points. If the minimal step drops a frontier point of a core, the set is no longer closed and the core stands for points that are not there. The new frontier can then hold a core. Drop cores, and with them the points that no other core touches.
  • The density in the simplified graph. In SS every cluster counts as exactly −D-D. For K4K_4 with points and distances the last target has density −3-3 in SS, but ρ(V)=6−8=−2\rho(V) = 6 - 8 = -2 in GG: one constraint is redundant. Compute the density of a cluster in GG.
  • A single point is dense. With w(v)=2w(v) = 2 and D=3D = 3, one point has ρ=−2≥−3\rho = -2 \ge -3. Ask for at least two cores, or two entities, in every target.
  • Dense is not rigid in space. The double banana passes the count in space and is flexible. In the plane the counts are exact only for generic points and distances; other constraints, such as angles, break Laman's theorem.

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.

frontier_vertex_algorithm.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/frontier-vertex-algorithm/. The authors are listed in prov/HMKXPX.jsonl.

"""The Frontier vertex algorithm for a DR-plan of a weighted constraint graph.

Entities are the vertices 0..n-1, each with weight vertex_weight (its degrees of freedom), and constraints are the
edges, each with weight edge_weight. A set X is dense when rho(X) = w(E(X)) - w(X) >= -D. The default weights are
points and distances in the plane: 2, 1 and D = 3.

The planner first makes every constraint a cluster. Then it repeats: find a minimal dense set X of the simplified
graph that does not lie inside one cluster, by maximum closure computations with network flow; record the cluster
that X stands for; and simplify, which keeps the frontier vertices of the cluster (those with constraints to the
outside) and replaces the rest by one core vertex of weight D joined to each frontier vertex f by an edge of
weight w(f)."""

from collections import deque
from typing import Optional, Sequence

Edge = tuple[int, int]
BIG = 1 << 60


def max_flow(cap: list[dict[int, int]], s: int, t: int) -> int:
    """Edmonds-Karp on a residual graph given as a list of dicts; cap is changed into the residual graph."""
    flow = 0
    while True:
        parent = {s: s}
        queue = deque([s])
        while queue and t not in parent:
            x = queue.popleft()
            for y, c in cap[x].items():
                if c > 0 and y not in parent:
                    parent[y] = x
                    queue.append(y)
        if t not in parent:
            return flow
        push, y = BIG, t
        while y != s:
            push = min(push, cap[parent[y]][y])
            y = parent[y]
        y = t
        while y != s:
            x = parent[y]
            cap[x][y] -= push
            cap[y][x] = cap[y].get(x, 0) + push
            y = x
        flow += push


class FrontierPlanner:
    def __init__(self, n: int, edges: Sequence[Edge], vertex_weight: int = 2, edge_weight: int = 1,
                 D: int = 3) -> None:
        self.n, self.D = n, D
        self.vertex_weight, self.edge_weight = vertex_weight, edge_weight
        self.w: dict[int, int] = {v: vertex_weight for v in range(n)}
        self.adj: dict[int, dict[int, int]] = {v: {} for v in range(n)}
        for u, v in edges:
            if u == v:
                raise ValueError("loop")
            self.adj[u][v] = self.adj[u].get(v, 0) + edge_weight
            self.adj[v][u] = self.adj[v].get(u, 0) + edge_weight
        self.edges = list(edges)
        self.clusters: list[dict] = []
        self.core_of: dict[int, int] = {}
        self.next_id = n

    # ----- the simplified graph -----

    def orig(self, x: int) -> frozenset:
        return frozenset([x]) if x < self.n else self.clusters[self.core_of[x]]["vertices"]

    def density(self, X: set) -> int:
        inside = sum(wt for x in X for y, wt in self.adj[x].items() if y in X) // 2
        return inside - sum(self.w[x] for x in X)

    def close(self, Z: set, Y: set) -> set:
        """Add the frontier of every core in Z; this never lowers the density."""
        Z = set(Z)
        for c in [x for x in Z if x >= self.n]:
            Z |= {f for f in self.adj[c] if f in Y}
        return Z

    def max_closure(self, Y: set, T: set) -> tuple[int, set]:
        """The largest density of a set Z with T <= Z <= Y, and such a set, by one minimum cut."""
        ys = sorted(Y)
        idx = {x: i + 2 for i, x in enumerate(ys)}
        es = [(x, y, wt) for x in ys for y, wt in self.adj[x].items() if y in Y and x < y]
        cap: list[dict[int, int]] = [dict() for _ in range(2 + len(ys) + len(es))]
        for k, (x, y, wt) in enumerate(es):
            e = 2 + len(ys) + k
            cap[0][e] = wt
            cap[e][idx[x]] = BIG
            cap[e][idx[y]] = BIG
        for x in ys:
            if x not in T:
                cap[idx[x]][1] = self.w[x]
        f = max_flow(cap, 0, 1)
        seen, queue = {0}, deque([0])
        while queue:
            a = queue.popleft()
            for b, c in cap[a].items():
                if c > 0 and b not in seen:
                    seen.add(b)
                    queue.append(b)
        Z = {x for x in ys if idx[x] in seen} | set(T)
        return sum(wt for _, _, wt in es) - f - sum(self.w[x] for x in T), Z

    def candidate_pairs(self, Y: set) -> list[tuple[int, int]]:
        """Pairs that every dense set not inside one cluster must contain one of: the two ends of a constraint
        that is not yet in a cluster, or two cores whose frontiers share a vertex."""
        pairs = set()
        for x in Y:
            nbrs = sorted(y for y in self.adj[x] if y in Y)
            if x < self.n:
                pairs |= {(x, y) for y in nbrs if y < self.n and x < y}
                cores = [y for y in nbrs if y >= self.n]
                pairs |= {(a, b) for i, a in enumerate(cores) for b in cores[i + 1:]}
        return sorted(pairs)

    def find_dense(self, Y: set) -> Optional[set]:
        for a, b in self.candidate_pairs(Y):  # @line L4
            value, Z = self.max_closure(Y, {a, b})  # @line L5
            if value >= -self.D:  # @line L5
                return self.close(Z, Y)
        return None

    def minimal(self, X: set) -> set:
        """Shrink a dense set to one that has no proper dense subset outside every cluster."""
        changed = True
        while changed:  # @line L7
            changed = False
            for c in sorted(x for x in X if x >= self.n):
                Y = set(X) - {c}
                Y = {y for y in Y if any(z in Y for z in self.adj[y])}
                Z = self.find_dense(Y)  # @line L8
                if Z is not None:
                    X, changed = Z, True  # @line L9
                    break
        return X

    def original_density(self, U: frozenset) -> int:
        inside = sum(self.edge_weight for u, v in self.edges if u in U and v in U)
        return inside - self.vertex_weight * len(U)

    def simplify(self, X: set) -> int:
        U = frozenset().union(*(self.orig(x) for x in X))  # @line L10
        rho = self.original_density(U)
        cores = {c for c in self.core_of if c in self.adj and self.orig(c) <= U}  # @line L11
        Xp = set(X) | cores
        children = sorted(self.core_of[c] for c in cores)
        covered = frozenset().union(*(self.clusters[i]["vertices"] for i in children))
        frontier = {x for x in Xp if any(y not in Xp for y in self.adj[x])}  # @line L12
        assert all(x < self.n for x in frontier)
        for x in Xp:
            for y in list(self.adj[x]):
                if y in Xp:
                    del self.adj[x][y]
        for x in Xp - frontier:  # @line L13
            for y in self.adj.pop(x):
                del self.adj[y][x]
            del self.w[x]
        c = self.next_id  # @line L14
        self.next_id += 1
        self.w[c] = self.D
        self.adj[c] = {}
        for f in frontier:
            self.adj[c][f] = self.adj[f][c] = self.w[f]  # @line L14
        self.core_of[c] = len(self.clusters)
        self.clusters.append({"vertices": U, "children": children, "leaves": sorted(U - covered),
                              "frontier": frozenset(frontier), "density": rho})  # @line L15
        return c

    # ----- the algorithm -----

    def run(self) -> list[dict]:
        for u, v in self.edges:  # @line L1
            if u in self.adj and v in self.adj[u]:
                self.simplify({u, v})  # @line L2
        while True:  # @line L3
            X = self.find_dense(set(self.adj))  # @line L4
            if X is None:
                break  # @line L6
            X = self.minimal(X)  # @line L7
            self.simplify(X)  # @line L10
        return self.clusters  # @line L16

    def roots(self) -> list[frozenset]:
        """The clusters that are not children of another cluster, and the vertices in no cluster."""
        live = [self.clusters[i]["vertices"] for c, i in self.core_of.items() if c in self.adj]
        covered = frozenset().union(*live) if live else frozenset()
        return live + [frozenset([v]) for v in range(self.n) if v not in covered]


def frontier_dr_plan(n: int, edges: Sequence[Edge], vertex_weight: int = 2, edge_weight: int = 1,
                     D: int = 3) -> tuple[list[dict], list[frozenset]]:
    """The clusters of the DR-plan, in the order made, and its roots."""
    planner = FrontierPlanner(n, edges, vertex_weight, edge_weight, D)
    clusters = planner.run()
    return clusters, planner.roots()
test_frontier_vertex_algorithm.py 126 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/frontier-vertex-algorithm/. The authors are listed in prov/HMKXPX.jsonl.

import random
from itertools import combinations

from frontier_vertex_algorithm import FrontierPlanner, frontier_dr_plan


def laman_rank(vertices, edges):
    """The generic rank in the plane by the Laman count: a greedy basis, each step checked by brute force
    over all vertex subsets of size k >= 2 (at most 2k - 3 edges each)."""
    vs = sorted(vertices)
    subsets = [set(X) for k in range(2, len(vs) + 1) for X in combinations(vs, k)]
    count = [0] * len(subsets)
    rank = 0
    for u, v in edges:
        if u not in vertices or v not in vertices:
            continue
        hit = [i for i, X in enumerate(subsets) if u in X and v in X]
        if all(count[i] < 2 * len(subsets[i]) - 3 for i in hit):
            rank += 1
            for i in hit:
                count[i] += 1
    return rank


def is_rigid(U, edges):
    return len(U) >= 2 and laman_rank(U, edges) == 2 * len(U) - 3


def rigid_components(n, edges):
    """The maximal vertex sets with at least two vertices that are generically rigid in the plane."""
    rigid = [frozenset(X) for k in range(2, n + 1) for X in combinations(range(n), k) if is_rigid(set(X), edges)]
    return {X for X in rigid if not any(X < Y for Y in rigid)}


def random_graph(rng, n, prob):
    return [e for e in combinations(range(n), 2) if rng.random() < prob]


def check_plan(n, edges):
    clusters, roots = frontier_dr_plan(n, edges)
    for c in clusters:
        U = c["vertices"]
        # every cluster is rigid by the Laman count, and its density is at least -3
        assert is_rigid(set(U), edges), (edges, sorted(U))
        assert c["density"] >= -3
        # every node is the union of its children and its leaves, and each child is a proper subset
        parts = [clusters[i]["vertices"] for i in c["children"]] + [frozenset([v]) for v in c["leaves"]]
        assert frozenset().union(*parts) == U
        assert all(P < U for P in parts)
        assert all(i < clusters.index(c) for i in c["children"])
    # the plan covers the graph: every edge lies in a root, and every vertex in exactly the roots listed
    for u, v in edges:
        assert any(u in R and v in R for R in roots)
    assert frozenset().union(*roots) == frozenset(range(n)) if n else True
    # each cluster is a child of at most one later cluster, so the roots are the clusters never used as children
    used = [i for c in clusters for i in c["children"]]
    assert len(used) == len(set(used))
    return clusters, roots


def test_random_graphs_clusters_rigid_and_plan_covers():
    rng = random.Random(1)
    for _ in range(40):
        n = rng.randint(2, 7)
        edges = random_graph(rng, n, rng.choice([0.4, 0.6, 0.8]))
        check_plan(n, edges)


def test_roots_are_the_rigid_components():
    rng = random.Random(2)
    for _ in range(25):
        n = rng.randint(3, 6)
        edges = random_graph(rng, n, rng.choice([0.5, 0.7]))
        _, roots = check_plan(n, edges)
        assert {R for R in roots if len(R) >= 2} == rigid_components(n, edges)


def test_prism():
    edges = [(0, 1), (0, 2), (1, 2), (3, 4), (3, 5), (4, 5), (0, 3), (1, 4), (2, 5)]
    clusters, roots = check_plan(6, edges)
    big = [c["vertices"] for c in clusters if len(c["vertices"]) >= 3]
    assert big == [frozenset({0, 1, 2}), frozenset({3, 4, 5}), frozenset(range(6))]
    assert roots == [frozenset(range(6))]
    last = clusters[-1]
    assert len(last["children"]) == 5 and last["density"] == -3


def test_shared_vertex_kept_by_frontier():
    """Vertex 0 lies in the triangle 012 and in the triangle 034; it stays a frontier vertex after 012 becomes a
    cluster, so the triangle 034 is still found, inside the rigid cluster 0345."""
    edges = [(0, 1), (0, 2), (1, 2), (3, 4), (3, 5), (4, 5), (0, 3), (0, 4), (1, 5)]
    clusters, roots = check_plan(6, edges)
    tri = next(c for c in clusters if c["vertices"] == frozenset({0, 1, 2}))
    assert 0 in tri["frontier"]
    sets = [c["vertices"] for c in clusters]
    assert frozenset({0, 3, 4, 5}) in sets
    assert roots == [frozenset(range(6))]
    assert clusters[-1]["density"] == -3


def test_hinged_bodies_are_two_roots():
    edges = [(0, 1), (0, 2), (1, 2), (2, 3), (2, 4), (3, 4)]
    _, roots = check_plan(5, edges)
    assert sorted(map(sorted, roots)) == [[0, 1, 2], [2, 3, 4]]


def test_over_constrained_k4():
    edges = list(combinations(range(4), 2))
    clusters, roots = check_plan(4, edges)
    assert roots == [frozenset(range(4))]
    assert clusters[-1]["density"] == -2


def test_isolated_vertex_is_a_root():
    _, roots = check_plan(4, [(0, 1), (1, 2), (0, 2)])
    assert frozenset([3]) in roots and frozenset([0, 1, 2]) in roots


def test_frontier_vertices_are_reported():
    planner = FrontierPlanner(5, [(0, 1), (0, 2), (1, 2), (2, 3), (3, 4), (2, 4)])
    clusters = planner.run()
    tri = next(c for c in clusters if c["vertices"] == frozenset({0, 1, 2}))
    assert tri["frontier"] == frozenset({2})

History

Earlier planners of the 1990s, such as the triangle merges of Fudos and Hoffmann and the splits of Owen, found rigid parts by patterns in the graph. In 1997 Hoffmann, Lomonosov and Sitharam showed how to find dense subgraphs of any weighted constraint graph with network flows, and how to shrink a dense subgraph to a minimal one. In 2001 they defined DR-plans and measures to compare planners (Part I), and gave the Frontier algorithm and its modified form (Part II), with the simplification to frontier vertices and a core. Later work by Sitharam and others studied optimal and canonical DR-plans; Baker, Sitharam, Wang and Willoughby (2015) showed that optimal DR-planning is NP-hard for over-constrained 2D systems and gave a polynomial algorithm for a broad class of other systems.

References

  1. Christoph M. Hoffmann, Andrew Lomonosov and Meera Sitharam, Decomposition plans for geometric constraint problems, Part II, New algorithms, Journal of Symbolic Computation 31(4), 409 to 427, 2001, the Frontier algorithm, its simplification of a cluster to its frontier vertices and one core vertex, and its modified form MFA (general locator)
  2. Christoph M. Hoffmann, Andrew Lomonosov and Meera Sitharam, Decomposition plans for geometric constraint systems, Part I, Performance measures for CAD, Journal of Symbolic Computation 31(4), 367 to 408, 2001, the definition of a DR-plan and the measures by which DR-planners are compared (general locator)
  3. Christoph M. Hoffmann, Andrew Lomonosov and Meera Sitharam, Finding solvable subsets of constraint graphs, Principles and Practice of Constraint Programming (CP97), LNCS 1330, 1997, the network flow test for dense subgraphs and the reduction of a dense subgraph to a minimal one (general locator)
  4. G. Laman, On graphs and rigidity of plane skeletal structures, Journal of Engineering Mathematics 4(4), 331 to 340, 1970, the counts that make a minimal dense set of points and distances rigid in the plane
  5. Troy Baker, Meera Sitharam, Menghan Wang and Joel Willoughby, Optimal decomposition and recombination of isostatic geometric constraint systems for designing layered materials, Computer Aided Geometric Design 40, 1 to 25, 2015, the abstract and introduction, on canonical DR-plans and the hardness of optimal DR-planning

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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example