---
title: Wiggle Count Minimization
url: https://www.emergentmind.com/topics/wiggle-count-minimization
type: topic
---

# Wiggle Count Minimization

In storyline visualization, wiggle count minimization is the optimization problem of minimizing how often characters change vertical position between consecutive time steps. A storyline represents interactions over time by drawing each character as an \(x\)-monotone curve, and a wiggle occurs whenever a character’s \(y\)-coordinate differs from one layer to the next. The resulting objective, denoted WCMin, is distinct from related wiggle-minimization problems in stacked area charts, where wiggle is defined through border changes of cumulative layers, and from unrelated uses of “wiggles” in spectroscopy or self-similar geometry [2508.19802], [2506.21175].

## 1. Formal definition and storyline model

A storyline visualization represents a temporal hypergraph: characters are vertices, and meetings or interactions are hyperedges occurring at particular time steps. The paper models an ordered storyline instance as
\[
(\mathcal{C}, T, \mathcal{M}, A),
\]
where \(\mathcal{C}=\{c_1,\dots,c_n\}\) is the set of characters, \(T=[\ell]\) is the ordered set of time steps or layers, \(\mathcal{M}\) is the set of meetings, and \(A(c)\subseteq T\) is the consecutive active interval of character \(c\). Each meeting \(M\in\mathcal{M}\) has a time stamp \(\tm(M)\in[\ell]\), and its participant set is \(\charac(M)\subseteq \mathcal{C}\). At each time \(t\), the active characters \(\mathcal{A}(t)\) are placed in a vertical order \(\pi_t\), and every meeting at time \(t\) must appear as a consecutive block in that order [2508.19802].

A valid coordination assigns each active character \(c\in\mathcal{A}(t)\) a \(y\)-coordinate \(y_{t,c}\) such that
\[
c\prec_t c' \implies y_{t,c}<y_{t,c'}.
\]
A “nice” coordination additionally enforces equal spacing inside meetings and minimum spacing otherwise. Within this model, a wiggle is the vertical movement a character experiences between consecutive time steps, and the paper distinguishes three objective functions:

| Objective | Definition | Interpretation |
|---|---|---|
| Total linear wiggle height | \(\LWH(y)=\sum_{t=1}^{\ell-1}\sum_{c\in \mathcal{A}(t)\cap \mathcal{A}(t+1)} |y_{t,c}-y_{t+1,c}|\) | Sums absolute movement |
| Total quadratic wiggle height | \(\QWH(y)=\sum_{t=1}^{\ell-1}\sum_{c\in \mathcal{A}(t)\cap \mathcal{A}(t+1)} (y_{t,c}-y_{t+1,c})^2\) | Penalizes large movements more strongly |
| Total wiggle count | \(\WC(y)=\left|\{(t,c)\mid 1 \le t\le \ell-1,\ c\in \mathcal{A}(t)\cap \mathcal{A}(t+1),\ y_{t,c}\ne y_{t+1,c}\}\right|\) | Counts nonzero wiggles |

The total wiggle count therefore measures how many times a character changes vertical position from one time step to the next. The paper explicitly notes that this aligns with the intuitive idea of wiggles as inflection points in character curves [2508.19802].

## 2. Complexity of WCMin

The central complexity result is that the decision variant of WCMin is NP-complete. NP-membership is established through a polynomial certificate: a set \(X\subseteq \mathcal{C}\times[\ell-1]\) of character-time pairs claimed to be wiggle-free. Feasibility is then checked by solving a linear program consisting of the ordering constraints together with equalities \(y_{t,c}=y_{t+1,c}\) for every \((c,t)\in X\) [2508.19802].

NP-hardness is proved by reduction from Planar Monotone 3-SAT (PM3-SAT). The source instance is a planar rectilinear embedding of the variable-clause graph in which all variables lie on one horizontal line, positive clauses lie above, negative clauses lie below, and edges are vertical. The constructed storyline instance uses three components: variable gadgets, clause gadgets, and a rigid frame [2508.19802].

The variable gadget has exactly two low-wiggle realizations corresponding to TRUE and FALSE. The key property stated in the paper is that the gadget can be drawn with \(|C_v|\) wiggles in one of two consistent states, but if forced into an inconsistent state it needs \(2|C_v|\) wiggles. The characters are partitioned into positive and negative wire characters, and the gadget semantics are summarized as follows: if the variable gadget has \(|C_v|\) wiggles, then either all positive wire characters are satisfying and all negative wire characters are not satisfying, or vice versa [2508.19802].

For a positive clause with three literals, the clause gadget admits two costs: if at least one wire character is satisfying, the gadget can be realized with \(5\) wiggles; if none is satisfying, it requires \(6\) wiggles. This one-wiggle gap is the logical mechanism of the reduction. The rigid frame prevents global rearrangements that would otherwise invalidate the gadget semantics. The reduction proves that satisfiability of the PM3-SAT instance is equivalent to the existence of a nice coordination with at most the specified wiggle budget, so WCMin is NP-complete [2508.19802].

## 3. Optimization models and algorithmic contrasts

Because WCMin is NP-complete, the paper provides an integer linear program for practical optimization. The formulation uses integer variables \(y_{t,c}\) for coordinates and binary variables \(z_{t,c}\in\{0,1\}\) to indicate whether character \(c\) wiggles between \(t\) and \(t+1\). The objective is
\[
\min \sum_{t\in[\ell-1]}\sum_{c\in \mathcal{A}(t)\cap\mathcal{A}(t+1)} z_{t,c}.
\]
Coordinate equality and inequality are linked to \(z_{t,c}\) through a large constant \(Y_{\max}\):
\[
y_{t,c} + Y_{\max} z_{t,c} \ge y_{t+1,c},
\]
\[
y_{t,c} - Y_{\max} z_{t,c} \le y_{t+1,c}.
\]
If \(z_{t,c}=0\), these constraints force equality, so there is no wiggle. The same ordering constraints as in the general storyline model are included. In practice, the authors also add a secondary height objective by introducing drawing height \(h\), constraining \(y_{t,c}\le h\), and adding \(h/Y_{\max}\) to the objective; this is used to avoid solutions with unnaturally large vertical extent [2508.19802].

The same paper contrasts WCMin with two wiggle-height objectives that admit efficient mathematical programming formulations. LWHMin is expressed as a linear program with coordinate variables \(y_{t,c}\) and linear wiggle variables \(w_{t,c}\), using standard absolute-value linearization:
\[
y_{t,c}-y_{t+1,c}\le w_{t,c},\qquad y_{t+1,c}-y_{t,c}\le w_{t,c}.
\]
A notable structural property is that if the spacing parameter is integral, then all extreme points of the LWHMin polytope are integral. QWHMin uses the same feasibility region but replaces the objective by a convex quadratic function,
\[
\min \sum_{t\in[\ell-1]}\sum_{c\in \mathcal{A}(t)\cap\mathcal{A}(t+1)} w_{t,c}^2,
\]
or equivalently \(\sum (y_{t,c}-y_{t+1,c})^2\). Because the objective matrix is positive semidefinite, QWHMin can be solved in polynomial time [2508.19802].

This yields a sharp algorithmic contrast: minimizing the number of wiggles is NP-complete, whereas minimizing linear or quadratic wiggle height is polynomial-time solvable under the same ordering constraints [2508.19802].

## 4. Relation to stacked area chart wiggle minimization

A closely related but distinct line of work studies wiggle minimization for stacked area charts. A stacked area chart shows \(n\) time series \(F=\{f_1,\dots,f_n\}\) over \(\ell\) discrete time points, with the series arranged in some vertical order \(\pi\). For a permutation \(\pi\) and prefix size \(i\), the border-change quantity is defined as
\[
W^\pi_{i,j}=\sum_{k=1}^i \big(\pi(k)(j+1)-\pi(k)(j)\big), \qquad i\in\{0\}\cup[n],\ j\in[\ell-1].
\]
This is the vertical change in the cumulative height of the first \(i\) series between time \(j\) and \(j+1\). Wiggle is then the sum of the magnitudes of these changes over all borders and time intervals [2506.21175].

For integer \(p\ge 1\), the unweighted problem is
\[
\min_\pi \sum_{i=1}^{n}\sum_{j=1}^{\ell-1}|W^\pi_{i,j}|^p,
\]
and the weighted version is
\[
\min_\pi \sum_{i=1}^{n}\sum_{j=1}^{\ell-1} \frac{\pi(i)(j)+\pi(i)(j+1)+\pi(i+1)(j)+\pi(i+1)(j+1)}{4}\,|W^\pi_{i,j}|^p,
\]
with \(\pi(n+1)\) treated as the all-zero series. The paper states that the key point is that the total wiggle depends only on the vertical order \(\pi\), not on the data values themselves, once the time series are fixed [2506.21175].

The paper isolates a two-time-point special case corresponding to the problem of ordering a set of numbers so as to minimize the sum of absolute prefix sums:
\[
\sum_{i=1}^n \left|\sum_{j=1}^{i}\pi(j)\right|.
\]
It proves an exact equivalence between this problem and \(1\)-WiggleMin on two time points. A simple lower bound is
\[
\sum_{i=1}^n |P_i^\pi| \ge \frac12 \sum_{s\in S}|s|,
\]
and an ordering achieving this bound is called bound-achieving. Using this structure, the paper proves that the decision version is strongly NP-complete via a reduction from Numerical 3-Dimensional Matching. It also studies the restricted case with exactly one negative element or exactly one positive element: if \(\sum_i s_i=0\), the problem can be solved in \(O(n\log n)\), but the decision problem remains NP-complete even with exactly one negative or one positive element [2506.21175].

For arbitrary fixed integer \(p\ge 1\), the paper reduces from Minimum Linear Arrangement (MLA) and shows that \(p\)-WiggleMin and Weighted-\(p\)-WiggleMin are strongly NP-complete. The same reduction transfers approximation hardness: a PTAS would imply that SAT could be solved in time \(2^{n^\epsilon}\) for arbitrarily small \(\epsilon>0\), and under the Small-Set Expansion Hypothesis there is no constant-factor approximation for either problem. The greedy heuristic BestFirst, which repeatedly appends the remaining time series causing the smallest immediate increase in the objective, has worst-case approximation factor at least
\[
\Omega(\sqrt[3]{n})
\]
for Min-\(\sum |prefix|\), \(1\)-WiggleMin, and Weighted-\(1\)-WiggleMin [2506.21175].

Thus, stacked area chart wiggle minimization and storyline WCMin share a common combinatorial theme—optimization over order-induced vertical variation—while differing in both objective function and geometric semantics [2506.21175].

## 5. Empirical behavior and trade-offs among wiggle objectives

The storyline study emphasizes that the three wiggle objectives are not interchangeable. Its case study on benchmark storyline instances reports that WCMin can reduce the number of wiggles, but it may produce large individual wiggles. QWHMin discourages large wiggles strongly, but may allow many wiggles and can lead to wider drawings under the chosen rendering style. LWHMin was reported to be the most consistent overall, producing visually balanced results more reliably than the others. The paper explicitly concludes that optimizing one wiggle metric can harm the others: minimizing wiggle count does not necessarily minimize total wiggle magnitude, minimizing quadratic height may over-penalize large moves but not reduce wiggle count, and linear wiggle height gives a good compromise in the experiments. For one larger instance, the WCMin ILP did not finish within \(24\) hours [2508.19802].

The same work also introduces a routing method for rendering wiggles smoothly. Each wiggle is drawn as two circular arcs meeting tangentially, and the required horizontal space satisfies
\[
dx^2 = 2(r'_{t,c}+r''_{t,c})\,dy_{t,c} - dy_{t,c}^2,
\]
where \(dy_{t,c}=|y_{t,c}-y_{t+1,c}|\). The routing method aims to keep neighboring curves at constant distance when they wiggle in parallel by using concentric arcs and preserving relative spacing. The authors note that this improves readability, though it can produce wider drawings. The case study also presents a new use case for storylines: visualization of rolling stock schedules in railway operation [2508.19802].

For stacked area charts, the experimental picture is different but comparable in spirit. The paper compares an exact MILP, WiggleMILP, with the state-of-the-art heuristic UpwardsOpt, which repeatedly removes and reinserts a series in the best position. On the instances solved optimally by the MILP, UpwardsOpt found the optimum on \(89\) of \(263\) cases, the optimality gaps were generally small, and UpwardsOpt was much faster with no timeouts in the experiments. WiggleMILP could solve small-to-medium instances exactly, but timed out already for some instances with around \(20\) time series [2506.21175].

Across both literatures, the practical picture is therefore not one of a single universally preferred wiggle criterion. The papers instead separate count, linear magnitude, and quadratic magnitude as different optimization targets with different computational and visual consequences [2508.19802], [2506.21175].

## 6. Terminological scope and domain disambiguation

The term “wiggle” is used in several technically unrelated arXiv contexts, and only some of them concern wiggle count minimization. In JWST NIRSpec integral field spectroscopy, “wiggles” are resampling noise artifacts in single-spaxel spectra caused by undersampling of the NIRSpec point-spread function when \(2\)-D detector data are resampled into \(3\)-D IFU datacubes. The package \(\texttt{raccoon}\) removes these artifacts by empirically fitting them as a multiplicative, wavelength-dependent resampling-noise pattern on top of a smooth, non-wiggly template spectrum. Its forward model is
\[
M(\lambda)=W(\lambda)\,T(\lambda),
\]
with \(W(\lambda)\) represented as a sinusoidal chirp whose amplitude and local frequency vary with wavelength. This is a correction problem, not a wiggle count minimization problem [2507.13341].

In a different direction, “Wiggle Island” defines a wiggle as an embedded self-similar curve \(w_z(I)\) arising as the limit of an iterated function system with maps
\[
f_z: x \to -zx+z, \qquad g_z: x \to (z-1)x+1,
\]
for parameters satisfying \(|z|<1\) and \(|1-z|<1\). The paper proves that the set of such wiggles is disconnected by exhibiting a wiggle island near \(z\approx 0.3409+0.43486i\). The paper explicitly does not study wiggle count as an optimization problem in the usual sense [2205.11442].

These distinctions matter because the phrase “wiggle count minimization” is meaningful only in settings where wiggle is defined combinatorially or geometrically as a countable event, such as character movements in storylines. In current arXiv usage represented here, storyline visualization provides the explicit formulation of wiggle count minimization, while stacked area charts provide the closest related family of wiggle-ordering problems [2508.19802], [2506.21175].

Source: https://www.emergentmind.com/topics/wiggle-count-minimization