name: Problem
about: Propose a new problem type
title: "[Model] LongestPath"
labels: model
assignees: ''
Motivation
LONGEST PATH (P105) from Garey & Johnson, A2 ND29. A classical NP-complete problem useful for reductions. Asks for a simple s-t path in a graph maximizing total edge length. NP-complete even with unit edge lengths, where it generalizes the Hamiltonian path problem. Solvable in polynomial time on DAGs.
Associated reduction rules:
- As source: None found in the current rule set.
- As target: R50: HAMILTONIAN PATH BETWEEN TWO VERTICES -> LONGEST PATH
Definition
Name: LongestPath
Canonical name: LONGEST PATH (also: Longest Simple Path, Maximum Weight Path)
Reference: Garey & Johnson, Computers and Intractability, A2 ND29
Mathematical definition:
INSTANCE: Graph G = (V,E), length l(e) ∈ Z^+ for each e ∈ E, specified vertices s,t ∈ V.
OBJECTIVE: Find a simple path in G from s to t that maximizes the total edge length, i.e., maximize the sum of l(e) over all edges e in the path.
Variables
- Count: |E| binary variables (one per edge), indicating whether the edge is included in the path.
- Per-variable domain: {0, 1} -- edge is excluded or included in the s-t path.
- Meaning: The variable assignment encodes a subset of edges. A valid assignment is a subset S of E such that the subgraph induced by S forms a simple path from s to t. The objective value is the sum of l(e) for e in S. An assignment that does not form a valid simple s-t path is Invalid.
Schema (data type)
Type name: LongestPath
Variants: graph type (G), weight type (W)
| Field |
Type |
Description |
graph |
G |
The undirected graph G = (V, E) |
lengths |
Vec<W> |
Edge length l(e) for each edge (indexed by edge index) |
source |
usize |
Index of source vertex s |
target |
usize |
Index of target vertex t |
Notes:
- This is an optimization problem:
Metric = SolutionSize<W>, implementing OptimizationProblem with Direction::Maximize.
- A configuration that does not form a valid simple s-t path evaluates to
SolutionSize::Invalid.
- A valid simple s-t path evaluates to
SolutionSize::Valid(total_length) where total_length is the sum of edge lengths along the path.
- The decision variant (is there a path of length ≥ K?) can be recovered by comparing the optimal value to the bound.
- The unit-weight special case is equivalent to finding the longest simple path by hop count.
- Polynomial-time solvable on DAGs (directed acyclic graphs) via topological sort + DP.
Complexity
- Best known exact algorithm: O*(2^n) via inclusion-exclusion / algebraic methods. The color-coding technique of Alon, Yuster, and Zwick (1995) solves the k-path problem in O*(2^k) time (FPT in path length k). For general longest path, exhaustive search over all simple paths dominates.
- Classic algorithm: O(n! / (n-k)!) brute force over all simple paths of length k; or O(n * 2^n) dynamic programming over vertex subsets (similar to Held-Karp).
- NP-completeness: NP-complete by transformation from HAMILTONIAN PATH BETWEEN TWO VERTICES (Garey & Johnson, ND29). Remains NP-complete with unit edge lengths.
- Special cases: Polynomial-time on DAGs, trees, interval graphs, and some other restricted graph classes.
- References:
- N. Alon, R. Yuster, U. Zwick (1995). "Color-coding." Journal of the ACM, 42(4):844-856.
- R. Williams (2009). "Finding paths of length k in O*(2^k) time." Information Processing Letters, 109(6):315-318.
Extra Remark
Full book text:
INSTANCE: Graph G = (V,E), length l(e) ∈ Z^+ for each e ∈ E, positive integer K, specified vertices s,t ∈ V.
QUESTION: Is there a simple path in G from s to t of length K or more, i.e., whose edge lengths sum to at least K?
Reference: Transformation from HAMILTONIAN PATH BETWEEN TWO VERTICES.
Comment: Remains NP-complete if l(e) = 1 for all e ∈ E, as does the corresponding problem for directed paths in directed graphs. The general problem can be solved in polynomial time for acyclic digraphs, e.g., see [Lawler, 1976a]. The analogous directed and undirected "shortest path" problems can be solved for arbitrary graphs in polynomial time (e.g., see [Lawler, 1976a]), but are NP-complete if negative lengths are allowed.
How to solve
Example Instance
Instance 1 (optimal path length = 20):
Graph G with 7 vertices {0, 1, 2, 3, 4, 5, 6} and 10 edges:
- Edges with lengths: {0,1}:3, {0,2}:2, {1,3}:4, {2,3}:1, {2,4}:5, {3,5}:2, {4,5}:3, {4,6}:2, {5,6}:4, {1,6}:1
- s = 0, t = 6
- Optimal path: 0 → 1 → 3 → 2 → 4 → 5 → 6
- Length: 3 + 4 + 1 + 5 + 3 + 4 = 20
- Suboptimal path: 0 → 2 → 4 → 5 → 3 → 1 → 6
- Length: 2 + 5 + 3 + 2 + 4 + 1 = 17
- Invalid configuration: edges {0,1}, {0,2}, {1,3} do not form a simple s-t path → Invalid
name: Problem
about: Propose a new problem type
title: "[Model] LongestPath"
labels: model
assignees: ''
Motivation
LONGEST PATH (P105) from Garey & Johnson, A2 ND29. A classical NP-complete problem useful for reductions. Asks for a simple s-t path in a graph maximizing total edge length. NP-complete even with unit edge lengths, where it generalizes the Hamiltonian path problem. Solvable in polynomial time on DAGs.
Associated reduction rules:
Definition
Name:
LongestPathCanonical name: LONGEST PATH (also: Longest Simple Path, Maximum Weight Path)
Reference: Garey & Johnson, Computers and Intractability, A2 ND29
Mathematical definition:
INSTANCE: Graph G = (V,E), length l(e) ∈ Z^+ for each e ∈ E, specified vertices s,t ∈ V.
OBJECTIVE: Find a simple path in G from s to t that maximizes the total edge length, i.e., maximize the sum of l(e) over all edges e in the path.
Variables
Schema (data type)
Type name:
LongestPathVariants: graph type (G), weight type (W)
graphGlengthsVec<W>sourceusizetargetusizeNotes:
Metric = SolutionSize<W>, implementingOptimizationProblemwithDirection::Maximize.SolutionSize::Invalid.SolutionSize::Valid(total_length)wheretotal_lengthis the sum of edge lengths along the path.Complexity
Extra Remark
Full book text:
INSTANCE: Graph G = (V,E), length l(e) ∈ Z^+ for each e ∈ E, positive integer K, specified vertices s,t ∈ V.
QUESTION: Is there a simple path in G from s to t of length K or more, i.e., whose edge lengths sum to at least K?
Reference: Transformation from HAMILTONIAN PATH BETWEEN TWO VERTICES.
Comment: Remains NP-complete if l(e) = 1 for all e ∈ E, as does the corresponding problem for directed paths in directed graphs. The general problem can be solved in polynomial time for acyclic digraphs, e.g., see [Lawler, 1976a]. The analogous directed and undirected "shortest path" problems can be solved for arbitrary graphs in polynomial time (e.g., see [Lawler, 1976a]), but are NP-complete if negative lengths are allowed.
How to solve
Example Instance
Instance 1 (optimal path length = 20):
Graph G with 7 vertices {0, 1, 2, 3, 4, 5, 6} and 10 edges: