# What's wrong with my linear programming formulation of longest path? [closed]

I have a directed graph which has cycles. Each edge has a positive weight. Now given two vertices $u$ and $v$, I want to find the longest simple path from $u$ to $v$. Simple means the path has no repetition in vertices.

I understand this problem is NP-hard in general. But I am wondering what's wrong in my following linear programming formulation.

Let us add a source vertex $s$, which is connected to $u$ by an edge with capacity $1$. Let v be connected to a sink vertex $t$ with capacity 1 too. Denote the new edge set as $E$. Use $w_{ij} = 1$ to represent that the edge $(i,j)$ is in the path, and $w_{ij} = 0$ if not. So $w_{ij} \in \{0,1\}$. Then a simple path from $s$ to $t$ needs to satisfy

1. Conservation constraints: for all vertices $i$ (except $s$ and $t$),

$\sum_{k: (k, i) \in E} w_{ki} = \sum_{j: (i,j) \in E} w_{ij}$.

Let us call this common quantity as $w_i$.

2. No repetition of vertex: add a vertex capacity 1 on each vertex:

$w_i \in \{0,1\}$.

Clearly any set of $\{w_{ij}\}$ satisfying these constraints represents an st-path, as long as $w_{ij}$ is not straight $0$.

Now let us drop the integral constraints:

$w_{ij} \in [0,1]$, $w_i \in [0,1]$,

$w_i = \sum_{k: (k, i) \in E} w_{ki}$ for all $i$,

$w_i = \sum_{j: (i,j) \in E} w_{ij}$ for all $i$.

Then I claim the coefficient matrix arising from these linear constraints is totally unimodular (TUM). To this end, it suffices to show that the coefficient matrix for the last two constraints is TUM. But this is trivial, say by the example 1 of this link (take $B$ as the set of all rows, and $C$ as an empty set).

Since a longest path maximizes a linear function of $w_{ij}$ with positive coefficients, the optimal solution must be an extreme point of the feasible region, which by TUM must be integral. Clearly, setting $w_{ij}$ to straight 0 is not optimal, and so the optimal solution must be an $st$-path.

So question: something must be wrong here, either

1. The integral constraints in 1 and 2 do not jointly define an $st$-path (ignoring the straight 0), and/or

2. TUM does not hold indeed.

• This is not a research-level question; it would be better for CS.se. – Jeffε Oct 23 '13 at 12:05