<p>The Eulerian cycle problem with "transition" costs $f$ is NP-hard by reduction from the Traveling Salesman Problem (TSP). Specifically, for any TSP instance given as a complete weighted graph on vertices $V = \{v_1,v_2,...,v_n\}$, encoded via the cost function $d : V \times V \rightarrow \cal{R}$, we can transform this into your problem in polynomial time as follows. </p>

<p>First, create a graph with a single "anchor" vertex $x$. Then, for each vertex $v_i \in V$, create a (self-looping*) edge $e_i = (x,x)$ with cost 0 (you can envision these self-loops as the separate "petals" of a flower-like graph in two-dimensions anchored around $x$). Finally, create a transition function $f$ (as per your definition) such that $f(x, e_i, e_j) = d(v_i, v_j)$. All Eulerian cycles (with transition costs from $f$) in this case are thus in 1:1 correspondence with all Hamiltonian cycles (i.e., solutions) of the original TSP instance and have equivalent cost. So if you can find a minimum-cost Eulerian cycle with such transition costs, then you can solve TSP to optimality, completing the reduction.</p>

<p>*Note that the self-looping edge encoding is not necessary, but it simplifies the description somewhat for the purposes of discussion above just to give the intuition (and your encoding seems to allow this). These self-loops can actually be broken up into separate "triangle" sub-graphs ($K_3$ gadgets), all anchored at the shared node $x$ whose edge transitions to other such gadgets are assigned costs accordingly from $d$ (but in a slightly-more-detailed manner).</p>

CC BY-SA 3.0
2018-01-19T22:02:29.820Z
2018-02-05T17:13:58.377Z
2018-02-05T17:13:58.377Z
Michael N. Rice
<p><strong>Problem:</strong></p>

<p>Given a planar (undirected and mostly sparse) graph with an Eulerian Path, we introduce a cost function f: (v, e1, e2) for all two edges e1 and e2 that share a vertex v. The function also fulfills f(v, e1, e2) = f(v, e2, e1)</p>

<p>For an Eulerian Path we then define the overall cost as the sum of costs of all path-neighboring edges and the vertex in-between.</p>

<p><strong>The goal is to obtain an Eulerian Path that has a minimal total cost.</strong> This has to be done somewhat efficiently, so testing all paths is not an option. Ideally answers should outline an algorithm.</p>

<p><strong>Background:</strong></p>

<p>The goal is to find a path that is "smooth". An example here is the B point in the image below. The flow is a lot smother if we go clockwise through the loop when coming from C.</p>

<p><strong>Thoughts:</strong></p>

<p>I think it is important to understand how many variations exist for an Eulerian Path and how we would obtain them.</p>

<ol>
<li>There exists one very obvious variation, which is changing the direction of the path. We don't need to consider this variation since f(v, e1, e2) = f(v, e2, e1)</li>
<li>For any vertex with 0,..,n incoming and n,..,0 outgoing path segments, the path can be altered by swapping the ith incoming with the ith outgoing edge for i in 0,..,n. However this needs some alterations when the start/end vertex is included as well. Maybe we can just ignore it. <em>Example:</em> Point B and D</li>
<li>We can further swap "inner pairings with outer pairings", i.e. ith incoming and ith outgoing can be swapped with jth incoming and jth outgoing respectively for i, j in 1,..,n. Again we need to ignore start/end edge. This rule only applies if >= 6 edges join in a single vertex.</li>
</ol>

<p><a href="https://i.sstatic.net/ILv9m.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ILv9m.png" alt="enter image description here"></a></p>

<p>It becomes more difficult when the cycles from the vertex overlap, because then we can swap between them as well. Or do we not need to consider this at all? It's getting complicated and I'm no longer sure about correctness. So I’m kind of stuck.</p>

<ul>
<li>Can we somehow convert this into an optimization problem?</li>
<li>Are there any papers on this topic? I couldn't find any.</li>
<li>Should I approach the problem completely different?</li>
<li>Can we somehow achieve minimal cost while executing Fleury's or Hierholzer's algorithm?</li>
</ul>

<hr>

<p><em>Edit (Aug 7 '17)</em></p>

<p>This presentation seems very interesting: <a href="https://www.cs.rochester.edu/~stefanko/Talks/EULER.pdf" rel="nofollow noreferrer">https://www.cs.rochester.edu/~stefanko/Talks/EULER.pdf</a> Unfortunately I wasn't able to find a paper accompanying it. At least counting Eulerian Cycle is #P-Complete.</p>

<p>Considering finding a minimum Eulerian Cycle for simplicity and using the idea of the <a href="https://en.wikipedia.org/wiki/Eulerian_path#Hierholzer.27s_algorithm" rel="nofollow noreferrer">Hierholzer's algorithm</a>, we can find all simple cycles in the graph efficiently using e.g. <a href="http://www.cs.tufts.edu/comp/150GA/homeworks/hw1/Johnson%2075.PDF" rel="nofollow noreferrer">http://www.cs.tufts.edu/comp/150GA/homeworks/hw1/Johnson%2075.PDF</a></p>

<p>We would then need to find the <a href="https://en.wikipedia.org/wiki/Edge_cycle_cover" rel="nofollow noreferrer">edge-disjoint edge cycle cover</a>. But this still doesn't guarantee a minimal path or Eulerian Cycle, because we still have to fuse the sub-cycles together.</p>

<hr>

<p><em>Edit (Jan 7 '18)</em></p>

<p>I've started looking at solving this for an Eulerian Cycle since we have to consider fewer edge cases and the cycle problem is easily converted into the path problem (see <a href="https://cstheory.stackexchange.com/questions/38717/modifying-edmonds-blossom-algorithm">here</a>).</p>

<p>There have been suggestions to solve this by optimizing for each node. However, as the next example shows (colors indicate Eulerian Cycle), the local optima "battle" for each other. The top node uses the local optima, however if we were to use the optimum for both nodes we would obtain two circles and no longer have an Eulerian path.</p>

<p><a href="https://i.sstatic.net/UzLCn.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/UzLCn.png" alt="Circles"></a></p>

<p>I'm thinking maybe we can break the Eulerian Cycle into several "locally optimal" walks and then fuse them together again (efficiently we could find those walks using the Hierholzer's algorithm and following the lowest cost edge). Not guaranteed to be optimal though I think (or is it if we fuse them optimally?).</p>

<p><strong>What's next?</strong>
I'll try to save up for a bounty to give this question some more exposure.</p>

<hr>

<p><em>Edit (Nov 6 '18)</em></p>

<p>Still looking for an answer. I will try to implement my technique suggested above next. I'm no longer looking for a perfect algorithm, but one that approximates the solution.</p>

CC BY-SA 3.0
2017-08-05T02:21:01.200Z
This problem is NP-complete. I don't have a simple proof, which is why this is a comment and not an answer, and of course you don't have to believe me without proof, but that should help direct people in the right direction. The reason I believe this is that I have a complicated reduction in mind (and am too lazy to write it up).
Mikhail Rudoy
CC BY-SA 3.0
2017-08-05T02:34:24.313Z
@MikhailRudoy I would have guessed that we can iteratively improve the solution. But basically you are saying that vertex edge choices heavily influence each other. Very curious if someone can come up with a proof. Feel free to sketch your idea more!
vincent
CC BY-SA 3.0
2017-12-24T18:21:25.687Z
@MikhailRudoy Would this change if we assumed that the graph is planar / with coordinates? I found this question very interesting: https://math.stackexchange.com/questions/8140/find-all-cycles-faces-in-a-graph
vincent
CC BY-SA 3.0
2017-12-27T04:48:22.157Z
The reduction that I'm thinking of also works if the graph is planar and the vertices are specified by coordinates. The reason I'm being too lazy to write it up is that the reduction is not from a well known problem but rather from a problem I made up called TRVB which people are generally not familiar with (see https://arxiv.org/abs/1706.07900). The key idea of the reduction is to simulate an "edge" in a TRVB instance using two parallel paths of degree-2 vertices in your problem and simulate a "breakable vertex" using a single vertex in your problem.
Mikhail Rudoy
<ds.algorithms><graph-theory><graph-algorithms><optimization>
Minimal Cost of Eulerian Path
vincent
# Minimal Cost of Eulerian Path

(Asked by: username_0 on 2017-08-04)

**Problem:**

Given a planar (undirected and mostly sparse) graph with an Eulerian Path, we introduce a cost function f: (v, e1, e2) for all two edges e1 and e2 that share a vertex v. The function also fulfills f(v, e1, e2) = f(v, e2, e1)

For an Eulerian Path we then define the overall cost as the sum of costs of all path-neighboring edges and the vertex in-between.

**The goal is to obtain an Eulerian Path that has a minimal total cost.** This has to be done somewhat efficiently, so testing all paths is not an option. Ideally answers should outline an algorithm.

**Background:**

The goal is to find a path that is "smooth". An example here is the B point in the image below. The flow is a lot smother if we go clockwise through the loop when coming from C.

**Thoughts:**

I think it is important to understand how many variations exist for an Eulerian Path and how we would obtain them.

1. There exists one very obvious variation, which is changing the direction of the path. We don't need to consider this variation since f(v, e1, e2) = f(v, e2, e1)
2. For any vertex with 0,..,n incoming and n,..,0 outgoing path segments, the path can be altered by swapping the ith incoming with the ith outgoing edge for i in 0,..,n. However this needs some alterations when the start/end vertex is included as well. Maybe we can just ignore it. *Example:* Point B and D
3. We can further swap "inner pairings with outer pairings", i.e. ith incoming and ith outgoing can be swapped with jth incoming and jth outgoing respectively for i, j in 1,..,n. Again we need to ignore start/end edge. This rule only applies if >= 6 edges join in a single vertex.

[![enter image description here](https://i.sstatic.net/ILv9m.png)](https://i.sstatic.net/ILv9m.png)

It becomes more difficult when the cycles from the vertex overlap, because then we can swap between them as well. Or do we not need to consider this at all? It's getting complicated and I'm no longer sure about correctness. So I’m kind of stuck.

* Can we somehow convert this into an optimization problem?
* Are there any papers on this topic? I couldn't find any.
* Should I approach the problem completely different?
* Can we somehow achieve minimal cost while executing Fleury's or Hierholzer's algorithm?

---

*Edit (Aug 7 '17)*

This presentation seems very interesting: <https://www.cs.rochester.edu/~stefanko/Talks/EULER.pdf> Unfortunately I wasn't able to find a paper accompanying it. At least counting Eulerian Cycle is #P-Complete.

Considering finding a minimum Eulerian Cycle for simplicity and using the idea of the [Hierholzer's algorithm](https://en.wikipedia.org/wiki/Eulerian_path#Hierholzer.27s_algorithm), we can find all simple cycles in the graph efficiently using e.g. <http://www.cs.tufts.edu/comp/150GA/homeworks/hw1/Johnson%2075.PDF>

We would then need to find the [edge-disjoint edge cycle cover](https://en.wikipedia.org/wiki/Edge_cycle_cover). But this still doesn't guarantee a minimal path or Eulerian Cycle, because we still have to fuse the sub-cycles together.

---

*Edit (Jan 7 '18)*

I've started looking at solving this for an Eulerian Cycle since we have to consider fewer edge cases and the cycle problem is easily converted into the path problem (see [here](https://cstheory.stackexchange.com/questions/38717/modifying-edmonds-blossom-algorithm)).

There have been suggestions to solve this by optimizing for each node. However, as the next example shows (colors indicate Eulerian Cycle), the local optima "battle" for each other. The top node uses the local optima, however if we were to use the optimum for both nodes we would obtain two circles and no longer have an Eulerian path.

[![Circles](https://i.sstatic.net/UzLCn.png)](https://i.sstatic.net/UzLCn.png)

I'm thinking maybe we can break the Eulerian Cycle into several "locally optimal" walks and then fuse them together again (efficiently we could find those walks using the Hierholzer's algorithm and following the lowest cost edge). Not guaranteed to be optimal though I think (or is it if we fuse them optimally?).

**What's next?**
I'll try to save up for a bounty to give this question some more exposure.

---

*Edit (Nov 6 '18)*

Still looking for an answer. I will try to implement my technique suggested above next. I'm no longer looking for a perfect algorithm, but one that approximates the solution.

**Tags:** ds.algorithms, graph-theory, graph-algorithms, optimization

> **Comments:**
> **username_1**: This problem is NP-complete. I don't have a simple proof, which is why this is a comment and not an answer, and of course you don't have to believe me without proof, but that should help direct people in the right direction. The reason I believe this is that I have a complicated reduction in mind (and am too lazy to write it up).  
> **username_0**: @MikhailRudoy I would have guessed that we can iteratively improve the solution. But basically you are saying that vertex edge choices heavily influence each other. Very curious if someone can come up with a proof. Feel free to sketch your idea more!  
> **username_0**: @MikhailRudoy Would this change if we assumed that the graph is planar / with coordinates? I found this question very interesting: https://math.stackexchange.com/questions/8140/find-all-cycles-faces-in-a-graph  
> **username_1**: The reduction that I'm thinking of also works if the graph is planar and the vertices are specified by coordinates. The reason I'm being too lazy to write it up is that the reduction is not from a well known problem but rather from a problem I made up called TRVB which people are generally not familiar with (see https://arxiv.org/abs/1706.07900). The key idea of the reduction is to simulate an "edge" in a TRVB instance using two parallel paths of degree-2 vertices in your problem and simulate a "breakable vertex" using a single vertex in your problem.  

---

## 1 answers

### Answer by username_2 on 2018-01-19. Score: 3

The Eulerian cycle problem with "transition" costs $f$ is NP-hard by reduction from the Traveling Salesman Problem (TSP). Specifically, for any TSP instance given as a complete weighted graph on vertices $V = \{v\_1,v\_2,...,v\_n\}$, encoded via the cost function $d : V \times V \rightarrow \cal{R}$, we can transform this into your problem in polynomial time as follows.

First, create a graph with a single "anchor" vertex $x$. Then, for each vertex $v\_i \in V$, create a (self-looping\*) edge $e\_i = (x,x)$ with cost 0 (you can envision these self-loops as the separate "petals" of a flower-like graph in two-dimensions anchored around $x$). Finally, create a transition function $f$ (as per your definition) such that $f(x, e\_i, e\_j) = d(v\_i, v\_j)$. All Eulerian cycles (with transition costs from $f$) in this case are thus in 1:1 correspondence with all Hamiltonian cycles (i.e., solutions) of the original TSP instance and have equivalent cost. So if you can find a minimum-cost Eulerian cycle with such transition costs, then you can solve TSP to optimality, completing the reduction.

\*Note that the self-looping edge encoding is not necessary, but it simplifies the description somewhat for the purposes of discussion above just to give the intuition (and your encoding seems to allow this). These self-loops can actually be broken up into separate "triangle" sub-graphs ($K\_3$ gadgets), all anchored at the shared node $x$ whose edge transitions to other such gadgets are assigned costs accordingly from $d$ (but in a slightly-more-detailed manner).


---

