<p>Probably the simplest approach is to perturb the edge weights <em>symbolically</em> rather than <em>numerically</em>.  Intuitively, you'd like to reassign the weight of each edge as
$$
\tilde{w}(e) = w(e) + \varepsilon \cdot w'(e)
$$
where $w(e)$ is the original edge weight, $w'(e)$ is a secondary edge weight, and $\varepsilon$ is a global scaling factor.  This perturbation scheme has to satisfy two requirements:</p>

<ul>
<li><p><strong>Every shortest path with respect to the perturbed edge weights must be also a shortest path with respect to the original edge weights.</strong>  It's not hard to prove that for <em>any</em> function $w'$, this property holds for all <em>sufficiently small</em> scaling factors $\varepsilon$.  Rather than spending time figuring out how small "sufficiently small" is, consider instead the limiting behavior as $\varepsilon$ approaches $0$.  Then your perturbed edge weights are best formalized as two-dimensional vectors
$$
\tilde{w}(e) = \big( w(e), w'(e) \big).
$$
The length of any path is also a vector, obtained by summing the vector-weights of each edge on the path.  Comparisons between length vectors are performed lexicographically:
$$
(a, a') &lt; (b, b') \iff a&lt;b \text{ or } (a = b \text{ and } a'&lt;b')
$$
This definition trivially implies that for any paths $\alpha$ and $\beta$, if $w(\alpha) &lt; w(\beta)$, then $\tilde{w}(\alpha) &lt; \tilde{w}(\beta)$.  One nice feature of this scheme is that if shortest paths with respect to $w$ are already unique, the algorithm never even notices $w'$.</p></li>
<li><p><strong>Shortest paths with respect to the perturbed edge weights must be unique.</strong>  It suffices to choose a function $w'$ such that shortest paths with respect to $w'$ are unique.  There are two standard methods for finding such a function $w'$.</p>

<ol>
<li><p>The simplest method is to generate each $w'(e)$ <em>randomly</em>.  The <a href="http://en.wikipedia.org/wiki/Isolation_lemma">Isolation Lemma</a> of Mulmuley, Vazirani, and Vazirani implies that if each $w'(e)$ is chosen independently and uniformly at random from the set $\{1, 2, \dots, n^4\}$, then with probability $1-O(1/n)$, all shortest paths are unique.  This scheme works for any shortest path algorithm with no run-time penalty and little modification to the algorithm, but it does have a small probability of failure.</p></li>
<li><p>A more complex deterministic method (which linear-programming people know as "lexicographic perturbation") indexes the edges from $1$ to $m$ and defines $w'(e_i) = 2^i$.  Clearly every subset of edges has distinct total $w'$eight.  However, using this method requires manipulating $m$-bit integers, so it's more efficient to implement this method symbolically as well.  For any paths $\alpha$ and $\beta$, we have $w'(\alpha) &lt; w'(\beta)$ if and only if the minimum edge-index in $\alpha\setminus\beta$ is smaller than the minimum edge-index in $\beta\setminus\alpha$.  Most shortest-path algorithms only compare paths that share a common prefix (starting at some source node $s$) and are otherwise edge-disjoint.  With an appropriate dynamic tree data structure (e.g., <a href="http://en.wikipedia.org/wiki/Link/cut_tree">link-cut trees</a> or <a href="http://en.wikipedia.org/wiki/Top_tree">top trees</a>), it is possible to find the node where the two paths split and the minimum edge-index along the disjoint suffixes in $O(\log n)$ amortized time.  So, this scheme is always correct, but it imposes a penalty in the running time that is only $O(\log n)$ <em>if</em> your algorithm has the right structure, and it requires significant data structure overhead.</p></li>
</ol></li>
</ul>

<p>You can guess which method I recommend.  My recent <a href="http://www.cs.uiuc.edu/~jeffe/pubs/multishort.html">journal paper</a> with Sergio Cabello and Erin Chambers describes both of these perturbation schemes in more detail.</p>

<p>There are also more specialized methods for specific algorithms and specific classes of graphs.</p>

<blockquote>
  <p>I would also like the "perturbed" shortest path to be chosen uniformly at random from the set of original shortest paths. Is this possible?</p>
</blockquote>

<p>I don't know.  In particular, the randomized perturbation scheme I described does <em>not</em> have this property.</p>

CC BY-SA 3.0
2013-05-10T18:55:23.810Z
Thanks a lot, Jeff. This is a great answer and gave me a lot of insights.
Matteo
CC BY-SA 3.0
2015-06-28T17:16:25.277Z
Nice answer. I also read your journal paper and would be interested if these techniques could be extended to euclidean instances. (Full question: http://cstheory.stackexchange.com/questions/31851/lexicographic-perturbation-for-euclidean-shortest-path-instances )
Listing
CC BY-SA 3.0
2013-05-10T14:35:07.083Z
2013-05-10T14:40:29.590Z
2013-05-10T14:40:29.590Z
Jeffε
<p>I have a graph $G=(V,E)$, with positive weights $w_e, e\in E$ on the edges, and I would like to randomly perturb the weights of the edges so that for each pair of distinct vertices $(u,v)$ such that there is a path from $u$ to $v$, there is, after perturbation, a unique shortest path from $u$ to $v$, and this shortest path is one of the "original" shortest paths, that is, one of the shortest paths before the perturbation. It seems to me that the perturbation can only be additive and at most equal to the minimum difference between two edge weights divided by the maximum number of vertices in a shortest paths between pair of vertices in $G$ (let this number be $\Delta$). That is, the perturbation that I add to the edge $e\in E$ should be some
$$ \varepsilon_e \in\left[0, \frac{\min_{\ell,r\in E}|w_\ell-w_r|}{\Delta}\right]
$$
and distributed according to some distribution (is uniform sufficient?) on the interval. </p>

<p>Possibly, I would also like the "perturbed" shortest path to be chosen uniformly at random from the set of original shortest paths. Is this possible? 
Any reference or hint is appreciated.
Thanks.</p>

<reference-request><graph-algorithms><randomized-algorithms><shortest-path>
Shortest paths perturbation
Matteo
# Shortest paths perturbation

(Asked by: username_0 on 2013-05-09)

I have a graph $G=(V,E)$, with positive weights $w\_e, e\in E$ on the edges, and I would like to randomly perturb the weights of the edges so that for each pair of distinct vertices $(u,v)$ such that there is a path from $u$ to $v$, there is, after perturbation, a unique shortest path from $u$ to $v$, and this shortest path is one of the "original" shortest paths, that is, one of the shortest paths before the perturbation. It seems to me that the perturbation can only be additive and at most equal to the minimum difference between two edge weights divided by the maximum number of vertices in a shortest paths between pair of vertices in $G$ (let this number be $\Delta$). That is, the perturbation that I add to the edge $e\in E$ should be some
$$ \varepsilon\_e \in\left[0, \frac{\min\_{\ell,r\in E}|w\_\ell-w\_r|}{\Delta}\right]
$$
and distributed according to some distribution (is uniform sufficient?) on the interval.

Possibly, I would also like the "perturbed" shortest path to be chosen uniformly at random from the set of original shortest paths. Is this possible?
Any reference or hint is appreciated.
Thanks.

**Tags:** reference-request, graph-algorithms, randomized-algorithms, shortest-path


---

## 1 answers

### Answer by username_1 on 2013-05-10. Score: 13 | Accepted answer

Probably the simplest approach is to perturb the edge weights *symbolically* rather than *numerically*. Intuitively, you'd like to reassign the weight of each edge as
$$
\tilde{w}(e) = w(e) + \varepsilon \cdot w'(e)
$$
where $w(e)$ is the original edge weight, $w'(e)$ is a secondary edge weight, and $\varepsilon$ is a global scaling factor. This perturbation scheme has to satisfy two requirements:

* **Every shortest path with respect to the perturbed edge weights must be also a shortest path with respect to the original edge weights.** It's not hard to prove that for *any* function $w'$, this property holds for all *sufficiently small* scaling factors $\varepsilon$. Rather than spending time figuring out how small "sufficiently small" is, consider instead the limiting behavior as $\varepsilon$ approaches $0$. Then your perturbed edge weights are best formalized as two-dimensional vectors
  $$
  \tilde{w}(e) = \big( w(e), w'(e) \big).
  $$
  The length of any path is also a vector, obtained by summing the vector-weights of each edge on the path. Comparisons between length vectors are performed lexicographically:
  $$
  (a, a') < (b, b') \iff a
* **Shortest paths with respect to the perturbed edge weights must be unique.** It suffices to choose a function $w'$ such that shortest paths with respect to $w'$ are unique. There are two standard methods for finding such a function $w'$.

  1. The simplest method is to generate each $w'(e)$ *randomly*. The [Isolation Lemma](http://en.wikipedia.org/wiki/Isolation_lemma) of Mulmuley, Vazirani, and Vazirani implies that if each $w'(e)$ is chosen independently and uniformly at random from the set $\{1, 2, \dots, n^4\}$, then with probability $1-O(1/n)$, all shortest paths are unique. This scheme works for any shortest path algorithm with no run-time penalty and little modification to the algorithm, but it does have a small probability of failure.
  2. A more complex deterministic method (which linear-programming people know as "lexicographic perturbation") indexes the edges from $1$ to $m$ and defines $w'(e\_i) = 2^i$. Clearly every subset of edges has distinct total $w'$eight. However, using this method requires manipulating $m$-bit integers, so it's more efficient to implement this method symbolically as well. For any paths $\alpha$ and $\beta$, we have $w'(\alpha) < w'(\beta)$ if and only if the minimum edge-index in $\alpha\setminus\beta$ is smaller than the minimum edge-index in $\beta\setminus\alpha$. Most shortest-path algorithms only compare paths that share a common prefix (starting at some source node $s$) and are otherwise edge-disjoint. With an appropriate dynamic tree data structure (e.g., [link-cut trees](http://en.wikipedia.org/wiki/Link/cut_tree) or [top trees](http://en.wikipedia.org/wiki/Top_tree)), it is possible to find the node where the two paths split and the minimum edge-index along the disjoint suffixes in $O(\log n)$ amortized time. So, this scheme is always correct, but it imposes a penalty in the running time that is only $O(\log n)$ *if* your algorithm has the right structure, and it requires significant data structure overhead.

You can guess which method I recommend. My recent [journal paper](http://www.cs.uiuc.edu/~jeffe/pubs/multishort.html) with Sergio Cabello and Erin Chambers describes both of these perturbation schemes in more detail.

There are also more specialized methods for specific algorithms and specific classes of graphs.

> I would also like the "perturbed" shortest path to be chosen uniformly at random from the set of original shortest paths. Is this possible?

I don't know. In particular, the randomized perturbation scheme I described does *not* have this property.

> **Comments:**
> **username_0**: Thanks a lot, Jeff. This is a great answer and gave me a lot of insights.  
> **username_2**: Nice answer. I also read your journal paper and would be interested if these techniques could be extended to euclidean instances. (Full question: http://cstheory.stackexchange.com/questions/31851/lexicographic-perturbation-for-euclidean-shortest-path-instances )  

---

